本文整理汇总了Java中android.preference.Preference类的典型用法代码示例。如果您正苦于以下问题:Java Preference类的具体用法?Java Preference怎么用?Java Preference使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Preference类属于android.preference包,在下文中一共展示了Preference类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onPreferenceChange
import android.preference.Preference; //导入依赖的package包/类
@Override
public boolean onPreferenceChange(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.
ListPreference listPreference = (ListPreference) preference;
int index = listPreference.findIndexOfValue(stringValue);
// Set the summary to reflect the new value.
preference.setSummary(index >= 0 ? listPreference.getEntries()[index] : null);
} else {
// For all other preferences, set the summary to the value's
// simple string representation.
preference.setSummary(stringValue);
}
return true;
}
示例2: onPreferenceClick
import android.preference.Preference; //导入依赖的package包/类
@Override
public boolean onPreferenceClick(Preference preference) {
switch (preference.getKey()) {
case CACHE_MAX:
break;
case CLEAR_CACHE:
Toast.makeText(getActivity(), "clear cache", Toast.LENGTH_SHORT).show();
break;
case CHECK_UPDATE:
Toast.makeText(getActivity(), "check update", Toast.LENGTH_SHORT).show();
break;
case VERSION_INFO:
startActivity(new Intent(getActivity(), VersionInfoAct.class));
break;
default:
return false;
}
return true;
}
示例3: onPreferenceChange
import android.preference.Preference; //导入依赖的package包/类
@Override
public boolean onPreferenceChange(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.
ListPreference listPreference = (ListPreference) preference;
int index = listPreference.findIndexOfValue(stringValue);
// Set the summary to reflect the new value.
preference.setSummary(
index >= 0
? listPreference.getEntries()[index]
: null);
} else {
// For all other preferences, set the summary to the value's
// simple string representation.
preference.setSummary(stringValue);
}
return true;
}
示例4: setChildrenStarted
import android.preference.Preference; //导入依赖的package包/类
private void setChildrenStarted(PreferenceGroup group, boolean started) {
final int count = group.getPreferenceCount();
for (int i = 0; i < count; i++) {
Preference pref = group.getPreference(i);
if (pref instanceof ApplicationLightPreference) {
ApplicationLightPreference ap = (ApplicationLightPreference) pref;
if (started) {
ap.onStart();
} else {
ap.onStop();
}
} else if (pref instanceof PreferenceGroup) {
setChildrenStarted((PreferenceGroup) pref, started);
}
}
}
示例5: onPreferenceChange
import android.preference.Preference; //导入依赖的package包/类
public boolean onPreferenceChange(final Preference p, Object newValue) {
// Asynchronously save the alarm since this method is called _before_
// the value of the preference has changed.
final String ktekstomalnova = ("" + mKanaloPref.getEntry()).trim();
sHandler.post(new Runnable() {
public void run() {
// Editing any preference (except enable) enables the alarm.
if (p != mEnabledPref) {
mEnabledPref.setChecked(true);
}
if (p == mKanaloPref) {
String kteksto = ("" + mKanaloPref.getEntry()).trim();
mKanaloPref.setSummary(kteksto);
String lteksto = mLabel.getText().toString().trim();
if (lteksto.length() == 0 || lteksto.equals(ktekstomalnova)) {
mLabel.setText(kteksto);
}
}
saveAlarm(null);
}
});
return true;
}
示例6: bindPreferenceSummaryToValue
import android.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' current value.
if (preference instanceof ListPreference
|| preference instanceof EditTextPreference) {
sBindPreferenceSummaryToValueListener.onPreferenceChange(preference,
PreferenceManager
.getDefaultSharedPreferences(preference.getContext())
.getString(preference.getKey(), ""));
} else if (preference instanceof SwitchPreference
|| preference instanceof CheckBoxPreference) {
sBindPreferenceSummaryToValueListener.onPreferenceChange(preference,
PreferenceManager
.getDefaultSharedPreferences(preference.getContext())
.getBoolean(preference.getKey(),true));
}
}
示例7: onCreate
import android.preference.Preference; //导入依赖的package包/类
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getActivity().setTitle(R.string.prefs_about_chrome);
addPreferencesFromResource(R.xml.about_chrome_preferences);
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
ChromeBasePreference deprecationWarning = new ChromeBasePreference(
new ContextThemeWrapper(getActivity(),
R.style.DeprecationWarningPreferenceTheme));
deprecationWarning.setOrder(-1);
deprecationWarning.setTitle(R.string.deprecation_warning);
deprecationWarning.setIcon(R.drawable.exclamation_triangle);
getPreferenceScreen().addPreference(deprecationWarning);
}
PrefServiceBridge prefServiceBridge = PrefServiceBridge.getInstance();
AboutVersionStrings versionStrings = prefServiceBridge.getAboutVersionStrings();
Preference p = findPreference(PREF_APPLICATION_VERSION);
p.setSummary(getApplicationVersion(getActivity(), versionStrings.getApplicationVersion()));
p = findPreference(PREF_OS_VERSION);
p.setSummary(versionStrings.getOSVersion());
p = findPreference(PREF_LEGAL_INFORMATION);
int currentYear = Calendar.getInstance().get(Calendar.YEAR);
p.setSummary(getString(R.string.legal_information_summary, currentYear));
}
示例8: onPreferenceChange
import android.preference.Preference; //导入依赖的package包/类
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
int value = Integer.parseInt((String) newValue);
final VibrateState vibrateState = VibrateState.fromId(value);
recipients.setVibrate(vibrateState);
new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
DatabaseFactory.getRecipientPreferenceDatabase(getActivity())
.setVibrate(recipients, vibrateState);
return null;
}
}.execute();
return false;
}
示例9: initSettings
import android.preference.Preference; //导入依赖的package包/类
private void initSettings() {
initTunnelSettings();
initAudioSettings();
initVideoSettings();
initCallSettings();
initChatSettings();
initNetworkSettings();
initAdvancedSettings();
findPreference(getString(R.string.pref_add_account_key)).setOnPreferenceClickListener(new OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
int nbAccounts = mPrefs.getAccountCount();
LinphoneActivity.instance().displayAccountSettings(nbAccounts);
return true;
}
});
}
示例10: createUserDictionaryPreference
import android.preference.Preference; //导入依赖的package包/类
/**
* Create a single User Dictionary Preference object, with its parameters set.
* @param localeString The locale for which this user dictionary is for.
* @return The corresponding preference.
*/
protected Preference createUserDictionaryPreference(@Nullable final String localeString) {
final Preference newPref = new Preference(getActivity());
final Intent intent = new Intent(USER_DICTIONARY_SETTINGS_INTENT_ACTION);
if (null == localeString) {
newPref.setTitle(Locale.getDefault().getDisplayName());
} else {
if (localeString.isEmpty()) {
newPref.setTitle(getString(R.string.user_dict_settings_all_languages));
} else {
newPref.setTitle(
LocaleUtils.constructLocaleFromString(localeString).getDisplayName());
}
intent.putExtra("locale", localeString);
newPref.getExtras().putString("locale", localeString);
}
newPref.setIntent(intent);
newPref.setFragment(UserDictionarySettings.class.getName());
return newPref;
}
示例11: setPreferenceSummaryByValue
import android.preference.Preference; //导入依赖的package包/类
/**
* Sets the summary of the preference according to its value
*
* @param preference
* @param value
*/
private static void setPreferenceSummaryByValue(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.
ListPreference listPreference = (ListPreference) preference;
int index = listPreference.findIndexOfValue(stringValue);
// Set the summary to reflect the new value.
preference.setSummary(
index >= 0
? listPreference.getEntries()[index]
: null);
}
else {
// For all other preferences, set the summary to the value's
// simple string representation.
preference.setSummary(stringValue);
}
}
示例12: onCreate
import android.preference.Preference; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
if(Build.VERSION.SDK_INT>=21)
setTheme(R.style.Material);
else if (Build.VERSION.SDK_INT>=11)
setTheme(R.style.Holo);
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preference_settings);
findPreference("disable_qq").setOnPreferenceChangeListener(new disabler("QQActivity"));
findPreference("disable_wechat").setOnPreferenceChangeListener(new disabler("WechatActivity"));
findPreference("disable_generic").setOnPreferenceChangeListener(new disabler("GenericActivity"));
findPreference("disable_this").setOnPreferenceChangeListener(new disabler("JumpActivity"));
findPreference("show_help").setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
startActivity(new Intent(SettingsActivity.this, GuideActivity.class));
return true;
}
});
}
示例13: onCreate
import android.preference.Preference; //导入依赖的package包/类
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.do_not_track_preferences);
getActivity().setTitle(R.string.do_not_track_title);
ChromeSwitchPreference doNotTrackSwitch =
(ChromeSwitchPreference) findPreference(PREF_DO_NOT_TRACK_SWITCH);
boolean isDoNotTrackEnabled = PrefServiceBridge.getInstance().isDoNotTrackEnabled();
doNotTrackSwitch.setChecked(isDoNotTrackEnabled);
doNotTrackSwitch.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
PrefServiceBridge.getInstance().setDoNotTrackEnabled((boolean) newValue);
return true;
}
});
}
示例14: updateDebugHwOverdraw
import android.preference.Preference; //导入依赖的package包/类
private void updateDebugHwOverdraw() {
final CharSequence[] entries = mDebugHwOverdrawPref.getEntries();
String value = SystemProperties.get(Constants.THREADED_RENDERER_DEBUG_OVERDRAW_PROPERTY);
int idxOfValue = mDebugHwOverdrawPref.findIndexOfValue(value);
if (idxOfValue != -1) {
mDebugHwOverdrawPref.setValueIndex(idxOfValue);
mDebugHwOverdrawPref.setSummary(entries[idxOfValue]);
}
mDebugHwOverdrawPref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
// ThreadedRenderer.DEBUG_OVERDRAW_PROPERTY
String command = String.format("setprop %s %s",
Constants.THREADED_RENDERER_DEBUG_OVERDRAW_PROPERTY,
newValue.toString());
ShellUtils.execCommand(command, true);
new SystemPropPoker().execute();
int indexOfValue = mDebugHwOverdrawPref.findIndexOfValue(newValue.toString());
preference.setSummary(entries[indexOfValue]);
return true;
}
});
}
示例15: onPreferenceChange
import android.preference.Preference; //导入依赖的package包/类
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
String value = newValue.toString();
try {
int intValue = Integer.parseInt(value);
if ((intValue < 1) || (intValue > 5)) {
return false;
}
} catch (NumberFormatException nfe) { }
if (isNewAccount) {
//TODO
} else {
mPrefs.setAvpfRRInterval(n, value);
}
preference.setSummary(value);
return true;
}