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:org.linphone.SettingsFragment.java

private void initializePreferredVideoSizePreferences(ListPreference pref) {
    List<CharSequence> entries = new ArrayList<CharSequence>();
    List<CharSequence> values = new ArrayList<CharSequence>();
    for (String name : LinphoneManager.getLc().getSupportedVideoSizes()) {
        entries.add(name);//from w  ww.  j a va2s  . c o  m
        values.add(name);
    }

    setListPreferenceValues(pref, entries, values);

    String value = mPrefs.getPreferredVideoSize();
    if (pref != null) {
        pref.setSummary(value);
        pref.setValue(value);
    }
}

From source file:com.xorcode.andtweet.PreferencesActivity.java

protected void showListPreference(String keyPreference, int keysR, int displayR, int summaryR) {
    String displayParm = "";
    ListPreference lP = (ListPreference) findPreference(keyPreference);
    if (lP != null) {
        String[] k = getResources().getStringArray(keysR);
        String[] d = getResources().getStringArray(displayR);
        displayParm = d[0];/*from   w ww  . j a  v  a2s . c  o m*/
        String listValue = lP.getValue();
        for (int i = 0; i < k.length; i++) {
            if (listValue.equals(k[i])) {
                displayParm = d[i];
                break;
            }
        }
    } else {
        displayParm = keyPreference + " was not found";
    }
    MessageFormat sf = new MessageFormat(getText(summaryR).toString());
    lP.setSummary(sf.format(new Object[] { displayParm }));
}

From source file:org.adblockplus.android.Preferences.java

/**
 * Constructs and updates subscription status text.
 *
 * @param text//  w w w . ja  va 2 s .  co m
 *          status message
 * @param time
 *          time of last change
 */
private void setSubscriptionStatus(final String text, final long time) {
    final ListPreference subscriptionList = (ListPreference) findPreference(
            getString(R.string.pref_subscription));
    final CharSequence summary = subscriptionList.getEntry();
    final StringBuilder builder = new StringBuilder();
    if (summary != null) {
        builder.append(summary);
        if (StringUtils.isNotEmpty(text)) {
            builder.append(" (");
            final int id = getResources().getIdentifier(text, "string", getPackageName());
            if (id > 0)
                builder.append(getString(id, text));
            else
                builder.append(text);
            if (time > 0) {
                builder.append(": ");
                final Calendar calendar = Calendar.getInstance();
                calendar.setTimeInMillis(time);
                final Date date = calendar.getTime();
                builder.append(DateFormat.getDateFormat(this).format(date));
                builder.append(" ");
                builder.append(DateFormat.getTimeFormat(this).format(date));
            }
            builder.append(")");
        }
        subscriptionSummary = builder.toString();
        subscriptionList.setSummary(subscriptionSummary);
    }
}

From source file:org.linphone.SettingsFragment.java

private void initMediaEncryptionPreference(ListPreference pref) {
    List<CharSequence> entries = new ArrayList<CharSequence>();
    List<CharSequence> values = new ArrayList<CharSequence>();
    entries.add(getString(R.string.media_encryption_none));
    values.add(getString(R.string.pref_media_encryption_key_none));

    LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull();
    if (lc == null || getResources().getBoolean(R.bool.disable_all_security_features_for_markets)) {
        setListPreferenceValues(pref, entries, values);
        return;/*from  w  w  w  . j a  v  a2  s  .  c  o  m*/
    }

    boolean hasZrtp = lc.mediaEncryptionSupported(MediaEncryption.ZRTP);
    boolean hasSrtp = lc.mediaEncryptionSupported(MediaEncryption.SRTP);
    if (!hasSrtp && !hasZrtp) {
        pref.setEnabled(false);
    } else {
        if (hasSrtp) {
            entries.add(getString(R.string.media_encryption_srtp));
            values.add(getString(R.string.pref_media_encryption_key_srtp));
        }
        if (hasZrtp) {
            entries.add(getString(R.string.media_encryption_zrtp));
            values.add(getString(R.string.pref_media_encryption_key_zrtp));
        }
        setListPreferenceValues(pref, entries, values);
    }

    MediaEncryption value = mPrefs.getMediaEncryption();
    pref.setSummary(value.toString());

    String key = getString(R.string.pref_media_encryption_key_none);
    if (value.toString().equals(getString(R.string.media_encryption_srtp)))
        key = getString(R.string.pref_media_encryption_key_srtp);
    else if (value.toString().equals(getString(R.string.media_encryption_zrtp)))
        key = getString(R.string.pref_media_encryption_key_zrtp);
    pref.setValue(key);
}

From source file:com.aware.Aware_Preferences.java

/**
 * Webservices module settings UI/* ww w.  j a  v a 2  s.  c om*/
 */
private void webservices() {
    final CheckBoxPreference webservice = (CheckBoxPreference) findPreference(
            Aware_Preferences.STATUS_WEBSERVICE);
    webservice.setChecked(
            Aware.getSetting(getApplicationContext(), Aware_Preferences.STATUS_WEBSERVICE).equals("true"));
    webservice.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {

            if (Aware.getSetting(getApplicationContext(), Aware_Preferences.WEBSERVICE_SERVER).length() == 0) {
                showDialog(DIALOG_ERROR_MISSING_PARAMETERS);
                Aware.setSetting(getApplicationContext(), Aware_Preferences.STATUS_WEBSERVICE, false);
                webservice.setChecked(false);
                return false;
            } else {
                Aware.setSetting(getApplicationContext(), Aware_Preferences.STATUS_WEBSERVICE,
                        webservice.isChecked());
                if (webservice.isChecked()
                        && Aware.getSetting(getApplicationContext(), WEBSERVICE_SERVER).length() > 0) {
                    //setup and send data
                    Intent study_config = new Intent(getApplicationContext(), StudyConfig.class);
                    study_config.putExtra("study_url",
                            Aware.getSetting(getApplicationContext(), WEBSERVICE_SERVER));
                    startService(study_config);
                }
                return true;
            }
        }
    });

    final EditTextPreference webservice_server = (EditTextPreference) findPreference(
            Aware_Preferences.WEBSERVICE_SERVER);
    webservice_server.setText(Aware.getSetting(getApplicationContext(), Aware_Preferences.WEBSERVICE_SERVER));
    if (Aware.getSetting(getApplicationContext(), Aware_Preferences.WEBSERVICE_SERVER).length() > 0) {
        webservice_server.setSummary(
                "Server: " + Aware.getSetting(getApplicationContext(), Aware_Preferences.WEBSERVICE_SERVER));
    }
    webservice_server.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            Aware.setSetting(getApplicationContext(), Aware_Preferences.WEBSERVICE_SERVER, (String) newValue);
            webservice_server.setSummary("Server: " + (String) newValue);
            return true;
        }
    });

    final CheckBoxPreference webservice_wifi_only = (CheckBoxPreference) findPreference(
            Aware_Preferences.WEBSERVICE_WIFI_ONLY);
    webservice_wifi_only.setChecked(
            Aware.getSetting(getApplicationContext(), Aware_Preferences.WEBSERVICE_WIFI_ONLY).equals("true"));
    webservice_wifi_only.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            Aware.setSetting(getApplicationContext(), Aware_Preferences.WEBSERVICE_WIFI_ONLY,
                    webservice_wifi_only.isChecked());
            return true;
        }
    });

    final EditTextPreference frequency_webservice = (EditTextPreference) findPreference(
            Aware_Preferences.FREQUENCY_WEBSERVICE);
    if (Aware.getSetting(getApplicationContext(), Aware_Preferences.FREQUENCY_WEBSERVICE).length() > 0) {
        frequency_webservice.setSummary(
                Aware.getSetting(getApplicationContext(), Aware_Preferences.FREQUENCY_WEBSERVICE) + " minutes");
    }
    frequency_webservice
            .setText(Aware.getSetting(getApplicationContext(), Aware_Preferences.FREQUENCY_WEBSERVICE));
    frequency_webservice.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            Aware.setSetting(getApplicationContext(), Aware_Preferences.FREQUENCY_WEBSERVICE,
                    (String) newValue);
            frequency_webservice.setSummary((String) newValue + " minutes");
            return true;
        }
    });

    final ListPreference clean_old_data = (ListPreference) findPreference(FREQUENCY_CLEAN_OLD_DATA);
    if (Aware.getSetting(getApplicationContext(), Aware_Preferences.FREQUENCY_CLEAN_OLD_DATA).length() > 0) {
        String freq = Aware.getSetting(getApplicationContext(), Aware_Preferences.FREQUENCY_CLEAN_OLD_DATA);
        if (freq.equals("0")) {
            clean_old_data.setSummary("Never");
        } else if (freq.equals("1")) {
            clean_old_data.setSummary("Weekly");
        } else if (freq.equals("2")) {
            clean_old_data.setSummary("Monthly");
        }
    }
    clean_old_data.setDefaultValue(Aware.getSetting(getApplicationContext(), FREQUENCY_CLEAN_OLD_DATA));
    clean_old_data.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            Aware.setSetting(getApplicationContext(), FREQUENCY_CLEAN_OLD_DATA, (String) newValue);
            if (((String) newValue).equals("0")) {
                clean_old_data.setSummary("Never");
            } else if (((String) newValue).equals("1")) {
                clean_old_data.setSummary("Weekly");
            } else if (((String) newValue).equals("2")) {
                clean_old_data.setSummary("Monthly");
            }
            return true;
        }
    });
}

From source file:com.nttec.everychan.chans.ponyach.PonyachModule.java

@Override
public void addPreferencesOnScreen(PreferenceGroup preferenceGroup) {
    final Context context = preferenceGroup.getContext();
    ListPreference captchaLevel = new LazyPreferences.ListPreference(context);
    captchaLevel.setTitle(R.string.ponyach_prefs_captcha);
    captchaLevel.setDialogTitle(R.string.ponyach_prefs_captcha);
    captchaLevel.setKey(getSharedKey(PREF_KEY_CAPTCHA_LEVEL));
    captchaLevel.setEntryValues(new String[] { "3", "2", "1" });
    captchaLevel.setEntries(new String[] { "Easy", "Easy++", "Medium" });
    captchaLevel.setDefaultValue("1");
    preferenceGroup.addPreference(captchaLevel);

    EditTextPreference passcodePref = new EditTextPreference(context);
    passcodePref.setTitle(R.string.ponyach_prefs_passcode);
    passcodePref.setDialogTitle(R.string.ponyach_prefs_passcode);
    passcodePref.getEditText().setFilters(new InputFilter[] { new InputFilter.LengthFilter(6) });
    passcodePref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
        @Override//from  w w w.  j a v a2  s .  c  om
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            final String newPasscode = (String) newValue;
            final CancellableTask passAuthTask = new CancellableTask.BaseCancellableTask();
            final ProgressDialog passAuthProgressDialog = new ProgressDialog(context);
            passAuthProgressDialog.setMessage("Logging in");
            passAuthProgressDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
                @Override
                public void onCancel(DialogInterface dialog) {
                    passAuthTask.cancel();
                }
            });
            passAuthProgressDialog.setCanceledOnTouchOutside(false);
            passAuthProgressDialog.show();
            Async.runAsync(new Runnable() {
                @Override
                public void run() {
                    try {
                        if (passAuthTask.isCancelled())
                            return;
                        String url = getUsingUrl() + "passcode.php";
                        List<BasicNameValuePair> pairs = Collections
                                .singletonList(new BasicNameValuePair("passcode_just_set", newPasscode));
                        HttpRequestModel request = HttpRequestModel.builder()
                                .setPOST(new UrlEncodedFormEntity(pairs, "UTF-8")).build();
                        HttpStreamer.getInstance().getStringFromUrl(url, request, httpClient, null,
                                passAuthTask, false);
                        savePhpCookies();
                    } catch (final Exception e) {
                        if (context instanceof Activity) {
                            ((Activity) context).runOnUiThread(new Runnable() {
                                @Override
                                public void run() {
                                    String message = e.getMessage() == null
                                            ? resources.getString(R.string.error_unknown)
                                            : e.getMessage();
                                    Toast.makeText(context, message, Toast.LENGTH_LONG).show();
                                }
                            });
                        }
                    } finally {
                        passAuthProgressDialog.dismiss();
                    }
                }
            });
            return false;
        }
    });
    preferenceGroup.addPreference(passcodePref);

    ListPreference domainPref = new LazyPreferences.ListPreference(context);
    domainPref.setTitle(R.string.pref_domain);
    domainPref.setDialogTitle(R.string.pref_domain);
    domainPref.setKey(getSharedKey(PREF_KEY_DOMAIN));
    domainPref.setEntryValues(DOMAINS);
    domainPref.setEntries(DOMAINS);
    domainPref.setDefaultValue(DEFAULT_DOMAIN);
    domainPref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            loadPhpCookies((String) newValue);
            return true;
        }
    });
    preferenceGroup.addPreference(domainPref);

    addHttpsPreference(preferenceGroup, useHttpsDefaultValue());
    addProxyPreferences(preferenceGroup);
    captchaLevel.setSummary(captchaLevel.getEntry());
    domainPref.setSummary(domainPref.getEntry());
}