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

The following examples show how to use androidx.preference.CheckBoxPreference#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: AdvancedPreferenceFragment.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
private void initializePushMessagingToggle() {
  CheckBoxPreference preference = (CheckBoxPreference)this.findPreference(PUSH_MESSAGING_PREF);

  if (TextSecurePreferences.isPushRegistered(getActivity())) {
    preference.setChecked(true);
    preference.setSummary(TextSecurePreferences.getLocalNumber(getActivity()));
  } else {
    preference.setChecked(false);
    preference.setSummary(R.string.preferences__free_private_messages_and_calls);
  }

  preference.setOnPreferenceChangeListener(new PushMessagingClickListener());
}
 
Example 2
Source File: ChatsPreferenceFragment.java    From deltachat-android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onCreate(Bundle paramBundle) {
  super.onCreate(paramBundle);

  mediaQuality = (ListPreference) this.findPreference("pref_compression");
  mediaQuality.setOnPreferenceChangeListener((preference, newValue) -> {
    updateListSummary(preference, newValue);
    dcContext.setConfigInt(DcHelper.CONFIG_MEDIA_QUALITY, Util.objectToInt(newValue));
    return true;
  });

  showEmails = (ListPreference) this.findPreference("pref_show_emails");
  showEmails.setOnPreferenceChangeListener((preference, newValue) -> {
    updateListSummary(preference, newValue);
    dcContext.setConfigInt(CONFIG_SHOW_EMAILS, Util.objectToInt(newValue));
    return true;
  });

  readReceiptsCheckbox = (CheckBoxPreference) this.findPreference("pref_read_receipts");
  readReceiptsCheckbox.setOnPreferenceChangeListener(new ReadReceiptToggleListener());

  this.findPreference("preference_category_blocked").setOnPreferenceClickListener(new BlockedContactsClickListener());

  Preference backup = this.findPreference("pref_backup");
  backup.setOnPreferenceClickListener(new BackupListener());

  autoDelDevice = findPreference("autodel_device");
  autoDelDevice.setOnPreferenceChangeListener(new AutodelChangeListener("delete_device_after"));

  autoDelServer = findPreference("autodel_server");
  autoDelServer.setOnPreferenceChangeListener(new AutodelChangeListener("delete_server_after"));
}
 
Example 3
Source File: SettingsFragment.java    From Shelter with Do What The F*ck You Want To Public License 4 votes vote down vote up
@Override
public void onCreatePreferences(Bundle bundle, String s) {
    addPreferencesFromResource(R.xml.preferences_settings);
    mServiceWork = IShelterService.Stub.asInterface(
            ((Bundle) getActivity().getIntent().getParcelableExtra("extras")).getBinder("profile_service"));

    // Set the displayed version
    try {
        findPreference(SETTINGS_VERSION).setSummary(
                getContext().getPackageManager().getPackageInfo(
                        getContext().getPackageName(), 0).versionName);
    } catch (PackageManager.NameNotFoundException e) {
        // WTF?
    }

    // Open source code url on click
    findPreference(SETTINGS_SOURCE_CODE)
            .setOnPreferenceClickListener(this::openSummaryUrl);
    findPreference(SETTINGS_BUG_REPORT)
            .setOnPreferenceClickListener(this::openSummaryUrl);
    findPreference(SETTINGS_PATREON)
            .setOnPreferenceClickListener(this::openSummaryUrl);

    // === Interactions ===
    mPrefCrossProfileFileChooser = (CheckBoxPreference) findPreference(SETTINGS_CROSS_PROFILE_FILE_CHOOSER);
    mPrefCrossProfileFileChooser.setChecked(mManager.getCrossProfileFileChooserEnabled());
    mPrefCrossProfileFileChooser.setOnPreferenceChangeListener(this);
    mPrefCameraProxy = (CheckBoxPreference) findPreference(SETTINGS_CAMERA_PROXY);
    mPrefCameraProxy.setChecked(mManager.getCameraProxyEnabled());
    mPrefCameraProxy.setOnPreferenceChangeListener(this);

    // === Services ===
    mPrefAutoFreezeService = (CheckBoxPreference) findPreference(SETTINGS_AUTO_FREEZE_SERVICE);
    mPrefAutoFreezeService.setChecked(mManager.getAutoFreezeServiceEnabled());
    mPrefAutoFreezeService.setOnPreferenceChangeListener(this);
    mPrefAutoFreezeDelay = findPreference(SETTINGS_AUTO_FREEZE_DELAY);
    mPrefAutoFreezeDelay.setOnPreferenceClickListener(this::openAutoFreezeDelayPicker);
    updateAutoFreezeDelay();
    mPrefSkipForeground = (CheckBoxPreference) findPreference(SETTINGS_SKIP_FOREGROUND);
    mPrefSkipForeground.setChecked(mManager.getSkipForegroundEnabled());
    mPrefSkipForeground.setOnPreferenceChangeListener(this);

    // Disable FileSuttle on Q for now
    // TODO: Refactor FileShuttle and remove this
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
        mPrefCrossProfileFileChooser.setEnabled(false);
    }
}
 
Example 4
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);
}