Search in sources :

Example 1 with WXImageSharpen

use of com.taobao.weex.common.WXImageSharpen 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 2 with WXImageSharpen

use of com.taobao.weex.common.WXImageSharpen in project weex-example by KalicyZhou.

the class WXAttr method getImageSharpen.

public WXImageSharpen getImageSharpen() {
    Object obj = get(Constants.Name.SHARPEN);
    if (obj == null) {
        obj = get(Constants.Name.IMAGE_SHARPEN);
    }
    if (obj == null) {
        return WXImageSharpen.UNSHARPEN;
    }
    String imageSharpen = obj.toString();
    WXImageSharpen waImageSharpen = WXImageSharpen.UNSHARPEN;
    if (imageSharpen.equals("sharpen")) {
        waImageSharpen = WXImageSharpen.SHARPEN;
    }
    return waImageSharpen;
}
Also used : WXImageSharpen(com.taobao.weex.common.WXImageSharpen)

Aggregations

WXImageSharpen (com.taobao.weex.common.WXImageSharpen)2 ImageView (android.widget.ImageView)1 IWXImgLoaderAdapter (com.taobao.weex.adapter.IWXImgLoaderAdapter)1 WXImageStrategy (com.taobao.weex.common.WXImageStrategy)1 ImmutableDomObject (com.taobao.weex.dom.ImmutableDomObject)1 WXDomObject (com.taobao.weex.dom.WXDomObject)1 WXImageView (com.taobao.weex.ui.view.WXImageView)1 ImageDrawable (com.taobao.weex.utils.ImageDrawable)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1