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