diff options
| author | 2018-12-14 01:04:53 +0000 | |
|---|---|---|
| committer | 2018-12-14 01:04:53 +0000 | |
| commit | f85dddfd0cf98d1593101d479ac4ba2b006eb4f0 (patch) | |
| tree | 0f55060f47bf112bd808345e2ed3d71ef69c8a92 | |
| parent | 9c5585943f4e5ad26fc5a04e790fe4dc2b53ce6b (diff) | |
| parent | 1899955c1c273d87388830f312c341e966c31e03 (diff) | |
Merge "Pip: Use raw input coordiates when calculating pip movement offsets"
| -rw-r--r-- | api/current.txt | 2 | ||||
| -rw-r--r-- | core/java/android/view/MotionEvent.java | 32 | ||||
| -rw-r--r-- | packages/SystemUI/src/com/android/systemui/pip/phone/PipTouchState.java | 29 |
3 files changed, 54 insertions, 9 deletions
diff --git a/api/current.txt b/api/current.txt index aac5cc1fbac1..92526d4f8bc4 100644 --- a/api/current.txt +++ b/api/current.txt @@ -48962,7 +48962,9 @@ package android.view { method public float getPressure(); method public float getPressure(int); method public float getRawX(); + method public float getRawX(int); method public float getRawY(); + method public float getRawY(int); method public float getSize(); method public float getSize(int); method public int getSource(); diff --git a/core/java/android/view/MotionEvent.java b/core/java/android/view/MotionEvent.java index b59d8c720b9d..a86abe517b6a 100644 --- a/core/java/android/view/MotionEvent.java +++ b/core/java/android/view/MotionEvent.java @@ -2588,6 +2588,38 @@ public final class MotionEvent extends InputEvent implements Parcelable { } /** + * Returns the original raw X coordinate of this event. For touch + * events on the screen, this is the original location of the event + * on the screen, before it had been adjusted for the containing window + * and views. + * + * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0 + * (the first pointer that is down) to {@link #getPointerCount()}-1. + * + * @see #getX(int) + * @see #AXIS_X + */ + public float getRawX(int pointerIndex) { + return nativeGetRawAxisValue(mNativePtr, AXIS_X, pointerIndex, HISTORY_CURRENT); + } + + /** + * Returns the original raw Y coordinate of this event. For touch + * events on the screen, this is the original location of the event + * on the screen, before it had been adjusted for the containing window + * and views. + * + * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0 + * (the first pointer that is down) to {@link #getPointerCount()}-1. + * + * @see #getY(int) + * @see #AXIS_Y + */ + public float getRawY(int pointerIndex) { + return nativeGetRawAxisValue(mNativePtr, AXIS_Y, pointerIndex, HISTORY_CURRENT); + } + + /** * Return the precision of the X coordinates being reported. You can * multiply this number with {@link #getX} to find the actual hardware * value of the X coordinate. diff --git a/packages/SystemUI/src/com/android/systemui/pip/phone/PipTouchState.java b/packages/SystemUI/src/com/android/systemui/pip/phone/PipTouchState.java index 9aa21f8270b3..69efbc8575e0 100644 --- a/packages/SystemUI/src/com/android/systemui/pip/phone/PipTouchState.java +++ b/packages/SystemUI/src/com/android/systemui/pip/phone/PipTouchState.java @@ -84,7 +84,7 @@ public class PipTouchState { * Processes a given touch event and updates the state. */ public void onTouchEvent(MotionEvent ev) { - switch (ev.getAction()) { + switch (ev.getActionMasked()) { case MotionEvent.ACTION_DOWN: { if (!mAllowTouches) { return; @@ -92,12 +92,13 @@ public class PipTouchState { // Initialize the velocity tracker initOrResetVelocityTracker(); + addMovement(ev); mActivePointerId = ev.getPointerId(0); if (DEBUG) { Log.e(TAG, "Setting active pointer id on DOWN: " + mActivePointerId); } - mLastTouch.set(ev.getX(), ev.getY()); + mLastTouch.set(ev.getRawX(), ev.getRawY()); mDownTouch.set(mLastTouch); mAllowDraggingOffscreen = true; mIsUserInteracting = true; @@ -118,15 +119,15 @@ public class PipTouchState { } // Update the velocity tracker - mVelocityTracker.addMovement(ev); + addMovement(ev); int pointerIndex = ev.findPointerIndex(mActivePointerId); if (pointerIndex == -1) { Log.e(TAG, "Invalid active pointer id on MOVE: " + mActivePointerId); break; } - float x = ev.getX(pointerIndex); - float y = ev.getY(pointerIndex); + float x = ev.getRawX(pointerIndex); + float y = ev.getRawY(pointerIndex); mLastDelta.set(x - mLastTouch.x, y - mLastTouch.y); mDownDelta.set(x - mDownTouch.x, y - mDownTouch.y); @@ -149,7 +150,7 @@ public class PipTouchState { } // Update the velocity tracker - mVelocityTracker.addMovement(ev); + addMovement(ev); int pointerIndex = ev.getActionIndex(); int pointerId = ev.getPointerId(pointerIndex); @@ -161,7 +162,7 @@ public class PipTouchState { Log.e(TAG, "Relinquish active pointer id on POINTER_UP: " + mActivePointerId); } - mLastTouch.set(ev.getX(newPointerIndex), ev.getY(newPointerIndex)); + mLastTouch.set(ev.getRawX(newPointerIndex), ev.getRawY(newPointerIndex)); } break; } @@ -172,7 +173,7 @@ public class PipTouchState { } // Update the velocity tracker - mVelocityTracker.addMovement(ev); + addMovement(ev); mVelocityTracker.computeCurrentVelocity(1000, mViewConfig.getScaledMaximumFlingVelocity()); mVelocity.set(mVelocityTracker.getXVelocity(), mVelocityTracker.getYVelocity()); @@ -184,7 +185,7 @@ public class PipTouchState { } mUpTouchTime = ev.getEventTime(); - mLastTouch.set(ev.getX(pointerIndex), ev.getY(pointerIndex)); + mLastTouch.set(ev.getRawX(pointerIndex), ev.getRawY(pointerIndex)); mPreviouslyDragging = mIsDragging; mIsWaitingForDoubleTap = !mIsDoubleTap && !mIsDragging && (mUpTouchTime - mDownTouchTime) < DOUBLE_TAP_TIMEOUT; @@ -331,6 +332,16 @@ public class PipTouchState { } } + private void addMovement(MotionEvent event) { + // Add movement to velocity tracker using raw screen X and Y coordinates instead + // of window coordinates because the window frame may be moving at the same time. + float deltaX = event.getRawX() - event.getX(); + float deltaY = event.getRawY() - event.getY(); + event.offsetLocation(deltaX, deltaY); + mVelocityTracker.addMovement(event); + event.offsetLocation(-deltaX, -deltaY); + } + public void dump(PrintWriter pw, String prefix) { final String innerPrefix = prefix + " "; pw.println(prefix + TAG); |