From e0809531150c897576787175ce37db394adbc9a5 Mon Sep 17 00:00:00 2001 From: Chumva Date: Wed, 16 Oct 2019 16:13:40 +0300 Subject: [PATCH] Add driving style pref to route parameters screen --- .../settings/RouteParametersFragment.java | 74 +++++++++++-------- 1 file changed, 44 insertions(+), 30 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/settings/RouteParametersFragment.java b/OsmAnd/src/net/osmand/plus/settings/RouteParametersFragment.java index 6c4dd6ba70..17dfca3136 100644 --- a/OsmAnd/src/net/osmand/plus/settings/RouteParametersFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/RouteParametersFragment.java @@ -15,7 +15,6 @@ import net.osmand.plus.OsmandSettings.BooleanPreference; import net.osmand.plus.R; import net.osmand.plus.activities.SettingsBaseActivity; import net.osmand.plus.activities.SettingsNavigationActivity; -import net.osmand.plus.routepreparationmenu.RoutingOptionsHelper; import net.osmand.plus.routing.RouteProvider; import net.osmand.plus.settings.preferences.ListPreferenceEx; import net.osmand.plus.settings.preferences.MultiSelectBooleanPreference; @@ -30,6 +29,7 @@ import java.util.Map; import java.util.Set; import static net.osmand.plus.activities.SettingsNavigationActivity.getRouter; +import static net.osmand.plus.routepreparationmenu.RoutingOptionsHelper.DRIVING_STYLE; public class RouteParametersFragment extends BaseSettingsFragment { @@ -43,6 +43,7 @@ public class RouteParametersFragment extends BaseSettingsFragment { private List avoidParameters = new ArrayList(); private List preferParameters = new ArrayList(); + private List drivingStyleParameters = new ArrayList(); private List reliefFactorParameters = new ArrayList(); private List otherRoutingParameters = new ArrayList(); @@ -130,14 +131,19 @@ public class RouteParametersFragment extends BaseSettingsFragment { preferParameters.add(routingParameter); } else if (RELIEF_SMOOTHNESS_FACTOR.equals(routingParameter.getGroup())) { reliefFactorParameters.add(routingParameter); + } else if (DRIVING_STYLE.equals(routingParameter.getGroup())) { + drivingStyleParameters.add(routingParameter); } else if (!param.equals(GeneralRouter.USE_SHORTEST_WAY) && !param.equals(GeneralRouter.VEHICLE_HEIGHT) && !param.equals(GeneralRouter.VEHICLE_WEIGHT) - && !param.equals(GeneralRouter.VEHICLE_WIDTH) - && !RoutingOptionsHelper.DRIVING_STYLE.equals(routingParameter.getGroup())) { + && !param.equals(GeneralRouter.VEHICLE_WIDTH)) { otherRoutingParameters.add(routingParameter); } } + if (drivingStyleParameters.size() > 0) { + ListPreferenceEx drivingStyleRouting = createRoutingBooleanListPreference(DRIVING_STYLE, drivingStyleParameters); + screen.addPreference(drivingStyleRouting); + } if (avoidParameters.size() > 0) { MultiSelectBooleanPreference avoidRouting = new MultiSelectBooleanPreference(app); avoidRouting.setKey(AVOID_ROUTING_PARAMETER_PREFIX); @@ -179,27 +185,8 @@ public class RouteParametersFragment extends BaseSettingsFragment { screen.addPreference(preferRouting); } if (reliefFactorParameters.size() > 0) { - String defaultTitle = Algorithms.capitalizeFirstLetterAndLowercase(RELIEF_SMOOTHNESS_FACTOR.replace('_', ' ')); - String title = SettingsBaseActivity.getRoutingStringPropertyName(app, RELIEF_SMOOTHNESS_FACTOR, defaultTitle); - - Object[] entryValues = new Object[reliefFactorParameters.size()]; - String[] entries = new String[entryValues.length]; - - String selectedParameterId = null; - for (int i = 0; i < reliefFactorParameters.size(); i++) { - GeneralRouter.RoutingParameter parameter = reliefFactorParameters.get(i); - entryValues[i] = parameter.getId(); - entries[i] = SettingsNavigationActivity.getRoutinParameterTitle(app, parameter); - if (SettingsNavigationActivity.isRoutingParameterSelected(settings, am, parameter)) { - selectedParameterId = parameter.getId(); - } - } - - ListPreferenceEx reliefFactorRouting = createListPreferenceEx(RELIEF_SMOOTHNESS_FACTOR, entries, entryValues, title, R.layout.preference_with_descr); - reliefFactorRouting.setPersistent(false); - reliefFactorRouting.setValue(selectedParameterId); + ListPreferenceEx reliefFactorRouting = createRoutingBooleanListPreference(RELIEF_SMOOTHNESS_FACTOR, reliefFactorParameters); reliefFactorRouting.setDescription(R.string.relief_smoothness_factor_descr); - reliefFactorRouting.setIconSpaceReserved(true); screen.addPreference(reliefFactorRouting); } @@ -243,13 +230,12 @@ public class RouteParametersFragment extends BaseSettingsFragment { public boolean onPreferenceChange(Preference preference, Object newValue) { String key = preference.getKey(); - if (RELIEF_SMOOTHNESS_FACTOR.equals(key)) { - if (newValue instanceof String) { - String selectedParameterId = (String) newValue; - for (GeneralRouter.RoutingParameter parameter : reliefFactorParameters) { - String parameterId = parameter.getId(); - SettingsNavigationActivity.setRoutingParameterSelected(settings, getSelectedAppMode(), parameterId, parameter.getDefaultBoolean(), parameterId.equals(selectedParameterId)); - } + if ((RELIEF_SMOOTHNESS_FACTOR.equals(key) || DRIVING_STYLE.equals(key)) && newValue instanceof String) { + String selectedParameterId = (String) newValue; + List routingParameters = DRIVING_STYLE.equals(key) ? drivingStyleParameters : reliefFactorParameters; + for (GeneralRouter.RoutingParameter parameter : routingParameters) { + String parameterId = parameter.getId(); + SettingsNavigationActivity.setRoutingParameterSelected(settings, getSelectedAppMode(), parameterId, parameter.getDefaultBoolean(), parameterId.equals(selectedParameterId)); } return true; } @@ -257,6 +243,32 @@ public class RouteParametersFragment extends BaseSettingsFragment { return super.onPreferenceChange(preference, newValue); } + private ListPreferenceEx createRoutingBooleanListPreference(String groupKey, List routingParameters) { + String defaultTitle = Algorithms.capitalizeFirstLetterAndLowercase(groupKey.replace('_', ' ')); + String title = SettingsBaseActivity.getRoutingStringPropertyName(app, groupKey, defaultTitle); + ApplicationMode am = settings.getApplicationMode(); + + Object[] entryValues = new Object[routingParameters.size()]; + String[] entries = new String[entryValues.length]; + + String selectedParameterId = null; + for (int i = 0; i < routingParameters.size(); i++) { + GeneralRouter.RoutingParameter parameter = routingParameters.get(i); + entryValues[i] = parameter.getId(); + entries[i] = SettingsNavigationActivity.getRoutinParameterTitle(app, parameter); + if (SettingsNavigationActivity.isRoutingParameterSelected(settings, am, parameter)) { + selectedParameterId = parameter.getId(); + } + } + + ListPreferenceEx routingListPref = createListPreferenceEx(groupKey, entries, entryValues, title, R.layout.preference_with_descr); + routingListPref.setPersistent(false); + routingListPref.setValue(selectedParameterId); + routingListPref.setIcon(getRoutingPrefIcon(groupKey)); + + return routingListPref; + } + private void clearParameters() { avoidParameters.clear(); preferParameters.clear(); @@ -270,6 +282,8 @@ public class RouteParametersFragment extends BaseSettingsFragment { return getIcon(R.drawable.ic_action_private_access); case AVOID_ROUTING_PARAMETER_PREFIX: return getContentIcon(R.drawable.ic_action_alert); + case DRIVING_STYLE: + return getContentIcon(R.drawable.ic_action_bicycle_dark); case "fast_route_mode": return getIcon(R.drawable.ic_action_fastest_route); case "enable_time_conditional_routing":