Search in sources :

Example 1 with MultiSelectListPreference

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;
        }
    });
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) Announcement(im.tny.segvault.disturbances.Announcement) ListPreference(net.xpece.android.support.preference.ListPreference) MultiSelectListPreference(net.xpece.android.support.preference.MultiSelectListPreference) RingtonePreference(net.xpece.android.support.preference.RingtonePreference) SeekBarPreference(net.xpece.android.support.preference.SeekBarPreference) Preference(android.support.v7.preference.Preference) ArrayList(java.util.ArrayList) MultiSelectListPreference(net.xpece.android.support.preference.MultiSelectListPreference)

Example 2 with MultiSelectListPreference

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;
        }
    });
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) ArrayList(java.util.ArrayList) MultiSelectListPreference(net.xpece.android.support.preference.MultiSelectListPreference) LinkedList(java.util.LinkedList) Line(im.tny.segvault.subway.Line) ListPreference(net.xpece.android.support.preference.ListPreference) MultiSelectListPreference(net.xpece.android.support.preference.MultiSelectListPreference) RingtonePreference(net.xpece.android.support.preference.RingtonePreference) SeekBarPreference(net.xpece.android.support.preference.SeekBarPreference) Preference(android.support.v7.preference.Preference) Network(im.tny.segvault.subway.Network)

Example 3 with MultiSelectListPreference

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);
}
Also used : ListPreference(net.xpece.android.support.preference.ListPreference) MultiSelectListPreference(net.xpece.android.support.preference.MultiSelectListPreference) RingtonePreference(net.xpece.android.support.preference.RingtonePreference) SeekBarPreference(net.xpece.android.support.preference.SeekBarPreference) Preference(android.support.v7.preference.Preference) ArrayList(java.util.ArrayList)

Example 4 with MultiSelectListPreference

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);
}
Also used : ListPreference(net.xpece.android.support.preference.ListPreference) MultiSelectListPreference(net.xpece.android.support.preference.MultiSelectListPreference) RingtonePreference(net.xpece.android.support.preference.RingtonePreference) SeekBarPreference(net.xpece.android.support.preference.SeekBarPreference) Preference(android.support.v7.preference.Preference) ArrayList(java.util.ArrayList)

Aggregations

Preference (android.support.v7.preference.Preference)4 ArrayList (java.util.ArrayList)4 ListPreference (net.xpece.android.support.preference.ListPreference)4 MultiSelectListPreference (net.xpece.android.support.preference.MultiSelectListPreference)4 RingtonePreference (net.xpece.android.support.preference.RingtonePreference)4 SeekBarPreference (net.xpece.android.support.preference.SeekBarPreference)4 HashSet (java.util.HashSet)2 Set (java.util.Set)2 Announcement (im.tny.segvault.disturbances.Announcement)1 Line (im.tny.segvault.subway.Line)1 Network (im.tny.segvault.subway.Network)1 LinkedList (java.util.LinkedList)1