Exemplo n.º 1
0
 @Override
 public void onResume(Activity activity) {
   super.onResume(activity);
   if (significantMotionEnabled && significantMotionRegistered) {
     sensorManager.requestTriggerSensor(mTriggerEventListener, mSensor);
   }
 }
Exemplo n.º 2
0
 public void testRequestTriggerWithNonTriggerSensor() {
   Sensor sensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
   boolean result;
   if (sensor != null) {
     result = mSensorManager.requestTriggerSensor(mTriggerListener, sensor);
     assertFalse(result);
   }
 }
Exemplo n.º 3
0
  @Override
  public void eventListenerAdded(String type, int count, final KrollProxy proxy) {
    if (accelerometerEnabled && !accelerometerRegistered) {
      if (EVENT_UPDATE.equals(type)) {
        Log.i(LCAT, "registerListener for ACCELEROMETER:");
        accelerationFilter = new MeanFilter(); // Used for gyro cals
        accelerationFilter.setWindowSize(10); // Used for gyro cals
        TiSensorHelper.registerListener(
            Sensor.TYPE_ACCELEROMETER, this, SensorManager.SENSOR_DELAY_UI);
        // TiSensorHelper.registerListener(Sensor.TYPE_MAGNETIC_FIELD, this,
        // SensorManager.SENSOR_DELAY_UI);
        accelerometerRegistered = true;
      }
    }

    if (magneticFieldEnabled && !magneticFieldRegistered) {
      if (EVENT_UPDATE.equals(type)) {
        Log.i(LCAT, "registerListener for MAGNETIC_FIELD:");
        magneticFilter = new MeanFilter(); // Used for gyro cals
        magneticFilter.setWindowSize(10); // Used for gyro cals
        TiSensorHelper.registerListener(
            Sensor.TYPE_MAGNETIC_FIELD, this, SensorManager.SENSOR_DELAY_UI);
        magneticFieldRegistered = true;
      }
    }

    if (ambiantTemperatureEnabled && !ambiantTemperatureRegistered) {
      if (EVENT_UPDATE.equals(type)) {
        Log.i(LCAT, "registerListener for TYPE_AMBIENT_TEMPERATURE:");
        TiSensorHelper.registerListener(
            Sensor.TYPE_AMBIENT_TEMPERATURE, this, SensorManager.SENSOR_DELAY_UI);
        ambiantTemperatureRegistered = true;
      }
    }

    if (gameRotationVectorEnabled && !gameRotationVectorRegistered) {
      if (EVENT_UPDATE.equals(type)) {
        Log.i(LCAT, "registerListener for TYPE_GAME_ROTATION_VECTOR:");
        TiSensorHelper.registerListener(
            Sensor.TYPE_GAME_ROTATION_VECTOR, this, SensorManager.SENSOR_DELAY_UI);
        gameRotationVectorRegistered = true;
      }
    }

    if (geomagneticRotationVectorEnabled && !geomagneticRotationVectorRegistered) {
      if (EVENT_UPDATE.equals(type)) {
        Log.i(LCAT, "registerListener for TYPE_GEOMAGNETIC_ROTATION_VECTOR:");
        TiSensorHelper.registerListener(
            Sensor.TYPE_GEOMAGNETIC_ROTATION_VECTOR, this, SensorManager.SENSOR_DELAY_UI);
        geomagneticRotationVectorRegistered = true;
      }
    }

    if (gravityEnabled && !gravityRegistered) {
      if (EVENT_UPDATE.equals(type)) {
        Log.i(LCAT, "registerListener for TYPE_GRAVITY:");
        TiSensorHelper.registerListener(Sensor.TYPE_GRAVITY, this, SensorManager.SENSOR_DELAY_UI);
        gravityRegistered = true;
      }
    }

    if (gyroscopeEnabled && !gyroscopeRegistered) {
      if (EVENT_UPDATE.equals(type)) {
        Log.i(LCAT, "registerListener for TYPE_GYROSCOPE:");
        initGyroMaths();
        TiSensorHelper.registerListener(Sensor.TYPE_GYROSCOPE, this, SensorManager.SENSOR_DELAY_UI);
        gyroscopeRegistered = true;
      }
    }

    if (gyroscopeUncalibratedEnabled && !gyroscopeUncalibratedRegistered) {
      if (EVENT_UPDATE.equals(type)) {
        Log.i(LCAT, "registerListener for TYPE_GYROSCOPE_UNCALIBRATED:");
        TiSensorHelper.registerListener(
            Sensor.TYPE_GYROSCOPE_UNCALIBRATED, this, SensorManager.SENSOR_DELAY_UI);
        gyroscopeUncalibratedRegistered = true;
      }
    }

    /*if (heartRateEnabled && !heartRateRegistered) {
    	if (EVENT_UPDATE.equals(type)) {
    		Log.i(LCAT, "registerListener for TYPE_HEART_RATE:");
    		TiSensorHelper.registerListener(Sensor.TYPE_HEART_RATE, this, SensorManager.SENSOR_DELAY_UI);
    		heartRateRegistered = true;
    	}
    }*/

    if (lightEnabled && !lightRegistered) {
      if (EVENT_UPDATE.equals(type)) {
        Log.i(LCAT, "registerListener for TYPE_LIGHT:");
        TiSensorHelper.registerListener(Sensor.TYPE_LIGHT, this, SensorManager.SENSOR_DELAY_UI);
        lightRegistered = true;
      }
    }

    if (linearAccelerationEnabled && !linearAccelerationRegistered) {
      if (EVENT_UPDATE.equals(type)) {
        Log.i(LCAT, "registerListener for TYPE_LINEAR_ACCELERATION:");
        TiSensorHelper.registerListener(
            Sensor.TYPE_LINEAR_ACCELERATION, this, SensorManager.SENSOR_DELAY_UI);
        linearAccelerationRegistered = true;
      }
    }

    if (magneticFieldUncalibratedEnabled && !magneticFieldUncalibratedRegistered) {
      if (EVENT_UPDATE.equals(type)) {
        Log.i(LCAT, "registerListener for TYPE_MAGNETIC_FIELD_UNCALIBRATED:");
        TiSensorHelper.registerListener(
            Sensor.TYPE_MAGNETIC_FIELD_UNCALIBRATED, this, SensorManager.SENSOR_DELAY_UI);
        magneticFieldUncalibratedRegistered = true;
      }
    }

    if (orientationEnabled && !orientationRegistered) {
      if (EVENT_UPDATE.equals(type)) {
        Log.i(LCAT, "registerListener for TYPE_ORIENTATION:");
        TiSensorHelper.registerListener(
            Sensor.TYPE_ORIENTATION, this, SensorManager.SENSOR_DELAY_UI);
        orientationRegistered = true;
      }
    }

    if (pressureEnabled && !pressureRegistered) {
      if (EVENT_UPDATE.equals(type)) {
        Log.i(LCAT, "registerListener for TYPE_PRESSURE:");
        TiSensorHelper.registerListener(Sensor.TYPE_PRESSURE, this, SensorManager.SENSOR_DELAY_UI);
        pressureRegistered = true;
      }
    }

    if (proximityEnabled && !proximityRegistered) {
      if (EVENT_UPDATE.equals(type)) {
        Log.i(LCAT, "registerListener for TYPE_PROXIMITY:");
        TiSensorHelper.registerListener(Sensor.TYPE_PROXIMITY, this, SensorManager.SENSOR_DELAY_UI);
        proximityRegistered = true;
      }
    }

    if (relativeHumidityEnabled && !relativeHumidityRegistered) {
      if (EVENT_UPDATE.equals(type)) {
        Log.i(LCAT, "registerListener for TYPE_RELATIVE_HUMIDITY:");
        TiSensorHelper.registerListener(
            Sensor.TYPE_RELATIVE_HUMIDITY, this, SensorManager.SENSOR_DELAY_UI);
        relativeHumidityRegistered = true;
      }
    }

    if (rotationVectorEnabled && !rotationVectorRegistered) {
      if (EVENT_UPDATE.equals(type)) {
        Log.i(LCAT, "registerListener for TYPE_ROTATION_VECTOR:");
        TiSensorHelper.registerListener(
            Sensor.TYPE_ROTATION_VECTOR, this, SensorManager.SENSOR_DELAY_UI);
        rotationVectorRegistered = true;
      }
    }

    if (significantMotionEnabled && !significantMotionRegistered) {
      if (EVENT_UPDATE.equals(type)) {
        Log.i(LCAT, "registerListener for TYPE_SIGNIFICANT_MOTION:");
        mSensor = sensorManager.getDefaultSensor(Sensor.TYPE_SIGNIFICANT_MOTION);
        mTriggerEventListener =
            new TriggerEventListener() {
              @Override
              public void onTrigger(TriggerEvent event) {
                KrollDict data = new KrollDict();
                data.put("sType", Sensor.TYPE_SIGNIFICANT_MOTION);
                significantMotionValues = event.values.clone();
                data.put("motion", significantMotionValues[0]);
                fireEvent(EVENT_UPDATE, data);
                sensorManager.requestTriggerSensor(mTriggerEventListener, mSensor);
              }
            };
        sensorManager.requestTriggerSensor(mTriggerEventListener, mSensor);
        significantMotionRegistered = true;
      }
    }

    if (stepCounterEnabled && !stepCounterRegistered) {
      if (EVENT_UPDATE.equals(type)) {
        Log.i(LCAT, "registerListener for TYPE_STEP_COUNTER:");
        TiSensorHelper.registerListener(
            Sensor.TYPE_STEP_COUNTER, this, SensorManager.SENSOR_DELAY_FASTEST);
        stepCounterRegistered = true;
      }
    }

    if (stepDetectorEnabled && !stepDetectorRegistered) {
      if (EVENT_UPDATE.equals(type)) {
        Log.i(LCAT, "registerListener for TYPE_STEP_DETECTOR:");
        TiSensorHelper.registerListener(
            Sensor.TYPE_STEP_DETECTOR, this, SensorManager.SENSOR_DELAY_FASTEST);
        stepDetectorRegistered = true;
      }
    }
    super.eventListenerAdded(type, count, proxy);
  }