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

Commit 72c5a9f3 authored by Liran Binyamin's avatar Liran Binyamin
Browse files

Fix magnetized object fling detection

When releasing a dragged object below the magnetized object but
close to it with low velocity (or 0 velocity), we currently
detect it as flinging towards the magnetized target. This change
updates the logic to check that velocity is high and in the direction
of the target.

Fix: 429108959
Flag: EXEMPT bug fix
Test: atest MagnetizedObjectTest
Test: manual
       - create bubble in bubble bar
       - drag bubble to dismiss target
       - drag outside below the center
       - release bubble
       - observe bubble animate back to bubble bar
Test: manual
       - create floating bubble
       - fling around and verify that fling behavior works as expected
       - repeat the same test as described above for bubble bar and
         verify fling is detected correctly
Change-Id: I52a874db27a7ad47f4f5d76c71f8a100ce0073dc
parent d712f1a6
Loading
Loading
Loading
Loading
+5 −2
Original line number Diff line number Diff line
@@ -548,8 +548,11 @@ abstract class MagnetizedObject<T : Any>(
        // Whether velocity is sufficient, depending on whether we're flinging into a target at the
        // top or the bottom of the screen.
        val velocitySufficient =
                if (rawY < target.centerOnDisplayY()) velY > flingToTargetMinVelocity
                else velY < flingToTargetMinVelocity
            if (rawY < target.centerOnDisplayY()) {
                velY > flingToTargetMinVelocity
            } else {
                velY < -flingToTargetMinVelocity
            }

        if (!velocitySufficient) {
            return false
+21 −1
Original line number Diff line number Diff line
@@ -298,7 +298,7 @@ class MagnetizedObjectTest : ShellTestCase() {
    }

    @Test
    fun testFlingTowardsTarget_towardsButTooSlow() {
    fun testFlingTowardsTarget_downTowardsButTooSlow() {
        // Very, very slowly fling the object towards the target (but never touch the magnetic
        // field). This value is only used to create MotionEvent timestamps, it will not block the
        // test for 10 seconds.
@@ -320,6 +320,26 @@ class MagnetizedObjectTest : ShellTestCase() {
        verifyNoMoreInteractions(magnetListener)
    }

    @Test
    fun testFlingTowardsTarget_upTowardsButTooSlow() {
        timeStep = 10000
        dispatchMotionEvents(
            getMotionEvent(
                x = targetCenterX,
                y = targetCenterY * 2,
                action = MotionEvent.ACTION_DOWN),
            getMotionEvent(
                x = targetCenterX,
                y = (targetCenterY * 1.5).toInt()),
            getMotionEvent(
                x = targetCenterX,
                y = targetCenterY + magneticFieldRadius * 2,
                action = MotionEvent.ACTION_UP))

        // No sticking should have occurred.
        verifyNoMoreInteractions(magnetListener)
    }

    @Test
    fun testFlingTowardsTarget_missTarget() {
        timeStep = 10