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();
}
}
}
}
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);
}
}
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();
}
}
Aggregations