summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Jim Miller <jaggies@google.com> 2011-06-20 13:42:24 -0700
committer Jim Miller <jaggies@google.com> 2011-06-20 15:19:32 -0700
commitb35e372bf4080f3b1940a371f1e39fb5dccde990 (patch)
tree9ac4dead61b2c565f768a59fda479532c7d8d245
parentb2af97e9a11119a257289cb8c539b5de79093052 (diff)
Handle dropped motion events in MultiWaveView due to high system activity
This change causes MultWaveView to look at historical motion events to make unlocking easier during high system load. Updated after review. Change-Id: Ibfc3cb513936e3b8488aa4390164bf5e214c982f
-rw-r--r--core/java/com/android/internal/widget/multiwaveview/MultiWaveView.java114
1 files changed, 60 insertions, 54 deletions
diff --git a/core/java/com/android/internal/widget/multiwaveview/MultiWaveView.java b/core/java/com/android/internal/widget/multiwaveview/MultiWaveView.java
index 1e9882796f6d..3e7b976aedb7 100644
--- a/core/java/com/android/internal/widget/multiwaveview/MultiWaveView.java
+++ b/core/java/com/android/internal/widget/multiwaveview/MultiWaveView.java
@@ -449,27 +449,25 @@ public class MultiWaveView extends View implements AnimatorUpdateListener {
final int action = event.getAction();
boolean handled = false;
- float x = event.getX();
- float y = event.getY();
switch (action) {
case MotionEvent.ACTION_DOWN:
- handleDown(x, y);
+ handleDown(event);
handled = true;
break;
case MotionEvent.ACTION_MOVE:
- handleMove(x, y);
+ handleMove(event);
handled = true;
break;
case MotionEvent.ACTION_UP:
- handleUp(x, y);
- handleMove(x, y);
+ handleMove(event);
+ handleUp(event);
handled = true;
break;
case MotionEvent.ACTION_CANCEL:
- handleMove(x, y);
+ handleMove(event);
handled = true;
break;
}
@@ -483,7 +481,9 @@ public class MultiWaveView extends View implements AnimatorUpdateListener {
mHandleDrawable.setY(y);
}
- private void handleDown(float x, float y) {
+ private void handleDown(MotionEvent event) {
+ final float x = event.getX();
+ final float y = event.getY();
final float dx = x - mWaveCenterX;
final float dy = y - mWaveCenterY;
if (dist2(dx,dy) <= square(mTapRadius)) {
@@ -498,66 +498,72 @@ public class MultiWaveView extends View implements AnimatorUpdateListener {
}
}
- private void handleUp(float x, float y) {
+ private void handleUp(MotionEvent event) {
if (DEBUG && mDragging) Log.v(TAG, "** Handle RELEASE");
- switchToState(STATE_FINISH, x, y);
+ switchToState(STATE_FINISH, event.getX(), event.getY());
}
- private void handleMove(float x, float y) {
+ private void handleMove(MotionEvent event) {
if (!mDragging) {
return;
}
- float tx = x - mWaveCenterX;
- float ty = y - mWaveCenterY;
- float touchRadius = (float) Math.sqrt(dist2(tx, ty));
- final float scale = touchRadius > mOuterRadius ? mOuterRadius / touchRadius : 1.0f;
- float limitX = mWaveCenterX + tx * scale;
- float limitY = mWaveCenterY + ty * scale;
-
int activeTarget = -1;
- boolean singleTarget = mTargetDrawables.size() == 1;
- if (singleTarget) {
- // Snap to outer ring if there's only one target
- float snapRadius = mOuterRadius - mSnapMargin;
- if (touchRadius > snapRadius) {
- activeTarget = 0;
+ final int historySize = event.getHistorySize();
+ for (int k = 0; k < historySize + 1; k++) {
+ float x = k < historySize ? event.getHistoricalX(k) : event.getX();
+ float y = k < historySize ? event.getHistoricalY(k) : event.getY();
+ float tx = x - mWaveCenterX;
+ float ty = y - mWaveCenterY;
+ float touchRadius = (float) Math.sqrt(dist2(tx, ty));
+ final float scale = touchRadius > mOuterRadius ? mOuterRadius / touchRadius : 1.0f;
+ float limitX = mWaveCenterX + tx * scale;
+ float limitY = mWaveCenterY + ty * scale;
+
+ boolean singleTarget = mTargetDrawables.size() == 1;
+ if (singleTarget) {
+ // Snap to outer ring if there's only one target
+ float snapRadius = mOuterRadius - mSnapMargin;
+ if (touchRadius > snapRadius) {
+ activeTarget = 0;
+ x = limitX;
+ y = limitY;
+ }
+ } else {
+ // If there's more than one target, snap to the closest one less than hitRadius away.
+ float best = Float.MAX_VALUE;
+ final float hitRadius2 = mHitRadius * mHitRadius;
+ for (int i = 0; i < mTargetDrawables.size(); i++) {
+ // Snap to the first target in range
+ TargetDrawable target = mTargetDrawables.get(i);
+ float dx = limitX - target.getX();
+ float dy = limitY - target.getY();
+ float dist2 = dx*dx + dy*dy;
+ if (target.isValid() && dist2 < hitRadius2 && dist2 < best) {
+ activeTarget = i;
+ best = dist2;
+ }
+ }
x = limitX;
y = limitY;
}
- } else {
- // If there's more than one target, snap to the closest one less than hitRadius away.
- float best = Float.MAX_VALUE;
- final float hitRadius2 = mHitRadius * mHitRadius;
- for (int i = 0; i < mTargetDrawables.size(); i++) {
- // Snap to the first target in range
- TargetDrawable target = mTargetDrawables.get(i);
- float dx = limitX - target.getX();
- float dy = limitY - target.getY();
- float dist2 = dx*dx + dy*dy;
- if (target.isValid() && dist2 < hitRadius2 && dist2 < best) {
- activeTarget = i;
- best = dist2;
+ if (activeTarget != -1) {
+ switchToState(STATE_SNAP, x,y);
+ float newX = singleTarget ? limitX : mTargetDrawables.get(activeTarget).getX();
+ float newY = singleTarget ? limitY : mTargetDrawables.get(activeTarget).getY();
+ moveHandleTo(newX, newY, false);
+ TargetDrawable currentTarget = mTargetDrawables.get(activeTarget);
+ if (currentTarget.hasState(TargetDrawable.STATE_FOCUSED)) {
+ currentTarget.setState(TargetDrawable.STATE_FOCUSED);
+ mHandleDrawable.setAlpha(0.0f);
}
+ } else {
+ switchToState(STATE_TRACKING, x, y);
+ moveHandleTo(x, y, false);
+ mHandleDrawable.setAlpha(1.0f);
}
- x = limitX;
- y = limitY;
- }
- if (activeTarget != -1) {
- switchToState(STATE_SNAP, x,y);
- float newX = singleTarget ? limitX : mTargetDrawables.get(activeTarget).getX();
- float newY = singleTarget ? limitY : mTargetDrawables.get(activeTarget).getY();
- moveHandleTo(newX, newY, false);
- TargetDrawable currentTarget = mTargetDrawables.get(activeTarget);
- if (currentTarget.hasState(TargetDrawable.STATE_FOCUSED)) {
- currentTarget.setState(TargetDrawable.STATE_FOCUSED);
- mHandleDrawable.setAlpha(0.0f);
- }
- } else {
- switchToState(STATE_TRACKING, x, y);
- moveHandleTo(x, y, false);
- mHandleDrawable.setAlpha(1.0f);
}
+
// Draw handle outside parent's bounds
invalidateGlobalRegion(mHandleDrawable);