use of com.taobao.weex.ui.view.border.BorderDrawable 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();
}
}
use of com.taobao.weex.ui.view.border.BorderDrawable in project weex-example by KalicyZhou.
the class WXComponent method getOrCreateBorder.
protected BorderDrawable getOrCreateBorder() {
if (mBackgroundDrawable == null) {
Drawable backgroundDrawable = mHost.getBackground();
WXViewUtils.setBackGround(mHost, null);
mBackgroundDrawable = new BorderDrawable();
if (backgroundDrawable == null) {
WXViewUtils.setBackGround(mHost, mBackgroundDrawable);
} else {
//TODO Not strictly clip according to background-clip:border-box
WXViewUtils.setBackGround(mHost, new LayerDrawable(new Drawable[] { mBackgroundDrawable, backgroundDrawable }));
}
}
return mBackgroundDrawable;
}
use of com.taobao.weex.ui.view.border.BorderDrawable in project weex-example by KalicyZhou.
the class WXViewUtils method clipCanvasWithinBorderBox.
public static void clipCanvasWithinBorderBox(View targetView, Canvas canvas) {
Drawable drawable;
/**
* According to https://code.google.com/p/android/issues/detail?id=225556&sort=-id&colspec=ID
* clipPath doesn't work with rotation nor scale when API level is 24 or higher.
*/
if ((Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2 || !canvas.isHardwareAccelerated()) && Build.VERSION.SDK_INT <= Build.VERSION_CODES.M && ((drawable = targetView.getBackground()) instanceof BorderDrawable)) {
BorderDrawable borderDrawable = (BorderDrawable) drawable;
if (borderDrawable.isRounded()) {
Path path = borderDrawable.getContentPath(new RectF(0, 0, targetView.getWidth(), targetView.getHeight()));
canvas.clipPath(path);
}
}
}
use of com.taobao.weex.ui.view.border.BorderDrawable in project weex-example by KalicyZhou.
the class WXImageTest method testSetBackgroundColor.
@Test
@PrepareForTest(WXImageView.class)
public void testSetBackgroundColor() throws Exception {
ImageView imageView = mWXImage.initComponentHostView(Robolectric.setupActivity(TestActivity.class));
mWXImage.mHost = imageView;
mWXImage.setBackgroundColor("#FFFFFF");
Drawable drawable = mWXImage.getHostView().getBackground();
assertEquals(drawable instanceof BorderDrawable, true);
}
use of com.taobao.weex.ui.view.border.BorderDrawable in project weex-example by KalicyZhou.
the class WXAnimationModule method createAnimator.
@Nullable
private static ObjectAnimator createAnimator(@NonNull WXAnimationBean animation, final View target, final int viewPortWidth) {
if (target == null) {
return null;
}
WXAnimationBean.Style style = animation.styles;
if (style != null) {
ObjectAnimator animator;
List<PropertyValuesHolder> holders = style.getHolders();
if (!TextUtils.isEmpty(style.backgroundColor)) {
BorderDrawable borderDrawable;
if ((borderDrawable = WXViewUtils.getBorderDrawable(target)) != null) {
holders.add(PropertyValuesHolder.ofObject(WXAnimationBean.Style.BACKGROUND_COLOR, new ArgbEvaluator(), borderDrawable.getColor(), WXResourceUtils.getColor(style.backgroundColor)));
} else if (target.getBackground() instanceof ColorDrawable) {
holders.add(PropertyValuesHolder.ofObject(WXAnimationBean.Style.BACKGROUND_COLOR, new ArgbEvaluator(), ((ColorDrawable) target.getBackground()).getColor(), WXResourceUtils.getColor(style.backgroundColor)));
}
}
if (style.getPivot() != null) {
Pair<Float, Float> pair = style.getPivot();
target.setPivotX(pair.first);
target.setPivotY(pair.second);
}
animator = ObjectAnimator.ofPropertyValuesHolder(target, holders.toArray(new PropertyValuesHolder[holders.size()]));
animator.setStartDelay(animation.delay);
if (target.getLayoutParams() != null && (!TextUtils.isEmpty(style.width) || !TextUtils.isEmpty(style.height))) {
DimensionUpdateListener listener = new DimensionUpdateListener(target);
ViewGroup.LayoutParams layoutParams = target.getLayoutParams();
if (!TextUtils.isEmpty(style.width)) {
listener.setWidth(layoutParams.width, (int) WXViewUtils.getRealPxByWidth(WXUtils.getFloat(style.width), viewPortWidth));
}
if (!TextUtils.isEmpty(style.height)) {
listener.setHeight(layoutParams.height, (int) WXViewUtils.getRealPxByWidth(WXUtils.getFloat(style.height), viewPortWidth));
}
animator.addUpdateListener(listener);
}
return animator;
} else {
return null;
}
}
Aggregations