Java Code Examples for android.content.RestrictionEntry#TYPE_STRING

The following examples show how to use android.content.RestrictionEntry#TYPE_STRING . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ManagedConfigurationsFragment.java    From android-testdpc with Apache License 2.0 6 votes vote down vote up
protected RestrictionEntry[] convertBundleToRestrictions(Bundle restrictionBundle) {
    List<RestrictionEntry> restrictionEntries = new ArrayList<>();
    Set<String> keys = restrictionBundle.keySet();
    for (String key : keys) {
        Object value = restrictionBundle.get(key);
        if (value instanceof Boolean) {
            restrictionEntries.add(new RestrictionEntry(key, (boolean) value));
        } else if (value instanceof Integer) {
            restrictionEntries.add(new RestrictionEntry(key, (int) value));
        } else if (value instanceof String) {
            RestrictionEntry entry = new RestrictionEntry(RestrictionEntry.TYPE_STRING, key);
            entry.setSelectedString((String) value);
            restrictionEntries.add(entry);
        } else if (value instanceof String[]) {
            restrictionEntries.add(new RestrictionEntry(key, (String[]) value));
        } else if (value instanceof Bundle) {
            addBundleEntryToRestrictions(restrictionEntries, key, (Bundle) value);
        } else if (value instanceof Parcelable[]) {
            addBundleArrayToRestrictions(restrictionEntries, key, (Parcelable[]) value);
        }
    }
    return restrictionEntries.toArray(new RestrictionEntry[0]);
}
 
Example 2
Source File: ManagedConfigurationsFragment.java    From android-testdpc with Apache License 2.0 6 votes vote down vote up
private int getTypeIndexFromRestrictionType(int restrictionType) {
    switch (restrictionType) {
        case RestrictionEntry.TYPE_BOOLEAN:
            return KeyValuePairDialogFragment.DialogType.BOOL_TYPE;
        case RestrictionEntry.TYPE_INTEGER:
            return KeyValuePairDialogFragment.DialogType.INT_TYPE;
        case RestrictionEntry.TYPE_STRING:
            return KeyValuePairDialogFragment.DialogType.STRING_TYPE;
        case RestrictionEntry.TYPE_MULTI_SELECT:
            return KeyValuePairDialogFragment.DialogType.STRING_ARRAY_TYPE;
        case RestrictionEntry.TYPE_BUNDLE:
            return KeyValuePairDialogFragment.DialogType.BUNDLE_TYPE;
        case RestrictionEntry.TYPE_BUNDLE_ARRAY:
            return KeyValuePairDialogFragment.DialogType.BUNDLE_ARRAY_TYPE;
        default:
            throw new AssertionError("Unknown restriction type");
    }
}
 
Example 3
Source File: ManagedConfigurationsFragment.java    From android-testdpc with Apache License 2.0 6 votes vote down vote up
private int getRestrictionTypeFromDialogType(int typeIndex) {
    switch (typeIndex) {
        case KeyValuePairDialogFragment.DialogType.BOOL_TYPE:
            return RestrictionEntry.TYPE_BOOLEAN;
        case KeyValuePairDialogFragment.DialogType.INT_TYPE:
            return RestrictionEntry.TYPE_INTEGER;
        case KeyValuePairDialogFragment.DialogType.STRING_TYPE:
            return RestrictionEntry.TYPE_STRING;
        case KeyValuePairDialogFragment.DialogType.STRING_ARRAY_TYPE:
            return RestrictionEntry.TYPE_MULTI_SELECT;
        case KeyValuePairDialogFragment.DialogType.BUNDLE_TYPE:
            return RestrictionEntry.TYPE_BUNDLE;
        case KeyValuePairDialogFragment.DialogType.BUNDLE_ARRAY_TYPE:
            return RestrictionEntry.TYPE_BUNDLE_ARRAY;
        default:
            throw new AssertionError("Unknown type index");
    }
}
 
Example 4
Source File: ManagedConfigurationsFragment.java    From android-testdpc with Apache License 2.0 5 votes vote down vote up
@TargetApi(VERSION_CODES.M)
private void updateRestrictionEntryFromResultIntent(RestrictionEntry restrictionEntry,
        Intent intent) {
    switch (restrictionEntry.getType()) {
        case RestrictionEntry.TYPE_BOOLEAN:
            restrictionEntry.setSelectedState(intent.getBooleanExtra(RESULT_VALUE, false));
            break;
        case RestrictionEntry.TYPE_INTEGER:
            restrictionEntry.setIntValue(intent.getIntExtra(RESULT_VALUE, 0));
            break;
        case RestrictionEntry.TYPE_STRING:
            restrictionEntry.setSelectedString(intent.getStringExtra(RESULT_VALUE));
            break;
        case RestrictionEntry.TYPE_MULTI_SELECT:
            restrictionEntry.setAllSelectedStrings(intent.getStringArrayExtra(RESULT_VALUE));
            break;
        case RestrictionEntry.TYPE_BUNDLE: {
            Bundle bundle = intent.getBundleExtra(RESULT_VALUE);
            restrictionEntry.setRestrictions(convertBundleToRestrictions(bundle));
            break;
        }
        case RestrictionEntry.TYPE_BUNDLE_ARRAY: {
            Parcelable[] bundleArray = intent.getParcelableArrayExtra(RESULT_VALUE);
            RestrictionEntry[] restrictionEntryArray = new RestrictionEntry[bundleArray.length];
            for (int i = 0; i< bundleArray.length; i++) {
                restrictionEntryArray[i] = RestrictionEntry.createBundleEntry(String.valueOf(i),
                        convertBundleToRestrictions((Bundle) bundleArray[i]));
            }
            restrictionEntry.setRestrictions(restrictionEntryArray);
            break;
        }
    }
}
 
Example 5
Source File: RestrictionManagerCompat.java    From android-testdpc with Apache License 2.0 5 votes vote down vote up
private static Bundle addRestrictionToBundle(Bundle bundle, RestrictionEntry entry) {
    switch (entry.getType()) {
        case RestrictionEntry.TYPE_BOOLEAN:
            bundle.putBoolean(entry.getKey(), entry.getSelectedState());
            break;
        case RestrictionEntry.TYPE_CHOICE:
        case RestrictionEntry.TYPE_MULTI_SELECT:
            bundle.putStringArray(entry.getKey(), entry.getAllSelectedStrings());
            break;
        case RestrictionEntry.TYPE_INTEGER:
            bundle.putInt(entry.getKey(), entry.getIntValue());
            break;
        case RestrictionEntry.TYPE_STRING:
        case RestrictionEntry.TYPE_NULL:
            bundle.putString(entry.getKey(), entry.getSelectedString());
            break;
        case RestrictionEntry.TYPE_BUNDLE:
            addBundleRestrictionToBundle(bundle, entry);
            break;
        case RestrictionEntry.TYPE_BUNDLE_ARRAY:
            addBundleArrayRestrictionToBundle(bundle, entry);
            break;
        default:
            throw new IllegalArgumentException(
                    "Unsupported restrictionEntry type: " + entry.getType());
    }
    return bundle;
}
 
Example 6
Source File: ManagedConfigurationsFragment.java    From android-testdpc with Apache License 2.0 4 votes vote down vote up
private void showEditDialog(final RestrictionEntry restrictionEntry) {
    mEditingRestrictionEntry = restrictionEntry;
    int type = KeyValuePairDialogFragment.DialogType.BOOL_TYPE;
    Object value = null;
    String key = "";
    if (restrictionEntry != null) {
        key = restrictionEntry.getKey();
        type = getTypeIndexFromRestrictionType(restrictionEntry.getType());
        switch (restrictionEntry.getType()) {
            case RestrictionEntry.TYPE_BOOLEAN:
                value = restrictionEntry.getSelectedState();
                break;
            case RestrictionEntry.TYPE_INTEGER:
                value = restrictionEntry.getIntValue();
                break;
            case RestrictionEntry.TYPE_STRING:
                value = restrictionEntry.getSelectedString();
                break;
            case RestrictionEntry.TYPE_MULTI_SELECT:
                value = restrictionEntry.getAllSelectedStrings();
                break;
            case RestrictionEntry.TYPE_BUNDLE:
                value = RestrictionManagerCompat.convertRestrictionsToBundle(Arrays.asList(
                        getRestrictionEntries(restrictionEntry)));
                break;
            case RestrictionEntry.TYPE_BUNDLE_ARRAY:
                RestrictionEntry[] restrictionEntries = getRestrictionEntries(restrictionEntry);
                Bundle[] bundles = new Bundle[restrictionEntries.length];
                for (int i = 0; i < restrictionEntries.length; i++) {
                    bundles[i] =
                            RestrictionManagerCompat.convertRestrictionsToBundle(Arrays.asList(
                                    getRestrictionEntries(restrictionEntries[i])));
                }
                value = bundles;
                break;
        }
    }
    int[] supportType = (Util.SDK_INT < VERSION_CODES.M)
            ? SUPPORTED_TYPES_PRE_M
            : SUPPORTED_TYPES;
    KeyValuePairDialogFragment dialogFragment =
            KeyValuePairDialogFragment.newInstance(type, true, key, value, supportType,
                    getCurrentAppName());
    dialogFragment.setTargetFragment(this, RESULT_CODE_EDIT_DIALOG);
    dialogFragment.show(getFragmentManager(), "dialog");
}