Search in sources :

Example 56 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 57 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 58 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)58 Preference (android.preference.Preference)25 CheckBoxPreference (android.preference.CheckBoxPreference)18 EditTextPreference (android.preference.EditTextPreference)15 PreferenceScreen (android.preference.PreferenceScreen)12 PreferenceCategory (android.preference.PreferenceCategory)8 SharedPreferences (android.content.SharedPreferences)7 Intent (android.content.Intent)6 Resources (android.content.res.Resources)5 OnPreferenceClickListener (android.preference.Preference.OnPreferenceClickListener)5 DialogInterface (android.content.DialogInterface)4 OnPreferenceChangeListener (android.preference.Preference.OnPreferenceChangeListener)4 ArrayList (java.util.ArrayList)4 SuppressLint (android.annotation.SuppressLint)3 View (android.view.View)3 File (java.io.File)3 Activity (android.app.Activity)2 AlertDialog (android.app.AlertDialog)2 PackageManager (android.content.pm.PackageManager)2 Bundle (android.os.Bundle)2