Java Code Examples for android.preference.MultiSelectListPreference#setDefaultValue()

The following examples show how to use android.preference.MultiSelectListPreference#setDefaultValue() . 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 JPPF with Apache License 2.0 6 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
  try {
    super.onCreate(savedInstanceState);
    // Load the preferences screen from an XML resource
    addPreferencesFromResource(R.xml.preferences);
    String[] pickerKeys = { PreferenceUtils.TRUST_STORE_LOCATION_KEY, PreferenceUtils.KEY_STORE_LOCATION_KEY };
    for (String key: pickerKeys) {
      FilechoserEditTextPreference picker = (FilechoserEditTextPreference) findPreference(key);
      picker.setFragment(this);
    }
    PreferenceScreen pref = (PreferenceScreen) findPreference("pref_security");
    if (SUPPORTED_CIPHER_SUITES.isEmpty()) {
      SSLSocketFactory ssf = (SSLSocketFactory) SSLSocketFactory.getDefault();
      ENABLED_CIPHER_SUITES.addAll(Arrays.asList(ssf.getDefaultCipherSuites()));
      SUPPORTED_CIPHER_SUITES.addAll(Arrays.asList(ssf.getSupportedCipherSuites()));
    }
    MultiSelectListPreference ciphersPref = (MultiSelectListPreference) findPreference(PreferenceUtils.ENABLED_CIPHER_SUITES_KEY);
    ciphersPref.setDefaultValue(ENABLED_CIPHER_SUITES.toArray(new String[ENABLED_CIPHER_SUITES.size()]));
    ciphersPref.setEntryValues(SUPPORTED_CIPHER_SUITES.toArray(new String[SUPPORTED_CIPHER_SUITES.size()]));
    ciphersPref.setEntries(SUPPORTED_CIPHER_SUITES.toArray(new String[SUPPORTED_CIPHER_SUITES.size()]));
  } catch(Throwable t) {
    t.printStackTrace();
  }
}
 
Example 2
Source File: SettingsActivity.java    From Equate with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Helper Class to setup the default Unit Type preference list in code
 */
private void setUpUnitTypePrefs() {
   PreferenceScreen screen = getPreferenceScreen();
   MultiSelectListPreference listPref = new MultiSelectListPreference(super.getActivity());
   listPref.setOrder(0);
   listPref.setDialogTitle(R.string.unit_select_title);
   listPref.setKey(UNIT_TYPE_PREF_KEY);
   listPref.setSummary(R.string.unit_select_summary);
   listPref.setTitle(R.string.unit_select_title);
   listPref.setEntries(getUnitTypeNameArray(getResources()));

   String[] keyArray = getUnitTypeKeyArray(getResources());
   listPref.setEntryValues(keyArray);

   final Set<String> result = new HashSet<>();
   Collections.addAll(result, keyArray);

   listPref.setDefaultValue(result);

   screen.addPreference(listPref);
}
 
Example 3
Source File: PrefsActivity.java    From ETSMobile-Android2 with Apache License 2.0 3 votes vote down vote up
@Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);

            addPreferencesFromResource(R.xml.preferences);
            
            String[] selections = getResources().getStringArray(R.array.sources_news_values);
            Set<String> selectionSet = new HashSet<String>();
            selectionSet.addAll(Arrays.asList(selections));

            MultiSelectListPreference multiSelectPref = new MultiSelectListPreference(getActivity());
            multiSelectPref.setKey("multi_pref");
            multiSelectPref.setTitle(CHOIX_DES_SOURCES);
            multiSelectPref.setEntries(R.array.sources_news);
            multiSelectPref.setEntryValues(R.array.sources_news_values);
            multiSelectPref.setDefaultValue(selectionSet);
            getPreferenceScreen().addPreference(multiSelectPref);





            // Make sure default values are applied.  In a real app, you would
            // want this in a shared function that is used to retrieve the
            // SharedPreferences wherever they are needed.
//            PreferenceManager.setDefaultValues(getActivity(),R.xml.advanced_preferences, false);

            // Load the preferences from an XML resource

        }