Search in sources :

Example 6 with Delta

use of com.nolanlawson.keepscore.db.Delta in project KeepScore by nolanlawson.

the class PlayerView method addZero.

private void addZero() {
    // with no points for a particular player
    synchronized (lock) {
        Delta delta = new Delta(System.currentTimeMillis(), 0);
        changeRecorder.onCallback(new RecordedChange(playerScore.getPlayerNumber(), Type.AddNew, delta));
        playerScore.getHistory().add(delta);
    }
    // reset last incremented
    lastIncremented.set(0);
    shouldAutosave.set(true);
    updateViews();
}
Also used : Delta(com.nolanlawson.keepscore.db.Delta) RecordedChange(com.nolanlawson.keepscore.data.RecordedChange)

Example 7 with Delta

use of com.nolanlawson.keepscore.db.Delta in project KeepScore by nolanlawson.

the class MainActivity method copyGame.

private void copyGame(Game game, final boolean resetScores) {
    final Game newGame = game.makeCleanCopy();
    if (resetScores) {
        for (PlayerScore playerScore : newGame.getPlayerScores()) {
            playerScore.setScore(PreferenceHelper.getIntPreference(R.string.CONSTANT_pref_initial_score, R.string.CONSTANT_pref_initial_score_default, this));
            playerScore.setHistory(new ArrayList<Delta>());
        }
    }
    new AsyncTask<Void, Void, Void>() {

        @Override
        protected Void doInBackground(Void... params) {
            GameDBHelper dbHelper = null;
            try {
                dbHelper = new GameDBHelper(MainActivity.this);
                dbHelper.saveGame(newGame);
            } finally {
                if (dbHelper != null) {
                    dbHelper.close();
                }
            }
            return null;
        }

        @Override
        protected void onPostExecute(Void result) {
            super.onPostExecute(result);
            onNewGameCreated(newGame);
            ToastHelper.showShort(MainActivity.this, resetScores ? R.string.toast_rematch_created : R.string.toast_game_copied);
        }
    }.execute((Void) null);
}
Also used : Game(com.nolanlawson.keepscore.db.Game) Delta(com.nolanlawson.keepscore.db.Delta) GameDBHelper(com.nolanlawson.keepscore.db.GameDBHelper) PlayerScore(com.nolanlawson.keepscore.db.PlayerScore)

Example 8 with Delta

use of com.nolanlawson.keepscore.db.Delta in project KeepScore by nolanlawson.

the class HistoryItem method createFromPlayerScore.

/**
	 * Create a list of displayable history items given a PlayerScore.  Entries should be listed from past to future.
	 * @param playerScore
	 * @return
	 */
public static List<HistoryItem> createFromPlayerScore(PlayerScore playerScore, Context context) {
    List<Delta> history = playerScore.getHistory();
    long runningScore = getStartingScore(playerScore);
    List<HistoryItem> historyItems = new ArrayList<HistoryItem>();
    // add an initial one to just show the starting score
    historyItems.add(new HistoryItem(0, runningScore, true));
    for (Delta historyDelta : history) {
        runningScore += historyDelta.getValue();
        historyItems.add(new HistoryItem(historyDelta.getValue(), runningScore, false));
    }
    return historyItems;
}
Also used : Delta(com.nolanlawson.keepscore.db.Delta) ArrayList(java.util.ArrayList)

Example 9 with Delta

use of com.nolanlawson.keepscore.db.Delta 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();
}
Also used : Delta(com.nolanlawson.keepscore.db.Delta) PlayerScore(com.nolanlawson.keepscore.db.PlayerScore)

Example 10 with Delta

use of com.nolanlawson.keepscore.db.Delta in project KeepScore by nolanlawson.

the class PlayerView method updateViews.

public void updateViews() {
    log.d("updateViews()");
    long currentTime = System.currentTimeMillis();
    if (borderDrawable == null) {
        borderDrawable = context.getResources().getDrawable(borderDrawableResId);
    }
    view.setBackgroundDrawable(borderDrawable);
    CharSequence playerName = playerScore.toDisplayName(context);
    nameTextView.setText(playerName);
    playerColorView.setPlayerColor(playerScore.getPlayerColor());
    playerColorView.setVisibility(PreferenceHelper.getShowColors(context) ? View.VISIBLE : View.GONE);
    scoreTextView.setText(Long.toString(playerScore.getScore()));
    scoreTextView.resizeText();
    if (currentTime < (lastIncremented.get() + getUpdateDelayInMs()) && !playerScore.getHistory().isEmpty()) {
        log.d("showing badge");
        // still
        // modifiable
        // show badge (blibbet)
        makeBadgeVisible();
        Delta lastDelta = playerScore.getHistory().get(playerScore.getHistory().size() - 1);
        badgeTextView.setText(IntegerUtil.toCharSequenceWithSign(lastDelta.getValue()));
        badgeLinearLayout.setBackgroundResource(lastDelta.getValue() >= 0 ? getPositiveBadge() : R.drawable.badge_red_fade_out);
        // update history text view now rather than later
        setHistoryTextLazily(playerScore.getHistory(), currentTime);
    } else {
        log.d("hiding badge");
        // hide badge (blibbet)
        // update history text view later
        final Spannable newText = fromHistory(playerScore.getHistory(), currentTime);
        final Integer newHash = historyHash(playerScore.getHistory(), currentTime);
        Runnable updateHistoryRunnable = new Runnable() {

            @Override
            public void run() {
                historyTextView.setText(newText);
                historyTextView.setTag(newHash);
            }
        };
        fadeOutBadge(updateHistoryRunnable);
    }
    // set values for delta buttons
    if (this.showOnscreenDeltaButtons) {
        for (int i = 0; i < deltaButtons.length; i++) {
            Button button = deltaButtons[i];
            button.setText(IntegerUtil.toCharSequenceWithSign(PreferenceHelper.getTwoPlayerDeltaButtonValue(i, context)));
        }
    }
}
Also used : Delta(com.nolanlawson.keepscore.db.Delta) Button(android.widget.Button) Spannable(android.text.Spannable)

Aggregations

Delta (com.nolanlawson.keepscore.db.Delta)15 PlayerScore (com.nolanlawson.keepscore.db.PlayerScore)5 RecordedChange (com.nolanlawson.keepscore.data.RecordedChange)3 ArrayList (java.util.ArrayList)3 Spannable (android.text.Spannable)2 Game (com.nolanlawson.keepscore.db.Game)2 SpannableString (android.text.SpannableString)1 ForegroundColorSpan (android.text.style.ForegroundColorSpan)1 SparseArray (android.util.SparseArray)1 Button (android.widget.Button)1 GameDBHelper (com.nolanlawson.keepscore.db.GameDBHelper)1 LineChartLine (com.nolanlawson.keepscore.widget.chart.LineChartLine)1