summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJim Miller <jaggies@google.com>2011-06-17 19:39:49 -0700
committerAndroid (Google) Code Review <android-gerrit@google.com>2011-06-17 19:39:49 -0700
commit94c9f39ece18183c3ad2ad224ddb4690e3dd5045 (patch)
tree97c78f3c970e72878c9a4b0ef4fe3e01dc6e61da
parent98769300af3580723f99415bba0f790e874fb27b (diff)
parentaced12fd2276ed7664af6bf70ff03ce2acaf6545 (diff)
downloadframeworks_base-94c9f39ece18183c3ad2ad224ddb4690e3dd5045.zip
frameworks_base-94c9f39ece18183c3ad2ad224ddb4690e3dd5045.tar.gz
frameworks_base-94c9f39ece18183c3ad2ad224ddb4690e3dd5045.tar.bz2
Merge "Handle dropped motion events in Pattern Unlock due to high system activity"
-rw-r--r--core/java/com/android/internal/widget/LockPatternView.java321
1 files changed, 169 insertions, 152 deletions
diff --git a/core/java/com/android/internal/widget/LockPatternView.java b/core/java/com/android/internal/widget/LockPatternView.java
index fd49ae3..cbb110a 100644
--- a/core/java/com/android/internal/widget/LockPatternView.java
+++ b/core/java/com/android/internal/widget/LockPatternView.java
@@ -618,51 +618,26 @@ public class LockPatternView extends View {
}
@Override
- public boolean onTouchEvent(MotionEvent motionEvent) {
+ public boolean onTouchEvent(MotionEvent event) {
if (!mInputEnabled || !isEnabled()) {
return false;
}
- final float x = motionEvent.getX();
- final float y = motionEvent.getY();
- Cell hitCell;
- switch(motionEvent.getAction()) {
+ switch(event.getAction()) {
case MotionEvent.ACTION_DOWN:
- resetPattern();
- hitCell = detectAndAddHit(x, y);
- if (hitCell != null && mOnPatternListener != null) {
- mPatternInProgress = true;
- mPatternDisplayMode = DisplayMode.Correct;
- mOnPatternListener.onPatternStart();
- } else if (mOnPatternListener != null) {
- mPatternInProgress = false;
- mOnPatternListener.onPatternCleared();
- }
- if (hitCell != null) {
- final float startX = getCenterXForColumn(hitCell.column);
- final float startY = getCenterYForRow(hitCell.row);
-
- final float widthOffset = mSquareWidth / 2f;
- final float heightOffset = mSquareHeight / 2f;
-
- invalidate((int) (startX - widthOffset), (int) (startY - heightOffset),
- (int) (startX + widthOffset), (int) (startY + heightOffset));
- }
- mInProgressX = x;
- mInProgressY = y;
- if (PROFILE_DRAWING) {
- if (!mDrawingProfilingStarted) {
- Debug.startMethodTracing("LockPatternDrawing");
- mDrawingProfilingStarted = true;
- }
- }
+ handleActionDown(event);
return true;
case MotionEvent.ACTION_UP:
- // report pattern detected
- if (!mPattern.isEmpty() && mOnPatternListener != null) {
+ handleActionUp(event);
+ return true;
+ case MotionEvent.ACTION_MOVE:
+ handleActionMove(event);
+ return true;
+ case MotionEvent.ACTION_CANCEL:
+ resetPattern();
+ if (mOnPatternListener != null) {
mPatternInProgress = false;
- mOnPatternListener.onPatternDetected(mPattern);
- invalidate();
+ mOnPatternListener.onPatternCleared();
}
if (PROFILE_DRAWING) {
if (mDrawingProfilingStarted) {
@@ -671,141 +646,183 @@ public class LockPatternView extends View {
}
}
return true;
- case MotionEvent.ACTION_MOVE:
- final int patternSizePreHitDetect = mPattern.size();
- hitCell = detectAndAddHit(x, y);
- final int patternSize = mPattern.size();
- if (hitCell != null && (mOnPatternListener != null) && (patternSize == 1)) {
- mPatternInProgress = true;
- mOnPatternListener.onPatternStart();
- }
- // note current x and y for rubber banding of in progress
- // patterns
- final float dx = Math.abs(x - mInProgressX);
- final float dy = Math.abs(y - mInProgressY);
- if (dx + dy > mSquareWidth * 0.01f) {
- float oldX = mInProgressX;
- float oldY = mInProgressY;
+ }
+ return false;
+ }
- mInProgressX = x;
- mInProgressY = y;
+ private void handleActionMove(MotionEvent event) {
+ // Handle all recent motion events so we don't skip any cells even when the device
+ // is busy...
+ final int historySize = event.getHistorySize();
+ for (int i = 0; i < historySize + 1; i++) {
+ final float x = i < historySize ? event.getHistoricalX(i) : event.getX();
+ final float y = i < historySize ? event.getHistoricalY(i) : event.getY();
+ final int patternSizePreHitDetect = mPattern.size();
+ Cell hitCell = detectAndAddHit(x, y);
+ final int patternSize = mPattern.size();
+ if (hitCell != null && (mOnPatternListener != null) && (patternSize == 1)) {
+ mPatternInProgress = true;
+ mOnPatternListener.onPatternStart();
+ }
+ // note current x and y for rubber banding of in progress patterns
+ final float dx = Math.abs(x - mInProgressX);
+ final float dy = Math.abs(y - mInProgressY);
+ if (dx + dy > mSquareWidth * 0.01f) {
+ float oldX = mInProgressX;
+ float oldY = mInProgressY;
- if (mPatternInProgress && patternSize > 0) {
- final ArrayList<Cell> pattern = mPattern;
- final float radius = mSquareWidth * mDiameterFactor * 0.5f;
+ mInProgressX = x;
+ mInProgressY = y;
- final Cell lastCell = pattern.get(patternSize - 1);
+ if (mPatternInProgress && patternSize > 0) {
+ final ArrayList<Cell> pattern = mPattern;
+ final float radius = mSquareWidth * mDiameterFactor * 0.5f;
- float startX = getCenterXForColumn(lastCell.column);
- float startY = getCenterYForRow(lastCell.row);
+ final Cell lastCell = pattern.get(patternSize - 1);
- float left;
- float top;
- float right;
- float bottom;
+ float startX = getCenterXForColumn(lastCell.column);
+ float startY = getCenterYForRow(lastCell.row);
- final Rect invalidateRect = mInvalidate;
+ float left;
+ float top;
+ float right;
+ float bottom;
- if (startX < x) {
- left = startX;
- right = x;
- } else {
- left = x;
- right = startX;
- }
+ final Rect invalidateRect = mInvalidate;
- if (startY < y) {
- top = startY;
- bottom = y;
- } else {
- top = y;
- bottom = startY;
- }
+ if (startX < x) {
+ left = startX;
+ right = x;
+ } else {
+ left = x;
+ right = startX;
+ }
- // Invalidate between the pattern's last cell and the current location
- invalidateRect.set((int) (left - radius), (int) (top - radius),
- (int) (right + radius), (int) (bottom + radius));
+ if (startY < y) {
+ top = startY;
+ bottom = y;
+ } else {
+ top = y;
+ bottom = startY;
+ }
- if (startX < oldX) {
- left = startX;
- right = oldX;
- } else {
- left = oldX;
- right = startX;
- }
+ // Invalidate between the pattern's last cell and the current location
+ invalidateRect.set((int) (left - radius), (int) (top - radius),
+ (int) (right + radius), (int) (bottom + radius));
- if (startY < oldY) {
- top = startY;
- bottom = oldY;
- } else {
- top = oldY;
- bottom = startY;
- }
+ if (startX < oldX) {
+ left = startX;
+ right = oldX;
+ } else {
+ left = oldX;
+ right = startX;
+ }
+
+ if (startY < oldY) {
+ top = startY;
+ bottom = oldY;
+ } else {
+ top = oldY;
+ bottom = startY;
+ }
+
+ // Invalidate between the pattern's last cell and the previous location
+ invalidateRect.union((int) (left - radius), (int) (top - radius),
+ (int) (right + radius), (int) (bottom + radius));
+
+ // Invalidate between the pattern's new cell and the pattern's previous cell
+ if (hitCell != null) {
+ startX = getCenterXForColumn(hitCell.column);
+ startY = getCenterYForRow(hitCell.row);
- // Invalidate between the pattern's last cell and the previous location
- invalidateRect.union((int) (left - radius), (int) (top - radius),
- (int) (right + radius), (int) (bottom + radius));
-
- // Invalidate between the pattern's new cell and the pattern's previous cell
- if (hitCell != null) {
- startX = getCenterXForColumn(hitCell.column);
- startY = getCenterYForRow(hitCell.row);
-
- if (patternSize >= 2) {
- // (re-using hitcell for old cell)
- hitCell = pattern.get(patternSize - 1 - (patternSize - patternSizePreHitDetect));
- oldX = getCenterXForColumn(hitCell.column);
- oldY = getCenterYForRow(hitCell.row);
-
- if (startX < oldX) {
- left = startX;
- right = oldX;
- } else {
- left = oldX;
- right = startX;
- }
-
- if (startY < oldY) {
- top = startY;
- bottom = oldY;
- } else {
- top = oldY;
- bottom = startY;
- }
+ if (patternSize >= 2) {
+ // (re-using hitcell for old cell)
+ hitCell = pattern.get(patternSize - 1 - (patternSize - patternSizePreHitDetect));
+ oldX = getCenterXForColumn(hitCell.column);
+ oldY = getCenterYForRow(hitCell.row);
+
+ if (startX < oldX) {
+ left = startX;
+ right = oldX;
} else {
- left = right = startX;
- top = bottom = startY;
+ left = oldX;
+ right = startX;
}
- final float widthOffset = mSquareWidth / 2f;
- final float heightOffset = mSquareHeight / 2f;
-
- invalidateRect.set((int) (left - widthOffset),
- (int) (top - heightOffset), (int) (right + widthOffset),
- (int) (bottom + heightOffset));
+ if (startY < oldY) {
+ top = startY;
+ bottom = oldY;
+ } else {
+ top = oldY;
+ bottom = startY;
+ }
+ } else {
+ left = right = startX;
+ top = bottom = startY;
}
- invalidate(invalidateRect);
- } else {
- invalidate();
- }
- }
- return true;
- case MotionEvent.ACTION_CANCEL:
- resetPattern();
- if (mOnPatternListener != null) {
- mPatternInProgress = false;
- mOnPatternListener.onPatternCleared();
- }
- if (PROFILE_DRAWING) {
- if (mDrawingProfilingStarted) {
- Debug.stopMethodTracing();
- mDrawingProfilingStarted = false;
+ final float widthOffset = mSquareWidth / 2f;
+ final float heightOffset = mSquareHeight / 2f;
+
+ invalidateRect.set((int) (left - widthOffset),
+ (int) (top - heightOffset), (int) (right + widthOffset),
+ (int) (bottom + heightOffset));
}
+
+ invalidate(invalidateRect);
+ } else {
+ invalidate();
}
- return true;
+ }
+ }
+ }
+
+ private void handleActionUp(MotionEvent event) {
+ // report pattern detected
+ if (!mPattern.isEmpty() && mOnPatternListener != null) {
+ mPatternInProgress = false;
+ mOnPatternListener.onPatternDetected(mPattern);
+ invalidate();
+ }
+ if (PROFILE_DRAWING) {
+ if (mDrawingProfilingStarted) {
+ Debug.stopMethodTracing();
+ mDrawingProfilingStarted = false;
+ }
+ }
+ }
+
+ private void handleActionDown(MotionEvent event) {
+ resetPattern();
+ final float x = event.getX();
+ final float y = event.getY();
+ final Cell hitCell = detectAndAddHit(x, y);
+ if (hitCell != null && mOnPatternListener != null) {
+ mPatternInProgress = true;
+ mPatternDisplayMode = DisplayMode.Correct;
+ mOnPatternListener.onPatternStart();
+ } else if (mOnPatternListener != null) {
+ mPatternInProgress = false;
+ mOnPatternListener.onPatternCleared();
+ }
+ if (hitCell != null) {
+ final float startX = getCenterXForColumn(hitCell.column);
+ final float startY = getCenterYForRow(hitCell.row);
+
+ final float widthOffset = mSquareWidth / 2f;
+ final float heightOffset = mSquareHeight / 2f;
+
+ invalidate((int) (startX - widthOffset), (int) (startY - heightOffset),
+ (int) (startX + widthOffset), (int) (startY + heightOffset));
+ }
+ mInProgressX = x;
+ mInProgressY = y;
+ if (PROFILE_DRAWING) {
+ if (!mDrawingProfilingStarted) {
+ Debug.startMethodTracing("LockPatternDrawing");
+ mDrawingProfilingStarted = true;
+ }
}
- return false;
}
private float getCenterXForColumn(int column) {