Java Code Examples for android.content.res.Resources#obtainAttributes()

The following examples show how to use android.content.res.Resources#obtainAttributes() . 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: Keyboard.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
public Row(Resources res, Keyboard parent, XmlResourceParser parser) {
    this.parent = parent;
    TypedArray a = res.obtainAttributes(Xml.asAttributeSet(parser), 
            com.android.internal.R.styleable.Keyboard);
    defaultWidth = getDimensionOrFraction(a, 
            com.android.internal.R.styleable.Keyboard_keyWidth, 
            parent.mDisplayWidth, parent.mDefaultWidth);
    defaultHeight = getDimensionOrFraction(a, 
            com.android.internal.R.styleable.Keyboard_keyHeight, 
            parent.mDisplayHeight, parent.mDefaultHeight);
    defaultHorizontalGap = getDimensionOrFraction(a,
            com.android.internal.R.styleable.Keyboard_horizontalGap, 
            parent.mDisplayWidth, parent.mDefaultHorizontalGap);
    verticalGap = getDimensionOrFraction(a, 
            com.android.internal.R.styleable.Keyboard_verticalGap, 
            parent.mDisplayHeight, parent.mDefaultVerticalGap);
    a.recycle();
    a = res.obtainAttributes(Xml.asAttributeSet(parser),
            com.android.internal.R.styleable.Keyboard_Row);
    rowEdgeFlags = a.getInt(com.android.internal.R.styleable.Keyboard_Row_rowEdgeFlags, 0);
    mode = a.getResourceId(com.android.internal.R.styleable.Keyboard_Row_keyboardMode,
            0);
}
 
Example 2
Source File: KeyboardLayoutSet.java    From AOSP-Kayboard-7.1.2 with Apache License 2.0 5 votes vote down vote up
private static int readScriptIdFromTagFeature(final Resources resources,
        final XmlPullParser parser) throws IOException, XmlPullParserException {
    final TypedArray featureAttr = resources.obtainAttributes(Xml.asAttributeSet(parser),
            R.styleable.KeyboardLayoutSet_Feature);
    try {
        final int scriptId =
                featureAttr.getInt(R.styleable.KeyboardLayoutSet_Feature_supportedScript,
                        ScriptUtils.SCRIPT_UNKNOWN);
        XmlParseUtils.checkEndTag(TAG_FEATURE, parser);
        return scriptId;
    } finally {
        featureAttr.recycle();
    }
}
 
Example 3
Source File: VectorDrawableCommon.java    From VectorChildFinder with Apache License 2.0 5 votes vote down vote up
/**
 * Obtains styled attributes from the theme, if available, or unstyled
 * resources if the theme is null.
 *
 * @hide
 */
protected static TypedArray obtainAttributes(
        Resources res, Resources.Theme theme, AttributeSet set, int[] attrs) {
    if (theme == null) {
        return res.obtainAttributes(set, attrs);
    }
    return theme.obtainStyledAttributes(set, attrs, 0, 0);
}
 
Example 4
Source File: AccountAuthenticatorCache.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Override
public AuthenticatorDescription parseServiceAttributes(Resources res,
        String packageName, AttributeSet attrs) {
    TypedArray sa = res.obtainAttributes(attrs,
            com.android.internal.R.styleable.AccountAuthenticator);
    try {
        final String accountType =
                sa.getString(com.android.internal.R.styleable.AccountAuthenticator_accountType);
        final int labelId = sa.getResourceId(
                com.android.internal.R.styleable.AccountAuthenticator_label, 0);
        final int iconId = sa.getResourceId(
                com.android.internal.R.styleable.AccountAuthenticator_icon, 0);
        final int smallIconId = sa.getResourceId(
                com.android.internal.R.styleable.AccountAuthenticator_smallIcon, 0);
        final int prefId = sa.getResourceId(
                com.android.internal.R.styleable.AccountAuthenticator_accountPreferences, 0);
        final boolean customTokens = sa.getBoolean(
                com.android.internal.R.styleable.AccountAuthenticator_customTokens, false);
        if (TextUtils.isEmpty(accountType)) {
            return null;
        }
        return new AuthenticatorDescription(accountType, packageName, labelId, iconId,
                smallIconId, prefId, customTokens);
    } finally {
        sa.recycle();
    }
}
 
Example 5
Source File: VectorDrawable.java    From Mover with Apache License 2.0 5 votes vote down vote up
public void inflate(Resources r, AttributeSet attrs, Theme theme) {
  // TODO TINT THEME Not supported yet
  final TypedArray a = r.obtainAttributes(attrs,
      R.styleable.VectorDrawableClipPath);
  updateStateFromTypedArray(a);
  a.recycle();
}
 
Example 6
Source File: DynamicApkParser.java    From Android-plugin-support with MIT License 5 votes vote down vote up
private boolean parseUsesPermission(DynamicApkInfo pkg, Resources res, XmlResourceParser parser,
                                    AttributeSet attrs) throws XmlPullParserException, IOException {
    TypedArray sa = res.obtainAttributes(attrs,
            Hooks.getStyleableArray("AndroidManifestUsesPermission"));

    // Note: don't allow this value to be a reference to a resource
    // that may change.
    String name = sa.getNonResourceString(
            Hooks.getStyleable("AndroidManifestUsesPermission_name"));

    int maxSdkVersion = 0;
    TypedValue val = sa.peekValue(
            Hooks.getStyleable("AndroidManifestUsesPermission_maxSdkVersion"));
    if (val != null) {
        if (val.type >= TypedValue.TYPE_FIRST_INT && val.type <= TypedValue.TYPE_LAST_INT) {
            maxSdkVersion = val.data;
        }
    }

    sa.recycle();

    if ((maxSdkVersion == 0) || (maxSdkVersion >= Build.VERSION.SDK_INT)) {
        if (name != null) {
            int index = pkg.requestedPermissions.indexOf(name);
            if (index == -1) {
                pkg.requestedPermissions.add(name.intern());
            } else {
                Log.w(TAG, "Ignoring duplicate uses-permissions/uses-permissions-sdk-m: "
                        + name + " in package: " + pkg.packageName + " at: "
                        + parser.getPositionDescription());
            }
        }
    }

    XmlUtils.skipCurrentTag(parser);
    return true;
}
 
Example 7
Source File: TouchEffectDrawable.java    From Genius-Android with Apache License 2.0 5 votes vote down vote up
static TypedArray obtainAttributes(
        Resources res, Resources.Theme theme, AttributeSet set, int[] attrs) {
    if (theme == null) {
        return res.obtainAttributes(set, attrs);
    }
    return theme.obtainStyledAttributes(set, attrs, 0, 0);
}
 
Example 8
Source File: PackageParser.java    From AndroidComponentPlugin with Apache License 2.0 5 votes vote down vote up
private boolean parseUsesPermission(Package pkg, Resources res, XmlResourceParser parser,
                                        AttributeSet attrs, String[] outError)
            throws XmlPullParserException, IOException {
        TypedArray sa = res.obtainAttributes(attrs,
                com.android.internal.R.styleable.AndroidManifestUsesPermission);

        // Note: don't allow this value to be a reference to a resource
        // that may change.
        String name = sa.getNonResourceString(
                com.android.internal.R.styleable.AndroidManifestUsesPermission_name);
/*
        boolean required = sa.getBoolean(
                com.android.internal.R.styleable.AndroidManifestUsesPermission_required, true);
*/
        boolean required = true; // Optional <uses-permission> not supported

        sa.recycle();

        if (name != null) {
            int index = pkg.requestedPermissions.indexOf(name);
            if (index == -1) {
                pkg.requestedPermissions.add(name.intern());
                pkg.requestedPermissionsRequired.add(required ? Boolean.TRUE : Boolean.FALSE);
            } else {
                if (pkg.requestedPermissionsRequired.get(index) != required) {
                    outError[0] = "conflicting <uses-permission> entries";
                    mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
                    return false;
                }
            }
        }

        XmlUtils.skipCurrentTag(parser);
        return true;
    }
 
Example 9
Source File: DrawableHelper.java    From ProjectX with Apache License 2.0 5 votes vote down vote up
static TypedArray obtainAttributes(Resources res, Resources.Theme theme,
                                   AttributeSet set, int[] attrs) {
    if (theme == null) {
        return res.obtainAttributes(set, attrs);
    }
    return theme.obtainStyledAttributes(set, attrs, 0, 0);
}
 
Example 10
Source File: PackageParser.java    From AndroidComponentPlugin with Apache License 2.0 4 votes vote down vote up
private PermissionGroup parsePermissionGroup(Package owner, int flags, Resources res,
        XmlPullParser parser, AttributeSet attrs, String[] outError)
    throws XmlPullParserException, IOException {
    PermissionGroup perm = new PermissionGroup(owner);

    TypedArray sa = res.obtainAttributes(attrs,
            com.android.internal.R.styleable.AndroidManifestPermissionGroup);

    if (!parsePackageItemInfo(owner, perm.info, outError,
            "<permission-group>", sa,
            com.android.internal.R.styleable.AndroidManifestPermissionGroup_name,
            com.android.internal.R.styleable.AndroidManifestPermissionGroup_label,
            com.android.internal.R.styleable.AndroidManifestPermissionGroup_icon,
            com.android.internal.R.styleable.AndroidManifestPermissionGroup_logo)) {
        sa.recycle();
        mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
        return null;
    }

    perm.info.descriptionRes = sa.getResourceId(
            com.android.internal.R.styleable.AndroidManifestPermissionGroup_description,
            0);
    perm.info.flags = sa.getInt(
            com.android.internal.R.styleable.AndroidManifestPermissionGroup_permissionGroupFlags, 0);
    perm.info.priority = sa.getInt(
            com.android.internal.R.styleable.AndroidManifestPermissionGroup_priority, 0);
    if (perm.info.priority > 0 && (flags&PARSE_IS_SYSTEM) == 0) {
        perm.info.priority = 0;
    }

    sa.recycle();
    
    if (!parseAllMetaData(res, parser, attrs, "<permission-group>", perm,
            outError)) {
        mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
        return null;
    }

    owner.permissionGroups.add(perm);

    return perm;
}
 
Example 11
Source File: DynamicApkParser.java    From Android-plugin-support with MIT License 4 votes vote down vote up
private Permission parsePermission(DynamicApkInfo owner, Resources res,
                                       XmlPullParser parser, AttributeSet attrs, String[] outError)
            throws XmlPullParserException, IOException {
        Permission perm = new Permission(owner);

        TypedArray sa = res.obtainAttributes(attrs,
                Hooks.getStyleableArray("AndroidManifestPermission"));

        if (!parsePackageItemInfo(owner, perm.info, outError,
                "<permission>", sa,
                Hooks.getStyleable("AndroidManifestPermission_name"),
                Hooks.getStyleable("AndroidManifestPermission_label"),
                Hooks.getStyleable("AndroidManifestPermission_icon"),
                Hooks.getStyleable("AndroidManifestPermission_logo"),
                Hooks.getStyleable("AndroidManifestPermission_banner"))) {
            sa.recycle();
            mParseError = INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
            return null;
        }

        // Note: don't allow this value to be a reference to a resource
        // that may change.
        perm.info.group = sa.getNonResourceString(
                Hooks.getStyleable("AndroidManifestPermission_permissionGroup"));
        if (perm.info.group != null) {
            perm.info.group = perm.info.group.intern();
        }

        perm.info.descriptionRes = sa.getResourceId(
                Hooks.getStyleable("AndroidManifestPermission_description"),
                0);

        perm.info.protectionLevel = sa.getInt(
                Hooks.getStyleable("AndroidManifestPermission_protectionLevel"),
                PermissionInfo.PROTECTION_NORMAL);

        perm.info.flags = sa.getInt(
                Hooks.getStyleable("AndroidManifestPermission_permissionFlags"), 0);

        sa.recycle();

        if (perm.info.protectionLevel == -1) {
            outError[0] = "<permission> does not specify protectionLevel";
            mParseError = INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
            return null;
        }

//        perm.info.protectionLevel = PermissionInfo.fixProtectionLevel(perm.info.protectionLevel);

        if ((perm.info.protectionLevel&PermissionInfo.PROTECTION_MASK_FLAGS) != 0) {
            if ((perm.info.protectionLevel&PermissionInfo.PROTECTION_MASK_BASE) !=
                    PermissionInfo.PROTECTION_SIGNATURE) {
                outError[0] = "<permission>  protectionLevel specifies a flag but is "
                        + "not based on signature type";
                mParseError = INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
                return null;
            }
        }

        if (!parseAllMetaData(res, parser, attrs, "<permission>", perm,
                outError)) {
            mParseError = INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
            return null;
        }

        owner.permissions.add(perm);

        return perm;
    }
 
Example 12
Source File: NavInflater.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
@NonNull
private NavDestination inflate(@NonNull Resources res, @NonNull XmlResourceParser parser,
        @NonNull AttributeSet attrs) throws XmlPullParserException, IOException {
    Navigator navigator = mNavigatorProvider.getNavigator(parser.getName());
    final NavDestination dest = navigator.createDestination();

    dest.onInflate(mContext, attrs);

    final int innerDepth = parser.getDepth() + 1;
    int type;
    int depth;
    while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
            && ((depth = parser.getDepth()) >= innerDepth
            || type != XmlPullParser.END_TAG)) {
        if (type != XmlPullParser.START_TAG) {
            continue;
        }

        if (depth > innerDepth) {
            continue;
        }

        final String name = parser.getName();
        if (TAG_ARGUMENT.equals(name)) {
            inflateArgument(res, dest, attrs);
        } else if (TAG_DEEP_LINK.equals(name)) {
            inflateDeepLink(res, dest, attrs);
        } else if (TAG_ACTION.equals(name)) {
            inflateAction(res, dest, attrs);
        } else if (TAG_INCLUDE.equals(name) && dest instanceof NavGraph) {
            final TypedArray a = res.obtainAttributes(attrs, R.styleable.NavInclude);
            final int id = a.getResourceId(R.styleable.NavInclude_graph, 0);
            ((NavGraph) dest).addDestination(inflate(id));
            a.recycle();
        } else if (dest instanceof NavGraph) {
            ((NavGraph) dest).addDestination(inflate(res, parser, attrs));
        }
    }

    return dest;
}
 
Example 13
Source File: PackageParser.java    From AndroidComponentPlugin with Apache License 2.0 4 votes vote down vote up
private Instrumentation parseInstrumentation(Package owner, Resources res,
        XmlPullParser parser, AttributeSet attrs, String[] outError)
    throws XmlPullParserException, IOException {
    TypedArray sa = res.obtainAttributes(attrs,
            com.android.internal.R.styleable.AndroidManifestInstrumentation);

    if (mParseInstrumentationArgs == null) {
        mParseInstrumentationArgs = new ParsePackageItemArgs(owner, outError,
                com.android.internal.R.styleable.AndroidManifestInstrumentation_name,
                com.android.internal.R.styleable.AndroidManifestInstrumentation_label,
                com.android.internal.R.styleable.AndroidManifestInstrumentation_icon,
                com.android.internal.R.styleable.AndroidManifestInstrumentation_logo);
        mParseInstrumentationArgs.tag = "<instrumentation>";
    }
    
    mParseInstrumentationArgs.sa = sa;
    
    Instrumentation a = new Instrumentation(mParseInstrumentationArgs,
            new InstrumentationInfo());
    if (outError[0] != null) {
        sa.recycle();
        mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
        return null;
    }

    String str;
    // Note: don't allow this value to be a reference to a resource
    // that may change.
    str = sa.getNonResourceString(
            com.android.internal.R.styleable.AndroidManifestInstrumentation_targetPackage);
    a.info.targetPackage = str != null ? str.intern() : null;

    a.info.handleProfiling = sa.getBoolean(
            com.android.internal.R.styleable.AndroidManifestInstrumentation_handleProfiling,
            false);

    a.info.functionalTest = sa.getBoolean(
            com.android.internal.R.styleable.AndroidManifestInstrumentation_functionalTest,
            false);

    sa.recycle();

    if (a.info.targetPackage == null) {
        outError[0] = "<instrumentation> does not specify targetPackage";
        mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
        return null;
    }

    if (!parseAllMetaData(res, parser, attrs, "<instrumentation>", a,
            outError)) {
        mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
        return null;
    }

    owner.instrumentation.add(a);

    return a;
}
 
Example 14
Source File: PackageParser.java    From AndroidComponentPlugin with Apache License 2.0 4 votes vote down vote up
private Permission parsePermission(Package owner, Resources res,
        XmlPullParser parser, AttributeSet attrs, String[] outError)
    throws XmlPullParserException, IOException {
    Permission perm = new Permission(owner);

    TypedArray sa = res.obtainAttributes(attrs,
            com.android.internal.R.styleable.AndroidManifestPermission);

    if (!parsePackageItemInfo(owner, perm.info, outError,
            "<permission>", sa,
            com.android.internal.R.styleable.AndroidManifestPermission_name,
            com.android.internal.R.styleable.AndroidManifestPermission_label,
            com.android.internal.R.styleable.AndroidManifestPermission_icon,
            com.android.internal.R.styleable.AndroidManifestPermission_logo)) {
        sa.recycle();
        mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
        return null;
    }

    // Note: don't allow this value to be a reference to a resource
    // that may change.
    perm.info.group = sa.getNonResourceString(
            com.android.internal.R.styleable.AndroidManifestPermission_permissionGroup);
    if (perm.info.group != null) {
        perm.info.group = perm.info.group.intern();
    }
    
    perm.info.descriptionRes = sa.getResourceId(
            com.android.internal.R.styleable.AndroidManifestPermission_description,
            0);

    perm.info.protectionLevel = sa.getInt(
            com.android.internal.R.styleable.AndroidManifestPermission_protectionLevel,
            PermissionInfo.PROTECTION_NORMAL);

    perm.info.flags = sa.getInt(
            com.android.internal.R.styleable.AndroidManifestPermission_permissionFlags, 0);

    sa.recycle();

    if (perm.info.protectionLevel == -1) {
        outError[0] = "<permission> does not specify protectionLevel";
        mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
        return null;
    }

    perm.info.protectionLevel = PermissionInfo.fixProtectionLevel(perm.info.protectionLevel);

    if ((perm.info.protectionLevel&PermissionInfo.PROTECTION_MASK_FLAGS) != 0) {
        if ((perm.info.protectionLevel&PermissionInfo.PROTECTION_MASK_BASE) !=
                PermissionInfo.PROTECTION_SIGNATURE) {
            outError[0] = "<permission>  protectionLevel specifies a flag but is "
                    + "not based on signature type";
            mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
            return null;
        }
    }
    
    if (!parseAllMetaData(res, parser, attrs, "<permission>", perm,
            outError)) {
        mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
        return null;
    }

    owner.permissions.add(perm);

    return perm;
}
 
Example 15
Source File: PackageParser.java    From AndroidComponentPlugin with Apache License 2.0 4 votes vote down vote up
private Provider parseProvider(Package owner, Resources res,
        XmlPullParser parser, AttributeSet attrs, int flags, String[] outError)
        throws XmlPullParserException, IOException {
    TypedArray sa = res.obtainAttributes(attrs,
            com.android.internal.R.styleable.AndroidManifestProvider);

    if (mParseProviderArgs == null) {
        mParseProviderArgs = new ParseComponentArgs(owner, outError,
                com.android.internal.R.styleable.AndroidManifestProvider_name,
                com.android.internal.R.styleable.AndroidManifestProvider_label,
                com.android.internal.R.styleable.AndroidManifestProvider_icon,
                com.android.internal.R.styleable.AndroidManifestProvider_logo,
                mSeparateProcesses,
                com.android.internal.R.styleable.AndroidManifestProvider_process,
                com.android.internal.R.styleable.AndroidManifestProvider_description,
                com.android.internal.R.styleable.AndroidManifestProvider_enabled);
        mParseProviderArgs.tag = "<provider>";
    }
    
    mParseProviderArgs.sa = sa;
    mParseProviderArgs.flags = flags;
    
    Provider p = new Provider(mParseProviderArgs, new ProviderInfo());
    if (outError[0] != null) {
        sa.recycle();
        return null;
    }

    p.info.exported = sa.getBoolean(
            com.android.internal.R.styleable.AndroidManifestProvider_exported, true);

    String cpname = sa.getNonConfigurationString(
            com.android.internal.R.styleable.AndroidManifestProvider_authorities, 0);

    p.info.isSyncable = sa.getBoolean(
            com.android.internal.R.styleable.AndroidManifestProvider_syncable,
            false);

    String permission = sa.getNonConfigurationString(
            com.android.internal.R.styleable.AndroidManifestProvider_permission, 0);
    String str = sa.getNonConfigurationString(
            com.android.internal.R.styleable.AndroidManifestProvider_readPermission, 0);
    if (str == null) {
        str = permission;
    }
    if (str == null) {
        p.info.readPermission = owner.applicationInfo.permission;
    } else {
        p.info.readPermission =
            str.length() > 0 ? str.toString().intern() : null;
    }
    str = sa.getNonConfigurationString(
            com.android.internal.R.styleable.AndroidManifestProvider_writePermission, 0);
    if (str == null) {
        str = permission;
    }
    if (str == null) {
        p.info.writePermission = owner.applicationInfo.permission;
    } else {
        p.info.writePermission =
            str.length() > 0 ? str.toString().intern() : null;
    }

    p.info.grantUriPermissions = sa.getBoolean(
            com.android.internal.R.styleable.AndroidManifestProvider_grantUriPermissions,
            false);

    p.info.multiprocess = sa.getBoolean(
            com.android.internal.R.styleable.AndroidManifestProvider_multiprocess,
            false);

    p.info.initOrder = sa.getInt(
            com.android.internal.R.styleable.AndroidManifestProvider_initOrder,
            0);

    sa.recycle();

    if ((owner.applicationInfo.flags&ApplicationInfo.FLAG_CANT_SAVE_STATE) != 0) {
        // A heavy-weight application can not have providers in its main process
        // We can do direct compare because we intern all strings.
        if (p.info.processName == owner.packageName) {
            outError[0] = "Heavy-weight applications can not have providers in main process";
            return null;
        }
    }
    
    if (cpname == null) {
        outError[0] = "<provider> does not incude authorities attribute";
        return null;
    }
    p.info.authority = cpname.intern();

    if (!parseProviderTags(res, parser, attrs, p, outError)) {
        return null;
    }

    return p;
}
 
Example 16
Source File: AnimatorInflater.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
/**
 * Creates a new animation whose parameters come from the specified context
 * and attributes set.
 *
 * @param res The resources
 * @param attrs The set of attributes holding the animation parameters
 * @param anim Null if this is a ValueAnimator, otherwise this is an
 *            ObjectAnimator
 */
private static ValueAnimator loadAnimator(Resources res, Theme theme,
        AttributeSet attrs, ValueAnimator anim, float pathErrorScale)
        throws NotFoundException {
    TypedArray arrayAnimator = null;
    TypedArray arrayObjectAnimator = null;

    if (theme != null) {
        arrayAnimator = theme.obtainStyledAttributes(attrs, R.styleable.Animator, 0, 0);
    } else {
        arrayAnimator = res.obtainAttributes(attrs, R.styleable.Animator);
    }

    // If anim is not null, then it is an object animator.
    if (anim != null) {
        if (theme != null) {
            arrayObjectAnimator = theme.obtainStyledAttributes(attrs,
                    R.styleable.PropertyAnimator, 0, 0);
        } else {
            arrayObjectAnimator = res.obtainAttributes(attrs, R.styleable.PropertyAnimator);
        }
        anim.appendChangingConfigurations(arrayObjectAnimator.getChangingConfigurations());
    }

    if (anim == null) {
        anim = new ValueAnimator();
    }
    anim.appendChangingConfigurations(arrayAnimator.getChangingConfigurations());

    parseAnimatorFromTypeArray(anim, arrayAnimator, arrayObjectAnimator, pathErrorScale);

    final int resID = arrayAnimator.getResourceId(R.styleable.Animator_interpolator, 0);
    if (resID > 0) {
        final Interpolator interpolator = AnimationUtils.loadInterpolator(res, theme, resID);
        if (interpolator instanceof BaseInterpolator) {
            anim.appendChangingConfigurations(
                    ((BaseInterpolator) interpolator).getChangingConfiguration());
        }
        anim.setInterpolator(interpolator);
    }

    arrayAnimator.recycle();
    if (arrayObjectAnimator != null) {
        arrayObjectAnimator.recycle();
    }
    return anim;
}
 
Example 17
Source File: DrawableCompat.java    From ElasticProgressBar with Apache License 2.0 4 votes vote down vote up
protected static TypedArray obtainAttributes(Resources res, Resources.Theme theme, AttributeSet set, int[] attrs) {
    if (theme == null) {
        return res.obtainAttributes(set, attrs);
    }
    return theme.obtainStyledAttributes(set, attrs, 0, 0);
}
 
Example 18
Source File: DynamicApkParser.java    From Android-plugin-support with MIT License 4 votes vote down vote up
private Permission parsePermissionTree(DynamicApkInfo owner, Resources res,
                                       XmlPullParser parser, AttributeSet attrs, String[] outError)
        throws XmlPullParserException, IOException {
    Permission perm = new Permission(owner);

    TypedArray sa = res.obtainAttributes(attrs,
            Hooks.getStyleableArray("AndroidManifestPermissionTree"));

    if (!parsePackageItemInfo(owner, perm.info, outError,
            "<permission-tree>", sa,
            Hooks.getStyleable("AndroidManifestPermissionTree_name"),
            Hooks.getStyleable("AndroidManifestPermissionTree_label"),
            Hooks.getStyleable("AndroidManifestPermissionTree_icon"),
            Hooks.getStyleable("AndroidManifestPermissionTree_logo"),
            Hooks.getStyleable("AndroidManifestPermissionTree_banner"))) {
        sa.recycle();
        mParseError = INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
        return null;
    }

    sa.recycle();

    int index = perm.info.name.indexOf('.');
    if (index > 0) {
        index = perm.info.name.indexOf('.', index+1);
    }
    if (index < 0) {
        outError[0] = "<permission-tree> name has less than three segments: "
                + perm.info.name;
        mParseError = INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
        return null;
    }

    perm.info.descriptionRes = 0;
    perm.info.protectionLevel = PermissionInfo.PROTECTION_NORMAL;
    perm.tree = true;

    if (!parseAllMetaData(res, parser, attrs, "<permission-tree>", perm,
            outError)) {
        mParseError = INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
        return null;
    }

    owner.permissions.add(perm);

    return perm;
}
 
Example 19
Source File: PackageParser.java    From AndroidComponentPlugin with Apache License 2.0 4 votes vote down vote up
private Permission parsePermissionTree(Package owner, Resources res,
        XmlPullParser parser, AttributeSet attrs, String[] outError)
    throws XmlPullParserException, IOException {
    Permission perm = new Permission(owner);

    TypedArray sa = res.obtainAttributes(attrs,
            com.android.internal.R.styleable.AndroidManifestPermissionTree);

    if (!parsePackageItemInfo(owner, perm.info, outError,
            "<permission-tree>", sa,
            com.android.internal.R.styleable.AndroidManifestPermissionTree_name,
            com.android.internal.R.styleable.AndroidManifestPermissionTree_label,
            com.android.internal.R.styleable.AndroidManifestPermissionTree_icon,
            com.android.internal.R.styleable.AndroidManifestPermissionTree_logo)) {
        sa.recycle();
        mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
        return null;
    }

    sa.recycle();
    
    int index = perm.info.name.indexOf('.');
    if (index > 0) {
        index = perm.info.name.indexOf('.', index+1);
    }
    if (index < 0) {
        outError[0] = "<permission-tree> name has less than three segments: "
            + perm.info.name;
        mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
        return null;
    }

    perm.info.descriptionRes = 0;
    perm.info.protectionLevel = PermissionInfo.PROTECTION_NORMAL;
    perm.tree = true;

    if (!parseAllMetaData(res, parser, attrs, "<permission-tree>", perm,
            outError)) {
        mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
        return null;
    }

    owner.permissions.add(perm);

    return perm;
}
 
Example 20
Source File: PackageParser.java    From AndroidComponentPlugin with Apache License 2.0 4 votes vote down vote up
private Permission parsePermissionTree(Package owner, Resources res,
        XmlPullParser parser, AttributeSet attrs, String[] outError)
    throws XmlPullParserException, IOException {
    Permission perm = new Permission(owner);

    TypedArray sa = res.obtainAttributes(attrs,
            com.android.internal.R.styleable.AndroidManifestPermissionTree);

    if (!parsePackageItemInfo(owner, perm.info, outError,
            "<permission-tree>", sa,
            com.android.internal.R.styleable.AndroidManifestPermissionTree_name,
            com.android.internal.R.styleable.AndroidManifestPermissionTree_label,
            com.android.internal.R.styleable.AndroidManifestPermissionTree_icon,
            com.android.internal.R.styleable.AndroidManifestPermissionTree_logo)) {
        sa.recycle();
        mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
        return null;
    }

    sa.recycle();
    
    int index = perm.info.name.indexOf('.');
    if (index > 0) {
        index = perm.info.name.indexOf('.', index+1);
    }
    if (index < 0) {
        outError[0] = "<permission-tree> name has less than three segments: "
            + perm.info.name;
        mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
        return null;
    }

    perm.info.descriptionRes = 0;
    perm.info.protectionLevel = PermissionInfo.PROTECTION_NORMAL;
    perm.tree = true;

    if (!parseAllMetaData(res, parser, attrs, "<permission-tree>", perm,
            outError)) {
        mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
        return null;
    }

    owner.permissions.add(perm);

    return perm;
}