diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml
index 228afb66a8..da7d276afb 100644
--- a/OsmAnd/res/values/strings.xml
+++ b/OsmAnd/res/values/strings.xml
@@ -1710,7 +1710,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
@@ -2867,4 +2867,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..5dbe4db73f 100644
--- a/OsmAnd/src/net/osmand/plus/helpers/WaypointHelper.java
+++ b/OsmAnd/src/net/osmand/plus/helpers/WaypointHelper.java
@@ -27,6 +27,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 +179,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 +193,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 +203,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..253666f7bd 100644
--- a/OsmAnd/src/net/osmand/plus/views/mapwidgets/RouteInfoWidgetsFactory.java
+++ b/OsmAnd/src/net/osmand/plus/views/mapwidgets/RouteInfoWidgetsFactory.java
@@ -55,6 +55,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 +1215,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 +1273,15 @@ public class RouteInfoWidgetsFactory {
} else {
locimgId = R.drawable.warnings_pedestrian;
}
+ } else if(alarm.getType() == AlarmInfoType.TUNNEL) {
+ DecimalFormat df = new DecimalFormat("#.#");
+ 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,6 +1291,8 @@ public class RouteInfoWidgetsFactory {
visible = cams;
} else if (alarm.getType() == AlarmInfoType.PEDESTRIAN) {
visible = peds;
+ } else if (alarm.getType() == AlarmInfoType.TUNNEL) {
+ visible = tunnels;
} else {
visible = trafficWarnings;
}