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

Commit 49821a8e authored by Luca Zuccarini's avatar Luca Zuccarini Committed by Automerger Merge Worker
Browse files

Merge "Make ActivityLaunchAnimator.Runner usable independently." into...

Merge "Make ActivityLaunchAnimator.Runner usable independently." into tm-qpr-dev am: ea07279e am: d5b2b20b

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/20710346



Change-Id: I0e84becdb873c5cdbcb3bba3a5989357b7196f6d
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 05d642a0 d5b2b20b
Loading
Loading
Loading
Loading
+47 −20
Original line number Original line Diff line number Diff line
@@ -49,12 +49,12 @@ private const val TAG = "ActivityLaunchAnimator"
 */
 */
class ActivityLaunchAnimator(
class ActivityLaunchAnimator(
    /** The animator used when animating a View into an app. */
    /** The animator used when animating a View into an app. */
    private val launchAnimator: LaunchAnimator = LaunchAnimator(TIMINGS, INTERPOLATORS),
    private val launchAnimator: LaunchAnimator = DEFAULT_LAUNCH_ANIMATOR,


    /** The animator used when animating a Dialog into an app. */
    /** The animator used when animating a Dialog into an app. */
    // TODO(b/218989950): Remove this animator and instead set the duration of the dim fade out to
    // TODO(b/218989950): Remove this animator and instead set the duration of the dim fade out to
    // TIMINGS.contentBeforeFadeOutDuration.
    // TIMINGS.contentBeforeFadeOutDuration.
    private val dialogToAppAnimator: LaunchAnimator = LaunchAnimator(DIALOG_TIMINGS, INTERPOLATORS)
    private val dialogToAppAnimator: LaunchAnimator = DEFAULT_DIALOG_TO_APP_ANIMATOR
) {
) {
    companion object {
    companion object {
        /** The timings when animating a View into an app. */
        /** The timings when animating a View into an app. */
@@ -85,6 +85,9 @@ class ActivityLaunchAnimator(
                contentAfterFadeInInterpolator = PathInterpolator(0f, 0f, 0.6f, 1f)
                contentAfterFadeInInterpolator = PathInterpolator(0f, 0f, 0.6f, 1f)
            )
            )


        private val DEFAULT_LAUNCH_ANIMATOR = LaunchAnimator(TIMINGS, INTERPOLATORS)
        private val DEFAULT_DIALOG_TO_APP_ANIMATOR = LaunchAnimator(DIALOG_TIMINGS, INTERPOLATORS)

        /** Durations & interpolators for the navigation bar fading in & out. */
        /** Durations & interpolators for the navigation bar fading in & out. */
        private const val ANIMATION_DURATION_NAV_FADE_IN = 266L
        private const val ANIMATION_DURATION_NAV_FADE_IN = 266L
        private const val ANIMATION_DURATION_NAV_FADE_OUT = 133L
        private const val ANIMATION_DURATION_NAV_FADE_OUT = 133L
@@ -117,6 +120,22 @@ class ActivityLaunchAnimator(
    /** The set of [Listener] that should be notified of any animation started by this animator. */
    /** The set of [Listener] that should be notified of any animation started by this animator. */
    private val listeners = LinkedHashSet<Listener>()
    private val listeners = LinkedHashSet<Listener>()


    /** Top-level listener that can be used to notify all registered [listeners]. */
    private val lifecycleListener =
        object : Listener {
            override fun onLaunchAnimationStart() {
                listeners.forEach { it.onLaunchAnimationStart() }
            }

            override fun onLaunchAnimationEnd() {
                listeners.forEach { it.onLaunchAnimationEnd() }
            }

            override fun onLaunchAnimationProgress(linearProgress: Float) {
                listeners.forEach { it.onLaunchAnimationProgress(linearProgress) }
            }
        }

    /**
    /**
     * Start an intent and animate the opening window. The intent will be started by running
     * Start an intent and animate the opening window. The intent will be started by running
     * [intentStarter], which should use the provided [RemoteAnimationAdapter] and return the launch
     * [intentStarter], which should use the provided [RemoteAnimationAdapter] and return the launch
@@ -156,7 +175,7 @@ class ActivityLaunchAnimator(
                ?: throw IllegalStateException(
                ?: throw IllegalStateException(
                    "ActivityLaunchAnimator.callback must be set before using this animator"
                    "ActivityLaunchAnimator.callback must be set before using this animator"
                )
                )
        val runner = Runner(controller)
        val runner = createRunner(controller)
        val hideKeyguardWithAnimation = callback.isOnKeyguard() && !showOverLockscreen
        val hideKeyguardWithAnimation = callback.isOnKeyguard() && !showOverLockscreen


        // Pass the RemoteAnimationAdapter to the intent starter only if we are not hiding the
        // Pass the RemoteAnimationAdapter to the intent starter only if we are not hiding the
@@ -256,7 +275,18 @@ class ActivityLaunchAnimator(
    }
    }


    /** Create a new animation [Runner] controlled by [controller]. */
    /** Create a new animation [Runner] controlled by [controller]. */
    @VisibleForTesting fun createRunner(controller: Controller): Runner = Runner(controller)
    @VisibleForTesting
    fun createRunner(controller: Controller): Runner {
        // Make sure we use the modified timings when animating a dialog into an app.
        val launchAnimator =
            if (controller.isDialogLaunch) {
                dialogToAppAnimator
            } else {
                launchAnimator
            }

        return Runner(controller, callback!!, launchAnimator, lifecycleListener)
    }


    interface PendingIntentStarter {
    interface PendingIntentStarter {
        /**
        /**
@@ -353,14 +383,20 @@ class ActivityLaunchAnimator(
         * this if the animation was already started, i.e. if [onLaunchAnimationStart] was called
         * this if the animation was already started, i.e. if [onLaunchAnimationStart] was called
         * before the cancellation.
         * before the cancellation.
         *
         *
         * If this launch animation affected the occlusion state of the keyguard, WM will provide
         * If this launch animation affected the occlusion state of the keyguard, WM will provide us
         * us with [newKeyguardOccludedState] so that we can set the occluded state appropriately.
         * with [newKeyguardOccludedState] so that we can set the occluded state appropriately.
         */
         */
        fun onLaunchAnimationCancelled(newKeyguardOccludedState: Boolean? = null) {}
        fun onLaunchAnimationCancelled(newKeyguardOccludedState: Boolean? = null) {}
    }
    }


    @VisibleForTesting
    class Runner(
    inner class Runner(private val controller: Controller) : IRemoteAnimationRunner.Stub() {
        private val controller: Controller,
        private val callback: Callback,
        /** The animator to use to animate the window launch. */
        private val launchAnimator: LaunchAnimator = DEFAULT_LAUNCH_ANIMATOR,
        /** Listener for animation lifecycle events. */
        private val listener: Listener? = null
    ) : IRemoteAnimationRunner.Stub() {
        private val launchContainer = controller.launchContainer
        private val launchContainer = controller.launchContainer
        private val context = launchContainer.context
        private val context = launchContainer.context
        private val transactionApplierView =
        private val transactionApplierView =
@@ -448,18 +484,9 @@ class ActivityLaunchAnimator(
                    left = windowBounds.left,
                    left = windowBounds.left,
                    right = windowBounds.right
                    right = windowBounds.right
                )
                )
            val callback = this@ActivityLaunchAnimator.callback!!
            val windowBackgroundColor =
            val windowBackgroundColor =
                window.taskInfo?.let { callback.getBackgroundColor(it) } ?: window.backgroundColor
                window.taskInfo?.let { callback.getBackgroundColor(it) } ?: window.backgroundColor


            // Make sure we use the modified timings when animating a dialog into an app.
            val launchAnimator =
                if (controller.isDialogLaunch) {
                    dialogToAppAnimator
                } else {
                    launchAnimator
                }

            // TODO(b/184121838): We should somehow get the top and bottom radius of the window
            // TODO(b/184121838): We should somehow get the top and bottom radius of the window
            // instead of recomputing isExpandingFullyAbove here.
            // instead of recomputing isExpandingFullyAbove here.
            val isExpandingFullyAbove =
            val isExpandingFullyAbove =
@@ -483,12 +510,12 @@ class ActivityLaunchAnimator(
            val controller =
            val controller =
                object : Controller by delegate {
                object : Controller by delegate {
                    override fun onLaunchAnimationStart(isExpandingFullyAbove: Boolean) {
                    override fun onLaunchAnimationStart(isExpandingFullyAbove: Boolean) {
                        listeners.forEach { it.onLaunchAnimationStart() }
                        listener?.onLaunchAnimationStart()
                        delegate.onLaunchAnimationStart(isExpandingFullyAbove)
                        delegate.onLaunchAnimationStart(isExpandingFullyAbove)
                    }
                    }


                    override fun onLaunchAnimationEnd(isExpandingFullyAbove: Boolean) {
                    override fun onLaunchAnimationEnd(isExpandingFullyAbove: Boolean) {
                        listeners.forEach { it.onLaunchAnimationEnd() }
                        listener?.onLaunchAnimationEnd()
                        iCallback?.invoke()
                        iCallback?.invoke()
                        delegate.onLaunchAnimationEnd(isExpandingFullyAbove)
                        delegate.onLaunchAnimationEnd(isExpandingFullyAbove)
                    }
                    }
@@ -505,7 +532,7 @@ class ActivityLaunchAnimator(
                        }
                        }
                        navigationBar?.let { applyStateToNavigationBar(it, state, linearProgress) }
                        navigationBar?.let { applyStateToNavigationBar(it, state, linearProgress) }


                        listeners.forEach { it.onLaunchAnimationProgress(linearProgress) }
                        listener?.onLaunchAnimationProgress(linearProgress)
                        delegate.onLaunchAnimationProgress(state, progress, linearProgress)
                        delegate.onLaunchAnimationProgress(state, progress, linearProgress)
                    }
                    }
                }
                }