use of net.xpece.android.support.preference.MultiSelectListPreference in project underlx by underlx.
the class NotifPreferenceFragment method updateSourcesPreference.
private void updateSourcesPreference() {
MultiSelectListPreference sourcesPreference;
sourcesPreference = (MultiSelectListPreference) findPreference(PreferenceNames.AnnouncementSources);
List<CharSequence> entryValues = new ArrayList<>();
List<CharSequence> entries = new ArrayList<>();
for (Announcement.Source source : Announcement.getSources()) {
entryValues.add(source.id);
entries.add(getString(source.nameResourceId));
}
sourcesPreference.setEntryValues(entryValues.toArray(new CharSequence[entryValues.size()]));
sourcesPreference.setEntries(entries.toArray(new CharSequence[entries.size()]));
updateSourcesPreferenceSummary(sourcesPreference, sourcesPreference.getValues());
sourcesPreference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
public boolean onPreferenceChange(Preference preference, Object newValue) {
MultiSelectListPreference multilistPreference = (MultiSelectListPreference) preference;
@SuppressWarnings("unchecked") Set<String> values = (Set<String>) newValue;
updateSourcesPreferenceSummary(multilistPreference, values);
return true;
}
});
}
use of net.xpece.android.support.preference.MultiSelectListPreference in project underlx by underlx.
the class NotifPreferenceFragment method updateLinesPreference.
private void updateLinesPreference() {
MultiSelectListPreference linesPreference;
linesPreference = (MultiSelectListPreference) findPreference(PreferenceNames.NotifsLines);
List<CharSequence> lineNames = new ArrayList<>();
List<CharSequence> lineIDs = new ArrayList<>();
List<Line> lines = new LinkedList<>();
if (mListener != null && mListener.getMainService() != null) {
for (Network n : mListener.getMainService().getNetworks()) {
lines.addAll(n.getLines());
}
Collections.sort(lines, new Comparator<Line>() {
@Override
public int compare(Line line, Line t1) {
return Integer.valueOf(line.getOrder()).compareTo(t1.getOrder());
}
});
for (Line l : lines) {
lineNames.add(Util.getLineNames(getContext(), l)[0]);
lineIDs.add(l.getId());
}
}
linesPreference.setEntries(lineNames.toArray(new CharSequence[lineNames.size()]));
linesPreference.setEntryValues(lineIDs.toArray(new CharSequence[lineIDs.size()]));
updateLinesPreferenceSummary(linesPreference, linesPreference.getValues());
linesPreference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
public boolean onPreferenceChange(Preference preference, Object newValue) {
MultiSelectListPreference multilistPreference = (MultiSelectListPreference) preference;
@SuppressWarnings("unchecked") Set<String> values = (Set<String>) newValue;
updateLinesPreferenceSummary(multilistPreference, values);
return true;
}
});
}
use of net.xpece.android.support.preference.MultiSelectListPreference in project underlx by underlx.
the class NotifPreferenceFragment method updateLinesPreferenceSummary.
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(PreferenceNames.NotifsServiceResumed);
Preference notifsDistRingtone = findPreference(PreferenceNames.NotifsRingtone);
Preference notifsDistVibrate = findPreference(PreferenceNames.NotifsVibrate);
notifsDistServiceResumed.setEnabled(values.size() != 0);
notifsDistRingtone.setEnabled(values.size() != 0);
notifsDistVibrate.setEnabled(values.size() != 0);
}
use of net.xpece.android.support.preference.MultiSelectListPreference in project underlx by underlx.
the class NotifPreferenceFragment method updateSourcesPreferenceSummary.
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(PreferenceNames.NotifsAnnouncementRingtone);
Preference notifsAnnVibrate = findPreference(PreferenceNames.NotifsAnnouncementVibrate);
notifsAnnRingtone.setEnabled(values.size() != 0);
notifsAnnVibrate.setEnabled(values.size() != 0);
}
Aggregations