Search in sources :

Example 91 with ListPreference

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);
}
Also used : Resources(android.content.res.Resources) ListPreference(android.preference.ListPreference) SuppressLint(android.annotation.SuppressLint)

Example 92 with ListPreference

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());
}
Also used : ListPreference(android.preference.ListPreference)

Example 93 with ListPreference

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());
}
Also used : ListPreference(android.preference.ListPreference)

Example 94 with ListPreference

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());
}
Also used : ListPreference(android.preference.ListPreference)

Example 95 with ListPreference

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;
        }
    });
}
Also used : CheckBoxPreference(android.preference.CheckBoxPreference) SharedPreferences(android.content.SharedPreferences) DialogInterface(android.content.DialogInterface) ListPreference(android.preference.ListPreference) EditTextPreference(android.preference.EditTextPreference) CheckBoxPreference(android.preference.CheckBoxPreference) EditTextPreference(android.preference.EditTextPreference) ListPreference(android.preference.ListPreference) Preference(android.preference.Preference)

Aggregations

ListPreference (android.preference.ListPreference)167 Preference (android.preference.Preference)80 CheckBoxPreference (android.preference.CheckBoxPreference)50 EditTextPreference (android.preference.EditTextPreference)35 PreferenceScreen (android.preference.PreferenceScreen)21 SharedPreferences (android.content.SharedPreferences)20 ArrayList (java.util.ArrayList)19 Intent (android.content.Intent)16 PreferenceCategory (android.preference.PreferenceCategory)16 SuppressLint (android.annotation.SuppressLint)13 OnPreferenceChangeListener (android.preference.Preference.OnPreferenceChangeListener)9 MultiSelectListPreference (android.preference.MultiSelectListPreference)8 OnPreferenceClickListener (android.preference.Preference.OnPreferenceClickListener)8 File (java.io.File)8 Bundle (android.os.Bundle)7 SwitchPreference (android.preference.SwitchPreference)7 View (android.view.View)7 Context (android.content.Context)6 DialogInterface (android.content.DialogInterface)6 RingtonePreference (android.preference.RingtonePreference)6