Example usage for android.content RestrictionEntry setSelectedString

List of usage examples for android.content RestrictionEntry setSelectedString

Introduction

In this page you can find the example usage for android.content RestrictionEntry setSelectedString.

Prototype

public void setSelectedString(String selectedString) 

Source Link

Document

Sets the string value to use as the selected value for this restriction.

Usage

From source file:com.android.tv.settings.users.AppRestrictionsFragment.java

@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
    String key = preference.getKey();
    if (key != null && key.contains(DELIMITER)) {
        StringTokenizer st = new StringTokenizer(key, DELIMITER);
        final String packageName = st.nextToken();
        final String restrictionKey = st.nextToken();
        AppRestrictionsPreference appPref = (AppRestrictionsPreference) mAppList
                .findPreference(getKeyForPackage(packageName));
        ArrayList<RestrictionEntry> restrictions = appPref.getRestrictions();
        if (restrictions != null) {
            for (RestrictionEntry entry : restrictions) {
                if (entry.getKey().equals(restrictionKey)) {
                    switch (entry.getType()) {
                    case RestrictionEntry.TYPE_BOOLEAN:
                        entry.setSelectedState((Boolean) newValue);
                        break;
                    case RestrictionEntry.TYPE_CHOICE:
                    case RestrictionEntry.TYPE_CHOICE_LEVEL:
                        ListPreference listPref = (ListPreference) preference;
                        entry.setSelectedString((String) newValue);
                        String readable = findInArray(entry.getChoiceEntries(), entry.getChoiceValues(),
                                (String) newValue);
                        listPref.setSummary(readable);
                        break;
                    case RestrictionEntry.TYPE_MULTI_SELECT:
                        Set<String> set = (Set<String>) newValue;
                        String[] selectedValues = new String[set.size()];
                        set.toArray(selectedValues);
                        entry.setAllSelectedStrings(selectedValues);
                        break;
                    default:
                        continue;
                    }//from   ww  w.j  a va2s. c om
                    mUserManager.setApplicationRestrictions(packageName,
                            RestrictionsManager.convertRestrictionsToBundle(restrictions), mUser);
                    break;
                }
            }
        }
    }
    return true;
}