Example usage for android.preference MultiSelectListPreference setSummary

List of usage examples for android.preference MultiSelectListPreference setSummary

Introduction

In this page you can find the example usage for android.preference MultiSelectListPreference setSummary.

Prototype

public void setSummary(CharSequence summary) 

Source Link

Document

Sets the summary for this Preference with a CharSequence.

Usage

From source file:fr.s13d.photobackup.preferences.PBPreferenceFragment.java

private void setSummaries() {
    final String wifiOnly = preferences.getString(PBConstants.PREF_WIFI_ONLY,
            getResources().getString(R.string.only_wifi_default)); // default
    final ListPreference wifiPreference = (ListPreference) findPreference(PBConstants.PREF_WIFI_ONLY);
    wifiPreference.setSummary(wifiOnly);

    final String recentUploadOnly = preferences.getString(PBConstants.PREF_RECENT_UPLOAD_ONLY,
            getResources().getString(R.string.only_recent_upload_default)); // default
    final ListPreference recentUploadPreference = (ListPreference) findPreference(
            PBConstants.PREF_RECENT_UPLOAD_ONLY);
    recentUploadPreference.setSummary(recentUploadOnly);

    final String serverUrl = preferences.getString(PBServerPreferenceFragment.PREF_SERVER_URL, null);
    if (serverUrl != null) {
        final String serverName = preferences.getString(PBConstants.PREF_SERVER, null);
        if (serverName != null) {
            final PBServerListPreference serverPreference = (PBServerListPreference) findPreference(
                    PBConstants.PREF_SERVER);
            serverPreference.setSummary(serverName + " @ " + serverUrl);

            // bonus: left icon of the server
            final int serverNamesId = getResources().getIdentifier("pref_server_names", "array",
                    getActivity().getPackageName());
            final String[] serverNames = getResources().getStringArray(serverNamesId);
            final int serverPosition = Arrays.asList(serverNames).indexOf(serverName);
            final int serverIconsId = getResources().getIdentifier("pref_server_icons", "array",
                    getActivity().getPackageName());
            final String[] serverIcons = getResources().getStringArray(serverIconsId);
            final String serverIcon = serverIcons[serverPosition];
            final String[] parts = serverIcon.split("\\.");
            final String drawableName = parts[parts.length - 1];
            final int id = getResources().getIdentifier(drawableName, "drawable",
                    getActivity().getPackageName());
            if (id != 0) {
                serverPreference.setIcon(id);
            }//  w w  w  .  ja v a 2s.c om
        }
    }

    String bucketSummary = "";
    final Set<String> selectedBuckets = preferences.getStringSet(PBConstants.PREF_PICTURE_FOLDER_LIST, null);
    if (selectedBuckets != null && bucketNames != null) {
        final ArrayList<String> selectedBucketNames = new ArrayList<>();
        for (String entry : selectedBuckets) {
            String oneName = bucketNames.get(entry);
            if (oneName != null) {
                oneName = oneName.substring(0, oneName.lastIndexOf('(') - 1);
                selectedBucketNames.add(oneName);
            }
        }
        bucketSummary = TextUtils.join(", ", selectedBucketNames);
    }
    final MultiSelectListPreference bucketListPreference = (MultiSelectListPreference) findPreference(
            PBConstants.PREF_PICTURE_FOLDER_LIST);
    bucketListPreference.setSummary(bucketSummary);
}