From d0c700fc61eee2ab515e4ea6d26ec28e8dc54571 Mon Sep 17 00:00:00 2001 From: Lucas Silva Date: Thu, 24 Mar 2022 15:14:16 -0400 Subject: [PATCH] Fix bouncer swipe touch handler This fix takes the direction of the swipe into account, depending on if the bouncer is showing or not. This prevents downward swipes from showing the bouncer. Test: atest BouncerSwipeTouchHandlerTest Test: manually on device Bug: 224996347 Change-Id: I33a7bbd0ca466bdb3412103454d7a2ad57cdcd09 --- .../systemui/dreams/touch/BouncerSwipeTouchHandler.java | 6 ++++-- .../systemui/dreams/touch/BouncerSwipeTouchHandlerTest.java | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/dreams/touch/BouncerSwipeTouchHandler.java b/packages/SystemUI/src/com/android/systemui/dreams/touch/BouncerSwipeTouchHandler.java index 1b62ec4772f35..f85d18332cbd4 100644 --- a/packages/SystemUI/src/com/android/systemui/dreams/touch/BouncerSwipeTouchHandler.java +++ b/packages/SystemUI/src/com/android/systemui/dreams/touch/BouncerSwipeTouchHandler.java @@ -116,8 +116,10 @@ public class BouncerSwipeTouchHandler implements DreamTouchHandler { // bouncer. As that view's expansion shrinks, the bouncer appears. The bouncer // is fully hidden at full expansion (1) and fully visible when fully collapsed // (0). - final float screenTravelPercentage = - Math.abs((e1.getY() - e2.getY()) / mCentralSurfaces.getDisplayHeight()); + final float dy = mBouncerInitiallyShowing ? e2.getY() - e1.getY() + : e1.getY() - e2.getY(); + final float screenTravelPercentage = Math.max(0, + dy / mCentralSurfaces.getDisplayHeight()); setPanelExpansion(mBouncerInitiallyShowing ? screenTravelPercentage : 1 - screenTravelPercentage); return true; diff --git a/packages/SystemUI/tests/src/com/android/systemui/dreams/touch/BouncerSwipeTouchHandlerTest.java b/packages/SystemUI/tests/src/com/android/systemui/dreams/touch/BouncerSwipeTouchHandlerTest.java index b08dd57f1c98b..d420ca1556509 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/dreams/touch/BouncerSwipeTouchHandlerTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/dreams/touch/BouncerSwipeTouchHandlerTest.java @@ -234,9 +234,9 @@ public class BouncerSwipeTouchHandlerTest extends SysuiTestCase { final float distanceY = SCREEN_HEIGHT_PX * scrollAmount; final MotionEvent event1 = MotionEvent.obtain(0, 0, MotionEvent.ACTION_MOVE, - 0, SCREEN_HEIGHT_PX, 0); - final MotionEvent event2 = MotionEvent.obtain(0, 0, MotionEvent.ACTION_MOVE, 0, SCREEN_HEIGHT_PX - distanceY, 0); + final MotionEvent event2 = MotionEvent.obtain(0, 0, MotionEvent.ACTION_MOVE, + 0, SCREEN_HEIGHT_PX, 0); assertThat(gestureListenerCaptor.getValue().onScroll(event1, event2, 0, distanceY)) .isTrue();