androidx.preference.CheckBoxPreference Java Examples

The following examples show how to use androidx.preference.CheckBoxPreference. 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: ReminderPreferences.java    From openScale with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
    setPreferencesFromResource(R.xml.reminder_preferences, rootKey);

    setHasOptionsMenu(true);

    reminderEnable = (CheckBoxPreference) findPreference(PREFERENCE_KEY_REMINDER_ENABLE);

    final MultiSelectListPreference prefDays = findPreference("reminderWeekdays");

    prefDays.setSummaryProvider(new Preference.SummaryProvider<MultiSelectListPreference>() {
        @Override
        public CharSequence provideSummary(MultiSelectListPreference preference) {
            return preference.getValues().toString();
        }
    });

    updateAlarmPreferences();
}
 
Example #2
Source File: AdvancedPreferenceFragment.java    From deltachat-android with GNU General Public License v3.0 6 votes vote down vote up
private boolean handleImapCheck(Preference preference, Object newValue, String dc_config_name) {
  final boolean newEnabled = (Boolean) newValue;
  if(newEnabled) {
    dcContext.stopIo();
    dcContext.setConfigInt(dc_config_name, 1);
    dcContext.maybeStartIo();
    return true;
  }
  else {
    new AlertDialog.Builder(getContext())
      .setMessage(R.string.pref_imap_folder_warn_disable_defaults)
      .setPositiveButton(R.string.ok, (dialogInterface, i) -> {
        dcContext.stopIo();
        dcContext.setConfigInt(dc_config_name, 0);
        ((CheckBoxPreference)preference).setChecked(false);
        dcContext.maybeStartIo();
      })
      .setNegativeButton(R.string.cancel, null)
      .show();
    return false;
  }

}
 
Example #3
Source File: PreferenceOnCheckOnSubscribe.java    From aptoide-client-v8 with GNU General Public License v3.0 6 votes vote down vote up
@Override public void call(Subscriber<? super Boolean> subscriber) {
  verifyMainThread();

  Preference.OnPreferenceClickListener listener = new Preference.OnPreferenceClickListener() {
    @Override public boolean onPreferenceClick(Preference preference) {
      if (!subscriber.isUnsubscribed()) {
        subscriber.onNext(((CheckBoxPreference) preference).isChecked());
        return true;
      }
      return true;
    }
  };

  subscriber.add(new MainThreadSubscription() {
    @Override protected void onUnsubscribe() {
      preference.setOnPreferenceClickListener(null);
    }
  });

  preference.setOnPreferenceClickListener(listener);
}
 
Example #4
Source File: EnabledApplicationsPreferenceFragment.java    From an2linuxclient with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onSharedPreferenceChanged(SharedPreferences sp, String key) {
    boolean newSettingsValue = sp.getBoolean(key, false);
    String prefEnableDisableAllKey = getString(R.string.preference_enable_disable_all_applications);
    if (key.equals(prefEnableDisableAllKey)) {
        final PreferenceScreen prefScreen = findPreference(getString(R.string.enabled_apps_pref_screen));
        for (int i = 1; i < prefScreen.getPreferenceCount(); i++) {
            ((CheckBoxPreference) (prefScreen.getPreference(i))).setChecked(newSettingsValue);
        }
    }

    // If newSettingsValue == false, clear it from SharedPreferences file to save up some space.
    // Since AN2Linux will default to false if the setting is not found.
    if (!newSettingsValue) {
        sp.edit().remove(key).apply();
    }
}
 
Example #5
Source File: EnabledApplicationsPreferenceFragment.java    From an2linuxclient with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    EnabledApplicationsViewModel viewModel = ViewModelProviders.of(getActivity()).get(EnabledApplicationsViewModel.class);
    viewModel.getFilteredCheckBoxPrefsData().observe(getViewLifecycleOwner(), checkBoxPreferencesData -> {
        setPreferencesFromResource(R.xml.enabled_applications_preferences, null);
        PreferenceScreen prefScreen = (PreferenceScreen) findPreference(getString(R.string.enabled_apps_pref_screen));
        for (CheckBoxPreferenceData checkBoxPreferenceData : checkBoxPreferencesData) {
            CheckBoxPreference c = new CheckBoxPreference(getPreferenceScreen().getContext());
            c.setKey(checkBoxPreferenceData.key);
            c.setTitle(checkBoxPreferenceData.title);
            c.setSummary(checkBoxPreferenceData.summary);
            c.setIcon(checkBoxPreferenceData.icon);
            prefScreen.addPreference(c);
        }
    });
}
 
Example #6
Source File: EnabledApplicationsPreferenceFragment.java    From an2linuxclient with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onSharedPreferenceChanged(SharedPreferences sp, String key) {
    boolean newSettingsValue = sp.getBoolean(key, false);
    String prefEnableDisableAllKey = getString(R.string.preference_enable_disable_all_applications);
    if (key.equals(prefEnableDisableAllKey)) {
        final PreferenceScreen prefScreen = findPreference(getString(R.string.enabled_apps_pref_screen));
        for (int i = 1; i < prefScreen.getPreferenceCount(); i++) {
            ((CheckBoxPreference) (prefScreen.getPreference(i))).setChecked(newSettingsValue);
        }
    }

    // If newSettingsValue == false, clear it from SharedPreferences file to save up some space.
    // Since AN2Linux will default to false if the setting is not found.
    if (!newSettingsValue) {
        sp.edit().remove(key).apply();
    }
}
 
Example #7
Source File: EnabledApplicationsPreferenceFragment.java    From an2linuxclient with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    EnabledApplicationsViewModel viewModel = ViewModelProviders.of(getActivity()).get(EnabledApplicationsViewModel.class);
    viewModel.getFilteredCheckBoxPrefsData().observe(getViewLifecycleOwner(), checkBoxPreferencesData -> {
        setPreferencesFromResource(R.xml.enabled_applications_preferences, null);
        PreferenceScreen prefScreen = (PreferenceScreen) findPreference(getString(R.string.enabled_apps_pref_screen));
        for (CheckBoxPreferenceData checkBoxPreferenceData : checkBoxPreferencesData) {
            CheckBoxPreference c = new CheckBoxPreference(getPreferenceScreen().getContext());
            c.setKey(checkBoxPreferenceData.key);
            c.setTitle(checkBoxPreferenceData.title);
            c.setSummary(checkBoxPreferenceData.summary);
            c.setIcon(checkBoxPreferenceData.icon);
            prefScreen.addPreference(c);
        }
    });
}
 
Example #8
Source File: AdvancedPreferenceFragment.java    From mollyim-android with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean onPreferenceChange(final Preference preference, Object newValue) {
  if (((CheckBoxPreference)preference).isChecked()) {
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setIconAttribute(R.attr.dialog_info_icon);
    builder.setTitle(R.string.ApplicationPreferencesActivity_disable_signal_messages_and_calls);
    builder.setMessage(R.string.ApplicationPreferencesActivity_disable_signal_messages_and_calls_by_unregistering);
    builder.setNegativeButton(android.R.string.cancel, null);
    builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
      @Override
      public void onClick(DialogInterface dialog, int which) {
        new DisablePushMessagesTask((CheckBoxPreference)preference).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
      }
    });
    builder.show();
  } else {
    startActivity(RegistrationNavigationActivity.newIntentForReRegistration(requireContext()));
  }

  return false;
}
 
Example #9
Source File: SettingsFragment.java    From fresco with MIT License 5 votes vote down vote up
private void updateOverrideSizeSummary(final Preference preference) {
  boolean currentState =
      updateCheckBoxPreference(
          getResources(),
          (CheckBoxPreference) preference,
          R.string.checked_auto_size_override,
          R.string.unchecked_auto_size_override);
  findPreference(Const.FORCED_ROTATION_ANGLE_KEY).setEnabled(!currentState);
}
 
Example #10
Source File: SettingsFragment.java    From fresco with MIT License 5 votes vote down vote up
private void updateInstrumentationSummary(final Preference preference) {
  updateCheckBoxPreference(
      getResources(),
      (CheckBoxPreference) preference,
      R.string.checked_instrumentation_summary,
      R.string.unchecked_instrumentation_summary);
}
 
Example #11
Source File: SettingsFragment.java    From fresco with MIT License 5 votes vote down vote up
private void updateDrawBorderSummary(final Preference preference) {
  updateCheckBoxPreference(
      getResources(),
      (CheckBoxPreference) preference,
      R.string.checked_draw_border_summary,
      R.string.unchecked_draw_border_summary);
}
 
Example #12
Source File: SettingsFragment.java    From fresco with MIT License 5 votes vote down vote up
private void updateDraweeOverlaySummary(final Preference preference) {
  updateCheckBoxPreference(
      getResources(),
      (CheckBoxPreference) preference,
      R.string.checked_drawee_overlay_summary,
      R.string.unchecked_drawee_overlay_summary);
}
 
Example #13
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 #14
Source File: SettingsFragment.java    From fresco with MIT License 5 votes vote down vote up
private void updateDownsamplingSummary(final Preference preference) {
  updateCheckBoxPreference(
      getResources(),
      (CheckBoxPreference) preference,
      R.string.checked_downsampling_summary,
      R.string.unchecked_downsampling_summary);
}
 
Example #15
Source File: SettingsFragment.java    From fresco with MIT License 5 votes vote down vote up
private void updateAutoRotateSummary(final Preference preference) {
  boolean currentState =
      updateCheckBoxPreference(
          getResources(),
          (CheckBoxPreference) preference,
          R.string.checked_auto_rotate_summary,
          R.string.unchecked_auto_rotate_summary);
  findPreference(Const.FORCED_ROTATION_ANGLE_KEY).setEnabled(!currentState);
}
 
Example #16
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 #17
Source File: SettingsFragment.java    From fresco with MIT License 5 votes vote down vote up
private static boolean updateCheckBoxPreference(
    Resources resources,
    CheckBoxPreference preference,
    int checkedSummaryRes,
    int uncheckedSummaryRes) {
  final boolean checkboxState = preference.isChecked();
  if (checkboxState) {
    preference.setSummary(resources.getString(checkedSummaryRes));
  } else {
    preference.setSummary(resources.getString(uncheckedSummaryRes));
  }
  return checkboxState;
}
 
Example #18
Source File: SettingsFragment.java    From fresco with MIT License 5 votes vote down vote up
private void updateWebpSupportSummary(final Preference preference) {
  updateCheckBoxPreference(
      getResources(),
      (CheckBoxPreference) preference,
      R.string.checked_webp_support_summary,
      R.string.unchecked_webp_support_summary);
}
 
Example #19
Source File: SettingsFragment.java    From fresco with MIT License 5 votes vote down vote up
private void updateDecodeCancellationSummary(final Preference preference) {
  updateCheckBoxPreference(
      getResources(),
      (CheckBoxPreference) preference,
      R.string.checked_decode_cancellation_summary,
      R.string.unchecked_decode_cancellation_summary);
}
 
Example #20
Source File: SettingsFragment.java    From fresco with MIT License 5 votes vote down vote up
private void updateUsePostprocessorSummary(final Preference preference) {
  updateCheckBoxPreference(
      getResources(),
      (CheckBoxPreference) preference,
      R.string.checked_postprocessor_summary,
      R.string.unchecked_postprocessor_summary);
}
 
Example #21
Source File: SettingsFragment.java    From fresco with MIT License 5 votes vote down vote up
private void updateRoundedAsCircleSummary(final Preference preference) {
  updateCheckBoxPreference(
      getResources(),
      (CheckBoxPreference) preference,
      R.string.checked_rounded_as_circle_summary,
      R.string.unchecked_rounded_as_circle_summary);
}
 
Example #22
Source File: SettingsFragment.java    From fresco with MIT License 5 votes vote down vote up
private void updateRoundedCornersSummary(final Preference preference) {
  updateCheckBoxPreference(
      getResources(),
      (CheckBoxPreference) preference,
      R.string.checked_rounded_corners_summary,
      R.string.unchecked_rounded_corners_summary);
}
 
Example #23
Source File: SettingsFragment.java    From fresco with MIT License 5 votes vote down vote up
private void updateReuseOldControllerSummary(final Preference preference) {
  updateCheckBoxPreference(
      getResources(),
      (CheckBoxPreference) preference,
      R.string.checked_reuse_old_controller_summary,
      R.string.unchecked_reuse_old_controller_summary);
}
 
Example #24
Source File: SettingsFragment.java    From fresco with MIT License 5 votes vote down vote up
private void updateDistinctDataSourceSummary(final Preference preference) {
  updateCheckBoxPreference(
      getResources(),
      (CheckBoxPreference) preference,
      R.string.checked_distinct_uri_data_source_summary,
      R.string.unchecked_distinct_uri_data_source_summary);
}
 
Example #25
Source File: SettingsFragment.java    From fresco with MIT License 5 votes vote down vote up
private void updateInfiniteDataSourceSummary(final Preference preference) {
  final boolean currentState =
      updateCheckBoxPreference(
          getResources(),
          (CheckBoxPreference) preference,
          R.string.checked_infinite_data_source_summary,
          R.string.unchecked_infinite_data_source_summary);
  // We disableDistinct Uris if infinite is not enabled
  findPreference(Const.DISTINCT_DATA_SOURCE_KEY).setEnabled(currentState);
}
 
Example #26
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 #27
Source File: AppProtectionPreferenceFragment.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
  boolean     value   = (boolean) newValue;

  Log.i(TAG, "Getting ready to change registration lock setting to: " + value);

  if (value) {
    RegistrationLockV2Dialog.showEnableDialog(requireContext(), () -> ((CheckBoxPreference) preference).setChecked(true));
  } else {
    RegistrationLockV2Dialog.showDisableDialog(requireContext(), () -> ((CheckBoxPreference) preference).setChecked(false));
  }

  return false;
}
 
Example #28
Source File: RxPreference.java    From aptoide-client-v8 with GNU General Public License v3.0 4 votes vote down vote up
@CheckResult @NonNull public static Observable<Boolean> checks(CheckBoxPreference preference) {
  checkNotNull(preference, "preference == null");
  return Observable.create(new PreferenceOnCheckOnSubscribe(preference));
}
 
Example #29
Source File: PreferenceOnCheckOnSubscribe.java    From aptoide-client-v8 with GNU General Public License v3.0 4 votes vote down vote up
public PreferenceOnCheckOnSubscribe(CheckBoxPreference preference) {
  this.preference = preference;
}
 
Example #30
Source File: SettingsFragment.java    From vinyl-cast with MIT License 4 votes vote down vote up
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
    Timber.d("onCreatePreferences");

    setPreferencesFromResource(R.xml.preferences, rootKey);

    AudioDevicePreference recordingDevicePref = findPreference(R.string.prefs_key_recording_device_id);
    AudioDevicePreference playbackDevicePref = findPreference(R.string.prefs_key_local_playback_device_id);
    CheckBoxPreference lowLatencyPref = findPreference(R.string.prefs_key_low_latency);
    ListPreference audioEncodingPref = findPreference(R.string.prefs_key_audio_encoding);
    Preference feedbackPref = findPreference(R.string.prefs_key_feedback);
    Preference androidApiLevelPref = findPreference(R.string.prefs_key_android_api_level);
    Preference appVersionPref = findPreference(R.string.prefs_key_app_version);

    if (recordingDevicePref != null) {
        recordingDevicePref.setDirectionType(AudioManager.GET_DEVICES_INPUTS);
        recordingDevicePref.setOnPreferenceClickListener(disabledPreferenceClickListener);
        recordingDevicePref.setOnPreferenceChangeListener(audioDeviceOnChangeListener);
    }
    if (playbackDevicePref != null) {
        playbackDevicePref.setDirectionType(AudioManager.GET_DEVICES_OUTPUTS);
        playbackDevicePref.setOnPreferenceClickListener(disabledPreferenceClickListener);
        playbackDevicePref.setOnPreferenceChangeListener(audioDeviceOnChangeListener);
    }
    if (lowLatencyPref != null) {
        lowLatencyPref.setOnPreferenceClickListener(disabledPreferenceClickListener);
    }
    if (audioEncodingPref != null) {
        audioEncodingPref.setEntries(R.array.prefs_audio_encoding_entries);
        audioEncodingPref.setEntryValues(R.array.prefs_audio_encoding_entry_values);
        audioEncodingPref.setOnPreferenceClickListener(disabledPreferenceClickListener);
    }
    if (feedbackPref != null && BuildConfig.FLAVOR.equals("playstore")) {
        feedbackPref.setVisible(true);
        feedbackPref.setOnPreferenceClickListener(preference -> {
            try {
                // Use reflection to get Instabug since only available in playstore product flavor
                Class instabugClazz = Class.forName("com.instabug.library.Instabug");
                if (binder != null) {
                    //Instabug.setUserAttribute("Audio API", getAudioApiVersionString());
                    Method setUserAttributeMethod = instabugClazz.getMethod("setUserAttribute", String.class, String.class);
                    setUserAttributeMethod.invoke(null, "Audio API", getAudioApiVersionString());
                }
                //Instabug.show();
                Method showMethod = instabugClazz.getMethod("show");
                showMethod.invoke(null);
            } catch (ReflectiveOperationException e) {
                e.printStackTrace();
            }
            return true;
        });
    }
    if (androidApiLevelPref != null) {
        androidApiLevelPref.setSummaryProvider(preference ->
                Integer.toString(Build.VERSION.SDK_INT)
        );
    }
    if (appVersionPref != null) {
        appVersionPref.setSummaryProvider(preference ->
                String.format(Locale.getDefault(), "%s (%d)", BuildConfig.VERSION_NAME, BuildConfig.VERSION_CODE)
        );
    }

    // set initial state of dynamic preferences
    updateDynamicPreferences();
}