Exemplo n.º 1
0
  public LocationModule(Context context) {
    mContext = context;
    mSettings = new SettingsManager(context);
    mSingleListeners = new ArrayList<SingleLocationListener>();
    mIsGpsHidden = mSettings.isGpsHidden();

    mScreenStateReceiver =
        new BroadcastReceiver() {
          @Override
          public void onReceive(Context context, Intent intent) {
            int state =
                intent.getIntExtra(
                    ScreenStateReceiver.SCREEN_STATE_EXTRA,
                    ScreenStateReceiver.SCREEN_STATE_UNKNOWN);

            switch (state) {
              case ScreenStateReceiver.SCREEN_STATE_OFF:
                startGpsListeners();
                break;
              case ScreenStateReceiver.SCREEN_STATE_ON:
                if (mIsGpsHidden) {
                  stopGpsListeners();
                }
                break;
              default:
                break;
            }
          }
        };

    sHandler = new MyHandler(this);

    PreferenceManager.getDefaultSharedPreferences(context)
        .registerOnSharedPreferenceChangeListener(this);
  }
Exemplo n.º 2
0
  @Override
  public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
    if (key.equals("USE_GPS")) {
      if (mSettings.isGpsTrackingEnabled()) {
        stopScheduledLocationUpdates();
        startScheduledLocationUpdates();
      } else {
        stopScheduledLocationUpdates();
      }
      return;
    }

    if (key.equals("GPS_TIMER") || key.equals("GPS_ONLY_NEW")) {
      stopScheduledLocationUpdates();

      if (mSettings.isGpsTrackingEnabled()) {
        startScheduledLocationUpdates();
      }
      return;
    }

    if (key.equals("GPS_HIDDEN")) {
      mIsGpsHidden = mSettings.isGpsHidden();
      if (mIsGpsHidden) {
        if (ScreenStateReceiver.getScreenState() != ScreenStateReceiver.SCREEN_STATE_OFF) {
          stopGpsListeners();
        }
      } else {
        startGpsListeners();
      }
      return;
    }
  }