Add driving style pref to route parameters screen
This commit is contained in:
parent
9b1d9e23a5
commit
e080953115
1 changed files with 44 additions and 30 deletions
|
@ -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<GeneralRouter.RoutingParameter> avoidParameters = new ArrayList<GeneralRouter.RoutingParameter>();
|
||||
private List<GeneralRouter.RoutingParameter> preferParameters = new ArrayList<GeneralRouter.RoutingParameter>();
|
||||
private List<GeneralRouter.RoutingParameter> drivingStyleParameters = new ArrayList<GeneralRouter.RoutingParameter>();
|
||||
private List<GeneralRouter.RoutingParameter> reliefFactorParameters = new ArrayList<GeneralRouter.RoutingParameter>();
|
||||
private List<GeneralRouter.RoutingParameter> otherRoutingParameters = new ArrayList<GeneralRouter.RoutingParameter>();
|
||||
|
||||
|
@ -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<GeneralRouter.RoutingParameter> 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<GeneralRouter.RoutingParameter> 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":
|
||||
|
|
Loading…
Reference in a new issue