summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJim Miller <jaggies@google.com>2011-06-17 16:09:46 -0700
committerJim Miller <jaggies@google.com>2011-06-17 16:09:46 -0700
commitaced12fd2276ed7664af6bf70ff03ce2acaf6545 (patch)
tree9d5d9f0219bbd344ca421414b8f67dd3efe1f245
parent576715c75987b64eff120f8800862815753b0c8a (diff)
downloadframeworks_base-aced12fd2276ed7664af6bf70ff03ce2acaf6545.zip
frameworks_base-aced12fd2276ed7664af6bf70ff03ce2acaf6545.tar.gz
frameworks_base-aced12fd2276ed7664af6bf70ff03ce2acaf6545.tar.bz2
Handle dropped motion events in Pattern Unlock due to high system activity
This enables the pattern unlock screen to look at historical motion events to make unlocking easier during high system load. Change-Id: I74a9c2d0833e8bb6745b89e8d397116baebb24a1
-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 bee8112..72ef13f 100644
--- a/core/java/com/android/internal/widget/LockPatternView.java
+++ b/core/java/com/android/internal/widget/LockPatternView.java
@@ -603,51 +603,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) {
@@ -656,141 +631,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) {