android.support.v7.preference.Preference.setOnPreferenceChangeListener()方法的使用及代码示例

x33g5p2x  于2022-01-26 转载在 其他  
字(13.4k)|赞(0)|评价(0)|浏览(141)

本文整理了Java中android.support.v7.preference.Preference.setOnPreferenceChangeListener()方法的一些代码示例,展示了Preference.setOnPreferenceChangeListener()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Preference.setOnPreferenceChangeListener()方法的具体详情如下:
包路径:android.support.v7.preference.Preference
类名称:Preference
方法名:setOnPreferenceChangeListener

Preference.setOnPreferenceChangeListener介绍

暂无

代码示例

代码示例来源:origin: TeamNewPipe/NewPipe

@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  String updateToggleKey = getString(R.string.update_app_key);
  findPreference(updateToggleKey).setOnPreferenceChangeListener(updatePreferenceChange);
}

代码示例来源:origin: TeamNewPipe/NewPipe

@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  String themeKey = getString(R.string.theme_key);
  startThemeKey = defaultPreferences.getString(themeKey, getString(R.string.default_theme_value));
  findPreference(themeKey).setOnPreferenceChangeListener(themePreferenceChange);
  captionSettingsKey = getString(R.string.caption_settings_key);
  if (!CAPTIONING_SETTINGS_ACCESSIBLE)  {
    final Preference captionSettings = findPreference(captionSettingsKey);
    getPreferenceScreen().removePreference(captionSettings);
  }
}

代码示例来源:origin: TeamNewPipe/NewPipe

setPreferredLanguage.setOnPreferenceChangeListener((Preference p, Object newLanguage) -> {
  Localization oldLocal = org.schabi.newpipe.util.Localization.getPreferredExtractorLocal(getActivity());
  NewPipe.setLocalization(new Localization(oldLocal.getCountry(), (String) newLanguage));
setPreferredCountry.setOnPreferenceChangeListener((Preference p, Object newCountry) -> {
  Localization oldLocal = org.schabi.newpipe.util.Localization.getPreferredExtractorLocal(getActivity());
  NewPipe.setLocalization(new Localization((String) newCountry, oldLocal.getLanguage()));

代码示例来源:origin: jberkel/sms-backup-plus

private void registerValidCallLogFolderCheck() {
    folderPreference.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
      public boolean onPreferenceChange(Preference preference, final Object newValue) {
        return checkValidImapFolder(preference, newValue.toString());
      }
    });
  }
}

代码示例来源:origin: udacity/ud851-Exercises

@Override
public void onCreatePreferences(Bundle bundle, String s) {
  // Add visualizer preferences, defined in the XML file in res->xml->pref_visualizer
  addPreferencesFromResource(R.xml.pref_visualizer);
  SharedPreferences sharedPreferences = getPreferenceScreen().getSharedPreferences();
  PreferenceScreen prefScreen = getPreferenceScreen();
  int count = prefScreen.getPreferenceCount();
  // Go through all of the preferences, and set up their preference summary.
  for (int i = 0; i < count; i++) {
    Preference p = prefScreen.getPreference(i);
    // You don't need to set up preference summaries for checkbox preferences because
    // they are already set up in xml using summaryOff and summary On
    if (!(p instanceof CheckBoxPreference)) {
      String value = sharedPreferences.getString(p.getKey(), "");
      setPreferenceSummary(p, value);
    }
  }
  // COMPLETED (3) Add the OnPreferenceChangeListener specifically to the EditTextPreference
  // Add the preference listener which checks that the size is correct to the size preference
  Preference preference = findPreference(getString(R.string.pref_size_key));
  preference.setOnPreferenceChangeListener(this);
}

代码示例来源:origin: jberkel/sms-backup-plus

private void registerValidImapFolderCheck() {
  findPreference(SMS.folderPreference)
      .setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
        public boolean onPreferenceChange(Preference preference, final Object newValue) {
          return checkValidImapFolder(preference, newValue.toString());
        }
      });
}

代码示例来源:origin: jberkel/sms-backup-plus

void addPreferenceListener(final Object event, String... prefKeys) {
    for (String prefKey : prefKeys) {
      findPreference(prefKey).setOnPreferenceChangeListener(
          new OnPreferenceChangeListener() {
            public boolean onPreferenceChange(Preference preference, final Object newValue) {
              handler.post(new Runnable() {
                @Override
                public void run() {
                  App.post(event);
                }
              });
              return true;
            }
          });
    }
  }
}

代码示例来源:origin: jberkel/sms-backup-plus

@Override
public void onResume() {
  super.onResume();
  updateMaxItemsPerRestore(null);
  findPreference(MAX_ITEMS_PER_RESTORE.key)
      .setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
        public boolean onPreferenceChange(Preference preference, Object newValue) {
          updateMaxItemsPerRestore(newValue.toString());
          return true;
        }
      });
}

代码示例来源:origin: jberkel/sms-backup-plus

.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
  public boolean onPreferenceChange(Preference preference, Object newValue) {
    final boolean plain = AuthMode.valueOf(newValue.toString().toUpperCase(Locale.ENGLISH))
.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
  @Override
  public boolean onPreferenceChange(Preference preference, Object newValue) {
.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
  public boolean onPreferenceChange(Preference preference, Object newValue) {
    updateUsernameLabel(newValue.toString());
.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
  public boolean onPreferenceChange(Preference preference, Object newValue) {
    authPreferences.setImapPassword(newValue.toString());

代码示例来源:origin: jberkel/sms-backup-plus

registerValidImapFolderCheck();
findPreference(MAX_ITEMS_PER_SYNC.key)
  .setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
    public boolean onPreferenceChange(Preference preference, Object newValue) {
      updateMaxItemsPerSync(newValue.toString());

代码示例来源:origin: avluis/Hentoid

@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
  setPreferencesFromResource(R.xml.preferences, rootKey);
  findPreference(Preferences.Key.PREF_HIDE_RECENT)
      .setOnPreferenceChangeListener((preference, newValue) -> onPrefRequiringRestartChanged());
  findPreference(Preferences.Key.PREF_ANALYTICS_TRACKING)
      .setOnPreferenceChangeListener((preference, newValue) -> onPrefRequiringRestartChanged());
  findPreference(Preferences.Key.PREF_USE_SFW)
      .setOnPreferenceChangeListener((preference, newValue) -> onPrefRequiringRestartChanged());
  findPreference(Preferences.Key.PREF_DL_THREADS_QUANTITY_LISTS)
      .setOnPreferenceChangeListener((preference, newValue) -> onPrefRequiringRestartChanged());
  findPreference(Preferences.Key.PREF_APP_LOCK)
      .setOnPreferenceChangeListener((preference, newValue) -> onAppLockPinChanged(newValue));
}

代码示例来源:origin: Calsign/APDE

private static void bindPreferenceSummaryToValue(Preference preference) {
  //Don't bind the preference if it doesn't appear in this fragment
  if(preference != null) {
    // Set the listener to watch for value changes.
    preference.setOnPreferenceChangeListener(sBindPreferenceSummaryToValueListener);
    
    // Trigger the listener immediately with the preference's
    // current value.
    sBindPreferenceSummaryToValueListener.onPreferenceChange(
        preference,
        PreferenceManager.getDefaultSharedPreferences(
            preference.getContext()).getString(preference.getKey(), ""));
  }
}

代码示例来源:origin: GrossumUA/TAS_Android_Boilerplate

private void initPrefs() {
  findPreference(getString(R.string.id_pref_logout)).setOnPreferenceClickListener(this);
  Preference switchBackgroundJob = findPreference(getString(R.string.id_pref_switcher));
  switchBackgroundJob.setOnPreferenceChangeListener(this);
  switchBackgroundJob.setEnabled(getArguments().getBoolean(AUTOLOGIN_ENABLED_ARGS));
}

代码示例来源:origin: WangDaYeeeeee/GeometricWeather

private void initBasicPart() {
  Preference darkMode = findPreference(getString(R.string.key_dark_mode));
  darkMode.setSummary(
      ValueUtils.getDarkMode(
          getActivity(),
          PreferenceManager.getDefaultSharedPreferences(getActivity())
              .getString(
                  getString(R.string.key_dark_mode),
                  "auto")));
  darkMode.setOnPreferenceChangeListener(this);
  Preference refreshRate = findPreference(getString(R.string.key_refresh_rate));
  refreshRate.setSummary(
      PreferenceManager.getDefaultSharedPreferences(getActivity())
          .getString(
              getString(R.string.key_refresh_rate),
              "1:30"));
  refreshRate.setOnPreferenceChangeListener(this);
}

代码示例来源:origin: fjoglar/android-dev-challenge

@Override
public void onCreatePreferences(Bundle bundle, String s) {
  // Add visualizer preferences, defined in the XML file in res->xml->pref_visualizer
  addPreferencesFromResource(R.xml.pref_visualizer);
  SharedPreferences sharedPreferences = getPreferenceScreen().getSharedPreferences();
  PreferenceScreen prefScreen = getPreferenceScreen();
  int count = prefScreen.getPreferenceCount();
  // Go through all of the preferences, and set up their preference summary.
  for (int i = 0; i < count; i++) {
    Preference p = prefScreen.getPreference(i);
    // You don't need to set up preference summaries for checkbox preferences because
    // they are already set up in xml using summaryOff and summary On
    if (!(p instanceof CheckBoxPreference)) {
      String value = sharedPreferences.getString(p.getKey(), "");
      setPreferenceSummary(p, value);
    }
  }
  // COMPLETED (3) Add the OnPreferenceChangeListener specifically to the EditTextPreference
  Preference preference = findPreference(getString(R.string.pref_size_key));
  preference.setOnPreferenceChangeListener(this);
}

代码示例来源:origin: WangDaYeeeeee/GeometricWeather

@Override
public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  addPreferencesFromResource(R.xml.perference_service_provider);
  Preference chineseSource = findPreference(getString(R.string.key_chinese_source));
  chineseSource.setSummary(
      ValueUtils.getWeatherSource(
          getActivity(),
          GeometricWeather.getInstance().getChineseSource()));
  chineseSource.setOnPreferenceChangeListener(this);
  Preference locationService = findPreference(getString(R.string.key_location_service));
  locationService.setSummary(
      ValueUtils.getLocationService(
          getActivity(),
          GeometricWeather.getInstance().getLocationService()));
  locationService.setOnPreferenceChangeListener(this);
}

代码示例来源:origin: consp1racy/android-support-preference

preference.setOnPreferenceChangeListener(sBindPreferenceSummaryToValueListener);

代码示例来源:origin: blurpy/kouchat-android

@Override
public void onCreatePreferences(final Bundle savedInstanceState, final String rootKey) {
  addPreferencesFromResource(R.xml.settings);
  nickNameKey = getString(R.string.settings_nick_name_key);
  wakeLockKey = getString(R.string.settings_wake_lock_key);
  ownColorKey = getString(R.string.settings_own_color_key);
  systemColorKey = getString(R.string.settings_sys_color_key);
  notificationLightKey = getString(R.string.settings_notification_light_key);
  notificationSoundKey = getString(R.string.settings_notification_sound_key);
  notificationVibrationKey = getString(R.string.settings_notification_vibration_key);
  final Preference nickNamePreference = findPreference(nickNameKey);
  nickNamePreference.setOnPreferenceChangeListener(this);
  setValueAsSummary(nickNamePreference);
}

代码示例来源:origin: Kr328/nevo-decorators-sms-captchas

@Override
public void onCreatePreferences(Bundle bundle, String s) {
  addPreferencesFromResource(R.xml.main_setting);
  getPreferenceScreen().setEnabled(false);
  mCaptchaHideOnLocked           = (CheckBoxPreference) findPreference(Settings.SETTING_CAPTCHA_HIDE_ON_LOCKED);
  mCaptchaOverrideDefaultAction  = (CheckBoxPreference) findPreference(Settings.SETTING_CAPTCHA_OVERRIDE_DEFAULT_ACTION);
  mCaptchaPostCopyAction         = (ListPreference)     findPreference(Settings.SETTING_CAPTCHA_POST_COPY_ACTION);
  mCaptchaIdentifyPattern        = (EditTextPreference) findPreference(Settings.SETTING_CAPTCHA_IDENTIFY_PATTERN);
  mCaptchaParsePattern           = (EditTextPreference) findPreference(Settings.SETTING_CAPTCHA_PARSE_PATTERN);
  mSubscribeIdentityPattern      = (EditTextPreference) findPreference(Settings.SETTING_SUBSCRIBE_IDENTIFY_PATTERN);
  mSubscribePriority             =                      findPreference(Settings.SETTING_SUBSCRIBE_PRIORITY);
  mHideInLauncher                = (CheckBoxPreference) findPreference(KEY_HIDE_IN_LAUNCHER);
  mCaptchaHideOnLocked.setOnPreferenceChangeListener(this::onPreferenceChange);
  mCaptchaOverrideDefaultAction.setOnPreferenceChangeListener(this::onPreferenceChange);
  mCaptchaPostCopyAction.setOnPreferenceChangeListener(this::onPreferenceChange);
  mCaptchaIdentifyPattern.setOnPreferenceChangeListener(this::onPreferenceChange);
  mCaptchaParsePattern.setOnPreferenceChangeListener(this::onPreferenceChange);
  mSubscribeIdentityPattern.setOnPreferenceChangeListener(this::onPreferenceChange);
  mHideInLauncher.setOnPreferenceChangeListener(this::onPreferenceChange);
  mSubscribePriority.setOnPreferenceChangeListener(this::onPreferenceChange);
  if (Build.VERSION.SDK_INT > Build.VERSION_CODES.O) {
    mSubscribePriority.setOnPreferenceClickListener((Preference p) -> {
      startActivity(
          new Intent("android.settings.APP_NOTIFICATION_SETTINGS").
              putExtra("android.provider.extra.APP_PACKAGE" , Global.NEVOLUTION_PACKAGE_NAME));
      return false;
    });
  }
  new Thread(this::loadSettingsAndUpdateViews).start();
}

代码示例来源:origin: marzika/Snapprefs

@SuppressWarnings("deprecation")
public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  getPreferenceManager().setSharedPreferencesMode(Context.MODE_WORLD_READABLE);
  addPreferencesFromResource(preferenceId);
  Preference pref = findPreference("pref_key_launcher");
  pref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
    @Override
    public boolean onPreferenceChange(Preference preference, Object newValue) {
      PackageManager packageManager = getActivity().getPackageManager();
      int state = (Boolean) newValue ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED : PackageManager.COMPONENT_ENABLED_STATE_DISABLED;
      ComponentName aliasName = new ComponentName(getActivity(), "com.marz.snapprefs.MainActivity-Alias");
      packageManager.setComponentEnabledSetting(aliasName, state, PackageManager.DONT_KILL_APP);
      return true;
    }
  });
  final LayoutInflater inflater = getLayoutInflater(savedInstanceState);
  Preference debugOptions = findPreference("pref_key_debug_options");
  debugOptions.setOnPreferenceClickListener(new OnPreferenceClickListener() {
    @Override
    public boolean onPreferenceClick(Preference preference) {
      displayDebugMenu(inflater);
      return false;
    }
  });
}

相关文章