Search in sources :

Example 1 with AndroidViewWidget

use of com.taobao.weex.ui.flat.widget.AndroidViewWidget in project incubator-weex by apache.

the class WXComponent method updateProperties.

@Deprecated
public void updateProperties(Map<String, Object> props) {
    if (props == null || (mHost == null && !isVirtualComponent())) {
        return;
    }
    for (Map.Entry<String, Object> entry : props.entrySet()) {
        String key = entry.getKey();
        Object param = entry.getValue();
        String value = WXUtils.getString(param, null);
        if (TextUtils.isEmpty(value)) {
            param = convertEmptyProperty(key, value);
        }
        if (!setProperty(key, param)) {
            if (mHolder == null) {
                return;
            }
            Invoker invoker = mHolder.getPropertyInvoker(key);
            if (invoker != null) {
                try {
                    Type[] paramClazzs = invoker.getParameterTypes();
                    if (paramClazzs.length != 1) {
                        WXLogUtils.e("[WXComponent] setX method only one parameter:" + invoker);
                        return;
                    }
                    param = WXReflectionUtils.parseArgument(paramClazzs[0], param);
                    invoker.invoke(this, param);
                } catch (Exception e) {
                    WXLogUtils.e("[WXComponent] updateProperties :" + "class:" + getClass() + "method:" + invoker.toString() + " function " + WXLogUtils.getStackTrace(e));
                }
            }
        }
    }
    readyToRender();
    if (this instanceof FlatComponent && mBackgroundDrawable != null) {
        FlatComponent flatComponent = (FlatComponent) this;
        if (!flatComponent.promoteToView(true) && !(flatComponent.getOrCreateFlatWidget() instanceof AndroidViewWidget)) {
            flatComponent.getOrCreateFlatWidget().setBackgroundAndBorder(mBackgroundDrawable);
        }
    }
}
Also used : FlatComponent(com.taobao.weex.ui.flat.FlatComponent) Type(java.lang.reflect.Type) ElementType(java.lang.annotation.ElementType) WXGestureType(com.taobao.weex.ui.view.gesture.WXGestureType) Invoker(com.taobao.weex.bridge.Invoker) AndroidViewWidget(com.taobao.weex.ui.flat.widget.AndroidViewWidget) WXDomObject(com.taobao.weex.dom.WXDomObject) JSONObject(com.alibaba.fastjson.JSONObject) IWXObject(com.taobao.weex.common.IWXObject) ImmutableDomObject(com.taobao.weex.dom.ImmutableDomObject) Map(java.util.Map) HashMap(java.util.HashMap) WXRuntimeException(com.taobao.weex.common.WXRuntimeException)

Example 2 with AndroidViewWidget

use of com.taobao.weex.ui.flat.widget.AndroidViewWidget in project incubator-weex by apache.

the class WXComponent method setWidgetParams.

private void setWidgetParams(Widget widget, FlatGUIContext UIImp, Point rawoffset, int width, int height, int left, int right, int top, int bottom) {
    Point childOffset = new Point();
    if (mParent != null) {
        if (mParent instanceof FlatComponent && UIImp.getFlatComponentAncestor(mParent) != null && UIImp.getAndroidViewWidget(mParent) == null) {
            childOffset.set(rawoffset.x, rawoffset.y);
        } else {
            childOffset.set(left, top);
        }
        if (mParent instanceof FlatComponent && UIImp.getFlatComponentAncestor(mParent) != null && UIImp.getAndroidViewWidget(mParent) == null) {
            Point parentLayoutOffset = ((FlatComponent) mParent).getOrCreateFlatWidget().getLocInFlatContainer();
            childOffset.offset(parentLayoutOffset.x, parentLayoutOffset.y);
        }
        ViewGroup.LayoutParams lp = mParent.getChildLayoutParams(this, mHost, width, height, left, right, top, bottom);
        if (lp instanceof MarginLayoutParams) {
            width = lp.width;
            height = lp.height;
            left = ((MarginLayoutParams) lp).leftMargin;
            right = ((MarginLayoutParams) lp).rightMargin;
            top = ((MarginLayoutParams) lp).topMargin;
            bottom = ((MarginLayoutParams) lp).bottomMargin;
        }
    }
    widget.setLayout(width, height, left, right, top, bottom, childOffset);
    if (widget instanceof AndroidViewWidget && ((AndroidViewWidget) widget).getView() != null) {
        // TODO generic method if ever possible
        setHostLayoutParams((T) ((AndroidViewWidget) widget).getView(), width, height, childOffset.x, right, childOffset.y, bottom);
    }
}
Also used : FlatComponent(com.taobao.weex.ui.flat.FlatComponent) ViewGroup(android.view.ViewGroup) AndroidViewWidget(com.taobao.weex.ui.flat.widget.AndroidViewWidget) Point(android.graphics.Point) MarginLayoutParams(android.view.ViewGroup.MarginLayoutParams)

Example 3 with AndroidViewWidget

use of com.taobao.weex.ui.flat.widget.AndroidViewWidget in project incubator-weex by apache.

the class WidgetContainer method createChildViewAt.

@Override
public void createChildViewAt(int index) {
    if (intendToBeFlatContainer()) {
        Pair<WXComponent, Integer> ret = rearrangeIndexAndGetChild(index);
        if (ret.first != null) {
            WXComponent child = ret.first;
            Widget flatChild;
            FlatGUIContext uiImp = getInstance().getFlatUIContext();
            WidgetContainer parent = uiImp.getFlatComponentAncestor(this);
            if (parent == null || uiImp.getAndroidViewWidget(this) != null) {
                parent = this;
            }
            uiImp.register(child, parent);
            if (child instanceof FlatComponent && !((FlatComponent) child).promoteToView(false)) {
                flatChild = ((FlatComponent) child).getOrCreateFlatWidget();
            } else {
                flatChild = new AndroidViewWidget(uiImp);
                uiImp.register(child, (AndroidViewWidget) flatChild);
                child.createView();
                ((AndroidViewWidget) flatChild).setContentView(child.getHostView());
                // TODO Use a sort algorithm to decide the childIndex of AndroidViewWidget
                parent.addSubView(child.getHostView(), -1);
            }
            uiImp.register(flatChild, child);
            addFlatChild(flatChild, ret.second);
        }
    } else {
        super.createChildViewAt(index);
    }
}
Also used : WXComponent(com.taobao.weex.ui.component.WXComponent) Widget(com.taobao.weex.ui.flat.widget.Widget) AndroidViewWidget(com.taobao.weex.ui.flat.widget.AndroidViewWidget) AndroidViewWidget(com.taobao.weex.ui.flat.widget.AndroidViewWidget)

Aggregations

AndroidViewWidget (com.taobao.weex.ui.flat.widget.AndroidViewWidget)3 FlatComponent (com.taobao.weex.ui.flat.FlatComponent)2 Point (android.graphics.Point)1 ViewGroup (android.view.ViewGroup)1 MarginLayoutParams (android.view.ViewGroup.MarginLayoutParams)1 JSONObject (com.alibaba.fastjson.JSONObject)1 Invoker (com.taobao.weex.bridge.Invoker)1 IWXObject (com.taobao.weex.common.IWXObject)1 WXRuntimeException (com.taobao.weex.common.WXRuntimeException)1 ImmutableDomObject (com.taobao.weex.dom.ImmutableDomObject)1 WXDomObject (com.taobao.weex.dom.WXDomObject)1 WXComponent (com.taobao.weex.ui.component.WXComponent)1 Widget (com.taobao.weex.ui.flat.widget.Widget)1 WXGestureType (com.taobao.weex.ui.view.gesture.WXGestureType)1 ElementType (java.lang.annotation.ElementType)1 Type (java.lang.reflect.Type)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1