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

The following examples show how to use android.preference.MultiSelectListPreference#setEntries() . 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: CreateModulePreference.java    From GNSS_Compare with Apache License 2.0 6 votes vote down vote up
/**
 * defines a multiSelectList preference
 * @param preferenceKey Key of the preference
 * @param registeredObjectNames set containing possible values in the list preference
 * @param intentExtras intent passed to the fragment
 */
private void defineMultiSelectListPrefernece(String preferenceKey, Set<String> registeredObjectNames, Bundle intentExtras) {

    MultiSelectListPreference preference = (MultiSelectListPreference) findPreference(preferenceKey);
    CharSequence[] entries =
            registeredObjectNames.toArray(new CharSequence[registeredObjectNames.size()]);

    preference.setEntries(entries);
    preference.setEntryValues(entries);

    if(intentExtras != null){
        if(intentExtras.getStringArray(preferenceKey) == null){
            preference.setValues(null);
        } else {
            Set<String> selectedCorrections = new HashSet<>(Arrays.asList(intentExtras.getStringArray(preferenceKey)));
            preference.setValues(selectedCorrections);
        }
    } else {
        preference.setValues(new HashSet<String>());
    }
}
 
Example 2
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 3
Source File: QuietHoursActivity.java    From GravityBox with Apache License 2.0 6 votes vote down vote up
private void setupWeekDaysPref() {
    mPrefWeekDays = (MultiSelectListPreference) findPreference(PREF_KEY_QH_WEEKDAYS);
    String[] days = new DateFormatSymbols(Locale.getDefault()).getWeekdays();
    CharSequence[] entries = new CharSequence[7];
    CharSequence[] entryValues = new CharSequence[7];
    for (int i = 1; i <= 7; i++) {
        entries[i - 1] = days[i];
        entryValues[i - 1] = String.valueOf(i);
    }
    mPrefWeekDays.setEntries(entries);
    mPrefWeekDays.setEntryValues(entryValues);
    if (mPrefs.getStringSet(PREF_KEY_QH_WEEKDAYS, null) == null) {
        Set<String> value = new HashSet<String>(Arrays.asList("2", "3", "4", "5", "6"));
        mPrefs.edit().putStringSet(PREF_KEY_QH_WEEKDAYS, value).commit();
        mPrefWeekDays.setValues(value);
    }
}
 
Example 4
Source File: SettingsActivity.java    From AndrOBD with GNU General Public License v3.0 6 votes vote down vote up
/**
 * set up protocol selection
 */
void setupElmCmdSelection()
{
	MultiSelectListPreference pref =
		(MultiSelectListPreference) findPreference(ELM_CMD_DISABLE);
	ElmProt.CMD[] values = ElmProt.CMD.values();
	HashSet<String> selections = new HashSet<>();
	CharSequence[] titles = new CharSequence[values.length];
	CharSequence[] keys = new CharSequence[values.length];
	int i = 0;
	for (ElmProt.CMD cmd : values)
	{
		titles[i] = cmd.toString();
		keys[i] = cmd.toString();
		if(!cmd.isEnabled()) selections.add(cmd.toString());
		i++;
	}
	// set enries and keys
	pref.setEntries(titles);
	pref.setEntryValues(keys);
	pref.setValues(selections);
}
 
Example 5
Source File: GroupPreferenceFragment.java    From tickmate with GNU General Public License v3.0 6 votes vote down vote up
private void loadGroup() {
    // Consider adding more features here, such as those in Track and TrackPreferenceFragment
    name = (EditTextPreference) findPreference("name");
    name.setText(group.getName());
    name.setSummary(group.getName());

    description = (EditTextPreference) findPreference("description");
    description.setText(group.getDescription());
    description.setSummary(group.getDescription());

    mTracksPref = (MultiSelectListPreference) findPreference("tracks");
    mTracksPref.setValues(getTrackIdsForGroupAsSet(group.getId()));

    mTracksPref.setEntries(getAllTrackNamesAsCharSeq());
    mTracksPref.setEntryValues(getAllTrackIdsAsCharSeq());
    mTracksPref.setSummary(getTrackNamesForSummary());

}
 
Example 6
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 7
Source File: PBPreferenceFragment.java    From client-android with GNU General Public License v2.0 5 votes vote down vote up
private void fillBuckets() {
    this.bucketNames = PBApplication.getMediaStore().getBucketData();

    final CharSequence[] ids = this.bucketNames.values().toArray(new CharSequence[this.bucketNames.size()]);
    final CharSequence[] names = this.bucketNames.keySet().toArray(new CharSequence[this.bucketNames.size()]);

    final MultiSelectListPreference bucketListPreference = (MultiSelectListPreference) findPreference(PBConstants.PREF_PICTURE_FOLDER_LIST);
    bucketListPreference.setEntries(ids);
    bucketListPreference.setEnabled(true);
    bucketListPreference.setEntryValues(names);

    setSummaries();
}
 
Example 8
Source File: SettingsActivity.java    From AndrOBD with GNU General Public License v3.0 5 votes vote down vote up
/**
 * set up selection for PIDs
 */
void setupPidSelection()
{
	MultiSelectListPreference itemList =
		(MultiSelectListPreference) findPreference(KEY_DATA_ITEMS);

	// collect data items for selection
	items = ObdProt.dataItems.getSvcDataItems(ObdProt.OBD_SVC_DATA);
	HashSet<String> selections = new HashSet<>();
	CharSequence[] titles = new CharSequence[items.size()];
	CharSequence[] keys = new CharSequence[items.size()];
	// loop through data items
	int i = 0;
	for (EcuDataItem currItem : items)
	{
		titles[i] = currItem.label;
		keys[i] = currItem.toString();
		selections.add(currItem.toString());
		i++;
	}
	// set enries and keys
	itemList.setEntries(titles);
	itemList.setEntryValues(keys);

	// if there is no item selected, mark all as selected
	if (itemList.getValues().size() == 0)
	{
		itemList.setValues(selections);
	}
}
 
Example 9
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

        }