Example usage for android.preference ListPreference setEntryValues

List of usage examples for android.preference ListPreference setEntryValues

Introduction

In this page you can find the example usage for android.preference ListPreference setEntryValues.

Prototype

public void setEntryValues(@ArrayRes int entryValuesResId) 

Source Link

Usage

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/* w  w w  .ja v  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.schoentoon.connectbot.HostEditorActivity.java

@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    getSupportActionBar().setSubtitle("Host editor");
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    long hostId = this.getIntent().getLongExtra(Intent.EXTRA_TITLE, -1);

    // TODO: we could pass through a specific ContentProvider uri here
    //this.getPreferenceManager().setSharedPreferencesName(uri);

    this.hostdb = new HostDatabase(this);
    this.pubkeydb = new PubkeyDatabase(this);

    host = hostdb.findHostById(hostId);/*from w  w  w  .  jav a 2 s.  c  o m*/

    connection = new ServiceConnection() {
        public void onServiceConnected(ComponentName className, IBinder service) {
            TerminalManager bound = ((TerminalManager.TerminalBinder) service).getService();

            hostBridge = bound.getConnectedBridge(host);
        }

        public void onServiceDisconnected(ComponentName name) {
            hostBridge = null;
        }
    };

    this.pref = new CursorPreferenceHack(HostDatabase.TABLE_HOSTS, hostId);
    this.pref.registerOnSharedPreferenceChangeListener(this);

    this.addPreferencesFromResource(R.xml.host_prefs);

    // add all existing pubkeys to our listpreference for user to choose from
    // TODO: may be an issue here when this activity is recycled after adding a new pubkey
    // TODO: should consider moving into onStart, but we dont have a good way of resetting the listpref after filling once
    ListPreference pubkeyPref = (ListPreference) this.findPreference(HostDatabase.FIELD_HOST_PUBKEYID);

    List<CharSequence> pubkeyNicks = new LinkedList<CharSequence>(Arrays.asList(pubkeyPref.getEntries()));
    pubkeyNicks.addAll(pubkeydb.allValues(PubkeyDatabase.FIELD_PUBKEY_NICKNAME));
    pubkeyPref.setEntries(pubkeyNicks.toArray(new CharSequence[pubkeyNicks.size()]));

    List<CharSequence> pubkeyIds = new LinkedList<CharSequence>(Arrays.asList(pubkeyPref.getEntryValues()));
    pubkeyIds.addAll(pubkeydb.allValues("_id"));
    pubkeyPref.setEntryValues(pubkeyIds.toArray(new CharSequence[pubkeyIds.size()]));

    // Populate the character set encoding list with all available
    final ListPreference charsetPref = (ListPreference) findPreference(HostDatabase.FIELD_HOST_ENCODING);

    if (CharsetHolder.isInitialized()) {
        initCharsetPref(charsetPref);
    } else {
        String[] currentCharsetPref = new String[1];
        currentCharsetPref[0] = charsetPref.getValue();
        charsetPref.setEntryValues(currentCharsetPref);
        charsetPref.setEntries(currentCharsetPref);

        new Thread(new Runnable() {
            public void run() {
                initCharsetPref(charsetPref);
            }
        }).start();
    }

    this.updateSummaries();
}

From source file:com.bellman.bible.android.view.activity.settings.SettingsActivity.java

private void addScreenTimeoutSettings() {
    ListPreference timeoutPref = (ListPreference) getPreferenceScreen()
            .findPreference(ScreenTimeoutSettings.SCREEN_TIMEOUT_PREF);

    timeoutPref.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {

        @Override/*w  w w.  j  a v a 2s  . c o  m*/
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            // update screen timeout
            try {
                if (StringUtils.isNotEmpty((String) newValue)) {
                    ScreenTimeoutSettings.setScreenTimeout(Integer.parseInt((String) newValue));
                }
            } catch (Exception e) {
                Log.e(TAG, "Error updating timeout set in preference screen", e);
            }

            return true;
        }
    });

    ScreenTimeoutSettings screenTimeoutSettings = new ScreenTimeoutSettings();
    timeoutPref.setEntries(screenTimeoutSettings.getPreferenceEntries());
    timeoutPref.setEntryValues(screenTimeoutSettings.getPreferenceEntryValues());
}

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//from  ww w. j  a v a2  s.c o  m
 * @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.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  av a  2  s.  com
        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  ww w.j a  v  a2s.  c om
        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();/*  www. j a  v  a 2  s .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:jackpal.androidterm.TermPreferences.java

private ListPreference setFontList(ListPreference fontFileList) {
    File files[] = new File(FONTPATH).listFiles();
    ArrayList<File> fonts = new ArrayList<File>();

    if (files != null) {
        for (File file : files) {
            if (file.isFile() == true && file.getName().matches(".*\\.(?i)(ttf|ttc|otf)")
                    && file.isHidden() == false) {
                fonts.add(file);//  w w  w .jav a  2 s .c o m
            }
        }
    }
    Collections.sort(fonts);
    int i = fonts.size() + 1;
    CharSequence[] items = new CharSequence[i];
    CharSequence[] values = new CharSequence[i];

    i = 0;
    Resources res = getResources();
    String systemFontName = res.getString(R.string.entry_fontfile_default);
    items[i] = systemFontName;
    values[i] = systemFontName;
    i++;

    Iterator<File> itr = fonts.iterator();
    while (itr.hasNext()) {
        File file = itr.next();
        items[i] = file.getName();
        values[i] = file.getName();
        i++;
    }

    fontFileList.setEntries(items);
    fontFileList.setEntryValues(values);
    return fontFileList;
}

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   www  .j a v  a  2  s.  c o m*/
        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);
    }
}