Java Code Examples for androidx.preference.SwitchPreference#setOnPreferenceChangeListener()

The following examples show how to use androidx.preference.SwitchPreference#setOnPreferenceChangeListener() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AutoInputSettingsFragment.java    From SmsCode with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onCreatePreferences(Bundle bundle, String s) {
    addPreferencesFromResource(R.xml.settings_auto_input_code);

    SwitchPreference autoInputEnablePref = findPreference(ENABLE_AUTO_INPUT_CODE);
    autoInputEnablePref.setOnPreferenceChangeListener(this);

    mAutoInputModePref = findPreference(AUTO_INPUT_MODE);
    mAutoInputModePref.setOnPreferenceChangeListener(this);
    mAutoInputMode = mAutoInputModePref.getValue();

    ListPreference focusModePref = findPreference(FOCUS_MODE);
    focusModePref.setOnPreferenceChangeListener(this);
    mFocusMode = focusModePref.getValue();

    mManualFocusIfFailedPref = findPreference(MANUAL_FOCUS_IF_FAILED);

    refreshEnableAutoInputPreference(autoInputEnablePref.isChecked());
    refreshAutoInputModePreference(mAutoInputMode);
    refreshFocusModePreference(focusModePref, focusModePref.getValue());
    refreshManualFocusIfFailedPreference();
}
 
Example 2
Source File: GesturesAndButtonsPreferenceFragment.java    From Infinity-For-Reddit with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
    setPreferencesFromResource(R.xml.gestures_and_buttons_preference, rootKey);
    ((Infinity) activity.getApplication()).getAppComponent().inject(this);

    SwitchPreference lockJumpToNextTopLevelCommentButtonSwitch =
            findPreference(SharedPreferencesUtils.LOCK_JUMP_TO_NEXT_TOP_LEVEL_COMMENT_BUTTON);
    SwitchPreference lockBottomAppBarSwitch = findPreference(SharedPreferencesUtils.LOCK_BOTTOM_APP_BAR);
    SwitchPreference swipeUpToHideJumpToNextTopLevelCommentButtonSwitch =
            findPreference(SharedPreferencesUtils.SWIPE_UP_TO_HIDE_JUMP_TO_NEXT_TOP_LEVEL_COMMENT_BUTTON);

    if (lockJumpToNextTopLevelCommentButtonSwitch != null && lockBottomAppBarSwitch != null &&
            swipeUpToHideJumpToNextTopLevelCommentButtonSwitch != null) {
        lockJumpToNextTopLevelCommentButtonSwitch.setOnPreferenceChangeListener((preference, newValue) -> {
            if ((Boolean) newValue) {
                swipeUpToHideJumpToNextTopLevelCommentButtonSwitch.setVisible(false);
            } else {
                swipeUpToHideJumpToNextTopLevelCommentButtonSwitch.setVisible(true);
            }
            return true;
        });

        if (sharedPreferences.getBoolean(SharedPreferencesUtils.BOTTOM_APP_BAR_KEY, false)) {
            lockBottomAppBarSwitch.setVisible(true);
            lockBottomAppBarSwitch.setOnPreferenceChangeListener((preference, newValue) -> {
                EventBus.getDefault().post(new ChangeLockBottomAppBarEvent((Boolean) newValue));
                return true;
            });
        }

        if (!sharedPreferences.getBoolean(SharedPreferencesUtils.LOCK_JUMP_TO_NEXT_TOP_LEVEL_COMMENT_BUTTON, false)) {
            swipeUpToHideJumpToNextTopLevelCommentButtonSwitch.setVisible(true);
        }
    }
}
 
Example 3
Source File: VideoPreferenceFragment.java    From Infinity-For-Reddit with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
    setPreferencesFromResource(R.xml.video_preferences, rootKey);

    ListPreference videoAutoplayListPreference = findPreference(SharedPreferencesUtils.VIDEO_AUTOPLAY);
    SwitchPreference muteAutoplayingVideosSwitchPreference = findPreference(SharedPreferencesUtils.MUTE_AUTOPLAYING_VIDEOS);
    SwitchPreference autoplayNsfwVideosSwitchPreference = findPreference(SharedPreferencesUtils.AUTOPLAY_NSFW_VIDEOS);

    if (videoAutoplayListPreference != null && autoplayNsfwVideosSwitchPreference != null) {
        videoAutoplayListPreference.setOnPreferenceChangeListener((preference, newValue) -> {
            EventBus.getDefault().post(new ChangeVideoAutoplayEvent((String) newValue));
            return true;
        });

        autoplayNsfwVideosSwitchPreference.setOnPreferenceChangeListener((preference, newValue) -> {
            EventBus.getDefault().post(new ChangeAutoplayNsfwVideosEvent((Boolean) newValue));
            return true;
        });
    }

    if (muteAutoplayingVideosSwitchPreference != null) {
        muteAutoplayingVideosSwitchPreference.setOnPreferenceChangeListener((preference, newValue) -> {
            EventBus.getDefault().post(new ChangeMuteAutoplayingVideosEvent((Boolean) newValue));
            return true;
        });
    }
}
 
Example 4
Source File: ImmersiveInterfacePreferenceFragment.java    From Infinity-For-Reddit with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
    setPreferencesFromResource(R.xml.immersive_interface_preferences, rootKey);

    SwitchPreference immersiveInterfaceSwitch = findPreference(SharedPreferencesUtils.IMMERSIVE_INTERFACE_KEY);
    SwitchPreference immersiveInterfaceIgnoreNavBarSwitch = findPreference(SharedPreferencesUtils.IMMERSIVE_INTERFACE_IGNORE_NAV_BAR_KEY);

    if (immersiveInterfaceSwitch != null && immersiveInterfaceIgnoreNavBarSwitch != null) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            immersiveInterfaceSwitch.setVisible(true);
            immersiveInterfaceSwitch.setOnPreferenceChangeListener((preference, newValue) -> {
                if ((Boolean) newValue) {
                    immersiveInterfaceIgnoreNavBarSwitch.setVisible(true);
                } else {
                    immersiveInterfaceIgnoreNavBarSwitch.setVisible(false);
                }
                EventBus.getDefault().post(new RecreateActivityEvent());
                return true;
            });

            if (immersiveInterfaceSwitch.isChecked()) {
                immersiveInterfaceIgnoreNavBarSwitch.setVisible(true);
            } else {
                immersiveInterfaceIgnoreNavBarSwitch.setVisible(false);
            }

            immersiveInterfaceIgnoreNavBarSwitch.setOnPreferenceChangeListener((preference, newValue) -> {
                EventBus.getDefault().post(new RecreateActivityEvent());
                return true;
            });
        } else {
            immersiveInterfaceSwitch.setVisible(false);
            immersiveInterfaceIgnoreNavBarSwitch.setVisible(false);
        }
    }
}
 
Example 5
Source File: ProfilePolicyManagementFragment.java    From android-testdpc with Apache License 2.0 5 votes vote down vote up
private void initSwitchPreferences() {
    mDisableBluetoothContactSharingSwitchPreference = (SwitchPreference) findPreference(
            DISABLE_BLUETOOTH_CONTACT_SHARING_KEY);
    mDisableCrossProfileCallerIdSwitchPreference = (SwitchPreference) findPreference(
            DISABLE_CROSS_PROFILE_CALLER_ID_KEY);
    mDisableCrossProfileContactsSearchSwitchPreference = (SwitchPreference) findPreference(
            DISABLE_CROSS_PROFILE_CONTACTS_SEARCH_KEY);
    mDisableBluetoothContactSharingSwitchPreference.setOnPreferenceChangeListener(this);
    mDisableCrossProfileCallerIdSwitchPreference.setOnPreferenceChangeListener(this);
    mDisableCrossProfileContactsSearchSwitchPreference.setOnPreferenceChangeListener(this);
    reloadBluetoothContactSharing();
    reloadCrossProfileCallerIdDisableUi();
}
 
Example 6
Source File: OverrideApnFragment.java    From android-testdpc with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
    addPreferencesFromResource(R.xml.override_apn_preferences);

    findPreference(INSERT_OVERRIDE_APN_KEY).setOnPreferenceClickListener(this);
    findPreference(REMOVE_OVERRIDE_APN_KEY).setOnPreferenceClickListener(this);
    mEnableOverrideApnPreference = (SwitchPreference) findPreference(ENABLE_OVERRIDE_APN_KEY);
    mEnableOverrideApnPreference.setOnPreferenceChangeListener(this);
}
 
Example 7
Source File: MainPreferenceFragment.java    From Infinity-For-Reddit with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
    setPreferencesFromResource(R.xml.main_preferences, rootKey);
    ((Infinity) activity.getApplication()).getAppComponent().inject(this);

    SwitchPreference confirmToExitSwitch = findPreference(SharedPreferencesUtils.CONFIRM_TO_EXIT);
    SwitchPreference nsfwSwitch = findPreference(SharedPreferencesUtils.NSFW_KEY);
    SwitchPreference blurNSFWSwitch = findPreference(SharedPreferencesUtils.BLUR_NSFW_KEY);
    SwitchPreference blurSpoilerSwitch = findPreference(SharedPreferencesUtils.BLUR_SPOILER_KEY);

    if (confirmToExitSwitch != null) {
        confirmToExitSwitch.setOnPreferenceChangeListener((preference, newValue) -> {
            EventBus.getDefault().post(new RecreateActivityEvent());
            return true;
        });
    }

    if (nsfwSwitch != null) {
        nsfwSwitch.setOnPreferenceChangeListener((preference, newValue) -> {
            EventBus.getDefault().post(new ChangeNSFWEvent((Boolean) newValue));
            if (blurNSFWSwitch != null) {
                blurNSFWSwitch.setVisible((Boolean) newValue);
            }
            return true;
        });
    }

    if (blurNSFWSwitch != null) {
        boolean nsfwEnabled = sharedPreferences.getBoolean(SharedPreferencesUtils.NSFW_KEY, false);

        if (nsfwEnabled) {
            blurNSFWSwitch.setVisible(true);
        } else {
            blurNSFWSwitch.setVisible(false);
        }

        blurNSFWSwitch.setOnPreferenceChangeListener((preference, newValue) -> {
            EventBus.getDefault().post(new ChangeNSFWBlurEvent((Boolean) newValue));
            return true;
        });
    }

    if (blurSpoilerSwitch != null) {
        blurSpoilerSwitch.setOnPreferenceChangeListener((preference, newValue) -> {
            EventBus.getDefault().post(new ChangeSpoilerBlurEvent((Boolean) newValue));
            return true;
        });
    }
}
 
Example 8
Source File: InterfacePreferenceFragment.java    From Infinity-For-Reddit with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
    setPreferencesFromResource(R.xml.interface_preference, rootKey);

    SwitchPreference bottomAppBarSwitch = findPreference(SharedPreferencesUtils.BOTTOM_APP_BAR_KEY);
    SwitchPreference voteButtonsOnTheRightSwitch = findPreference(SharedPreferencesUtils.VOTE_BUTTONS_ON_THE_RIGHT_KEY);
    SwitchPreference showElapsedTimeSwitch = findPreference(SharedPreferencesUtils.SHOW_ELAPSED_TIME_KEY);
    ListPreference defaultPostLayoutSwitch = findPreference(SharedPreferencesUtils.DEFAULT_POST_LAYOUT_KEY);
    SwitchPreference showDividerInCompactLayout = findPreference(SharedPreferencesUtils.SHOW_DIVIDER_IN_COMPACT_LAYOUT);
    SwitchPreference showThumbnailOnTheRightInCompactLayout = findPreference(SharedPreferencesUtils.SHOW_THUMBNAIL_ON_THE_RIGHT_IN_COMPACT_LAYOUT);
    SwitchPreference showAbsoluteNumberOfVotes = findPreference(SharedPreferencesUtils.SHOW_ABSOLUTE_NUMBER_OF_VOTES);

    if (bottomAppBarSwitch != null) {
        bottomAppBarSwitch.setOnPreferenceChangeListener((preference, newValue) -> {
            EventBus.getDefault().post(new RecreateActivityEvent());
            return true;
        });
    }

    if (voteButtonsOnTheRightSwitch != null) {
        voteButtonsOnTheRightSwitch.setOnPreferenceChangeListener((preference, newValue) -> {
            EventBus.getDefault().post(new ChangeVoteButtonsPositionEvent((Boolean) newValue));
            return true;
        });
    }

    if (showElapsedTimeSwitch != null) {
        showElapsedTimeSwitch.setOnPreferenceChangeListener((preference, newValue) -> {
            EventBus.getDefault().post(new ChangeShowElapsedTimeEvent((Boolean) newValue));
            return true;
        });
    }

    if (defaultPostLayoutSwitch != null) {
        defaultPostLayoutSwitch.setOnPreferenceChangeListener((preference, newValue) -> {
            EventBus.getDefault().post(new ChangeDefaultPostLayoutEvent(Integer.parseInt((String) newValue)));
            return true;
        });
    }

    if (showDividerInCompactLayout != null) {
        showDividerInCompactLayout.setOnPreferenceChangeListener((preference, newValue) -> {
            EventBus.getDefault().post(new ShowDividerInCompactLayoutPreferenceEvent((Boolean) newValue));
            return true;
        });
    }

    if (showThumbnailOnTheRightInCompactLayout != null) {
        showThumbnailOnTheRightInCompactLayout.setOnPreferenceChangeListener((preference, newValue) -> {
            EventBus.getDefault().post(new ShowThumbnailOnTheRightInCompactLayoutEvent((Boolean) newValue));
            return true;
        });
    }

    if (showAbsoluteNumberOfVotes != null) {
        showAbsoluteNumberOfVotes.setOnPreferenceChangeListener((preference, newValue) -> {
            EventBus.getDefault().post(new ChangeShowAbsoluteNumberOfVotesEvent((Boolean) newValue));
            return true;
        });
    }
}
 
Example 9
Source File: SettingsFragment.java    From SmsCode with GNU General Public License v3.0 4 votes vote down vote up
@Override
    public void onCreatePreferences(Bundle bundle, String s) {

        addPreferencesFromResource(R.xml.settings);

        // general groups
        mEnablePref = findPreference(PrefConst.ENABLE);
        mEnablePref.setOnPreferenceChangeListener(this);

        // listen mode preference
        ListPreference listenModePref = findPreference(LISTEN_MODE);
        listenModePref.setOnPreferenceChangeListener(this);
        mCurListenMode = listenModePref.getValue();
        refreshListenModePreference(listenModePref, mCurListenMode);

//        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
//            // hide copy to clipboard preference
//            PreferenceGroup generalGroup = findPreference(KEY_GENERAL);
//            Preference copyToClipboardPref = findPreference(COPY_TO_CLIPBOARD);
//            generalGroup.removePreference(copyToClipboardPref);
//        }

        findPreference(ENTRY_AUTO_INPUT_CODE).setOnPreferenceClickListener(this);

        Preference chooseThemePref = findPreference(PrefConst.CHOOSE_THEME);
        chooseThemePref.setOnPreferenceClickListener(this);
        initChooseThemePreference(chooseThemePref);
        // general groups end


        // experimental groups
        findPreference(MARK_AS_READ).setOnPreferenceChangeListener(this);

        findPreference(BLOCK_NOTIFICATION).setOnPreferenceChangeListener(this);

        findPreference(DELETE_SMS).setOnPreferenceChangeListener(this);
        // experimental groups end


        // code message group
        findPreference(CODE_RULES).setOnPreferenceClickListener(this);
        findPreference(SMSCODE_TEST).setOnPreferenceClickListener(this);
        // code message group end


        // code records group
        Preference recordsEntryPref = findPreference(ENTRY_CODE_RECORDS);
        recordsEntryPref.setOnPreferenceClickListener(this);
        initRecordEntryPreference(recordsEntryPref);
        // code records group end


        // others group
        // exclude from recent apps preference
        mExcludeFromRecentsPref = findPreference(EXCLUDE_FROM_RECENTS);
        mExcludeFromRecentsPref.setOnPreferenceChangeListener(this);

        // verbose log preference
        SwitchPreference verboseLogPref = findPreference(VERBOSE_LOG_MODE);
        verboseLogPref.setOnPreferenceChangeListener(this);
        refreshVerboseLogPreference(verboseLogPref, verboseLogPref.isChecked());
        // others group end


        // about group
        Preference versionPref = findPreference(VERSION);
        refreshVersionInfoPreference(versionPref);
        findPreference(SOURCE_CODE).setOnPreferenceClickListener(this);
        findPreference(RATING).setOnPreferenceClickListener(this);
        findPreference(GET_ALIPAY_PACKET).setOnPreferenceClickListener(this);
        findPreference(DONATE_BY_ALIPAY).setOnPreferenceClickListener(this);
        // about group end
    }
 
Example 10
Source File: PreferencesFragment.java    From SAI with GNU General Public License v3.0 4 votes vote down vote up
@SuppressLint("ApplySharedPref")
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
    setPreferencesFromResource(R.xml.preferences_main, rootKey);

    mHelper = PreferencesHelper.getInstance(requireContext());

    mHomeDirPref = findPreference("home_directory");
    updateHomeDirPrefSummary();
    mHomeDirPref.setOnPreferenceClickListener((p) -> {
        selectHomeDir();
        return true;
    });

    mFilePickerSortPref = findPreference("file_picker_sort");
    updateFilePickerSortSummary();
    mFilePickerSortPref.setOnPreferenceClickListener((p) -> {
        SingleChoiceListDialogFragment.newInstance(getText(R.string.settings_main_file_picker_sort), R.array.file_picker_sort_variants, mHelper.getFilePickerRawSort()).show(getChildFragmentManager(), "sort");
        return true;
    });

    findPreference("about").setOnPreferenceClickListener((p) -> {
        startActivity(new Intent(getContext(), AboutActivity.class));
        return true;
    });
    findPreference("donate").setOnPreferenceClickListener(p -> {
        startActivity(new Intent(requireContext(), DonateActivity.class));
        return true;
    });

    mInstallerPref = findPreference("installer");
    updateInstallerSummary();
    mInstallerPref.setOnPreferenceClickListener((p -> {
        SingleChoiceListDialogFragment.newInstance(getText(R.string.settings_main_installer), R.array.installers, mHelper.getInstaller()).show(getChildFragmentManager(), "installer");
        return true;
    }));

    findPreference(PreferencesKeys.BACKUP_SETTINGS).setOnPreferenceClickListener(p -> {
        startActivity(new Intent(requireContext(), BackupSettingsActivity.class));
        return true;
    });

    mThemePref = findPreference(PreferencesKeys.THEME);
    updateThemeSummary();
    mThemePref.setOnPreferenceClickListener(p -> {
        ThemeSelectionDialogFragment.newInstance(requireContext()).show(getChildFragmentManager(), "theme");
        return true;
    });
    if (Theme.getInstance(requireContext()).getThemeMode() != Theme.Mode.CONCRETE) {
        mThemePref.setVisible(false);
    }

    mAutoThemeSwitch = Objects.requireNonNull(findPreference(PreferencesKeys.AUTO_THEME));
    mAutoThemePicker = findPreference(PreferencesKeys.AUTO_THEME_PICKER);
    updateAutoThemePickerSummary();

    mAutoThemeSwitch.setOnPreferenceChangeListener((preference, newValue) -> {
        boolean value = (boolean) newValue;
        if (value) {
            if (!Utils.apiIsAtLeast(Build.VERSION_CODES.Q))
                SimpleAlertDialogFragment.newInstance(requireContext(), R.string.settings_main_auto_theme, R.string.settings_main_auto_theme_pre_q_warning).show(getChildFragmentManager(), null);

            Theme.getInstance(requireContext()).setMode(Theme.Mode.AUTO_LIGHT_DARK);
        } else {
            Theme.getInstance(requireContext()).setMode(Theme.Mode.CONCRETE);
        }

        //Hack to not mess with hiding/showing preferences manually
        requireActivity().recreate();
        return true;
    });

    mAutoThemePicker.setOnPreferenceClickListener(pref -> {
        DarkLightThemeSelectionDialogFragment.newInstance().show(getChildFragmentManager(), null);
        return true;
    });

    if (Theme.getInstance(requireContext()).getThemeMode() != Theme.Mode.AUTO_LIGHT_DARK) {
        mAutoThemePicker.setVisible(false);
    }

    SwitchPreference firebasePref = findPreference(PreferencesKeys.ENABLE_FIREBASE);
    firebasePref.setOnPreferenceChangeListener((preference, newValue) -> {
        Firebase.setDataCollectionEnabled(requireContext(), (boolean) newValue);
        return true;
    });
    if (BuildConfig.IS_FLOSS_BUILD)
        firebasePref.setVisible(false);


    getPreferenceManager().getSharedPreferences().registerOnSharedPreferenceChangeListener(this);
}
 
Example 11
Source File: SettingsFragment.java    From Mysplash with GNU Lesser General Public License v3.0 4 votes vote down vote up
private void initDisplayPart() {
    // saturation animation enabled.
    SwitchPreference saturationEnabled = findPreference(getString(R.string.key_saturation_animation_enabled));
    saturationEnabled.setOnPreferenceChangeListener((preference, newValue) -> {
        SettingsServiceIMP.getInstance(requireActivity())
                .setSaturationAnimationEnabled((Boolean) newValue);
        return true;
    });

    // saturation animation duration.
    ListPreference duration = findPreference(getString(R.string.key_saturation_animation_duration));
    duration.setSummary(
            getNameByValue(
                    ComponentFactory.getSettingsService().getSaturationAnimationDuration(),
                    R.array.saturation_animation_durations,
                    R.array.saturation_animation_duration_values
            )
    );
    duration.setOnPreferenceChangeListener((preference, newValue) -> {
        SettingsServiceIMP.getInstance(requireActivity())
                .setSaturationAnimationDuration((String) newValue);
        preference.setSummary(
                getNameByValue(
                        (String) newValue,
                        R.array.saturation_animation_durations,
                        R.array.saturation_animation_duration_values
                )
        );
        return true;
    });

    // grid list in port.
    SwitchPreference gridPort = findPreference(getString(R.string.key_grid_list_in_port));
    gridPort.setVisible(DisplayUtils.isTabletDevice(requireActivity()));
    gridPort.setOnPreferenceChangeListener((preference, newValue) -> {
        showRebootSnackbar();
        return true;
    });

    // grid list in land.
    findPreference(getString(R.string.key_grid_list_in_land)).setOnPreferenceChangeListener((p, v) -> {
        showRebootSnackbar();
        return true;
    });
}
 
Example 12
Source File: MuzeiSettingsFragment.java    From Mysplash with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.perference_muzei);

    MuzeiOptionManager manager = MuzeiOptionManager.getInstance(requireActivity());

    // muzei source.
    ListPreference source = findPreference(getString(R.string.key_muzei_source));
    source.setSummary(
            getNameByValue(
                    manager.getSource(),
                    R.array.muzei_sources,
                    R.array.muzei_source_values
            )
    );
    source.setOnPreferenceChangeListener((preference, newValue) -> {
        manager.setSource((String) newValue);
        preference.setSummary(
                getNameByValue(
                        manager.getSource(),
                        R.array.muzei_sources,
                        R.array.muzei_source_values
                )
        );

        findPreference(getString(R.string.key_muzei_collection_source)).setEnabled(
                manager.getSource().equals(MuzeiOptionManager.SOURCE_COLLECTIONS)
        );
        return true;
    });

    // screen size.
    SwitchPreference screenSizeImage = findPreference(getString(R.string.key_muzei_screen_size_image));
    int[] size = MuzeiUpdateHelper.getScreenSize(requireActivity());
    screenSizeImage.setSummaryOn(size[1] + "×" + size[0]);
    screenSizeImage.setSummaryOff(R.string.muzei_settings_title_screen_size_image_summary_off);
    screenSizeImage.setOnPreferenceChangeListener((preference, newValue) -> {
        manager.setScreenSizeImage((Boolean) newValue);
        return true;
    });

    // cache mode.
    ListPreference cacheMode = findPreference(getString(R.string.key_muzei_cache_mode));
    cacheMode.setSummary(
            getNameByValue(
                    manager.getCacheMode(),
                    R.array.muzei_cache_modes,
                    R.array.muzei_cache_mode_values
            )
    );
    cacheMode.setOnPreferenceChangeListener((preference, newValue) -> {
        manager.setCacheMode((String) newValue);
        preference.setSummary(
                getNameByValue(
                        manager.getCacheMode(),
                        R.array.muzei_cache_modes,
                        R.array.muzei_cache_mode_values
                )
        );
        return true;
    });

    // collections.
    Preference collectionSource = findPreference(getString(R.string.key_muzei_collection_source));
    collectionSource.setEnabled(manager.getSource().equals(MuzeiOptionManager.SOURCE_COLLECTIONS));
    collectionSource.setOnPreferenceClickListener(preference -> {
        ComponentFactory.getMuzeiService()
                .startMuzeiCollectionSourceConfigActivity(requireActivity());
        return true;
    });

    // query.
    Preference query = findPreference(getString(R.string.key_muzei_query));
    query.setSummary(manager.getQuery());
    query.setOnPreferenceClickListener(preference -> {
        MuzeiQueryDialog dialog = new MuzeiQueryDialog();
        dialog.setOnQueryChangedListener(query1 -> {
            MuzeiOptionManager.updateQuery(requireActivity(), query1);
            Preference q = findPreference(getString(R.string.key_muzei_query));
            q.setSummary(MuzeiOptionManager.getInstance(requireActivity()).getQuery());
        });
        dialog.show(requireFragmentManager(), null);
        return true;
    });
}