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

Commit 7ca6aef1 authored by Robin Lee's avatar Robin Lee Committed by Android (Google) Code Review
Browse files

Merge "Sync wallpaper animation with unlock animation" into udc-dev

parents 4a30c1d2 0ed572b2
Loading
Loading
Loading
Loading
+41 −64
Original line number Original line Diff line number Diff line
@@ -258,12 +258,10 @@ class KeyguardUnlockAnimationController @Inject constructor(
     */
     */
    private var surfaceBehindAlpha = 1f
    private var surfaceBehindAlpha = 1f


    private var wallpaperAlpha = 1f

    @VisibleForTesting
    @VisibleForTesting
    var surfaceBehindAlphaAnimator = ValueAnimator.ofFloat(0f, 1f)
    var surfaceBehindAlphaAnimator = ValueAnimator.ofFloat(0f, 1f)


    var wallpaperAlphaAnimator = ValueAnimator.ofFloat(0f, 1f)
    var wallpaperCannedUnlockAnimator = ValueAnimator.ofFloat(0f, 1f)


    /**
    /**
     * Matrix applied to [surfaceBehindRemoteAnimationTarget], which is the surface of the
     * Matrix applied to [surfaceBehindRemoteAnimationTarget], which is the surface of the
@@ -330,6 +328,7 @@ class KeyguardUnlockAnimationController @Inject constructor(
                    if (surfaceBehindAlpha == 0f) {
                    if (surfaceBehindAlpha == 0f) {
                        Log.d(TAG, "surfaceBehindAlphaAnimator#onAnimationEnd")
                        Log.d(TAG, "surfaceBehindAlphaAnimator#onAnimationEnd")
                        surfaceBehindRemoteAnimationTargets = null
                        surfaceBehindRemoteAnimationTargets = null
                        wallpaperTargets = null
                        keyguardViewMediator.get().finishSurfaceBehindRemoteAnimation(
                        keyguardViewMediator.get().finishSurfaceBehindRemoteAnimation(
                            false /* cancelled */)
                            false /* cancelled */)
                    } else {
                    } else {
@@ -340,23 +339,17 @@ class KeyguardUnlockAnimationController @Inject constructor(
            })
            })
        }
        }


        with(wallpaperAlphaAnimator) {
        with(wallpaperCannedUnlockAnimator) {
            duration = LAUNCHER_ICONS_ANIMATION_DURATION_MS
            duration = LAUNCHER_ICONS_ANIMATION_DURATION_MS
            interpolator = Interpolators.ALPHA_OUT
            interpolator = Interpolators.ALPHA_OUT
            addUpdateListener { valueAnimator: ValueAnimator ->
            addUpdateListener { valueAnimator: ValueAnimator ->
                wallpaperAlpha = valueAnimator.animatedValue as Float
                setWallpaperAppearAmount(valueAnimator.animatedValue as Float)
                setWallpaperAppearAmount(wallpaperAlpha)
            }
            }
            addListener(object : AnimatorListenerAdapter() {
            addListener(object : AnimatorListenerAdapter() {
                override fun onAnimationEnd(animation: Animator) {
                override fun onAnimationEnd(animation: Animator) {
                    Log.d(TAG, "wallpaperAlphaAnimator#onAnimationEnd, animation ended ")
                    Log.d(TAG, "wallpaperCannedUnlockAnimator#onAnimationEnd")
                    if (wallpaperAlpha == 1f) {
                    keyguardViewMediator.get().exitKeyguardAndFinishSurfaceBehindRemoteAnimation(
                        wallpaperTargets = null
                        false /* cancelled */)
                        keyguardViewMediator.get().finishExitRemoteAnimation()
                    } else {
                        Log.d(TAG, "wallpaperAlphaAnimator#onAnimationEnd, " +
                                "animation was cancelled: skipping finishAnimation()")
                    }
                }
                }
            })
            })
        }
        }
@@ -387,11 +380,6 @@ class KeyguardUnlockAnimationController @Inject constructor(
            context.resources.getDimensionPixelSize(R.dimen.rounded_corner_radius).toFloat()
            context.resources.getDimensionPixelSize(R.dimen.rounded_corner_radius).toFloat()
    }
    }


    fun isAnyKeyguyardAnimatorPlaying(): Boolean {
        return surfaceBehindAlphaAnimator.isStarted ||
                wallpaperAlphaAnimator.isStarted || surfaceBehindEntryAnimator.isStarted
    }

    /**
    /**
     * Add a listener to be notified of various stages of the unlock animation.
     * Add a listener to be notified of various stages of the unlock animation.
     */
     */
@@ -536,8 +524,6 @@ class KeyguardUnlockAnimationController @Inject constructor(
        wallpaperTargets = wallpapers
        wallpaperTargets = wallpapers
        surfaceBehindRemoteAnimationStartTime = startTime
        surfaceBehindRemoteAnimationStartTime = startTime


        fadeInWallpaper()

        // If we specifically requested that the surface behind be made visible (vs. it being made
        // If we specifically requested that the surface behind be made visible (vs. it being made
        // visible because we're unlocking), then we're in the middle of a swipe-to-unlock touch
        // visible because we're unlocking), then we're in the middle of a swipe-to-unlock touch
        // gesture and the surface behind the keyguard should be made visible so that we can animate
        // gesture and the surface behind the keyguard should be made visible so that we can animate
@@ -599,8 +585,10 @@ class KeyguardUnlockAnimationController @Inject constructor(
        // Finish the keyguard remote animation if the dismiss amount has crossed the threshold.
        // Finish the keyguard remote animation if the dismiss amount has crossed the threshold.
        // Check it here in case there is no more change to the dismiss amount after the last change
        // Check it here in case there is no more change to the dismiss amount after the last change
        // that starts the keyguard animation. @see #updateKeyguardViewMediatorIfThresholdsReached()
        // that starts the keyguard animation. @see #updateKeyguardViewMediatorIfThresholdsReached()
        if (!playingCannedUnlockAnimation) {
            finishKeyguardExitRemoteAnimationIfReachThreshold()
            finishKeyguardExitRemoteAnimationIfReachThreshold()
        }
        }
    }


    /**
    /**
     * Play a canned unlock animation to unlock the device. This is used when we were *not* swiping
     * Play a canned unlock animation to unlock the device. This is used when we were *not* swiping
@@ -650,7 +638,7 @@ class KeyguardUnlockAnimationController @Inject constructor(
     * transition if possible.
     * transition if possible.
     */
     */
    private fun unlockToLauncherWithInWindowAnimations() {
    private fun unlockToLauncherWithInWindowAnimations() {
        setSurfaceBehindAppearAmount(1f)
        setSurfaceBehindAppearAmount(1f, wallpapers = false)


        try {
        try {
            // Begin the animation, waiting for the shade to animate out.
            // Begin the animation, waiting for the shade to animate out.
@@ -676,19 +664,8 @@ class KeyguardUnlockAnimationController @Inject constructor(
        // visible, hide our smartspace.
        // visible, hide our smartspace.
        lockscreenSmartspace?.visibility = View.INVISIBLE
        lockscreenSmartspace?.visibility = View.INVISIBLE


        // As soon as the shade has animated out of the way, finish the keyguard exit animation. The
        // Start an animation for the wallpaper, which will finish keyguard exit when it completes.
        // in-window animations in the Launcher window will end on their own.
        fadeInWallpaper()
        handler.postDelayed({
            if (keyguardViewMediator.get().isShowingAndNotOccluded &&
                !keyguardStateController.isKeyguardGoingAway) {
                    Log.e(TAG, "Finish keyguard exit animation delayed Runnable ran, but we are " +
                            "showing and not going away.")
                return@postDelayed
            }

            keyguardViewMediator.get().exitKeyguardAndFinishSurfaceBehindRemoteAnimation(
                false /* cancelled */)
        }, CANNED_UNLOCK_START_DELAY)
    }
    }


    /**
    /**
@@ -809,7 +786,16 @@ class KeyguardUnlockAnimationController @Inject constructor(
     * animations and swipe gestures to animate the surface's entry (and exit, if the swipe is
     * animations and swipe gestures to animate the surface's entry (and exit, if the swipe is
     * cancelled).
     * cancelled).
     */
     */
    fun setSurfaceBehindAppearAmount(amount: Float) {
    fun setSurfaceBehindAppearAmount(amount: Float, wallpapers: Boolean = true) {
        val animationAlpha = when {
            // If we're snapping the keyguard back, immediately begin fading it out.
            keyguardStateController.isSnappingKeyguardBackAfterSwipe -> amount
            // If the screen has turned back off, the unlock animation is going to be cancelled,
            // so set the surface alpha to 0f so it's no longer visible.
            !powerManager.isInteractive -> 0f
            else -> surfaceBehindAlpha
        }

        surfaceBehindRemoteAnimationTargets?.forEach { surfaceBehindRemoteAnimationTarget ->
        surfaceBehindRemoteAnimationTargets?.forEach { surfaceBehindRemoteAnimationTarget ->
            val surfaceHeight: Int = surfaceBehindRemoteAnimationTarget.screenSpaceBounds.height()
            val surfaceHeight: Int = surfaceBehindRemoteAnimationTarget.screenSpaceBounds.height()


@@ -839,16 +825,6 @@ class KeyguardUnlockAnimationController @Inject constructor(
                    surfaceHeight * SURFACE_BEHIND_SCALE_PIVOT_Y
                    surfaceHeight * SURFACE_BEHIND_SCALE_PIVOT_Y
            )
            )



            val animationAlpha = when {
                // If we're snapping the keyguard back, immediately begin fading it out.
                keyguardStateController.isSnappingKeyguardBackAfterSwipe -> amount
                // If the screen has turned back off, the unlock animation is going to be cancelled,
                // so set the surface alpha to 0f so it's no longer visible.
                !powerManager.isInteractive -> 0f
                else -> surfaceBehindAlpha
            }

            // SyncRtSurfaceTransactionApplier cannot apply transaction when the target view is
            // SyncRtSurfaceTransactionApplier cannot apply transaction when the target view is
            // unable to draw
            // unable to draw
            val sc: SurfaceControl? = surfaceBehindRemoteAnimationTarget.leash
            val sc: SurfaceControl? = surfaceBehindRemoteAnimationTarget.leash
@@ -871,20 +847,19 @@ class KeyguardUnlockAnimationController @Inject constructor(
                )
                )
            }
            }
        }
        }

        if (wallpapers) {
            setWallpaperAppearAmount(amount)
        }
    }
    }


    /**
     * Modify the opacity of a wallpaper window.
     */
    fun setWallpaperAppearAmount(amount: Float) {
    fun setWallpaperAppearAmount(amount: Float) {
        wallpaperTargets?.forEach { wallpaper ->
        val animationAlpha = when {
        val animationAlpha = when {
                // If the screen has turned back off, the unlock animation is going to be cancelled,
                // so set the surface alpha to 0f so it's no longer visible.
            !powerManager.isInteractive -> 0f
            !powerManager.isInteractive -> 0f
            else -> amount
            else -> amount
        }
        }


        wallpaperTargets?.forEach { wallpaper ->
            // SyncRtSurfaceTransactionApplier cannot apply transaction when the target view is
            // SyncRtSurfaceTransactionApplier cannot apply transaction when the target view is
            // unable to draw
            // unable to draw
            val sc: SurfaceControl? = wallpaper.leash
            val sc: SurfaceControl? = wallpaper.leash
@@ -923,6 +898,7 @@ class KeyguardUnlockAnimationController @Inject constructor(
        setSurfaceBehindAppearAmount(1f)
        setSurfaceBehindAppearAmount(1f)
        surfaceBehindAlphaAnimator.cancel()
        surfaceBehindAlphaAnimator.cancel()
        surfaceBehindEntryAnimator.cancel()
        surfaceBehindEntryAnimator.cancel()
        wallpaperCannedUnlockAnimator.cancel()
        try {
        try {
            launcherUnlockController?.setUnlockAmount(1f, false /* forceIfAnimating */)
            launcherUnlockController?.setUnlockAmount(1f, false /* forceIfAnimating */)
        } catch (e: RemoteException) {
        } catch (e: RemoteException) {
@@ -931,6 +907,7 @@ class KeyguardUnlockAnimationController @Inject constructor(


        // That target is no longer valid since the animation finished, null it out.
        // That target is no longer valid since the animation finished, null it out.
        surfaceBehindRemoteAnimationTargets = null
        surfaceBehindRemoteAnimationTargets = null
        wallpaperTargets = null


        playingCannedUnlockAnimation = false
        playingCannedUnlockAnimation = false
        willUnlockWithInWindowLauncherAnimations = false
        willUnlockWithInWindowLauncherAnimations = false
@@ -972,8 +949,8 @@ class KeyguardUnlockAnimationController @Inject constructor(


    private fun fadeInWallpaper() {
    private fun fadeInWallpaper() {
        Log.d(TAG, "fadeInWallpaper")
        Log.d(TAG, "fadeInWallpaper")
        wallpaperAlphaAnimator.cancel()
        wallpaperCannedUnlockAnimator.cancel()
        wallpaperAlphaAnimator.start()
        wallpaperCannedUnlockAnimator.start()
    }
    }


    private fun fadeOutSurfaceBehind() {
    private fun fadeOutSurfaceBehind() {
+0 −13
Original line number Original line Diff line number Diff line
@@ -3009,19 +3009,6 @@ public class KeyguardViewMediator implements CoreStartable, Dumpable,
        mSurfaceBehindRemoteAnimationRequested = false;
        mSurfaceBehindRemoteAnimationRequested = false;
        mSurfaceBehindRemoteAnimationRunning = false;
        mSurfaceBehindRemoteAnimationRunning = false;
        mKeyguardStateController.notifyKeyguardGoingAway(false);
        mKeyguardStateController.notifyKeyguardGoingAway(false);
        finishExitRemoteAnimation();
    }

    void finishExitRemoteAnimation() {
        if (mKeyguardUnlockAnimationControllerLazy.get().isAnyKeyguyardAnimatorPlaying()
                || mKeyguardStateController.isDismissingFromSwipe()) {
            // If the animation is ongoing, or we are not done with the swipe gesture,
            // it's too early to terminate the animation
            Log.d(TAG, "finishAnimation not executing now because "
                    + "not all animations have finished");
            return;
        }
        Log.d(TAG, "finishAnimation executing");


        if (mSurfaceBehindRemoteAnimationFinishedCallback != null) {
        if (mSurfaceBehindRemoteAnimationFinishedCallback != null) {
            try {
            try {
+0 −1
Original line number Original line Diff line number Diff line
@@ -114,7 +114,6 @@ class KeyguardUnlockAnimationControllerTest : SysuiTestCase() {
    @After
    @After
    fun tearDown() {
    fun tearDown() {
        keyguardUnlockAnimationController.notifyFinishedKeyguardExitAnimation(true)
        keyguardUnlockAnimationController.notifyFinishedKeyguardExitAnimation(true)
        keyguardUnlockAnimationController.wallpaperAlphaAnimator.cancel()
    }
    }


    /**
    /**