Search in sources :

Example 1 with SwitchPreferenceEx

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

the class DevelopmentSettingsFragment method setupFullscreenMapDrawingModePref.

private void setupFullscreenMapDrawingModePref() {
    SwitchPreferenceEx fullscreenMapDrawingMode = findPreference(settings.TRANSPARENT_STATUS_BAR.getId());
    fullscreenMapDrawingMode.setDescription(getString(R.string.transparent_status_bar_descr));
    fullscreenMapDrawingMode.setIconSpaceReserved(false);
}
Also used : SwitchPreferenceEx(net.osmand.plus.settings.preferences.SwitchPreferenceEx)

Example 2 with SwitchPreferenceEx

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

the class MonitoringSettingsFragment method setupDisableRecordingOnceAppKilledPref.

private void setupDisableRecordingOnceAppKilledPref() {
    SwitchPreferenceEx disableRecordingOnceAppKilled = (SwitchPreferenceEx) findPreference(settings.DISABLE_RECORDING_ONCE_APP_KILLED.getId());
    disableRecordingOnceAppKilled.setDescription(getString(R.string.disable_recording_once_app_killed_descrp));
}
Also used : SwitchPreferenceEx(net.osmand.plus.settings.preferences.SwitchPreferenceEx)

Example 3 with SwitchPreferenceEx

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

the class BooleanPreferenceBottomSheet method createMenuItems.

@Override
public void createMenuItems(Bundle savedInstanceState) {
    final OsmandApplication app = getMyApplication();
    if (app == null) {
        return;
    }
    final SwitchPreferenceEx switchPreference = getSwitchPreferenceEx();
    if (switchPreference == null) {
        return;
    }
    OsmandPreference preference = app.getSettings().getPreference(switchPreference.getKey());
    if (!(preference instanceof BooleanPreference)) {
        return;
    }
    Context themedCtx = UiUtilities.getThemedContext(app, nightMode);
    String title = switchPreference.getTitle().toString();
    items.add(new TitleItem(title));
    final BooleanPreference pref = (BooleanPreference) preference;
    CharSequence summaryOn = switchPreference.getSummaryOn();
    CharSequence summaryOff = switchPreference.getSummaryOff();
    final String on = summaryOn == null || summaryOn.toString().isEmpty() ? getString(R.string.shared_string_enabled) : summaryOn.toString();
    final String off = summaryOff == null || summaryOff.toString().isEmpty() ? getString(R.string.shared_string_disabled) : summaryOff.toString();
    final int activeColor = AndroidUtils.resolveAttribute(themedCtx, R.attr.active_color_basic);
    final int disabledColor = AndroidUtils.resolveAttribute(themedCtx, android.R.attr.textColorSecondary);
    boolean checked = switchPreference.isChecked();
    final BottomSheetItemWithCompoundButton[] preferenceBtn = new BottomSheetItemWithCompoundButton[1];
    preferenceBtn[0] = (BottomSheetItemWithCompoundButton) new BottomSheetItemWithCompoundButton.Builder().setChecked(checked).setTitle(checked ? on : off).setTitleColorId(checked ? activeColor : disabledColor).setCustomView(getCustomButtonView(app, getAppMode(), checked, nightMode)).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            boolean newValue = !switchPreference.isChecked();
            Fragment targetFragment = getTargetFragment();
            if (targetFragment instanceof OnConfirmPreferenceChange) {
                ApplyQueryType applyQueryType = getApplyQueryType();
                if (applyQueryType == ApplyQueryType.SNACK_BAR) {
                    applyQueryType = ApplyQueryType.NONE;
                }
                OnConfirmPreferenceChange confirmationInterface = (OnConfirmPreferenceChange) targetFragment;
                if (confirmationInterface.onConfirmPreferenceChange(switchPreference.getKey(), newValue, applyQueryType)) {
                    switchPreference.setChecked(newValue);
                    preferenceBtn[0].setTitle(newValue ? on : off);
                    preferenceBtn[0].setChecked(newValue);
                    preferenceBtn[0].setTitleColorId(newValue ? activeColor : disabledColor);
                    updateCustomButtonView(app, getAppMode(), v, newValue, nightMode);
                    if (targetFragment instanceof OnPreferenceChanged) {
                        ((OnPreferenceChanged) targetFragment).onPreferenceChanged(switchPreference.getKey());
                    }
                }
            }
        }
    }).create();
    if (isProfileDependent()) {
        preferenceBtn[0].setCompoundButtonColor(getAppMode().getProfileColor(nightMode));
    }
    items.add(preferenceBtn[0]);
    String description = switchPreference.getDescription();
    if (description != null) {
        BaseBottomSheetItem preferenceDescription = new BottomSheetItemWithDescription.Builder().setDescription(description).setLayoutId(R.layout.bottom_sheet_item_descr).create();
        items.add(preferenceDescription);
    }
}
Also used : Context(android.content.Context) BaseBottomSheetItem(net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem) OsmandApplication(net.osmand.plus.OsmandApplication) OsmandPreference(net.osmand.plus.settings.backend.preferences.OsmandPreference) TitleItem(net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem) SwitchPreferenceEx(net.osmand.plus.settings.preferences.SwitchPreferenceEx) OnConfirmPreferenceChange(net.osmand.plus.settings.fragments.OnConfirmPreferenceChange) View(android.view.View) Fragment(androidx.fragment.app.Fragment) BottomSheetItemWithDescription(net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithDescription) BooleanPreference(net.osmand.plus.settings.backend.preferences.BooleanPreference) ApplyQueryType(net.osmand.plus.settings.fragments.ApplyQueryType) BottomSheetItemWithCompoundButton(net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithCompoundButton) OnPreferenceChanged(net.osmand.plus.settings.fragments.OnPreferenceChanged)

Example 4 with SwitchPreferenceEx

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

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

the class NavigationFragment method setupPreferences.

@Override
protected void setupPreferences() {
    navigationType = findPreference(NAVIGATION_TYPE);
    setupNavigationTypePref();
    Preference routeParameters = findPreference("route_parameters");
    SwitchPreferenceCompat showRoutingAlarms = findPreference(settings.SHOW_ROUTING_ALARMS.getId());
    SwitchPreferenceEx animateMyLocation = findPreference(settings.ANIMATE_MY_LOCATION.getId());
    routeParameters.setIcon(getContentIcon(R.drawable.ic_action_route_distance));
    showRoutingAlarms.setIcon(getPersistentPrefIcon(R.drawable.ic_action_alert));
    setupSpeakRoutingAlarmsPref();
    setupVehicleParametersPref();
    showHideCustomizeRouteLinePref();
    animateMyLocation.setDescription(getString(R.string.animate_my_location_desc));
}
Also used : Preference(androidx.preference.Preference) SwitchPreferenceCompat(androidx.preference.SwitchPreferenceCompat) SwitchPreferenceEx(net.osmand.plus.settings.preferences.SwitchPreferenceEx)

Aggregations

SwitchPreferenceEx (net.osmand.plus.settings.preferences.SwitchPreferenceEx)49 Drawable (android.graphics.drawable.Drawable)5 ApplicationMode (net.osmand.plus.settings.backend.ApplicationMode)5 OsmandApplication (net.osmand.plus.OsmandApplication)3 Context (android.content.Context)2 View (android.view.View)2 Fragment (androidx.fragment.app.Fragment)2 Preference (androidx.preference.Preference)2 BaseBottomSheetItem (net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem)2 BottomSheetItemWithCompoundButton (net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithCompoundButton)2 TitleItem (net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem)2 BooleanPreference (net.osmand.plus.settings.backend.preferences.BooleanPreference)2 OsmandPreference (net.osmand.plus.settings.backend.preferences.OsmandPreference)2 OnConfirmPreferenceChange (net.osmand.plus.settings.fragments.OnConfirmPreferenceChange)2 ListPreferenceEx (net.osmand.plus.settings.preferences.ListPreferenceEx)2 MultiSelectBooleanPreference (net.osmand.plus.settings.preferences.MultiSelectBooleanPreference)2 TextView (android.widget.TextView)1 FragmentManager (androidx.fragment.app.FragmentManager)1 EditTextPreference (androidx.preference.EditTextPreference)1 PreferenceScreen (androidx.preference.PreferenceScreen)1