Example usage for android.preference Preference getClass

List of usage examples for android.preference Preference getClass

Introduction

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

Prototype

@HotSpotIntrinsicCandidate
public final native Class<?> getClass();

Source Link

Document

Returns the runtime class of this Object .

Usage

From source file:net.sf.sprockets.app.ui.SprocketsPreferenceFragment.java

/**
 * Set the preference's value(s) as its summary.
 *///  ww  w . ja  va2 s . c o  m
protected void setSummary(Preference pref) {
    SharedPreferences prefs = getPreferenceManager().getSharedPreferences();
    if (pref instanceof RingtonePreference) {
        String val = prefs.getString(pref.getKey(), null);
        if (!TextUtils.isEmpty(val)) {
            Ringtone tone = RingtoneManager.getRingtone(a, Uri.parse(val));
            if (tone != null) {
                pref.setSummary(tone.getTitle(a));
            }
        } else {
            pref.setSummary(R.string.none);
        }
    } else if (pref instanceof MultiSelectListPreference) {
        Set<String> vals = prefs.getStringSet(pref.getKey(), null);
        if (vals != null) {
            if (!vals.isEmpty()) {
                MultiSelectListPreference multi = (MultiSelectListPreference) pref;
                IntList indexList = new ArrayIntList(vals.size());
                for (String val : vals) { // find selected entry indexes
                    int i = multi.findIndexOfValue(val);
                    if (i >= 0) {
                        indexList.add(i);
                    }
                }
                int[] indexes = indexList.toArray();
                Arrays.sort(indexes); // to display in same order as dialog
                pref.setSummary(TextUtils.join(getString(R.string.delimiter),
                        Elements.slice(multi.getEntries(), indexes)));
            } else {
                pref.setSummary(R.string.none);
            }
        }
    } else if (pref instanceof EditTextPreference) {
        pref.setSummary(prefs.getString(pref.getKey(), null));
    } else if (pref.getClass() == Preference.class) {
        String val = prefs.getString(pref.getKey(), null);
        if (!TextUtils.isEmpty(val)) { // don't clear existing summary
            pref.setSummary(val);
        }
    }
}