示例#1
0
 @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;
   }
 }
示例#2
0
  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)));
      }
    }
  }