List of usage examples for android.content RestrictionsManager convertRestrictionsToBundle
public static Bundle convertRestrictionsToBundle(List<RestrictionEntry> entries)
RestrictionEntry | Bundle |
---|---|
RestrictionEntry#TYPE_BOOLEAN | Bundle#putBoolean |
RestrictionEntry#TYPE_CHOICE , RestrictionEntry#TYPE_MULTI_SELECT | Bundle#putStringArray |
RestrictionEntry#TYPE_INTEGER | Bundle#putInt |
RestrictionEntry#TYPE_STRING | Bundle#putString |
RestrictionEntry#TYPE_BUNDLE | Bundle#putBundle |
RestrictionEntry#TYPE_BUNDLE_ARRAY | Bundle#putParcelableArray |
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 w w w . j av a 2 s .co m*/ mUserManager.setApplicationRestrictions(packageName, RestrictionsManager.convertRestrictionsToBundle(restrictions), mUser); break; } } } } return true; }
From source file:com.android.tv.settings.users.AppRestrictionsFragment.java
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); AppRestrictionsPreference pref = (AppRestrictionsPreference) findPreference( mCustomRequestMap.get(requestCode)); if (pref == null) { Log.w(TAG, "Unknown requestCode " + requestCode); return;//from w w w. j av a 2s . c om } if (resultCode == Activity.RESULT_OK) { String packageName = getPackageFromKey(pref.getKey()); ArrayList<RestrictionEntry> list = data.getParcelableArrayListExtra(Intent.EXTRA_RESTRICTIONS_LIST); Bundle bundle = data.getBundleExtra(Intent.EXTRA_RESTRICTIONS_BUNDLE); if (list != null) { // If there's a valid result, persist it to the user manager. pref.setRestrictions(list); mUserManager.setApplicationRestrictions(packageName, RestrictionsManager.convertRestrictionsToBundle(list), mUser); } else if (bundle != null) { // If there's a valid result, persist it to the user manager. mUserManager.setApplicationRestrictions(packageName, bundle, mUser); } } // Remove request from the map mCustomRequestMap.remove(requestCode); }