Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e9a3ef94 authored by Juan Sebastian Martinez's avatar Juan Sebastian Martinez
Browse files

Dismissing with correct velocity when flinging and not detaching.

If the user flings a notification without detaching it, the detach
direction should be 0. In this case, the SwipeHelper should use an
unmodified velocity to run the dismiss animation. At the same time, the
internal direction estimator of MagneticRowManagerImpl should reset the
direction to 0 when called to reset()

Test: manual. Verified notifications dismiss in the correct direction
  when flinging right and left without magnetic detachtments.
Test: added Unit test
Flag: com.android.systemui.magnetic_notification_swipes
Bug: 416012576
Change-Id: Ibac2d86499340e013c42dbf897e5eb72637c1041
parent 1cd751d8
Loading
Loading
Loading
Loading
+19 −0
Original line number Diff line number Diff line
@@ -488,6 +488,25 @@ class MagneticNotificationRowManagerImplTest : SysuiTestCase() {
            assertThat(detachDirection).isEqualTo(-1)
        }

    @Test
    fun getDetachDirection_afterADismissal_returnsCorrectDirection() =
        kosmos.testScope.runTest {
            // GIVEN that the swiped row is detached to the right
            setDetachedState()
            assertThat(underTest.getDetachDirection(swipedRow)).isEqualTo(1)

            // GIVEN that the notification is dismissed
            underTest.onMagneticInteractionEnd(swipedRow, dismissing = true, velocity = 5000f)

            // WHEN we begin interacting with another row
            swipedRow = children.attachedChildren.first()
            setTargets()
            underTest.setMagneticRowTranslation(swipedRow, translation = 100f)

            // THEN the detach direction is 0
            assertThat(underTest.getDetachDirection(swipedRow)).isEqualTo(0)
        }

    @After
    fun tearDown() {
        // We reset the manager so that all MagneticRowListener can cancel all animations
+4 −1
Original line number Diff line number Diff line
@@ -429,8 +429,11 @@ public class SwipeHelper implements Gefingerpoken, Dumpable {
            boolean isDismissAll) {
        if (magneticNotificationSwipes()) {
            int direction = mCallback.getMagneticDetachDirection(animView);
            if (direction != 0) {
                // If detached, modify the velocity to agree with the detaching direction
                velocity = direction * Math.max(getMinDismissVelocity(), Math.abs(velocity));
            }
        }
        final boolean canBeDismissed = mCallback.canChildBeDismissed(animView);
        float newPos;
        boolean isLayoutRtl = animView.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL;
+1 −0
Original line number Diff line number Diff line
@@ -484,6 +484,7 @@ constructor(
        }

        fun reset() {
            direction = 0f
            translationBuffer.clear()
            acceptTranslations = true
        }