From 0534fda25c934564e611ddcbb6460d18e7b94744 Mon Sep 17 00:00:00 2001 From: MadWasp79 Date: Sat, 28 Dec 2019 16:12:37 +0200 Subject: [PATCH] get next shield --- .../plus/routing/RouteCalculationResult.java | 48 +++++-- .../plus/routing/RouteDirectionInfo.java | 2 +- .../osmand/plus/routing/RoutingHelper.java | 3 +- .../mapwidgets/MapInfoWidgetsFactory.java | 123 ++++++++++-------- 4 files changed, 110 insertions(+), 66 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/routing/RouteCalculationResult.java b/OsmAnd/src/net/osmand/plus/routing/RouteCalculationResult.java index 1ec6ef44cd..f53400282d 100644 --- a/OsmAnd/src/net/osmand/plus/routing/RouteCalculationResult.java +++ b/OsmAnd/src/net/osmand/plus/routing/RouteCalculationResult.java @@ -5,7 +5,6 @@ import android.support.annotation.Nullable; import net.osmand.Location; import net.osmand.PlatformUtil; -import net.osmand.binary.BinaryMapIndexReader; import net.osmand.binary.BinaryMapRouteReaderAdapter.RouteRegion; import net.osmand.binary.BinaryMapRouteReaderAdapter.RouteTypeRule; import net.osmand.binary.RouteDataObject; @@ -15,10 +14,7 @@ import net.osmand.data.QuadRect; import net.osmand.plus.ApplicationMode; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; -import net.osmand.plus.render.MapRenderRepositories; import net.osmand.plus.routing.AlarmInfo.AlarmInfoType; -import net.osmand.render.RenderingRuleSearchRequest; -import net.osmand.render.RenderingRulesStorage; import net.osmand.router.ExitInfo; import net.osmand.router.RouteSegmentResult; import net.osmand.router.RoutingContext; @@ -32,6 +28,8 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; +import gnu.trove.map.hash.TIntObjectHashMap; + import static net.osmand.binary.RouteDataObject.HEIGHT_UNDEFINED; public class RouteCalculationResult { @@ -335,17 +333,50 @@ public class RouteCalculationResult { ctx.getSettings().MAP_TRANSLITERATE_NAMES.get())); info.setDestinationName(next.getObject().getDestinationName(ctx.getSettings().MAP_PREFERRED_LOCALE.get(), ctx.getSettings().MAP_TRANSLITERATE_NAMES.get(), next.isForwardDirection())); - if (s.getObject().isExitPoint() && next.getObject().getHighway().equals("motorway_link")) { ExitInfo exitInfo = new ExitInfo(); exitInfo.setRef(next.getObject().getExitRef()); exitInfo.setExitStreetName(next.getObject().getExitName()); info.setExitInfo(exitInfo); } + + if (ref != null) { + RouteDataObject nextRoad = next.getObject(); + boolean isNextShieldFound = false; + int[] nextSegmentNameIds = nextRoad.nameIds; + for (int nm = 0; nm < nextSegmentNameIds.length; nm++) { + int nmId = nextSegmentNameIds[nm]; + if (nextRoad.region.quickGetEncodingRule(nextSegmentNameIds[nm]).getTag().startsWith("road_ref")) {// && nextSegmentNames.get(nmId).equals(ref)) { + info.setRouteDataObject(nextRoad); + isNextShieldFound = true; + } + } + + if (!isNextShieldFound) { + for (int ind = lind; ind < list.size(); ind++) { + if (list.get(ind).getTurnType() != null) { + info.setRouteDataObject(null); + break; + } else { + RouteDataObject obj = list.get(ind).getObject(); + int[] nameIds = obj.nameIds; + for (int idx = 0; idx < nameIds.length; idx ++) { + if (obj.region.routeEncodingRules.get(obj.nameIds[idx]).getTag().startsWith("road_ref")) { + info.setRouteDataObject(obj); + break; + } + } + if (info.getRouteDataObject() != null) { + break; + } + } + } + } + } } - String description = toString(turn, ctx, false) + " " + RoutingHelper.formatStreetName(info.getStreetName(), - info.getRef(), info.getDestinationName(), ctx.getString(R.string.towards)); + String description = toString(turn, ctx, false) + " " + RoutingHelper.formatStreetName(info.getStreetName(), + null, info.getDestinationName(), ctx.getString(R.string.towards)); description = description.trim(); String[] pointNames = s.getObject().getPointNames(s.getStartPointIndex()); if(pointNames != null) { @@ -362,7 +393,8 @@ public class RouteCalculationResult { prevDirectionDistance = 0; prevDirectionTime = 0; } - info.setRouteDataObject(s.getObject()); + + directions.add(info); } prevDirectionDistance += s.getDistance(); diff --git a/OsmAnd/src/net/osmand/plus/routing/RouteDirectionInfo.java b/OsmAnd/src/net/osmand/plus/routing/RouteDirectionInfo.java index b66e2fc865..9c503ccd82 100644 --- a/OsmAnd/src/net/osmand/plus/routing/RouteDirectionInfo.java +++ b/OsmAnd/src/net/osmand/plus/routing/RouteDirectionInfo.java @@ -26,7 +26,7 @@ public class RouteDirectionInfo { private String destinationName; - private RouteDataObject routeDataObject; + private RouteDataObject routeDataObject = null; @Nullable private ExitInfo exitInfo; diff --git a/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java b/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java index ad09f26e6d..0cfff0e39f 100644 --- a/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java +++ b/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java @@ -825,7 +825,8 @@ public class RoutingHelper { // return false; // } - public synchronized String getCurrentName(TurnType[] next, NextDirectionInfo n) { + public synchronized String getCurrentName(TurnType[] next){ + NextDirectionInfo n = getNextRouteDirectionInfo(new NextDirectionInfo(), true); Location l = lastFixedLocation; float speed = 0; if(l != null && l.hasSpeed()) { diff --git a/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapInfoWidgetsFactory.java b/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapInfoWidgetsFactory.java index d72615a97d..eabc9c558b 100644 --- a/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapInfoWidgetsFactory.java +++ b/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapInfoWidgetsFactory.java @@ -37,6 +37,7 @@ import com.jwetherell.openmap.common.UTMPoint; import net.osmand.AndroidUtils; import net.osmand.Location; import net.osmand.LocationConvert; +import net.osmand.PlatformUtil; import net.osmand.binary.BinaryMapRouteReaderAdapter; import net.osmand.binary.RouteDataObject; import net.osmand.data.LatLon; @@ -75,6 +76,8 @@ import net.osmand.router.TurnType; import net.osmand.util.Algorithms; import net.osmand.util.MapUtils; +import org.apache.commons.logging.Log; + import java.util.Iterator; import java.util.LinkedList; @@ -924,6 +927,7 @@ public class MapInfoWidgetsFactory { private TurnDrawable turnDrawable; private boolean showMarker; private int shadowRad; + private static final Log LOG = PlatformUtil.getLog(TopTextView.class); public TopTextView(OsmandApplication app, MapActivity map) { topBar = map.findViewById(R.id.map_top_bar); @@ -974,16 +978,14 @@ public class MapInfoWidgetsFactory { boolean showNextTurn = false; boolean showMarker = this.showMarker; boolean showExitInfo = false; + boolean showShield = false; ExitInfo exitInfo = null; - + RouteDataObject object = null; if (routingHelper != null && routingHelper.isRouteCalculated() && !routingHelper.isDeviatedFromRoute()) { if (routingHelper.isFollowingMode()) { - RouteCalculationResult.NextDirectionInfo nextDirInfo = routingHelper.getNextRouteDirectionInfo( - new RouteCalculationResult.NextDirectionInfo(), true); - if (settings.SHOW_STREET_NAME.get()) { - text = routingHelper.getCurrentName(type, nextDirInfo); + text = routingHelper.getCurrentName(type); if (text == null) { text = ""; } else { @@ -994,61 +996,43 @@ public class MapInfoWidgetsFactory { } } - if (nextDirInfo != null) { - RouteDirectionInfo directionInfo = nextDirInfo.directionInfo; + RouteCalculationResult.NextDirectionInfo nextDirInfo = routingHelper.getNextRouteDirectionInfo( + new RouteCalculationResult.NextDirectionInfo(), true); - if (directionInfo != null && directionInfo.getExitInfo() != null) { - exitInfo = directionInfo.getExitInfo(); - showExitInfo = true; - } else { - showExitInfo = false; - } - if (showExitInfo) { - text = exitInfo.getExitStreetName(); - } + RouteDirectionInfo directionInfo = nextDirInfo.directionInfo; + if (directionInfo != null && directionInfo.getExitInfo() != null) { + exitInfo = directionInfo.getExitInfo(); + showExitInfo = true; + } else { + showExitInfo = false; } - if (nextDirInfo != null && nextDirInfo.directionInfo.getRouteDataObject() != null) { - RouteDataObject object = nextDirInfo.directionInfo.getRouteDataObject(); - String nameTag = null; - String name = null; - StringBuilder additional = new StringBuilder(); - if (object != null) { - if (object.nameIds != null) { - for (int i = 0; i < object.nameIds.length; i++) { - String key = object.region.routeEncodingRules.get(object.nameIds[i]).getTag(); - String val = object.names.get(object.nameIds[i]); - if (key.equals("road_ref_1")) { - nameTag = key; - name = val; - } else { - additional.append(key).append("=").append(val).append(";"); - } - } - } - if (name != null && setRoadShield(shieldIcon, object, nameTag, name, additional)) { - AndroidUiHelper.updateVisibility(shieldIcon, true); - } else { - AndroidUiHelper.updateVisibility(shieldIcon, false); - } - } + if (showExitInfo) { + text = exitInfo.getExitStreetName(); + } + + + if (nextDirInfo.directionInfo.getRouteDataObject() != null) { + object = nextDirInfo.directionInfo.getRouteDataObject(); + showShield = true; } } - + } else { + int di = MapRouteInfoMenu.getDirectionInfo(); + if (di >= 0 && map.getMapRouteInfoMenu().isVisible() && + di < routingHelper.getRouteDirections().size()) { + showNextTurn = true; + RouteDirectionInfo next = routingHelper.getRouteDirections().get(di); + type[0] = next.getTurnType(); + turnDrawable.setColor(R.color.nav_arrow_distant); + text = RoutingHelper.formatStreetName(next.getStreetName(), null, next.getDestinationName(), "»"); + if (text == null) { + text = ""; + } } else { - int di = MapRouteInfoMenu.getDirectionInfo(); - if (di >= 0 && map.getMapRouteInfoMenu().isVisible() && - di < routingHelper.getRouteDirections().size()) { - showNextTurn = true; - RouteDirectionInfo next = routingHelper.getRouteDirections().get(di); - type[0] = next.getTurnType(); - turnDrawable.setColor(R.color.nav_arrow_distant); - text = RoutingHelper.formatStreetName(next.getStreetName(), null, next.getDestinationName(), "»"); - - } else { text = null; } } @@ -1060,11 +1044,10 @@ public class MapInfoWidgetsFactory { //ref = rt.getRef(settings.MAP_PREFERRED_LOCALE.get(), settings.MAP_TRANSLITERATE_NAMES.get(), rt.bearingVsRouteDirection(lastKnownLocation)); text = RoutingHelper.formatStreetName( rt.getName(settings.MAP_PREFERRED_LOCALE.get(), settings.MAP_TRANSLITERATE_NAMES.get()), - null, + rt.getRef(settings.MAP_PREFERRED_LOCALE.get(), settings.MAP_TRANSLITERATE_NAMES.get(), rt.bearingVsRouteDirection(lastKnownLocation)), rt.getDestinationName(settings.MAP_PREFERRED_LOCALE.get(), settings.MAP_TRANSLITERATE_NAMES.get(), rt.bearingVsRouteDirection(lastKnownLocation)), "»"); } - if (text == null) { text = ""; } else { @@ -1095,6 +1078,18 @@ public class MapInfoWidgetsFactory { AndroidUiHelper.updateVisibility(addressTextShadow, shadowRad > 0); boolean update = turnDrawable.setTurnType(type[0]) || showMarker != this.showMarker; this.showMarker = showMarker; + + if (showShield) { + + if (setRoadShield(shieldIcon, object)) { + AndroidUiHelper.updateVisibility(shieldIcon, true); + } else { + AndroidUiHelper.updateVisibility(shieldIcon, false); + } + } else { + AndroidUiHelper.updateVisibility(shieldIcon, false); + } + if (showExitInfo) { String exitRef = exitInfo.getRef(); if (!Algorithms.isEmpty(exitRef)) { @@ -1127,7 +1122,23 @@ public class MapInfoWidgetsFactory { return false; } - private boolean setRoadShield(ImageView view, RouteDataObject object, String nameTag, String name, StringBuilder additional) { + private boolean setRoadShield(ImageView view, RouteDataObject object) { + + String nameTag = null; + String name = null; + StringBuilder additional = new StringBuilder(); + for (int i = 0; i < object.nameIds.length; i++) { + String key = object.region.routeEncodingRules.get(object.nameIds[i]).getTag(); + String val = object.names.get(object.nameIds[i]); + if (key.startsWith("road_ref")) { + nameTag = key; + name = val; + } else { + additional.append(key).append("=").append(val).append(";"); + } + } + LOG.debug("Additionals (names): " + additional.toString() ); + Context context = topBar.getContext(); int[] tps = object.getTypes(); OsmandApplication app = ((OsmandApplication) context.getApplicationContext()); @@ -1138,8 +1149,8 @@ public class MapInfoWidgetsFactory { for (int i : tps) { BinaryMapRouteReaderAdapter.RouteTypeRule tp = object.region.quickGetEncodingRule(i); - if (tp.getTag().equals("highway")) { - rreq.setInitialTagValueZoom(tp.getTag(), tp.getValue(), 15, null); + if (tp.getTag().equals("highway") || tp.getTag().equals("route")) { + rreq.setInitialTagValueZoom(tp.getTag(), tp.getValue(), 13, null); } else { additional.append(tp.getTag()).append("=").append(tp.getValue()).append(";"); }