本文整理汇总了Java中android.support.v7.preference.Preference.setOnPreferenceChangeListener方法的典型用法代码示例。如果您正苦于以下问题:Java Preference.setOnPreferenceChangeListener方法的具体用法?Java Preference.setOnPreferenceChangeListener怎么用?Java Preference.setOnPreferenceChangeListener使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.support.v7.preference.Preference
的用法示例。
在下文中一共展示了Preference.setOnPreferenceChangeListener方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onCreatePreferences
import android.support.v7.preference.Preference; //导入方法依赖的package包/类
@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);
}
示例2: bindPreferenceSummaryToValue
import android.support.v7.preference.Preference; //导入方法依赖的package包/类
/**
* Binds a preference's summary to its value. More specifically, when the
* preference's value is changed, its summary (line of text below the
* preference title) is updated to reflect the value. The summary is also
* immediately updated upon calling this method. The exact display format is
* dependent on the type of preference.
*
* @see #sBindPreferenceSummaryToValueListener
*/
private static void bindPreferenceSummaryToValue(Preference preference) {
// Set the listener to watch for value changes.
preference.setOnPreferenceChangeListener(sBindPreferenceSummaryToValueListener);
// Trigger the listener immediately with the preference's
// current value.
final String key = preference.getKey();
if (preference instanceof MultiSelectListPreference) {
Set<String> summary = SharedPreferencesCompat.getStringSet(
PreferenceManager.getDefaultSharedPreferences(preference.getContext()),
key,
new HashSet<>());
sBindPreferenceSummaryToValueListener.onPreferenceChange(preference, summary);
} else if (preference instanceof ColorPreference) {
sBindPreferenceSummaryToValueListener.onPreferenceChange(preference, ((ColorPreference) preference).getColor());
} else if (preference instanceof SeekBarPreference) {
sBindPreferenceSummaryToValueListener.onPreferenceChange(preference, ((SeekBarPreference) preference).getValue());
} else {
String value = PreferenceManager
.getDefaultSharedPreferences(preference.getContext())
.getString(key, "");
sBindPreferenceSummaryToValueListener.onPreferenceChange(preference, value);
}
}
示例3: onCreatePreferences
import android.support.v7.preference.Preference; //导入方法依赖的package包/类
@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);
}
}
// TODO (3) Add the OnPreferenceChangeListener specifically to the EditTextPreference
Preference preference = findPreference(getString(R.string.pref_size_key));
preference.setOnPreferenceChangeListener(this);
}
示例4: bindPreferenceSummaryToValue
import android.support.v7.preference.Preference; //导入方法依赖的package包/类
private static void bindPreferenceSummaryToValue(Preference preference) {
// Set the listener to watch for value changes.
preference.setOnPreferenceChangeListener(sBindPreferenceSummaryToValueListener);
// Trigger the listener immediately with the preference's
// current value.
final String key = preference.getKey();
if (preference instanceof MultiSelectListPreference) {
Set<String> summary = SharedPreferencesCompat.getStringSet(
PreferenceManager.getDefaultSharedPreferences(preference.getContext()),
key, new HashSet<String>());
sBindPreferenceSummaryToValueListener.onPreferenceChange(preference, summary);
} else if (preference instanceof SeekBarPreference) {
sBindPreferenceSummaryToValueListener.onPreferenceChange(preference, ((SeekBarPreference) preference).getValue());
} else {
String value = PreferenceManager
.getDefaultSharedPreferences(preference.getContext())
.getString(key, "");
sBindPreferenceSummaryToValueListener.onPreferenceChange(preference, value);
}
}
示例5: initPrefsSummary
import android.support.v7.preference.Preference; //导入方法依赖的package包/类
/**
* Init single Preference
*/
protected void initPrefsSummary(SharedPreferences sharedPreferences,
Preference p) {
if (p instanceof PreferenceCategory) {
PreferenceCategory pCat = (PreferenceCategory) p;
int pcCatCount = pCat.getPreferenceCount();
for (int i = 0; i < pcCatCount; i++) {
initPrefsSummary(sharedPreferences, pCat.getPreference(i));
}
} else {
updatePrefsSummary(sharedPreferences, p);
if (p instanceof RingtonePreference) {
p.setOnPreferenceChangeListener(new RingToneOnPreferenceChangeListener());
mRingtonePreference = (RingtonePreference) p;
}
}
}
示例6: onCreatePreferences
import android.support.v7.preference.Preference; //导入方法依赖的package包/类
@Override
public void onCreatePreferences(Bundle bundle, String s) {
// Add preferences, defined in the XML file in res->xml->preferences.xml
addPreferencesFromResource(R.xml.preferences);
//set the summaries for the different preferences for the first time
SharedPreferences sharedPreferences = getPreferenceScreen().getSharedPreferences();
PreferenceScreen prefScreen = getPreferenceScreen();
int count = prefScreen.getPreferenceCount();
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) && !(p instanceof MultiSelectListPreference)) {
String value = sharedPreferences.getString(p.getKey(), "");
setPreferenceSummary(p, value);
}
}
//attach listener to check for changes in the radius preference
//because it should only contain only doubles and the code has to enforce this
Preference preference = findPreference(getString(R.string.pref_radius_key));
preference.setOnPreferenceChangeListener(this);
}
示例7: invalidateSettings
import android.support.v7.preference.Preference; //导入方法依赖的package包/类
public void invalidateSettings() {
SwitchPreference dark = (SwitchPreference) findPreference("dark_theme");
ExcludeFolderPreference exclude = (ExcludeFolderPreference) findPreference("excluded_folders_listener_key");
ColorPickerPreference primary = (ColorPickerPreference) findPreference("primary");
ColorPickerPreference accent = (ColorPickerPreference) findPreference("accent");
Preference security = findPreference("security_placeholder");
Preference animations = findPreference("animations");
Preference staggered = findPreference("staggered");
Preference cache = findPreference("clear_cache_placeholder");
Preference sdcard = findPreference("externalsd_placeholder");
Preference removesd = findPreference("removesd_placeholder");
sdcard.setSummary(ExtSdHelper.getSdPath()==null ? getContext().getResources().getString(R.string.no_sd) : ExtSdHelper.getSdPath().substring(ExtSdHelper.getSdPath().lastIndexOf("/")+1));
if (Build.VERSION.SDK_INT < 21) {
sdcard.setEnabled(false);
}
removesd.setOnPreferenceClickListener(this);
sdcard.setOnPreferenceClickListener(this);
security.setOnPreferenceClickListener(this);
exclude.setOnPreferenceClickListener(this);
cache.setOnPreferenceClickListener(this);
staggered.setOnPreferenceChangeListener(this);
animations.setOnPreferenceChangeListener(this);
dark.setOnPreferenceChangeListener(this);
primary.setOnPreferenceChangeListener(this);
accent.setOnPreferenceChangeListener(this);
}
示例8: updatePreferenceSummaries
import android.support.v7.preference.Preference; //导入方法依赖的package包/类
private void updatePreferenceSummaries() {
Preference enableLocationTracking = findPreference(Common.PREF_ENABLE_LOCATION_TRACKING);
enableLocationTracking.setOnPreferenceChangeListener((preference, newValue) -> {
if (newValue == Boolean.TRUE && ActivityCompat.checkSelfPermission(getActivity(), Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(getActivity(), new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, 0);
return false;
}
updateLocationTracker();
return true;
});
Preference deviceName = findPreference(Common.PREF_LOCATION_DEVICE_NAME);
deviceName.setSummary(getResources().getString(R.string.preference_location_device_name_summary, prefs.getString(deviceName.getKey(), "nothing")));
deviceName.setOnPreferenceChangeListener((preference, newValue) -> {
preference.setSummary(getResources().getString(R.string.preference_location_device_name_summary, newValue));
updateLocationTracker();
return true;
});
Preference updateInterval = findPreference(Common.PREF_LOCATION_UPDATE_INTERVAL);
int selectedIndex = Arrays.binarySearch(getResources().getIntArray(R.array.location_update_interval_values), prefs.getInt(updateInterval.getKey(), 10));
updateInterval.setSummary(getResources().getStringArray(R.array.location_update_interval_summaries)[selectedIndex]);
Preference resetIgnoredSSLMismatches = findPreference(Common.PREF_RESET_HOST_MISMATCHES);
if (prefs.getStringSet(Common.PREF_ALLOWED_HOST_MISMATCHES_KEY, null) == null) {
resetIgnoredSSLMismatches.setSummary(R.string.preference_reset_host_mismatches_summary_empty);
resetIgnoredSSLMismatches.setEnabled(false);
}
}
示例9: bindPreferenceSummaryToValue
import android.support.v7.preference.Preference; //导入方法依赖的package包/类
private void bindPreferenceSummaryToValue(@NonNull Preference preference) {
// Set the listener to watch for value changes.
preference.setOnPreferenceChangeListener(listener);
listener.onPreferenceChange(preference, mSetting.getValue(preference.getKey()));
}