Search in sources :

Example 1 with WXImage

use of com.taobao.weex.ui.component.WXImage in project weex-example by KalicyZhou.

the class WXImageView method setImageDrawable.

public void setImageDrawable(@Nullable Drawable drawable, boolean isGif) {
    this.gif = isGif;
    ViewGroup.LayoutParams layoutParams;
    if ((layoutParams = getLayoutParams()) != null) {
        Drawable wrapDrawable = ImageDrawable.createImageDrawable(drawable, getScaleType(), borderRadius, layoutParams.width - getPaddingLeft() - getPaddingRight(), layoutParams.height - getPaddingTop() - getPaddingBottom(), isGif);
        if (wrapDrawable instanceof ImageDrawable) {
            ImageDrawable imageDrawable = (ImageDrawable) wrapDrawable;
            if (!Arrays.equals(imageDrawable.getCornerRadii(), borderRadius)) {
                imageDrawable.setCornerRadii(borderRadius);
            }
        }
        super.setImageDrawable(wrapDrawable);
        if (mWeakReference != null) {
            WXImage component = mWeakReference.get();
            if (component != null) {
                component.readyToRender();
            }
        }
    }
}
Also used : ImageDrawable(com.taobao.weex.utils.ImageDrawable) ViewGroup(android.view.ViewGroup) BitmapDrawable(android.graphics.drawable.BitmapDrawable) ImageDrawable(com.taobao.weex.utils.ImageDrawable) Drawable(android.graphics.drawable.Drawable) WXImage(com.taobao.weex.ui.component.WXImage)

Example 2 with WXImage

use of com.taobao.weex.ui.component.WXImage in project incubator-weex by apache.

the class WXImageView method setImageDrawable.

public void setImageDrawable(@Nullable Drawable drawable, boolean isGif) {
    this.gif = isGif;
    ViewGroup.LayoutParams layoutParams;
    if ((layoutParams = getLayoutParams()) != null) {
        Drawable wrapDrawable = ImageDrawable.createImageDrawable(drawable, getScaleType(), borderRadius, layoutParams.width - getPaddingLeft() - getPaddingRight(), layoutParams.height - getPaddingTop() - getPaddingBottom(), isGif);
        if (wrapDrawable instanceof ImageDrawable) {
            ImageDrawable imageDrawable = (ImageDrawable) wrapDrawable;
            if (!Arrays.equals(imageDrawable.getCornerRadii(), borderRadius)) {
                imageDrawable.setCornerRadii(borderRadius);
            }
        }
        super.setImageDrawable(wrapDrawable);
        if (mWeakReference != null) {
            WXImage component = mWeakReference.get();
            if (component != null) {
                component.readyToRender();
            }
        }
    }
}
Also used : ImageDrawable(com.taobao.weex.utils.ImageDrawable) ViewGroup(android.view.ViewGroup) BitmapDrawable(android.graphics.drawable.BitmapDrawable) ImageDrawable(com.taobao.weex.utils.ImageDrawable) Drawable(android.graphics.drawable.Drawable) WXImage(com.taobao.weex.ui.component.WXImage)

Example 3 with WXImage

use of com.taobao.weex.ui.component.WXImage in project incubator-weex by apache.

the class WXImageView method autoRecoverImage.

public void autoRecoverImage() {
    if (enableBitmapAutoManage) {
        if (isBitmapReleased) {
            WXImage image = getComponent();
            if (image != null) {
                image.autoRecoverImage();
            }
            isBitmapReleased = false;
        }
    }
}
Also used : WXImage(com.taobao.weex.ui.component.WXImage)

Example 4 with WXImage

use of com.taobao.weex.ui.component.WXImage in project WeexErosFramework by bmfe.

the class DefaultWXImageAdapter method handleError.

private void handleError(WXImageView imageView) {
    WXImage component = imageView.getComponent();
    if (component == null)
        return;
    ImmutableDomObject domObject = component.getDomObject();
    if (domObject == null)
        return;
    Bitmap bitmap = getErrorBitmap(imageView.getContext());
    if (domObject.getLayoutWidth() > 0 && domObject.getLayoutHeight() > 0) {
        int target = Math.min((int) (domObject.getLayoutWidth()), (int) (domObject.getLayoutHeight())) / 2;
        Bitmap zoomBitmap = ImageUtil.zoomImage(bitmap, target, target);
        if (zoomBitmap != null) {
            imageView.drawErrorBitmap(zoomBitmap);
        }
    }
}
Also used : Bitmap(android.graphics.Bitmap) ImmutableDomObject(com.taobao.weex.dom.ImmutableDomObject) WXImage(com.taobao.weex.ui.component.WXImage)

Example 5 with WXImage

use of com.taobao.weex.ui.component.WXImage in project incubator-weex by apache.

the class Statements method doRenderBindingAttrsAndEvent.

/**
 * render dynamic binding attrs and bind them to component node.
 */
private static void doRenderBindingAttrsAndEvent(WXComponent component, WXDomObject domObject, CellRenderContext context) {
    ArrayStack stack = context.stack;
    component.setWaste(false);
    WXAttr attr = domObject.getAttrs();
    if (attr != null && attr.getBindingAttrs() != null && attr.getBindingAttrs().size() > 0) {
        ArrayMap<String, Object> bindAttrs = domObject.getAttrs().getBindingAttrs();
        Map<String, Object> dynamic = renderBindingAttrs(bindAttrs, stack);
        Set<Map.Entry<String, Object>> entries = dynamic.entrySet();
        /**
         * diff attrs, see attrs has update, remove none update attrs
         */
        Iterator<Map.Entry<String, Object>> iterator = entries.iterator();
        while (iterator.hasNext()) {
            Map.Entry<String, Object> entry = iterator.next();
            String key = entry.getKey();
            Object value = entry.getValue();
            Object oldValue = attr.get(key);
            if (value == null) {
                if (oldValue == null) {
                    iterator.remove();
                    continue;
                }
            } else {
                if (value.equals(oldValue)) {
                    iterator.remove();
                }
            }
        }
        if (dynamic.size() > 0) {
            if (dynamic.size() == 1 && dynamic.get(Constants.Name.SRC) != null && component instanceof WXImage) {
                // for image avoid dirty layout, only update src attrs
                domObject.getAttrs().put(Constants.Name.SRC, dynamic.get(Constants.Name.SRC));
            } else {
                // dirty layout
                domObject.updateAttr(dynamic);
            }
            if (isMainThread()) {
                component.updateProperties(dynamic);
            }
            dynamic.clear();
        }
    }
    WXStyle style = domObject.getStyles();
    if (style != null && style.getBindingStyle() != null) {
        ArrayMap<String, Object> bindStyle = style.getBindingStyle();
        Map<String, Object> dynamic = renderBindingAttrs(bindStyle, stack);
        Set<Map.Entry<String, Object>> entries = dynamic.entrySet();
        /**
         * diff attrs, see attrs has update, remove none update attrs
         */
        Iterator<Map.Entry<String, Object>> iterator = entries.iterator();
        while (iterator.hasNext()) {
            Map.Entry<String, Object> entry = iterator.next();
            String key = entry.getKey();
            Object value = entry.getValue();
            Object oldValue = style.get(key);
            if (value == null) {
                if (oldValue == null) {
                    iterator.remove();
                    continue;
                }
            } else {
                if (value.equals(oldValue)) {
                    iterator.remove();
                }
            }
        }
        if (dynamic.size() > 0) {
            domObject.updateStyle(dynamic, false);
            domObject.applyStyle(dynamic);
            if (isMainThread()) {
                component.updateProperties(dynamic);
            }
        }
    }
    WXEvent event = domObject.getEvents();
    if (event == null || event.getEventBindingArgs() == null) {
        return;
    }
    Set<Map.Entry<String, Object>> eventBindArgsEntrySet = event.getEventBindingArgs().entrySet();
    for (Map.Entry<String, Object> eventBindArgsEntry : eventBindArgsEntrySet) {
        List<Object> values = getBindingEventArgs(stack, eventBindArgsEntry.getValue());
        if (values != null) {
            event.putEventBindingArgsValue(eventBindArgsEntry.getKey(), values);
        }
    }
}
Also used : WXStyle(com.taobao.weex.dom.WXStyle) ArrayStack(com.taobao.weex.el.parse.ArrayStack) WXEvent(com.taobao.weex.dom.WXEvent) WXDomObject(com.taobao.weex.dom.WXDomObject) JSONObject(com.alibaba.fastjson.JSONObject) WXImage(com.taobao.weex.ui.component.WXImage) HashMap(java.util.HashMap) ArrayMap(android.support.v4.util.ArrayMap) Map(java.util.Map) WXAttr(com.taobao.weex.dom.WXAttr)

Aggregations

WXImage (com.taobao.weex.ui.component.WXImage)6 BitmapDrawable (android.graphics.drawable.BitmapDrawable)2 Drawable (android.graphics.drawable.Drawable)2 ViewGroup (android.view.ViewGroup)2 ImageDrawable (com.taobao.weex.utils.ImageDrawable)2 Bitmap (android.graphics.Bitmap)1 ArrayMap (android.support.v4.util.ArrayMap)1 JSONObject (com.alibaba.fastjson.JSONObject)1 ImmutableDomObject (com.taobao.weex.dom.ImmutableDomObject)1 WXAttr (com.taobao.weex.dom.WXAttr)1 WXDomObject (com.taobao.weex.dom.WXDomObject)1 WXEvent (com.taobao.weex.dom.WXEvent)1 WXStyle (com.taobao.weex.dom.WXStyle)1 ArrayStack (com.taobao.weex.el.parse.ArrayStack)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1