Search in sources :

Example 21 with ResourceReference

use of com.android.ide.common.rendering.api.ResourceReference in project android_frameworks_base by AOSPA.

the class FakeExpandableAdapter method createItems.

private void createItems(Iterable<DataBindingItem> iterable, final int itemCount, final int repeatCount, List<ResourceReference> types, int depth) {
    // Need an array to count for each type.
    // This is likely too big, but is the max it can be.
    int[] typeCount = new int[itemCount];
    // we put several repeating sets.
    for (int r = 0; r < repeatCount; r++) {
        // loop on the type of list items, and add however many for each type.
        for (DataBindingItem dataBindingItem : iterable) {
            ResourceReference viewRef = dataBindingItem.getViewReference();
            int typeIndex = types.indexOf(viewRef);
            if (typeIndex == -1) {
                typeIndex = types.size();
                types.add(viewRef);
            }
            List<DataBindingItem> children = dataBindingItem.getChildren();
            int count = dataBindingItem.getCount();
            // if there are children, we use the count as a repeat count for the children.
            if (children.size() > 0) {
                count = 1;
            }
            int index = typeCount[typeIndex];
            typeCount[typeIndex] += count;
            for (int k = 0; k < count; k++) {
                AdapterItem item = new AdapterItem(dataBindingItem, typeIndex, mItems.size(), index++);
                mItems.add(item);
                if (children.size() > 0) {
                    createItems(dataBindingItem, depth + 1);
                }
            }
        }
    }
}
Also used : DataBindingItem(com.android.ide.common.rendering.api.DataBindingItem) ResourceReference(com.android.ide.common.rendering.api.ResourceReference)

Example 22 with ResourceReference

use of com.android.ide.common.rendering.api.ResourceReference in project android_frameworks_base by AOSPA.

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)

Example 23 with ResourceReference

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

the class Resources_Theme_Delegate method resolveStyle.

@Nullable
private static StyleResourceValue resolveStyle(int nativeResid) {
    if (nativeResid == 0) {
        return null;
    }
    BridgeContext context = RenderSessionImpl.getCurrentContext();
    ResourceReference theme = context.resolveId(nativeResid);
    if (theme.isFramework()) {
        return (StyleResourceValue) context.getRenderResources().getFrameworkResource(ResourceType.STYLE, theme.getName());
    } else {
        return (StyleResourceValue) context.getRenderResources().getProjectResource(ResourceType.STYLE, theme.getName());
    }
}
Also used : StyleResourceValue(com.android.ide.common.rendering.api.StyleResourceValue) BridgeContext(com.android.layoutlib.bridge.android.BridgeContext) ResourceReference(com.android.ide.common.rendering.api.ResourceReference) Nullable(android.annotation.Nullable)

Example 24 with ResourceReference

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

the class FakeExpandableAdapter method createItems.

private void createItems(Iterable<DataBindingItem> iterable, final int itemCount, final int repeatCount, List<ResourceReference> types, int depth) {
    // Need an array to count for each type.
    // This is likely too big, but is the max it can be.
    int[] typeCount = new int[itemCount];
    // we put several repeating sets.
    for (int r = 0; r < repeatCount; r++) {
        // loop on the type of list items, and add however many for each type.
        for (DataBindingItem dataBindingItem : iterable) {
            ResourceReference viewRef = dataBindingItem.getViewReference();
            int typeIndex = types.indexOf(viewRef);
            if (typeIndex == -1) {
                typeIndex = types.size();
                types.add(viewRef);
            }
            List<DataBindingItem> children = dataBindingItem.getChildren();
            int count = dataBindingItem.getCount();
            // if there are children, we use the count as a repeat count for the children.
            if (children.size() > 0) {
                count = 1;
            }
            int index = typeCount[typeIndex];
            typeCount[typeIndex] += count;
            for (int k = 0; k < count; k++) {
                AdapterItem item = new AdapterItem(dataBindingItem, typeIndex, mItems.size(), index++);
                mItems.add(item);
                if (children.size() > 0) {
                    createItems(dataBindingItem, depth + 1);
                }
            }
        }
    }
}
Also used : DataBindingItem(com.android.ide.common.rendering.api.DataBindingItem) ResourceReference(com.android.ide.common.rendering.api.ResourceReference)

Example 25 with ResourceReference

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

the class AdapterHelper method fillView.

private static void fillView(BridgeContext context, View view, AdapterItem item, AdapterItem parentItem, LayoutlibCallback callback, ResourceReference adapterRef) {
    if (view instanceof ViewGroup) {
        ViewGroup group = (ViewGroup) view;
        final int count = group.getChildCount();
        for (int i = 0; i < count; i++) {
            fillView(context, group.getChildAt(i), item, parentItem, callback, adapterRef);
        }
    } else {
        int id = view.getId();
        if (id != 0) {
            ResourceReference resolvedRef = context.resolveId(id);
            if (resolvedRef != null) {
                int fullPosition = item.getFullPosition();
                int positionPerType = item.getPositionPerType();
                int fullParentPosition = parentItem != null ? parentItem.getFullPosition() : 0;
                int parentPositionPerType = parentItem != null ? parentItem.getPositionPerType() : 0;
                if (view instanceof TextView) {
                    TextView tv = (TextView) view;
                    Object value = callback.getAdapterItemValue(adapterRef, context.getViewKey(view), item.getDataBindingItem().getViewReference(), fullPosition, positionPerType, fullParentPosition, parentPositionPerType, resolvedRef, ViewAttribute.TEXT, tv.getText().toString());
                    if (value != null) {
                        if (value.getClass() != ViewAttribute.TEXT.getAttributeClass()) {
                            Bridge.getLog().error(LayoutLog.TAG_BROKEN, String.format("Wrong Adapter Item value class for TEXT. Expected String, got %s", value.getClass().getName()), null);
                        } else {
                            tv.setText((String) value);
                        }
                    }
                }
                if (view instanceof Checkable) {
                    Checkable cb = (Checkable) view;
                    Object value = callback.getAdapterItemValue(adapterRef, context.getViewKey(view), item.getDataBindingItem().getViewReference(), fullPosition, positionPerType, fullParentPosition, parentPositionPerType, resolvedRef, ViewAttribute.IS_CHECKED, cb.isChecked());
                    if (value != null) {
                        if (value.getClass() != ViewAttribute.IS_CHECKED.getAttributeClass()) {
                            Bridge.getLog().error(LayoutLog.TAG_BROKEN, String.format("Wrong Adapter Item value class for IS_CHECKED. Expected Boolean, got %s", value.getClass().getName()), null);
                        } else {
                            cb.setChecked((Boolean) value);
                        }
                    }
                }
                if (view instanceof ImageView) {
                    ImageView iv = (ImageView) view;
                    Object value = callback.getAdapterItemValue(adapterRef, context.getViewKey(view), item.getDataBindingItem().getViewReference(), fullPosition, positionPerType, fullParentPosition, parentPositionPerType, resolvedRef, ViewAttribute.SRC, iv.getDrawable());
                    if (value != null) {
                        if (value.getClass() != ViewAttribute.SRC.getAttributeClass()) {
                            Bridge.getLog().error(LayoutLog.TAG_BROKEN, String.format("Wrong Adapter Item value class for SRC. Expected Boolean, got %s", value.getClass().getName()), null);
                        } else {
                        // FIXME
                        }
                    }
                }
            }
        }
    }
}
Also used : ViewGroup(android.view.ViewGroup) TextView(android.widget.TextView) ResourceReference(com.android.ide.common.rendering.api.ResourceReference) Checkable(android.widget.Checkable) ImageView(android.widget.ImageView)

Aggregations

ResourceReference (com.android.ide.common.rendering.api.ResourceReference)28 ViewGroup (android.view.ViewGroup)12 BridgeContext (com.android.layoutlib.bridge.android.BridgeContext)10 StyleResourceValue (com.android.ide.common.rendering.api.StyleResourceValue)9 AdapterBinding (com.android.ide.common.rendering.api.AdapterBinding)7 DataBindingItem (com.android.ide.common.rendering.api.DataBindingItem)7 View (android.view.View)6 AbsListView (android.widget.AbsListView)6 AbsSpinner (android.widget.AbsSpinner)6 AdapterView (android.widget.AdapterView)6 Checkable (android.widget.Checkable)6 ExpandableListView (android.widget.ExpandableListView)6 ImageView (android.widget.ImageView)6 ListView (android.widget.ListView)6 QuickContactBadge (android.widget.QuickContactBadge)6 TabHost (android.widget.TabHost)6 TextView (android.widget.TextView)6 SessionParams (com.android.ide.common.rendering.api.SessionParams)6 FakeAdapter (com.android.layoutlib.bridge.impl.binding.FakeAdapter)6 FakeExpandableAdapter (com.android.layoutlib.bridge.impl.binding.FakeExpandableAdapter)6