use of android.preference.ListPreference in project AntennaPod by AntennaPod.
the class PreferenceController method buildEpisodeCleanupPreference.
private void buildEpisodeCleanupPreference() {
final Resources res = ui.getActivity().getResources();
ListPreference pref = (ListPreference) ui.findPreference(UserPreferences.PREF_EPISODE_CLEANUP);
String[] values = res.getStringArray(R.array.episode_cleanup_values);
String[] entries = new String[values.length];
for (int x = 0; x < values.length; x++) {
int v = Integer.parseInt(values[x]);
if (v == UserPreferences.EPISODE_CLEANUP_QUEUE) {
entries[x] = res.getString(R.string.episode_cleanup_queue_removal);
} else if (v == UserPreferences.EPISODE_CLEANUP_NULL) {
entries[x] = res.getString(R.string.episode_cleanup_never);
} else if (v == 0) {
entries[x] = res.getString(R.string.episode_cleanup_after_listening);
} else {
entries[x] = res.getQuantityString(R.plurals.episode_cleanup_days_after_listening, v, v);
}
}
pref.setEntries(entries);
}
use of android.preference.ListPreference in project android_frameworks_base by AOSPA.
the class ListPreferenceTest method testListPreferenceSummaryFromEntries.
public void testListPreferenceSummaryFromEntries() {
String[] entries = { "one", "two", "three" };
String[] entryValues = { "1", "2", "3" };
ListPreference lp = new ListPreference(getContext());
lp.setEntries(entries);
lp.setEntryValues(entryValues);
lp.setValue(entryValues[1]);
assertTrue(lp.getSummary() == null);
lp.setSummary("%1$s");
assertEquals(entries[1], lp.getSummary());
lp.setValue(entryValues[2]);
assertEquals(entries[2], lp.getSummary());
lp.setSummary(null);
assertTrue(lp.getSummary() == null);
lp.setSummary("The color is %1$s");
assertEquals("The color is " + entries[2], lp.getSummary());
}
use of android.preference.ListPreference in project android_frameworks_base by DirtyUnicorns.
the class ListPreferenceTest method testListPreferenceSummaryFromEntries.
public void testListPreferenceSummaryFromEntries() {
String[] entries = { "one", "two", "three" };
String[] entryValues = { "1", "2", "3" };
ListPreference lp = new ListPreference(getContext());
lp.setEntries(entries);
lp.setEntryValues(entryValues);
lp.setValue(entryValues[1]);
assertTrue(lp.getSummary() == null);
lp.setSummary("%1$s");
assertEquals(entries[1], lp.getSummary());
lp.setValue(entryValues[2]);
assertEquals(entries[2], lp.getSummary());
lp.setSummary(null);
assertTrue(lp.getSummary() == null);
lp.setSummary("The color is %1$s");
assertEquals("The color is " + entries[2], lp.getSummary());
}
use of android.preference.ListPreference in project android_frameworks_base by crdroidandroid.
the class ListPreferenceTest method testListPreferenceSummaryFromEntries.
public void testListPreferenceSummaryFromEntries() {
String[] entries = { "one", "two", "three" };
String[] entryValues = { "1", "2", "3" };
ListPreference lp = new ListPreference(getContext());
lp.setEntries(entries);
lp.setEntryValues(entryValues);
lp.setValue(entryValues[1]);
assertTrue(lp.getSummary() == null);
lp.setSummary("%1$s");
assertEquals(entries[1], lp.getSummary());
lp.setValue(entryValues[2]);
assertEquals(entries[2], lp.getSummary());
lp.setSummary(null);
assertTrue(lp.getSummary() == null);
lp.setSummary("The color is %1$s");
assertEquals("The color is " + entries[2], lp.getSummary());
}
use of android.preference.ListPreference in project apps-android-commons by commons-app.
the class SettingsFragment method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Load the preferences from an XML resource
addPreferencesFromResource(R.xml.preferences);
// Update spinner to show selected value as summary
ListPreference licensePreference = (ListPreference) findPreference(Prefs.DEFAULT_LICENSE);
licensePreference.setSummary(getString(Utils.licenseNameFor(licensePreference.getValue())));
// Keep summary updated when changing value
licensePreference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
preference.setSummary(getString(Utils.licenseNameFor((String) newValue)));
return true;
}
});
CheckBoxPreference themePreference = (CheckBoxPreference) findPreference("theme");
themePreference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
getActivity().recreate();
return true;
}
});
final EditTextPreference uploadLimit = (EditTextPreference) findPreference("uploads");
final SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(CommonsApplication.getInstance());
int uploads = sharedPref.getInt(Prefs.UPLOADS_SHOWING, 100);
uploadLimit.setText(uploads + "");
uploadLimit.setSummary(uploads + "");
uploadLimit.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
int value = Integer.parseInt(newValue.toString());
final SharedPreferences.Editor editor = sharedPref.edit();
if (value > 500) {
new AlertDialog.Builder(getActivity()).setTitle(R.string.maximum_limit).setMessage(R.string.maximum_limit_alert).setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
}
}).setIcon(android.R.drawable.ic_dialog_alert).show();
editor.putInt(Prefs.UPLOADS_SHOWING, 500);
editor.putBoolean(Prefs.IS_CONTRIBUTION_COUNT_CHANGED, true);
uploadLimit.setSummary(500 + "");
uploadLimit.setText(500 + "");
} else {
editor.putInt(Prefs.UPLOADS_SHOWING, Integer.parseInt(newValue.toString()));
editor.putBoolean(Prefs.IS_CONTRIBUTION_COUNT_CHANGED, true);
uploadLimit.setSummary(newValue.toString());
}
editor.apply();
return true;
}
});
}
Aggregations