From 5b14c7cde0310353981166de79f68d8037b7f646 Mon Sep 17 00:00:00 2001 From: Ivan Date: Fri, 29 Nov 2024 17:51:06 +0200 Subject: [PATCH] New widget (#21476) * New widget * Set voice navigation * Fix destination shields creating * Simplify * Formatting * Destination ref vs exit ref --- .../net/osmand/binary/RouteDataObject.java | 4 +- .../main/java/net/osmand/router/ExitInfo.java | 4 ++ .../osmand/router/RouteResultPreparation.java | 2 +- .../net/osmand/router/RouteSegmentResult.java | 12 +++--- .../main/java/net/osmand/util/Algorithms.java | 16 ++++++++ .../src/net/osmand/plus/auto/TripUtils.java | 27 +------------ .../plus/routing/CurrentStreetName.java | 20 +++++++++- .../net/osmand/plus/routing/RoadShield.java | 40 +++++++++++++++++++ .../plus/routing/RouteCalculationResult.java | 7 ++-- .../plus/routing/RouteDirectionInfo.java | 25 ++++++++++++ .../net/osmand/plus/routing/VoiceRouter.java | 4 +- 11 files changed, 121 insertions(+), 40 deletions(-) diff --git a/OsmAnd-java/src/main/java/net/osmand/binary/RouteDataObject.java b/OsmAnd-java/src/main/java/net/osmand/binary/RouteDataObject.java index 1d2b4475655..09597437dcd 100644 --- a/OsmAnd-java/src/main/java/net/osmand/binary/RouteDataObject.java +++ b/OsmAnd-java/src/main/java/net/osmand/binary/RouteDataObject.java @@ -328,7 +328,7 @@ public String getDestinationRef(String lang, boolean transliterate, boolean dire int k = kt[i]; if (region.routeEncodingRules.size() > k) { if (refTag.equals(region.routeEncodingRules.get(k).getTag())) { - return names.get(k); + return Algorithms.splitAndClearRepeats(names.get(k), ";"); } if (refTagDefault.equals(region.routeEncodingRules.get(k).getTag())) { refDefault = names.get(k); @@ -336,7 +336,7 @@ public String getDestinationRef(String lang, boolean transliterate, boolean dire } } if (refDefault != null) { - return refDefault; + return Algorithms.splitAndClearRepeats(refDefault, ";"); } //return names.get(region.refTypeRule); } diff --git a/OsmAnd-java/src/main/java/net/osmand/router/ExitInfo.java b/OsmAnd-java/src/main/java/net/osmand/router/ExitInfo.java index 3f51d0f9d0d..ca8e853f7bf 100644 --- a/OsmAnd-java/src/main/java/net/osmand/router/ExitInfo.java +++ b/OsmAnd-java/src/main/java/net/osmand/router/ExitInfo.java @@ -22,4 +22,8 @@ public String getExitStreetName() { public void setExitStreetName(String exitStreetName) { this.exitStreetName = exitStreetName; } + + public boolean isEmpty() { + return ref == null && exitStreetName == null; + } } diff --git a/OsmAnd-java/src/main/java/net/osmand/router/RouteResultPreparation.java b/OsmAnd-java/src/main/java/net/osmand/router/RouteResultPreparation.java index a04b9dd47f9..f5c9a9c299b 100644 --- a/OsmAnd-java/src/main/java/net/osmand/router/RouteResultPreparation.java +++ b/OsmAnd-java/src/main/java/net/osmand/router/RouteResultPreparation.java @@ -903,7 +903,7 @@ public void addTurnInfoDescriptions(List result) { if (!Algorithms.isEmpty(nm) || !Algorithms.isEmpty(ref)) { streetName = String.format("onto %s %s " , nm, ref); } - String to = result.get(prevSegment + 1).getDestinationName("", false, result, prevSegment + 1); + String to = result.get(prevSegment + 1).getDestinationName("", false, result, prevSegment + 1, true); if(!Algorithms.isEmpty(to)) { streetName = "to " + to; } diff --git a/OsmAnd-java/src/main/java/net/osmand/router/RouteSegmentResult.java b/OsmAnd-java/src/main/java/net/osmand/router/RouteSegmentResult.java index 3f296b204f2..0c5fa6ab8f9 100644 --- a/OsmAnd-java/src/main/java/net/osmand/router/RouteSegmentResult.java +++ b/OsmAnd-java/src/main/java/net/osmand/router/RouteSegmentResult.java @@ -652,7 +652,7 @@ public String toString() { return object.toString() + ": " + startPointIndex + "-" + endPointIndex; } - public String getDestinationName(String lang, boolean transliterate, List list, int routeInd) { + public String getDestinationName(String lang, boolean transliterate, List list, int routeInd, boolean withRef) { String dnRef = getObject().getDestinationRef(lang, transliterate, isForwardDirection()); String destinationName = getObject().getDestinationName(lang, transliterate, isForwardDirection()); if (Algorithms.isEmpty(destinationName)) { @@ -678,10 +678,12 @@ public String getDestinationName(String lang, boolean transliterate, List shields = new ArrayList<>(); public String exitRef; + private boolean useDestination = false; + public CurrentStreetName() { } @@ -32,6 +34,11 @@ public CurrentStreetName(@NonNull NextDirectionInfo info) { setupStreetName(info); } + public CurrentStreetName(@NonNull NextDirectionInfo info, boolean useDestination) { + this.useDestination = useDestination; + setupStreetName(info); + } + public CurrentStreetName(@NonNull RoutingHelper routingHelper, @NonNull NextDirectionInfo info) { setupCurrentName(routingHelper, info); } @@ -55,10 +62,12 @@ public void setupCurrentName(@NonNull RoutingHelper routingHelper, @NonNull Next boolean isSet = false; // 1. turn is imminent if (info.distanceTo > 0 && adt.isTurnStateActive(adt.getSpeed(l), info.distanceTo * 1.3, STATE_PREPARE_TURN)) { + useDestination = true; isSet = setupStreetName(info); } // 2. display current road street name if (!isSet) { + useDestination = false; RouteSegmentResult rs = routingHelper.getCurrentSegmentResult(); if (rs != null) { text = getRouteSegmentStreetName(routingHelper, rs, false); @@ -93,8 +102,15 @@ public boolean setupStreetName(@NonNull NextDirectionInfo info) { isSet = !(Algorithms.isEmpty(name) && Algorithms.isEmpty(ref) && Algorithms.isEmpty(destinationName)); RouteDataObject dataObject = info.directionInfo.getRouteDataObject(); - shields = RoadShield.create(dataObject); - text = RoutingHelperUtils.formatStreetName(name, ref, destinationName, "ยป", shields); + if (useDestination) { + shields = RoadShield.createDestination(dataObject, info.directionInfo); + } else { + shields = RoadShield.create(dataObject); + } + if (shields.isEmpty()) { + destinationName = info.directionInfo.getDestinationRefAndName(); + } + text = RoutingHelperUtils.formatStreetName(name, ref, destinationName, "", shields); turnType = info.directionInfo.getTurnType(); if (turnType == null) { turnType = TurnType.valueOf(TurnType.C, false); diff --git a/OsmAnd/src/net/osmand/plus/routing/RoadShield.java b/OsmAnd/src/net/osmand/plus/routing/RoadShield.java index ecb08421ad4..b793db0debb 100644 --- a/OsmAnd/src/net/osmand/plus/routing/RoadShield.java +++ b/OsmAnd/src/net/osmand/plus/routing/RoadShield.java @@ -4,9 +4,13 @@ import androidx.annotation.Nullable; import net.osmand.binary.RouteDataObject; +import net.osmand.util.Algorithms; import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Objects; public class RoadShield { @@ -45,6 +49,42 @@ public static List create(@Nullable RouteDataObject rdo) { return shields; } + @NonNull + public static List createDestination(@Nullable RouteDataObject rdo, RouteDirectionInfo info) { + List shields = create(rdo); + String destRef = info.getDestinationRef(); + if (rdo != null && !Algorithms.isEmpty(destRef) && !shields.isEmpty()) { + String refs = Algorithms.splitAndClearRepeats(destRef, ";"); + List split = Arrays.asList(refs.split(";")); + Map map = new HashMap<>(); + String tag = null; + StringBuilder additional = new StringBuilder(); + for (RoadShield s : shields) { + map.put(s.value, s); + if (split.contains(s.value)) { + tag = s.tag; + } + additional = s.additional; + } + + shields.clear(); + if (tag == null) { + return shields; + } + for (String s : split) { + RoadShield shield = map.get(s); + if (shield == null) { + shield = new RoadShield(rdo, tag, s); + shield.additional = additional; + } + shields.add(shield); + map.remove(s); + } + shields.addAll(map.values()); + } + return shields; + } + public RouteDataObject getRdo() { return rdo; } diff --git a/OsmAnd/src/net/osmand/plus/routing/RouteCalculationResult.java b/OsmAnd/src/net/osmand/plus/routing/RouteCalculationResult.java index 5b6cb4f75f9..6010670e6c3 100644 --- a/OsmAnd/src/net/osmand/plus/routing/RouteCalculationResult.java +++ b/OsmAnd/src/net/osmand/plus/routing/RouteCalculationResult.java @@ -449,7 +449,8 @@ private static List convertVectorResult(List convertVectorResult(List 0 && (exitInfo.getRef() != null || exitInfo.getExitStreetName() != null)) { + if (!exitInfo.isEmpty() && info.getDestinationRef() == null && routeInd > 0) { // set ref and road name (or shield icon) from previous segment because exit point is not consist of highway ref RouteSegmentResult previous; previous = list.get(routeInd - 1); @@ -492,7 +493,7 @@ private static List convertVectorResult(List