diff --git a/project/java/Accelerometer.java b/project/java/Accelerometer.java index 3e93b82..9796355 100644 --- a/project/java/Accelerometer.java +++ b/project/java/Accelerometer.java @@ -45,6 +45,7 @@ class AccelerometerReader implements SensorEventListener public boolean openedBySDL = false; public static final GyroscopeListener gyro = new GyroscopeListener(); public static final OrientationListener orientation = new OrientationListener(); + public static final ProximityListener proximity = new ProximityListener(); public AccelerometerReader(Activity context) { @@ -59,6 +60,7 @@ class AccelerometerReader implements SensorEventListener _manager.unregisterListener(this); _manager.unregisterListener(gyro); _manager.unregisterListener(orientation); + _manager.unregisterListener(proximity); } } @@ -84,6 +86,11 @@ class AccelerometerReader implements SensorEventListener Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2 ? Sensor.TYPE_GAME_ROTATION_VECTOR : Sensor.TYPE_ROTATION_VECTOR), SensorManager.SENSOR_DELAY_GAME); } + if( _manager != null && _manager.getDefaultSensor(Sensor.TYPE_PROXIMITY) != null ) + { + Log.i("SDL", "libSDL: starting proximity sensor"); + _manager.registerListener(proximity, _manager.getDefaultSensor(Sensor.TYPE_PROXIMITY), SensorManager.SENSOR_DELAY_GAME); + } } public void onSensorChanged(SensorEvent event) @@ -168,7 +175,22 @@ class AccelerometerReader implements SensorEventListener } } + static class ProximityListener implements SensorEventListener + { + public ProximityListener() + { + } + public void onSensorChanged(SensorEvent event) + { + nativeProximity(event.values[0]); + } + public void onAccuracyChanged(Sensor s, int a) + { + } + } + private static native void nativeAccelerometer(float accX, float accY, float accZ); private static native void nativeGyroscope(float X, float Y, float Z); private static native void nativeOrientation(float X, float Y, float Z); + private static native void nativeProximity(float X); }