You've already forked android_translation_layer
mirror of
https://gitlab.com/android_translation_layer/android_translation_layer.git
synced 2025-10-27 11:48:10 -07:00
api-impl: implement accelerometer support, no backend yet
currently x,y,z values are hardcoded and can only be changed with gdb
This commit is contained in:
@@ -4,8 +4,10 @@ public class SensorEvent {
|
||||
|
||||
public final float[] values;
|
||||
|
||||
public SensorEvent(float[] values) {
|
||||
public Sensor sensor;
|
||||
|
||||
public SensorEvent(float[] values, Sensor sensor) {
|
||||
this.values = values;
|
||||
this.sensor = sensor;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -17,16 +17,19 @@ public class SensorManager {
|
||||
return true; // we could try saying that the sensor doesn't exist and hope the app just doesn't use it then, but as long as we never call the handler the app should leave this alone
|
||||
}
|
||||
|
||||
public boolean registerListener(final SensorEventListener listener, Sensor sensor, int samplingPeriodUs) {
|
||||
public boolean registerListener(final SensorEventListener listener, final Sensor sensor, int samplingPeriodUs) {
|
||||
switch(sensor.getType()) {
|
||||
case Sensor.TYPE_ORIENTATION:
|
||||
new LocationManager().requestLocationUpdates(null, 0, 0, new LocationListener() {
|
||||
@Override
|
||||
public void onLocationChanged(Location location) {
|
||||
listener.onSensorChanged(new SensorEvent(new float[]{(float)location.getBearing()}));
|
||||
listener.onSensorChanged(new SensorEvent(new float[]{(float)location.getBearing()}, sensor));
|
||||
}
|
||||
});
|
||||
return true;
|
||||
case Sensor.TYPE_ACCELEROMETER:
|
||||
register_accelerometer_listener_native(listener, sensor);
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
@@ -35,4 +38,6 @@ public class SensorManager {
|
||||
public void unregisterListener(final SensorEventListener listener, Sensor sensor) {
|
||||
System.out.println("STUB: andoroid.hw.SensorManager.unregisterListener");
|
||||
}
|
||||
|
||||
native void register_accelerometer_listener_native(SensorEventListener listener, Sensor sensor);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user