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

Commit 1772969d authored by Robin Lee's avatar Robin Lee Committed by Automerger Merge Worker
Browse files

Merge "Sync wallpaper animation with unlock animation" into udc-dev am: 7ca6aef1 am: e02b69c2

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

    private var wallpaperAlpha = 1f

    @VisibleForTesting
    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
@@ -330,6 +328,7 @@ class KeyguardUnlockAnimationController @Inject constructor(
                    if (surfaceBehindAlpha == 0f) {
                        Log.d(TAG, "surfaceBehindAlphaAnimator#onAnimationEnd")
                        surfaceBehindRemoteAnimationTargets = null
                        wallpaperTargets = null
                        keyguardViewMediator.get().finishSurfaceBehindRemoteAnimation(
                            false /* cancelled */)
                    } else {
@@ -340,23 +339,17 @@ class KeyguardUnlockAnimationController @Inject constructor(
            })
        }

        with(wallpaperAlphaAnimator) {
        with(wallpaperCannedUnlockAnimator) {
            duration = LAUNCHER_ICONS_ANIMATION_DURATION_MS
            interpolator = Interpolators.ALPHA_OUT
            addUpdateListener { valueAnimator: ValueAnimator ->
                wallpaperAlpha = valueAnimator.animatedValue as Float
                setWallpaperAppearAmount(wallpaperAlpha)
                setWallpaperAppearAmount(valueAnimator.animatedValue as Float)
            }
            addListener(object : AnimatorListenerAdapter() {
                override fun onAnimationEnd(animation: Animator) {
                    Log.d(TAG, "wallpaperAlphaAnimator#onAnimationEnd, animation ended ")
                    if (wallpaperAlpha == 1f) {
                        wallpaperTargets = null
                        keyguardViewMediator.get().finishExitRemoteAnimation()
                    } else {
                        Log.d(TAG, "wallpaperAlphaAnimator#onAnimationEnd, " +
                                "animation was cancelled: skipping finishAnimation()")
                    }
                    Log.d(TAG, "wallpaperCannedUnlockAnimator#onAnimationEnd")
                    keyguardViewMediator.get().exitKeyguardAndFinishSurfaceBehindRemoteAnimation(
                        false /* cancelled */)
                }
            })
        }
@@ -387,11 +380,6 @@ class KeyguardUnlockAnimationController @Inject constructor(
            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.
     */
@@ -536,8 +524,6 @@ class KeyguardUnlockAnimationController @Inject constructor(
        wallpaperTargets = wallpapers
        surfaceBehindRemoteAnimationStartTime = startTime

        fadeInWallpaper()

        // 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
        // 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.
        // 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()
        if (!playingCannedUnlockAnimation) {
            finishKeyguardExitRemoteAnimationIfReachThreshold()
        }
    }

    /**
     * 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.
     */
    private fun unlockToLauncherWithInWindowAnimations() {
        setSurfaceBehindAppearAmount(1f)
        setSurfaceBehindAppearAmount(1f, wallpapers = false)

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

        // As soon as the shade has animated out of the way, finish the keyguard exit animation. The
        // in-window animations in the Launcher window will end on their own.
        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)
        // Start an animation for the wallpaper, which will finish keyguard exit when it completes.
        fadeInWallpaper()
    }

    /**
@@ -809,7 +786,16 @@ class KeyguardUnlockAnimationController @Inject constructor(
     * animations and swipe gestures to animate the surface's entry (and exit, if the swipe is
     * 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 ->
            val surfaceHeight: Int = surfaceBehindRemoteAnimationTarget.screenSpaceBounds.height()

@@ -839,16 +825,6 @@ class KeyguardUnlockAnimationController @Inject constructor(
                    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
            // unable to draw
            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) {
        wallpaperTargets?.forEach { wallpaper ->
        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
            else -> amount
        }

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

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

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

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

    private fun fadeOutSurfaceBehind() {
+0 −13
Original line number Diff line number Diff line
@@ -3009,19 +3009,6 @@ public class KeyguardViewMediator implements CoreStartable, Dumpable,
        mSurfaceBehindRemoteAnimationRequested = false;
        mSurfaceBehindRemoteAnimationRunning = 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) {
            try {
+0 −1
Original line number Diff line number Diff line
@@ -114,7 +114,6 @@ class KeyguardUnlockAnimationControllerTest : SysuiTestCase() {
    @After
    fun tearDown() {
        keyguardUnlockAnimationController.notifyFinishedKeyguardExitAnimation(true)
        keyguardUnlockAnimationController.wallpaperAlphaAnimator.cancel()
    }

    /**