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

Commit 45dc5c09 authored by mattsziklay's avatar mattsziklay
Browse files

Set position during shrink animation.

When performing a drag to desktop, the initial task shrinking animation
sets scale via an animation and position based on input. This resulted
in the task moving away from the pointer if the pointer stopped moving,
as only scale would be updated.

This CL changes the positioning such that scale and position are updated
at the same time while the task is animating, keeping the handle under
the pointer as it is dragged.

Bug: 315520199
Test: Manual, drag with both finger and mouse
Change-Id: I2efdb85dba54b5e8b4536b471c3ff07388f6add8
parent d26ee5b9
Loading
Loading
Loading
Loading
+20 −6
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@ class MoveToDesktopAnimator @JvmOverloads constructor(
        get() = dragToDesktopAnimator.animatedValue as Float * startBounds.width()
    val scale: Float
        get() = dragToDesktopAnimator.animatedValue as Float
    private val mostRecentInput = PointF()
    private val dragToDesktopAnimator: ValueAnimator = ValueAnimator.ofFloat(1f,
            DRAG_FREEFORM_SCALE)
            .setDuration(ANIMATION_DURATION.toLong())
@@ -40,8 +41,12 @@ class MoveToDesktopAnimator @JvmOverloads constructor(
                val t = SurfaceControl.Transaction()
                val cornerRadius = ScreenDecorationsUtils.getWindowCornerRadius(context)
                addUpdateListener {
                    setTaskPosition(mostRecentInput.x, mostRecentInput.y)
                    t.setScale(taskSurface, scale, scale)
                        .setCornerRadius(taskSurface, cornerRadius)
                        .setScale(taskSurface, scale, scale)
                        .setCornerRadius(taskSurface, cornerRadius)
                        .setPosition(taskSurface, position.x, position.y)
                        .apply()
                }
            }
@@ -78,18 +83,27 @@ class MoveToDesktopAnimator @JvmOverloads constructor(
        // allow dragging beyond its stage across any region of the display. Because of that, the
        // rawX/Y are more true to where the gesture is on screen and where the surface should be
        // positioned.
        position.x = ev.rawX - animatedTaskWidth / 2
        position.y = ev.rawY
        mostRecentInput.set(ev.rawX, ev.rawY)

        if (!allowSurfaceChangesOnMove) {
        // If animator is running, allow it to set scale and position at the same time.
        if (!allowSurfaceChangesOnMove || dragToDesktopAnimator.isRunning) {
            return
        }

        setTaskPosition(ev.rawX, ev.rawY)
        val t = transactionFactory()
        t.setPosition(taskSurface, position.x, position.y)
        t.apply()
    }

    /**
     * Calculates the top left corner of task from input coordinates.
     * Top left will be needed for the resulting surface control transaction.
     */
    private fun setTaskPosition(x: Float, y: Float) {
        position.x = x - animatedTaskWidth / 2
        position.y = y
    }

    /**
     * Cancels the animation, intended to be used when another animator will take over.
     */