Search in sources :

Example 1 with ImageDrawable

use of com.taobao.weex.utils.ImageDrawable 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 ImageDrawable

use of com.taobao.weex.utils.ImageDrawable in project weex-example by KalicyZhou.

the class WXImage method setRemoteSrc.

private void setRemoteSrc(Uri rewrited) {
    WXImageStrategy imageStrategy = new WXImageStrategy();
    imageStrategy.isClipping = true;
    WXImageSharpen imageSharpen = getDomObject().getAttrs().getImageSharpen();
    imageStrategy.isSharpen = imageSharpen == WXImageSharpen.SHARPEN;
    int radius = getDomObject().getStyles().getBlur();
    radius = Math.max(0, radius);
    imageStrategy.blurRadius = Math.min(10, radius);
    imageStrategy.setImageListener(new WXImageStrategy.ImageListener() {

        @Override
        public void onImageFinish(String url, ImageView imageView, boolean result, Map extra) {
            if (getDomObject() != null && getDomObject().getEvents().contains(Constants.Event.ONLOAD)) {
                Map<String, Object> params = new HashMap<String, Object>();
                Map<String, Object> size = new HashMap<>(2);
                if (imageView != null && imageView.getDrawable() != null && imageView.getDrawable() instanceof ImageDrawable) {
                    size.put("naturalWidth", ((ImageDrawable) imageView.getDrawable()).getBitmapWidth());
                    size.put("naturalHeight", ((ImageDrawable) imageView.getDrawable()).getBitmapHeight());
                } else {
                    size.put("naturalWidth", 0);
                    size.put("naturalHeight", 0);
                }
                if (getDomObject() != null && containsEvent(Constants.Event.ONLOAD)) {
                    params.put("success", result);
                    params.put("size", size);
                    fireEvent(Constants.Event.ONLOAD, params);
                }
            }
        }
    });
    String placeholder = null;
    if (getDomObject().getAttrs().containsKey(Constants.Name.PLACEHOLDER)) {
        placeholder = (String) getDomObject().getAttrs().get(Constants.Name.PLACEHOLDER);
    } else if (getDomObject().getAttrs().containsKey(Constants.Name.PLACE_HOLDER)) {
        placeholder = (String) getDomObject().getAttrs().get(Constants.Name.PLACE_HOLDER);
    }
    if (placeholder != null) {
        imageStrategy.placeHolder = getInstance().rewriteUri(Uri.parse(placeholder), URIAdapter.IMAGE).toString();
    }
    IWXImgLoaderAdapter imgLoaderAdapter = getInstance().getImgLoaderAdapter();
    if (imgLoaderAdapter != null) {
        imgLoaderAdapter.setImage(rewrited.toString(), getHostView(), getDomObject().getAttrs().getImageQuality(), imageStrategy);
    }
}
Also used : WXImageStrategy(com.taobao.weex.common.WXImageStrategy) ImageDrawable(com.taobao.weex.utils.ImageDrawable) WXImageSharpen(com.taobao.weex.common.WXImageSharpen) WXDomObject(com.taobao.weex.dom.WXDomObject) ImmutableDomObject(com.taobao.weex.dom.ImmutableDomObject) ImageView(android.widget.ImageView) WXImageView(com.taobao.weex.ui.view.WXImageView) HashMap(java.util.HashMap) Map(java.util.Map) IWXImgLoaderAdapter(com.taobao.weex.adapter.IWXImgLoaderAdapter)

Example 3 with ImageDrawable

use of com.taobao.weex.utils.ImageDrawable in project weex-example by KalicyZhou.

the class WXImage method updateProperties.

@Override
public void updateProperties(Map<String, Object> props) {
    super.updateProperties(props);
    WXImageView imageView;
    ImmutableDomObject imageDom;
    if ((imageDom = getDomObject()) != null && getHostView() instanceof WXImageView) {
        imageView = (WXImageView) getHostView();
        BorderDrawable borderDrawable = WXViewUtils.getBorderDrawable(getHostView());
        float[] borderRadius;
        if (borderDrawable != null) {
            RectF borderBox = new RectF(0, 0, WXDomUtils.getContentWidth(imageDom), WXDomUtils.getContentHeight(imageDom));
            borderRadius = borderDrawable.getBorderRadius(borderBox);
        } else {
            borderRadius = new float[] { 0, 0, 0, 0, 0, 0, 0, 0 };
        }
        imageView.setBorderRadius(borderRadius);
        if (imageView.getDrawable() instanceof ImageDrawable) {
            ImageDrawable imageDrawable = (ImageDrawable) imageView.getDrawable();
            float[] previousRadius = imageDrawable.getCornerRadii();
            if (!Arrays.equals(previousRadius, borderRadius)) {
                imageDrawable.setCornerRadii(borderRadius);
            }
        }
        readyToRender();
    }
}
Also used : RectF(android.graphics.RectF) ImageDrawable(com.taobao.weex.utils.ImageDrawable) BorderDrawable(com.taobao.weex.ui.view.border.BorderDrawable) ImmutableDomObject(com.taobao.weex.dom.ImmutableDomObject) WXImageView(com.taobao.weex.ui.view.WXImageView)

Aggregations

ImageDrawable (com.taobao.weex.utils.ImageDrawable)3 ImmutableDomObject (com.taobao.weex.dom.ImmutableDomObject)2 WXImageView (com.taobao.weex.ui.view.WXImageView)2 RectF (android.graphics.RectF)1 BitmapDrawable (android.graphics.drawable.BitmapDrawable)1 Drawable (android.graphics.drawable.Drawable)1 ViewGroup (android.view.ViewGroup)1 ImageView (android.widget.ImageView)1 IWXImgLoaderAdapter (com.taobao.weex.adapter.IWXImgLoaderAdapter)1 WXImageSharpen (com.taobao.weex.common.WXImageSharpen)1 WXImageStrategy (com.taobao.weex.common.WXImageStrategy)1 WXDomObject (com.taobao.weex.dom.WXDomObject)1 WXImage (com.taobao.weex.ui.component.WXImage)1 BorderDrawable (com.taobao.weex.ui.view.border.BorderDrawable)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1