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
LocationManager: expose more information from the backend to the apps
note: GnssStatus was accidentally bundled into ab5b600bf1
This commit is contained in:
@@ -14,12 +14,13 @@ static void location_updated (
|
|||||||
gchar* description,
|
gchar* description,
|
||||||
gint64 timestamp_s,
|
gint64 timestamp_s,
|
||||||
gint64 timestamp_ms,
|
gint64 timestamp_ms,
|
||||||
JavaVM *jvm
|
JavaVM *jvm)
|
||||||
) {
|
{
|
||||||
JNIEnv *env;
|
JNIEnv *env;
|
||||||
(*jvm)->GetEnv(jvm, (void**)&env, JNI_VERSION_1_6);
|
(*jvm)->GetEnv(jvm, (void**)&env, JNI_VERSION_1_6);
|
||||||
jclass class = (*env)->FindClass(env, "android/location/LocationManager");
|
jclass class = (*env)->FindClass(env, "android/location/LocationManager");
|
||||||
(*env)->CallStaticVoidMethod(env, class, _STATIC_METHOD(class, "locationUpdated", "(DDD)V"), latitude, longitude, heading);
|
jlong timestamp = timestamp_s * 1000 + timestamp_ms;
|
||||||
|
(*env)->CallStaticVoidMethod(env, class, _STATIC_METHOD(class, "locationUpdated", "(DDDDDDJ)V"), latitude, longitude, altitude, accuracy, speed, heading, timestamp);
|
||||||
}
|
}
|
||||||
|
|
||||||
JNIEXPORT void JNICALL Java_android_location_LocationManager_nativeGetLocation(JNIEnv *env, jobject) {
|
JNIEXPORT void JNICALL Java_android_location_LocationManager_nativeGetLocation(JNIEnv *env, jobject) {
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ public class SensorManager {
|
|||||||
new LocationManager().requestLocationUpdates(null, 0, 0, new LocationListener() {
|
new LocationManager().requestLocationUpdates(null, 0, 0, new LocationListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onLocationChanged(Location location) {
|
public void onLocationChanged(Location location) {
|
||||||
listener.onSensorChanged(new SensorEvent(new float[]{(float)location.getBearing()}, sensor));
|
listener.onSensorChanged(new SensorEvent(new float[]{location.getBearing()}, sensor));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -4,12 +4,27 @@ public class Location {
|
|||||||
|
|
||||||
private double latitude;
|
private double latitude;
|
||||||
private double longitude;
|
private double longitude;
|
||||||
|
private double altitude;
|
||||||
|
private double accuracy;
|
||||||
|
private double speed;
|
||||||
private double bearing;
|
private double bearing;
|
||||||
|
private long timestamp;
|
||||||
|
|
||||||
public Location (double latitude, double longitude, double bearing) {
|
/* for internal use */
|
||||||
|
public Location (double latitude,
|
||||||
|
double longitude,
|
||||||
|
double altitude,
|
||||||
|
double accuracy,
|
||||||
|
double speed,
|
||||||
|
double bearing,
|
||||||
|
long timestamp) {
|
||||||
this.latitude = latitude;
|
this.latitude = latitude;
|
||||||
this.longitude = longitude;
|
this.longitude = longitude;
|
||||||
|
this.altitude = altitude;
|
||||||
|
this.accuracy = accuracy;
|
||||||
|
this.speed = speed;
|
||||||
this.bearing = bearing;
|
this.bearing = bearing;
|
||||||
|
this.timestamp = timestamp;
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getLatitude() {
|
public double getLatitude() {
|
||||||
@@ -20,8 +35,43 @@ public class Location {
|
|||||||
return longitude;
|
return longitude;
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getBearing() {
|
public boolean hasAltitude() {
|
||||||
return bearing;
|
return altitude != -Double.MAX_VALUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public double getAltitude() {
|
||||||
|
return altitude;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasAccuracy() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getAccuracy() {
|
||||||
|
return (float)accuracy;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasSpeed() {
|
||||||
|
return speed != -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getSpeed() {
|
||||||
|
return (float)speed;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasBearing() {
|
||||||
|
return bearing != -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getBearing() {
|
||||||
|
return (float)bearing;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getTime() {
|
||||||
|
return timestamp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getProvider() {
|
||||||
|
return "fused";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,10 @@
|
|||||||
package android.location;
|
package android.location;
|
||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.os.Handler;
|
||||||
|
import android.os.Looper;
|
||||||
|
|
||||||
|
import java.lang.Runnable;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -26,9 +29,15 @@ public class LocationManager {
|
|||||||
|
|
||||||
private native void nativeGetLocation();
|
private native void nativeGetLocation();
|
||||||
|
|
||||||
private static void locationUpdated(double latitude, double longitude, double heading) {
|
private static void locationUpdated(double latitude,
|
||||||
|
double longitude,
|
||||||
|
double altitude,
|
||||||
|
double accuracy,
|
||||||
|
double speed,
|
||||||
|
double bearing,
|
||||||
|
long timestamp) {
|
||||||
for (LocationListener locationListener : listeners) {
|
for (LocationListener locationListener : listeners) {
|
||||||
locationListener.onLocationChanged(new Location(latitude, longitude, heading));
|
locationListener.onLocationChanged(new Location(latitude, longitude, altitude, accuracy, speed, bearing, timestamp));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -42,4 +51,21 @@ public class LocationManager {
|
|||||||
public List<String> getAllProviders() {
|
public List<String> getAllProviders() {
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<String> getProviders(boolean enabledOnly) {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean registerGnssStatusCallback(GnssStatus.Callback callback, Handler handler) {
|
||||||
|
new Handler(Looper.getMainLooper()).post(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
callback.onSatelliteStatusChanged(new GnssStatus());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void unregisterGnssStatusCallback(GnssStatus.Callback callback) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -259,6 +259,7 @@ srcs = [
|
|||||||
'android/hardware/input/InputManager.java',
|
'android/hardware/input/InputManager.java',
|
||||||
'android/hardware/usb/UsbManager.java',
|
'android/hardware/usb/UsbManager.java',
|
||||||
'android/location/Criteria.java',
|
'android/location/Criteria.java',
|
||||||
|
'android/location/GnssStatus.java',
|
||||||
'android/location/Location.java',
|
'android/location/Location.java',
|
||||||
'android/location/LocationListener.java',
|
'android/location/LocationListener.java',
|
||||||
'android/location/LocationManager.java',
|
'android/location/LocationManager.java',
|
||||||
|
|||||||
Reference in New Issue
Block a user