@Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.main);
    mNavigationDrawerFragment =
        (NavigationDrawerFragment)
            getSupportFragmentManager().findFragmentById(R.id.navigation_drawer);
    mTitle = getTitle();

    // Set up the drawer.
    mNavigationDrawerFragment.setUp(
        R.id.navigation_drawer, (DrawerLayout) findViewById(R.id.drawer_layout));

    FragmentManager fragmentManager = getFragmentManager();
    // GlobalFeedFragment feedFragment = new GlobalFeedFragment();
    // fragmentManager.beginTransaction().replace(R.id.container, feedFragment).commit();

    mStepValue = 0;
    mPaceValue = 0;

    startService(new Intent(this, Time.class));
    Log.i(TAG, "Started service");

    try {
      if (!mIsRunning) {
        p1_button.setText("Start ►");
        // p1_button.setBackgroundResource(R.drawable.resume);
      } else if (mIsRunning) {
        p1_button.setText("Stop ◼");
        // p1_button.setBackgroundResource(R.drawable.pause);

      }
    } catch (NullPointerException e) {

    }

    mPedometerUtils = PedometerUtils.getInstance();

    RebootSteps = (TextView) findViewById(R.id.time);
    RS = (TextView) findViewById(R.id.textView8);

    PackageManager m = getPackageManager();
    if (!m.hasSystemFeature(PackageManager.FEATURE_SENSOR_STEP_COUNTER)) {
      RS.setVisibility(View.INVISIBLE);
      RebootSteps.setVisibility(View.INVISIBLE);
    }

    mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
    mStepCounterSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_STEP_COUNTER);
    mStepDetectorSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_STEP_DETECTOR);
  }
 @Override
 public void handleMessage(Message msg) {
   switch (msg.what) {
     case STEPS_MSG:
       mStepValue = (int) msg.arg1;
       mStepValueView.setText("" + mStepValue);
       break;
     case PACE_MSG:
       mPaceValue = msg.arg1;
       if (mPaceValue <= 0) {
         mPaceValueView.setText("0");
       } else {
         mPaceValueView.setText("" + (int) mPaceValue);
       }
       break;
     case DISTANCE_MSG:
       mDistanceValue = ((int) msg.arg1) / 1000f;
       if (mDistanceValue <= 0) {
         mDistanceValueView.setText("0");
       } else {
         mDistanceValueView.setText(("" + (mDistanceValue + 0.000001f)).substring(0, 5));
       }
       break;
     case SPEED_MSG:
       mSpeedValue = ((int) msg.arg1) / 1000f;
       if (mSpeedValue <= 0) {
         mSpeedValueView.setText("0");
       } else {
         mSpeedValueView.setText(("" + (mSpeedValue + 0.000001f)).substring(0, 4));
       }
       break;
     case CALORIES_MSG:
       mCaloriesValue = msg.arg1;
       if (mCaloriesValue <= 0) {
         mCaloriesValueView.setText("0");
       } else {
         mCaloriesValueView.setText("" + (int) mCaloriesValue);
       }
       break;
     case PedomenterMainActivity.TIME_MSG /*6*/:
       PedomenterMainActivity.this.mTimeValue = ((Long) msg.obj).longValue();
       PedomenterMainActivity.this.mTimeValueView.setText(
           PedometerUtils.formatTime(
               PedomenterMainActivity.this.mTimeValue
                   + PedomenterMainActivity.this
                       .getSharedPreferences("state", 0)
                       .getLong("time", 0)));
     default:
       super.handleMessage(msg);
   }
 }
  @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();
  }