From 81bf4ea094840169243f365fb46859ef375aa262 Mon Sep 17 00:00:00 2001 From: max-klaus Date: Fri, 4 Sep 2020 14:25:51 +0300 Subject: [PATCH] Fix kmh / mph nav parameters --- .../SettingsNavigationActivity.java | 39 ++++++++++--------- .../plus/base/MapViewTrackingUtilities.java | 4 +- .../osmand/plus/helpers/WaypointHelper.java | 4 +- .../plus/settings/backend/OsmandSettings.java | 4 +- .../MapDuringNavigationFragment.java | 30 +++++++------- .../fragments/VoiceAnnouncesFragment.java | 30 +++++++------- 6 files changed, 52 insertions(+), 59 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/activities/SettingsNavigationActivity.java b/OsmAnd/src/net/osmand/plus/activities/SettingsNavigationActivity.java index 3f0ba10d29..260fd63719 100644 --- a/OsmAnd/src/net/osmand/plus/activities/SettingsNavigationActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/SettingsNavigationActivity.java @@ -165,33 +165,34 @@ public class SettingsNavigationActivity extends SettingsBaseActivity { 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) { - Float[] speedLimitsKm = new Float[]{-10f, -7f, -5f, 0f, 5f, 7f, 10f, 15f, 20f}; - Float[] speedLimitsKmPos = new Float[]{0f, 5f, 7f, 10f, 15f, 20f}; - String[] speedNames = new String[speedLimitsKm.length]; - String[] speedNamesPos = new String[speedLimitsKmPos.length]; - for (int i = 0; i < speedLimitsKm.length; i++) { - speedNames[i] = speedLimitsKm[i].intValue() + " " + getString(R.string.km_h); + String[] speedNames = new String[speedLimitsKmh.length]; + String[] speedNamesPos = new String[speedLimitsKmhPos.length]; + for (int i = 0; i < speedLimitsKmh.length; i++) { + speedNames[i] = speedLimitsKmh[i].intValue() + " " + getString(R.string.km_h); } - for (int i = 0; i < speedLimitsKmPos.length; i++) { - speedNamesPos[i] = speedLimitsKmPos[i].intValue() + " " + getString(R.string.km_h); + for (int i = 0; i < speedLimitsKmhPos.length; i++) { + speedNamesPos[i] = speedLimitsKmhPos[i].intValue() + " " + getString(R.string.km_h); } - registerListPreference(settings.SPEED_LIMIT_EXCEED, screen, speedNames, speedLimitsKm); - registerListPreference(settings.SWITCH_MAP_DIRECTION_TO_COMPASS, screen, speedNamesPos, speedLimitsKmPos); + registerListPreference(settings.SPEED_LIMIT_EXCEED_KMH, screen, speedNames, speedLimitsKmh); + registerListPreference(settings.SWITCH_MAP_DIRECTION_TO_COMPASS_KMH, screen, speedNamesPos, speedLimitsKmhPos); } else { - Float[] speedLimitsMiles = new Float[]{-7f, -5f, -3f, 0f, 3f, 5f, 7f, 10f, 15f}; - Float[] speedLimitsMilesPos = new Float[]{0f, 3f, 5f, 7f, 10f, 15f}; - - String[] speedNames = new String[speedLimitsMiles.length]; + String[] speedNames = new String[speedLimitsMph.length]; + String[] speedNamesPos = new String[speedLimitsMphPos.length]; 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++) { - 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.SWITCH_MAP_DIRECTION_TO_COMPASS, screen, speedNamesPos, speedLimitsMilesPos); + registerListPreference(settings.SPEED_LIMIT_EXCEED_KMH, screen, speedNames, speedLimitsKmh); + registerListPreference(settings.SWITCH_MAP_DIRECTION_TO_COMPASS_KMH, screen, speedNamesPos, speedLimitsKmhPos); } PreferenceCategory category = (PreferenceCategory) screen.findPreference("guidance_preferences"); diff --git a/OsmAnd/src/net/osmand/plus/base/MapViewTrackingUtilities.java b/OsmAnd/src/net/osmand/plus/base/MapViewTrackingUtilities.java index e04bb51559..601fb62909 100644 --- a/OsmAnd/src/net/osmand/plus/base/MapViewTrackingUtilities.java +++ b/OsmAnd/src/net/osmand/plus/base/MapViewTrackingUtilities.java @@ -128,7 +128,7 @@ public class MapViewTrackingUtilities implements OsmAndLocationListener, IMapLoc headingChanged = Math.abs(MapUtils.degreesDiff(prevHeading, heading)) > 1.0; } 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 && myLocation != null && isSmallSpeedForDirectionOfMovement(myLocation, speedForDirectionOfMovement); 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); } 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 && isSmallSpeedForDirectionOfMovement(location, speedForDirectionOfMovement); boolean smallSpeedForCompass = isSmallSpeedForCompass(location); diff --git a/OsmAnd/src/net/osmand/plus/helpers/WaypointHelper.java b/OsmAnd/src/net/osmand/plus/helpers/WaypointHelper.java index 8dbfb93a78..b143653754 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/WaypointHelper.java +++ b/OsmAnd/src/net/osmand/plus/helpers/WaypointHelper.java @@ -196,7 +196,7 @@ public class WaypointHelper { public AlarmInfo getMostImportantAlarm(OsmandSettings.SpeedConstants sc, boolean showCameras) { Location lastProjection = app.getRoutingHelper().getLastProjection(); 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); if (speedAlarm != null) { getVoiceRouter().announceSpeedAlarm(speedAlarm.getIntValue(), lastProjection.getSpeed()); @@ -293,7 +293,7 @@ public class WaypointHelper { 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; + float delta = app.getSettings().SPEED_LIMIT_EXCEED_KMH.get() / 3.6f; AlarmInfo speedAlarm = createSpeedAlarm(sc, mxspeed, loc, delta); if (speedAlarm != null) { getVoiceRouter().announceSpeedAlarm(speedAlarm.getIntValue(), loc.getSpeed()); diff --git a/OsmAnd/src/net/osmand/plus/settings/backend/OsmandSettings.java b/OsmAnd/src/net/osmand/plus/settings/backend/OsmandSettings.java index 4afce65383..bfb593be38 100644 --- a/OsmAnd/src/net/osmand/plus/settings/backend/OsmandSettings.java +++ b/OsmAnd/src/net/osmand/plus/settings/backend/OsmandSettings.java @@ -1790,7 +1790,7 @@ public class OsmandSettings { public final OsmandPreference ARRIVAL_DISTANCE_FACTOR = new FloatPreference("arrival_distance_factor", 1f).makeProfile(); - public final OsmandPreference SPEED_LIMIT_EXCEED = + public final OsmandPreference SPEED_LIMIT_EXCEED_KMH = new FloatPreference("speed_limit_exceed", 5f).makeProfile(); public final CommonPreference DEFAULT_SPEED = new FloatPreference("default_speed", 10f).makeProfile().cache(); @@ -1873,7 +1873,7 @@ public class OsmandSettings { public final CommonPreference APP_MODE_ORDER = new IntPreference("app_mode_order", 0).makeProfile().cache(); - public final OsmandPreference SWITCH_MAP_DIRECTION_TO_COMPASS = + public final OsmandPreference SWITCH_MAP_DIRECTION_TO_COMPASS_KMH = new FloatPreference("speed_for_map_to_direction_of_movement", 0f).makeProfile(); // this value string is synchronized with settings_pref.xml preference name diff --git a/OsmAnd/src/net/osmand/plus/settings/fragments/MapDuringNavigationFragment.java b/OsmAnd/src/net/osmand/plus/settings/fragments/MapDuringNavigationFragment.java index e44f338ee1..06aa0c4c08 100644 --- a/OsmAnd/src/net/osmand/plus/settings/fragments/MapDuringNavigationFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/fragments/MapDuringNavigationFragment.java @@ -74,28 +74,24 @@ public class MapDuringNavigationFragment extends BaseSettingsFragment { } private void setupMapDirectionToCompassPref() { - String[] entries; - Float[] entryValues; + //array size must be equal! + 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) { - entryValues = new Float[] {0f, 5f, 7f, 10f, 15f, 20f}; - entries = new String[entryValues.length]; - - for (int i = 0; i < entryValues.length; i++) { - entries[i] = entryValues[i].intValue() + " " + getString(R.string.km_h); + names = new String[valuesKmh.length]; + for (int i = 0; i < names.length; i++) { + names[i] = valuesKmh[i].intValue() + " " + getString(R.string.km_h); } } else { - Float[] speedLimitsMiles = new Float[] {-7f, -5f, -3f, 0f, 3f, 5f, 7f, 10f, 15f}; - entryValues = new Float[] {0f, 3f, 5f, 7f, 10f, 15f}; - entries = new String[entryValues.length]; - - for (int i = 0; i < entries.length; i++) { - entries[i] = speedLimitsMiles[i].intValue() + " " + getString(R.string.mile_per_hour); + names = new String[valuesMph.length]; + for (int i = 0; i < names.length; i++) { + names[i] = valuesMph[i].intValue() + " " + getString(R.string.mile_per_hour); } } - - ListPreferenceEx switchMapDirectionToCompass = (ListPreferenceEx) findPreference(settings.SWITCH_MAP_DIRECTION_TO_COMPASS.getId()); - switchMapDirectionToCompass.setEntries(entries); - switchMapDirectionToCompass.setEntryValues(entryValues); + ListPreferenceEx switchMapDirectionToCompass = (ListPreferenceEx) findPreference(settings.SWITCH_MAP_DIRECTION_TO_COMPASS_KMH.getId()); + switchMapDirectionToCompass.setEntries(names); + switchMapDirectionToCompass.setEntryValues(valuesKmh); } @Override diff --git a/OsmAnd/src/net/osmand/plus/settings/fragments/VoiceAnnouncesFragment.java b/OsmAnd/src/net/osmand/plus/settings/fragments/VoiceAnnouncesFragment.java index 24a1b817d4..4ff8f3262d 100644 --- a/OsmAnd/src/net/osmand/plus/settings/fragments/VoiceAnnouncesFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/fragments/VoiceAnnouncesFragment.java @@ -103,28 +103,24 @@ public class VoiceAnnouncesFragment extends BaseSettingsFragment implements OnPr } private void setupSpeedLimitExceedPref() { - Float[] speedLimitValues; - String[] speedLimitNames; - + //array size must be equal! + 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) { - speedLimitValues = new Float[] {-10f, -7f, -5f, 0f, 5f, 7f, 10f, 15f, 20f}; - speedLimitNames = new String[speedLimitValues.length]; - - for (int i = 0; i < speedLimitValues.length; i++) { - speedLimitNames[i] = speedLimitValues[i].intValue() + " " + getString(R.string.km_h); + names = new String[valuesKmh.length]; + for (int i = 0; i < names.length; i++) { + names[i] = valuesKmh[i].intValue() + " " + getString(R.string.km_h); } } else { - speedLimitValues = new Float[] {-7f, -5f, -3f, 0f, 3f, 5f, 7f, 10f, 15f}; - speedLimitNames = new String[speedLimitValues.length]; - - for (int i = 0; i < speedLimitNames.length; i++) { - speedLimitNames[i] = speedLimitValues[i].intValue() + " " + getString(R.string.mile_per_hour); + names = new String[valuesMph.length]; + for (int i = 0; i < names.length; i++) { + names[i] = valuesMph[i].intValue() + " " + getString(R.string.mile_per_hour); } } - - ListPreferenceEx voiceProvider = (ListPreferenceEx) findPreference(settings.SPEED_LIMIT_EXCEED.getId()); - voiceProvider.setEntries(speedLimitNames); - voiceProvider.setEntryValues(speedLimitValues); + ListPreferenceEx voiceProvider = (ListPreferenceEx) findPreference(settings.SPEED_LIMIT_EXCEED_KMH.getId()); + voiceProvider.setEntries(names); + voiceProvider.setEntryValues(valuesKmh); } private void setupKeepInformingPref() {