diff options
author | Adam Powell <adamp@google.com> | 2010-03-02 10:42:16 -0800 |
---|---|---|
committer | Adam Powell <adamp@google.com> | 2010-03-03 17:12:55 -0800 |
commit | f5bcc6addd9c1f8f6bb8b8626540d003b3f964fa (patch) | |
tree | 69332a76fdc7995b4298b56e81d7274ada12a6f1 /core/java/android/view/ScaleGestureDetector.java | |
parent | 9b10ef5fe85e9d29721ff0cd15161f960d38a8db (diff) | |
download | frameworks_base-f5bcc6addd9c1f8f6bb8b8626540d003b3f964fa.zip frameworks_base-f5bcc6addd9c1f8f6bb8b8626540d003b3f964fa.tar.gz frameworks_base-f5bcc6addd9c1f8f6bb8b8626540d003b3f964fa.tar.bz2 |
InputDevice filtering for jumpy screens.
Updated ScaleGestureDetector for framework deprecations.
Diffstat (limited to 'core/java/android/view/ScaleGestureDetector.java')
-rw-r--r-- | core/java/android/view/ScaleGestureDetector.java | 94 |
1 files changed, 50 insertions, 44 deletions
diff --git a/core/java/android/view/ScaleGestureDetector.java b/core/java/android/view/ScaleGestureDetector.java index 8140d61..d8b6d1f 100644 --- a/core/java/android/view/ScaleGestureDetector.java +++ b/core/java/android/view/ScaleGestureDetector.java @@ -154,9 +154,8 @@ public class ScaleGestureDetector { boolean handled = true; if (!mGestureInProgress) { - if ((action == MotionEvent.ACTION_POINTER_1_DOWN || - action == MotionEvent.ACTION_POINTER_2_DOWN) && - event.getPointerCount() >= 2) { + switch (action & MotionEvent.ACTION_MASK) { + case MotionEvent.ACTION_POINTER_DOWN: { // We have a new multi-finger gesture // as orientation can change, query the metrics in touch down @@ -189,7 +188,7 @@ public class ScaleGestureDetector { boolean p1sloppy = x1 < edgeSlop || y1 < edgeSlop || x1 > rightSlop || y1 > bottomSlop; - if(p0sloppy && p1sloppy) { + if (p0sloppy && p1sloppy) { mFocusX = -1; mFocusY = -1; mSloppyGesture = true; @@ -204,54 +203,61 @@ public class ScaleGestureDetector { } else { mGestureInProgress = mListener.onScaleBegin(this); } - } else if (action == MotionEvent.ACTION_MOVE && mSloppyGesture) { - // Initiate sloppy gestures if we've moved outside of the slop area. - final float edgeSlop = mEdgeSlop; - final float rightSlop = mRightSlopEdge; - final float bottomSlop = mBottomSlopEdge; - final float x0 = event.getRawX(); - final float y0 = event.getRawY(); - final float x1 = getRawX(event, 1); - final float y1 = getRawY(event, 1); - - boolean p0sloppy = x0 < edgeSlop || y0 < edgeSlop - || x0 > rightSlop || y0 > bottomSlop; - boolean p1sloppy = x1 < edgeSlop || y1 < edgeSlop - || x1 > rightSlop || y1 > bottomSlop; - - if(p0sloppy && p1sloppy) { - mFocusX = -1; - mFocusY = -1; - } else if (p0sloppy) { - mFocusX = event.getX(1); - mFocusY = event.getY(1); - } else if (p1sloppy) { - mFocusX = event.getX(0); - mFocusY = event.getY(0); - } else { - mSloppyGesture = false; - mGestureInProgress = mListener.onScaleBegin(this); + } + break; + + case MotionEvent.ACTION_MOVE: + if (mSloppyGesture) { + // Initiate sloppy gestures if we've moved outside of the slop area. + final float edgeSlop = mEdgeSlop; + final float rightSlop = mRightSlopEdge; + final float bottomSlop = mBottomSlopEdge; + final float x0 = event.getRawX(); + final float y0 = event.getRawY(); + final float x1 = getRawX(event, 1); + final float y1 = getRawY(event, 1); + + boolean p0sloppy = x0 < edgeSlop || y0 < edgeSlop + || x0 > rightSlop || y0 > bottomSlop; + boolean p1sloppy = x1 < edgeSlop || y1 < edgeSlop + || x1 > rightSlop || y1 > bottomSlop; + + if(p0sloppy && p1sloppy) { + mFocusX = -1; + mFocusY = -1; + } else if (p0sloppy) { + mFocusX = event.getX(1); + mFocusY = event.getY(1); + } else if (p1sloppy) { + mFocusX = event.getX(0); + mFocusY = event.getY(0); + } else { + mSloppyGesture = false; + mGestureInProgress = mListener.onScaleBegin(this); + } + } + break; + + case MotionEvent.ACTION_POINTER_UP: + if (mSloppyGesture) { + // Set focus point to the remaining finger + int id = (((action & MotionEvent.ACTION_POINTER_INDEX_MASK) + >> MotionEvent.ACTION_POINTER_INDEX_SHIFT) == 0) ? 1 : 0; + mFocusX = event.getX(id); + mFocusY = event.getY(id); } - } else if ((action == MotionEvent.ACTION_POINTER_1_UP - || action == MotionEvent.ACTION_POINTER_2_UP) - && mSloppyGesture) { - // Set focus point to the remaining finger - int id = (((action & MotionEvent.ACTION_POINTER_ID_MASK) - >> MotionEvent.ACTION_POINTER_ID_SHIFT) == 0) ? 1 : 0; - mFocusX = event.getX(id); - mFocusY = event.getY(id); + break; } } else { // Transform gesture in progress - attempt to handle it - switch (action) { - case MotionEvent.ACTION_POINTER_1_UP: - case MotionEvent.ACTION_POINTER_2_UP: + switch (action & MotionEvent.ACTION_MASK) { + case MotionEvent.ACTION_POINTER_UP: // Gesture ended setContext(event); // Set focus point to the remaining finger - int id = (((action & MotionEvent.ACTION_POINTER_ID_MASK) - >> MotionEvent.ACTION_POINTER_ID_SHIFT) == 0) ? 1 : 0; + int id = (((action & MotionEvent.ACTION_POINTER_INDEX_MASK) + >> MotionEvent.ACTION_POINTER_INDEX_SHIFT) == 0) ? 1 : 0; mFocusX = event.getX(id); mFocusY = event.getY(id); |