Search in sources :

Example 1 with MultiSelectBooleanPreference

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);
    }
}
Also used : FragmentManager(androidx.fragment.app.FragmentManager) ListPreferenceEx(net.osmand.plus.settings.preferences.ListPreferenceEx) MultiSelectBooleanPreference(net.osmand.plus.settings.preferences.MultiSelectBooleanPreference) ApplicationMode(net.osmand.plus.settings.backend.ApplicationMode) EditTextPreference(androidx.preference.EditTextPreference) SwitchPreferenceEx(net.osmand.plus.settings.preferences.SwitchPreferenceEx)

Example 2 with MultiSelectBooleanPreference

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);
    }
}
Also used : OsmandApplication(net.osmand.plus.OsmandApplication) PreferenceScreen(androidx.preference.PreferenceScreen) MultiSelectBooleanPreference(net.osmand.plus.settings.preferences.MultiSelectBooleanPreference) OsmandPreference(net.osmand.plus.settings.backend.preferences.OsmandPreference) GeneralRouter(net.osmand.router.GeneralRouter) ApplicationMode(net.osmand.plus.settings.backend.ApplicationMode) SwitchPreferenceEx(net.osmand.plus.settings.preferences.SwitchPreferenceEx) RoutingParameter(net.osmand.router.GeneralRouter.RoutingParameter) ListPreferenceEx(net.osmand.plus.settings.preferences.ListPreferenceEx) MultiSelectBooleanPreference(net.osmand.plus.settings.preferences.MultiSelectBooleanPreference) BooleanPreference(net.osmand.plus.settings.backend.preferences.BooleanPreference) CommonPreference(net.osmand.plus.settings.backend.preferences.CommonPreference) OsmandPreference(net.osmand.plus.settings.backend.preferences.OsmandPreference) Preference(androidx.preference.Preference) Map(java.util.Map)

Example 3 with MultiSelectBooleanPreference

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;
}
Also used : MultiSelectBooleanPreference(net.osmand.plus.settings.preferences.MultiSelectBooleanPreference) BooleanPreference(net.osmand.plus.settings.backend.preferences.BooleanPreference) RoutingParameter(net.osmand.router.GeneralRouter.RoutingParameter) MultiSelectBooleanPreference(net.osmand.plus.settings.preferences.MultiSelectBooleanPreference) ApplicationMode(net.osmand.plus.settings.backend.ApplicationMode) HashSet(java.util.HashSet)

Example 4 with MultiSelectBooleanPreference

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]));
        }
    }
}
Also used : Set(java.util.Set) MultiSelectBooleanPreference(net.osmand.plus.settings.preferences.MultiSelectBooleanPreference) SpannableString(android.text.SpannableString) SuppressLint(android.annotation.SuppressLint)

Aggregations

MultiSelectBooleanPreference (net.osmand.plus.settings.preferences.MultiSelectBooleanPreference)4 ApplicationMode (net.osmand.plus.settings.backend.ApplicationMode)3 BooleanPreference (net.osmand.plus.settings.backend.preferences.BooleanPreference)2 ListPreferenceEx (net.osmand.plus.settings.preferences.ListPreferenceEx)2 SwitchPreferenceEx (net.osmand.plus.settings.preferences.SwitchPreferenceEx)2 RoutingParameter (net.osmand.router.GeneralRouter.RoutingParameter)2 SuppressLint (android.annotation.SuppressLint)1 SpannableString (android.text.SpannableString)1 FragmentManager (androidx.fragment.app.FragmentManager)1 EditTextPreference (androidx.preference.EditTextPreference)1 Preference (androidx.preference.Preference)1 PreferenceScreen (androidx.preference.PreferenceScreen)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Set (java.util.Set)1 OsmandApplication (net.osmand.plus.OsmandApplication)1 CommonPreference (net.osmand.plus.settings.backend.preferences.CommonPreference)1 OsmandPreference (net.osmand.plus.settings.backend.preferences.OsmandPreference)1 GeneralRouter (net.osmand.router.GeneralRouter)1