diff --git a/OsmAnd-java/src/main/java/net/osmand/binary/BinaryMapIndexReader.java b/OsmAnd-java/src/main/java/net/osmand/binary/BinaryMapIndexReader.java index ce83e15956..e26f9de7f8 100644 --- a/OsmAnd-java/src/main/java/net/osmand/binary/BinaryMapIndexReader.java +++ b/OsmAnd-java/src/main/java/net/osmand/binary/BinaryMapIndexReader.java @@ -505,7 +505,7 @@ public class BinaryMapIndexReader { finishInit.add(transportRoute); } TIntObjectHashMap indexedStringTable = transportAdapter.initializeStringTable(ind, stringTable); - for(TransportRoute transportRoute : finishInit ) { + for (TransportRoute transportRoute : finishInit) { transportAdapter.initializeNames(false, transportRoute, indexedStringTable); } diff --git a/OsmAnd/src/net/osmand/plus/ApplicationMode.java b/OsmAnd/src/net/osmand/plus/ApplicationMode.java index 50fd1d78e5..17633b0720 100644 --- a/OsmAnd/src/net/osmand/plus/ApplicationMode.java +++ b/OsmAnd/src/net/osmand/plus/ApplicationMode.java @@ -65,9 +65,6 @@ public class ApplicationMode { private ApplicationMode parentAppMode; private int iconRes = R.drawable.ic_world_globe_dark; - private int minDistanceForTurn = 50; - private int offRouteDistance = 350; - private ApplicationMode(int key, String stringKey) { this.keyName = key; this.stringKey = stringKey; @@ -77,21 +74,18 @@ public class ApplicationMode { * DEFAULT("Browse map"), CAR("Car"), BICYCLE("Bicycle"), PEDESTRIAN("Pedestrian"); NAUTICAL("boat"); PUBLIC_TRANSPORT("Public transport"); AIRCRAFT("Aircraft") */ public static final ApplicationMode DEFAULT = createBase(R.string.app_mode_default, "default") - .distanceForTurn(5).offRouteDistance(350) .icon(R.drawable.ic_world_globe_dark).reg(); + public static final ApplicationMode CAR = createBase(R.string.app_mode_car, "car") - .distanceForTurn(35).offRouteDistance(350) .icon(R.drawable.ic_action_car_dark) .description(R.string.base_profile_descr_car).reg(); public static final ApplicationMode BICYCLE = createBase(R.string.app_mode_bicycle, "bicycle") - .distanceForTurn(15).offRouteDistance(50) .icon(R.drawable.ic_action_bicycle_dark) .description(R.string.base_profile_descr_bicycle).reg(); public static final ApplicationMode PEDESTRIAN = createBase(R.string.app_mode_pedestrian, "pedestrian") - .distanceForTurn(5).offRouteDistance(20) .icon(R.drawable.ic_action_pedestrian_dark) .description(R.string.base_profile_descr_pedestrian).reg(); @@ -100,17 +94,14 @@ public class ApplicationMode { .description(R.string.base_profile_descr_public_transport).reg(); public static final ApplicationMode BOAT = createBase(R.string.app_mode_boat, "boat") - .distanceForTurn(20) .icon(R.drawable.ic_action_sail_boat_dark) .description(R.string.base_profile_descr_boat).reg(); public static final ApplicationMode AIRCRAFT = createBase(R.string.app_mode_aircraft, "aircraft") - .distanceForTurn(100) .icon(R.drawable.ic_action_aircraft) .description(R.string.base_profile_descr_aircraft).reg(); public static final ApplicationMode SKI = createBase(R.string.app_mode_skiing, "ski") - .distanceForTurn(15).offRouteDistance(50) .icon(R.drawable.ic_action_skiing) .description(R.string.base_profile_descr_ski).reg(); @@ -313,8 +304,6 @@ public class ApplicationMode { public void setParentAppMode(ApplicationMode parentAppMode) { if (isCustomProfile()) { this.parentAppMode = parentAppMode; - minDistanceForTurn = parentAppMode.minDistanceForTurn; - offRouteDistance = parentAppMode.offRouteDistance; app.getSettings().PARENT_APP_MODE.setModeValue(this, parentAppMode.getStringKey()); } } @@ -367,12 +356,18 @@ public class ApplicationMode { } public int getMinDistanceForTurn() { - return minDistanceForTurn; + // used to be: 50 kmh - 35 m, 10 kmh - 15 m, 4 kmh - 5 m, 10 kmh - 20 m, 400 kmh - 100 m, + float speed = Math.max(getDefaultSpeed(), 0.3f); + // 2 sec + 7 m: 50 kmh - 35 m, 10 kmh - 12 m, 4 kmh - 9 m, 400 kmh - 230 m + return (int) (7 + speed * 2); } public int getOffRouteDistance() { - return offRouteDistance; + // used to be: 50/14 - 350 m, 10/2.7 - 50 m, 4/1.11 - 20 m + float speed = Math.max(getDefaultSpeed(), 0.3f); + // become: 50 kmh - 280 m, 10 kmh - 55 m, 4 kmh - 22 m + return (int) (speed * 20); } public boolean hasFastSpeed() { @@ -699,9 +694,6 @@ public class ApplicationMode { values.add(applicationMode); ApplicationMode parent = applicationMode.parentAppMode; - applicationMode.minDistanceForTurn = parent.minDistanceForTurn; - applicationMode.offRouteDistance = parent.offRouteDistance; - applicationMode.setParentAppMode(parent); applicationMode.setUserProfileName(userProfileName); applicationMode.setRouteService(routeService); @@ -730,16 +722,6 @@ public class ApplicationMode { return this; } - public ApplicationModeBuilder distanceForTurn(int distForTurn) { - applicationMode.minDistanceForTurn = distForTurn; - return this; - } - - public ApplicationModeBuilder offRouteDistance(int offRouteDistance) { - applicationMode.offRouteDistance = offRouteDistance; - return this; - } - public ApplicationModeBuilder setUserProfileName(String userProfileName) { this.userProfileName = userProfileName; return this; diff --git a/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java b/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java index a3ff26645a..385a31ec74 100644 --- a/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java +++ b/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java @@ -46,7 +46,9 @@ public class RoutingHelper { public static final float ALLOWED_DEVIATION = 2; // This should be correlated with RoutingHelper.updateCurrentRouteStatus ( when processed turn now is not announced) - public static int GPS_TOLERANCE = 12; + private static int DEFAULT_GPS_TOLERANCE = 12; + public static int GPS_TOLERANCE = DEFAULT_GPS_TOLERANCE; + public static float ARRIVAL_DISTANCE_FACTOR = 1; private List> listeners = new LinkedList<>(); private List> updateListeners = new LinkedList<>(); @@ -263,6 +265,8 @@ public class RoutingHelper { public void setAppMode(ApplicationMode mode){ this.mode = mode; + ARRIVAL_DISTANCE_FACTOR = Math.max(settings.ARRIVAL_DISTANCE_FACTOR.getModeValue(mode), 0.1f); + GPS_TOLERANCE = (int) (DEFAULT_GPS_TOLERANCE * ARRIVAL_DISTANCE_FACTOR); voiceRouter.updateAppMode(); } @@ -485,7 +489,7 @@ public class RoutingHelper { voiceRouter.interruptRouteCommands(); voiceRouterStopped = true; // Prevents excessive execution of stop() code } - if (distOrth > mode.getOffRouteDistance() && !settings.DISABLE_OFFROUTE_RECALC.get()) { + if (distOrth > mode.getOffRouteDistance() * ARRIVAL_DISTANCE_FACTOR && !settings.DISABLE_OFFROUTE_RECALC.get()) { voiceRouter.announceOffRoute(distOrth); } } @@ -583,8 +587,8 @@ public class RoutingHelper { } processed = true; } - } else if (newDist < dist || newDist < 10) { - // newDist < 10 (avoid distance 0 till next turn) + } else if (newDist < dist || newDist < GPS_TOLERANCE / 2) { + // newDist < GPS_TOLERANCE (avoid distance 0 till next turn) if (dist > posTolerance) { processed = true; if (log.isDebugEnabled()) { @@ -739,7 +743,7 @@ public class RoutingHelper { // return ((float)settings.getApplicationMode().getArrivalDistance()) * settings.ARRIVAL_DISTANCE_FACTOR.getModeValue(m); // GPS_TOLERANCE - 12 m // 5 seconds: car - 80 m @ 50 kmh, bicyle - 45 m @ 25 km/h, bicyle - 25 m @ 10 km/h, pedestrian - 18 m @ 4 km/h, - return (float) (GPS_TOLERANCE + defaultSpeed * 5) * settings.ARRIVAL_DISTANCE_FACTOR.getModeValue(m); + return GPS_TOLERANCE + defaultSpeed * 5 * ARRIVAL_DISTANCE_FACTOR; } diff --git a/OsmAnd/src/net/osmand/plus/routing/VoiceRouter.java b/OsmAnd/src/net/osmand/plus/routing/VoiceRouter.java index 3a1aa5cdd1..ebaa8a0baf 100644 --- a/OsmAnd/src/net/osmand/plus/routing/VoiceRouter.java +++ b/OsmAnd/src/net/osmand/plus/routing/VoiceRouter.java @@ -190,16 +190,15 @@ public class VoiceRouter { } // Turn now: 3.5 sec normal speed, 7 second for halfspeed (default) - float TURN_NOW_TIME = 7; + // float TURN_NOW_TIME = 7; // ** #8749 to keep 1m / 1 sec precision (GPS_TOLERANCE - 12 m) // 1 kmh - 1 m, 4 kmh - 4 m (pedestrian), 10 kmh - 10 m (bicycle), 50 kmh - 50 m (car) // TURN_NOW_DISTANCE = (int) (DEFAULT_SPEED * 3.6); // 3.6 sec // 50 kmh - 48 m (car), 10 kmh - 20 m, 4 kmh - 15 m, 1 kmh - 12 m - float factor = settings.ARRIVAL_DISTANCE_FACTOR.getModeValue(appMode); - TURN_NOW_DISTANCE = (int) ((RoutingHelper.GPS_TOLERANCE + DEFAULT_SPEED * 2.5) * factor); // 3.6 sec + TURN_NOW_DISTANCE = (int) (RoutingHelper.GPS_TOLERANCE + DEFAULT_SPEED * 2.5 * RoutingHelper.ARRIVAL_DISTANCE_FACTOR); // 3.6 sec // 1 kmh - 1 sec, 4 kmh - 2 sec (pedestrian), 10 kmh - 3 sec (*bicycle), 50 kmh - 7 sec (car) - TURN_NOW_TIME = (float) Math.min(Math.sqrt(DEFAULT_SPEED * 3.6), 8); + float TURN_NOW_TIME = (float) Math.min(Math.sqrt(DEFAULT_SPEED * 3.6), 8); TURN_NOW_SPEED = TURN_NOW_DISTANCE / TURN_NOW_TIME; }