use of android.content.RestrictionEntry in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class AppRestrictionsFragment method addLocationAppRestrictionsPreference.
private void addLocationAppRestrictionsPreference(AppRestrictionsHelper.SelectableAppInfo app, AppRestrictionsPreference p) {
String packageName = app.packageName;
p.setIcon(R.drawable.ic_preference_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 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 Resurrection_packages_apps_Settings by ResurrectionRemix.
the class RestrictionUtils method getRestrictions.
/**
* Returns the current user restrictions in the form of application
* restriction entries.
* @return list of RestrictionEntry objects with user-visible text.
*/
public static ArrayList<RestrictionEntry> getRestrictions(Context context, UserHandle user) {
Resources res = context.getResources();
ArrayList<RestrictionEntry> entries = new ArrayList<RestrictionEntry>();
UserManager um = UserManager.get(context);
Bundle userRestrictions = um.getUserRestrictions(user);
for (int i = 0; i < sRestrictionKeys.length; i++) {
RestrictionEntry entry = new RestrictionEntry(sRestrictionKeys[i], !userRestrictions.getBoolean(sRestrictionKeys[i], false));
entry.setTitle(res.getString(sRestrictionTitles[i]));
entry.setDescription(res.getString(sRestrictionDescriptions[i]));
entry.setType(RestrictionEntry.TYPE_BOOLEAN);
entries.add(entry);
}
return entries;
}
use of android.content.RestrictionEntry in project Android-Developers-Samples by johnjohndoe.
the class CustomRestrictionsFragment method onActivityCreated.
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
final Activity activity = getActivity();
// BEGIN_INCLUDE (GET_CURRENT_RESTRICTIONS)
// Existing app restriction settings, if exist, can be retrieved from the Bundle.
mRestrictionsBundle = activity.getIntent().getBundleExtra(Intent.EXTRA_RESTRICTIONS_BUNDLE);
if (mRestrictionsBundle == null) {
mRestrictionsBundle = ((UserManager) activity.getSystemService(Context.USER_SERVICE)).getApplicationRestrictions(activity.getPackageName());
}
if (mRestrictionsBundle == null) {
mRestrictionsBundle = new Bundle();
}
mRestrictions = activity.getIntent().getParcelableArrayListExtra(Intent.EXTRA_RESTRICTIONS_LIST);
// Transfers the saved values into the preference hierarchy.
if (mRestrictions != null) {
for (RestrictionEntry entry : mRestrictions) {
if (entry.getKey().equals(GetRestrictionsReceiver.KEY_BOOLEAN)) {
mBooleanPref.setChecked(entry.getSelectedState());
mBooleanEntry = entry;
} else if (entry.getKey().equals(GetRestrictionsReceiver.KEY_CHOICE)) {
mChoicePref.setValue(entry.getSelectedString());
mChoiceEntry = entry;
} else if (entry.getKey().equals(GetRestrictionsReceiver.KEY_MULTI_SELECT)) {
HashSet<String> set = new HashSet<String>();
for (String value : entry.getAllSelectedStrings()) {
set.add(value);
}
mMultiPref.setValues(set);
mMultiEntry = entry;
}
}
} else {
mRestrictions = new ArrayList<RestrictionEntry>();
// Initializes the boolean restriction entry and updates its corresponding shared
// preference value.
mBooleanEntry = new RestrictionEntry(GetRestrictionsReceiver.KEY_BOOLEAN, mRestrictionsBundle.getBoolean(GetRestrictionsReceiver.KEY_BOOLEAN, false));
mBooleanEntry.setType(RestrictionEntry.TYPE_BOOLEAN);
mBooleanPref.setChecked(mBooleanEntry.getSelectedState());
// Initializes the single choice restriction entry and updates its corresponding
// shared preference value.
mChoiceEntry = new RestrictionEntry(GetRestrictionsReceiver.KEY_CHOICE, mRestrictionsBundle.getString(GetRestrictionsReceiver.KEY_CHOICE));
mChoiceEntry.setType(RestrictionEntry.TYPE_CHOICE);
mChoicePref.setValue(mChoiceEntry.getSelectedString());
// Initializes the multi-select restriction entry and updates its corresponding
// shared preference value.
mMultiEntry = new RestrictionEntry(GetRestrictionsReceiver.KEY_MULTI_SELECT, mRestrictionsBundle.getStringArray(GetRestrictionsReceiver.KEY_MULTI_SELECT));
mMultiEntry.setType(RestrictionEntry.TYPE_MULTI_SELECT);
if (mMultiEntry.getAllSelectedStrings() != null) {
HashSet<String> set = new HashSet<String>();
final String[] values = mRestrictionsBundle.getStringArray(GetRestrictionsReceiver.KEY_MULTI_SELECT);
if (values != null) {
for (String value : values) {
set.add(value);
}
}
mMultiPref.setValues(set);
}
mRestrictions.add(mBooleanEntry);
mRestrictions.add(mChoiceEntry);
mRestrictions.add(mMultiEntry);
}
// Prepares result to be passed back to the Settings app when the custom restrictions
// activity finishes.
Intent intent = new Intent(getActivity().getIntent());
intent.putParcelableArrayListExtra(Intent.EXTRA_RESTRICTIONS_LIST, new ArrayList<RestrictionEntry>(mRestrictions));
getActivity().setResult(Activity.RESULT_OK, intent);
}
use of android.content.RestrictionEntry in project Android-Developers-Samples by johnjohndoe.
the class GetRestrictionsReceiver method initRestrictions.
// Demonstrates the creation of standard app restriction types: boolean, single choice, and
// multi-select.
private ArrayList<RestrictionEntry> initRestrictions(Context context) {
ArrayList<RestrictionEntry> newRestrictions = new ArrayList<RestrictionEntry>();
Resources res = context.getResources();
RestrictionEntry reBoolean = new RestrictionEntry(KEY_BOOLEAN, false);
populateBooleanEntry(res, reBoolean);
newRestrictions.add(reBoolean);
RestrictionEntry reSingleChoice = new RestrictionEntry(KEY_CHOICE, (String) null);
populateChoiceEntry(res, reSingleChoice);
newRestrictions.add(reSingleChoice);
RestrictionEntry reMultiSelect = new RestrictionEntry(KEY_MULTI_SELECT, (String[]) null);
populateMultiEntry(res, reMultiSelect);
newRestrictions.add(reMultiSelect);
return newRestrictions;
}
Aggregations