use of com.nolanlawson.keepscore.db.PlayerScore in project KeepScore by nolanlawson.
the class OrganizePlayersActivity method setUpWidgets.
private void setUpWidgets() {
okButton = (Button) findViewById(R.id.button_ok);
okButton.setOnClickListener(this);
cancelButton = (Button) findViewById(R.id.button_cancel);
cancelButton.setOnClickListener(this);
adapter = new EditablePlayerAdapter(this, game.getPlayerScores());
setListAdapter(adapter);
adapter.setOnChangeListener(new Runnable() {
@Override
public void run() {
// update the Add Player button if necessary
supportInvalidateOptionsMenu();
}
});
adapter.setOnDeleteListener(new Callback<PlayerScore>() {
@Override
public void onCallback(PlayerScore playerScore) {
// i.e. there's something the user might regret deleting
if (playerScore.getHistory() != null && playerScore.getHistory().size() > 0) {
deletedPlayersToWarnAbout.add(playerScore.toDisplayName(OrganizePlayersActivity.this).toString());
}
}
});
((DragSortListView) getListView()).setDropListener(adapter);
}
use of com.nolanlawson.keepscore.db.PlayerScore in project KeepScore by nolanlawson.
the class OrganizePlayersActivity method addNewPlayer.
private void addNewPlayer(CharSequence name) {
PlayerScore playerScore = new PlayerScore();
playerScore.setId(-1);
playerScore.setName(StringUtil.nullToEmpty(name));
playerScore.setPlayerNumber(adapter.getCount());
playerScore.setScore(PreferenceHelper.getIntPreference(R.string.CONSTANT_pref_initial_score, R.string.CONSTANT_pref_initial_score_default, this));
playerScore.setHistory(new ArrayList<Delta>());
playerScore.setPlayerColor(PlayerColor.BUILT_INS[playerScore.getPlayerNumber() % PlayerColor.BUILT_INS.length]);
adapter.add(playerScore);
adapter.notifyDataSetChanged();
}
use of com.nolanlawson.keepscore.db.PlayerScore in project KeepScore by nolanlawson.
the class HistoryTimelineFragment method createTimelineLayout.
private void createTimelineLayout(Activity activity) {
List<String> xAxisLabels = new ArrayList<String>();
SparseArray<SparseArray<Long>> smoothedData = smoothData(game);
List<LineChartLine> data = new ArrayList<LineChartLine>();
for (PlayerScore playerScore : game.getPlayerScores()) {
data.add(new LineChartLine(playerScore.toDisplayName(activity).toString(), new ArrayList<Integer>()));
}
long[] lastPlayerScores = new long[game.getPlayerScores().size()];
for (int i = 0; i < smoothedData.size(); i++) {
int timeSinceStart = smoothedData.keyAt(i);
xAxisLabels.add(TimeUtil.formatSeconds(timeSinceStart));
SparseArray<Long> scores = smoothedData.get(timeSinceStart);
for (int playerIdx = 0; playerIdx < game.getPlayerScores().size(); playerIdx++) {
Long scoreObj = scores.get(playerIdx);
// just give the player a zero-delta (i.e. previous score) for this "round" if no changes
long score = scoreObj == null ? lastPlayerScores[playerIdx] : scoreObj;
List<Integer> dataPoints = data.get(playerIdx).getDataPoints();
dataPoints.add((int) score);
lastPlayerScores[playerIdx] = score;
}
}
timelineChartView.setLineColors(createLineColors(game, activity));
timelineChartView.setxAxisLabels(xAxisLabels);
log.d("x labels are %s", xAxisLabels);
timelineChartView.loadData(data);
}
use of com.nolanlawson.keepscore.db.PlayerScore in project KeepScore by nolanlawson.
the class GamesBackupSerializer method deserialize.
@SuppressWarnings("incomplete-switch")
public static GamesBackup deserialize(String xmlData) {
int parserEvent = -1;
XmlPullParser parser = null;
Tag tag = null;
GamesBackup gamesBackup = new GamesBackup();
gamesBackup.setGames(new ArrayList<Game>());
Game game = null;
PlayerScore playerScore = null;
Map<String, String> attributes = null;
try {
// calls service (referenced in url) to request XML serialized data
parser = XmlHelper.loadData(xmlData);
parserEvent = parser.getEventType();
while (parserEvent != XmlPullParser.END_DOCUMENT) {
switch(parserEvent) {
case XmlPullParser.START_TAG:
tag = Tag.valueOf(parser.getName());
switch(tag) {
case Game:
game = new Game();
game.setPlayerScores(new ArrayList<PlayerScore>());
break;
case PlayerScore:
playerScore = new PlayerScore();
break;
}
// null or empty marker
if (parser.getAttributeCount() != -1) {
attributes = getAttributes(parser);
}
break;
case XmlPullParser.END_TAG:
tag = Tag.valueOf(parser.getName());
switch(tag) {
case Game:
gamesBackup.getGames().add(game);
break;
case PlayerScore:
game.getPlayerScores().add(playerScore);
break;
}
break;
case XmlPullParser.TEXT:
String text = parser.getText();
if (!StringUtil.isEmptyOrWhitespace(text)) {
handleText(text, tag, attributes, gamesBackup, game, playerScore);
}
break;
}
parserEvent = parser.next();
}
} catch (XmlPullParserException e) {
log.e(e, "unexpected");
} catch (IOException e) {
log.e(e, "unexpected");
}
applyVersionFixes(gamesBackup);
// return de-serialized game backup
return gamesBackup;
}
Aggregations