@Test public void testDispatchDraw() { ActivityController<Activity> activityController = Robolectric.buildActivity(Activity.class).create().start().resume() .visible(); Activity activity = activityController.get(); CircleView mView = new CircleView(activity); mView.setCenterY(2); mView.setCenterX(3); mView.setRadius(22); Canvas canvasMock = Mockito.mock(Canvas.class); mView.dispatchDraw(canvasMock); verify(canvasMock).drawCircle(Matchers.eq(3.0f), Matchers.eq(2.0f), Matchers.eq(22.0f), any(Paint.class)); }
@Override protected void dispatchDraw(Canvas canvas) { Paint paint = new Paint(); paint.setColor(defaultColor); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_OUT)); canvas.drawCircle(mCenterX, mCenterY, mRadius, paint); if(mTransparentRadius != 0){ Paint paintTransparent = new Paint(); paintTransparent.setColor(Color.YELLOW); paintTransparent.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_OUT)); canvas.drawCircle(mCenterX, mCenterY, mTransparentRadius, paintTransparent); } super.dispatchDraw(canvas); }
CircleView extends View { @Override protected void dispatchDraw(Canvas canvas) { Paint paint = new Paint(); paint.setColor(defaultColor); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_OUT)); canvas.drawCircle(mCenterX, mCenterY, mRadius, paint); if(mTransparentRadius != 0){ Paint paintTransparent = new Paint(); paintTransparent.setColor(Color.YELLOW); paintTransparent.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_OUT)); canvas.drawCircle(mCenterX, mCenterY, mTransparentRadius, paintTransparent); } super.dispatchDraw(canvas); } }
CircleView extends View { @Override protected void dispatchDraw(Canvas canvas) { Paint paint = new Paint(); paint.setColor(defaultColor); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_OUT)); canvas.drawCircle(mCenterX, mCenterY, mRadius, paint); if(mTransparentRadius != 0){ Paint paintTransparent = new Paint(); paintTransparent.setColor(Color.YELLOW); paintTransparent.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_OUT)); canvas.drawCircle(mCenterX, mCenterY, mTransparentRadius, paintTransparent); } super.dispatchDraw(canvas); } CircleView(Context context);  CircleView(Context context, AttributeSet attrs);  CircleView(Context context, AttributeSet attrs, int defStyleAttr); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)  CircleView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes); }
CircleView extends View { @Override protected void dispatchDraw(Canvas canvas) { Paint paint = new Paint(); paint.setColor(defaultColor); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_OUT)); canvas.drawCircle(mCenterX, mCenterY, mRadius, paint); if(mTransparentRadius != 0){ Paint paintTransparent = new Paint(); paintTransparent.setColor(Color.YELLOW); paintTransparent.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_OUT)); canvas.drawCircle(mCenterX, mCenterY, mTransparentRadius, paintTransparent); } super.dispatchDraw(canvas); } CircleView(Context context);  CircleView(Context context, AttributeSet attrs);  CircleView(Context context, AttributeSet attrs, int defStyleAttr); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)  CircleView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes); void setCenterX(float mCenterX); void setCenterY(float mCenterY); void setRadius(float radius); void setColor(int color); void setTransparentRadius(float radius); }
CircleView extends View { @Override protected void dispatchDraw(Canvas canvas) { Paint paint = new Paint(); paint.setColor(defaultColor); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_OUT)); canvas.drawCircle(mCenterX, mCenterY, mRadius, paint); if(mTransparentRadius != 0){ Paint paintTransparent = new Paint(); paintTransparent.setColor(Color.YELLOW); paintTransparent.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_OUT)); canvas.drawCircle(mCenterX, mCenterY, mTransparentRadius, paintTransparent); } super.dispatchDraw(canvas); } CircleView(Context context);  CircleView(Context context, AttributeSet attrs);  CircleView(Context context, AttributeSet attrs, int defStyleAttr); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)  CircleView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes); void setCenterX(float mCenterX); void setCenterY(float mCenterY); void setRadius(float radius); void setColor(int color); void setTransparentRadius(float radius);  }