androidx.preference.SwitchPreference Java Examples

The following examples show how to use androidx.preference.SwitchPreference. 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: BaseSettingFragment.java    From hipda with GNU General Public License v2.0 5 votes vote down vote up
protected static void bindPreferenceSummaryToValue(Preference preference) {
    // Set the listener to watch for value changes.
    if (preference == null)
        return;
    preference.setOnPreferenceChangeListener(sBindPreferenceSummaryToValueListener);

    // Trigger the listener immediately with the preference's
    // current value.
    if (preference instanceof CheckBoxPreference) {
        sBindPreferenceSummaryToValueListener.onPreferenceChange(
                preference,
                PreferenceManager.getDefaultSharedPreferences(
                        preference.getContext()).getBoolean(preference.getKey(),
                        false));
    } else if (preference instanceof SwitchPreference) {
        sBindPreferenceSummaryToValueListener.onPreferenceChange(
                preference,
                PreferenceManager.getDefaultSharedPreferences(
                        preference.getContext()).getBoolean(preference.getKey(),
                        false));
    } else if (preference instanceof MultiSelectListPreference) {
        sBindPreferenceSummaryToValueListener.onPreferenceChange(
                preference,
                PreferenceManager.getDefaultSharedPreferences(
                        preference.getContext()).getStringSet(preference.getKey(),
                        new HashSet<String>()));
    } else {
        sBindPreferenceSummaryToValueListener.onPreferenceChange(
                preference,
                PreferenceManager.getDefaultSharedPreferences(
                        preference.getContext()).getString(preference.getKey(),
                        ""));
    }
}
 
Example #6
Source File: SettingsFragment.java    From SmsCode with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
    String key = preference.getKey();
    switch (key) {
        case ENABLE:
            onEnabledSwitched((Boolean) newValue);
            break;
        case LISTEN_MODE: {
            if (!newValue.equals(mCurListenMode)) {
                mCurListenMode = (String) newValue;
                refreshListenModePreference((ListPreference) preference, mCurListenMode);
                if (PrefConst.LISTEN_MODE_COMPATIBLE.equals(mCurListenMode)) {
                    showCompatibleModePrompt();
                }
            }
            break;
        }
        case MARK_AS_READ:
            showAppOpsPrompt((SwitchPreference) preference, (Boolean) newValue);
            break;
        case DELETE_SMS:
            showAppOpsPrompt((SwitchPreference) preference, (Boolean) newValue);
            break;
        case VERBOSE_LOG_MODE:
            refreshVerboseLogPreference(preference, (Boolean) newValue);
            break;
        case EXCLUDE_FROM_RECENTS:
            onExcludeFromRecentsSwitched((Boolean) newValue);
            break;
        case BLOCK_NOTIFICATION:
            onBlockNotificationSwitched((SwitchPreference) preference, (Boolean) newValue);
            break;
        default:
            return false;
    }
    return true;
}
 
Example #7
Source File: SettingsFragment.java    From SmsCode with GNU General Public License v3.0 5 votes vote down vote up
private void showAppOpsPrompt(final SwitchPreference switchPref, boolean on) {
    if (!on) {
        return;
    }

    final String packageName = BuildConfig.APPLICATION_ID;
    final int uid = Process.myUid();
    if (!AppOpsUtils.checkOp(mActivity, AppOpsUtils.OP_WRITE_SMS, uid, packageName)) {
        new MaterialDialog.Builder(mActivity)
                .title(R.string.extra_permission_request_prompt_title)
                .content(R.string.write_sms_appops_prompt_content)
                .negativeText(R.string.view_adb_setting_help)
                .onNegative((dialog, which) -> {
                    String url = Utils.getProjectDocUrl(Const.PROJECT_DOC_BASE_URL, Const.DOC_APPOPS_ADB_HELP);
                    Utils.showWebPage(mActivity, url);
                })
                .positiveText(R.string.granted_by_root)
                .onPositive((dialog, which) -> {
                    if (ShellUtils.allowOpWriteSMS()) {
                        Toast.makeText(mActivity, R.string.granted_appops_by_root_succeed, Toast.LENGTH_SHORT).show();
                    } else {
                        switchPref.setChecked(false);
                        Toast.makeText(mActivity, R.string.granted_appops_by_root_failed, Toast.LENGTH_LONG).show();
                    }
                })
                .cancelListener(dialog -> switchPref.setChecked(false)).show();
    } else {
        Toast.makeText(mActivity, R.string.relevant_permission_already_granted, Toast.LENGTH_LONG).show();
    }
}
 
Example #8
Source File: SettingsFragment.java    From SmsCode with GNU General Public License v3.0 5 votes vote down vote up
private void onBlockNotificationSwitched(final SwitchPreference switchPref, boolean on) {
    if (!on)
        return;
    if (!SettingsUtils.checkNotificationListenerEnabled(mActivity)) {
        MaterialDialog dialog = new MaterialDialog.Builder(mActivity)
                .title(R.string.permission_requirement)
                .content(R.string.notification_access_prompt_content)
                .positiveText(R.string.go_to_open)
                .onPositive((dialog1, which) -> SettingsUtils.gotoNotificationListenerSettings(mActivity))
                .negativeText(R.string.cancel)
                .cancelListener(dialog12 -> switchPref.setChecked(false))
                .build();
        dialog.show();
    }
}
 
Example #9
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 #10
Source File: SettingsFragment.java    From haven with GNU General Public License v3.0 5 votes vote down vote up
private void onRemoteNotificationParameterChange() {
    SwitchPreference switchPreference =
            (SwitchPreference) findPreference(PreferenceManager.REMOTE_NOTIFICATION_ACTIVE);

    boolean remoteNotificationActive = canSendRemoteNotification();
    preferences.setRemoteNotificationActive(remoteNotificationActive);

    switchPreference.setChecked(remoteNotificationActive);
}
 
Example #11
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 #12
Source File: SettingsFragment.java    From c3nav-android with Apache License 2.0 4 votes vote down vote up
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
    setPreferencesFromResource(R.xml.preferences, rootKey);

    useWifiLocating = (CheckBoxPreference)this.findPreference(getString(R.string.use_wifi_locating_key));
    sharePrefs = PreferenceManager.getDefaultSharedPreferences(getContext());
    if (sharePrefs.getBoolean(getString(R.string.use_wifi_locating_key), true) && !checkLocationPermisson()) {
        useWifiLocating.setChecked(false);
    }
    useWifiLocating.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            if (!(boolean)newValue) {
                // always let user disable wifi locating
                return true;
            }

            boolean permissionAsked = false;
            while (permissionAsked == false) {
                if (checkLocationPermisson()) {
                    return true;
                }
                permissionAsked = true;
                ActivityCompat.requestPermissions(getActivity(),
                        new String[]{Manifest.permission.ACCESS_FINE_LOCATION},
                        MainActivity.PERM_REQUEST);
            }
            return false;
        }
    });

    developerSettings = (PreferenceCategory)findPreference(getString(R.string.developer_settings_key));
    developerModeEnabled = (SwitchPreference)findPreference(getString(R.string.developer_mode_enabled_key));
    developerInstanceUrl = (EditTextPreference)findPreference(getString(R.string.developer_instance_url_key));
    developerHttpUser = (EditTextPreference)findPreference(getString(R.string.developer_http_user_key));
    developerHttpPassword = (EditTextPreference)findPreference(getString(R.string.developer_http_password_key));

    developerSettings.setVisible(BuildConfig.DEBUG);
    developerModeEnabled.setVisible(BuildConfig.DEBUG);
    developerInstanceUrl.setVisible(BuildConfig.DEBUG);
    developerHttpUser.setVisible(BuildConfig.DEBUG);
    developerHttpPassword.setVisible(BuildConfig.DEBUG);
}
 
Example #13
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 #14
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;
    });
}
 
Example #15
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 #16
Source File: NotificationPreferenceFragment.java    From intra42 with Apache License 2.0 4 votes vote down vote up
private void updateCheckBoxSyncCalendarEnabled() {
    boolean enabled = AppSettings.Notifications.getCalendarSyncEnable(requireContext());
    final SwitchPreference prefCalendar = findPreference(AppSettings.Notifications.ENABLE_CALENDAR);
    prefCalendar.setChecked(enabled);
    updateCalendarList();
}
 
Example #17
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 #18
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 #19
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 #20
Source File: SettingsFragment.java    From haven with GNU General Public License v3.0 3 votes vote down vote up
protected void save() {
    preferences.activateAccelerometer(true);

    preferences.activateCamera(true);

    preferences.activateMicrophone(true);

    setPhoneNumber();

    boolean videoMonitoringActive = ((SwitchPreference) findPreference(mActivity.getResources().getString(R.string.video_active_preference_key))).isChecked();

    preferences.setActivateVideoMonitoring(videoMonitoringActive);

    boolean remoteNotificationActive =
            ((SwitchPreference) findPreference(PreferenceManager.REMOTE_NOTIFICATION_ACTIVE)).isChecked();
    preferences.setRemoteNotificationActive(remoteNotificationActive);

    boolean remoteAccessActive = ((SwitchPreference) findPreference(PreferenceManager.REMOTE_ACCESS_ACTIVE)).isChecked();

    preferences.activateRemoteAccess(remoteAccessActive);
    String password = ((EditTextPreference) findPreference(PreferenceManager.REMOTE_ACCESS_CRED)).getText();

    if (checkValidStrings(password, preferences.getRemoteAccessCredential()) && (TextUtils.isEmpty(preferences.getRemoteAccessCredential()) || !password.trim().equals(preferences.getRemoteAccessCredential().trim()))) {
        preferences.setRemoteAccessCredential(password.trim());
        app.stopServer();
        app.startServer();
    }

    preferences.setVoiceVerification(false);

    boolean heartbeatMonitorActive = ((SwitchPreference) findPreference(PreferenceManager.HEARTBEAT_MONITOR_ACTIVE)).isChecked();

    preferences.activateHeartbeat(heartbeatMonitorActive);

    mActivity.setResult(AppCompatActivity.RESULT_OK);
    mActivity.finish();
}