Search in sources :

Example 11 with RestrictionEntry

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

Example 12 with RestrictionEntry

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;
}
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)

Example 13 with RestrictionEntry

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;
}
Also used : RestrictionEntry(android.content.RestrictionEntry) UserManager(android.os.UserManager) Bundle(android.os.Bundle) ArrayList(java.util.ArrayList) Resources(android.content.res.Resources)

Aggregations

RestrictionEntry (android.content.RestrictionEntry)13 Bundle (android.os.Bundle)5 HashSet (java.util.HashSet)4 Intent (android.content.Intent)3 ArrayList (java.util.ArrayList)3 Resources (android.content.res.Resources)2 MultiSelectListPreference (android.support.v14.preference.MultiSelectListPreference)2 ListPreference (android.support.v7.preference.ListPreference)2 Set (java.util.Set)2 Activity (android.app.Activity)1 UserManager (android.os.UserManager)1 SwitchPreference (android.support.v14.preference.SwitchPreference)1 Preference (android.support.v7.preference.Preference)1 StringTokenizer (java.util.StringTokenizer)1