use of net.osmand.plus.settings.preferences.MultiSelectBooleanPreference in project Osmand by osmandapp.
the class BaseSettingsFragment method onDisplayPreferenceDialog.
@Override
public void onDisplayPreferenceDialog(Preference preference) {
FragmentManager fragmentManager = getFragmentManager();
if (fragmentManager == null) {
return;
}
ApplicationMode appMode = getSelectedAppMode();
if (preference instanceof ListPreferenceEx) {
SingleSelectPreferenceBottomSheet.showInstance(fragmentManager, preference.getKey(), this, false, appMode, isProfileDependent(), false);
} else if (preference instanceof SwitchPreferenceEx) {
BooleanPreferenceBottomSheet.showInstance(fragmentManager, preference.getKey(), this, false, appMode, getApplyQueryType(), isProfileDependent());
} else if (preference instanceof EditTextPreference) {
EditTextPreferenceBottomSheet.showInstance(fragmentManager, preference.getKey(), this, false, appMode);
} else if (preference instanceof MultiSelectBooleanPreference) {
MultiSelectPreferencesBottomSheet.showInstance(fragmentManager, preference.getKey(), this, false, appMode, isProfileDependent());
} else {
super.onDisplayPreferenceDialog(preference);
}
}
use of net.osmand.plus.settings.preferences.MultiSelectBooleanPreference in project Osmand by osmandapp.
the class RouteParametersFragment method setupRoutingPrefs.
private void setupRoutingPrefs() {
OsmandApplication app = getMyApplication();
if (app == null) {
return;
}
PreferenceScreen screen = getPreferenceScreen();
ApplicationMode am = getSelectedAppMode();
SwitchPreferenceEx fastRoute = createSwitchPreferenceEx(app.getSettings().FAST_ROUTE_MODE.getId(), R.string.fast_route_mode, R.layout.preference_with_descr_dialog_and_switch);
fastRoute.setIcon(getRoutingPrefIcon(app.getSettings().FAST_ROUTE_MODE.getId()));
fastRoute.setDescription(getString(R.string.fast_route_mode_descr));
fastRoute.setSummaryOn(R.string.shared_string_on);
fastRoute.setSummaryOff(R.string.shared_string_off);
if (am.getRouteService() == RouteService.OSMAND) {
GeneralRouter router = app.getRouter(am);
clearParameters();
if (router != null) {
Map<String, RoutingParameter> parameters = router.getParameters();
if (!am.isDerivedRoutingFrom(ApplicationMode.CAR)) {
screen.addPreference(fastRoute);
}
for (Map.Entry<String, RoutingParameter> e : parameters.entrySet()) {
String param = e.getKey();
RoutingParameter routingParameter = e.getValue();
if (param.startsWith(AVOID_ROUTING_PARAMETER_PREFIX)) {
avoidParameters.add(routingParameter);
} else if (param.startsWith(PREFER_ROUTING_PARAMETER_PREFIX)) {
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) || am.isDerivedRoutingFrom(ApplicationMode.CAR)) && !param.equals(GeneralRouter.VEHICLE_HEIGHT) && !param.equals(GeneralRouter.VEHICLE_WEIGHT) && !param.equals(GeneralRouter.VEHICLE_WIDTH) && !param.equals(GeneralRouter.VEHICLE_LENGTH)) {
otherRoutingParameters.add(routingParameter);
}
}
if (drivingStyleParameters.size() > 0) {
ListPreferenceEx drivingStyleRouting = createRoutingBooleanListPreference(DRIVING_STYLE, drivingStyleParameters);
screen.addPreference(drivingStyleRouting);
}
if (avoidParameters.size() > 0) {
String title;
String description;
if (am.isDerivedRoutingFrom(ApplicationMode.PUBLIC_TRANSPORT)) {
title = getString(R.string.avoid_pt_types);
description = getString(R.string.avoid_pt_types_descr);
} else {
title = getString(R.string.impassable_road);
description = getString(R.string.avoid_in_routing_descr_);
}
MultiSelectBooleanPreference avoidRouting = createRoutingBooleanMultiSelectPref(AVOID_ROUTING_PARAMETER_PREFIX, title, description, avoidParameters);
screen.addPreference(avoidRouting);
}
if (preferParameters.size() > 0) {
String title = getString(R.string.prefer_in_routing_title);
MultiSelectBooleanPreference preferRouting = createRoutingBooleanMultiSelectPref(PREFER_ROUTING_PARAMETER_PREFIX, title, "", preferParameters);
screen.addPreference(preferRouting);
}
for (RoutingParameter p : otherRoutingParameters) {
String title = AndroidUtils.getRoutingStringPropertyName(app, p.getId(), p.getName());
String description = AndroidUtils.getRoutingStringPropertyDescription(app, p.getId(), p.getDescription());
if (p.getType() == RoutingParameterType.BOOLEAN) {
OsmandPreference pref = settings.getCustomRoutingBooleanProperty(p.getId(), p.getDefaultBoolean());
SwitchPreferenceEx switchPreferenceEx = createSwitchPreferenceEx(pref.getId(), title, description, R.layout.preference_with_descr_dialog_and_switch);
switchPreferenceEx.setDescription(description);
switchPreferenceEx.setIcon(getRoutingPrefIcon(p.getId()));
screen.addPreference(switchPreferenceEx);
setupOtherBooleanParameterSummary(am, p, switchPreferenceEx);
} else {
Object[] vls = p.getPossibleValues();
String[] svlss = new String[vls.length];
int i = 0;
for (Object o : vls) {
svlss[i++] = o.toString();
}
OsmandPreference pref = settings.getCustomRoutingProperty(p.getId(), p.getType() == RoutingParameterType.NUMERIC ? "0.0" : "-");
ListPreferenceEx listPreferenceEx = (ListPreferenceEx) createListPreferenceEx(pref.getId(), p.getPossibleValueDescriptions(), svlss, title, R.layout.preference_with_descr);
listPreferenceEx.setDescription(description);
listPreferenceEx.setIcon(getRoutingPrefIcon(p.getId()));
screen.addPreference(listPreferenceEx);
}
}
}
setupTimeConditionalRoutingPref();
} else if (am.getRouteService() == RouteService.BROUTER) {
screen.addPreference(fastRoute);
setupTimeConditionalRoutingPref();
} else if (am.getRouteService() == RouteService.STRAIGHT) {
Preference straightAngle = new Preference(app.getApplicationContext());
straightAngle.setPersistent(false);
straightAngle.setKey(settings.ROUTE_STRAIGHT_ANGLE.getId());
straightAngle.setTitle(getString(R.string.recalc_angle_dialog_title));
straightAngle.setSummary(String.format(getString(R.string.shared_string_angle_param), String.valueOf((int) am.getStrAngle())));
straightAngle.setLayoutResource(R.layout.preference_with_descr);
// TODO change for appropriate icon when available
straightAngle.setIcon(getRoutingPrefIcon("routing_recalc_distance"));
getPreferenceScreen().addPreference(straightAngle);
}
addDivider(screen);
setupRouteRecalcHeader(screen);
setupSelectRouteRecalcDistance(screen);
setupReverseDirectionRecalculation(screen);
if (OsmandPlugin.isActive(OsmandDevelopmentPlugin.class)) {
setupDevelopmentCategoryPreferences(screen, am);
}
}
use of net.osmand.plus.settings.preferences.MultiSelectBooleanPreference in project Osmand by osmandapp.
the class RouteParametersFragment method createRoutingBooleanMultiSelectPref.
private MultiSelectBooleanPreference createRoutingBooleanMultiSelectPref(String groupKey, String title, String descr, List<RoutingParameter> routingParameters) {
MultiSelectBooleanPreference multiSelectPref = new MultiSelectBooleanPreference(app);
multiSelectPref.setKey(groupKey);
multiSelectPref.setTitle(title);
multiSelectPref.setSummary(descr);
multiSelectPref.setDescription(descr);
multiSelectPref.setLayoutResource(R.layout.preference_with_descr);
multiSelectPref.setIcon(getRoutingPrefIcon(groupKey));
multiSelectPref.setIconSpaceReserved(true);
String[] entries = new String[routingParameters.size()];
String[] prefsIds = new String[routingParameters.size()];
Set<String> enabledPrefsIds = new HashSet<>();
ApplicationMode selectedMode = getSelectedAppMode();
for (int i = 0; i < routingParameters.size(); i++) {
RoutingParameter p = routingParameters.get(i);
BooleanPreference booleanRoutingPref = (BooleanPreference) settings.getCustomRoutingBooleanProperty(p.getId(), p.getDefaultBoolean());
entries[i] = AndroidUtils.getRoutingStringPropertyName(app, p.getId(), p.getName());
prefsIds[i] = booleanRoutingPref.getId();
if (booleanRoutingPref.getModeValue(selectedMode)) {
enabledPrefsIds.add(booleanRoutingPref.getId());
}
}
multiSelectPref.setEntries(entries);
multiSelectPref.setEntryValues(prefsIds);
multiSelectPref.setValues(enabledPrefsIds);
return multiSelectPref;
}
use of net.osmand.plus.settings.preferences.MultiSelectBooleanPreference in project Osmand by osmandapp.
the class BaseSettingsFragment method applyPreference.
protected final void applyPreference(Preference pref, boolean applyToAllProfiles, Object newValue) {
if (pref instanceof MultiSelectBooleanPreference) {
MultiSelectBooleanPreference msp = (MultiSelectBooleanPreference) pref;
Set<String> values = (Set<String>) newValue;
String[] ids = msp.getPrefsIds();
for (int i = 0; i < ids.length; i++) {
applyPreference(ids[i], applyToAllProfiles, values.contains(ids[i]));
}
}
}
Aggregations