Example usage for android.preference ListPreference setSummary

List of usage examples for android.preference ListPreference setSummary

Introduction

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

Prototype

@Override
public void setSummary(CharSequence summary) 

Source Link

Document

Sets the summary for this Preference with a CharSequence.

Usage

From source file:fr.free.nrw.commons.settings.SettingsFragment.java

@Override
public void onCreate(Bundle savedInstanceState) {
    AndroidInjection.inject(this);
    super.onCreate(savedInstanceState);

    // Load the preferences from an XML resource
    addPreferencesFromResource(R.xml.preferences);

    // Update spinner to show selected value as summary
    ListPreference licensePreference = (ListPreference) findPreference(Prefs.DEFAULT_LICENSE);
    licensePreference.setSummary(getString(Utils.licenseNameFor(licensePreference.getValue())));

    // Keep summary updated when changing value
    licensePreference.setOnPreferenceChangeListener((preference, newValue) -> {
        preference.setSummary(getString(Utils.licenseNameFor((String) newValue)));
        return true;
    });//from www  . ja v a 2 s. c  om

    CheckBoxPreference themePreference = (CheckBoxPreference) findPreference("theme");
    themePreference.setOnPreferenceChangeListener((preference, newValue) -> {
        getActivity().recreate();
        return true;
    });

    final EditTextPreference uploadLimit = (EditTextPreference) findPreference("uploads");
    int uploads = prefs.getInt(Prefs.UPLOADS_SHOWING, 100);
    uploadLimit.setText(uploads + "");
    uploadLimit.setSummary(uploads + "");
    uploadLimit.setOnPreferenceChangeListener((preference, newValue) -> {
        int value = Integer.parseInt(newValue.toString());
        final SharedPreferences.Editor editor = prefs.edit();
        if (value > 500) {
            new AlertDialog.Builder(getActivity()).setTitle(R.string.maximum_limit)
                    .setMessage(R.string.maximum_limit_alert)
                    .setPositiveButton(android.R.string.yes, (dialog, which) -> {
                    }).setIcon(android.R.drawable.ic_dialog_alert).show();
            editor.putInt(Prefs.UPLOADS_SHOWING, 500);
            editor.putBoolean(Prefs.IS_CONTRIBUTION_COUNT_CHANGED, true);
            uploadLimit.setSummary(500 + "");
            uploadLimit.setText(500 + "");
        } else {
            editor.putInt(Prefs.UPLOADS_SHOWING, Integer.parseInt(newValue.toString()));
            editor.putBoolean(Prefs.IS_CONTRIBUTION_COUNT_CHANGED, true);
            uploadLimit.setSummary(newValue.toString());
        }
        editor.apply();
        return true;
    });

    Preference sendLogsPreference = findPreference("sendLogFile");
    sendLogsPreference.setOnPreferenceClickListener(preference -> {
        //first we need to check if we have the necessary permissions
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            if (ContextCompat.checkSelfPermission(getActivity(),
                    Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
                sendAppLogsViaEmail();
            } else {
                //first get the necessary permission
                requestPermissions(new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE },
                        REQUEST_CODE_WRITE_EXTERNAL_STORAGE);
            }
        } else {
            sendAppLogsViaEmail();
        }

        return true;
    });
}

From source file:monakhv.android.samlib.SamlibPreferencesActivity.java

private void updateSummary(String key) {
    if (autoSumKeys.contains(key)) {
        Preference pr = getPreferenceScreen().findPreference(key);
        if (pr instanceof ListPreference) {
            final ListPreference currentPreference = (ListPreference) pr;
            currentPreference.setSummary(currentPreference.getEntry());
        } else if (pr instanceof EditTextPreference) {
            final EditTextPreference currentPreference = (EditTextPreference) pr;
            currentPreference.setSummary(currentPreference.getText());
        }/*from  www . j  a v  a  2  s . c om*/
    }
}

From source file:com.nttec.everychan.chans.synch.SynchModule.java

@Override
public void addPreferencesOnScreen(PreferenceGroup preferenceGroup) {
    Context context = preferenceGroup.getContext();
    ListPreference domainPref = new LazyPreferences.ListPreference(context);
    domainPref.setKey(getSharedKey(PREF_KEY_DOMAIN));
    domainPref.setTitle(R.string.pref_domain);
    domainPref.setSummary(resources.getString(R.string.pref_domain_summary, DOMAINS_HINT));
    domainPref.setDialogTitle(R.string.pref_domain);
    domainPref.setEntries(DOMAINS);//from   www.  ja  v a  2 s  .  c  om
    domainPref.setEntryValues(DOMAINS);
    domainPref.setDefaultValue(DOMAINS[0]);
    preferenceGroup.addPreference(domainPref);
    super.addPreferencesOnScreen(preferenceGroup);
}

From source file:de.tum.in.tumcampus.fragments.SettingsFragment.java

void setSummary(String key) {
    Preference t = findPreference(key);// w w  w.j  ava  2  s .  c om
    if (t instanceof ListPreference) {
        ListPreference pref = (ListPreference) t;
        pref.setSummary(pref.getEntry());
    }
}

From source file:de.hero.vertretungsplan.PrefsActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.preferences);

    mySharedPreferences = PreferenceManager.getDefaultSharedPreferences(getBaseContext());

    ListPreference listPref = (ListPreference) findPreference("prefs_benachrichtigungsintervall");
    listPref.setSummary(
            getSummaryInterval(mySharedPreferences.getString("prefs_benachrichtigungsintervall", "1")));
    listPref.setOnPreferenceChangeListener(new ListPreference.OnPreferenceChangeListener() {
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            preference.setSummary(getSummaryInterval(newValue.toString()));

            MainActivity.setNewAlarm(getBaseContext(), true, newValue.toString());
            return true;
        }/*w w  w  . ja  va  2s . c  o m*/

    });

    Preference klasse = findPreference("prefs_klasse");
    klasse.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

        public boolean onPreferenceClick(Preference preference) {
            showDialog(R.string.dialog_klasse);
            return true;
        }
    });

    CheckBoxPreference ckBxPref = (CheckBoxPreference) findPreference("prefs_benachrichtigungen");
    ckBxPref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

        public boolean onPreferenceChange(Preference preference, Object newValue) {
            if (preference.getKey().equals("prefs_benachrichtigungen")) {
                MainActivity.setNewAlarm(getBaseContext(), !((CheckBoxPreference) preference).isChecked(),
                        mySharedPreferences);
            }
            return true;
        }
    });

    CheckBoxPreference ckBxPrefAppUpdate = (CheckBoxPreference) findPreference("prefs_check_for_app_updates");
    ckBxPrefAppUpdate.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

        public boolean onPreferenceChange(Preference preference, Object newValue) {
            if (preference.getKey().equals("prefs_check_for_app_updates")) {
                Intent i = new Intent(getBaseContext(), CheckForAppUpdate.class);
                i.putExtra("setTimer", !((CheckBoxPreference) preference).isChecked());
                if (!((CheckBoxPreference) preference).isChecked()) {
                    i.putExtra("checkNow", true);
                }
                getBaseContext().startService(i);
            }
            return true;
        }
    });

    Preference ueber = findPreference("ueber");
    ueber.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

        public boolean onPreferenceClick(Preference preference) {
            Dialog ueberDialog = new Dialog(PrefsActivity.this);

            ueberDialog.setContentView(R.layout.ueber_dialog_layout);
            ueberDialog.setTitle(getString(R.string.ueber));
            ueberDialog.setCancelable(true);
            ueberDialog.setCanceledOnTouchOutside(true);

            TextView dialogText = (TextView) ueberDialog.findViewById(R.id.text_in_dialog);
            dialogText.setTextColor(Color.BLACK);
            dialogText.setAutoLinkMask(Linkify.ALL);

            dialogText.setText(String.format(getString(R.string.ueberTextFormated),
                    getString(R.string.version_nr), getString(R.string.emailAdresseEntwickler),
                    getString(R.string.webAdresseAppDownload), getString(R.string.GNU_GPLwebadresse)));
            ueberDialog.show();
            return true;
        }
    });

    CheckBoxPreference ckBxPrefDebugging = (CheckBoxPreference) findPreference("prefs_debug");
    ckBxPrefDebugging.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

        public boolean onPreferenceChange(Preference preference, Object newValue) {
            if (preference.getKey().equals("prefs_debug")) {
                Log.d("PrefsActivity", "new");
                if (!((CheckBoxPreference) preference).isChecked()) {
                    AlertDialog.Builder builder = new AlertDialog.Builder(preference.getContext());

                    builder.setMessage(getString(R.string.debugText)).setTitle(getString(R.string.debugTitel));

                    AlertDialog dialog = builder.create();
                    dialog.show();
                }
            }
            return true;
        }
    });
}

From source file:de.tum.in.tumcampus.fragments.SettingsFragment.java

@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
    Preference pref = findPreference(key);
    if (pref instanceof ListPreference) {
        ListPreference listPreference = (ListPreference) pref;
        listPreference.setSummary(listPreference.getEntry());
    }//from   ww w  .  j ava 2  s .c om

    if (key.startsWith("card_")) {
        CardManager.shouldRefresh = true;
    }

    // When newspread selection changes
    // deselect all newspread sources and select only the
    // selected source if one of all was selected before
    if (key.equals("news_newspread")) {
        SharedPreferences.Editor e = sharedPreferences.edit();
        boolean value = false;
        for (int i = 7; i < 14; i++) {
            if (sharedPreferences.getBoolean("card_news_source_" + i, false))
                value = true;
            e.putBoolean("card_news_source_" + i, false);
        }
        String new_source = sharedPreferences.getString(key, "7");
        e.putBoolean("card_news_source_" + new_source, value);
        e.apply();
        CardManager.shouldRefresh = true;
    }

    // If the silent mode was activated, start the service. This will invoke
    // the service to call onHandleIntent which checks available lectures
    if (key.equals(Const.SILENCE_SERVICE)) {
        Intent service = new Intent(mContext, SilenceService.class);
        if (sharedPreferences.getBoolean(key, false)) {
            mContext.startService(service);
        } else {
            mContext.stopService(service);
        }
    }

    // If the background mode was activated, start the service. This will invoke
    // the service to call onHandleIntent which updates all background data
    if (key.equals(Const.BACKGROUND_MODE)) {
        Intent service = new Intent(mContext, BackgroundService.class);
        if (sharedPreferences.getBoolean(key, false)) {
            mContext.startService(service);
        } else {
            mContext.stopService(service);
        }
    }
}

From source file:com.airflo.preferences.ListPreferenceActivity.java

/**
 * Add one slider preference to the category.
 * @param cat//w ww.  j a  v a  2s  . com
 * @param key
 * @param title
 */
private void addOneListItem(PreferenceCategory cat, String key, String title) {
    final ListPreference listPref = new ListPreference(this);
    listPref.setKey(key);
    listPref.setEntries(FlightData.identis.getPrefListChars(true));
    listPref.setEntryValues(FlightData.identis.getPrefListChars(false));
    listPref.setDialogTitle(title);
    listPref.setSummary(
            FlightData.identis.getIdenti(root.getSharedPreferences().getString(key, "empty")).getStringRep());
    listPref.setTitle(title);
    cat.addPreference(listPref);
    listPref.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            listPref.setSummary(FlightData.identis.getIdenti((String) newValue).getStringRep());
            return true;
        }
    });
}

From source file:com.airflo.preferences.ListPreferenceActivity.java

@SuppressWarnings("deprecation")
@SuppressLint("NewApi")
@Override/*w  w w  .  j a v  a  2 s. c om*/
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        getActionBar().setDisplayHomeAsUpEnabled(true);
    }

    root = getPreferenceManager().createPreferenceScreen(this);

    //Array of sorting preference keys to be included. 
    //SortType must be specified in bookitems.xml!
    String[] sortValues = new String[] { "number", "date;starttime", "site;date;starttime", "duration",
            "maxheight", "maxvario", "starttype;date;starttime" };
    //Generate according Entry Strings.
    String[] sortEntries = new String[sortValues.length];
    for (int i = 0; i < sortEntries.length; i++)
        sortEntries[i] = sortKeyToString(sortValues[i]);

    //Make sorting category
    PreferenceCategory cat = new PreferenceCategory(this);
    cat.setTitle(R.string.list_pref_cat_sort_title);
    root.addPreference(cat);
    final ListPreference listPref = new ListPreference(this);
    listPref.setKey("list_pref_sort");
    listPref.setEntries(sortEntries);
    listPref.setEntryValues(sortValues);
    listPref.setDialogTitle(R.string.list_pref_sort_criterium);
    listPref.setSummary(sortKeyToString(root.getSharedPreferences().getString("list_pref_sort", "number")));
    listPref.setTitle(R.string.list_pref_sort_criterium);
    cat.addPreference(listPref);
    listPref.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            listPref.setSummary(sortKeyToString((String) newValue));
            return true;
        }
    });
    final ListPreference orderPref = new ListPreference(this);
    orderPref.setKey("list_pref_order");
    orderPref.setEntries(new String[] { OnlyContext.rString("list_pref_sort_ascending"),
            OnlyContext.rString("list_pref_sort_decending") });
    orderPref.setEntryValues(new String[] { "list_pref_sort_ascending", "list_pref_sort_decending" });
    orderPref.setDialogTitle(R.string.list_pref_sort_sequence);
    orderPref.setSummary(OnlyContext
            .rString(root.getSharedPreferences().getString("list_pref_order", "list_pref_sort_decending")));
    orderPref.setTitle(R.string.list_pref_sort_sequence);
    cat.addPreference(orderPref);
    orderPref.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            orderPref.setSummary(OnlyContext.rString((String) newValue));
            return true;
        }
    });

    //Make item categories
    addManyListItems(R.string.list_pref_cat1_title, "listhead", 3);
    addManyListItems(R.string.list_pref_cat2_title, "listsub", 3);

    this.setPreferenceScreen(root);
}

From source file:com.syncedsynapse.kore2.ui.SettingsFragment.java

/**
 * Sets up the preferences state and summaries
 * @param hasBoughtCoffee Whether the user has bought me a coffee
 *///from w  w  w. j av  a  2  s  .com
private void setupPreferences(boolean hasBoughtCoffee) {
    final Settings settings = Settings.getInstance(getActivity());

    LogUtils.LOGD(TAG, "Setting up preferences. Has bought coffee? " + hasBoughtCoffee);

    // Coffee upgrade
    final Preference coffeePref = findPreference(Settings.KEY_PREF_COFFEE);
    if (coffeePref != null) {
        if (hasBoughtCoffee) {
            if (settings.showThanksForCofeeMessage) {
                coffeePref.setTitle(getResources().getString(R.string.thanks_for_coffe));
                coffeePref.setSummary(getResources().getString(R.string.remove_coffee_message));
                coffeePref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
                    @Override
                    public boolean onPreferenceClick(Preference preference) {
                        settings.showThanksForCofeeMessage = false;
                        settings.save();
                        getPreferenceScreen().removePreference(coffeePref);
                        return true;
                    }
                });
            } else {
                getPreferenceScreen().removePreference(coffeePref);
            }
        } else {
            coffeePref.setTitle(getResources().getString(R.string.buy_me_coffee));
            coffeePref.setSummary(getResources().getString(R.string.expresso_please));
            coffeePref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
                @Override
                public boolean onPreferenceClick(Preference preference) {
                    launchCoffeePurchase();
                    return true;
                }
            });
        }
    }

    // Theme preferences
    ListPreference themePref = (ListPreference) findPreference(Settings.KEY_PREF_THEME);
    if (hasBoughtCoffee) {
        themePref.setEnabled(true);
        themePref.setSummary(themePref.getEntry());
    } else {
        themePref.setEnabled(false);
        themePref.setSummary(getActivity().getString(R.string.buy_coffee_to_unlock_themes));
    }

    // About preference
    String nameAndVersion = getActivity().getString(R.string.app_name);
    try {
        nameAndVersion += " v" + getActivity().getPackageManager()
                .getPackageInfo(getActivity().getPackageName(), 0).versionName;
    } catch (PackageManager.NameNotFoundException exc) {
    }
    Preference aboutPreference = findPreference(Settings.KEY_PREF_ABOUT);
    aboutPreference.setSummary(nameAndVersion);
    aboutPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            AboutDialogFragment aboutDialog = new AboutDialogFragment();
            aboutDialog.show(getActivity().getFragmentManager(), null);
            return true;
        }
    });

}