Search in sources :

Example 11 with Pair

use of com.android.util.Pair in project platform_frameworks_base by android.

the class BridgeContext method createStyleBasedTypedArray.

// ------------- private new methods
/**
     * Creates a {@link BridgeTypedArray} by filling the values defined by the int[] with the
     * values found in the given style. If no style is specified, the default theme, along with the
     * styles applied to it are used.
     *
     * @see #obtainStyledAttributes(int, int[])
     */
private Pair<BridgeTypedArray, PropertiesMap> createStyleBasedTypedArray(@Nullable StyleResourceValue style, int[] attrs) throws Resources.NotFoundException {
    List<Pair<String, Boolean>> attributes = searchAttrs(attrs);
    BridgeTypedArray ta = Resources_Delegate.newTypeArray(mSystemResources, attrs.length, false);
    PropertiesMap defaultPropMap = new PropertiesMap();
    // for each attribute, get its name so that we can search it in the style
    for (int i = 0; i < attrs.length; i++) {
        Pair<String, Boolean> attribute = attributes.get(i);
        if (attribute != null) {
            // look for the value in the given style
            ResourceValue resValue;
            String attrName = attribute.getFirst();
            boolean frameworkAttr = attribute.getSecond();
            if (style != null) {
                resValue = mRenderResources.findItemInStyle(style, attrName, frameworkAttr);
            } else {
                resValue = mRenderResources.findItemInTheme(attrName, frameworkAttr);
            }
            if (resValue != null) {
                // Add it to defaultPropMap before resolving
                String preResolve = resValue.getValue();
                // resolve it to make sure there are no references left.
                resValue = mRenderResources.resolveResValue(resValue);
                ta.bridgeSetValue(i, attrName, frameworkAttr, resValue);
                defaultPropMap.put(frameworkAttr ? SdkConstants.ANDROID_PREFIX + attrName : attrName, new Property(preResolve, resValue.getValue()));
            }
        }
    }
    ta.sealArray();
    return Pair.of(ta, defaultPropMap);
}
Also used : StyleResourceValue(com.android.ide.common.rendering.api.StyleResourceValue) ResourceValue(com.android.ide.common.rendering.api.ResourceValue) BridgeTypedArray(android.content.res.BridgeTypedArray) PropertiesMap(com.android.util.PropertiesMap) Property(com.android.util.PropertiesMap.Property) Pair(com.android.util.Pair)

Example 12 with Pair

use of com.android.util.Pair in project android_frameworks_base by AOSPA.

the class BridgeContext method createStyleBasedTypedArray.

// ------------- private new methods
/**
     * Creates a {@link BridgeTypedArray} by filling the values defined by the int[] with the
     * values found in the given style. If no style is specified, the default theme, along with the
     * styles applied to it are used.
     *
     * @see #obtainStyledAttributes(int, int[])
     */
private Pair<BridgeTypedArray, PropertiesMap> createStyleBasedTypedArray(@Nullable StyleResourceValue style, int[] attrs) throws Resources.NotFoundException {
    List<Pair<String, Boolean>> attributes = searchAttrs(attrs);
    BridgeTypedArray ta = Resources_Delegate.newTypeArray(mSystemResources, attrs.length, false);
    PropertiesMap defaultPropMap = new PropertiesMap();
    // for each attribute, get its name so that we can search it in the style
    for (int i = 0; i < attrs.length; i++) {
        Pair<String, Boolean> attribute = attributes.get(i);
        if (attribute != null) {
            // look for the value in the given style
            ResourceValue resValue;
            String attrName = attribute.getFirst();
            boolean frameworkAttr = attribute.getSecond();
            if (style != null) {
                resValue = mRenderResources.findItemInStyle(style, attrName, frameworkAttr);
            } else {
                resValue = mRenderResources.findItemInTheme(attrName, frameworkAttr);
            }
            if (resValue != null) {
                // Add it to defaultPropMap before resolving
                String preResolve = resValue.getValue();
                // resolve it to make sure there are no references left.
                resValue = mRenderResources.resolveResValue(resValue);
                ta.bridgeSetValue(i, attrName, frameworkAttr, resValue);
                defaultPropMap.put(frameworkAttr ? SdkConstants.ANDROID_PREFIX + attrName : attrName, new Property(preResolve, resValue.getValue()));
            }
        }
    }
    ta.sealArray();
    return Pair.of(ta, defaultPropMap);
}
Also used : StyleResourceValue(com.android.ide.common.rendering.api.StyleResourceValue) ResourceValue(com.android.ide.common.rendering.api.ResourceValue) BridgeTypedArray(android.content.res.BridgeTypedArray) PropertiesMap(com.android.util.PropertiesMap) Property(com.android.util.PropertiesMap.Property) Pair(com.android.util.Pair)

Example 13 with Pair

use of com.android.util.Pair in project android_frameworks_base by crdroidandroid.

the class BridgeContext method createStyleBasedTypedArray.

// ------------- private new methods
/**
     * Creates a {@link BridgeTypedArray} by filling the values defined by the int[] with the
     * values found in the given style. If no style is specified, the default theme, along with the
     * styles applied to it are used.
     *
     * @see #obtainStyledAttributes(int, int[])
     */
private Pair<BridgeTypedArray, PropertiesMap> createStyleBasedTypedArray(@Nullable StyleResourceValue style, int[] attrs) throws Resources.NotFoundException {
    List<Pair<String, Boolean>> attributes = searchAttrs(attrs);
    BridgeTypedArray ta = Resources_Delegate.newTypeArray(mSystemResources, attrs.length, false);
    PropertiesMap defaultPropMap = new PropertiesMap();
    // for each attribute, get its name so that we can search it in the style
    for (int i = 0; i < attrs.length; i++) {
        Pair<String, Boolean> attribute = attributes.get(i);
        if (attribute != null) {
            // look for the value in the given style
            ResourceValue resValue;
            String attrName = attribute.getFirst();
            boolean frameworkAttr = attribute.getSecond();
            if (style != null) {
                resValue = mRenderResources.findItemInStyle(style, attrName, frameworkAttr);
            } else {
                resValue = mRenderResources.findItemInTheme(attrName, frameworkAttr);
            }
            if (resValue != null) {
                // Add it to defaultPropMap before resolving
                String preResolve = resValue.getValue();
                // resolve it to make sure there are no references left.
                resValue = mRenderResources.resolveResValue(resValue);
                ta.bridgeSetValue(i, attrName, frameworkAttr, resValue);
                defaultPropMap.put(frameworkAttr ? SdkConstants.ANDROID_PREFIX + attrName : attrName, new Property(preResolve, resValue.getValue()));
            }
        }
    }
    ta.sealArray();
    return Pair.of(ta, defaultPropMap);
}
Also used : StyleResourceValue(com.android.ide.common.rendering.api.StyleResourceValue) ResourceValue(com.android.ide.common.rendering.api.ResourceValue) BridgeTypedArray(android.content.res.BridgeTypedArray) PropertiesMap(com.android.util.PropertiesMap) Property(com.android.util.PropertiesMap.Property) Pair(com.android.util.Pair)

Aggregations

Pair (com.android.util.Pair)13 BridgeTypedArray (android.content.res.BridgeTypedArray)12 ResourceValue (com.android.ide.common.rendering.api.ResourceValue)12 StyleResourceValue (com.android.ide.common.rendering.api.StyleResourceValue)12 PropertiesMap (com.android.util.PropertiesMap)10 Property (com.android.util.PropertiesMap.Property)10 BridgeResources (android.content.res.BridgeResources)2 VisibleForTesting (com.android.annotations.VisibleForTesting)1 IntArrayWrapper (com.android.ide.common.resources.IntArrayWrapper)1 ResourceType (com.android.resources.ResourceType)1 AppResourceRepository (com.android.tools.idea.res.AppResourceRepository)1 TIntObjectHashMap (gnu.trove.TIntObjectHashMap)1 TObjectIntHashMap (gnu.trove.TObjectIntHashMap)1 EnumMap (java.util.EnumMap)1 HashMap (java.util.HashMap)1