Java Code Examples for androidx.preference.TwoStatePreference#setChecked()

The following examples show how to use androidx.preference.TwoStatePreference#setChecked() . 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: SettingsFragment.java    From Kore with Apache License 2.0 6 votes vote down vote up
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String permissions[], @NonNull int[] grantResults) {
    switch (requestCode) {
        case Utils.PERMISSION_REQUEST_READ_PHONE_STATE:
            // If request is cancelled, the result arrays are empty.
            if ((grantResults.length == 0) ||
                (grantResults[0] != PackageManager.PERMISSION_GRANTED)) {
                Toast.makeText(getActivity(), R.string.read_phone_state_permission_denied, Toast.LENGTH_SHORT)
                     .show();
                TwoStatePreference pauseCallPreference =
                        (TwoStatePreference)findPreference(Settings.KEY_PREF_PAUSE_DURING_CALLS);
                pauseCallPreference.setChecked(false);
            }
            break;
    }
}
 
Example 2
Source File: TalkBackPreferencesActivity.java    From talkback with Apache License 2.0 6 votes vote down vote up
/**
 * In versions O and above, assign a default value for speaking passwords without headphones to
 * the system setting for speaking passwords out loud. This way, if the user already wants the
 * system to speak speak passwords out loud, the user will see no change and passwords will
 * continue to be spoken. In M and below, hide this preference.
 */
private void updateSpeakPasswordsPreference() {
  if (FeatureSupport.useSpeakPasswordsServicePref()) {
    // Read talkback speak-passwords preference, with default to system preference.
    boolean speakPassValue = SpeakPasswordsManager.getAlwaysSpeakPasswordsPref(context);
    // Update talkback preference display to match read value.
    TwoStatePreference prefSpeakPasswords =
        (TwoStatePreference)
            findPreferenceByResId(R.string.pref_speak_passwords_without_headphones);
    if (prefSpeakPasswords != null) {
      prefSpeakPasswords.setChecked(speakPassValue);
    }
  } else {
    PreferenceSettingsUtils.hidePreference(
        context, getPreferenceScreen(), R.string.pref_speak_passwords_without_headphones);
  }
}
 
Example 3
Source File: TalkBackPreferencesActivity.java    From talkback with Apache License 2.0 6 votes vote down vote up
/** Update the audio focus if the activity is visible and the selector has changed the state. */
private void updateAudioFocusPreference() {
  final TwoStatePreference audioFocusPreference =
      (TwoStatePreference) findPreferenceByResId(R.string.pref_use_audio_focus_key);
  if (audioFocusPreference == null) {
    return;
  }

  // Make sure that we have the latest value of the audio focus preference before
  // continuing.
  boolean focusEnabled =
      SharedPreferencesUtils.getBooleanPref(
          prefs,
          getResources(),
          R.string.pref_use_audio_focus_key,
          R.bool.pref_use_audio_focus_default);

  audioFocusPreference.setChecked(focusEnabled);
}
 
Example 4
Source File: TalkBackPreferencesActivity.java    From talkback with Apache License 2.0 6 votes vote down vote up
/** Ensure that the vibration setting does not appear on devices without a vibrator. */
private void checkVibrationSupport() {
  Activity activity = getActivity();
  if (activity == null) {
    return;
  }

  final Vibrator vibrator = (Vibrator) activity.getSystemService(VIBRATOR_SERVICE);

  if (vibrator != null && vibrator.hasVibrator()) {
    return;
  }

  final PreferenceGroup category =
      (PreferenceGroup) findPreferenceByResId(R.string.pref_category_feedback_key);
  final TwoStatePreference prefVibration =
      (TwoStatePreference) findPreferenceByResId(R.string.pref_vibration_key);

  if (prefVibration != null) {
    prefVibration.setChecked(false);
    category.removePreference(prefVibration);
  }
}
 
Example 5
Source File: TalkBackPreferencesActivity.java    From talkback with Apache License 2.0 6 votes vote down vote up
/**
 * Ensure that the proximity sensor setting does not appear on devices without a proximity
 * sensor.
 */
private void checkProximitySupport() {
  Activity activity = getActivity();
  if (activity == null) {
    return;
  }

  final SensorManager manager = (SensorManager) activity.getSystemService(SENSOR_SERVICE);
  final Sensor proximity = manager.getDefaultSensor(Sensor.TYPE_PROXIMITY);

  if (proximity != null) {
    return;
  }

  final PreferenceGroup category =
      (PreferenceGroup) findPreferenceByResId(R.string.pref_category_when_to_speak_key);
  final TwoStatePreference prefProximity =
      (TwoStatePreference) findPreferenceByResId(R.string.pref_proximity_key);

  if (prefProximity != null) {
    prefProximity.setChecked(false);
    category.removePreference(prefProximity);
  }
}
 
Example 6
Source File: TalkBackDeveloperPreferencesActivity.java    From talkback with Apache License 2.0 5 votes vote down vote up
/**
 * Updates the preferences state to match the actual state of touch exploration. This is called
 * once when the preferences activity launches and again whenever the actual state of touch
 * exploration changes.
 */
private void updateTouchExplorationDisplay() {
  TwoStatePreference prefTouchExploration =
      (TwoStatePreference)
          findPreference(getString(R.string.pref_explore_by_touch_reflect_key));
  if (prefTouchExploration == null) {
    return;
  }

  Activity activity = getActivity();
  if (activity == null) {
    return;
  }

  ContentResolver resolver = activity.getContentResolver();
  Resources res = getResources();
  SharedPreferences prefs = SharedPreferencesUtils.getSharedPreferences(activity);

  boolean requestedState =
      SharedPreferencesUtils.getBooleanPref(
          prefs, res, R.string.pref_explore_by_touch_key, R.bool.pref_explore_by_touch_default);
  boolean reflectedState = prefTouchExploration.isChecked();
  boolean actualState =
      TalkBackService.isServiceActive() ? isTouchExplorationEnabled(resolver) : requestedState;

  // If touch exploration is actually off and we requested it on, the user
  // must have declined the "Enable touch exploration" dialog. Update the
  // requested value to reflect this.
  if (requestedState != actualState) {
    LogUtils.d(TAG, "Set touch exploration preference to reflect actual state %b", actualState);
    SharedPreferencesUtils.putBooleanPref(
        prefs, res, R.string.pref_explore_by_touch_key, actualState);
  }

  // Ensure that the check box preference reflects the requested state,
  // which was just synchronized to match the actual state.
  if (reflectedState != actualState) {
    prefTouchExploration.setChecked(actualState);
  }
}