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

Commit fd02ccb7 authored by Johannes Gallmann's avatar Johannes Gallmann
Browse files

Respect duration of custom cross activity back animation specs

Bug: 339440390
Flag: com.android.window.flags.predictive_back_system_anims NEXTFOOD
Test: Manual, i.e. testing different custom animation specs with various durations
Change-Id: I06f0570518aa20b2ced0c88acd9ad206ccd3db4f
parent c14c0eac
Loading
Loading
Loading
Loading
+7 −2
Original line number Diff line number Diff line
@@ -122,6 +122,11 @@ abstract class CrossActivityBackAnimation(
     */
    abstract fun preparePreCommitEnteringRectMovement()

    /**
     * Subclasses must provide a duration (in ms) for the post-commit part of the animation
     */
    abstract fun getPostCommitAnimationDuration(): Long

    /**
     * Returns a base transformation to apply to the entering target during pre-commit. The system
     * will apply the default animation on top of it.
@@ -260,7 +265,8 @@ abstract class CrossActivityBackAnimation(
            .setSpring(postCommitFlingSpring)
        flingAnimation.start()

        val valueAnimator = ValueAnimator.ofFloat(1f, 0f).setDuration(POST_COMMIT_DURATION)
        val valueAnimator =
            ValueAnimator.ofFloat(1f, 0f).setDuration(getPostCommitAnimationDuration())
        valueAnimator.addUpdateListener { animation: ValueAnimator ->
            val progress = animation.animatedFraction
            onPostCommitProgress(progress)
@@ -523,7 +529,6 @@ abstract class CrossActivityBackAnimation(
        internal const val MAX_SCALE = 0.9f
        private const val MAX_SCRIM_ALPHA_DARK = 0.8f
        private const val MAX_SCRIM_ALPHA_LIGHT = 0.2f
        private const val POST_COMMIT_DURATION = 300L
        private const val SPRING_SCALE = 100f
        private const val MAX_FLING_SCALE = 0.6f
    }
+33 −8
Original line number Diff line number Diff line
@@ -32,6 +32,8 @@ import com.android.wm.shell.RootTaskDisplayAreaOrganizer
import com.android.wm.shell.protolog.ShellProtoLogGroup
import com.android.wm.shell.shared.annotations.ShellMainThread
import javax.inject.Inject
import kotlin.math.max
import kotlin.math.min

/** Class that handles customized predictive cross activity back animations. */
@ShellMainThread
@@ -80,6 +82,12 @@ class CustomCrossActivityBackAnimation(
        targetEnteringRect.set(startClosingRect)
    }

    override fun getPostCommitAnimationDuration(): Long {
        return min(
            MAX_POST_COMMIT_ANIM_DURATION, max(closeAnimation!!.duration, enterAnimation!!.duration)
        )
    }

    override fun getPreCommitEnteringBaseTransformation(progress: Float): Transformation {
        gestureProgress = progress
        transformation.clear()
@@ -109,10 +117,13 @@ class CustomCrossActivityBackAnimation(
        super.onPostCommitProgress(linearProgress)
        if (closingTarget == null || enteringTarget == null) return

        // TODO: Should we use the duration from the custom xml spec for the post-commit animation?
        applyTransform(closingTarget!!.leash, currentClosingRect, linearProgress, closeAnimation!!)
        val enteringProgress =
            MathUtils.lerp(gestureProgress * PRE_COMMIT_MAX_PROGRESS, 1f, linearProgress)
        val closingProgress = closeAnimation!!.getPostCommitProgress(linearProgress)
        applyTransform(closingTarget!!.leash, currentClosingRect, closingProgress, closeAnimation!!)
        val enteringProgress = MathUtils.lerp(
            gestureProgress * PRE_COMMIT_MAX_PROGRESS,
            1f,
            enterAnimation!!.getPostCommitProgress(linearProgress)
        )
        applyTransform(
            enteringTarget!!.leash,
            currentEnteringRect,
@@ -159,6 +170,19 @@ class CustomCrossActivityBackAnimation(
        return false
    }

    private fun Animation.getPostCommitProgress(linearProgress: Float): Float {
        return when (duration) {
            0L -> 1f
            else -> min(
                1f,
                getPostCommitAnimationDuration() / min(
                    MAX_POST_COMMIT_ANIM_DURATION,
                    duration
                ).toFloat() * linearProgress
            )
        }
    }

    class AnimationLoadResult {
        var closeAnimation: Animation? = null
        var enterAnimation: Animation? = null
@@ -167,6 +191,7 @@ class CustomCrossActivityBackAnimation(

    companion object {
        private const val PRE_COMMIT_MAX_PROGRESS = 0.2f
        private const val MAX_POST_COMMIT_ANIM_DURATION = 2000L
    }
}

+7 −0
Original line number Diff line number Diff line
@@ -56,6 +56,8 @@ constructor(
        targetEnteringRect.scaleCentered(MAX_SCALE)
    }

    override fun getPostCommitAnimationDuration() = POST_COMMIT_DURATION

    override fun onGestureCommitted(velocity: Float) {
        // We enter phase 2 of the animation, the starting coordinates for phase 2 are the current
        // coordinate of the gesture driven phase. Let's update the start and target rects and kick
@@ -78,4 +80,9 @@ constructor(
        applyTransform(enteringTarget?.leash, currentEnteringRect, 1f)
        applyTransaction()
    }


    companion object {
        private const val POST_COMMIT_DURATION = 300L
    }
}