FileDocCategorySizeDatePackage
AdapterHelper.javaAPI DocAndroid 5.1 API7090Thu Mar 12 22:22:44 GMT 2015com.android.layoutlib.bridge.impl.binding

AdapterHelper

public class AdapterHelper extends Object
A Helper class to do fake data binding in {@link AdapterView} objects.

Fields Summary
Constructors Summary
Methods Summary
private static voidfillView(com.android.layoutlib.bridge.android.BridgeContext context, android.view.View view, AdapterItem item, AdapterItem parentItem, com.android.ide.common.rendering.api.IProjectCallback callback, com.android.ide.common.rendering.api.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 TEXT. 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 TEXT. Expected Boolean, got %s",
                                        value.getClass().getName()), null);
                            } else {
                                // FIXME
                            }
                        }
                    }
                }
            }
        }
    
static com.android.util.PairgetView(AdapterItem item, AdapterItem parentItem, android.view.ViewGroup parent, com.android.ide.common.rendering.api.IProjectCallback callback, com.android.ide.common.rendering.api.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);