Fix kmh / mph nav parameters

This commit is contained in:
max-klaus 2020-09-04 14:25:51 +03:00
parent 61b6e6077c
commit 81bf4ea094
6 changed files with 52 additions and 59 deletions

View file

@ -165,33 +165,34 @@ public class SettingsNavigationActivity extends SettingsBaseActivity {
registerListPreference(settings.ARRIVAL_DISTANCE_FACTOR, screen, arrivalNames, arrivalValues); registerListPreference(settings.ARRIVAL_DISTANCE_FACTOR, screen, arrivalNames, arrivalValues);
//array size must be equal!
Float[] speedLimitsKmh = new Float[]{-10f, -7f, -5f, 0f, 5f, 7f, 10f, 15f, 20f};
Float[] speedLimitsMph = new Float[]{-7f, -5f, -3f, 0f, 3f, 5f, 7f, 10f, 15f};
//array size must be equal!
Float[] speedLimitsKmhPos = new Float[]{0f, 5f, 7f, 10f, 15f, 20f};
Float[] speedLimitsMphPos = new Float[]{0f, 3f, 5f, 7f, 10f, 15f};
if (settings.METRIC_SYSTEM.get() == OsmandSettings.MetricsConstants.KILOMETERS_AND_METERS) { if (settings.METRIC_SYSTEM.get() == OsmandSettings.MetricsConstants.KILOMETERS_AND_METERS) {
Float[] speedLimitsKm = new Float[]{-10f, -7f, -5f, 0f, 5f, 7f, 10f, 15f, 20f}; String[] speedNames = new String[speedLimitsKmh.length];
Float[] speedLimitsKmPos = new Float[]{0f, 5f, 7f, 10f, 15f, 20f}; String[] speedNamesPos = new String[speedLimitsKmhPos.length];
String[] speedNames = new String[speedLimitsKm.length]; for (int i = 0; i < speedLimitsKmh.length; i++) {
String[] speedNamesPos = new String[speedLimitsKmPos.length]; speedNames[i] = speedLimitsKmh[i].intValue() + " " + getString(R.string.km_h);
for (int i = 0; i < speedLimitsKm.length; i++) {
speedNames[i] = speedLimitsKm[i].intValue() + " " + getString(R.string.km_h);
} }
for (int i = 0; i < speedLimitsKmPos.length; i++) { for (int i = 0; i < speedLimitsKmhPos.length; i++) {
speedNamesPos[i] = speedLimitsKmPos[i].intValue() + " " + getString(R.string.km_h); speedNamesPos[i] = speedLimitsKmhPos[i].intValue() + " " + getString(R.string.km_h);
} }
registerListPreference(settings.SPEED_LIMIT_EXCEED, screen, speedNames, speedLimitsKm); registerListPreference(settings.SPEED_LIMIT_EXCEED_KMH, screen, speedNames, speedLimitsKmh);
registerListPreference(settings.SWITCH_MAP_DIRECTION_TO_COMPASS, screen, speedNamesPos, speedLimitsKmPos); registerListPreference(settings.SWITCH_MAP_DIRECTION_TO_COMPASS_KMH, screen, speedNamesPos, speedLimitsKmhPos);
} else { } else {
Float[] speedLimitsMiles = new Float[]{-7f, -5f, -3f, 0f, 3f, 5f, 7f, 10f, 15f}; String[] speedNames = new String[speedLimitsMph.length];
Float[] speedLimitsMilesPos = new Float[]{0f, 3f, 5f, 7f, 10f, 15f}; String[] speedNamesPos = new String[speedLimitsMphPos.length];
String[] speedNames = new String[speedLimitsMiles.length];
for (int i = 0; i < speedNames.length; i++) { for (int i = 0; i < speedNames.length; i++) {
speedNames[i] = speedLimitsMiles[i].intValue() + " " + getString(R.string.mile_per_hour); speedNames[i] = speedLimitsMph[i].intValue() + " " + getString(R.string.mile_per_hour);
} }
String[] speedNamesPos = new String[speedLimitsMilesPos.length];
for (int i = 0; i < speedNamesPos.length; i++) { for (int i = 0; i < speedNamesPos.length; i++) {
speedNamesPos[i] = speedLimitsMiles[i].intValue() + " " + getString(R.string.mile_per_hour); speedNamesPos[i] = speedLimitsMphPos[i].intValue() + " " + getString(R.string.mile_per_hour);
} }
registerListPreference(settings.SPEED_LIMIT_EXCEED, screen, speedNames, speedLimitsMiles); registerListPreference(settings.SPEED_LIMIT_EXCEED_KMH, screen, speedNames, speedLimitsKmh);
registerListPreference(settings.SWITCH_MAP_DIRECTION_TO_COMPASS, screen, speedNamesPos, speedLimitsMilesPos); registerListPreference(settings.SWITCH_MAP_DIRECTION_TO_COMPASS_KMH, screen, speedNamesPos, speedLimitsKmhPos);
} }
PreferenceCategory category = (PreferenceCategory) screen.findPreference("guidance_preferences"); PreferenceCategory category = (PreferenceCategory) screen.findPreference("guidance_preferences");

View file

@ -128,7 +128,7 @@ public class MapViewTrackingUtilities implements OsmAndLocationListener, IMapLoc
headingChanged = Math.abs(MapUtils.degreesDiff(prevHeading, heading)) > 1.0; headingChanged = Math.abs(MapUtils.degreesDiff(prevHeading, heading)) > 1.0;
} }
if (mapView != null) { if (mapView != null) {
float speedForDirectionOfMovement = settings.SWITCH_MAP_DIRECTION_TO_COMPASS.get()/3.6f; float speedForDirectionOfMovement = settings.SWITCH_MAP_DIRECTION_TO_COMPASS_KMH.get()/3.6f;
boolean smallSpeedForDirectionOfMovement = speedForDirectionOfMovement != 0 && boolean smallSpeedForDirectionOfMovement = speedForDirectionOfMovement != 0 &&
myLocation != null && isSmallSpeedForDirectionOfMovement(myLocation, speedForDirectionOfMovement); myLocation != null && isSmallSpeedForDirectionOfMovement(myLocation, speedForDirectionOfMovement);
if ((settings.ROTATE_MAP.get() == OsmandSettings.ROTATE_MAP_COMPASS || (settings.ROTATE_MAP.get() == OsmandSettings.ROTATE_MAP_BEARING && smallSpeedForDirectionOfMovement)) && !routePlanningMode) { if ((settings.ROTATE_MAP.get() == OsmandSettings.ROTATE_MAP_COMPASS || (settings.ROTATE_MAP.get() == OsmandSettings.ROTATE_MAP_BEARING && smallSpeedForDirectionOfMovement)) && !routePlanningMode) {
@ -187,7 +187,7 @@ public class MapViewTrackingUtilities implements OsmAndLocationListener, IMapLoc
zoom = autozoom(tb, location); zoom = autozoom(tb, location);
} }
int currentMapRotation = settings.ROTATE_MAP.get(); int currentMapRotation = settings.ROTATE_MAP.get();
float speedForDirectionOfMovement = settings.SWITCH_MAP_DIRECTION_TO_COMPASS.get()/3.6f; float speedForDirectionOfMovement = settings.SWITCH_MAP_DIRECTION_TO_COMPASS_KMH.get()/3.6f;
boolean smallSpeedForDirectionOfMovement = speedForDirectionOfMovement != 0 boolean smallSpeedForDirectionOfMovement = speedForDirectionOfMovement != 0
&& isSmallSpeedForDirectionOfMovement(location, speedForDirectionOfMovement); && isSmallSpeedForDirectionOfMovement(location, speedForDirectionOfMovement);
boolean smallSpeedForCompass = isSmallSpeedForCompass(location); boolean smallSpeedForCompass = isSmallSpeedForCompass(location);

View file

@ -196,7 +196,7 @@ public class WaypointHelper {
public AlarmInfo getMostImportantAlarm(OsmandSettings.SpeedConstants sc, boolean showCameras) { public AlarmInfo getMostImportantAlarm(OsmandSettings.SpeedConstants sc, boolean showCameras) {
Location lastProjection = app.getRoutingHelper().getLastProjection(); Location lastProjection = app.getRoutingHelper().getLastProjection();
float mxspeed = route.getCurrentMaxSpeed(); float mxspeed = route.getCurrentMaxSpeed();
float delta = app.getSettings().SPEED_LIMIT_EXCEED.get() / 3.6f; float delta = app.getSettings().SPEED_LIMIT_EXCEED_KMH.get() / 3.6f;
AlarmInfo speedAlarm = createSpeedAlarm(sc, mxspeed, lastProjection, delta); AlarmInfo speedAlarm = createSpeedAlarm(sc, mxspeed, lastProjection, delta);
if (speedAlarm != null) { if (speedAlarm != null) {
getVoiceRouter().announceSpeedAlarm(speedAlarm.getIntValue(), lastProjection.getSpeed()); getVoiceRouter().announceSpeedAlarm(speedAlarm.getIntValue(), lastProjection.getSpeed());
@ -293,7 +293,7 @@ public class WaypointHelper {
public AlarmInfo calculateMostImportantAlarm(RouteDataObject ro, Location loc, MetricsConstants mc, public AlarmInfo calculateMostImportantAlarm(RouteDataObject ro, Location loc, MetricsConstants mc,
OsmandSettings.SpeedConstants sc, boolean showCameras) { OsmandSettings.SpeedConstants sc, boolean showCameras) {
float mxspeed = ro.getMaximumSpeed(ro.bearingVsRouteDirection(loc)); float mxspeed = ro.getMaximumSpeed(ro.bearingVsRouteDirection(loc));
float delta = app.getSettings().SPEED_LIMIT_EXCEED.get() / 3.6f; float delta = app.getSettings().SPEED_LIMIT_EXCEED_KMH.get() / 3.6f;
AlarmInfo speedAlarm = createSpeedAlarm(sc, mxspeed, loc, delta); AlarmInfo speedAlarm = createSpeedAlarm(sc, mxspeed, loc, delta);
if (speedAlarm != null) { if (speedAlarm != null) {
getVoiceRouter().announceSpeedAlarm(speedAlarm.getIntValue(), loc.getSpeed()); getVoiceRouter().announceSpeedAlarm(speedAlarm.getIntValue(), loc.getSpeed());

View file

@ -1790,7 +1790,7 @@ public class OsmandSettings {
public final OsmandPreference<Float> ARRIVAL_DISTANCE_FACTOR = public final OsmandPreference<Float> ARRIVAL_DISTANCE_FACTOR =
new FloatPreference("arrival_distance_factor", 1f).makeProfile(); new FloatPreference("arrival_distance_factor", 1f).makeProfile();
public final OsmandPreference<Float> SPEED_LIMIT_EXCEED = public final OsmandPreference<Float> SPEED_LIMIT_EXCEED_KMH =
new FloatPreference("speed_limit_exceed", 5f).makeProfile(); new FloatPreference("speed_limit_exceed", 5f).makeProfile();
public final CommonPreference<Float> DEFAULT_SPEED = new FloatPreference("default_speed", 10f).makeProfile().cache(); public final CommonPreference<Float> DEFAULT_SPEED = new FloatPreference("default_speed", 10f).makeProfile().cache();
@ -1873,7 +1873,7 @@ public class OsmandSettings {
public final CommonPreference<Integer> APP_MODE_ORDER = new IntPreference("app_mode_order", 0).makeProfile().cache(); public final CommonPreference<Integer> APP_MODE_ORDER = new IntPreference("app_mode_order", 0).makeProfile().cache();
public final OsmandPreference<Float> SWITCH_MAP_DIRECTION_TO_COMPASS = public final OsmandPreference<Float> SWITCH_MAP_DIRECTION_TO_COMPASS_KMH =
new FloatPreference("speed_for_map_to_direction_of_movement", 0f).makeProfile(); new FloatPreference("speed_for_map_to_direction_of_movement", 0f).makeProfile();
// this value string is synchronized with settings_pref.xml preference name // this value string is synchronized with settings_pref.xml preference name

View file

@ -74,28 +74,24 @@ public class MapDuringNavigationFragment extends BaseSettingsFragment {
} }
private void setupMapDirectionToCompassPref() { private void setupMapDirectionToCompassPref() {
String[] entries; //array size must be equal!
Float[] entryValues; Float[] valuesKmh = new Float[]{0f, 5f, 7f, 10f, 15f, 20f};
Float[] valuesMph = new Float[]{0f, 3f, 5f, 7f, 10f, 15f};
String[] names;
if (settings.METRIC_SYSTEM.getModeValue(getSelectedAppMode()) == OsmandSettings.MetricsConstants.KILOMETERS_AND_METERS) { if (settings.METRIC_SYSTEM.getModeValue(getSelectedAppMode()) == OsmandSettings.MetricsConstants.KILOMETERS_AND_METERS) {
entryValues = new Float[] {0f, 5f, 7f, 10f, 15f, 20f}; names = new String[valuesKmh.length];
entries = new String[entryValues.length]; for (int i = 0; i < names.length; i++) {
names[i] = valuesKmh[i].intValue() + " " + getString(R.string.km_h);
for (int i = 0; i < entryValues.length; i++) {
entries[i] = entryValues[i].intValue() + " " + getString(R.string.km_h);
} }
} else { } else {
Float[] speedLimitsMiles = new Float[] {-7f, -5f, -3f, 0f, 3f, 5f, 7f, 10f, 15f}; names = new String[valuesMph.length];
entryValues = new Float[] {0f, 3f, 5f, 7f, 10f, 15f}; for (int i = 0; i < names.length; i++) {
entries = new String[entryValues.length]; names[i] = valuesMph[i].intValue() + " " + getString(R.string.mile_per_hour);
for (int i = 0; i < entries.length; i++) {
entries[i] = speedLimitsMiles[i].intValue() + " " + getString(R.string.mile_per_hour);
} }
} }
ListPreferenceEx switchMapDirectionToCompass = (ListPreferenceEx) findPreference(settings.SWITCH_MAP_DIRECTION_TO_COMPASS_KMH.getId());
ListPreferenceEx switchMapDirectionToCompass = (ListPreferenceEx) findPreference(settings.SWITCH_MAP_DIRECTION_TO_COMPASS.getId()); switchMapDirectionToCompass.setEntries(names);
switchMapDirectionToCompass.setEntries(entries); switchMapDirectionToCompass.setEntryValues(valuesKmh);
switchMapDirectionToCompass.setEntryValues(entryValues);
} }
@Override @Override

View file

@ -103,28 +103,24 @@ public class VoiceAnnouncesFragment extends BaseSettingsFragment implements OnPr
} }
private void setupSpeedLimitExceedPref() { private void setupSpeedLimitExceedPref() {
Float[] speedLimitValues; //array size must be equal!
String[] speedLimitNames; Float[] valuesKmh = new Float[]{-10f, -7f, -5f, 0f, 5f, 7f, 10f, 15f, 20f};
Float[] valuesMph = new Float[]{-7f, -5f, -3f, 0f, 3f, 5f, 7f, 10f, 15f};
String[] names;
if (settings.METRIC_SYSTEM.getModeValue(getSelectedAppMode()) == OsmandSettings.MetricsConstants.KILOMETERS_AND_METERS) { if (settings.METRIC_SYSTEM.getModeValue(getSelectedAppMode()) == OsmandSettings.MetricsConstants.KILOMETERS_AND_METERS) {
speedLimitValues = new Float[] {-10f, -7f, -5f, 0f, 5f, 7f, 10f, 15f, 20f}; names = new String[valuesKmh.length];
speedLimitNames = new String[speedLimitValues.length]; for (int i = 0; i < names.length; i++) {
names[i] = valuesKmh[i].intValue() + " " + getString(R.string.km_h);
for (int i = 0; i < speedLimitValues.length; i++) {
speedLimitNames[i] = speedLimitValues[i].intValue() + " " + getString(R.string.km_h);
} }
} else { } else {
speedLimitValues = new Float[] {-7f, -5f, -3f, 0f, 3f, 5f, 7f, 10f, 15f}; names = new String[valuesMph.length];
speedLimitNames = new String[speedLimitValues.length]; for (int i = 0; i < names.length; i++) {
names[i] = valuesMph[i].intValue() + " " + getString(R.string.mile_per_hour);
for (int i = 0; i < speedLimitNames.length; i++) {
speedLimitNames[i] = speedLimitValues[i].intValue() + " " + getString(R.string.mile_per_hour);
} }
} }
ListPreferenceEx voiceProvider = (ListPreferenceEx) findPreference(settings.SPEED_LIMIT_EXCEED_KMH.getId());
ListPreferenceEx voiceProvider = (ListPreferenceEx) findPreference(settings.SPEED_LIMIT_EXCEED.getId()); voiceProvider.setEntries(names);
voiceProvider.setEntries(speedLimitNames); voiceProvider.setEntryValues(valuesKmh);
voiceProvider.setEntryValues(speedLimitValues);
} }
private void setupKeepInformingPref() { private void setupKeepInformingPref() {