From 9ddfeb83aa071990110c0dac7f9280d35ebf2239 Mon Sep 17 00:00:00 2001 From: Jim Miller Date: Wed, 10 Apr 2013 18:15:30 -0700 Subject: [PATCH] Fix keyguard pattern invalidate bug The framework used to invalidate both the previous invalidate region and the current one. However, with change I9fb96f99 this is no longer the case (it was always true for software rendering, but never showed because most platforms use acceleration). The fix is to invalidate the union of the old region and the new region ourselves. Fixes bug 8503031 Change-Id: If303e0892772dd9d6915efa55118d054a742c1a5 --- .../internal/widget/LockPatternView.java | 47 +++++++++---------- 1 file changed, 22 insertions(+), 25 deletions(-) diff --git a/core/java/com/android/internal/widget/LockPatternView.java b/core/java/com/android/internal/widget/LockPatternView.java index 1b088b3c81ac9..b066d703360a5 100644 --- a/core/java/com/android/internal/widget/LockPatternView.java +++ b/core/java/com/android/internal/widget/LockPatternView.java @@ -38,7 +38,6 @@ import android.view.View; import android.view.accessibility.AccessibilityManager; import com.android.internal.R; -import com.android.internal.widget.LockPatternView.Cell; import java.util.ArrayList; import java.util.List; @@ -51,7 +50,6 @@ import java.util.List; * "correct" states. */ public class LockPatternView extends View { - private static final String TAG = "LockPatternView"; // Aspect to use when rendering this view private static final int ASPECT_SQUARE = 0; // View will be the minimum of width/height private static final int ASPECT_LOCK_WIDTH = 1; // Fixed width; height will be minimum of (w,h) @@ -63,9 +61,6 @@ public class LockPatternView extends View { private Paint mPaint = new Paint(); private Paint mPathPaint = new Paint(); - // TODO: make this common with PhoneWindow - static final int STATUS_BAR_HEIGHT = 25; - /** * How many milliseconds we spend animating each circle of a lock pattern * if the animating mode is set. The entire animation should take this @@ -124,6 +119,7 @@ public class LockPatternView extends View { private final Path mCurrentPath = new Path(); private final Rect mInvalidate = new Rect(); + private final Rect mTmpInvalidateRect = new Rect(); private int mBitmapWidth; private int mBitmapHeight; @@ -132,7 +128,6 @@ public class LockPatternView extends View { private final Matrix mArrowMatrix = new Matrix(); private final Matrix mCircleMatrix = new Matrix(); - /** * Represents a cell in the 3 X 3 matrix of the unlock pattern view. */ @@ -680,8 +675,9 @@ public class LockPatternView extends View { private void handleActionMove(MotionEvent event) { // Handle all recent motion events so we don't skip any cells even when the device // is busy... + final float radius = (mSquareWidth * mDiameterFactor * 0.5f); final int historySize = event.getHistorySize(); - Rect invalidateRect = mInvalidate; + mTmpInvalidateRect.setEmpty(); boolean invalidateNow = false; for (int i = 0; i < historySize + 1; i++) { final float x = i < historySize ? event.getHistoricalX(i) : event.getX(); @@ -702,30 +698,30 @@ public class LockPatternView extends View { if (mPatternInProgress && patternSize > 0) { final ArrayList pattern = mPattern; final Cell lastCell = pattern.get(patternSize - 1); - float startX = getCenterXForColumn(lastCell.column); - float startY = getCenterYForRow(lastCell.row); + float lastCellCenterX = getCenterXForColumn(lastCell.column); + float lastCellCenterY = getCenterYForRow(lastCell.row); - // Adjust for current position. Radius accounts for line width. - final float radius = (mSquareWidth * mDiameterFactor * 0.5f); - float left = Math.min(startX, x) - radius; - float right = Math.max(startX, x) + radius; - float top = Math.min(startY, y) - radius; - float bottom = Math.max(startY, y) + radius; + // Adjust for drawn segment from last cell to (x,y). Radius accounts for line width. + float left = Math.min(lastCellCenterX, x) - radius; + float right = Math.max(lastCellCenterX, x) + radius; + float top = Math.min(lastCellCenterY, y) - radius; + float bottom = Math.max(lastCellCenterY, y) + radius; // Invalidate between the pattern's new cell and the pattern's previous cell - if (hitCell != null && patternSize >= 2) { + if (hitCell != null) { final float width = mSquareWidth * 0.5f; final float height = mSquareHeight * 0.5f; - final float x2 = getCenterXForColumn(hitCell.column); - final float y2 = getCenterYForRow(hitCell.row); - left = Math.min(x2, left - width); - right = Math.max(x2, right + width); - top = Math.min(y2, top - height); - bottom = Math.max(y2, bottom + height); + final float hitCellCenterX = getCenterXForColumn(hitCell.column); + final float hitCellCenterY = getCenterYForRow(hitCell.row); + + left = Math.min(hitCellCenterX - width, left); + right = Math.max(hitCellCenterX + width, right); + top = Math.min(hitCellCenterY - height, top); + bottom = Math.max(hitCellCenterY + height, bottom); } // Invalidate between the pattern's last cell and the previous location - invalidateRect.union(Math.round(left), Math.round(top), + mTmpInvalidateRect.union(Math.round(left), Math.round(top), Math.round(right), Math.round(bottom)); } } @@ -734,8 +730,9 @@ public class LockPatternView extends View { // To save updates, we only invalidate if the user moved beyond a certain amount. if (invalidateNow) { - invalidate(invalidateRect); - invalidateRect.setEmpty(); + mInvalidate.union(mTmpInvalidateRect); + invalidate(mInvalidate); + mInvalidate.set(mTmpInvalidateRect); } }