Java Code Examples for android.preference.ListPreference#getEntryValues()

The following examples show how to use android.preference.ListPreference#getEntryValues() . 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: SettingsFragment.java    From 600SeriesAndroidUploader with MIT License 6 votes vote down vote up
/**
 * 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 2
Source File: KeyguardSettings.java    From AcDisplay with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void updateSummary(@NonNull Preference preference,
                          @NonNull Config.Option option,
                          @NonNull Object value) {
    ListPreference cbp = (ListPreference) preference;
    final CharSequence valueStr = Integer.toString((Integer) value);
    final CharSequence[] values = cbp.getEntryValues();
    final int length = values.length;
    for (int i = 0; i < length; i++) {
        if (valueStr.equals(values[i])) {
            cbp.setSummary(cbp.getEntries()[i]);
            break;
        }
    }

}
 
Example 3
Source File: KeyguardSettings.java    From HeadsUp with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void updateSummary(@NonNull Preference preference,
                          @NonNull Config.Option option,
                          @NonNull Object value) {
    String theme = (String) value;
    ListPreference cbp = (ListPreference) preference;

    CharSequence[] themes = cbp.getEntryValues();
    for (int i = 0; i < themes.length; i++) {
        if (TextUtils.equals(theme, themes[i])) {
            cbp.setSummary(getString(
                    R.string.settings_theme_summary,
                    cbp.getEntries()[i]));
            break;
        }
    }
}
 
Example 4
Source File: Preferences.java    From Plumble with GNU General Public License v3.0 6 votes vote down vote up
private static void configureAudioPreferences(final PreferenceScreen screen) {
    ListPreference inputPreference = (ListPreference) screen.findPreference(Settings.PREF_INPUT_METHOD);
    inputPreference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            updateAudioDependents(screen, (String) newValue);
            return true;
        }
    });

    // Scan each bitrate and determine if the device supports it
    ListPreference inputQualityPreference = (ListPreference) screen.findPreference(Settings.PREF_INPUT_RATE);
    String[] bitrateNames = new String[inputQualityPreference.getEntryValues().length];
    for(int x=0;x<bitrateNames.length;x++) {
        int bitrate = Integer.parseInt(inputQualityPreference.getEntryValues()[x].toString());
        boolean supported = AudioRecord.getMinBufferSize(bitrate, AudioFormat.CHANNEL_IN_MONO, AudioFormat.ENCODING_PCM_16BIT) > 0;
        bitrateNames[x] = bitrate+"Hz" + (supported ? "" : " (unsupported)");
    }
    inputQualityPreference.setEntries(bitrateNames);

    updateAudioDependents(screen, inputPreference.getValue());
}
 
Example 5
Source File: GeneralPreferenceFragment.java    From V2EX with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getPreferenceManager().setSharedPreferencesName(
            Config.getConfig(ConfigRefEnum.CONFIG_PREFERENCE_SETTING_FILE));
    addPreferencesFromResource(R.xml.pref_general);

    ListPreference themePreference = (ListPreference) findPreference(
            getString(R.string.key_theme));
    themePreference.setSummary(Config.getConfig(ConfigRefEnum.CONFIG_THEME));

    ListPreference dateFormatPreference = (ListPreference)findPreference(
            getString(R.string.key_date_format));
    String[] dateEntries = new String[dateFormatPreference.getEntryValues().length];
    int i = 0;
    for (CharSequence s:dateFormatPreference.getEntryValues()){
        String date = TimeUtil.getDateNow(String.valueOf(s));
        dateEntries[i++] = date;
    }
    dateFormatPreference.setEntries(dateEntries);
    dateFormatPreference.setSummary(TimeUtil.getDateNow(Config.getConfig(
            ConfigRefEnum.CONFIG_DATE_FORMAT)));

    ListPreference localePreference = (ListPreference) findPreference(getString(R.string.key_local));
    String[] localesEntryValue = new String[Config.LOCAL_LIST.size()];
    String[] localesEntries= new String[Config.LOCAL_LIST.size()];
    int index = 0;
    for (Locale locale:Config.LOCAL_LIST){
        localesEntryValue[index] = locale.toString();
        localesEntries[index++] = locale.getDisplayCountry();
    }
    localePreference.setDefaultValue(localesEntryValue[0]);
    localePreference.setEntryValues(localesEntryValue);
    localePreference.setEntries(localesEntries);

    Preference clearCachePreference = findPreference(getString(R.string.clear_cache));
    clearCachePreference.setOnPreferenceClickListener(this::clearCache);
    clearCachePreference.setSummary("缓存大小 12 MB");
    findPreference(getString(R.string.key_home_tabs)).setOnPreferenceClickListener(preference -> {
        CustomTabActivity.start(getActivity());
        return false;
    });
}