Search in sources :

Example 6 with AttrResourceValue

use of com.android.ide.common.rendering.api.AttrResourceValue in project android_frameworks_base by ResurrectionRemix.

the class BridgeTypedArray method resolveEnumAttribute.

/**
     * Searches for the string in the attributes (flag or enums) and returns the integer.
     * If found, it will return an integer matching the value.
     *
     * @param index Index of attribute to retrieve.
     *
     * @return Attribute int value, or null if not defined.
     */
private Integer resolveEnumAttribute(int index) {
    // Get the map of attribute-constant -> IntegerValue
    Map<String, Integer> map = null;
    if (mIsFramework[index]) {
        map = Bridge.getEnumValues(mNames[index]);
    } else {
        // get the styleable matching the resolved name
        RenderResources res = mContext.getRenderResources();
        ResourceValue attr = res.getProjectResource(ResourceType.ATTR, mNames[index]);
        if (attr instanceof AttrResourceValue) {
            map = ((AttrResourceValue) attr).getAttributeValues();
        }
    }
    if (map != null) {
        // accumulator to store the value of the 1+ constants.
        int result = 0;
        boolean found = false;
        // split the value in case this is a mix of several flags.
        String[] keywords = mResourceData[index].getValue().split("\\|");
        for (String keyword : keywords) {
            Integer i = map.get(keyword.trim());
            if (i != null) {
                result |= i;
                found = true;
            }
        // TODO: We should act smartly and log a warning for incorrect keywords. However,
        // this method is currently called even if the resourceValue is not an enum.
        }
        if (found) {
            return result;
        }
    }
    return null;
}
Also used : AttrResourceValue(com.android.ide.common.rendering.api.AttrResourceValue) RenderResources(com.android.ide.common.rendering.api.RenderResources) StyleResourceValue(com.android.ide.common.rendering.api.StyleResourceValue) ResourceValue(com.android.ide.common.rendering.api.ResourceValue) AttrResourceValue(com.android.ide.common.rendering.api.AttrResourceValue) ArrayResourceValue(com.android.ide.common.rendering.api.ArrayResourceValue)

Example 7 with AttrResourceValue

use of com.android.ide.common.rendering.api.AttrResourceValue in project android_frameworks_base by crdroidandroid.

the class BridgeTypedArray method resolveEnumAttribute.

/**
     * Searches for the string in the attributes (flag or enums) and returns the integer.
     * If found, it will return an integer matching the value.
     *
     * @param index Index of attribute to retrieve.
     *
     * @return Attribute int value, or null if not defined.
     */
private Integer resolveEnumAttribute(int index) {
    // Get the map of attribute-constant -> IntegerValue
    Map<String, Integer> map = null;
    if (mIsFramework[index]) {
        map = Bridge.getEnumValues(mNames[index]);
    } else {
        // get the styleable matching the resolved name
        RenderResources res = mContext.getRenderResources();
        ResourceValue attr = res.getProjectResource(ResourceType.ATTR, mNames[index]);
        if (attr instanceof AttrResourceValue) {
            map = ((AttrResourceValue) attr).getAttributeValues();
        }
    }
    if (map != null) {
        // accumulator to store the value of the 1+ constants.
        int result = 0;
        boolean found = false;
        // split the value in case this is a mix of several flags.
        String[] keywords = mResourceData[index].getValue().split("\\|");
        for (String keyword : keywords) {
            Integer i = map.get(keyword.trim());
            if (i != null) {
                result |= i;
                found = true;
            }
        // TODO: We should act smartly and log a warning for incorrect keywords. However,
        // this method is currently called even if the resourceValue is not an enum.
        }
        if (found) {
            return result;
        }
    }
    return null;
}
Also used : AttrResourceValue(com.android.ide.common.rendering.api.AttrResourceValue) RenderResources(com.android.ide.common.rendering.api.RenderResources) StyleResourceValue(com.android.ide.common.rendering.api.StyleResourceValue) ResourceValue(com.android.ide.common.rendering.api.ResourceValue) AttrResourceValue(com.android.ide.common.rendering.api.AttrResourceValue) ArrayResourceValue(com.android.ide.common.rendering.api.ArrayResourceValue)

Aggregations

AttrResourceValue (com.android.ide.common.rendering.api.AttrResourceValue)7 ResourceValue (com.android.ide.common.rendering.api.ResourceValue)6 RenderResources (com.android.ide.common.rendering.api.RenderResources)5 StyleResourceValue (com.android.ide.common.rendering.api.StyleResourceValue)5 ArrayResourceValue (com.android.ide.common.rendering.api.ArrayResourceValue)4 DeclareStyleableResourceValue (com.android.ide.common.rendering.api.DeclareStyleableResourceValue)1 ResourceItem (com.android.ide.common.res2.ResourceItem)1 ImmutableList (com.google.common.collect.ImmutableList)1 MethodVisitor (org.jetbrains.org.objectweb.asm.MethodVisitor)1