I am trying to draw 3 rects on canvas.
First one is green and is going on the back. Second is red and is over the green one. Third is going over both of them, and it should "cut through" first two rects. Something like this:
I get that I should do something like this:
canvas.drawColor(red);
canvas.drawRect(greenRect, paintGreen);
canvas.drawRect(smallRect, paintWithSomePorterduff);
canvas.drawRect(redRect, paintRed);
canvas.drawRect(smallRect, paintWithSomePorterduff);
But what PorterDuffXfermode to use, and how to clip only one rect and not make a hole through all of them and get this:
P.S. I can't make different bitmaps and then draw them because it will redraw it at every 1 or 2 seconds.
I had to do it by creating a bitmap and redrawing it.
canvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR);
canvas.drawColor(colorBottom);
timeBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
timeCanvas = new Canvas(timeBitmap);
timeCanvas.drawArc(oval, 270, secRot, true, secondHandPaint);
timePaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.XOR));
timeCanvas.drawText(time, xOffset, yOffset, timePaint);
canvas.drawBitmap(timeBitmap, 0, 0, new Paint());