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
implement LocationManager and orientation sensor using libportal
This commit is contained in:
@@ -327,7 +327,8 @@ public final class Sensor {
|
||||
private int mFifoReservedEventCount;
|
||||
private int mFifoMaxEventCount;
|
||||
|
||||
Sensor() {
|
||||
Sensor(int type) {
|
||||
mType = type;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
11
src/api-impl/android/hardware/SensorEvent.java
Normal file
11
src/api-impl/android/hardware/SensorEvent.java
Normal file
@@ -0,0 +1,11 @@
|
||||
package android.hardware;
|
||||
|
||||
public class SensorEvent {
|
||||
|
||||
public final float[] values;
|
||||
|
||||
public SensorEvent(float[] values) {
|
||||
this.values = values;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,4 +1,6 @@
|
||||
package android.hardware;
|
||||
|
||||
public interface SensorEventListener {
|
||||
|
||||
public void onSensorChanged(SensorEvent event);
|
||||
}
|
||||
|
||||
@@ -1,13 +1,31 @@
|
||||
package android.hardware;
|
||||
|
||||
import android.location.Location;
|
||||
import android.location.LocationListener;
|
||||
import android.location.LocationManager;
|
||||
import android.os.Handler;
|
||||
|
||||
public class SensorManager {
|
||||
public Sensor getDefaultSensor(int type) {
|
||||
return null;
|
||||
return new Sensor(type);
|
||||
}
|
||||
|
||||
public boolean registerListener(SensorEventListener listener, Sensor sensor, int samplingPeriodUs, Handler handler) {
|
||||
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) {
|
||||
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()}));
|
||||
}
|
||||
});
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user