Search in sources :

Example 16 with PropertiesMap

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

the class BridgeContext method obtainStyledAttributes.

@Override
public final BridgeTypedArray obtainStyledAttributes(int resId, int[] attrs) throws Resources.NotFoundException {
    StyleResourceValue style = null;
    // get the StyleResourceValue based on the resId;
    if (resId != 0) {
        style = getStyleByDynamicId(resId);
        if (style == null) {
            // In some cases, style may not be a dynamic id, so we do a full search.
            ResourceReference ref = resolveId(resId);
            if (ref != null) {
                style = mRenderResources.getStyle(ref.getName(), ref.isFramework());
            }
        }
        if (style == null) {
            throw new Resources.NotFoundException();
        }
    }
    if (mTypedArrayCache == null) {
        mTypedArrayCache = new TypedArrayCache();
    }
    List<StyleResourceValue> currentThemes = mRenderResources.getAllThemes();
    Pair<BridgeTypedArray, PropertiesMap> typeArrayAndPropertiesPair = mTypedArrayCache.get(attrs, currentThemes, resId);
    if (typeArrayAndPropertiesPair == null) {
        typeArrayAndPropertiesPair = createStyleBasedTypedArray(style, attrs);
        mTypedArrayCache.put(attrs, currentThemes, resId, typeArrayAndPropertiesPair);
    }
    // Add value to defaultPropsMap if needed
    if (typeArrayAndPropertiesPair.getSecond() != null) {
        BridgeXmlBlockParser parser = getCurrentParser();
        Object key = parser != null ? parser.getViewCookie() : null;
        if (key != null) {
            PropertiesMap defaultPropMap = mDefaultPropMaps.get(key);
            if (defaultPropMap == null) {
                defaultPropMap = typeArrayAndPropertiesPair.getSecond();
                mDefaultPropMaps.put(key, defaultPropMap);
            } else {
                defaultPropMap.putAll(typeArrayAndPropertiesPair.getSecond());
            }
        }
    }
    return typeArrayAndPropertiesPair.getFirst();
}
Also used : StyleResourceValue(com.android.ide.common.rendering.api.StyleResourceValue) FileNotFoundException(java.io.FileNotFoundException) ResourceReference(com.android.ide.common.rendering.api.ResourceReference) BridgeTypedArray(android.content.res.BridgeTypedArray) PropertiesMap(com.android.util.PropertiesMap)

Aggregations

PropertiesMap (com.android.util.PropertiesMap)16 BridgeTypedArray (android.content.res.BridgeTypedArray)15 StyleResourceValue (com.android.ide.common.rendering.api.StyleResourceValue)15 ResourceValue (com.android.ide.common.rendering.api.ResourceValue)10 Pair (com.android.util.Pair)10 Property (com.android.util.PropertiesMap.Property)10 ResourceReference (com.android.ide.common.rendering.api.ResourceReference)5 FileNotFoundException (java.io.FileNotFoundException)5 NlComponent (com.android.tools.idea.uibuilder.model.NlComponent)1 ScreenView (com.android.tools.idea.uibuilder.surface.ScreenView)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 NotNull (org.jetbrains.annotations.NotNull)1