Search in sources :

Example 1 with AccelerationData

use of org.andengine.input.sensor.acceleration.AccelerationData in project AndEngine by nicolasgramlich.

the class Engine method enableAccelerationSensor.

/**
	 * @return <code>true</code> when the sensor was successfully enabled, <code>false</code> otherwise.
	 */
public boolean enableAccelerationSensor(final Context pContext, final IAccelerationListener pAccelerationListener, final AccelerationSensorOptions pAccelerationSensorOptions) {
    final SensorManager sensorManager = (SensorManager) pContext.getSystemService(Context.SENSOR_SERVICE);
    if (Engine.isSensorSupported(sensorManager, Sensor.TYPE_ACCELEROMETER)) {
        this.mAccelerationListener = pAccelerationListener;
        if (this.mAccelerationData == null) {
            final Display display = ((WindowManager) pContext.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
            final int displayRotation = display.getOrientation();
            this.mAccelerationData = new AccelerationData(displayRotation);
        }
        this.registerSelfAsSensorListener(sensorManager, Sensor.TYPE_ACCELEROMETER, pAccelerationSensorOptions.getSensorDelay());
        return true;
    } else {
        return false;
    }
}
Also used : SensorManager(android.hardware.SensorManager) AccelerationData(org.andengine.input.sensor.acceleration.AccelerationData) Display(android.view.Display) WindowManager(android.view.WindowManager)

Aggregations

SensorManager (android.hardware.SensorManager)1 Display (android.view.Display)1 WindowManager (android.view.WindowManager)1 AccelerationData (org.andengine.input.sensor.acceleration.AccelerationData)1