List of usage examples for android.preference ListPreference setEntries
public void setEntries(@ArrayRes int entriesResId)
From source file:com.nttec.everychan.chans.allchan.AllchanModule.java
@Override public void addPreferencesOnScreen(PreferenceGroup preferenceGroup) { Context context = preferenceGroup.getContext(); addOnlyNewPostsPreference(preferenceGroup, true); final ListPreference captchaPreference = new LazyPreferences.ListPreference(context); //captcha_type captchaPreference.setTitle(R.string.pref_captcha_type); captchaPreference.setDialogTitle(R.string.pref_captcha_type); captchaPreference.setKey(getSharedKey(PREF_KEY_CAPTCHA_TYPE)); captchaPreference.setEntryValues(CAPTCHA_TYPES_KEYS); captchaPreference.setEntries(CAPTCHA_TYPES); captchaPreference.setDefaultValue(CAPTCHA_TYPE_DEFAULT); int i = Arrays.asList(CAPTCHA_TYPES_KEYS) .indexOf(preferences.getString(getSharedKey(PREF_KEY_CAPTCHA_TYPE), CAPTCHA_TYPE_DEFAULT)); if (i >= 0) captchaPreference.setSummary(CAPTCHA_TYPES[i]); preferenceGroup.addPreference(captchaPreference); addHttpsPreference(preferenceGroup, true); addCloudflareRecaptchaFallbackPreference(preferenceGroup); addProxyPreferences(preferenceGroup); final CheckBoxPreference proxyPreference = (CheckBoxPreference) preferenceGroup .findPreference(getSharedKey(PREF_KEY_USE_PROXY)); proxyPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override/*from w ww . j a v a 2s. co m*/ public boolean onPreferenceClick(Preference preference) { if (proxyPreference.isChecked() && captchaPreference.getValue().equals("recaptcha")) { captchaPreference.setValue("recaptcha-fallback"); } return false; } }); captchaPreference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { if (proxyPreference.isChecked() && newValue.equals("recaptcha")) { captchaPreference.setValue("recaptcha-fallback"); return false; } return true; } }); }
From source file:nya.miku.wishmaster.chans.tumbach.TumbachModule.java
@Override public void addPreferencesOnScreen(PreferenceGroup preferenceGroup) { Context context = preferenceGroup.getContext(); addOnlyNewPostsPreference(preferenceGroup, true); final ListPreference captchaPreference = new LazyPreferences.ListPreference(context); //captcha_type captchaPreference.setTitle(R.string.pref_captcha_type); captchaPreference.setDialogTitle(R.string.pref_captcha_type); captchaPreference.setKey(getSharedKey(PREF_KEY_CAPTCHA_TYPE)); captchaPreference.setEntryValues(CAPTCHA_TYPES_KEYS); captchaPreference.setEntries(CAPTCHA_TYPES); captchaPreference.setDefaultValue(CAPTCHA_TYPE_DEFAULT); int i = Arrays.asList(CAPTCHA_TYPES_KEYS) .indexOf(preferences.getString(getSharedKey(PREF_KEY_CAPTCHA_TYPE), CAPTCHA_TYPE_DEFAULT)); if (i >= 0) captchaPreference.setSummary(CAPTCHA_TYPES[i]); preferenceGroup.addPreference(captchaPreference); addPasswordPreference(preferenceGroup); addHttpsPreference(preferenceGroup, true); addCloudflareRecaptchaFallbackPreference(preferenceGroup); addProxyPreferences(preferenceGroup); final CheckBoxPreference proxyPreference = (CheckBoxPreference) preferenceGroup .findPreference(getSharedKey(PREF_KEY_USE_PROXY)); proxyPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override//from w ww. ja v a2 s . c o m public boolean onPreferenceClick(Preference preference) { if (proxyPreference.isChecked() && captchaPreference.getValue().equals("recaptcha")) { captchaPreference.setValue("recaptcha-fallback"); } return false; } }); captchaPreference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { if (proxyPreference.isChecked() && newValue.equals("recaptcha")) { captchaPreference.setValue("recaptcha-fallback"); return false; } return true; } }); }
From source file:com.nttec.everychan.chans.ponyach.PonyachModule.java
@Override public void addPreferencesOnScreen(PreferenceGroup preferenceGroup) { final Context context = preferenceGroup.getContext(); ListPreference captchaLevel = new LazyPreferences.ListPreference(context); captchaLevel.setTitle(R.string.ponyach_prefs_captcha); captchaLevel.setDialogTitle(R.string.ponyach_prefs_captcha); captchaLevel.setKey(getSharedKey(PREF_KEY_CAPTCHA_LEVEL)); captchaLevel.setEntryValues(new String[] { "3", "2", "1" }); captchaLevel.setEntries(new String[] { "Easy", "Easy++", "Medium" }); captchaLevel.setDefaultValue("1"); preferenceGroup.addPreference(captchaLevel); EditTextPreference passcodePref = new EditTextPreference(context); passcodePref.setTitle(R.string.ponyach_prefs_passcode); passcodePref.setDialogTitle(R.string.ponyach_prefs_passcode); passcodePref.getEditText().setFilters(new InputFilter[] { new InputFilter.LengthFilter(6) }); passcodePref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override//from ww w . j av a 2 s . c o m public boolean onPreferenceChange(Preference preference, Object newValue) { final String newPasscode = (String) newValue; final CancellableTask passAuthTask = new CancellableTask.BaseCancellableTask(); final ProgressDialog passAuthProgressDialog = new ProgressDialog(context); passAuthProgressDialog.setMessage("Logging in"); passAuthProgressDialog.setOnCancelListener(new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { passAuthTask.cancel(); } }); passAuthProgressDialog.setCanceledOnTouchOutside(false); passAuthProgressDialog.show(); Async.runAsync(new Runnable() { @Override public void run() { try { if (passAuthTask.isCancelled()) return; String url = getUsingUrl() + "passcode.php"; List<BasicNameValuePair> pairs = Collections .singletonList(new BasicNameValuePair("passcode_just_set", newPasscode)); HttpRequestModel request = HttpRequestModel.builder() .setPOST(new UrlEncodedFormEntity(pairs, "UTF-8")).build(); HttpStreamer.getInstance().getStringFromUrl(url, request, httpClient, null, passAuthTask, false); savePhpCookies(); } catch (final Exception e) { if (context instanceof Activity) { ((Activity) context).runOnUiThread(new Runnable() { @Override public void run() { String message = e.getMessage() == null ? resources.getString(R.string.error_unknown) : e.getMessage(); Toast.makeText(context, message, Toast.LENGTH_LONG).show(); } }); } } finally { passAuthProgressDialog.dismiss(); } } }); return false; } }); preferenceGroup.addPreference(passcodePref); ListPreference domainPref = new LazyPreferences.ListPreference(context); domainPref.setTitle(R.string.pref_domain); domainPref.setDialogTitle(R.string.pref_domain); domainPref.setKey(getSharedKey(PREF_KEY_DOMAIN)); domainPref.setEntryValues(DOMAINS); domainPref.setEntries(DOMAINS); domainPref.setDefaultValue(DEFAULT_DOMAIN); domainPref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { loadPhpCookies((String) newValue); return true; } }); preferenceGroup.addPreference(domainPref); addHttpsPreference(preferenceGroup, useHttpsDefaultValue()); addProxyPreferences(preferenceGroup); captchaLevel.setSummary(captchaLevel.getEntry()); domainPref.setSummary(domainPref.getEntry()); }
From source file:com.android.email.activity.setup.MailboxSettings.java
/** * Setup the entries and entry values for the sync lookback preference * @param context the caller's context/*w w w .jav a2 s .com*/ * @param pref a ListPreference to be set up * @param maxLookback The maximum lookback allowed, or 0 if no max. * @param showWithDefault Whether to show the version with default, or without. */ public static void setupLookbackPreferenceOptions(final Context context, final ListPreference pref, final int maxLookback, final boolean showWithDefault) { final Resources resources = context.getResources(); // Load the complete list of entries/values CharSequence[] entries; CharSequence[] values; final int offset; if (showWithDefault) { entries = resources.getTextArray(R.array.account_settings_mail_window_entries_with_default); values = resources.getTextArray(R.array.account_settings_mail_window_values_with_default); offset = 1; } else { entries = resources.getTextArray(R.array.account_settings_mail_window_entries); values = resources.getTextArray(R.array.account_settings_mail_window_values); offset = 0; } // If we have a maximum lookback policy, enforce it if (maxLookback > 0) { final int size = maxLookback + offset; entries = Arrays.copyOf(entries, size); values = Arrays.copyOf(values, size); } // Set up the preference pref.setEntries(entries); pref.setEntryValues(values); pref.setSummary(pref.getEntry()); }
From source file:com.ichi2.anki.PreferenceContext.java
public void updateNotificationPreference(ListPreference listpref) { CharSequence[] entries = listpref.getEntries(); CharSequence[] values = listpref.getEntryValues(); for (int i = 0; i < entries.length; i++) { int value = Integer.parseInt(values[i].toString()); if (entries[i].toString().contains("%d")) { entries[i] = String.format(entries[i].toString(), value); }//from w ww .ja va2 s . co m } listpref.setEntries(entries); listpref.setSummary(listpref.getEntry().toString()); }
From source file:com.almalence.opencam.Fragment.java
private void initExportName(Preference preference, Object newValue) { EditTextPreference prefix = (EditTextPreference) this .findPreference(getResources().getString(R.string.Preference_SavePathPrefixValue)); String prefixValue = ""; if (prefix != null) { if (preference != null && prefix.getKey().equals(preference.getKey())) { prefixValue = newValue.toString(); } else {//from ww w . ja v a 2 s .c om prefixValue = prefix.getText(); } if (!prefixValue.equals("")) { prefixValue = prefixValue + "_"; } } EditTextPreference postfix = (EditTextPreference) this .findPreference(getResources().getString(R.string.Preference_SavePathPostfixValue)); String postfixValue = ""; if (postfix != null) { if (preference != null && postfix.getKey().equals(preference.getKey())) { postfixValue = newValue.toString(); } else { postfixValue = postfix.getText(); } if (!postfixValue.equals("")) { postfixValue = "_" + postfixValue; } } ListPreference exportNameList = (ListPreference) this .findPreference(getResources().getString(R.string.Preference_ExportNameValue)); if (exportNameList != null) { String[] names = MainScreen.getAppResources().getStringArray(R.array.exportNameArray); CharSequence[] newNames = new CharSequence[names.length]; int i = 0; for (String name : names) { newNames[i] = prefixValue + name + postfixValue; i++; } exportNameList.setEntries(newNames); exportNameList.setSummary(exportNameList.getEntries()[Integer.parseInt(exportNameList.getValue()) - 1]); } }
From source file:com.hichinaschool.flashcards.anki.DeckOptions.java
protected void buildLists() { ListPreference deckConfPref = (ListPreference) findPreference("deckConf"); ArrayList<JSONObject> confs = mCol.getDecks().allConf(); Collections.sort(confs, new JSONNameComparator()); String[] confValues = new String[confs.size()]; String[] confLabels = new String[confs.size()]; try {//from w w w . j a va 2s. c o m for (int i = 0; i < confs.size(); i++) { JSONObject o = confs.get(i); confValues[i] = o.getString("id"); confLabels[i] = o.getString("name"); } } catch (JSONException e) { throw new RuntimeException(e); } deckConfPref.setEntries(confLabels); deckConfPref.setEntryValues(confValues); deckConfPref.setValue(mPref.getString("deckConf", "0")); ListPreference newOrderPref = (ListPreference) findPreference("newOrder"); newOrderPref.setEntries(R.array.new_order_labels); newOrderPref.setEntryValues(R.array.new_order_values); newOrderPref.setValue(mPref.getString("newOrder", "0")); ListPreference leechActPref = (ListPreference) findPreference("lapLeechAct"); leechActPref.setEntries(R.array.leech_action_labels); leechActPref.setEntryValues(R.array.leech_action_values); leechActPref.setValue(mPref.getString("lapLeechAct", "0")); }
From source file:com.fastbootmobile.encore.app.fragments.SettingsFragment.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); getPreferenceManager().setSharedPreferencesName(SettingsKeys.PREF_SETTINGS); // Load the preferences from an XML resource addPreferencesFromResource(R.xml.settings); // Load Bluetooth paired devices final ListPreference btNameList = (ListPreference) findPreference( SettingsKeys.KEY_BLUETOOTH_AUTOCONNECT_NAME); BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter(); if (adapter == null) { // No Bluetooth adapter, remove preferences getPreferenceScreen().removePreference(findPreference(SettingsKeys.KEY_BLUETOOTH_AUTOCONNECT_ENABLE)); getPreferenceScreen().removePreference(findPreference(SettingsKeys.KEY_BLUETOOTH_AUTOCONNECT_ACTION)); getPreferenceScreen().removePreference(findPreference(SettingsKeys.KEY_BLUETOOTH_AUTOCONNECT_NAME)); getPreferenceScreen().removePreference(findPreference("category_bluetooth")); } else {//from w w w . j a v a2 s . c o m Set<BluetoothDevice> pairedDevices = adapter.getBondedDevices(); CharSequence[] entries = new CharSequence[pairedDevices.size()]; String currentPreferred = getPrefs().getString(SettingsKeys.KEY_BLUETOOTH_AUTOCONNECT_NAME, null); int i = 0; for (BluetoothDevice device : pairedDevices) { entries[i] = device.getName(); ++i; } btNameList.setEntries(entries); btNameList.setEntryValues(entries); if (currentPreferred != null) { btNameList.setDefaultValue(currentPreferred); } } }
From source file:com.android.switchaccess.SwitchAccessPreferenceActivity.java
private void adjustAutoscanPrefs() { if (isAutoScanEnabled(this)) { ListPreference scanMethodsPref = (ListPreference) findPreference( getString(R.string.pref_scanning_methods_key)); String optionScanKey = getString(R.string.option_scanning_key); if (isOptionScanningEnabled(this)) { /* If somehow both autoscan and option scan are enabled, turn off option scan */ scanMethodsPref.setValue(getString(R.string.row_col_scanning_key)); SharedPreferencesUtils.getSharedPreferences(this).edit() .putString(getString(R.string.pref_scanning_methods_key), getString(R.string.row_col_scanning_key)) .commit();//from ww w . j a v a2s.c o m } ArrayList<String> entries = new ArrayList<>( Arrays.asList(getResources().getStringArray(R.array.switch_access_scanning_methods_entries))); ArrayList<String> entryValues = new ArrayList<>( Arrays.asList(getResources().getStringArray(R.array.switch_access_scanning_methods_values))); int optionScanIndex = entryValues.indexOf(optionScanKey); entries.remove(optionScanIndex); entryValues.remove(optionScanIndex); scanMethodsPref.setEntries(entries.toArray(new String[entries.size()])); scanMethodsPref.setEntryValues(entryValues.toArray(new String[entries.size()])); } else { PreferenceScreen mainPrefScreen = (PreferenceScreen) findPreference( getString(R.string.main_pref_screen_key)); PreferenceScreen keyAssignmentScreen = (PreferenceScreen) findPreference( getString(R.string.pref_category_scan_mappings_key)); mainPrefScreen.removePreference(findPreference(getString(R.string.pref_key_auto_scan_time_delay))); removeKeyAssignmentPressIfEmpty(keyAssignmentScreen, R.string.pref_key_mapped_to_auto_scan_key); removeKeyAssignmentPressIfEmpty(keyAssignmentScreen, R.string.pref_key_mapped_to_reverse_auto_scan_key); if (isOptionScanningEnabled(this)) { mainPrefScreen.removePreference(findPreference(getString(R.string.pref_key_auto_scan_enabled))); } } }
From source file:com.ichi2.anki.PreferenceContext.java
private void initializeLanguageDialog(PreferenceScreen screen) { ListPreference languageSelection = (ListPreference) screen.findPreference(LANGUAGE); if (languageSelection != null) { Map<String, String> items = new TreeMap<>(); for (String localeCode : LanguageUtil.APP_LANGUAGES) { Locale loc = LanguageUtil.getLocale(localeCode); items.put(loc.getDisplayName(), loc.toString()); }//from w w w . ja va2 s . com CharSequence[] languageDialogLabels = new CharSequence[items.size() + 1]; CharSequence[] languageDialogValues = new CharSequence[items.size() + 1]; languageDialogLabels[0] = getResources().getString(R.string.language_system); languageDialogValues[0] = ""; int i = 1; for (Map.Entry<String, String> e : items.entrySet()) { languageDialogLabels[i] = e.getKey(); languageDialogValues[i] = e.getValue(); i++; } languageSelection.setEntries(languageDialogLabels); languageSelection.setEntryValues(languageDialogValues); } }