Example usage for android.content RestrictionEntry setSelectedState

List of usage examples for android.content RestrictionEntry setSelectedState

Introduction

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

Prototype

public void setSelectedState(boolean state) 

Source Link

Document

Sets the current selected state for an entry of type #TYPE_BOOLEAN .

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;
                    }/*  www.  j av a2s.c om*/
                    mUserManager.setApplicationRestrictions(packageName,
                            RestrictionsManager.convertRestrictionsToBundle(restrictions), mUser);
                    break;
                }
            }
        }
    }
    return true;
}