Search in sources :

Example 1 with HookWXImageView

use of com.eros.framework.extend.hook.ui.view.HookWXImageView in project WeexErosFramework by bmfe.

the class HookImage method updateProperties.

@Override
public void updateProperties(Map<String, Object> props) {
    super.updateProperties(props);
    HookWXImageView imageView;
    ImmutableDomObject imageDom;
    if ((imageDom = getDomObject()) != null && getHostView() instanceof HookWXImageView) {
        imageView = (HookWXImageView) 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) HookWXImageView(com.eros.framework.extend.hook.ui.view.HookWXImageView)

Example 2 with HookWXImageView

use of com.eros.framework.extend.hook.ui.view.HookWXImageView in project WeexErosFramework by bmfe.

the class HookImage method collateBorderRadius.

private void collateBorderRadius() {
    if (getHostView() instanceof HookWXImageView) {
        HookWXImageView hookWXImageView = (HookWXImageView) getHostView();
        BorderDrawable borderDrawable = WXViewUtils.getBorderDrawable(hookWXImageView);
        if (borderDrawable != null) {
            ImmutableDomObject imageDom = getDomObject();
            RectF borderBox = new RectF(0, 0, WXDomUtils.getContentWidth(imageDom), WXDomUtils.getContentHeight(imageDom));
            float[] borderRadius = borderDrawable.getBorderRadius(borderBox);
            hookWXImageView.collateBorderRadius(borderRadius);
        }
    }
}
Also used : RectF(android.graphics.RectF) BorderDrawable(com.taobao.weex.ui.view.border.BorderDrawable) ImmutableDomObject(com.taobao.weex.dom.ImmutableDomObject) HookWXImageView(com.eros.framework.extend.hook.ui.view.HookWXImageView)

Example 3 with HookWXImageView

use of com.eros.framework.extend.hook.ui.view.HookWXImageView in project WeexErosFramework by bmfe.

the class HookImage method initComponentHostView.

@Override
protected ImageView initComponentHostView(@NonNull Context context) {
    HookWXImageView view = new HookWXImageView(context);
    view.setScaleType(ScaleType.FIT_XY);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        view.setCropToPadding(true);
    }
    view.holdComponent(this);
    return view;
}
Also used : HookWXImageView(com.eros.framework.extend.hook.ui.view.HookWXImageView)

Example 4 with HookWXImageView

use of com.eros.framework.extend.hook.ui.view.HookWXImageView in project WeexErosFramework by bmfe.

the class DefaultWXImageAdapter method setImage.

@Override
public void setImage(final String url, final ImageView view, WXImageQuality quality, final WXImageStrategy strategy) {
    if (view == null || !(view instanceof HookWXImageView))
        return;
    final String loadUri = url;
    if (HookImage.AUTORECYCLE_URL.equals(loadUri)) {
        // wximage被回收
        view.setImageBitmap(null);
        return;
    }
    final HookWXImageView wxImageView = (HookWXImageView) view;
    if (TextUtils.isEmpty(loadUri)) {
        // 设置的src为null
        wxImageView.setImageBitmap(null);
        handleError(wxImageView);
        if (strategy != null && strategy.getImageListener() != null) {
            strategy.getImageListener().onImageFinish(loadUri, view, true, null);
        }
        return;
    }
    wxImageView.hideErrorBitmap();
    // set placeHolder
    if (isDefaultPlaceHolder(strategy)) {
        int[] wh = WXCommonUtil.getComponentWH(wxImageView.getComponent());
        wxImageView.showLoading(wh[0], wh[1]);
    } else if (isCustomPlaceHolder(strategy)) {
        // customer placeHolder
        BMHookGlide.load(BMWXApplication.getWXApplication(), strategy.placeHolder).apply(new RequestOptions().fitCenter().diskCacheStrategy(DiskCacheStrategy.AUTOMATIC)).into(wxImageView);
    } else {
        // no placeHolder
        // 防止复用出现的问题
        wxImageView.hideLoading();
    }
    DefaultImageViewTarget viewTarget = new DefaultImageViewTarget(wxImageView);
    viewTarget.setImageLoadListener(new DefaultImageViewTarget.ImageLoadListener() {

        @Override
        public void onResourceReady(@NonNull Drawable resource, @Nullable Transition<? super Drawable> transition) {
            if (strategy != null && strategy.getImageListener() != null) {
                strategy.getImageListener().onImageFinish(loadUri, wxImageView, true, null);
            }
            if (isDefaultPlaceHolder(strategy)) {
                wxImageView.hideLoading();
            }
        }

        @Override
        public void onLoadFailed(@Nullable Drawable errorDrawable) {
            handleError((HookWXImageView) wxImageView);
            if (strategy != null && strategy.getImageListener() != null) {
                strategy.getImageListener().onImageFinish(loadUri, wxImageView, true, null);
            }
            if (isDefaultPlaceHolder(strategy)) {
                wxImageView.hideLoading();
            }
        }
    });
    BMHookGlide.load(BMWXApplication.getWXApplication(), loadUri).apply(new RequestOptions().diskCacheStrategy(DiskCacheStrategy.AUTOMATIC).transforms(new CenterCrop())).into(viewTarget);
}
Also used : RequestOptions(com.bumptech.glide.request.RequestOptions) Drawable(android.graphics.drawable.Drawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) GifDrawable(com.bumptech.glide.load.resource.gif.GifDrawable) CenterCrop(com.bumptech.glide.load.resource.bitmap.CenterCrop) HookWXImageView(com.eros.framework.extend.hook.ui.view.HookWXImageView)

Aggregations

HookWXImageView (com.eros.framework.extend.hook.ui.view.HookWXImageView)4 RectF (android.graphics.RectF)2 ImmutableDomObject (com.taobao.weex.dom.ImmutableDomObject)2 BorderDrawable (com.taobao.weex.ui.view.border.BorderDrawable)2 BitmapDrawable (android.graphics.drawable.BitmapDrawable)1 Drawable (android.graphics.drawable.Drawable)1 CenterCrop (com.bumptech.glide.load.resource.bitmap.CenterCrop)1 GifDrawable (com.bumptech.glide.load.resource.gif.GifDrawable)1 RequestOptions (com.bumptech.glide.request.RequestOptions)1 ImageDrawable (com.taobao.weex.utils.ImageDrawable)1