From 8ad6f937b6bda6a1d5e066b4abcc0f0dfd30cc05 Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Thu, 23 Jul 2020 14:28:28 +0300 Subject: [PATCH] Fix default speed slider --- .../SettingsNavigationActivity.java | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/activities/SettingsNavigationActivity.java b/OsmAnd/src/net/osmand/plus/activities/SettingsNavigationActivity.java index 6cec61b52b..e128a6da80 100644 --- a/OsmAnd/src/net/osmand/plus/activities/SettingsNavigationActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/SettingsNavigationActivity.java @@ -30,15 +30,10 @@ import androidx.core.content.ContextCompat; import com.google.android.material.slider.Slider; -import net.osmand.plus.settings.backend.ApplicationMode; import net.osmand.plus.ContextMenuAdapter; import net.osmand.plus.ContextMenuItem; import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.OsmandApplication; -import net.osmand.plus.settings.backend.OsmandSettings; -import net.osmand.plus.settings.backend.OsmandSettings.AutoZoomMap; -import net.osmand.plus.settings.backend.OsmandSettings.OsmandPreference; -import net.osmand.plus.settings.backend.OsmandSettings.SpeedConstants; import net.osmand.plus.R; import net.osmand.plus.UiUtilities; import net.osmand.plus.Version; @@ -48,6 +43,11 @@ import net.osmand.plus.helpers.FileNameTranslationHelper; import net.osmand.plus.routepreparationmenu.RoutingOptionsHelper; import net.osmand.plus.routing.RouteProvider.RouteService; import net.osmand.plus.routing.RoutingHelper; +import net.osmand.plus.settings.backend.ApplicationMode; +import net.osmand.plus.settings.backend.OsmandSettings; +import net.osmand.plus.settings.backend.OsmandSettings.AutoZoomMap; +import net.osmand.plus.settings.backend.OsmandSettings.OsmandPreference; +import net.osmand.plus.settings.backend.OsmandSettings.SpeedConstants; import net.osmand.plus.voice.CommandPlayer; import net.osmand.router.GeneralRouter; import net.osmand.router.GeneralRouter.GeneralRouterProfile; @@ -749,8 +749,9 @@ public class SettingsNavigationActivity extends SettingsBaseActivity { float settingsMinSpeed = mode.getMinSpeed(); float settingsMaxSpeed = mode.getMaxSpeed(); + float settingsDefaultSpeed = mode.getDefaultSpeed(); - final int[] defaultValue = {Math.round(mode.getDefaultSpeed() * ratio[0])}; + final int[] defaultValue = {Math.round(settingsDefaultSpeed * ratio[0])}; final int[] minValue = new int[1]; final int[] maxValue = new int[1]; final int min; @@ -761,10 +762,13 @@ public class SettingsNavigationActivity extends SettingsBaseActivity { min = minValue[0]; max = maxValue[0]; } else { - minValue[0] = Math.round((settingsMinSpeed > 0 ? settingsMinSpeed : router.getMinSpeed()) * ratio[0]); - maxValue[0] = Math.round((settingsMaxSpeed > 0 ? settingsMaxSpeed : router.getMaxSpeed()) * ratio[0]); - min = Math.round(router.getMinSpeed() * ratio[0] / 2f); - max = Math.round(router.getMaxSpeed() * ratio[0] * 1.5f); + float minSpeedValue = settingsMinSpeed > 0 ? settingsMinSpeed : router.getMinSpeed(); + float maxSpeedValue = settingsMaxSpeed > 0 ? settingsMaxSpeed : router.getMaxSpeed(); + minValue[0] = Math.round(Math.min(minSpeedValue, settingsDefaultSpeed) * ratio[0]); + maxValue[0] = Math.round(Math.max(maxSpeedValue, settingsDefaultSpeed) * ratio[0]); + + min = Math.round(Math.min(router.getMinSpeed(), settingsDefaultSpeed) * ratio[0] / 2f); + max = Math.round(Math.max(router.getMaxSpeed(), settingsDefaultSpeed) * ratio[0] * 1.5f); } boolean nightMode = !app.getSettings().isLightContentForMode(mode);