@Override public void onClick(View v) { switch (v.getId()) { case R.id.button_minus: increment(-1); break; case R.id.button_plus: increment(1); break; case R.id.text_name: case R.id.text_history: // do nothing - just let it flash the background, so that the user // knows this text view is long-clickable break; case android.R.id.button1: // 2p-mode button #1 increment(PreferenceHelper.getTwoPlayerDeltaButtonValue(0, context)); break; case android.R.id.button2: // 2p-mode button #2 increment(PreferenceHelper.getTwoPlayerDeltaButtonValue(1, context)); break; case android.R.id.button3: // 2p-mode button #3 increment(PreferenceHelper.getTwoPlayerDeltaButtonValue(2, context)); break; case R.id.button4: // 2p-mode button #4 increment(PreferenceHelper.getTwoPlayerDeltaButtonValue(3, context)); break; } }
private int getPositiveTextColor(ColorScheme colorScheme) { if (PreferenceHelper.getGreenTextPreference(context)) { return colorScheme.getGreenPositiveColorResId(); } else { return colorScheme.getPositiveColorResId(); } }
private int getPositiveBadge() { if (PreferenceHelper.getGreenTextPreference(context)) { return R.drawable.badge_green_fade_out; } else { return R.drawable.badge_blue_fade_out; } }
public void updateViews() { long currentTime = System.currentTimeMillis(); if (borderDrawable == null) { borderDrawable = context.getResources().getDrawable(borderDrawableResId); } view.setBackgroundDrawable(borderDrawable); String playerName = playerScore.toDisplayName(context); nameTextView.setText(playerName); scoreTextView.setText(Long.toString(playerScore.getScore())); if (currentTime < (lastIncremented.get() + getUpdateDelayInMs()) && !playerScore.getHistory().isEmpty()) { // still // modifiable // show badge (blibbet) makeBadgeVisible(); Integer lastDelta = playerScore.getHistory().get(playerScore.getHistory().size() - 1); badgeTextView.setText(IntegerUtil.toStringWithSign(lastDelta)); badgeLinearLayout.setBackgroundResource( lastDelta >= 0 ? getPositiveBadge() : R.drawable.badge_red_fade_out); // update history text view now rather than later setHistoryTextLazily(playerScore.getHistory(), currentTime); } else { // 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 (deltaButton1 != null) { Button[] deltaButtons = new Button[] {deltaButton1, deltaButton2, deltaButton3, deltaButton4}; for (int i = 0; i < deltaButtons.length; i++) { Button button = deltaButtons[i]; button.setOnClickListener(this); button.setText( IntegerUtil.toStringWithSign( PreferenceHelper.getTwoPlayerDeltaButtonValue(i, context))); } } }
public void reset(Context context) { synchronized (lock) { playerScore.setScore( PreferenceHelper.getIntPreference( R.string.pref_initial_score, R.string.pref_initial_score_default, context)); playerScore.setHistory(new ArrayList<Integer>()); } lastIncremented.set(0); shouldAutosave.set(true); updateViews(); }
private void init() { // enable or disable onscreen delta buttons based on whether we have // enough room onscreen or not deltaButtonsViewStub = view.findViewById(R.id.onscreen_delta_buttons_stub); int versionInt = VersionHelper.getVersionSdkIntCompat(); if (versionInt > VersionHelper.VERSION_DONUT && versionInt < VersionHelper.VERSION_FROYO) { // in eclair, there's a bug where ViewStubs within ViewSubs do not // render correctly, so inflate the ViewStubs no matter what if (deltaButtonsViewStub instanceof ViewStub) { deltaButtonsViewStub = ((ViewStub) deltaButtonsViewStub).inflate(); } } deltaButtonsViewStub.setVisibility(showOnscreenDeltaButtons ? View.VISIBLE : View.GONE); onscreenDeltaButtonsLayout = (LinearLayout) view.findViewById(R.id.onscreen_delta_buttons_table_layout); divider1 = view.findViewById(R.id.player_score_divider_1); divider2 = view.findViewById(R.id.player_score_divider_2); nameTextView = (TextView) view.findViewById(R.id.text_name); scoreTextView = (TextView) view.findViewById(R.id.text_score); historyTextView = (TextView) view.findViewById(R.id.text_history); badgeTextView = (TextView) view.findViewById(R.id.text_badge); badgeLinearLayout = (LinearLayout) view.findViewById(R.id.linear_layout_badge); minusButton = (Button) view.findViewById(R.id.button_minus); plusButton = (Button) view.findViewById(R.id.button_plus); deltaButton1 = (Button) view.findViewById(android.R.id.button1); deltaButton2 = (Button) view.findViewById(android.R.id.button2); deltaButton3 = (Button) view.findViewById(android.R.id.button3); deltaButton4 = (Button) view.findViewById(R.id.button4); minusButton.setOnClickListener(this); minusButton.setOnLongClickListener(this); plusButton.setOnClickListener(this); plusButton.setOnLongClickListener(this); nameTextView.setOnClickListener(this); nameTextView.setOnLongClickListener(this); historyTextView.setOnClickListener(this); historyTextView.setOnLongClickListener(this); ColorScheme colorScheme = PreferenceHelper.getColorScheme(context); setNewColorScheme(colorScheme); updateViews(); log.d("history is: %s", playerScore.getHistory()); }
private long getUpdateDelayInMs() { return PreferenceHelper.getUpdateDelay(context) * 1000L; }