コード例 #1
0
  @Override
  protected void onPause() {
    Log.i(TAG, "[ACTIVITY] onPause");
    if (mIsRunning) {
      unbindStepService();
    }
    if (mQuitting) {
      mPedometerSettings.saveServiceRunningWithNullTimestamp(mIsRunning);
    } else {
      mPedometerSettings.saveServiceRunningWithTimestamp(mIsRunning);
    }

    super.onPause();
    // unregisterReceiver(br);
    Log.i(TAG, "Unregistered broacast receiver");
    savePaceSetting();
  }
コード例 #2
0
 private void savePaceSetting() {
   mPedometerSettings.savePaceOrSpeedSetting(mMaintain, mDesiredPaceOrSpeed);
 }
コード例 #3
0
  @Override
  protected void onResume() {
    super.onResume();
    // registerReceiver(br, new IntentFilter(Time.COUNTDOWN_BR));
    Log.i(TAG, "Registered broadcast receiver");
    mSensorManager.registerListener(this, mStepCounterSensor, SensorManager.SENSOR_DELAY_FASTEST);
    mSensorManager.registerListener(this, mStepDetectorSensor, SensorManager.SENSOR_DELAY_FASTEST);

    Log.i(TAG, "[ACTIVITY] onResume");
    super.onResume();

    mSettings = PreferenceManager.getDefaultSharedPreferences(this);
    mPedometerSettings = new PedometerSettings(mSettings);

    mPedometerUtils.setSpeak(mSettings.getBoolean("speak", false));

    // Read from preferences if the service was running on the last onPause
    mIsRunning = mPedometerSettings.isServiceRunning();

    // Start the service if this is considered to be an application start (last onPause was long
    // ago)
    if (!mIsRunning && mPedometerSettings.isNewStart()) {
      startStepService();
      bindStepService();
      Button p1_button = (Button) findViewById(R.id.button2);
      p1_button.setText("Start ►");
      // p1_button.setBackgroundResource(R.drawable.resume);
    } else if (mIsRunning) {
      bindStepService();
      Button p1_button = (Button) findViewById(R.id.button2);
      p1_button.setText("Stop ◼");
      // p1_button.setBackgroundResource(R.drawable.pause);
    }

    mPedometerSettings.clearServiceRunning();

    mStepValueView = (TextView) findViewById(R.id.step_value);
    mPaceValueView = (TextView) findViewById(R.id.pace_value);
    mDistanceValueView = (TextView) findViewById(R.id.distance_value);
    mSpeedValueView = (TextView) findViewById(R.id.speed_value);
    mCaloriesValueView = (TextView) findViewById(R.id.calories_value);
    mDesiredPaceView = (TextView) findViewById(R.id.desired_pace_value);
    mTimeValueView = (TextView) findViewById(R.id.textView);

    mIsMetric = mPedometerSettings.isMetric();
    ((TextView) findViewById(R.id.distance_units))
        .setText(getString(mIsMetric ? R.string.kilometers : R.string.miles));
    ((TextView) findViewById(R.id.speed_units))
        .setText(getString(mIsMetric ? R.string.kilometers_per_hour : R.string.miles_per_hour));

    mMaintain = mPedometerSettings.getMaintainOption();
    ((LinearLayout) this.findViewById(R.id.desired_pace_control))
        .setVisibility(mMaintain != PedometerSettings.M_NONE ? View.VISIBLE : View.INVISIBLE);
    if (mMaintain == PedometerSettings.M_PACE) {
      mMaintainInc = 5f;
      mDesiredPaceOrSpeed = (float) mPedometerSettings.getDesiredPace();
    } else if (mMaintain == PedometerSettings.M_SPEED) {
      mDesiredPaceOrSpeed = mPedometerSettings.getDesiredSpeed();
      mMaintainInc = 0.1f;
    }

    Button b1 = (Button) findViewById(R.id.button1);
    b1.setOnClickListener(
        new View.OnClickListener() {
          public void onClick(View v) {
            Intent intent = new Intent(PedomenterMainActivity.this, Settings.class);
            startActivity(intent);
          }
        });

    Button b2 = (Button) findViewById(R.id.button2);
    b2.setOnClickListener(
        new View.OnClickListener() {
          public void onClick(View v) {
            if (!mIsRunning) {

              startStepService();
              bindStepService();
              Button p1_button = (Button) findViewById(R.id.button2);
              p1_button.setText("Stop ◼");
              // p1_button.setBackgroundResource(R.drawable.resume);
            } else {

              unbindStepService();
              stopStepService();
              Button p1_button = (Button) findViewById(R.id.button2);
              p1_button.setText("Start ►");
              // p1_button.setBackgroundResource(R.drawable.pause);
            }
          }
        });

    Button b3 = (Button) findViewById(R.id.button3);
    b3.setOnClickListener(
        new View.OnClickListener() {
          public void onClick(View v) {
            resetValues(true);
            mTimeValueView.setText("00:00");
            getSharedPreferences("state", 0).edit().putLong("time", 0).commit();
          }
        });
    Button button1 = (Button) findViewById(R.id.button_desired_pace_lower);
    button1.setOnClickListener(
        new View.OnClickListener() {
          public void onClick(View v) {
            mDesiredPaceOrSpeed -= mMaintainInc;
            mDesiredPaceOrSpeed = Math.round(mDesiredPaceOrSpeed * 10) / 10f;
            displayDesiredPaceOrSpeed();
            setDesiredPaceOrSpeed(mDesiredPaceOrSpeed);
          }
        });
    Button button2 = (Button) findViewById(R.id.button_desired_pace_raise);
    button2.setOnClickListener(
        new View.OnClickListener() {
          public void onClick(View v) {
            mDesiredPaceOrSpeed += mMaintainInc;
            mDesiredPaceOrSpeed = Math.round(mDesiredPaceOrSpeed * 10) / 10f;
            displayDesiredPaceOrSpeed();
            setDesiredPaceOrSpeed(mDesiredPaceOrSpeed);
          }
        });
    if (mMaintain != PedometerSettings.M_NONE) {
      ((TextView) findViewById(R.id.desired_pace_label))
          .setText(
              mMaintain == PedometerSettings.M_PACE
                  ? R.string.desired_pace
                  : R.string.desired_speed);
    }
    displayDesiredPaceOrSpeed();
  }