Java Code Examples for android.preference.ListPreference#findIndexOfValue()
The following examples show how to use
android.preference.ListPreference#findIndexOfValue() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SettingsActivity.java From ScreenShift with Apache License 2.0 | 6 votes |
@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; }
Example 2
Source File: SettingsActivity.java From gito-github-client with Apache License 2.0 | 6 votes |
@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; }
Example 3
Source File: SettingsActivity.java From chronosnap with MIT License | 6 votes |
@Override public boolean onPreferenceChange(Preference preference, Object newValue) { String stringValue = newValue.toString(); // The method for updating the summary differs based on the preference type if (preference instanceof TimeIntervalPreference) { preference.setSummary(((TimeIntervalPreference) preference).getSummary(stringValue)); } else if (preference instanceof ListPreference) { ListPreference listPreference = (ListPreference) preference; int index = listPreference.findIndexOfValue(stringValue); preference.setSummary(index >= 0 ? listPreference.getEntries()[index] : null); } else { preference.setSummary(stringValue); } return true; }
Example 4
Source File: PreferencesUtil.java From text_converter with GNU General Public License v3.0 | 6 votes |
@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; }
Example 5
Source File: SettingsActivity.java From Equate with GNU General Public License v3.0 | 6 votes |
@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; }
Example 6
Source File: SettingsFragment.java From 600SeriesAndroidUploader with MIT License | 6 votes |
/** * set lowBatPollInterval to normal poll interval at least * and adapt the selectable values * * @param pollIntervalPref * @param lowBatPollIntervalPref */ private void setMinBatPollIntervall(ListPreference pollIntervalPref, ListPreference lowBatPollIntervalPref) { final String currentValue = lowBatPollIntervalPref.getValue(); final int pollIntervalPos = (pollIntervalPref.findIndexOfValue(pollIntervalPref.getValue()) >= 0?pollIntervalPref.findIndexOfValue(pollIntervalPref.getValue()):0), length = pollIntervalPref.getEntries().length; CharSequence[] entries = new String[length - pollIntervalPos], entryValues = new String[length - pollIntervalPos]; // generate temp Entries and EntryValues for(int i = pollIntervalPos; i < length; i++) { entries[i - pollIntervalPos] = pollIntervalPref.getEntries()[i]; entryValues[i - pollIntervalPos] = pollIntervalPref.getEntryValues()[i]; } lowBatPollIntervalPref.setEntries(entries); lowBatPollIntervalPref.setEntryValues(entryValues); // and set the correct one if (lowBatPollIntervalPref.findIndexOfValue(currentValue) == -1) { lowBatPollIntervalPref.setValueIndex(0); } }
Example 7
Source File: SettingsActivity.java From PKUCourses with GNU General Public License v3.0 | 6 votes |
@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; }
Example 8
Source File: SettingsActivity.java From SecScanQR with GNU General Public License v3.0 | 6 votes |
@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; }
Example 9
Source File: SettingsActivity.java From mOrgAnd with GNU General Public License v2.0 | 6 votes |
@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; }
Example 10
Source File: SettingsActivity.java From privacy-friendly-qr-scanner with GNU General Public License v3.0 | 6 votes |
@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; }
Example 11
Source File: SettingsPresenter.java From go-bees with GNU General Public License v3.0 | 6 votes |
@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 (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); } return true; }
Example 12
Source File: SettingsFragment.java From Augendiagnose with GNU General Public License v2.0 | 6 votes |
/** * Update the summary for a preference. * * @param preference The preference. * @param value the new value of the preference. */ private void setSummary(@NonNull final Preference preference, final String value) { if (preference.getClass().equals(ListPreference.class)) { // For list preferences (except customized ones), look up the correct display value in the preference's 'entries' list. ListPreference listPreference = (ListPreference) preference; int index = listPreference.findIndexOfValue(value); if (preference.getKey().startsWith(getString(R.string.key_indexed_overlaytype))) { updateSummaryForOverlayPreference(listPreference); } else if (index < 0) { preference.setSummary(null); } else { String entryValue = listPreference.getEntries()[index].toString(); preference.setSummary(entryValue); } } else { // For all other preferences, set the summary to the value's simple string representation. preference.setSummary(value); } }
Example 13
Source File: SettingsActivity.java From JayPS-AndroidApp with MIT License | 6 votes |
private void setRefreshSummary(String p_refreshInterval) { ListPreference refreshPref = (ListPreference) findPreference("REFRESH_INTERVAL"); if (refreshPref.findIndexOfValue(p_refreshInterval) >= 0) { CharSequence listDesc = refreshPref.getEntries()[refreshPref.findIndexOfValue(p_refreshInterval)]; refreshPref.setSummary(listDesc); } else { // not in the list (old value?) int refresh_interval = 0; try { refresh_interval = Integer.valueOf(_sharedPreferences.getString("REFRESH_INTERVAL", "500")); } catch (NumberFormatException nfe) { refresh_interval = Constants.REFRESH_INTERVAL_DEFAULT; } refresh_interval = refresh_interval % 100000; if (refresh_interval < 1000) { refreshPref.setSummary(refresh_interval + " ms"); } else { refreshPref.setSummary(refresh_interval/1000 + " s"); } } }
Example 14
Source File: SubScreenFragment.java From AOSP-Kayboard-7.1.2 with Apache License 2.0 | 5 votes |
static void updateListPreferenceSummaryToCurrentValue(final String prefKey, final PreferenceScreen screen) { // Because the "%s" summary trick of {@link ListPreference} doesn't work properly before // KitKat, we need to update the summary programmatically. final ListPreference listPreference = (ListPreference)screen.findPreference(prefKey); if (listPreference == null) { return; } final CharSequence entries[] = listPreference.getEntries(); final int entryIndex = listPreference.findIndexOfValue(listPreference.getValue()); listPreference.setSummary(entryIndex < 0 ? null : entries[entryIndex]); }
Example 15
Source File: SubScreenFragment.java From Indic-Keyboard with Apache License 2.0 | 5 votes |
static void updateListPreferenceSummaryToCurrentValue(final String prefKey, final PreferenceScreen screen) { // Because the "%s" summary trick of {@link ListPreference} doesn't work properly before // KitKat, we need to update the summary programmatically. final ListPreference listPreference = (ListPreference)screen.findPreference(prefKey); if (listPreference == null) { return; } final CharSequence entries[] = listPreference.getEntries(); final int entryIndex = listPreference.findIndexOfValue(listPreference.getValue()); listPreference.setSummary(entryIndex < 0 ? null : entries[entryIndex]); }
Example 16
Source File: ProfileEditFragment.java From SecondScreen with Apache License 2.0 | 5 votes |
@Override public boolean onPreferenceChange(Preference preference, Object value) { String stringValue = value.toString(); // Damage control if user inputs an empty profile name if(stringValue.isEmpty() && preference.getKey().equals("profile_name")) { stringValue = name; listener.setEmptyTitle(name); } 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); CharSequence summary = index >= 0 ? listPreference.getEntries()[index] : null; // Set the summary to reflect the new value. if(summary == null) { stringValue = listener.generateBlurb(preference.getKey(), stringValue); preference.setSummary(stringValue); } else preference.setSummary(summary); } else { if((preference.getKey().equals("density") && !stringValue.isEmpty()) || preference.getKey().equals("size")) stringValue = listener.generateBlurb(preference.getKey(), stringValue); // For all other preferences, set the summary to the value's // simple string representation. preference.setSummary(stringValue); } return true; }
Example 17
Source File: SettingsActivity.java From codeexamples-android with Eclipse Public License 1.0 | 4 votes |
@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; }
Example 18
Source File: SettingsActivity.java From beaconloc with Apache License 2.0 | 4 votes |
@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; }
Example 19
Source File: TalkBackKeyboardShortcutPreferencesActivity.java From talkback with Apache License 2.0 | 4 votes |
@Override public boolean onPreferenceChange(Preference preference, Object newValue) { String preferenceKeyForTriggerModifier = getKeyComboManager().getKeyComboModel().getPreferenceKeyForTriggerModifier(); if (preference instanceof KeyboardShortcutDialogPreference && newValue instanceof Long) { KeyboardShortcutDialogPreference keyBoardPreference = (KeyboardShortcutDialogPreference) preference; keyBoardPreference.setKeyComboCode((Long) newValue); keyBoardPreference.notifyChanged(); } else if (preference.getKey() != null && preference.getKey().equals(getString(R.string.pref_select_keymap_key)) && newValue instanceof String) { String newKeymap = (String) newValue; // Do nothing if keymap is the same. if (keymap.equals(newKeymap)) { return false; } // Replace preference fragment. TalkBackKeyboardShortcutPreferenceFragment fragment = TalkBackKeyboardShortcutPreferenceFragment.createFor(newKeymap); getFragmentManager() .beginTransaction() .replace(android.R.id.content, fragment) .commit(); // Set new key combo model. KeyComboManager keyComboManager = getKeyComboManager(); keyComboManager.setKeyComboModel(keyComboManager.createKeyComboModelFor(newKeymap)); // Announce new keymap. announceText( String.format( getString(R.string.keycombo_menu_announce_active_keymap), getKeymapName(newKeymap)), getActivity()); } else if (preference.getKey() != null && preference.getKey().equals(preferenceKeyForTriggerModifier) && newValue instanceof String) { triggerModifierToBeSet = (String) newValue; ListPreference listPreference = (ListPreference) preference; if (listPreference.getValue().equals(triggerModifierToBeSet)) { return false; } CharSequence[] entries = listPreference.getEntries(); CharSequence newTriggerModifier = entries[listPreference.findIndexOfValue(triggerModifierToBeSet)]; // Show alert dialog. AlertDialog dialog = new AlertDialog.Builder(getActivity()) .setTitle(R.string.keycombo_menu_alert_title_trigger_modifier) .setMessage( getString( R.string.keycombo_menu_alert_message_trigger_modifier, newTriggerModifier)) .setPositiveButton( android.R.string.ok, chooseTriggerModifierConfirmDialogPositive) .setNegativeButton( android.R.string.cancel, chooseTriggerModifierConfirmDialogNegative) .show(); focusCancelButton(dialog); return false; } return true; }
Example 20
Source File: SettingActivity.java From SimplePomodoro-android with MIT License | 4 votes |
@Override public boolean onPreferenceChange(Preference preference, Object value) { String stringValue = value.toString(); if (preference instanceof ListPreference) { 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; }