Search in sources :

Example 1 with OnPreferenceChanged

use of net.osmand.plus.settings.fragments.OnPreferenceChanged 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 2 with OnPreferenceChanged

use of net.osmand.plus.settings.fragments.OnPreferenceChanged in project Osmand by osmandapp.

the class WakeTimeBottomSheet method onRightBottomButtonClick.

@Override
protected void onRightBottomButtonClick() {
    if (keepScreenOnEnabled) {
        selectedEntryIndex = 0;
    }
    Object[] entryValues = listPreference.getEntryValues();
    if (entryValues != null && selectedEntryIndex >= 0) {
        Object value = entryValues[selectedEntryIndex];
        if (listPreference.callChangeListener(value)) {
            listPreference.setValue(value);
        }
        Fragment target = getTargetFragment();
        if (target instanceof OnPreferenceChanged) {
            ((OnPreferenceChanged) target).onPreferenceChanged(listPreference.getKey());
        }
    }
    dismiss();
}
Also used : Fragment(androidx.fragment.app.Fragment) OnPreferenceChanged(net.osmand.plus.settings.fragments.OnPreferenceChanged)

Example 3 with OnPreferenceChanged

use of net.osmand.plus.settings.fragments.OnPreferenceChanged in project Osmand by osmandapp.

the class AnnouncementTimeBottomSheet method onRightBottomButtonClick.

@Override
protected void onRightBottomButtonClick() {
    Object[] entryValues = listPreference.getEntryValues();
    if (entryValues != null && selectedEntryIndex >= 0) {
        Object value = entryValues[selectedEntryIndex];
        if (listPreference.callChangeListener(value)) {
            listPreference.setValue(value);
        }
        Fragment target = getTargetFragment();
        if (target instanceof OnPreferenceChanged) {
            ((OnPreferenceChanged) target).onPreferenceChanged(listPreference.getKey());
        }
    }
    dismiss();
}
Also used : Fragment(androidx.fragment.app.Fragment) OnPreferenceChanged(net.osmand.plus.settings.fragments.OnPreferenceChanged)

Example 4 with OnPreferenceChanged

use of net.osmand.plus.settings.fragments.OnPreferenceChanged in project Osmand by osmandapp.

the class EditTextPreferenceBottomSheet method onRightBottomButtonClick.

@Override
protected void onRightBottomButtonClick() {
    EditTextPreferenceEx editTextPreference = getEditTextPreference();
    if (editTextPreference != null) {
        String value = editText.getText().toString();
        if (editTextPreference.callChangeListener(value)) {
            editTextPreference.setText(value);
            Fragment target = getTargetFragment();
            if (target instanceof OnPreferenceChanged) {
                ((OnPreferenceChanged) target).onPreferenceChanged(editTextPreference.getKey());
            }
        }
    }
    dismiss();
}
Also used : Fragment(androidx.fragment.app.Fragment) OnPreferenceChanged(net.osmand.plus.settings.fragments.OnPreferenceChanged) EditTextPreferenceEx(net.osmand.plus.settings.preferences.EditTextPreferenceEx)

Example 5 with OnPreferenceChanged

use of net.osmand.plus.settings.fragments.OnPreferenceChanged in project Osmand by osmandapp.

the class MultiSelectPreferencesBottomSheet method onRightBottomButtonClick.

@Override
protected void onRightBottomButtonClick() {
    if (prefChanged) {
        final Set<String> values = enabledPrefs;
        if (multiSelectBooleanPreference.callChangeListener(values)) {
            multiSelectBooleanPreference.setValues(values);
            Fragment target = getTargetFragment();
            if (target instanceof OnPreferenceChanged) {
                ((OnPreferenceChanged) target).onPreferenceChanged(multiSelectBooleanPreference.getKey());
            }
        }
    }
    prefChanged = false;
    dismiss();
}
Also used : Fragment(androidx.fragment.app.Fragment) OnPreferenceChanged(net.osmand.plus.settings.fragments.OnPreferenceChanged)

Aggregations

Fragment (androidx.fragment.app.Fragment)7 OnPreferenceChanged (net.osmand.plus.settings.fragments.OnPreferenceChanged)7 Context (android.content.Context)1 View (android.view.View)1 OsmandApplication (net.osmand.plus.OsmandApplication)1 MenuBottomSheetDialogFragment (net.osmand.plus.base.MenuBottomSheetDialogFragment)1 BaseBottomSheetItem (net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem)1 BottomSheetItemWithCompoundButton (net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithCompoundButton)1 BottomSheetItemWithDescription (net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithDescription)1 TitleItem (net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem)1 BooleanPreference (net.osmand.plus.settings.backend.preferences.BooleanPreference)1 OsmandPreference (net.osmand.plus.settings.backend.preferences.OsmandPreference)1 ApplyQueryType (net.osmand.plus.settings.fragments.ApplyQueryType)1 OnConfirmPreferenceChange (net.osmand.plus.settings.fragments.OnConfirmPreferenceChange)1 EditTextPreferenceEx (net.osmand.plus.settings.preferences.EditTextPreferenceEx)1 SwitchPreferenceEx (net.osmand.plus.settings.preferences.SwitchPreferenceEx)1