Search in sources :

Example 11 with DataBindingItem

use of com.android.ide.common.rendering.api.DataBindingItem in project android_frameworks_base by DirtyUnicorns.

the class AdapterHelper method getView.

@SuppressWarnings("deprecation")
static Pair<View, Boolean> getView(AdapterItem item, AdapterItem parentItem, ViewGroup parent, LayoutlibCallback callback, ResourceReference adapterRef, boolean skipCallbackParser) {
    // we don't care about recycling here because we never scroll.
    DataBindingItem dataBindingItem = item.getDataBindingItem();
    BridgeContext context = RenderAction.getCurrentContext();
    Pair<View, Boolean> pair = context.inflateView(dataBindingItem.getViewReference(), parent, false, /*attachToRoot*/
    skipCallbackParser);
    View view = pair.getFirst();
    skipCallbackParser |= pair.getSecond();
    if (view != null) {
        fillView(context, view, item, parentItem, callback, adapterRef);
    } else {
        // create a text view to display an error.
        TextView tv = new TextView(context);
        tv.setText("Unable to find layout: " + dataBindingItem.getViewReference().getName());
        view = tv;
    }
    return Pair.of(view, skipCallbackParser);
}
Also used : BridgeContext(com.android.layoutlib.bridge.android.BridgeContext) DataBindingItem(com.android.ide.common.rendering.api.DataBindingItem) TextView(android.widget.TextView) ImageView(android.widget.ImageView) TextView(android.widget.TextView) View(android.view.View) AdapterView(android.widget.AdapterView)

Example 12 with DataBindingItem

use of com.android.ide.common.rendering.api.DataBindingItem in project android_frameworks_base by DirtyUnicorns.

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 13 with DataBindingItem

use of com.android.ide.common.rendering.api.DataBindingItem 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)

Aggregations

DataBindingItem (com.android.ide.common.rendering.api.DataBindingItem)13 ResourceReference (com.android.ide.common.rendering.api.ResourceReference)7 View (android.view.View)6 AdapterView (android.widget.AdapterView)6 ImageView (android.widget.ImageView)6 TextView (android.widget.TextView)6 BridgeContext (com.android.layoutlib.bridge.android.BridgeContext)6 Nullable (com.android.annotations.Nullable)1 AdapterBinding (com.android.ide.common.rendering.api.AdapterBinding)1