mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-06-14 09:00:04 +02:00
44 lines
1.6 KiB
Java
44 lines
1.6 KiB
Java
package nodomain.freeyourgadget.gadgetbridge.service.devices.garmin;
|
|
|
|
import android.location.Location;
|
|
import android.os.Build;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.proto.vivomovehr.GdiCore;
|
|
|
|
public final class GarminUtils {
|
|
private GarminUtils() {
|
|
// utility class
|
|
}
|
|
|
|
public static int degreesToSemicircles(final double degrees) {
|
|
return (int) ((degrees * 2.147483648E9d) / 180.0d);
|
|
}
|
|
|
|
public static double semicirclesToDegrees(final long semicircles) {
|
|
return semicircles * (180.0D / 0x80000000);
|
|
}
|
|
|
|
public static GdiCore.CoreService.LocationData toLocationData(final Location location, final GdiCore.CoreService.DataType dataType) {
|
|
final GdiCore.CoreService.LatLon positionForWatch = GdiCore.CoreService.LatLon.newBuilder()
|
|
.setLat(degreesToSemicircles(location.getLatitude()))
|
|
.setLon(degreesToSemicircles(location.getLongitude()))
|
|
.build();
|
|
|
|
float vAccuracy = 0;
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
vAccuracy = location.getVerticalAccuracyMeters();
|
|
}
|
|
|
|
return GdiCore.CoreService.LocationData.newBuilder()
|
|
.setPosition(positionForWatch)
|
|
.setAltitude((float) location.getAltitude())
|
|
.setTimestamp(GarminTimeUtils.javaMillisToGarminTimestamp(location.getTime()))
|
|
.setHAccuracy(location.getAccuracy())
|
|
.setVAccuracy(vAccuracy)
|
|
.setPositionType(dataType)
|
|
.setBearing(location.getBearing())
|
|
.setSpeed(location.getSpeed())
|
|
.build();
|
|
}
|
|
}
|