Example usage for android.preference Preference getSummary

List of usage examples for android.preference Preference getSummary

Introduction

In this page you can find the example usage for android.preference Preference getSummary.

Prototype

public CharSequence getSummary() 

Source Link

Document

Returns the summary of this Preference.

Usage

From source file:com.harshad.linconnectclient.SettingsActivity.java

public static void refreshServerList() {

    // Determine server list icons based on IP address
    String ip = sharedPreferences.getString("pref_ip", "0.0.0.0:9090");
    for (int i = 0; i < serverCategory.getPreferenceCount() - 1; i++) {
        Preference p = serverCategory.getPreference(i);
        if (ip.equals(p.getSummary().toString())) {
            p.setIcon(R.drawable.ic_checkmark);
        } else {/*from  w  ww  . j a v  a  2s.c om*/
            p.setIcon(R.drawable.ic_computer);
        }
    }
}

From source file:com.vignesh.conf.SettingsFragment.java

/**
 * A preference value change listener that updates the preference's summary
 * to reflect its new value./*from  w  ww .java2  s.  c  om*/
 */

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getActivity().setTitle(R.string.title_activity_settings);
    addPreferencesFromResource(R.xml.pref_headers);
    SharedPreferences sharedPref = PreferenceManager
            .getDefaultSharedPreferences(getActivity().getApplicationContext());
    sharedPref.registerOnSharedPreferenceChangeListener(this);
    Preference preference = findPreference("contact");
    preference.setOnPreferenceClickListener(this);
    findPreference("calendar").setOnPreferenceClickListener(this);
    for (int i = 0; i < getPreferenceScreen().getPreferenceCount(); i++) {
        Preference p = getPreferenceScreen().getPreference(i);
        p.setSummary(
                sharedPref.getString(p.getKey(), (p.getSummary() != null) ? p.getSummary().toString() : null));
        Log.e("WOWOWOW:", (p.getSummary() != null) ? p.getSummary().toString() : "nothing");
    }
}

From source file:org.teleportr.activity.Autocompletion.java

@Override
public boolean onPreferenceClick(final Preference preference) {
    new AlertDialog.Builder(Autocompletion.this).setTitle(preference.getTitle())
            .setMessage(preference.getSummary())
            .setPositiveButton(getString(R.string.dialog_yes), new OnClickListener() {
                @Override/*from ww w .ja  v a  2  s .c  o m*/
                public void onClick(DialogInterface dialog, int which) {
                    new Download().execute((preference.getKey()));
                }
            }).setNegativeButton(getString(R.string.dialog_no), new OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    ((CheckBoxPreference) preference).setChecked(false);
                    getPreferenceScreen().getSharedPreferences().edit().remove(preference.getKey()).commit();
                }
            }).show();
    return true;
}

From source file:fyp.hkust.facet.activity.SettingsActivity.java

private void convertPreferenceToUseCustomFont(Preference somePreference) {
    Typeface fontType = FontManager.getTypeface(getApplicationContext(), FontManager.APP_FONT);

    CustomTypeFaceSpan customTypefaceSpan = new CustomTypeFaceSpan("", fontType);

    SpannableStringBuilder ss;//from  ww  w  . j av a  2s . c  o  m
    if (somePreference.getTitle() != null) {
        ss = new SpannableStringBuilder(somePreference.getTitle().toString());
        ss.setSpan(new StyleSpan(Typeface.BOLD), 0, ss.length(), 0);
        ss.setSpan(customTypefaceSpan, 0, ss.length(), Spanned.SPAN_EXCLUSIVE_INCLUSIVE);
        somePreference.setTitle(ss);
    }

    if (somePreference.getSummary() != null) {
        ss = new SpannableStringBuilder(somePreference.getSummary().toString());
        ss.setSpan(customTypefaceSpan, 0, ss.length(), Spanned.SPAN_EXCLUSIVE_INCLUSIVE);
        somePreference.setSummary(ss);
    }
}

From source file:com.crowflying.buildwatch.ConfigurationActivity.java

/**
 * Refresh the summaries of the prefs. This is done in one single hunk for
 * all prefs which is suboptimal from a performance point of view, but is
 * less code to write. To optimize, only refresh summaries on the settings
 * that actually changed./*from  w  ww  . j a v  a 2  s . c o m*/
 */
private void refreshSummaries() {
    long t1 = System.currentTimeMillis();
    List<Pair<String, Integer>> setSummaryTextPrefs = new LinkedList<Pair<String, Integer>>();
    setSummaryTextPrefs
            .add(new Pair<String, Integer>(PREFS_KEY_GCM_SENDER_ID, R.string.config_gcm_sender_id_summary));
    setSummaryTextPrefs.add(new Pair<String, Integer>(PREFS_KEY_GCM_TOKEN, R.string.config_gcm_token_summary));
    setSummaryTextPrefs
            .add(new Pair<String, Integer>(PREFS_KEY_JENKINS_TOKEN, R.string.config_jenkins_token_summary));
    setSummaryTextPrefs
            .add(new Pair<String, Integer>(PREFS_KEY_JENKINS_URL, R.string.config_jenkins_base_url_summary));
    setSummaryTextPrefs.add(
            new Pair<String, Integer>(PREFS_KEY_JENKINS_USERNAME, R.string.config_jenkins_username_summary));
    SharedPreferences prefs = getPreferenceScreen().getSharedPreferences();

    for (Pair<String, Integer> p : setSummaryTextPrefs) {
        Preference pref = findPreference(p.first);
        if (pref != null) {
            pref.setSummary(String.format(getString(p.second), prefs.getString(p.first, "")));

        }
    }

    // Add 'press to share' to GCM token pref, if there is a token
    // configured.
    if (!TextUtils.isEmpty(prefs.getString(PREFS_KEY_GCM_TOKEN, ""))) {
        Preference pref = findPreference(PREFS_KEY_GCM_TOKEN);
        if (pref != null) {
            CharSequence summary = pref.getSummary();
            summary = summary + " " + getString(R.string.config_gcm_token_summary_share);
            pref.setSummary(summary);
        }
    }

    Log.d(LOG_TAG, String.format("Updating summaries took %s ms. This can easily be optimized.",
            (System.currentTimeMillis() - t1)));

}

From source file:com.hichinaschool.flashcards.anki.CramDeckOptions.java

protected void updateSummaries() {
    mAllowCommit = false;// w ww  .  j a  v a  2  s.  com
    // for all text preferences, set summary as current database value
    for (String key : mPref.mValues.keySet()) {
        Preference pref = this.findPreference(key);
        String value = null;
        if (pref == null) {
            continue;
        } else if (pref instanceof CheckBoxPreference) {
            continue;
        } else if (pref instanceof ListPreference) {
            ListPreference lp = (ListPreference) pref;
            value = lp.getEntry().toString();
        } else {
            value = this.mPref.getString(key, "");
        }
        // update value for EditTexts
        if (pref instanceof EditTextPreference) {
            ((EditTextPreference) pref).setText(value);
        }
        // update summary
        if (!mPref.mSummaries.containsKey(key)) {
            CharSequence s = pref.getSummary();
            mPref.mSummaries.put(key, s != null ? pref.getSummary().toString() : null);
        }
        String summ = mPref.mSummaries.get(key);
        if (summ != null && summ.contains("XXX")) {
            pref.setSummary(summ.replace("XXX", value));
        } else {
            pref.setSummary(value);
        }
    }
    mAllowCommit = true;
}

From source file:com.ichi2.anki2.DeckOptions.java

protected void updateSummaries() {
    // for all text preferences, set summary as current database value
    for (String key : mPref.mValues.keySet()) {
        Preference pref = this.findPreference(key);
        String value = null;//from w w  w  .  j a va  2s.com
        if (pref == null) {
            continue;
        } else if (pref instanceof CheckBoxPreference) {
            continue;
        } else if (pref instanceof ListPreference) {
            ListPreference lp = (ListPreference) pref;
            value = lp.getEntry() != null ? lp.getEntry().toString() : "";
        } else {
            value = this.mPref.getString(key, "");
        }
        // update summary
        if (!mPref.mSummaries.containsKey(key)) {
            CharSequence s = pref.getSummary();
            mPref.mSummaries.put(key, s != null ? pref.getSummary().toString() : null);
        }
        String summ = mPref.mSummaries.get(key);
        if (summ != null && summ.contains("XXX")) {
            pref.setSummary(summ.replace("XXX", value));
        } else {
            pref.setSummary(value);
        }
    }
}

From source file:com.ichi2.anki.FilteredDeckOptions.java

protected void updateSummaries() {
    mAllowCommit = false;/* ww w. ja  v a2  s . co m*/
    // for all text preferences, set summary as current database value
    for (String key : mPref.mValues.keySet()) {
        Preference pref = this.findPreference(key);
        String value = null;
        if (pref == null) {
            continue;
        } else if (pref instanceof CheckBoxPreference) {
            continue;
        } else if (pref instanceof ListPreference) {
            ListPreference lp = (ListPreference) pref;
            CharSequence entry = lp.getEntry();
            if (entry != null) {
                value = entry.toString();
            } else {
                value = "";
            }
        } else {
            value = this.mPref.getString(key, "");
        }
        // update value for EditTexts
        if (pref instanceof EditTextPreference) {
            ((EditTextPreference) pref).setText(value);
        }
        // update summary
        if (!mPref.mSummaries.containsKey(key)) {
            CharSequence s = pref.getSummary();
            mPref.mSummaries.put(key, s != null ? pref.getSummary().toString() : null);
        }
        String summ = mPref.mSummaries.get(key);
        if (summ != null && summ.contains("XXX")) {
            pref.setSummary(summ.replace("XXX", value));
        } else {
            pref.setSummary(value);
        }
    }
    mAllowCommit = true;
}

From source file:com.hichinaschool.flashcards.anki.DeckOptions.java

protected void updateSummaries() {
    Resources res = getResources();
    // for all text preferences, set summary as current database value
    for (String key : mPref.mValues.keySet()) {
        Preference pref = this.findPreference(key);
        if (key.equals("deckConf")) {
            String groupName = getOptionsGroupName();
            int count = getOptionsGroupCount();
            pref.setSummary(res.getQuantityString(R.plurals.deck_conf_group_summ, count, groupName, count));
            continue;
        }//w ww.  ja v  a 2  s.  c om

        String value = null;
        if (pref == null) {
            continue;
        } else if (pref instanceof CheckBoxPreference) {
            continue;
        } else if (pref instanceof ListPreference) {
            ListPreference lp = (ListPreference) pref;
            value = lp.getEntry() != null ? lp.getEntry().toString() : "";
        } else {
            value = this.mPref.getString(key, "");
        }
        // update summary
        if (!mPref.mSummaries.containsKey(key)) {
            CharSequence s = pref.getSummary();
            mPref.mSummaries.put(key, s != null ? pref.getSummary().toString() : null);
        }
        String summ = mPref.mSummaries.get(key);
        if (summ != null && summ.contains("XXX")) {
            pref.setSummary(summ.replace("XXX", value));
        } else {
            pref.setSummary(value);
        }
    }
    // Update summaries of preference items that don't have values (aren't in mValues)
    int subDeckCount = getSubdeckCount();
    this.findPreference("confSetSubdecks").setSummary(
            res.getQuantityString(R.plurals.deck_conf_set_subdecks_summ, subDeckCount, subDeckCount));
}

From source file:com.ichi2.anki.DeckOptions.java

protected void updateSummaries() {
    Resources res = getResources();
    // for all text preferences, set summary as current database value
    for (String key : mPref.mValues.keySet()) {
        Preference pref = this.findPreference(key);
        if (key.equals("deckConf")) {
            String groupName = getOptionsGroupName();
            int count = getOptionsGroupCount();
            // Escape "%" in groupName as it's treated as a token
            groupName = groupName.replaceAll("%", "%%");
            pref.setSummary(res.getQuantityString(R.plurals.deck_conf_group_summ, count, groupName, count));
            continue;
        }/* w  w w  . j a  va2 s. c o m*/

        String value = null;
        if (pref == null) {
            continue;
        } else if (pref instanceof CheckBoxPreference) {
            continue;
        } else if (pref instanceof ListPreference) {
            ListPreference lp = (ListPreference) pref;
            value = lp.getEntry() != null ? lp.getEntry().toString() : "";
        } else {
            value = this.mPref.getString(key, "");
        }
        // update summary
        if (!mPref.mSummaries.containsKey(key)) {
            CharSequence s = pref.getSummary();
            mPref.mSummaries.put(key, s != null ? pref.getSummary().toString() : null);
        }
        String summ = mPref.mSummaries.get(key);
        if (summ != null && summ.contains("XXX")) {
            pref.setSummary(summ.replace("XXX", value));
        } else {
            pref.setSummary(value);
        }
    }
    // Update summaries of preference items that don't have values (aren't in mValues)
    int subDeckCount = getSubdeckCount();
    this.findPreference("confSetSubdecks").setSummary(
            res.getQuantityString(R.plurals.deck_conf_set_subdecks_summ, subDeckCount, subDeckCount));
}