From 7b7e3fc6fe3b21dd509b46ba31e88a40802cb770 Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Wed, 5 Aug 2020 14:43:56 +0300 Subject: [PATCH] Add turnInfo for aidl --- .../osmand/aidlapi/info/AppInfoParams.java | 39 ++++++++++------ OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java | 46 +++++++++++++++++-- 2 files changed, 65 insertions(+), 20 deletions(-) diff --git a/OsmAnd-api/src/net/osmand/aidlapi/info/AppInfoParams.java b/OsmAnd-api/src/net/osmand/aidlapi/info/AppInfoParams.java index 13eb6f2292..8b6b2c236a 100644 --- a/OsmAnd-api/src/net/osmand/aidlapi/info/AppInfoParams.java +++ b/OsmAnd-api/src/net/osmand/aidlapi/info/AppInfoParams.java @@ -10,17 +10,20 @@ public class AppInfoParams extends AidlParams { private ALatLon lastKnownLocation; private ALatLon mapLocation; - private int time; - private long eta; + + private Bundle turnInfo; + private int leftTime; private int leftDistance; + private long arrivalTime; private boolean mapVisible; - public AppInfoParams(ALatLon lastKnownLocation, ALatLon mapLocation, int time, long eta, int leftDistance, boolean mapVisible) { + public AppInfoParams(ALatLon lastKnownLocation, ALatLon mapLocation, Bundle turnInfo, int leftTime, int leftDistance, long arrivalTime, boolean mapVisible) { this.lastKnownLocation = lastKnownLocation; this.mapLocation = mapLocation; - this.time = time; - this.eta = eta; + this.leftTime = leftTime; this.leftDistance = leftDistance; + this.arrivalTime = arrivalTime; + this.turnInfo = turnInfo; this.mapVisible = mapVisible; } @@ -48,12 +51,12 @@ public class AppInfoParams extends AidlParams { return mapLocation; } - public int getTime() { - return time; + public int getLeftTime() { + return leftTime; } - public long getEta() { - return eta; + public long getArrivalTime() { + return arrivalTime; } public int getLeftDistance() { @@ -64,23 +67,29 @@ public class AppInfoParams extends AidlParams { return mapVisible; } + public Bundle getTurnInfo() { + return turnInfo; + } + @Override public void writeToBundle(Bundle bundle) { - bundle.putParcelable("location", lastKnownLocation); + bundle.putParcelable("lastKnownLocation", lastKnownLocation); bundle.putParcelable("mapLocation", mapLocation); - bundle.putInt("time", time); - bundle.putLong("eta", eta); + bundle.putInt("leftTime", leftTime); + bundle.putLong("arrivalTime", arrivalTime); bundle.putInt("leftDistance", leftDistance); + bundle.putBundle("turnInfo", turnInfo); bundle.putBoolean("mapVisible", mapVisible); } @Override protected void readFromBundle(Bundle bundle) { - lastKnownLocation = bundle.getParcelable("location"); + lastKnownLocation = bundle.getParcelable("lastKnownLocation"); mapLocation = bundle.getParcelable("mapLocation"); - time = bundle.getInt("time"); - eta = bundle.getLong("eta"); + leftTime = bundle.getInt("leftTime"); + arrivalTime = bundle.getLong("arrivalTime"); leftDistance = bundle.getInt("leftDistance"); + turnInfo = bundle.getBundle("turnInfo"); mapVisible = bundle.getBoolean("mapVisible"); } } \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java b/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java index f36cbad0ea..5e606801ef 100644 --- a/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java +++ b/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java @@ -73,6 +73,7 @@ import net.osmand.plus.quickaction.QuickActionRegistry; import net.osmand.plus.rastermaps.OsmandRasterMapsPlugin; import net.osmand.plus.routing.IRoutingDataUpdateListener; import net.osmand.plus.routing.RouteCalculationResult.NextDirectionInfo; +import net.osmand.plus.routing.RouteDirectionInfo; import net.osmand.plus.routing.RoutingHelper; import net.osmand.plus.routing.VoiceRouter; import net.osmand.plus.settings.backend.ApplicationMode; @@ -103,6 +104,7 @@ import java.io.InputStream; import java.lang.ref.WeakReference; import java.lang.reflect.Type; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.HashMap; @@ -127,6 +129,11 @@ import static net.osmand.aidlapi.OsmandAidlConstants.COPY_FILE_PART_SIZE_LIMIT_E import static net.osmand.aidlapi.OsmandAidlConstants.COPY_FILE_UNSUPPORTED_FILE_TYPE_ERROR; import static net.osmand.aidlapi.OsmandAidlConstants.COPY_FILE_WRITE_LOCK_ERROR; import static net.osmand.aidlapi.OsmandAidlConstants.OK_RESPONSE; +import static net.osmand.plus.helpers.ExternalApiHelper.PARAM_NT_DIRECTION_LANES; +import static net.osmand.plus.helpers.ExternalApiHelper.PARAM_NT_DIRECTION_NAME; +import static net.osmand.plus.helpers.ExternalApiHelper.PARAM_NT_DIRECTION_TURN; +import static net.osmand.plus.helpers.ExternalApiHelper.PARAM_NT_DISTANCE; +import static net.osmand.plus.helpers.ExternalApiHelper.PARAM_NT_IMMINENT; public class OsmandAidlApi { @@ -1734,17 +1741,46 @@ public class OsmandAidlApi { mapVisible = mapActivity.isMapVisible(); } - int time = 0; - long eta = 0; + int leftTime = 0; + long arrivalTime = 0; int leftDistance = 0; + Bundle turnInfo = null; RoutingHelper routingHelper = app.getRoutingHelper(); if (routingHelper.isRouteCalculated()) { - time = routingHelper.getLeftTime(); - eta = time + System.currentTimeMillis() / 1000; + leftTime = routingHelper.getLeftTime(); + arrivalTime = leftTime + System.currentTimeMillis() / 1000; leftDistance = routingHelper.getLeftDistance(); + + NextDirectionInfo directionInfo = routingHelper.getNextRouteDirectionInfo(new NextDirectionInfo(), true); + turnInfo = new Bundle(); + if (directionInfo.distanceTo > 0) { + updateTurnInfo("next_", turnInfo, directionInfo); + directionInfo = routingHelper.getNextRouteDirectionInfoAfter(directionInfo, new NextDirectionInfo(), true); + if (directionInfo.distanceTo > 0) { + updateTurnInfo("after_next", turnInfo, directionInfo); + } + } + routingHelper.getNextRouteDirectionInfo(new NextDirectionInfo(), false); + if (directionInfo.distanceTo > 0) { + updateTurnInfo("no_speak_next_", turnInfo, directionInfo); + } + } + return new AppInfoParams(lastKnownLocation, mapLocation, turnInfo, leftTime, leftDistance, arrivalTime, mapVisible); + } + + private void updateTurnInfo(String prefix, Bundle bundle, NextDirectionInfo ni) { + bundle.putInt(prefix + PARAM_NT_DISTANCE, ni.distanceTo); + bundle.putInt(prefix + PARAM_NT_IMMINENT, ni.imminent); + if (ni.directionInfo != null && ni.directionInfo.getTurnType() != null) { + TurnType tt = ni.directionInfo.getTurnType(); + RouteDirectionInfo a = ni.directionInfo; + bundle.putString(prefix + PARAM_NT_DIRECTION_NAME, RoutingHelper.formatStreetName(a.getStreetName(), a.getRef(), a.getDestinationName(), "")); + bundle.putString(prefix + PARAM_NT_DIRECTION_TURN, tt.toXmlString()); + if (tt.getLanes() != null) { + bundle.putString(prefix + PARAM_NT_DIRECTION_LANES, Arrays.toString(tt.getLanes())); + } } - return new AppInfoParams(lastKnownLocation, mapLocation, time, eta, leftDistance, mapVisible); } boolean search(final String searchQuery, final int searchType, final double latitude, final double longitude,