use of com.nolanlawson.keepscore.widget.PlayerView in project KeepScore by nolanlawson.
the class GameActivity method setOrUpdateColorScheme.
private void setOrUpdateColorScheme() {
ColorScheme colorScheme = PreferenceHelper.getColorScheme(this);
int foregroundColor = getResources().getColor(colorScheme.getForegroundColorResId());
int backgroundColor = getResources().getColor(colorScheme.getBackgroundColorResId());
int dividerColor = getResources().getColor(colorScheme.getDividerColorResId());
rootLayout.setBackgroundColor(backgroundColor);
for (PlayerView playerView : playerViews) {
playerView.getNameTextView().setTextColor(foregroundColor);
playerView.getNameTextView().setTypeface(colorScheme.getPlayerNameTypeface());
playerView.getScoreTextView().setTextColor(foregroundColor);
playerView.setNewColorScheme(colorScheme);
playerView.getDivider1().setBackgroundColor(dividerColor);
if (playerView.getDivider2() != null) {
playerView.getDivider2().setBackgroundColor(dividerColor);
}
for (Button button : new Button[] { playerView.getPlusButton(), playerView.getMinusButton(), playerView.getDeltaButton1(), playerView.getDeltaButton2(), playerView.getDeltaButton3(), playerView.getDeltaButton4() }) {
if (button != null) {
button.setBackgroundDrawable(getResources().getDrawable(colorScheme.getButtonBackgroundDrawableResId()));
button.setTextColor(getResources().getColor(colorScheme.getForegroundColorResId()));
}
}
playerView.updateViews();
}
if (roundTotalTextView != null) {
roundTotalTextView.setTextColor(getResources().getColor(colorScheme.getForegroundColorResId()));
}
}
use of com.nolanlawson.keepscore.widget.PlayerView in project KeepScore by nolanlawson.
the class GameActivity method undoOrRedo.
private void undoOrRedo(boolean undo) {
DataExpiringStack<RecordedChange> stackToPoll = undo ? undoStack : redoStack;
DataExpiringStack<RecordedChange> stackToPop = !undo ? undoStack : redoStack;
RecordedChange recordedChange = null;
int lastPlayerNumber = -1;
RecordedChange.Type lastType = null;
while ((recordedChange = stackToPoll.peek()) != null && (lastPlayerNumber == -1 || lastPlayerNumber == recordedChange.getPlayerNumber()) && // only apply multiple changes to the same PlayerScore
(lastType == null || isAcceptableUndoOrRedoTransition(undo, lastType, recordedChange.getType()))) {
recordedChange = stackToPoll.poll();
PlayerView playerView = playerViews.get(recordedChange.getPlayerNumber());
if (undo) {
playerView.revertChange(recordedChange);
} else {
playerView.reexecuteChange(recordedChange);
}
stackToPop.pop(recordedChange);
lastPlayerNumber = recordedChange.getPlayerNumber();
lastType = recordedChange.getType();
}
if (lastPlayerNumber != -1) {
PlayerView playerView = playerViews.get(lastPlayerNumber);
// keeps the badge from showing
playerView.resetLastIncremented();
playerView.updateViews();
}
}
use of com.nolanlawson.keepscore.widget.PlayerView in project KeepScore by nolanlawson.
the class GameActivity method updateHighlightedPlayer.
private void updateHighlightedPlayer() {
// highlight the most recently changed player. This helps with round-based games
// (where it's important to know that each player's round has been tallied)
// or games where the scoring has to happen in a particular order (e.g. Cribbage)
long maxLastUpdate = 0;
int maxLastUpdateIdx = -1;
for (int i = 0; i < playerScores.size(); i++) {
PlayerScore playerScore = playerScores.get(i);
log.d("playerScore lastUpdate is %s", playerScore.getLastUpdate());
if (playerScore.getLastUpdate() > maxLastUpdate) {
maxLastUpdate = playerScore.getLastUpdate();
maxLastUpdateIdx = i;
}
}
log.d("updating highlighted player score to idx %s", maxLastUpdateIdx);
// if none of the player scores are above 0, then this is a game from an older version
// of KeepScore where we didn't track the lastUpdate, so we don't highlight anything
boolean disableTagIcon = PreferenceHelper.getBooleanPreference(R.string.CONSTANT_pref_disable_highlight_tag, R.string.CONSTANT_pref_disable_highlight_tag_default, this);
for (int i = 0; i < playerViews.size(); i++) {
PlayerView playerView = playerViews.get(i);
boolean highlighted = (!disableTagIcon && (i == maxLastUpdateIdx));
// highlight or un-highlight by showing or hiding the bullet
ImageView tagImageView = playerView.getTagImageView();
tagImageView.setVisibility(highlighted ? View.VISIBLE : View.INVISIBLE);
}
}
use of com.nolanlawson.keepscore.widget.PlayerView in project KeepScore by nolanlawson.
the class GameActivity method createRematchGame.
private void createRematchGame() {
// save the original game
saveGame(game, true, null);
for (PlayerView playerView : playerViews) {
playerView.cancelPendingUpdates();
}
game = game.makeCleanCopy();
playerScores = game.getPlayerScores();
setUpWidgets();
for (PlayerView playerView : playerViews) {
playerView.reset(GameActivity.this);
}
// save the new game
saveGame(game, true, null);
updateRoundTotalViewText();
undoStack.clear();
redoStack.clear();
Toast.makeText(this, R.string.toast_rematch_created, Toast.LENGTH_SHORT).show();
}
use of com.nolanlawson.keepscore.widget.PlayerView in project KeepScore by nolanlawson.
the class GameActivity method setUpWidgets.
private void setUpWidgets() {
rootLayout = (LinearLayout) findViewById(R.id.game_root_layout);
// add top and bottom spacing on the two-player game. it looks nicer
rootPadding1 = findViewById(R.id.game_root_padding_1);
rootPadding2 = findViewById(R.id.game_root_padding_2);
rootPadding1.setVisibility(playerScores.size() <= 2 ? View.VISIBLE : View.GONE);
rootPadding2.setVisibility(playerScores.size() <= 2 ? View.VISIBLE : View.GONE);
// if the round totals are enabled
try {
roundTotalViewStub = (ViewStub) findViewById(R.id.round_totals);
int versionInt = VersionHelper.getVersionSdkIntCompat();
if (versionInt > VersionHelper.VERSION_DONUT && versionInt < VersionHelper.VERSION_FROYO) {
roundTotalTextView = (TextView) roundTotalViewStub.inflate();
}
} catch (ClassCastException ignore) {
// view stub already inflated
}
playerViews = new ArrayList<PlayerView>();
boolean showOnscreenDeltaButtons = getShouldShowOnscreenDeltaButtons();
for (int i = 0; i < playerScores.size(); i++) {
PlayerScore playerScore = playerScores.get(i);
int resId = getPlayerViewResId(i);
View view = getPlayerScoreView(resId);
if (view == null) {
log.e("Null pointer exception; view for player %s is null", i);
}
PlayerView playerView = new PlayerView(this, view, playerScore, handler, showOnscreenDeltaButtons);
playerView.setChangeRecorder(new Callback<RecordedChange>() {
@Override
public void onCallback(RecordedChange recordedChange) {
undoStack.pop(recordedChange);
redoStack.clear();
}
});
playerView.setOnChangeListener(new Runnable() {
@Override
public void run() {
updateRoundTotalViewText();
updateHighlightedPlayer();
}
});
// worth saving. This only applies for newly created games.
if (game.getId() == -1 && !TextUtils.isEmpty(playerScore.getName())) {
playerView.getShouldAutosave().set(true);
}
playerViews.add(playerView);
}
hideAbsentPlayers();
}
Aggregations