本文整理汇总了Java中android.support.v7.preference.Preference类的典型用法代码示例。如果您正苦于以下问题:Java Preference类的具体用法?Java Preference怎么用?Java Preference使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Preference类属于android.support.v7.preference包,在下文中一共展示了Preference类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setPreferenceSummary
import android.support.v7.preference.Preference; //导入依赖的package包/类
private void setPreferenceSummary(Preference preference, Object value) {
String stringValue = value.toString();
if (preference instanceof ListPreference) {
// For list preferences, look up the correct display value in
// the preference's 'entries' list (since they have separate labels/values).
ListPreference listPreference = (ListPreference) preference;
int prefIndex = listPreference.findIndexOfValue(stringValue);
if (prefIndex >= 0) {
preference.setSummary(listPreference.getEntries()[prefIndex]);
}
} else {
// For other preferences, set the summary to the value's simple string representation.
preference.setSummary(stringValue);
}
}
示例2: onCreatePreferences
import android.support.v7.preference.Preference; //导入依赖的package包/类
@Override
public void onCreatePreferences(Bundle bundle, String s) {
// Add 'general' preferences, defined in the XML file
addPreferencesFromResource(R.xml.pref_general);
SharedPreferences sharedPreferences = getPreferenceScreen().getSharedPreferences();
PreferenceScreen prefScreen = getPreferenceScreen();
int count = prefScreen.getPreferenceCount();
for (int i = 0; i < count; i++) {
Preference p = prefScreen.getPreference(i);
if (!(p instanceof CheckBoxPreference)) {
String value = sharedPreferences.getString(p.getKey(), "");
setPreferenceSummary(p, value);
}
}
}
示例3: onCreatePreferences
import android.support.v7.preference.Preference; //导入依赖的package包/类
@Override
public void onCreatePreferences(Bundle bundle, String s) {
/* Add 'general' preferences, defined in the XML file */
addPreferencesFromResource(R.xml.pref_general);
SharedPreferences sharedPreferences = getPreferenceScreen().getSharedPreferences();
PreferenceScreen prefScreen = getPreferenceScreen();
int count = prefScreen.getPreferenceCount();
for (int i = 0; i < count; i++) {
Preference p = prefScreen.getPreference(i);
if (!(p instanceof CheckBoxPreference)) {
String value = sharedPreferences.getString(p.getKey(), "");
setPreferenceSummary(p, value);
}
}
}
示例4: onSharedPreferenceChanged
import android.support.v7.preference.Preference; //导入依赖的package包/类
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
Activity activity = getActivity();
if (key.equals(getString(R.string.pref_location_key))) {
// we've changed the location
// Wipe out any potential PlacePicker latlng values so that we can use this text entry.
SunshinePreferences.resetLocationCoordinates(activity);
} else if (key.equals(getString(R.string.pref_units_key))) {
// units have changed. update lists of weather entries accordingly
activity.getContentResolver().notifyChange(WeatherContract.WeatherEntry.CONTENT_URI, null);
}
Preference preference = findPreference(key);
if (null != preference) {
if (!(preference instanceof CheckBoxPreference)) {
setPreferenceSummary(preference, sharedPreferences.getString(key, ""));
}
}
}
示例5: onDisplayPreferenceDialog
import android.support.v7.preference.Preference; //导入依赖的package包/类
@Override
public void onDisplayPreferenceDialog(Preference preference) {
if (callback != null) {
callback.onSettingChanged();
}
DialogFragment dialogFragment = null;
if (preference instanceof StylePreference) {
dialogFragment
= StylePreferenceDialogFragment
.newInstance(preference);
} else if (preference instanceof ColumnCountPreference) {
dialogFragment
= ColumnCountPreferenceDialogFragment
.newInstance(preference);
}
if (dialogFragment != null) {
dialogFragment.setTargetFragment(this, 0);
dialogFragment.show(this.getFragmentManager(), DIALOG_FRAGMENT_TAG);
return;
}
super.onDisplayPreferenceDialog(preference);
}
示例6: 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;
}
}
}
示例7: onSharedPreferenceChanged
import android.support.v7.preference.Preference; //导入依赖的package包/类
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
Activity activity = getActivity();
if (key.equals(getString(R.string.pref_location_key))) {
// we've changed the location
// Wipe out any potential PlacePicker latlng values so that we can use this text entry.
SunshinePreferences.resetLocationCoordinates(activity);
SunshineSyncUtils.startImmediateSync(activity);
} else if (key.equals(getString(R.string.pref_units_key))) {
// units have changed. update lists of weather entries accordingly
activity.getContentResolver().notifyChange(WeatherContract.WeatherEntry.CONTENT_URI, null);
}
Preference preference = findPreference(key);
if (null != preference) {
if (!(preference instanceof CheckBoxPreference)) {
setPreferenceSummary(preference, sharedPreferences.getString(key, ""));
}
}
}
示例8: onCreatePreferences
import android.support.v7.preference.Preference; //导入依赖的package包/类
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
addPreferencesFromResource(R.xml.preferences);
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);
//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);
}
}
}
示例9: onPreferenceChange
import android.support.v7.preference.Preference; //导入依赖的package包/类
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
NotificationManager manager = new NotificationManager(getContext());
ListPreference delay = (ListPreference)findPreference("delayNotifications");
CheckBoxPreference display = (CheckBoxPreference)findPreference("displaySilNotification");
app.savePublicPreference(Common.GLOBAL_SETTING_ISNOTIFON, (boolean)newValue);
if ((boolean)newValue) {
delay.setEnabled(true);
display.setEnabled(true);
display.setChecked(app.getPublicPreferenceB(Common.GLOBAL_SETTING_NOTIFICATIONDISPLAY));
manager.setRecurrentService();
} else {
delay.setEnabled(false);
display.setEnabled(false);
display.setChecked(false);
manager.deactivateRecurrentService();
}
return true;
}
示例10: createPreferences
import android.support.v7.preference.Preference; //导入依赖的package包/类
@Override
protected void createPreferences(PreferenceScreen screen)
{
switch (mAction) {
case SettingsConstantsUI.ACTION_PREFS_GENERAL:
addPreferencesFromResource(R.xml.preferences_general);
final ListPreference theme =
(ListPreference) findPreference(SettingsConstantsUI.KEY_PREF_THEME);
initializeTheme(getActivity(), theme);
final Preference reset =
findPreference(SettingsConstantsUI.KEY_PREF_RESET_SETTINGS);
initializeReset(getActivity(), reset);
break;
case SettingsConstantsUI.ACTION_PREFS_UPDATE:
ApkDownloader.check(getActivity(), true);
break;
}
}
示例11: initializeTheme
import android.support.v7.preference.Preference; //导入依赖的package包/类
public static void initializeTheme(
final Activity activity,
final ListPreference theme)
{
if (null != theme) {
theme.setSummary(theme.getEntry());
theme.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener()
{
@Override
public boolean onPreferenceChange(
Preference preference,
Object newValue)
{
activity.startActivity(activity.getIntent());
activity.finish();
return true;
}
});
}
}
示例12: 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);
}
示例13: 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);
}
}
示例14: onPreferenceChange
import android.support.v7.preference.Preference; //导入依赖的package包/类
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
Toast error = Toast.makeText(getContext(), "Please select a number between 0.1 and 3", Toast.LENGTH_SHORT);
String sizeKey = getString(R.string.pref_size_key);
if (preference.getKey().equals(sizeKey)) {
String stringSize = ((String) newValue).trim();
try {
float size = Float.parseFloat(stringSize);
if (size > 3 || size <= 0.1) {
error.show();
return false;
}
} catch (NumberFormatException nfe) {
error.show();
return false;
}
}
return true;
}
示例15: 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);
// COMPLETED (3) Get the preference screen, get the number of preferences and iterate through
// all of the preferences if it is not a checkbox preference, call the setSummary method
// passing in a preference and the value of the preference
SharedPreferences sharedPreferences = getPreferenceScreen().getSharedPreferences();
PreferenceScreen preferenceScreen = getPreferenceScreen();
int count = preferenceScreen.getPreferenceCount();
for (int i = 0; i < count; i++) {
Preference pref = preferenceScreen.getPreference(i);
if (!(pref instanceof CheckBoxPreference)) {
setPreferenceSummary(pref, sharedPreferences.getString(pref.getKey(), ""));
}
}
}