When I call invalidate (rect) inside the view, I want it to clear the "rect" area on the canvas and do what is indicated in onDraw. The problem is that it ignores the given βdirectβ estimates and invalidates the whole view.
I made a small test program to show my problem. When the application starts, the first line is displayed. When the user touches the screen, the second line is typed (and invalidate (rect) is called in this region). Line 1 is intentionally not redrawn. The problem is that line 1 disappears and only line 2 is displayed on the screen.
the code:
public class TestInval extends View { ... @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); Log.d(TAG, "onDraw bounds: " + canvas.getClipBounds()); //Logs: Rect(0, 0 - 720, 1134) if (drawOtherLine) canvas.drawLine(50, 50, 100, 100, defaultPaint); else canvas.drawLine(0, 0, 50, 50, defaultPaint); } .. public boolean onTouch(View view, MotionEvent motionEvent) { if (motionEvent.getAction() == MotionEvent.ACTION_UP) { drawOtherLine = true; Rect invalidateRect = new Rect(50, 50, 100, 100); invalidate(invalidateRect); } return true; } @Override public void invalidate(Rect dirty) { Log.d(TAG, "invalidate: " + dirty); //Logs: Rect(50, 50 - 100, 100) super.invalidate(dirty); }


UPDATE:
My device, Samsung Galaxy S3 is running 4.1.2, not rooted, it seems like a problem. Running the same test application on an Android emulator gives the expected clipping boundaries. Still not sure why this is happening on my device.
source share