diff --git a/OsmAnd-java/src/main/java/net/osmand/binary/StringBundle.java b/OsmAnd-java/src/main/java/net/osmand/binary/StringBundle.java index ee156c5484..dd66cfc969 100644 --- a/OsmAnd-java/src/main/java/net/osmand/binary/StringBundle.java +++ b/OsmAnd-java/src/main/java/net/osmand/binary/StringBundle.java @@ -8,6 +8,7 @@ import java.util.Collections; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import java.util.Map.Entry; import gnu.trove.iterator.TIntObjectIterator; import gnu.trove.map.hash.TIntObjectHashMap; @@ -305,18 +306,6 @@ public class StringBundle { } } - public void putArray(String key, String[] array) { - if (array != null) { - map.put(key, new StringItem(key, strArrayToString(array))); - } - } - - public void putArray(String key, String[][] array) { - if (array != null) { - map.put(key, new StringItem(key, strStrArrayToString(array))); - } - } - public void putMap(String key, TIntObjectHashMap map) { if (map != null) { StringBundle bundle = newInstance(); @@ -334,7 +323,7 @@ public class StringBundle { public void putMap(String key, Map map) { if (map != null) { StringBundle bundle = newInstance(); - for (Map.Entry entry : map.entrySet()) { + for (Entry entry : map.entrySet()) { bundle.putString(String.valueOf(entry.getKey()), String.valueOf(entry.getValue())); } this.map.put(key, new StringBundleItem(key, bundle)); @@ -433,17 +422,6 @@ public class StringBundle { b.append(intArrayToString(arr)); } } - /* - for (int i = 0; i < a.length; i++) { - int[] value = a[i]; - if (value != null && value.length > 0) { - if (b.length() > 0) { - b.append(";"); - } - b.append(i).append(":").append(intArrayToString(value)); - } - } - */ return b.toString(); } @@ -465,48 +443,6 @@ public class StringBundle { } } } - /* - String[] items = a.split(";"); - int[][] res = new int[items.length][]; - for (int i = 0; i < items.length; i++) { - String[] subItems = a.split(","); - res[i] = new int[subItems.length]; - for (int k = 0; k < subItems.length; k++) { - res[i][k] = Integer.parseInt(subItems[k]); - } - } - */ return res; } - - private static String strArrayToString(String[] a) { - if (a == null) { - return null; - } - StringBuilder b = new StringBuilder(); - for (String value : a) { - if (b.length() > 0) { - b.append(0x1E); - } - b.append(value); - } - return b.toString(); - } - - private static String strStrArrayToString(String[][] a) { - if (a == null) { - return null; - } - StringBuilder b = new StringBuilder(); - for (int i = 0; i < a.length; i++) { - String[] value = a[i]; - if (value != null && value.length > 0) { - if (b.length() > 0) { - b.append(0x1F); - } - b.append(String.valueOf(i)).append(":").append(strArrayToString(value)); - } - } - return b.toString(); - } } diff --git a/OsmAnd-java/src/main/java/net/osmand/router/RouteDataResources.java b/OsmAnd-java/src/main/java/net/osmand/router/RouteDataResources.java index 634dd7219e..cb60c5ce33 100644 --- a/OsmAnd-java/src/main/java/net/osmand/router/RouteDataResources.java +++ b/OsmAnd-java/src/main/java/net/osmand/router/RouteDataResources.java @@ -2,8 +2,10 @@ package net.osmand.router; import net.osmand.Location; import net.osmand.binary.BinaryMapRouteReaderAdapter.RouteTypeRule; +import net.osmand.binary.RouteDataObject; import java.util.ArrayList; +import java.util.HashMap; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -14,6 +16,7 @@ public class RouteDataResources { private List locations; private int currentLocation; + private Map pointNamesMap = new HashMap<>(); public RouteDataResources() { this.locations = new ArrayList<>(); @@ -43,4 +46,8 @@ public class RouteDataResources { public void incrementCurrentLocation(int index) { currentLocation += index; } + + public Map getPointNamesMap() { + return pointNamesMap; + } } diff --git a/OsmAnd-java/src/main/java/net/osmand/router/RouteImporter.java b/OsmAnd-java/src/main/java/net/osmand/router/RouteImporter.java index c0f09e970d..db6e14a31f 100644 --- a/OsmAnd-java/src/main/java/net/osmand/router/RouteImporter.java +++ b/OsmAnd-java/src/main/java/net/osmand/router/RouteImporter.java @@ -114,7 +114,7 @@ public class RouteImporter { if (gpxFile != null) { GPXUtilities.loadGPXFile(null, gpxFile, extensionsReader); for (RouteSegmentResult segment : route) { - segment.fillData(); + segment.fillNames(resources); } } else if (file != null) { FileInputStream fis = null; @@ -122,7 +122,7 @@ public class RouteImporter { fis = new FileInputStream(file); GPXFile gpxFile = GPXUtilities.loadGPXFile(fis, null, extensionsReader); for (RouteSegmentResult segment : route) { - segment.fillData(); + segment.fillNames(resources); } gpxFile.path = file.getAbsolutePath(); gpxFile.modifiedTime = file.lastModified(); 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 18f0d9dfac..31d3397e97 100644 --- a/OsmAnd-java/src/main/java/net/osmand/router/RouteSegmentResult.java +++ b/OsmAnd-java/src/main/java/net/osmand/router/RouteSegmentResult.java @@ -87,6 +87,21 @@ public class RouteSegmentResult implements StringExternalizable } } } + if (object.pointNameTypes != null) { + int start = Math.min(startPointIndex, endPointIndex); + int end = Math.min(Math.max(startPointIndex, endPointIndex) + 1, object.pointNameTypes.length); + for (int i = start; i < end; i++) { + int[] types = object.pointNameTypes[i]; + if (types != null) { + for (int type : types) { + RouteTypeRule r = region.quickGetEncodingRule(type); + if (!rules.containsKey(r)) { + rules.put(r, rules.size()); + } + } + } + } + } } private void collectRules(Map rules, int[] types) { @@ -158,7 +173,34 @@ public class RouteSegmentResult implements StringExternalizable return res; } - public void fillData() { + private int[][] convertPointNames(int[][] nameTypes, Map rules) { + if (nameTypes == null || nameTypes.length == 0) { + return null; + } + int[][] res = new int[nameTypes.length][]; + for (int i = 0; i < nameTypes.length; i++) { + int[] types = nameTypes[i]; + if (types != null) { + int[] arr = new int[types.length]; + for (int k = 0; k < types.length; k++) { + int type = types[k]; + String tag = object.region.quickGetEncodingRule(type).getTag(); + String name = object.pointNames[i][k]; + RouteTypeRule rule = new RouteTypeRule(tag, name); + Integer ruleId = rules.get(rule); + if (ruleId == null) { + ruleId = rules.size(); + rules.put(rule, ruleId); + } + arr[k] = ruleId; + } + res[i] = arr; + } + } + return res; + } + + public void fillNames(RouteDataResources resources) { if (object.nameIds != null && object.nameIds.length > 0) { RouteRegion region = object.region; int nameTypeRule = region.getNameTypeRule(); @@ -176,6 +218,33 @@ public class RouteSegmentResult implements StringExternalizable } } } + String[][] pointNames = null; + int[][] pointNameTypes = null; + int[][] pointNamesArr = resources.getPointNamesMap().get(object); + if (pointNamesArr != null) { + pointNames = new String[pointNamesArr.length][]; + pointNameTypes = new int[pointNamesArr.length][]; + for (int i = 0; i < pointNamesArr.length; i++) { + int[] namesIds = pointNamesArr[i]; + if (namesIds != null) { + pointNames[i] = new String[namesIds.length]; + pointNameTypes[i] = new int[namesIds.length]; + for (int k = 0; k < namesIds.length; k++) { + int id = namesIds[k]; + RouteTypeRule r = object.region.quickGetEncodingRule(id); + if (r != null) { + pointNames[i][k] = r.getValue(); + int nameType = object.region.searchRouteEncodingRule(r.getTag(), null); + if (nameType != -1) { + pointNameTypes[i][k] = nameType; + } + } + } + } + } + } + object.pointNames = pointNames; + object.pointNameTypes = pointNameTypes; } @Override @@ -199,15 +268,22 @@ public class RouteSegmentResult implements StringExternalizable } bundle.putLong("id", object.id); bundle.putArray("types", convertTypes(object.types, rules)); + int start = Math.min(startPointIndex, endPointIndex); - int end = Math.max(startPointIndex, endPointIndex); - if (object.hasPointTypes()) { - bundle.putArray("pointTypes", convertTypes( - Arrays.copyOfRange(object.pointTypes, start, Math.min(end + 1, object.pointTypes.length)), rules)); + int end = Math.max(startPointIndex, endPointIndex) + 1; + if (object.pointTypes != null && start < object.pointTypes.length) { + int[][] types = Arrays.copyOfRange(object.pointTypes, start, Math.min(end, object.pointTypes.length)); + bundle.putArray("pointTypes", convertTypes(types, rules)); } - if (object.hasPointNames()) { + if (object.nameIds != null) { bundle.putArray("names", convertNameIds(object.nameIds, rules)); } + if (object.pointNameTypes != null && start < object.pointNameTypes.length) { + int[][] types = Arrays.copyOfRange(object.pointNameTypes, start, Math.min(end, object.pointNameTypes.length)); + if (object.pointNames != null) { + bundle.putArray("pointNames", convertPointNames(types, rules)); + } + } } @Override @@ -231,6 +307,10 @@ public class RouteSegmentResult implements StringExternalizable object.types = bundle.getIntArray("types", null); object.pointTypes = bundle.getIntIntArray("pointTypes", null); object.nameIds = bundle.getIntArray("names", null); + int[][] pointNames = bundle.getIntIntArray("pointNames", null); + if (pointNames != null) { + bundle.getResources().getPointNamesMap().put(object, pointNames); + } RouteDataResources resources = bundle.getResources(); object.pointsX = new int[length]; diff --git a/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java b/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java index 7ff55f74c5..351fc805a6 100644 --- a/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java +++ b/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java @@ -23,6 +23,7 @@ import net.osmand.plus.routing.RouteCalculationResult.NextDirectionInfo; import net.osmand.plus.routing.RouteProvider.GPXRouteParamsBuilder; import net.osmand.plus.routing.RouteProvider.RouteService; import net.osmand.router.RouteCalculationProgress; +import net.osmand.router.RouteExporter; import net.osmand.router.RouteSegmentResult; import net.osmand.router.TurnType; import net.osmand.util.Algorithms; @@ -245,7 +246,9 @@ public class RoutingHelper { return currentGPXRoute; } - + public boolean isCurrentGPXRouteV2() { + return currentGPXRoute != null && RouteExporter.OSMAND_ROUTER_V2.equals(currentGPXRoute.getFile().author); + } public void setGpxParams(GPXRouteParamsBuilder params) { currentGPXRoute = params; diff --git a/OsmAnd/src/net/osmand/plus/views/mapwidgets/RouteInfoWidgetsFactory.java b/OsmAnd/src/net/osmand/plus/views/mapwidgets/RouteInfoWidgetsFactory.java index ed1aea7c51..0cb329a88e 100644 --- a/OsmAnd/src/net/osmand/plus/views/mapwidgets/RouteInfoWidgetsFactory.java +++ b/OsmAnd/src/net/osmand/plus/views/mapwidgets/RouteInfoWidgetsFactory.java @@ -407,7 +407,7 @@ public class RouteInfoWidgetsFactory { @Override public boolean updateInfo(DrawSettings drawSettings) { float mx = 0; - if ((rh == null || !rh.isFollowingMode() || rh.isDeviatedFromRoute() || rh.getCurrentGPXRoute() != null) + if ((rh == null || !rh.isFollowingMode() || rh.isDeviatedFromRoute() || !rh.isCurrentGPXRouteV2()) && trackingUtilities.isMapLinkedToLocation()) { RouteDataObject ro = locationProvider.getLastKnownRouteSegment(); if(ro != null) { @@ -811,7 +811,7 @@ public class RouteInfoWidgetsFactory { int[] loclanes = null; int dist = 0; // TurnType primary = null; - if ((rh == null || !rh.isFollowingMode() || rh.isDeviatedFromRoute() || rh.getCurrentGPXRoute() != null) + if ((rh == null || !rh.isFollowingMode() || rh.isDeviatedFromRoute() || !rh.isCurrentGPXRouteV2()) && trackingUtilities.isMapLinkedToLocation() && settings.SHOW_LANES.get()) { RouteDataObject ro = locationProvider.getLastKnownRouteSegment(); Location lp = locationProvider.getLastKnownLocation(); @@ -1272,7 +1272,7 @@ public class RouteInfoWidgetsFactory { if ((rh.isFollowingMode() || trackingUtilities.isMapLinkedToLocation()) && showRoutingAlarms && (trafficWarnings || cams)) { AlarmInfo alarm; - if(rh.isFollowingMode() && !rh.isDeviatedFromRoute() && rh.getCurrentGPXRoute() == null) { + if(rh.isFollowingMode() && !rh.isDeviatedFromRoute() && (rh.getCurrentGPXRoute() == null || rh.isCurrentGPXRouteV2())) { alarm = wh.getMostImportantAlarm(settings.SPEED_SYSTEM.get(), cams); } else { RouteDataObject ro = locationProvider.getLastKnownRouteSegment();