Java Code Examples for androidx.preference.ListPreference#getEntries()

The following examples show how to use androidx.preference.ListPreference#getEntries() . 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 Android-Application with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
    ListPreference thermalPeletteList = (ListPreference) preference;

    try{
        String val = (String) newValue;
        //Try to get ThermalPalette from value...
        String className = ThermalPalette.class.getPackage().getName()+"."+val;
        Log.d("SettingsFragment", "Trying to load className: " + className);
        ThermalPalette palette = (ThermalPalette) Class.forName(className).newInstance();

        double min = palette.getDefaultMinTemperature();
        double max = palette.getDefaultMaxTemperature();

        findPreference("thermal_palette_default_range_info").setTitle("Default Range is from " + min + " to " + max + ".");

        //current selected to summary
        CharSequence entry = thermalPeletteList.getEntries()[thermalPeletteList.findIndexOfValue(val)];
        Log.d("SettingsFragment", "Changing summary to: " + entry);
        ((ListPreference)preference).setSummary(entry);

    } catch (Exception ex) {
        ex.printStackTrace();
    }



    return true;

}
 
Example 2
Source File: SettingsFragment.java    From SmsCode with GNU General Public License v3.0 5 votes vote down vote up
private void refreshListenModePreference(ListPreference listenModePref, String newValue) {
    if (TextUtils.isEmpty(newValue))
        return;
    CharSequence[] entries = listenModePref.getEntries();
    int index = listenModePref.findIndexOfValue(newValue);
    try {
        listenModePref.setSummary(entries[index]);
    } catch (Exception e) {
        //ignore
    }
}
 
Example 3
Source File: AutoInputSettingsFragment.java    From SmsCode with GNU General Public License v3.0 5 votes vote down vote up
private void refreshFocusModePreference(ListPreference focusModePref, String newValue) {
    if (TextUtils.isEmpty(newValue))
        return;
    CharSequence[] entries = focusModePref.getEntries();
    int index = focusModePref.findIndexOfValue(newValue);
    try {
        focusModePref.setSummary(entries[index]);
    } catch (Exception e) {
        //ignore
    }
}
 
Example 4
Source File: ListSummaryPreferenceFragment.java    From deltachat-android with GNU General Public License v3.0 5 votes vote down vote up
protected String getSelectedSummary(Preference preference, Object value) {
  ListPreference listPref = (ListPreference) preference;
  int entryIndex = Arrays.asList(listPref.getEntryValues()).indexOf(value);
  return entryIndex >= 0 && entryIndex < listPref.getEntries().length
          ? listPref.getEntries()[entryIndex].toString()
          : getString(R.string.unknown);
}
 
Example 5
Source File: TalkBackPreferencesActivity.java    From talkback with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
  if (preference instanceof ListPreference && newValue instanceof String) {
    final ListPreference listPreference = (ListPreference) preference;
    final int index = listPreference.findIndexOfValue((String) newValue);
    final CharSequence[] entries = listPreference.getEntries();

    if (index >= 0 && index < entries.length) {
      preference.setSummary(entries[index].toString().replaceAll("%", "%%"));
    } else {
      preference.setSummary("");
    }
  }

  final String key = preference.getKey();
  if (getString(R.string.pref_resume_talkback_key).equals(key)) {
    final String oldValue =
        SharedPreferencesUtils.getStringPref(
            prefs,
            getResources(),
            R.string.pref_resume_talkback_key,
            R.string.pref_resume_talkback_default);
    if (!newValue.equals(oldValue)) {
      // Reset the suspend warning dialog when the resume
      // preference changes.
      SharedPreferencesUtils.putBooleanPref(
          prefs, getResources(), R.string.pref_show_suspension_confirmation_dialog, true);
    }
  }

  return true;
}