Search in sources :

Example 1 with RestrictionEntry

use of android.content.RestrictionEntry in project cw-omnibus by commonsguy.

the class RestrictionEntriesReceiver method onReceive.

@Override
public void onReceive(Context ctxt, Intent intent) {
    Bundle current = (Bundle) intent.getParcelableExtra(Intent.EXTRA_RESTRICTIONS_BUNDLE);
    ArrayList<RestrictionEntry> restrictions = new ArrayList<RestrictionEntry>();
    restrictions.add(buildBooleanRestriction(ctxt, current));
    restrictions.add(buildChoiceRestriction(ctxt, current));
    restrictions.add(buildMultiSelectRestriction(ctxt, current));
    Bundle result = new Bundle();
    result.putParcelableArrayList(Intent.EXTRA_RESTRICTIONS_LIST, restrictions);
    setResultExtras(result);
}
Also used : Bundle(android.os.Bundle) RestrictionEntry(android.content.RestrictionEntry) ArrayList(java.util.ArrayList)

Example 2 with RestrictionEntry

use of android.content.RestrictionEntry in project cw-omnibus by commonsguy.

the class RestrictionEntriesReceiver method buildChoiceRestriction.

private RestrictionEntry buildChoiceRestriction(Context ctxt, Bundle current) {
    RestrictionEntry entry = new RestrictionEntry(RESTRICTION_CHOICE, current.getString(RESTRICTION_CHOICE));
    entry.setTitle(ctxt.getString(R.string.choice_restriction_title));
    entry.setChoiceEntries(ctxt, R.array.display_values);
    entry.setChoiceValues(ctxt, R.array.restriction_values);
    return (entry);
}
Also used : RestrictionEntry(android.content.RestrictionEntry)

Example 3 with RestrictionEntry

use of android.content.RestrictionEntry in project cw-omnibus by commonsguy.

the class RestrictionEntriesReceiver method buildMultiSelectRestriction.

private RestrictionEntry buildMultiSelectRestriction(Context ctxt, Bundle current) {
    RestrictionEntry entry = new RestrictionEntry(RESTRICTION_MULTI, current.getStringArray(RESTRICTION_MULTI));
    entry.setTitle("A Multi-Select Restriction");
    entry.setChoiceEntries(ctxt, R.array.display_values);
    entry.setChoiceValues(ctxt, R.array.restriction_values);
    return (entry);
}
Also used : RestrictionEntry(android.content.RestrictionEntry)

Example 4 with RestrictionEntry

use of android.content.RestrictionEntry in project android_packages_apps_Settings by LineageOS.

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);
}
Also used : RestrictionEntry(android.content.RestrictionEntry)

Example 5 with RestrictionEntry

use of android.content.RestrictionEntry in project android_packages_apps_Settings by LineageOS.

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;
}
Also used : StringTokenizer(java.util.StringTokenizer) HashSet(java.util.HashSet) Set(java.util.Set) RestrictionEntry(android.content.RestrictionEntry) ListPreference(android.support.v7.preference.ListPreference) MultiSelectListPreference(android.support.v14.preference.MultiSelectListPreference)

Aggregations

RestrictionEntry (android.content.RestrictionEntry)44 Bundle (android.os.Bundle)17 HashSet (java.util.HashSet)16 MultiSelectListPreference (android.support.v14.preference.MultiSelectListPreference)12 ListPreference (android.support.v7.preference.ListPreference)12 ArrayList (java.util.ArrayList)9 Resources (android.content.res.Resources)8 Set (java.util.Set)8 UserManager (android.os.UserManager)7 StringTokenizer (java.util.StringTokenizer)7 SwitchPreference (android.support.v14.preference.SwitchPreference)6 Preference (android.support.v7.preference.Preference)6 Intent (android.content.Intent)3 ListPreference (androidx.preference.ListPreference)2 MultiSelectListPreference (androidx.preference.MultiSelectListPreference)2 Activity (android.app.Activity)1 Preference (androidx.preference.Preference)1 SwitchPreference (androidx.preference.SwitchPreference)1 Test (org.junit.Test)1