Beispiel #1
0
 @Override
 public void onRestoreInstanceState(Bundle savedInstanceState) {
   super.onRestoreInstanceState(savedInstanceState);
   if (savedInstanceState != null) {
     clock.setPlayer1Remaining(savedInstanceState.getLong(PLAYER_1_REMAINING, 25 * 60 * 1000));
     clock.setPlayer2Remaining(savedInstanceState.getLong(PLAYER_2_REMAINING, 25 * 60 * 1000));
   }
 }
Beispiel #2
0
  @Override
  public void onResume() {
    super.onResume();

    if (themeId
        != Integer.parseInt(
            prefs.getString(COLOR_THEME, Integer.toString(R.style.Bramblecriste)))) {
      reload();
    }

    config.initialTimePlayer1 = Long.parseLong(prefs.getString(PLAYER_1_INITIAL, INITIAL_DEFAULT));
    config.initialTimePlayer2 = Long.parseLong(prefs.getString(PLAYER_2_INITIAL, INITIAL_DEFAULT));
    clock.setPlayer1Remaining(prefs.getLong(PLAYER_1_REMAINING, config.initialTimePlayer1));
    clock.setPlayer2Remaining(prefs.getLong(PLAYER_2_REMAINING, config.initialTimePlayer2));
    handler.postDelayed(updateTimeDisplayTask, 10);
    player1Button.setEnabled(true);
    player2Button.setEnabled(true);
    vibrateOnPress = prefs.getBoolean(VIBRATE_ON_PRESS, false);
  }
Beispiel #3
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow()
        .setFlags(
            WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

    vibe = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);

    prefs = PreferenceManager.getDefaultSharedPreferences(this);
    config =
        new ClockConfig(
            Long.parseLong(prefs.getString(PLAYER_1_INITIAL, INITIAL_DEFAULT)),
            Long.parseLong(prefs.getString(PLAYER_2_INITIAL, INITIAL_DEFAULT)),
            Long.parseLong(prefs.getString(INCREMENT, INCREMENT_DEFAULT)));
    clock = new Clock(config);
    try {
      themeId =
          Integer.parseInt(prefs.getString(COLOR_THEME, Integer.toString(R.style.Bramblecriste)));
    } catch (NumberFormatException e) {
      themeId = R.style.Bramblecriste;
    }
    setTheme(themeId);

    vibrateOnPress = prefs.getBoolean(VIBRATE_ON_PRESS, false);

    if (savedInstanceState != null) {
      clock.setPlayer1Remaining(savedInstanceState.getLong(PLAYER_1_REMAINING));
      clock.setPlayer2Remaining(savedInstanceState.getLong(PLAYER_2_REMAINING));
    }

    setContentView(R.layout.activity_timer);

    player1Button = (Button) findViewById(R.id.playerabutton);
    player2Button = (Button) findViewById(R.id.playerbbutton);
    pauseButton = (ResetButton) findViewById(R.id.pausebutton);

    player1Button.setText(formatTime(clock.getPlayer1Remaining()));
    player2Button.setText(formatTime(clock.getPlayer2Remaining()));

    final TypedValue playerActiveColor = new TypedValue();
    getTheme().resolveAttribute(R.attr.player_active_color, playerActiveColor, true);
    final TypedValue playerDefaultColor = new TypedValue();
    getTheme().resolveAttribute(R.attr.player_default_color, playerDefaultColor, true);
    final TypedValue resetColor = new TypedValue();
    getTheme().resolveAttribute(R.attr.reset_color, resetColor, true);

    pauseButton.setResetColor(resetColor.data);
    player1Button.setOnTouchListener(
        new View.OnTouchListener() {
          @Override
          public boolean onTouch(View v, MotionEvent e) {
            if (e.getAction() == MotionEvent.ACTION_DOWN) {
              handler.removeCallbacks(updateTimeDisplayTask);
              handler.postDelayed(updateTimeDisplayTask, 20);
              pauseButton.clear();
              if (vibrateOnPress) vibe.vibrate(50);
              clock.startPlayer2();
              player2Button.setEnabled(true);
              player2Button.setBackgroundColor(playerActiveColor.data);
              player1Button.setEnabled(false);
              player1Button.setBackgroundColor(playerDefaultColor.data);
            }
            return true;
          }
        });
    player2Button.setOnTouchListener(
        new View.OnTouchListener() {
          @Override
          public boolean onTouch(View v, MotionEvent e) {
            if (e.getAction() == MotionEvent.ACTION_DOWN) {
              handler.removeCallbacks(updateTimeDisplayTask);
              handler.postDelayed(updateTimeDisplayTask, 20);
              pauseButton.clear();
              if (vibrateOnPress) vibe.vibrate(50);
              clock.startPlayer1();
              player2Button.setEnabled(false);
              player2Button.setBackgroundColor(playerDefaultColor.data);
              player1Button.setEnabled(true);
              player1Button.setBackgroundColor(playerActiveColor.data);
            }
            return true;
          }
        });
    pauseButton.setOnTouchListener(
        new View.OnTouchListener() {
          private Handler holdTimer = new Handler();
          private Runnable launchMenu =
              new Runnable() {
                @Override
                public void run() {
                  Timer.this.openOptionsMenu();
                  pauseButton.clear();
                }
              };

          @Override
          public boolean onTouch(View v, MotionEvent e) {
            if (e.getAction() == MotionEvent.ACTION_DOWN) {
              handler.removeCallbacks(updateTimeDisplayTask);

              if (vibrateOnPress) vibe.vibrate(50);

              clock.pause();

              player2Button.setEnabled(true);
              player2Button.setBackgroundColor(playerDefaultColor.data);
              player1Button.setEnabled(true);
              player1Button.setBackgroundColor(playerDefaultColor.data);

              if (pauseButton.increment()) {
                clock.reset();
              }

              holdTimer.postDelayed(launchMenu, 1500);
            } else if (e.getAction() == MotionEvent.ACTION_UP) {
              holdTimer.removeCallbacks(launchMenu);
            }

            updateTimeDisplay();

            return true;
          }
        });

    handler = new Handler();
  }