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

Commit 2339349d authored by Matt Sziklay's avatar Matt Sziklay Committed by Android (Google) Code Review
Browse files

Merge "Set position during shrink animation." into main

parents 1cb28c18 45dc5c09
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.
     */