Beispiel #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();
        }
      }
    }
  }
Beispiel #2
0
  @Override
  public Object get(String name, Scriptable start) {
    if (this.has(name, start)) {
      return super.get(name, start);
    }
    if (target instanceof TiProxy) {
      TiDict constants = ((TiProxy) target).getConstants();
      if (constants != null) {
        if (constants.containsKey(name)) {
          Object value = constants.get(name);
          super.putConst(name, start, value);
          return value;
        }
      }
    }

    if (DBG) {
      Log.d(LCAT, "get name: " + name);
    }
    Object o = NOT_FOUND;

    // If starts with Capital letter see if there is a module for it.
    if (name.matches("^[A-Z].*") || name.matches("iPhone")) {
      Object p = loadModule(name);
      if (p != null) {
        o = new KrollObject(this, p);
        put(name, this, o);
        ((TiModule) p).postCreate();
      }
    } else {
      if (DBG) {
        Log.d(LCAT, "Start: " + start.getClassName() + " looking for method:" + name);
      }
      o = handleMethodOrProperty(name, start, true, null);
    }

    return o;
  }
Beispiel #3
0
  public void onResume() {

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