/**
* Set the default preference values.
*
* @param savedInstanceState the current Activity's state, as passed by
* Android
*/
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences);
sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
listPreferenceSourceLanguage = (ListPreference) getPreferenceScreen().findPreference(KEY_SOURCE_LANGUAGE_PREFERENCE);
listPreferenceTargetLanguage = (ListPreference) getPreferenceScreen().findPreference(KEY_TARGET_LANGUAGE_PREFERENCE);
listPreferenceTranslator = (ListPreference) getPreferenceScreen().findPreference(KEY_TRANSLATOR);
listPreferenceOcrEngineMode = (ListPreference) getPreferenceScreen().findPreference(KEY_OCR_ENGINE_MODE);
editTextPreferenceCharacterBlacklist = (EditTextPreference) getPreferenceScreen().findPreference(KEY_CHARACTER_BLACKLIST);
editTextPreferenceCharacterWhitelist = (EditTextPreference) getPreferenceScreen().findPreference(KEY_CHARACTER_WHITELIST);
listPreferencePageSegmentationMode = (ListPreference) getPreferenceScreen().findPreference(KEY_PAGE_SEGMENTATION_MODE);
// Create the entries/entryvalues for the translation target language list.
initTranslationTargetList();
}
java类android.preference.ListPreference的实例源码
PreferencesActivity.java 文件源码
项目:android-mrz-reader
阅读 31
收藏 0
点赞 0
评论 0
AccountSettings.java 文件源码
项目:q-mail
阅读 37
收藏 0
点赞 0
评论 0
private void removeListEntry(ListPreference listPreference, String remove) {
CharSequence[] entryValues = listPreference.getEntryValues();
CharSequence[] entries = listPreference.getEntries();
CharSequence[] newEntryValues = new String[entryValues.length - 1];
CharSequence[] newEntries = new String[entryValues.length - 1];
for (int i = 0, out = 0; i < entryValues.length; i++) {
CharSequence value = entryValues[i];
if (!value.equals(remove)) {
newEntryValues[out] = value;
newEntries[out] = entries[i];
out++;
}
}
listPreference.setEntryValues(newEntryValues);
listPreference.setEntries(newEntries);
}
AccountSettings.java 文件源码
项目:q-mail
阅读 38
收藏 0
点赞 0
评论 0
@Override
protected void onPreExecute() {
autoExpandFolder = (ListPreference) findPreference(PREFERENCE_AUTO_EXPAND_FOLDER);
autoExpandFolder.setEnabled(false);
archiveFolder = (ListPreference) findPreference(PREFERENCE_ARCHIVE_FOLDER);
archiveFolder.setEnabled(false);
draftsFolder = (ListPreference) findPreference(PREFERENCE_DRAFTS_FOLDER);
draftsFolder.setEnabled(false);
sentFolder = (ListPreference) findPreference(PREFERENCE_SENT_FOLDER);
sentFolder.setEnabled(false);
spamFolder = (ListPreference) findPreference(PREFERENCE_SPAM_FOLDER);
spamFolder.setEnabled(false);
trashFolder = (ListPreference) findPreference(PREFERENCE_TRASH_FOLDER);
trashFolder.setEnabled(false);
if (!isMoveCapable) {
PreferenceScreen foldersCategory =
(PreferenceScreen) findPreference(PREFERENCE_CATEGORY_FOLDERS);
foldersCategory.removePreference(archiveFolder);
foldersCategory.removePreference(spamFolder);
foldersCategory.removePreference(draftsFolder);
foldersCategory.removePreference(sentFolder);
foldersCategory.removePreference(trashFolder);
}
}
SettingsActivity.java 文件源码
项目:Treebolic
阅读 39
收藏 0
点赞 0
评论 0
@Override
public void onCreate(final Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
// inflate
addPreferencesFromResource(R.xml.pref_service);
// preference
final ListPreference listPreference = (ListPreference) findPreference(Settings.PREF_SERVICE);
// activity
final SettingsActivity activity = (SettingsActivity) getActivity();
// connect to data
activity.fillWithServiceData(listPreference);
// bind
activity.bind(listPreference, Settings.getStringPref(activity, listPreference.getKey()), activity.listener);
}
ChatsPreferenceFragment.java 文件源码
项目:Cable-Android
阅读 25
收藏 0
点赞 0
评论 0
@Override
public void onCreate(Bundle paramBundle) {
super.onCreate(paramBundle);
addPreferencesFromResource(R.xml.preferences_chats);
findPreference(TextSecurePreferences.MEDIA_DOWNLOAD_MOBILE_PREF)
.setOnPreferenceChangeListener(new MediaDownloadChangeListener());
findPreference(TextSecurePreferences.MEDIA_DOWNLOAD_WIFI_PREF)
.setOnPreferenceChangeListener(new MediaDownloadChangeListener());
findPreference(TextSecurePreferences.MEDIA_DOWNLOAD_ROAMING_PREF)
.setOnPreferenceChangeListener(new MediaDownloadChangeListener());
findPreference(TextSecurePreferences.MESSAGE_BODY_TEXT_SIZE_PREF)
.setOnPreferenceChangeListener(new ListSummaryListener());
findPreference(TextSecurePreferences.THREAD_TRIM_NOW)
.setOnPreferenceClickListener(new TrimNowClickListener());
findPreference(TextSecurePreferences.THREAD_TRIM_LENGTH)
.setOnPreferenceChangeListener(new TrimLengthValidationListener());
initializeListSummary((ListPreference) findPreference(TextSecurePreferences.MESSAGE_BODY_TEXT_SIZE_PREF));
}
SettingsActivity.java 文件源码
项目:android-slideshow
阅读 30
收藏 0
点赞 0
评论 0
@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;
}
NotificationsPreferenceFragment.java 文件源码
项目:PeSanKita-android
阅读 25
收藏 0
点赞 0
评论 0
@Override
public void onCreate(Bundle paramBundle) {
super.onCreate(paramBundle);
masterSecret = getArguments().getParcelable("master_secret");
addPreferencesFromResource(R.xml.preferences_notifications);
this.findPreference(TextSecurePreferences.LED_COLOR_PREF)
.setOnPreferenceChangeListener(new ListSummaryListener());
this.findPreference(TextSecurePreferences.LED_BLINK_PREF)
.setOnPreferenceChangeListener(new ListSummaryListener());
this.findPreference(TextSecurePreferences.RINGTONE_PREF)
.setOnPreferenceChangeListener(new RingtoneSummaryListener());
this.findPreference(TextSecurePreferences.REPEAT_ALERTS_PREF)
.setOnPreferenceChangeListener(new ListSummaryListener());
this.findPreference(TextSecurePreferences.NOTIFICATION_PRIVACY_PREF)
.setOnPreferenceChangeListener(new NotificationPrivacyListener());
initializeListSummary((ListPreference) findPreference(TextSecurePreferences.LED_COLOR_PREF));
initializeListSummary((ListPreference) findPreference(TextSecurePreferences.LED_BLINK_PREF));
initializeListSummary((ListPreference) findPreference(TextSecurePreferences.REPEAT_ALERTS_PREF));
initializeListSummary((ListPreference) findPreference(TextSecurePreferences.NOTIFICATION_PRIVACY_PREF));
initializeRingtoneSummary((RingtonePreference) findPreference(TextSecurePreferences.RINGTONE_PREF));
}
SettingsActivity.java 文件源码
项目:Treebolic
阅读 24
收藏 0
点赞 0
评论 0
/**
* Connect list preference to service data
*
* @param listPreference list preference
*/
private void fillWithServiceData(@NonNull final ListPreference listPreference)
{
final List<HashMap<String, Object>> services = Services.getServices(this, true);
if (services != null)
{
final int n = services.size();
final String[] entries = new String[n];
final String[] values = new String[n];
for (int i = 0; i < n; i++)
{
final HashMap<String, Object> service = services.get(i);
entries[i] = (String) service.get(Services.LABEL);
values[i] = (String) service.get(Services.PACKAGE) + '/' + service.get(Services.NAME);
}
listPreference.setEntries(entries);
listPreference.setEntryValues(values);
}
}
SettingsActivity.java 文件源码
项目:BeaconMqtt
阅读 36
收藏 0
点赞 0
评论 0
@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;
}
SettingsActivity.java 文件源码
项目:C500Companion
阅读 26
收藏 0
点赞 0
评论 0
@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;
}
PreferencesUtil.java 文件源码
项目:text_converter
阅读 31
收藏 0
点赞 0
评论 0
@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 if (preference instanceof RingtonePreference) {
} else if (preference instanceof EditTextPreference) {
EditTextPreference editTextPreference = (EditTextPreference) preference;
editTextPreference.setSummary(editTextPreference.getText());
} else {
// For all other preferences, set the summary to the value's
// simple string representation.
preference.setSummary(stringValue);
}
return true;
}
ServerPreferencesScreen.java 文件源码
项目:bananapeel
阅读 27
收藏 0
点赞 0
评论 0
private void setKeys(PreferenceScreen screen)
{
for(int i = 0; i < screen.getPreferenceCount(); i++)
{
Preference preference = screen.getPreference(i);
String key = server + ";" + preference.getKey();
preference.setKey(key);
if(preference instanceof EditIntPreference)
((EditIntPreference)preference).setInt(preference.getSharedPreferences().getInt(key, -1));
else if(preference instanceof EditTextPreference)
((EditTextPreference)preference).setText(preference.getSharedPreferences().getString(key, null));
else if(preference instanceof ListPreference)
((ListPreference)preference).setValue(preference.getSharedPreferences().getString(key, null));
else if(preference instanceof CheckBoxPreference)
((CheckBoxPreference)preference).setChecked(preference.getSharedPreferences().getBoolean(key, false));
if(preference instanceof PreferenceScreen)
setKeys((PreferenceScreen)preference);
}
}
SettingsActivity.java 文件源码
项目:social-journal
阅读 28
收藏 0
点赞 0
评论 0
@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;
}
SettingsActivity.java 文件源码
项目:SecScanQR
阅读 28
收藏 0
点赞 0
评论 0
@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;
}
SettingsActivity.java 文件源码
项目:AndroidIRCLogViewer
阅读 27
收藏 0
点赞 0
评论 0
@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;
}
PreferenceActivity.java 文件源码
项目:AndiCar
阅读 34
收藏 0
点赞 0
评论 0
/**
* 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);
}
}
SettingActivity.java 文件源码
项目:QuakeRepor
阅读 33
收藏 0
点赞 0
评论 0
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
String stringValue = newValue.toString();
if (preference instanceof ListPreference) {
ListPreference listPreference = (ListPreference) preference;
int prefIndex = listPreference.findIndexOfValue(stringValue);
if (prefIndex >= 0) {
CharSequence[] labels = listPreference.getEntries();
preference.setSummary(labels[prefIndex]);
}
}else {
preference.setSummary(stringValue);
}
return true;
}
SettingsActivity.java 文件源码
项目:proto-collecte
阅读 29
收藏 0
点赞 0
评论 0
@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;
}
PreferencesUtil.java 文件源码
项目:javaide
阅读 35
收藏 0
点赞 0
评论 0
@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 if (preference instanceof RingtonePreference) {
} else if (preference instanceof EditTextPreference) {
EditTextPreference editTextPreference = (EditTextPreference) preference;
editTextPreference.setSummary(editTextPreference.getText());
} else {
// For all other preferences, set the summary to the value's
// simple string representation.
preference.setSummary(stringValue);
}
return true;
}
CustomRestrictionsFragment.java 文件源码
项目:buildAPKsSamples
阅读 28
收藏 0
点赞 0
评论 0
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.custom_prefs);
// This sample app uses shared preferences to maintain app restriction settings. Your app
// can use other methods to maintain the settings.
mBooleanPref = (CheckBoxPreference) findPreference(KEY_BOOLEAN_PREF);
mChoicePref = (ListPreference) findPreference(KEY_CHOICE_PREF);
mMultiPref = (MultiSelectListPreference) findPreference(KEY_MULTI_PREF);
mBooleanPref.setOnPreferenceChangeListener(this);
mChoicePref.setOnPreferenceChangeListener(this);
mMultiPref.setOnPreferenceChangeListener(this);
setRetainInstance(true);
}
SettingsActivity.java 文件源码
项目:LaunchTime
阅读 31
收藏 0
点赞 0
评论 0
protected static void setListPreferenceIconsPacksData(ListPreference lp, Context context) {
IconsHandler iph = GlobState.getIconsHandler(context);
iph.loadAvailableIconsPacks();
Map<String, String> iconsPacks = iph.getAllIconsThemes();
CharSequence[] entries = new CharSequence[iconsPacks.size()];
CharSequence[] entryValues = new CharSequence[iconsPacks.size()];
int i = 0;
for (String packageIconsPack : iconsPacks.keySet()) {
entries[i] = iconsPacks.get(packageIconsPack);
entryValues[i] = packageIconsPack;
i++;
}
lp.setEntries(entries);
lp.setDefaultValue(IconsHandler.DEFAULT_PACK);
lp.setEntryValues(entryValues);
}
SettingsActivity.java 文件源码
项目:GitHub
阅读 31
收藏 0
点赞 0
评论 0
private void setSummary(Preference pref, boolean init) {
if (pref instanceof EditTextPreference) {
EditTextPreference editPref = (EditTextPreference) pref;
pref.setSummary(editPref.getText());
if (editPref.getKey().equals("env_dir") && !init) {
editPref.setText(PrefStore.getEnvDir(this));
pref.setSummary(editPref.getText());
}
if (editPref.getKey().equals("http_conf") &&
editPref.getText().isEmpty()) {
editPref.setText(PrefStore.getHttpConf(this));
pref.setSummary(editPref.getText());
}
}
if (pref instanceof ListPreference) {
ListPreference listPref = (ListPreference) pref;
pref.setSummary(listPref.getEntry());
}
if (pref instanceof CheckBoxPreference) {
CheckBoxPreference checkPref = (CheckBoxPreference) pref;
if (checkPref.getKey().equals("logger") && checkPref.isChecked() && init) {
requestWritePermissions();
}
}
}
SettingsFragment.java 文件源码
项目:Linphone4Android
阅读 24
收藏 0
点赞 0
评论 0
private void initTunnelSettings() {
if (!LinphoneManager.getLc().isTunnelAvailable()) {
return;
}
setPreferenceDefaultValueAndSummary(R.string.pref_tunnel_host_key, mPrefs.getTunnelHost());
setPreferenceDefaultValueAndSummary(R.string.pref_tunnel_port_key, String.valueOf(mPrefs.getTunnelPort()));
ListPreference tunnelModePref = (ListPreference) findPreference(getString(R.string.pref_tunnel_mode_key));
String tunnelMode = mPrefs.getTunnelMode();
tunnelModePref.setSummary(tunnelMode);
tunnelModePref.setValue(tunnelMode);
}
SettingsAppearanceFragment.java 文件源码
项目:Rey-MusicPlayer
阅读 20
收藏 0
点赞 0
评论 0
@Override
public void onCreate(Bundle onSavedInstanceState) {
super.onCreate(onSavedInstanceState);
addPreferencesFromResource(R.xml.settings_appearance);
mPreferenceManager = this.getPreferenceManager();
mStartUpScreenPreference = (ListPreference) mPreferenceManager.findPreference("preference_key_startup_screen");
mStartUpScreenPreference.setOnPreferenceChangeListener((preference, o) -> {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setTitle(R.string.restart_app);
builder.setMessage(R.string.restart_app_des);
builder.setPositiveButton(R.string.ok, (dialogInterface, i) -> {
dialogInterface.dismiss();
Intent intent = getActivity().getBaseContext().getPackageManager().getLaunchIntentForPackage(getActivity().getBaseContext().getPackageName());
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
getActivity().finish();
startActivity(intent);
});
builder.setNegativeButton(R.string.cancel, (dialogInterface, i) -> dialogInterface.dismiss());
builder.create().show();
return true;
});
}
SettingsFragment.java 文件源码
项目:Linphone4Android
阅读 34
收藏 0
点赞 0
评论 0
private void initializePreferredVideoSizePreferences(ListPreference pref) {
List<CharSequence> entries = new ArrayList<CharSequence>();
List<CharSequence> values = new ArrayList<CharSequence>();
for (String name : LinphoneManager.getLc().getSupportedVideoSizes()) {
entries.add(name);
values.add(name);
}
setListPreferenceValues(pref, entries, values);
String value = mPrefs.getPreferredVideoSize();
pref.setSummary(value);
pref.setValue(value);
}
SettingsActivity.java 文件源码
项目:WeatherAlarmClock
阅读 28
收藏 0
点赞 0
评论 0
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
String stringValue = newValue.toString();
if (preference instanceof ListPreference) {
ListPreference listPreference = (ListPreference) preference;
int prefIndex = listPreference.findIndexOfValue(stringValue);
if (prefIndex >= 0) {
preference.setSummary(listPreference.getEntries()[prefIndex]);
}
} else {
preference.setSummary(stringValue);
}
return true;
}
SettingsFragment.java 文件源码
项目:Linphone4Android
阅读 43
收藏 0
点赞 0
评论 0
private void initLimeEncryptionPreference(ListPreference pref) {
List<CharSequence> entries = new ArrayList<CharSequence>();
List<CharSequence> values = new ArrayList<CharSequence>();
entries.add(getString(R.string.lime_encryption_entry_disabled));
values.add(LinphoneLimeState.Disabled.toString());
LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull();
if (lc == null || !lc.isLimeEncryptionAvailable()) {
setListPreferenceValues(pref, entries, values);
pref.setEnabled(false);
return;
}
entries.add(getString(R.string.lime_encryption_entry_mandatory));
values.add(LinphoneLimeState.Mandatory.toString());
entries.add(getString(R.string.lime_encryption_entry_preferred));
values.add(LinphoneLimeState.Preferred.toString());
setListPreferenceValues(pref, entries, values);
LinphoneLimeState lime = mPrefs.getLimeEncryption();
if (lime == LinphoneLimeState.Disabled) {
pref.setSummary(getString(R.string.lime_encryption_entry_disabled));
} else if (lime == LinphoneLimeState.Mandatory) {
pref.setSummary(getString(R.string.lime_encryption_entry_mandatory));
} else if (lime == LinphoneLimeState.Preferred) {
pref.setSummary(getString(R.string.lime_encryption_entry_preferred));
}
pref.setValue(lime.toString());
}
AccountPreferencesFragment.java 文件源码
项目:Linphone4Android
阅读 24
收藏 0
点赞 0
评论 0
private static void setListPreferenceValues(ListPreference pref, List<CharSequence> entries, List<CharSequence> values) {
CharSequence[] contents = new CharSequence[entries.size()];
entries.toArray(contents);
pref.setEntries(contents);
contents = new CharSequence[values.size()];
values.toArray(contents);
pref.setEntryValues(contents);
}
ListSummaryPreferenceFragment.java 文件源码
项目:Cable-Android
阅读 22
收藏 0
点赞 0
评论 0
@Override
public boolean onPreferenceChange(Preference preference, Object value) {
ListPreference listPref = (ListPreference) preference;
int entryIndex = Arrays.asList(listPref.getEntryValues()).indexOf(value);
listPref.setSummary(entryIndex >= 0 && entryIndex < listPref.getEntries().length
? listPref.getEntries()[entryIndex]
: getString(R.string.preferences__led_color_unknown));
return true;
}
SettingsActivity.java 文件源码
项目:SampleAppArch
阅读 27
收藏 0
点赞 0
评论 0
@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 if (preference instanceof RingtonePreference) {
// For ringtone preferences, look up the correct display value
// using RingtoneManager.
if (TextUtils.isEmpty(stringValue)) {
// Empty values correspond to 'silent' (no ringtone).
preference.setSummary(R.string.pref_ringtone_silent);
} else {
Ringtone ringtone = RingtoneManager.getRingtone(
preference.getContext(), Uri.parse(stringValue));
if (ringtone == null) {
// Clear the summary if there was a lookup error.
preference.setSummary(null);
} else {
// Set the summary to reflect the new ringtone display
// name.
String name = ringtone.getTitle(preference.getContext());
preference.setSummary(name);
}
}
} else {
// For all other preferences, set the summary to the value's
// simple string representation.
preference.setSummary(stringValue);
}
return true;
}