1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-08-25 00:30:37 +02:00

Changed NavigationSpec's distance into a String.

Previously we used an integer (in meters) but when using
Google Maps navigation, Google Maps picks units based on locale *and*
the distance - it might report "100m" or "20km". Then we carefully undo
all that work, and for PineTime we just as "m" so you may well have "20000m"
or more displayed, which is not ideal.

I imagine at some point that will change, but we probably want to
be able to handle that in the OSMAnd side of Gadgetbridge so all watches
that implement navigation will benefit (and won't duplicate code).
This commit is contained in:
Gordon Williams 2023-06-12 12:20:43 +01:00 committed by José Rebelo
parent 5c3b76b838
commit b2aa61e182
5 changed files with 9 additions and 20 deletions

View File

@ -61,7 +61,7 @@ public class OsmandEventReceiver {
@Override
public void updateNavigationInfo(ADirectionInfo directionInfo) {
navigationInfoSpec.nextAction = directionInfo.getTurnType();
navigationInfoSpec.distanceToTurn = directionInfo.getDistanceTo();
navigationInfoSpec.distanceToTurn = directionInfo.getDistanceTo()+"m";
if (shouldSendNavigation()) {
GBApplication.deviceService().onSetNavigationInfo(navigationInfoSpec);

View File

@ -958,21 +958,8 @@ public class GoogleMapsNotificationHandler {
if (matchedIcon>=0)
navInfo.nextAction = matchedIcon;
navInfo.instruction = instruction;
if (distance != null) {
float distanceMultiplier = 1;
String distanceUnit = distance.replaceAll("[\\d.\\s]", "").toLowerCase();
if (distanceUnit.equals("m")) distanceMultiplier = 1;
else if (distanceUnit.equals("mi")) distanceMultiplier = 1609.34f;
else if (distanceUnit.equals("yd")) distanceMultiplier = 0.9144f;
else if (distanceUnit.equals("ft")) distanceMultiplier = 0.3048f;
else if (distanceUnit.equals("km")) distanceMultiplier = 1000;
else LOG.info("Unknown distance unit '"+distanceUnit+"'");
try {
navInfo.distanceToTurn = Math.round(distanceMultiplier * Float.parseFloat(distance.replaceAll("[^\\d.]", "")));
} catch (NumberFormatException e) {
LOG.info("Couldn't parse distance");
}
}
if (distance != null)
navInfo.distanceToTurn = distance;
if (navLines[2].contains("ETA"))
navInfo.ETA = navLines[2].replace("ETA","").trim();
GBApplication.deviceService().onSetNavigationInfo(navInfo);

View File

@ -37,7 +37,7 @@ public class NavigationInfoSpec {
// ETA? Total Distance?
public String instruction;
public int distanceToTurn; ///< Distance to turn (in metres?)
public String distanceToTurn; ///< Distance to turn (as a string, eg "100m")
public int nextAction; ///< One of the ACTION_ constants
public String ETA; ///< Estimated time of Arrival
}

View File

@ -890,7 +890,7 @@ public class DeviceCommunicationService extends Service implements SharedPrefere
NavigationInfoSpec navigationInfoSpec = new NavigationInfoSpec();
navigationInfoSpec.instruction = intent.getStringExtra(EXTRA_NAVIGATION_INSTRUCTION);
navigationInfoSpec.nextAction = intent.getIntExtra(EXTRA_NAVIGATION_NEXT_ACTION,0);
navigationInfoSpec.distanceToTurn = intent.getIntExtra(EXTRA_NAVIGATION_DISTANCE_TO_TURN,0);
navigationInfoSpec.distanceToTurn = intent.getStringExtra(EXTRA_NAVIGATION_DISTANCE_TO_TURN);
navigationInfoSpec.ETA = intent.getStringExtra(EXTRA_NAVIGATION_ETA);
deviceSupport.onSetNavigationInfo(navigationInfoSpec);
break;

View File

@ -326,9 +326,11 @@ public class PineTimeJFSupport extends AbstractBTLEDeviceSupport implements DfuL
if (navigationInfoSpec.instruction == null) {
navigationInfoSpec.instruction = "";
}
if (navigationInfoSpec.distanceToTurn == null) {
navigationInfoSpec.distanceToTurn = "";
}
safeWriteToCharacteristic(builder, PineTimeJFConstants.UUID_CHARACTERISTICS_NAVIGATION_NARRATIVE, navigationInfoSpec.instruction.getBytes(StandardCharsets.UTF_8));
safeWriteToCharacteristic(builder, PineTimeJFConstants.UUID_CHARACTERISTICS_NAVIGATION_MAN_DISTANCE, (navigationInfoSpec.distanceToTurn + "m").getBytes(StandardCharsets.UTF_8));
safeWriteToCharacteristic(builder, PineTimeJFConstants.UUID_CHARACTERISTICS_NAVIGATION_MAN_DISTANCE, navigationInfoSpec.distanceToTurn.getBytes(StandardCharsets.UTF_8));
String iconname;
switch (navigationInfoSpec.nextAction) {
case NavigationInfoSpec.ACTION_CONTINUE: