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

Commit 4b6a4feb authored by Mady Mellor's avatar Mady Mellor Committed by Android (Google) Code Review
Browse files

Merge "Fix magnetized object fling detection" into main

parents bfebdaf0 72c5a9f3
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