From c8548557ce622e679e3d63c0ebbf6c503f786ae6 Mon Sep 17 00:00:00 2001 From: Siarhei Vishniakou Date: Wed, 24 Oct 2018 23:14:55 -0700 Subject: [PATCH] Use raw MotionEvent coordinates when tracking velocity Unfortunately, we have to roll back the commit "use raw coordinates in velocitytracker" ag/3545962 because it broke some assumptions in the view hierarchy. That is being done in aosp/800996. As a result, we have to start working around the revert by manually adjusting the coordinates. This is effectively a revert of ag/4071758 that has been rebased on ag/4891556. Test: manual interaction with notification panel (pulling down, flinging at various points) Bug: 117921784 Bug: 117475766 Change-Id: I24c5815967381cd4be983ef7e8456fa7d42c53c8 --- .../systemui/statusbar/phone/PanelView.java | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PanelView.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PanelView.java index 57c243957b486..f29b7cab5cbc9 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PanelView.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PanelView.java @@ -227,6 +227,16 @@ public abstract class PanelView extends FrameLayout { mUnlockFalsingThreshold = res.getDimensionPixelSize(R.dimen.unlock_falsing_threshold); } + 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 setTouchAndAnimationDisabled(boolean disabled) { mTouchDisabled = disabled; if (mTouchDisabled) { @@ -307,7 +317,7 @@ public abstract class PanelView extends FrameLayout { mTouchAboveFalsingThreshold = false; mCollapsedAndHeadsUpOnDown = isFullyCollapsed() && mHeadsUpManager.hasPinnedHeadsUp(); - mVelocityTracker.addMovement(event); + addMovement(event); if (!mGestureWaitForTouchSlop || (mHeightAnimator != null && !mHintAnimationRunning) || mPeekAnimator != null) { mTouchSlopExceeded = (mHeightAnimator != null && !mHintAnimationRunning) @@ -341,7 +351,7 @@ public abstract class PanelView extends FrameLayout { } break; case MotionEvent.ACTION_MOVE: - mVelocityTracker.addMovement(event); + addMovement(event); float h = y - mInitialTouchY; // If the panel was collapsed when touching, we only need to check for the @@ -386,7 +396,7 @@ public abstract class PanelView extends FrameLayout { case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: - mVelocityTracker.addMovement(event); + addMovement(event); endMotionEvent(event, x, y, false /* forceCancel */); break; } @@ -573,7 +583,7 @@ public abstract class PanelView extends FrameLayout { mHasLayoutedSinceDown = false; mUpdateFlingOnLayout = false; mTouchAboveFalsingThreshold = false; - mVelocityTracker.addMovement(event); + addMovement(event); break; case MotionEvent.ACTION_POINTER_UP: final int upPointer = event.getPointerId(event.getActionIndex()); @@ -593,7 +603,7 @@ public abstract class PanelView extends FrameLayout { break; case MotionEvent.ACTION_MOVE: final float h = y - mInitialTouchY; - mVelocityTracker.addMovement(event); + addMovement(event); if (scrolledToBottom || mTouchStartedInEmptyArea || mAnimatingOnDown) { float hAbs = Math.abs(h); if ((h < -mTouchSlop || (mAnimatingOnDown && hAbs > mTouchSlop))