本文整理汇总了Java中net.xpece.android.support.preference.MultiSelectListPreference类的典型用法代码示例。如果您正苦于以下问题:Java MultiSelectListPreference类的具体用法?Java MultiSelectListPreference怎么用?Java MultiSelectListPreference使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MultiSelectListPreference类属于net.xpece.android.support.preference包,在下文中一共展示了MultiSelectListPreference类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: bindPreferenceSummaryToValue
import net.xpece.android.support.preference.MultiSelectListPreference; //导入依赖的package包/类
/**
* Binds a preference's summary to its value. More specifically, when the
* preference's value is changed, its summary (line of text below the
* preference title) is updated to reflect the value. The summary is also
* immediately updated upon calling this method. The exact display format is
* dependent on the type of preference.
*
* @see #sBindPreferenceSummaryToValueListener
*/
private static void bindPreferenceSummaryToValue(Preference preference) {
// Set the listener to watch for value changes.
preference.setOnPreferenceChangeListener(sBindPreferenceSummaryToValueListener);
// Trigger the listener immediately with the preference's
// current value.
final String key = preference.getKey();
if (preference instanceof MultiSelectListPreference) {
Set<String> summary = SharedPreferencesCompat.getStringSet(
PreferenceManager.getDefaultSharedPreferences(preference.getContext()),
key,
new HashSet<>());
sBindPreferenceSummaryToValueListener.onPreferenceChange(preference, summary);
} else if (preference instanceof ColorPreference) {
sBindPreferenceSummaryToValueListener.onPreferenceChange(preference, ((ColorPreference) preference).getColor());
} else if (preference instanceof SeekBarPreference) {
sBindPreferenceSummaryToValueListener.onPreferenceChange(preference, ((SeekBarPreference) preference).getValue());
} else {
String value = PreferenceManager
.getDefaultSharedPreferences(preference.getContext())
.getString(key, "");
sBindPreferenceSummaryToValueListener.onPreferenceChange(preference, value);
}
}
示例2: updateLinesPreferenceSummary
import net.xpece.android.support.preference.MultiSelectListPreference; //导入依赖的package包/类
private void updateLinesPreferenceSummary(MultiSelectListPreference preference, Set<String> values) {
List<String> sortedValues = new ArrayList<String>(values);
Collections.sort(sortedValues);
if (!values.isEmpty()) {
CharSequence summary = getSelectedEntries(sortedValues, preference).toString();
summary = summary.subSequence(1, summary.length() - 1);
preference.setSummary(String.format(getString(R.string.frag_notif_summary_lines), summary));
} else {
preference.setSummary(getString(R.string.frag_notif_summary_no_lines));
}
Preference notifsDistServiceResumed = findPreference("pref_notifs_service_resumed");
Preference notifsDistRingtone = findPreference("pref_notifs_ringtone");
Preference notifsDistVibrate = findPreference("pref_notifs_vibrate");
notifsDistServiceResumed.setEnabled(values.size() != 0);
notifsDistRingtone.setEnabled(values.size() != 0);
notifsDistVibrate.setEnabled(values.size() != 0);
}
示例3: updateSourcesPreferenceSummary
import net.xpece.android.support.preference.MultiSelectListPreference; //导入依赖的package包/类
private void updateSourcesPreferenceSummary(MultiSelectListPreference preference, Set<String> values) {
List<String> sortedValues = new ArrayList<String>(values);
Collections.sort(sortedValues);
if (!values.isEmpty()) {
CharSequence summary = getSelectedEntries(sortedValues, preference).toString();
summary = summary.subSequence(1, summary.length() - 1);
preference.setSummary(String.format(getString(R.string.frag_notif_summary_sources), summary));
} else {
preference.setSummary(getString(R.string.frag_notif_summary_no_sources));
}
Preference notifsAnnRingtone = findPreference("pref_notifs_announcement_ringtone");
Preference notifsAnnVibrate = findPreference("pref_notifs_announcement_vibrate");
notifsAnnRingtone.setEnabled(values.size() != 0);
notifsAnnVibrate.setEnabled(values.size() != 0);
}
示例4: bindPreferenceSummaryToValue
import net.xpece.android.support.preference.MultiSelectListPreference; //导入依赖的package包/类
private static void bindPreferenceSummaryToValue(Preference preference) {
// Set the listener to watch for value changes.
preference.setOnPreferenceChangeListener(sBindPreferenceSummaryToValueListener);
// Trigger the listener immediately with the preference's
// current value.
final String key = preference.getKey();
if (preference instanceof MultiSelectListPreference) {
Set<String> summary = SharedPreferencesCompat.getStringSet(
PreferenceManager.getDefaultSharedPreferences(preference.getContext()),
key, new HashSet<String>());
sBindPreferenceSummaryToValueListener.onPreferenceChange(preference, summary);
} else if (preference instanceof SeekBarPreference) {
sBindPreferenceSummaryToValueListener.onPreferenceChange(preference, ((SeekBarPreference) preference).getValue());
} else {
String value = PreferenceManager
.getDefaultSharedPreferences(preference.getContext())
.getString(key, "");
sBindPreferenceSummaryToValueListener.onPreferenceChange(preference, value);
}
}
示例5: getSelectedEntries
import net.xpece.android.support.preference.MultiSelectListPreference; //导入依赖的package包/类
private List<CharSequence> getSelectedEntries(List<String> values, MultiSelectListPreference multilistPreference) {
List<CharSequence> labels = new ArrayList<>();
for (String value : values) {
int index = multilistPreference.findIndexOfValue(value);
if (index >= 0) {
labels.add(multilistPreference.getEntries()[index]);
}
}
return labels;
}
示例6: onPreferenceChange
import net.xpece.android.support.preference.MultiSelectListPreference; //导入依赖的package包/类
@Override
public boolean onPreferenceChange(Preference preference, Object value) {
String stringValue = value.toString();
if (preference instanceof SeekBarPreference) {
SeekBarPreference pref = (SeekBarPreference) preference;
int progress = (int) value;
pref.setInfo(progress + "%");
} else if (preference instanceof ListPreference) {
// For list preferences, look up the correct display value in
// the preference's 'entries' list.
ListPreference listPreference = (ListPreference) preference;
int index = listPreference.findIndexOfValue(stringValue);
// Set the summary to reflect the new value.
preference.setSummary(
index >= 0
? listPreference.getEntries()[index]
: null);
} else if (preference instanceof MultiSelectListPreference) {
String summary = stringValue.trim().substring(1, stringValue.length() - 1); // strip []
preference.setSummary(summary);
} else if (preference instanceof RingtonePreference) {
// For ringtone preferences, look up the correct display value using RingtoneManager.
if (TextUtils.isEmpty(stringValue)) {
// Empty values correspond to 'silent' (no ringtone).
preference.setSummary(R.string.frag_notif_summary_silent);
} else {
final Uri selectedUri = Uri.parse(stringValue);
try {
final Ringtone ringtone = RingtoneManager.getRingtone(
preference.getContext(), selectedUri);
if (ringtone == null) {
// Clear the summary if there was a lookup error, i.e. does not exist.
preference.setSummary(null);
} else {
// Set the summary to reflect the new ringtone display name.
final String name = ringtone.getTitle(preference.getContext());
preference.setSummary(name);
}
} catch (SecurityException ex) {
// The user has selected a ringtone from external storage
// and then revoked READ_EXTERNAL_STORAGE permission.
// We have no way of guessing the ringtone title.
// We'd have to store the title of selected ringtone in prefs as well.
preference.setSummary("???");
}
}
} else {
// For all other preferences, set the summary to the value's
// simple string representation.
preference.setSummary(stringValue);
}
return true;
}