Search in sources :

Example 1 with BorderDrawable

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();
    }
}
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) WXImageView(com.taobao.weex.ui.view.WXImageView)

Example 2 with BorderDrawable

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;
}
Also used : BorderDrawable(com.taobao.weex.ui.view.border.BorderDrawable) LayerDrawable(android.graphics.drawable.LayerDrawable) Drawable(android.graphics.drawable.Drawable) BorderDrawable(com.taobao.weex.ui.view.border.BorderDrawable) LayerDrawable(android.graphics.drawable.LayerDrawable)

Example 3 with BorderDrawable

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);
        }
    }
}
Also used : Path(android.graphics.Path) RectF(android.graphics.RectF) BorderDrawable(com.taobao.weex.ui.view.border.BorderDrawable) LayerDrawable(android.graphics.drawable.LayerDrawable) BorderDrawable(com.taobao.weex.ui.view.border.BorderDrawable) Drawable(android.graphics.drawable.Drawable)

Example 4 with BorderDrawable

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);
}
Also used : BorderDrawable(com.taobao.weex.ui.view.border.BorderDrawable) Drawable(android.graphics.drawable.Drawable) BorderDrawable(com.taobao.weex.ui.view.border.BorderDrawable) TestActivity(com.taobao.weex.TestActivity) ImageView(android.widget.ImageView) WXImageView(com.taobao.weex.ui.view.WXImageView) WXSDKInstanceTest(com.taobao.weex.WXSDKInstanceTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 5 with BorderDrawable

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;
    }
}
Also used : ObjectAnimator(android.animation.ObjectAnimator) ViewGroup(android.view.ViewGroup) ArgbEvaluator(android.animation.ArgbEvaluator) BorderDrawable(com.taobao.weex.ui.view.border.BorderDrawable) ColorDrawable(android.graphics.drawable.ColorDrawable) PropertyValuesHolder(android.animation.PropertyValuesHolder) Nullable(android.support.annotation.Nullable)

Aggregations

BorderDrawable (com.taobao.weex.ui.view.border.BorderDrawable)5 Drawable (android.graphics.drawable.Drawable)3 RectF (android.graphics.RectF)2 LayerDrawable (android.graphics.drawable.LayerDrawable)2 WXImageView (com.taobao.weex.ui.view.WXImageView)2 ArgbEvaluator (android.animation.ArgbEvaluator)1 ObjectAnimator (android.animation.ObjectAnimator)1 PropertyValuesHolder (android.animation.PropertyValuesHolder)1 Path (android.graphics.Path)1 ColorDrawable (android.graphics.drawable.ColorDrawable)1 Nullable (android.support.annotation.Nullable)1 ViewGroup (android.view.ViewGroup)1 ImageView (android.widget.ImageView)1 TestActivity (com.taobao.weex.TestActivity)1 WXSDKInstanceTest (com.taobao.weex.WXSDKInstanceTest)1 ImmutableDomObject (com.taobao.weex.dom.ImmutableDomObject)1 ImageDrawable (com.taobao.weex.utils.ImageDrawable)1 Test (org.junit.Test)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1