use of android.content.RestrictionEntry in project android_packages_apps_Settings by crdroidandroid.
the class AppRestrictionsFragment method onPreferenceChange.
@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(PKG_PREFIX + 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;
}
mUserManager.setApplicationRestrictions(packageName, RestrictionsManager.convertRestrictionsToBundle(restrictions), mUser);
break;
}
}
}
return true;
}
return false;
}
use of android.content.RestrictionEntry in project android_packages_apps_Settings by SudaMod.
the class AppRestrictionsFragment method onActivityResult.
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
AppRestrictionsPreference pref = mCustomRequestMap.get(requestCode);
if (pref == null) {
Log.w(TAG, "Unknown requestCode " + requestCode);
return;
}
if (resultCode == Activity.RESULT_OK) {
String packageName = pref.getKey().substring(PKG_PREFIX.length());
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);
}
use of android.content.RestrictionEntry in project android_packages_apps_Settings by SudaMod.
the class AppRestrictionsFragment method onRestrictionsReceived.
private void onRestrictionsReceived(AppRestrictionsPreference preference, ArrayList<RestrictionEntry> restrictions) {
// Remove any earlier restrictions
removeRestrictionsForApp(preference);
// Non-custom-activity case - expand the restrictions in-place
int count = 1;
for (RestrictionEntry entry : restrictions) {
Preference p = null;
switch(entry.getType()) {
case RestrictionEntry.TYPE_BOOLEAN:
p = new SwitchPreference(getPrefContext());
p.setTitle(entry.getTitle());
p.setSummary(entry.getDescription());
((SwitchPreference) p).setChecked(entry.getSelectedState());
break;
case RestrictionEntry.TYPE_CHOICE:
case RestrictionEntry.TYPE_CHOICE_LEVEL:
p = new ListPreference(getPrefContext());
p.setTitle(entry.getTitle());
String value = entry.getSelectedString();
if (value == null) {
value = entry.getDescription();
}
p.setSummary(findInArray(entry.getChoiceEntries(), entry.getChoiceValues(), value));
((ListPreference) p).setEntryValues(entry.getChoiceValues());
((ListPreference) p).setEntries(entry.getChoiceEntries());
((ListPreference) p).setValue(value);
((ListPreference) p).setDialogTitle(entry.getTitle());
break;
case RestrictionEntry.TYPE_MULTI_SELECT:
p = new MultiSelectListPreference(getPrefContext());
p.setTitle(entry.getTitle());
((MultiSelectListPreference) p).setEntryValues(entry.getChoiceValues());
((MultiSelectListPreference) p).setEntries(entry.getChoiceEntries());
HashSet<String> set = new HashSet<>();
Collections.addAll(set, entry.getAllSelectedStrings());
((MultiSelectListPreference) p).setValues(set);
((MultiSelectListPreference) p).setDialogTitle(entry.getTitle());
break;
case RestrictionEntry.TYPE_NULL:
default:
}
if (p != null) {
p.setPersistent(false);
p.setOrder(preference.getOrder() + count);
// Store the restrictions key string as a key for the preference
p.setKey(preference.getKey().substring(PKG_PREFIX.length()) + DELIMITER + entry.getKey());
mAppList.addPreference(p);
p.setOnPreferenceChangeListener(AppRestrictionsFragment.this);
p.setIcon(R.drawable.empty_icon);
preference.mChildren.add(p);
count++;
}
}
preference.setRestrictions(restrictions);
if (// No visible restrictions
count == 1 && preference.isImmutable() && preference.isChecked()) {
// Special case of required app with no visible restrictions. Remove it
mAppList.removePreference(preference);
}
}
use of android.content.RestrictionEntry in project platform_packages_apps_Settings by BlissRoms.
the class AppRestrictionsFragment method addLocationAppRestrictionsPreference.
private void addLocationAppRestrictionsPreference(AppRestrictionsHelper.SelectableAppInfo app, AppRestrictionsPreference p) {
String packageName = app.packageName;
p.setIcon(R.drawable.ic_settings_location);
p.setKey(getKeyForPackage(packageName));
ArrayList<RestrictionEntry> restrictions = RestrictionUtils.getRestrictions(getActivity(), mUser);
RestrictionEntry locationRestriction = restrictions.get(0);
p.setTitle(locationRestriction.getTitle());
p.setRestrictions(restrictions);
p.setSummary(locationRestriction.getDescription());
p.setChecked(locationRestriction.getSelectedState());
p.setPersistent(false);
p.setOnPreferenceClickListener(this);
p.setOrder(MAX_APP_RESTRICTIONS);
mAppList.addPreference(p);
}
use of android.content.RestrictionEntry in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class AppRestrictionsFragment method onRestrictionsReceived.
private void onRestrictionsReceived(AppRestrictionsPreference preference, ArrayList<RestrictionEntry> restrictions) {
// Remove any earlier restrictions
removeRestrictionsForApp(preference);
// Non-custom-activity case - expand the restrictions in-place
int count = 1;
for (RestrictionEntry entry : restrictions) {
Preference p = null;
switch(entry.getType()) {
case RestrictionEntry.TYPE_BOOLEAN:
p = new SwitchPreference(getPrefContext());
p.setTitle(entry.getTitle());
p.setSummary(entry.getDescription());
((SwitchPreference) p).setChecked(entry.getSelectedState());
break;
case RestrictionEntry.TYPE_CHOICE:
case RestrictionEntry.TYPE_CHOICE_LEVEL:
p = new ListPreference(getPrefContext());
p.setTitle(entry.getTitle());
String value = entry.getSelectedString();
if (value == null) {
value = entry.getDescription();
}
p.setSummary(findInArray(entry.getChoiceEntries(), entry.getChoiceValues(), value));
((ListPreference) p).setEntryValues(entry.getChoiceValues());
((ListPreference) p).setEntries(entry.getChoiceEntries());
((ListPreference) p).setValue(value);
((ListPreference) p).setDialogTitle(entry.getTitle());
break;
case RestrictionEntry.TYPE_MULTI_SELECT:
p = new MultiSelectListPreference(getPrefContext());
p.setTitle(entry.getTitle());
((MultiSelectListPreference) p).setEntryValues(entry.getChoiceValues());
((MultiSelectListPreference) p).setEntries(entry.getChoiceEntries());
HashSet<String> set = new HashSet<>();
Collections.addAll(set, entry.getAllSelectedStrings());
((MultiSelectListPreference) p).setValues(set);
((MultiSelectListPreference) p).setDialogTitle(entry.getTitle());
break;
case RestrictionEntry.TYPE_NULL:
default:
}
if (p != null) {
p.setPersistent(false);
p.setOrder(preference.getOrder() + count);
// Store the restrictions key string as a key for the preference
p.setKey(preference.getKey().substring(PKG_PREFIX.length()) + DELIMITER + entry.getKey());
mAppList.addPreference(p);
p.setOnPreferenceChangeListener(AppRestrictionsFragment.this);
p.setIcon(R.drawable.empty_icon);
preference.mChildren.add(p);
count++;
}
}
preference.setRestrictions(restrictions);
if (// No visible restrictions
count == 1 && preference.isImmutable() && preference.isChecked()) {
// Special case of required app with no visible restrictions. Remove it
mAppList.removePreference(preference);
}
}
Aggregations