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

Commit aa68525a authored by Matt Casey's avatar Matt Casey
Browse files

Apply touch velocity to screenshot UI on dismissal ACTION_UP

Previously ACTION_UP would initiate the dismissal animation, but would
not update the location the the UI based upon the time elapsed since the
last ACTION_MOVE last caused an update to the UI location.

Bug: 413411582
Test: Manual swipe test across small/large screens, observing smoother
      transition from touch to animation.
Flag: EXEMPT narrow bugfix
Change-Id: I1338ddd7d92ef61d38357d6babe30ea990109c38
parent 3fe29ca3
Loading
Loading
Loading
Loading
+15 −0
Original line number Diff line number Diff line
@@ -31,6 +31,8 @@ class SwipeGestureListener(
    private val displayMetrics = view.resources.displayMetrics

    private var startX = 0f
    private var previousX = 0f
    private var previousTime = 0L

    fun onMotionEvent(ev: MotionEvent): Boolean {
        ev.offsetLocation(view.translationX, 0f)
@@ -38,10 +40,20 @@ class SwipeGestureListener(
            MotionEvent.ACTION_DOWN -> {
                velocityTracker.addMovement(ev)
                startX = ev.rawX
                previousX = ev.rawX
                previousTime = ev.eventTime
            }
            MotionEvent.ACTION_UP -> {

                velocityTracker.computeCurrentVelocity(1)
                val xVelocity = velocityTracker.xVelocity

                val dt = ev.eventTime - previousTime
                // Apply the velocity for the time elapsed since the last translation (the animation
                // will not start immediately and doesn't know how much time has passed since the
                // last ACTION_MOVE).
                view.translationX = previousX + xVelocity * dt - startX

                if (
                    abs(xVelocity) > FloatingWindowUtil.dpToPx(displayMetrics, FLING_THRESHOLD_DP)
                ) {
@@ -61,6 +73,9 @@ class SwipeGestureListener(
            MotionEvent.ACTION_MOVE -> {
                velocityTracker.addMovement(ev)
                view.translationX = ev.rawX - startX

                previousX = ev.rawX
                previousTime = ev.eventTime
            }
        }
        return false