Ejemplo n.º 1
0
  protected void manageUpdateListener(boolean register, SensorEventListener listener) {
    if (register) {
      if (!listeningForUpdate) {
        sensorAttached = sensorHelper.attach(proxy.getTiContext().getActivity());

        if (sensorAttached) {

          LocationManager locationManager =
              (LocationManager)
                  proxy.getTiContext().getActivity().getSystemService(Context.LOCATION_SERVICE);

          Criteria criteria = new Criteria();
          String provider = locationManager.getBestProvider(criteria, true);
          if (provider != null) {
            Location location = locationManager.getLastKnownLocation(provider);
            if (location != null) {
              geomagneticField =
                  new GeomagneticField(
                      (float) location.getLatitude(),
                      (float) location.getLongitude(),
                      (float) location.getAltitude(),
                      System.currentTimeMillis());
            }
          }
          sensorHelper.registerListener(SENSORS, listener, SensorManager.SENSOR_DELAY_UI);
          listeningForUpdate = true;
        }
      }
    } else {
      if (listeningForUpdate) {
        sensorHelper.unregisterListener(SENSORS, listener);
        if (sensorHelper.isEmpty()) {
          listeningForUpdate = false;
          sensorHelper.detach();
        }
      }
    }
  }
Ejemplo n.º 2
0
  public void onResume() {

    if (proxy.getTiContext().hasEventListener(EVENT_HEADING, proxy)) {
      manageUpdateListener(true, updateListener);
    }
  }