Ejemplo n.º 1
0
  @Override
  public void onCreate() {
    LoginScreen.appendLog(TAG, "[SERVICE] onCreate");
    super.onCreate();

    // Load settings
    mSettings = PreferenceManager.getDefaultSharedPreferences(this);
    mPedometerSettings = new PedometerSettings(mSettings);
    mState = getSharedPreferences("state", 0);

    mUtils = Utils.getInstance();
    mUtils.setService(this);

    acquireWakeLock();

    // Start detecting
    mStepDetector = new StepDetector();
    mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
    registerDetector();

    // Register our receiver for the ACTION_SCREEN_OFF action. This will make our receiver
    // code be called whenever the phone enters standby mode.
    IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_OFF);
    registerReceiver(mReceiver, filter);

    mStepDisplayer = new StepDisplayer(mPedometerSettings, mUtils);
    mStepDisplayer.setSteps(mSteps = mState.getInt("steps", 0));
    mStepDisplayer.addListener(mStepListener);
    mStepDetector.addStepListener(mStepDisplayer);

    mPaceNotifier = new PaceNotifier(mPedometerSettings, mUtils);
    mPaceNotifier.setPace(mPace = mState.getInt("pace", 0));
    mPaceNotifier.addListener(mPaceListener);
    mStepDetector.addStepListener(mPaceNotifier);

    mDistanceNotifier = new DistanceNotifier(mDistanceListener, mPedometerSettings, mUtils);
    mDistanceNotifier.setDistance(mDistance = mState.getFloat("distance", 0));
    mStepDetector.addStepListener(mDistanceNotifier);

    mSpeedNotifier = new SpeedNotifier(mSpeedListener, mPedometerSettings, mUtils);
    mSpeedNotifier.setSpeed(mSpeed = mState.getFloat("speed", 0));
    mPaceNotifier.addListener(mSpeedNotifier);

    mCaloriesNotifier = new CaloriesNotifier(mCaloriesListener, mPedometerSettings, mUtils);
    mCaloriesNotifier.setCalories(mCalories = mState.getFloat("calories", 0));
    mStepDetector.addStepListener(mCaloriesNotifier);

    // Start voice
    reloadSettings();

    // Tell the user we started.
    // Toast.makeText(this, "we started pedometer service bruh", Toast.LENGTH_SHORT).show();
  }
Ejemplo n.º 2
0
 public void resetValues() {
   mStepDisplayer.setSteps(0);
   mPaceNotifier.setPace(0);
   mDistanceNotifier.setDistance(0);
   mSpeedNotifier.setSpeed(0);
   mCaloriesNotifier.setCalories(0);
 }
Ejemplo n.º 3
0
  public void reloadSettings() {
    mSettings = PreferenceManager.getDefaultSharedPreferences(this);

    if (mStepDetector != null) {
      mStepDetector.setSensitivity(Float.valueOf(mSettings.getString("sensitivity", "10")));
    }

    if (mStepDisplayer != null) mStepDisplayer.reloadSettings();
    if (mPaceNotifier != null) mPaceNotifier.reloadSettings();
    if (mDistanceNotifier != null) mDistanceNotifier.reloadSettings();
    if (mSpeedNotifier != null) mSpeedNotifier.reloadSettings();
    if (mCaloriesNotifier != null) mCaloriesNotifier.reloadSettings();
  }
Ejemplo n.º 4
0
 /**
  * Called by activity to pass the desired pace value, whenever it is modified by the user.
  *
  * @param desiredPace
  */
 public void setDesiredPace(int desiredPace) {
   mDesiredPace = desiredPace;
   if (mPaceNotifier != null) {
     mPaceNotifier.setDesiredPace(mDesiredPace);
   }
 }