Merge pull request #4973 from osmandapp/PaulsBranch

Pauls branch
This commit is contained in:
Alexander Sytnyk 2018-02-01 16:16:14 +02:00 committed by GitHub
commit 8e104ba6f0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 60 additions and 5 deletions

View file

@ -1710,7 +1710,7 @@
<string name="poi_filter_for_tourists">For tourists</string>
<string name="poi_filter_fuel">Fuel</string>
<string name="show_warnings_title">Show alerts…</string>
<string name="show_warnings_descr">Configure traffic warnings (speed limits, forced stops, speed bumps), speed camera warnings, and lane information.</string>
<string name="show_warnings_descr">Configure traffic warnings (speed limits, forced stops, speed bumps, tunnels), speed camera warnings, and lane information.</string>
<string name="use_compass_navigation_descr">Use the compass when no heading is detected otherwise.</string>
<string name="use_compass_navigation">Use compass</string>
<string name="avoid_motorway">Avoid motorways</string>
@ -2867,4 +2867,6 @@
<string name="nautical_renderer">Nautical</string>
<string name="copy_location_name">Copy Point/POI name</string>
<string name="toast_empty_name_error">Location has no name</string>
<string name="tunnel_warning">Tunnel ahead</string>
<string name="show_tunnels">Tunnels</string>
</resources>

View file

@ -1070,6 +1070,12 @@ public class OsmandSettings {
SHOW_PEDESTRIAN.setModeDefaultValue(ApplicationMode.CAR, true);
}
public final CommonPreference<Boolean> SHOW_TUNNELS = new BooleanPreference("show_tunnels", false).makeProfile().cache();
{
SHOW_TUNNELS.setModeDefaultValue(ApplicationMode.CAR, true);
}
public final OsmandPreference<Boolean> SHOW_CAMERAS = new BooleanPreference("show_cameras", false).makeProfile().cache();
public final CommonPreference<Boolean> SHOW_LANES = new BooleanPreference("show_lanes", false).makeProfile().cache();

View file

@ -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),

View file

@ -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<LocationPointWrapper> 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<RouteSegmentResult> 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<RouteSegmentResult> 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:

View file

@ -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() {

View file

@ -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;
}