Beispiel #1
0
  @Override
  protected void onResume() {
    super.onResume();

    firstfix = true;
    if (!data.isRunning()) {
      Gson gson = new Gson();
      String json = sharedPreferences.getString("data", "");
      data = gson.fromJson(json, Data.class);
    }
    if (data == null) {
      data = new Data(onGpsServiceUpdate);
    } else {
      data.setOnGpsServiceUpdate(onGpsServiceUpdate);
    }

    if (mLocationManager.getAllProviders().indexOf(LocationManager.GPS_PROVIDER) >= 0) {
      mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 500, 0, this);
    } else {
      Log.w(
          "MainActivity",
          "No GPS location provider found. GPS data display will not be available.");
    }

    if (!mLocationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
      showGpsDisabledDialog();
    }

    mLocationManager.addGpsStatusListener(this);
  }
Beispiel #2
0
  @Override
  public void onLocationChanged(Location location) {
    if (location.hasAccuracy()) {
      SpannableString s = new SpannableString(String.format("%.0f", location.getAccuracy()) + "m");
      s.setSpan(new RelativeSizeSpan(0.75f), s.length() - 1, s.length(), 0);
      accuracy.setText(s);

      if (firstfix) {
        status.setText("");
        fab.setVisibility(View.VISIBLE);
        if (!data.isRunning() && !maxSpeed.getText().equals("")) {
          refresh.setVisibility(View.VISIBLE);
        }
        firstfix = false;
      }
    } else {
      firstfix = true;
    }

    if (location.hasSpeed()) {
      progressBarCircularIndeterminate.setVisibility(View.GONE);
      SpannableString s =
          new SpannableString(String.format("%.0f", location.getSpeed() * 3.6) + "km/h");
      s.setSpan(new RelativeSizeSpan(0.25f), s.length() - 4, s.length(), 0);
      currentSpeed.setText(s);
    }
  }
Beispiel #3
0
 public void onFabClick(View v) {
   if (!data.isRunning()) {
     fab.setImageDrawable(getResources().getDrawable(R.drawable.ic_action_pause));
     data.setRunning(true);
     time.setBase(SystemClock.elapsedRealtime() - data.getTime());
     time.start();
     data.setFirstTime(true);
     startService(new Intent(getBaseContext(), GpsServices.class));
     refresh.setVisibility(View.INVISIBLE);
   } else {
     fab.setImageDrawable(getResources().getDrawable(R.drawable.ic_action_play));
     data.setRunning(false);
     status.setText("");
     stopService(new Intent(getBaseContext(), GpsServices.class));
     refresh.setVisibility(View.VISIBLE);
   }
 }