diff options
3 files changed, 45 insertions, 7 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/SwipeHelper.java b/packages/SystemUI/src/com/android/systemui/SwipeHelper.java index 8af92ce4bcb1..806d1aff3a30 100644 --- a/packages/SystemUI/src/com/android/systemui/SwipeHelper.java +++ b/packages/SystemUI/src/com/android/systemui/SwipeHelper.java @@ -34,6 +34,7 @@ import android.app.PendingIntent; import android.content.res.Resources; import android.graphics.RectF; import android.os.Handler; +import android.os.Trace; import android.util.ArrayMap; import android.util.Log; import android.view.MotionEvent; @@ -277,9 +278,11 @@ public class SwipeHelper implements Gefingerpoken, Dumpable { // invalidate the view's own bounds all the way up the view hierarchy public static void invalidateGlobalRegion(View view) { + Trace.beginSection("SwipeHelper.invalidateGlobalRegion"); invalidateGlobalRegion( view, new RectF(view.getLeft(), view.getTop(), view.getRight(), view.getBottom())); + Trace.endSection(); } // invalidate a rectangle relative to the view's coordinate system all the way up the view @@ -492,7 +495,7 @@ public class SwipeHelper implements Gefingerpoken, Dumpable { } if (!mCancelled || wasRemoved) { mCallback.onChildDismissed(animView); - resetSwipeOfView(animView); + resetViewIfSwiping(animView); } if (endAction != null) { endAction.accept(mCancelled); @@ -547,7 +550,7 @@ public class SwipeHelper implements Gefingerpoken, Dumpable { if (!cancelled) { updateSwipeProgressFromOffset(animView, canBeDismissed); - resetSwipeOfView(animView); + resetViewIfSwiping(animView); // Clear the snapped view after success, assuming it's not being swiped now if (animView == mTouchedView && !mIsSwiping) { mTouchedView = null; @@ -811,7 +814,7 @@ public class SwipeHelper implements Gefingerpoken, Dumpable { return mIsSwiping ? mTouchedView : null; } - protected void resetSwipeOfView(View view) { + protected void resetViewIfSwiping(View view) { if (getSwipedView() == view) { resetSwipeState(); } @@ -825,6 +828,12 @@ public class SwipeHelper implements Gefingerpoken, Dumpable { resetSwipeStates(/* resetAll= */ true); } + public void forceResetSwipeState(@NonNull View view) { + if (view.getTranslationX() == 0) return; + setTranslation(view, 0); + updateSwipeProgressFromOffset(view, /* dismissable= */ true, 0); + } + /** This method resets the swipe state, and if `resetAll` is true, also resets the snap state */ private void resetSwipeStates(boolean resetAll) { final View touchedView = mTouchedView; diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationStackScrollLayout.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationStackScrollLayout.java index f7c6594e3a70..df6fe3d5e434 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationStackScrollLayout.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationStackScrollLayout.java @@ -4011,7 +4011,7 @@ public class NotificationStackScrollLayout extends ViewGroup implements Dumpable mCentralSurfaces.resetUserExpandedStates(); clearTemporaryViews(); clearUserLockedViews(); - cancelActiveSwipe(); + resetAllSwipeState(); } } @@ -4077,7 +4077,7 @@ public class NotificationStackScrollLayout extends ViewGroup implements Dumpable mGroupExpansionManager.collapseGroups(); mExpandHelper.cancelImmediately(); if (!mIsExpansionChanging) { - cancelActiveSwipe(); + resetAllSwipeState(); } finalizeClearAllAnimation(); } @@ -4406,7 +4406,7 @@ public class NotificationStackScrollLayout extends ViewGroup implements Dumpable boolean nowHiddenAtAll = mAmbientState.isHiddenAtAll(); if (nowFullyHidden != wasFullyHidden) { updateVisibility(); - mSwipeHelper.resetTouchState(); + resetAllSwipeState(); } if (!wasHiddenAtAll && nowHiddenAtAll) { resetExposedMenuView(true /* animate */, true /* animate */); @@ -5866,9 +5866,14 @@ public class NotificationStackScrollLayout extends ViewGroup implements Dumpable } } - private void cancelActiveSwipe() { + private void resetAllSwipeState() { + Trace.beginSection("NSSL.resetAllSwipeState()"); mSwipeHelper.resetTouchState(); + for (int i = 0; i < getChildCount(); i++) { + mSwipeHelper.forceResetSwipeState(getChildAt(i)); + } updateContinuousShadowDrawing(); + Trace.endSection(); } void updateContinuousShadowDrawing() { diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/stack/NotificationSwipeHelperTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/stack/NotificationSwipeHelperTest.java index 7632d01d4d43..df65c09eb8a9 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/stack/NotificationSwipeHelperTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/stack/NotificationSwipeHelperTest.java @@ -21,6 +21,7 @@ import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.ArgumentMatchers.anyFloat; import static org.mockito.ArgumentMatchers.anyInt; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.doReturn; @@ -29,6 +30,7 @@ import static org.mockito.Mockito.never; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoMoreInteractions; import static org.mockito.Mockito.when; import android.animation.Animator; @@ -670,6 +672,28 @@ public class NotificationSwipeHelperTest extends SysuiTestCase { } @Test + public void testForceResetSwipeStateDoesNothingIfTranslationIsZero() { + doReturn(FAKE_ROW_WIDTH).when(mNotificationRow).getMeasuredWidth(); + doReturn(0f).when(mNotificationRow).getTranslationX(); + + mSwipeHelper.forceResetSwipeState(mNotificationRow); + + verify(mNotificationRow).getTranslationX(); + verifyNoMoreInteractions(mNotificationRow); + } + + @Test + public void testForceResetSwipeStateResetsTranslationAndAlpha() { + doReturn(FAKE_ROW_WIDTH).when(mNotificationRow).getMeasuredWidth(); + doReturn(10f).when(mNotificationRow).getTranslationX(); + + mSwipeHelper.forceResetSwipeState(mNotificationRow); + + verify(mNotificationRow).setTranslation(eq(0f)); + verify(mNotificationRow).setContentAlpha(eq(1f)); + } + + @Test public void testContentAlphaRemainsUnchangedWhenFeatureFlagIsDisabled() { // Returning true prevents alpha fade. In an unmocked scenario the callback is instantiated |