From 3117c351d7d697822caf42d5388aac76ed3383e9 Mon Sep 17 00:00:00 2001 From: PaulStets Date: Thu, 1 Feb 2018 15:25:42 +0200 Subject: [PATCH 1/3] Added the tunnel warnings --- .../binary/BinaryMapRouteReaderAdapter.java | 3 +++ OsmAnd/res/values/strings.xml | 4 ++- .../src/net/osmand/plus/OsmandSettings.java | 6 +++++ .../SettingsNavigationActivity.java | 4 +-- .../osmand/plus/helpers/WaypointHelper.java | 27 ++++++++++++++++++- .../net/osmand/plus/routing/AlarmInfo.java | 12 ++++++++- .../mapwidgets/RouteInfoWidgetsFactory.java | 17 +++++++++++- 7 files changed, 67 insertions(+), 6 deletions(-) diff --git a/OsmAnd-java/src/net/osmand/binary/BinaryMapRouteReaderAdapter.java b/OsmAnd-java/src/net/osmand/binary/BinaryMapRouteReaderAdapter.java index f4c5323ec0..9f526d38e9 100644 --- a/OsmAnd-java/src/net/osmand/binary/BinaryMapRouteReaderAdapter.java +++ b/OsmAnd-java/src/net/osmand/binary/BinaryMapRouteReaderAdapter.java @@ -52,6 +52,7 @@ public class BinaryMapRouteReaderAdapter { public final static int TRAFFIC_SIGNALS = 6; public final static int RAILWAY_CROSSING = 7; private final static int LANES = 8; + private static final int TUNNEL = 9; private final String t; private final String v; private int intValue; @@ -201,6 +202,8 @@ public class BinaryMapRouteReaderAdapter { if (i > 0) { intValue = Integer.parseInt(v.substring(0, i)); } + } else if (t.equalsIgnoreCase("tunnel") && v != null) { + type = TUNNEL; } } } diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index a6bd3c28f5..d2e2266a17 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -1702,7 +1702,7 @@ For tourists Fuel Show alerts… - Configure traffic warnings (speed limits, forced stops, speed bumps), speed camera warnings, and lane information. + Configure traffic warnings (speed limits, forced stops, speed bumps, tunnels), speed camera warnings, and lane information. Use the compass when no heading is detected otherwise. Use compass Avoid motorways @@ -2859,4 +2859,6 @@ Nautical Copy Point/POI name Location has no name + Tunnel ahead + Tunnels diff --git a/OsmAnd/src/net/osmand/plus/OsmandSettings.java b/OsmAnd/src/net/osmand/plus/OsmandSettings.java index d72737873f..9b7c0012ae 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandSettings.java +++ b/OsmAnd/src/net/osmand/plus/OsmandSettings.java @@ -1070,6 +1070,12 @@ public class OsmandSettings { SHOW_PEDESTRIAN.setModeDefaultValue(ApplicationMode.CAR, true); } + public final CommonPreference SHOW_TUNNELS = new BooleanPreference("show_tunnels", false).makeProfile().cache(); + + { + SHOW_TUNNELS.setModeDefaultValue(ApplicationMode.CAR, true); + } + public final OsmandPreference SHOW_CAMERAS = new BooleanPreference("show_cameras", false).makeProfile().cache(); public final CommonPreference SHOW_LANES = new BooleanPreference("show_lanes", false).makeProfile().cache(); diff --git a/OsmAnd/src/net/osmand/plus/activities/SettingsNavigationActivity.java b/OsmAnd/src/net/osmand/plus/activities/SettingsNavigationActivity.java index 55c6ed23dd..f088cfb2fb 100644 --- a/OsmAnd/src/net/osmand/plus/activities/SettingsNavigationActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/SettingsNavigationActivity.java @@ -630,8 +630,8 @@ public class SettingsNavigationActivity extends SettingsBaseActivity { return true; } else if (preference == showAlarms) { showBooleanSettings(new String[] { getString(R.string.show_traffic_warnings), getString(R.string.show_pedestrian_warnings), - getString(R.string.show_cameras), getString(R.string.show_lanes) }, new OsmandPreference[] { settings.SHOW_TRAFFIC_WARNINGS, - settings.SHOW_PEDESTRIAN, settings.SHOW_CAMERAS, settings.SHOW_LANES }, preference.getTitle()); + getString(R.string.show_cameras), getString(R.string.show_lanes), getString(R.string.show_tunnels) }, new OsmandPreference[] { settings.SHOW_TRAFFIC_WARNINGS, + settings.SHOW_PEDESTRIAN, settings.SHOW_CAMERAS, settings.SHOW_LANES, settings.SHOW_TUNNELS }, preference.getTitle()); return true; } else if (preference == speakAlarms) { AlertDialog dlg = showBooleanSettings(new String[] { getString(R.string.speak_street_names), diff --git a/OsmAnd/src/net/osmand/plus/helpers/WaypointHelper.java b/OsmAnd/src/net/osmand/plus/helpers/WaypointHelper.java index 5d48eca0f0..958590af65 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/WaypointHelper.java +++ b/OsmAnd/src/net/osmand/plus/helpers/WaypointHelper.java @@ -16,6 +16,7 @@ import net.osmand.plus.ApplicationMode; import net.osmand.plus.IconsCache; import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.OsmandApplication; +import net.osmand.plus.OsmandSettings; import net.osmand.plus.OsmandSettings.MetricsConstants; import net.osmand.plus.R; import net.osmand.plus.TargetPointsHelper.TargetPoint; @@ -27,6 +28,7 @@ import net.osmand.plus.routing.AlarmInfo; import net.osmand.plus.routing.AlarmInfo.AlarmInfoType; import net.osmand.plus.routing.RouteCalculationResult; import net.osmand.plus.routing.VoiceRouter; +import net.osmand.router.RouteSegmentResult; import net.osmand.util.MapUtils; import java.util.ArrayList; @@ -178,6 +180,7 @@ public class WaypointHelper { } AlarmInfo mostImportant = speedAlarm; int value = speedAlarm != null ? speedAlarm.updateDistanceAndGetPriority(0, 0) : Integer.MAX_VALUE; + float speed = lastProjection != null && lastProjection.hasSpeed() ? lastProjection.getSpeed() : 0; if (ALARMS < pointsProgress.size()) { int kIterator = pointsProgress.get(ALARMS); List lp = locationPoints.get(ALARMS); @@ -191,7 +194,6 @@ public class WaypointHelper { break; } AlarmInfo inf = (AlarmInfo) lwp.point; - float speed = lastProjection != null && lastProjection.hasSpeed() ? lastProjection.getSpeed() : 0; float time = speed > 0 ? d / speed : Integer.MAX_VALUE; int vl = inf.updateDistanceAndGetPriority(time, d); if (vl < value && (showCameras || inf.getType() != AlarmInfoType.SPEED_CAMERA)) { @@ -202,9 +204,32 @@ public class WaypointHelper { kIterator++; } } + List segments = route.getUpcomingTunnel(500); + if (segments != null && !segments.isEmpty()) { + AlarmInfo inf = new AlarmInfo(AlarmInfoType.TUNNEL, 0); + int d = route.getDistanceToPoint(segments.get(0).getStartPointIndex()); + float time = speed > 0 ? d / speed : Integer.MAX_VALUE; + inf.setFloatValue(calculateDistance(segments, mc)); + int vl = inf.updateDistanceAndGetPriority(time, d); + if (vl < value && (showCameras || inf.getType() != AlarmInfoType.SPEED_CAMERA)) { + mostImportant = inf; + } + } return mostImportant; } + private float calculateDistance(List segments, MetricsConstants mc) { + float sum = 0f; + for (RouteSegmentResult r : segments) { + sum += r.getDistance(); + } + if (mc == MetricsConstants.KILOMETERS_AND_METERS) { + return sum / 1000f; + } else { + return sum * 0.00062137f; + } + } + public void enableWaypointType(int type, boolean enable) { //An item will be displayed in the Waypoint list if either "Show..." or "Announce..." is selected for it in the Navigation settings //Keep both "Show..." and "Announce..." Nav settings in sync when user changes what to display in the Waypoint list, as follows: diff --git a/OsmAnd/src/net/osmand/plus/routing/AlarmInfo.java b/OsmAnd/src/net/osmand/plus/routing/AlarmInfo.java index 912bf48824..bd3846c418 100644 --- a/OsmAnd/src/net/osmand/plus/routing/AlarmInfo.java +++ b/OsmAnd/src/net/osmand/plus/routing/AlarmInfo.java @@ -18,7 +18,8 @@ public class AlarmInfo implements LocationPoint { STOP(7, R.string.traffic_warning_stop), PEDESTRIAN(8, R.string.traffic_warning_pedestrian), HAZARD(9, R.string.traffic_warning_hazard), - MAXIMUM(10, R.string.traffic_warning); + MAXIMUM(10, R.string.traffic_warning), + TUNNEL(8, R.string.tunnel_warning); private int priority; private int string; @@ -41,6 +42,7 @@ public class AlarmInfo implements LocationPoint { private AlarmInfoType type; protected final int locationIndex; private int intValue; + private float floatValue; private double latitude; private double longitude; @@ -53,6 +55,14 @@ public class AlarmInfo implements LocationPoint { public AlarmInfoType getType() { return type; } + + public float getFloatValue() { + return floatValue; + } + + public void setFloatValue(float floatValue) { + this.floatValue = floatValue; + } @Override public double getLatitude() { diff --git a/OsmAnd/src/net/osmand/plus/views/mapwidgets/RouteInfoWidgetsFactory.java b/OsmAnd/src/net/osmand/plus/views/mapwidgets/RouteInfoWidgetsFactory.java index f2e4d0efa3..f750ffa8b2 100644 --- a/OsmAnd/src/net/osmand/plus/views/mapwidgets/RouteInfoWidgetsFactory.java +++ b/OsmAnd/src/net/osmand/plus/views/mapwidgets/RouteInfoWidgetsFactory.java @@ -17,6 +17,7 @@ import android.hardware.GeomagneticField; import android.os.BatteryManager; import android.support.annotation.NonNull; import android.text.format.DateFormat; +import android.util.Log; import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; @@ -55,6 +56,7 @@ import net.osmand.router.RouteResultPreparation; import net.osmand.router.TurnType; import net.osmand.util.Algorithms; +import java.text.DecimalFormat; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; @@ -1214,6 +1216,7 @@ public class RouteInfoWidgetsFactory { boolean trafficWarnings = settings.SHOW_TRAFFIC_WARNINGS.get(); boolean cams = settings.SHOW_CAMERAS.get(); boolean peds = settings.SHOW_PEDESTRIAN.get(); + boolean tunnels = settings.SHOW_TUNNELS.get(); boolean visible = false; if ((rh.isFollowingMode() || trackingUtilities.isMapLinkedToLocation()) && (trafficWarnings || cams)) { @@ -1271,6 +1274,15 @@ public class RouteInfoWidgetsFactory { } else { locimgId = R.drawable.warnings_pedestrian; } + } else if(alarm.getType() == AlarmInfoType.TUNNEL) { + DecimalFormat df = new DecimalFormat("0.#"); + if(settings.DRIVING_REGION.get().americanSigns){ + locimgId = R.drawable.warnings_tunnel_us; + text = df.format(alarm.getFloatValue()) +" mi"; + } else { + locimgId = R.drawable.warnings_tunnel; + text = df.format(alarm.getFloatValue()) +" km"; + } } else { text = null; } @@ -1280,7 +1292,10 @@ public class RouteInfoWidgetsFactory { visible = cams; } else if (alarm.getType() == AlarmInfoType.PEDESTRIAN) { visible = peds; - } else { + } else if (alarm.getType() == AlarmInfoType.TUNNEL) { + visible = tunnels; + } + else { visible = trafficWarnings; } } From c3a4ed09b3b952c7481550e91871041bbec382cc Mon Sep 17 00:00:00 2001 From: PaulStets Date: Thu, 1 Feb 2018 15:34:49 +0200 Subject: [PATCH 2/3] Small refactoring and cleaning --- .../src/net/osmand/binary/BinaryMapRouteReaderAdapter.java | 3 --- OsmAnd/src/net/osmand/plus/helpers/WaypointHelper.java | 1 - .../osmand/plus/views/mapwidgets/RouteInfoWidgetsFactory.java | 4 +--- 3 files changed, 1 insertion(+), 7 deletions(-) diff --git a/OsmAnd-java/src/net/osmand/binary/BinaryMapRouteReaderAdapter.java b/OsmAnd-java/src/net/osmand/binary/BinaryMapRouteReaderAdapter.java index 9f526d38e9..f4c5323ec0 100644 --- a/OsmAnd-java/src/net/osmand/binary/BinaryMapRouteReaderAdapter.java +++ b/OsmAnd-java/src/net/osmand/binary/BinaryMapRouteReaderAdapter.java @@ -52,7 +52,6 @@ public class BinaryMapRouteReaderAdapter { public final static int TRAFFIC_SIGNALS = 6; public final static int RAILWAY_CROSSING = 7; private final static int LANES = 8; - private static final int TUNNEL = 9; private final String t; private final String v; private int intValue; @@ -202,8 +201,6 @@ public class BinaryMapRouteReaderAdapter { if (i > 0) { intValue = Integer.parseInt(v.substring(0, i)); } - } else if (t.equalsIgnoreCase("tunnel") && v != null) { - type = TUNNEL; } } } diff --git a/OsmAnd/src/net/osmand/plus/helpers/WaypointHelper.java b/OsmAnd/src/net/osmand/plus/helpers/WaypointHelper.java index 958590af65..5dbe4db73f 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/WaypointHelper.java +++ b/OsmAnd/src/net/osmand/plus/helpers/WaypointHelper.java @@ -16,7 +16,6 @@ import net.osmand.plus.ApplicationMode; import net.osmand.plus.IconsCache; import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.OsmandApplication; -import net.osmand.plus.OsmandSettings; import net.osmand.plus.OsmandSettings.MetricsConstants; import net.osmand.plus.R; import net.osmand.plus.TargetPointsHelper.TargetPoint; diff --git a/OsmAnd/src/net/osmand/plus/views/mapwidgets/RouteInfoWidgetsFactory.java b/OsmAnd/src/net/osmand/plus/views/mapwidgets/RouteInfoWidgetsFactory.java index f750ffa8b2..c8278e2314 100644 --- a/OsmAnd/src/net/osmand/plus/views/mapwidgets/RouteInfoWidgetsFactory.java +++ b/OsmAnd/src/net/osmand/plus/views/mapwidgets/RouteInfoWidgetsFactory.java @@ -17,7 +17,6 @@ import android.hardware.GeomagneticField; import android.os.BatteryManager; import android.support.annotation.NonNull; import android.text.format.DateFormat; -import android.util.Log; import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; @@ -1294,8 +1293,7 @@ public class RouteInfoWidgetsFactory { visible = peds; } else if (alarm.getType() == AlarmInfoType.TUNNEL) { visible = tunnels; - } - else { + } else { visible = trafficWarnings; } } From db93a2f539d29f3ab72a38da0d99bbc32e4d64a7 Mon Sep 17 00:00:00 2001 From: PaulStets Date: Thu, 1 Feb 2018 15:55:21 +0200 Subject: [PATCH 3/3] Correct distance format --- .../osmand/plus/views/mapwidgets/RouteInfoWidgetsFactory.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OsmAnd/src/net/osmand/plus/views/mapwidgets/RouteInfoWidgetsFactory.java b/OsmAnd/src/net/osmand/plus/views/mapwidgets/RouteInfoWidgetsFactory.java index c8278e2314..253666f7bd 100644 --- a/OsmAnd/src/net/osmand/plus/views/mapwidgets/RouteInfoWidgetsFactory.java +++ b/OsmAnd/src/net/osmand/plus/views/mapwidgets/RouteInfoWidgetsFactory.java @@ -1274,7 +1274,7 @@ public class RouteInfoWidgetsFactory { locimgId = R.drawable.warnings_pedestrian; } } else if(alarm.getType() == AlarmInfoType.TUNNEL) { - DecimalFormat df = new DecimalFormat("0.#"); + DecimalFormat df = new DecimalFormat("#.#"); if(settings.DRIVING_REGION.get().americanSigns){ locimgId = R.drawable.warnings_tunnel_us; text = df.format(alarm.getFloatValue()) +" mi";