Search in sources :

Example 21 with ListPreferenceEx

use of net.osmand.plus.settings.preferences.ListPreferenceEx 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 22 with ListPreferenceEx

use of net.osmand.plus.settings.preferences.ListPreferenceEx in project Osmand by osmandapp.

the class RouteParametersFragment method createRoutingBooleanListPreference.

private ListPreferenceEx createRoutingBooleanListPreference(String groupKey, List<RoutingParameter> routingParameters) {
    String defaultTitle = Algorithms.capitalizeFirstLetterAndLowercase(groupKey.replace('_', ' '));
    String title = AndroidUtils.getRoutingStringPropertyName(app, groupKey, defaultTitle);
    String description = AndroidUtils.getRoutingStringPropertyDescription(app, groupKey, "");
    ApplicationMode am = getSelectedAppMode();
    Object[] entryValues = new Object[routingParameters.size()];
    String[] entries = new String[entryValues.length];
    String selectedParameterId = null;
    for (int i = 0; i < routingParameters.size(); i++) {
        RoutingParameter parameter = routingParameters.get(i);
        entryValues[i] = parameter.getId();
        entries[i] = getRoutingParameterTitle(app, parameter);
        if (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));
    if (!Algorithms.isEmpty(defaultTitle)) {
        routingListPref.setDescription(description);
    }
    return routingListPref;
}
Also used : RoutingParameter(net.osmand.router.GeneralRouter.RoutingParameter) ListPreferenceEx(net.osmand.plus.settings.preferences.ListPreferenceEx) ApplicationMode(net.osmand.plus.settings.backend.ApplicationMode)

Example 23 with ListPreferenceEx

use of net.osmand.plus.settings.preferences.ListPreferenceEx in project Osmand by osmandapp.

the class VoiceAnnouncesFragment method setupAudioStreamGuidancePref.

private void setupAudioStreamGuidancePref() {
    String[] streamTypes = new String[] { getString(R.string.voice_stream_music), getString(R.string.voice_stream_notification), getString(R.string.voice_stream_voice_call) };
    // getString(R.string.shared_string_default)};
    Integer[] streamIntTypes = new Integer[] { AudioManager.STREAM_MUSIC, AudioManager.STREAM_NOTIFICATION, AudioManager.STREAM_VOICE_CALL };
    // AudioManager.USE_DEFAULT_STREAM_TYPE};
    ListPreferenceEx audioStreamGuidance = createListPreferenceEx(settings.AUDIO_MANAGER_STREAM.getId(), streamTypes, streamIntTypes, R.string.choose_audio_stream, R.layout.preference_with_descr);
    getPreferenceScreen().addPreference(audioStreamGuidance);
}
Also used : ListPreferenceEx(net.osmand.plus.settings.preferences.ListPreferenceEx)

Example 24 with ListPreferenceEx

use of net.osmand.plus.settings.preferences.ListPreferenceEx in project Osmand by osmandapp.

the class AccessibilitySettingsFragment method setupSpeechRatePref.

private void setupSpeechRatePref() {
    Float[] entryValues = new Float[] { 0.5f, 0.75f, 1f, 1.25f, 1.5f, 2f };
    String[] entries = new String[entryValues.length];
    for (int i = 0; i < entries.length; i++) {
        entries[i] = (int) (entryValues[i] * 100) + " %";
    }
    ListPreferenceEx speechRate = (ListPreferenceEx) findPreference(settings.SPEECH_RATE.getId());
    speechRate.setEntries(entries);
    speechRate.setEntryValues(entryValues);
    speechRate.setIcon(getContentIcon(R.drawable.ic_world_globe_dark));
    speechRate.setDescription(R.string.speech_rate_descr);
}
Also used : ListPreferenceEx(net.osmand.plus.settings.preferences.ListPreferenceEx)

Example 25 with ListPreferenceEx

use of net.osmand.plus.settings.preferences.ListPreferenceEx in project Osmand by osmandapp.

the class AccessibilitySettingsFragment method setupAccessibilityModePref.

private void setupAccessibilityModePref() {
    AccessibilityMode[] accessibilityModes = AccessibilityMode.values();
    String[] entries = new String[accessibilityModes.length];
    Integer[] entryValues = new Integer[accessibilityModes.length];
    for (int i = 0; i < entries.length; i++) {
        entries[i] = accessibilityModes[i].toHumanString(app);
        entryValues[i] = accessibilityModes[i].ordinal();
    }
    ListPreferenceEx accessibilityMode = (ListPreferenceEx) findPreference(settings.ACCESSIBILITY_MODE.getId());
    accessibilityMode.setEntries(entries);
    accessibilityMode.setEntryValues(entryValues);
    accessibilityMode.setIcon(getPersistentPrefIcon(R.drawable.ic_action_android));
    accessibilityMode.setDescription(R.string.accessibility_mode_descr);
}
Also used : ListPreferenceEx(net.osmand.plus.settings.preferences.ListPreferenceEx)

Aggregations

ListPreferenceEx (net.osmand.plus.settings.preferences.ListPreferenceEx)41 SpannableString (android.text.SpannableString)13 ArrayList (java.util.ArrayList)5 ApplicationMode (net.osmand.plus.settings.backend.ApplicationMode)4 SpannableStringBuilder (android.text.SpannableStringBuilder)3 Camera (android.hardware.Camera)2 MultiSelectBooleanPreference (net.osmand.plus.settings.preferences.MultiSelectBooleanPreference)2 SwitchPreferenceEx (net.osmand.plus.settings.preferences.SwitchPreferenceEx)2 RoutingParameter (net.osmand.router.GeneralRouter.RoutingParameter)2 Context (android.content.Context)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 FragmentManager (androidx.fragment.app.FragmentManager)1 EditTextPreference (androidx.preference.EditTextPreference)1 Preference (androidx.preference.Preference)1 PreferenceScreen (androidx.preference.PreferenceScreen)1 Map (java.util.Map)1 OsmandApplication (net.osmand.plus.OsmandApplication)1 BooleanPreference (net.osmand.plus.settings.backend.preferences.BooleanPreference)1 CommonPreference (net.osmand.plus.settings.backend.preferences.CommonPreference)1