Fix Speed limit warning should use speed unit instead of distance unit #7430
This commit is contained in:
parent
fc45250199
commit
00625536b8
3 changed files with 25 additions and 17 deletions
|
@ -3272,21 +3272,25 @@ public class OsmandSettings {
|
|||
}
|
||||
|
||||
public enum SpeedConstants {
|
||||
KILOMETERS_PER_HOUR(R.string.km_h, R.string.si_kmh),
|
||||
MILES_PER_HOUR(R.string.mile_per_hour, R.string.si_mph),
|
||||
METERS_PER_SECOND(R.string.m_s, R.string.si_m_s),
|
||||
MINUTES_PER_MILE(R.string.min_mile, R.string.si_min_m),
|
||||
MINUTES_PER_KILOMETER(R.string.min_km, R.string.si_min_km),
|
||||
NAUTICALMILES_PER_HOUR(R.string.nm_h, R.string.si_nm_h);
|
||||
KILOMETERS_PER_HOUR(R.string.km_h, R.string.si_kmh, false),
|
||||
MILES_PER_HOUR(R.string.mile_per_hour, R.string.si_mph, true),
|
||||
METERS_PER_SECOND(R.string.m_s, R.string.si_m_s, false),
|
||||
MINUTES_PER_MILE(R.string.min_mile, R.string.si_min_m, true),
|
||||
MINUTES_PER_KILOMETER(R.string.min_km, R.string.si_min_km, false),
|
||||
NAUTICALMILES_PER_HOUR(R.string.nm_h, R.string.si_nm_h, true);
|
||||
|
||||
private final int key;
|
||||
private int descr;
|
||||
public final int key;
|
||||
public final int descr;
|
||||
public final boolean imperial;
|
||||
|
||||
SpeedConstants(int key, int descr) {
|
||||
SpeedConstants(int key, int descr, boolean imperial) {
|
||||
this.key = key;
|
||||
this.descr = descr;
|
||||
this.imperial = imperial;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public String toHumanString(Context ctx) {
|
||||
return ctx.getString(descr);
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@ import net.osmand.osm.PoiType;
|
|||
import net.osmand.plus.ApplicationMode;
|
||||
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;
|
||||
|
@ -169,11 +170,11 @@ public class WaypointHelper {
|
|||
return found;
|
||||
}
|
||||
|
||||
public AlarmInfo getMostImportantAlarm(MetricsConstants mc, boolean showCameras) {
|
||||
public AlarmInfo getMostImportantAlarm(MetricsConstants mc, OsmandSettings.SpeedConstants sc, boolean showCameras) {
|
||||
Location lastProjection = app.getRoutingHelper().getLastProjection();
|
||||
float mxspeed = route.getCurrentMaxSpeed();
|
||||
float delta = app.getSettings().SPEED_LIMIT_EXCEED.get() / 3.6f;
|
||||
AlarmInfo speedAlarm = createSpeedAlarm(mc, mxspeed, lastProjection, delta);
|
||||
AlarmInfo speedAlarm = createSpeedAlarm(mc, sc, mxspeed, lastProjection, delta);
|
||||
if (speedAlarm != null) {
|
||||
getVoiceRouter().announceSpeedAlarm(speedAlarm.getIntValue(), lastProjection.getSpeed());
|
||||
}
|
||||
|
@ -266,10 +267,11 @@ public class WaypointHelper {
|
|||
return true;
|
||||
}
|
||||
|
||||
public AlarmInfo calculateMostImportantAlarm(RouteDataObject ro, Location loc, MetricsConstants mc, boolean showCameras) {
|
||||
public AlarmInfo calculateMostImportantAlarm(RouteDataObject ro, Location loc, MetricsConstants mc,
|
||||
OsmandSettings.SpeedConstants sc, boolean showCameras) {
|
||||
float mxspeed = ro.getMaximumSpeed(ro.bearingVsRouteDirection(loc));
|
||||
float delta = app.getSettings().SPEED_LIMIT_EXCEED.get() / 3.6f;
|
||||
AlarmInfo speedAlarm = createSpeedAlarm(mc, mxspeed, loc, delta);
|
||||
AlarmInfo speedAlarm = createSpeedAlarm(mc, sc, mxspeed, loc, delta);
|
||||
if (speedAlarm != null) {
|
||||
getVoiceRouter().announceSpeedAlarm(speedAlarm.getIntValue(), loc.getSpeed());
|
||||
return speedAlarm;
|
||||
|
@ -306,12 +308,12 @@ public class WaypointHelper {
|
|||
return null;
|
||||
}
|
||||
|
||||
private static AlarmInfo createSpeedAlarm(MetricsConstants mc, float mxspeed, Location loc, float delta) {
|
||||
private static AlarmInfo createSpeedAlarm(MetricsConstants mc, OsmandSettings.SpeedConstants sc, float mxspeed, Location loc, float delta) {
|
||||
AlarmInfo speedAlarm = null;
|
||||
if (mxspeed != 0 && loc != null && loc.hasSpeed() && mxspeed != RouteDataObject.NONE_MAX_SPEED) {
|
||||
if (loc.getSpeed() > mxspeed + delta) {
|
||||
int speed;
|
||||
if (mc == MetricsConstants.KILOMETERS_AND_METERS) {
|
||||
if (sc.imperial) {
|
||||
speed = Math.round(mxspeed * 3.6f);
|
||||
} else {
|
||||
speed = Math.round(mxspeed * 3.6f / 1.6f);
|
||||
|
|
|
@ -1258,12 +1258,14 @@ public class RouteInfoWidgetsFactory {
|
|||
&& showRoutingAlarms && (trafficWarnings || cams)) {
|
||||
AlarmInfo alarm;
|
||||
if(rh.isFollowingMode() && !rh.isDeviatedFromRoute() && rh.getCurrentGPXRoute() == null) {
|
||||
alarm = wh.getMostImportantAlarm(settings.METRIC_SYSTEM.get(), cams);
|
||||
alarm = wh.getMostImportantAlarm(settings.METRIC_SYSTEM.get(),
|
||||
settings.SPEED_SYSTEM.get(), cams);
|
||||
} else {
|
||||
RouteDataObject ro = locationProvider.getLastKnownRouteSegment();
|
||||
Location loc = locationProvider.getLastKnownLocation();
|
||||
if(ro != null && loc != null) {
|
||||
alarm = wh.calculateMostImportantAlarm(ro, loc, settings.METRIC_SYSTEM.get(), cams);
|
||||
alarm = wh.calculateMostImportantAlarm(ro, loc, settings.METRIC_SYSTEM.get(),
|
||||
settings.SPEED_SYSTEM.get(), cams);
|
||||
} else {
|
||||
alarm = null;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue