Merge "Introduce RemoteAnimationDelegate." into tm-qpr-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
42313920fb
@@ -37,6 +37,8 @@ import android.view.ViewGroup
|
|||||||
import android.view.WindowManager
|
import android.view.WindowManager
|
||||||
import android.view.animation.Interpolator
|
import android.view.animation.Interpolator
|
||||||
import android.view.animation.PathInterpolator
|
import android.view.animation.PathInterpolator
|
||||||
|
import androidx.annotation.BinderThread
|
||||||
|
import androidx.annotation.UiThread
|
||||||
import com.android.internal.annotations.VisibleForTesting
|
import com.android.internal.annotations.VisibleForTesting
|
||||||
import com.android.internal.policy.ScreenDecorationsUtils
|
import com.android.internal.policy.ScreenDecorationsUtils
|
||||||
import kotlin.math.roundToInt
|
import kotlin.math.roundToInt
|
||||||
@@ -226,7 +228,7 @@ class ActivityLaunchAnimator(
|
|||||||
// If we expect an animation, post a timeout to cancel it in case the remote animation is
|
// If we expect an animation, post a timeout to cancel it in case the remote animation is
|
||||||
// never started.
|
// never started.
|
||||||
if (willAnimate) {
|
if (willAnimate) {
|
||||||
runner.postTimeout()
|
runner.delegate.postTimeout()
|
||||||
|
|
||||||
// Hide the keyguard using the launch animation instead of the default unlock animation.
|
// Hide the keyguard using the launch animation instead of the default unlock animation.
|
||||||
if (hideKeyguardWithAnimation) {
|
if (hideKeyguardWithAnimation) {
|
||||||
@@ -389,14 +391,51 @@ class ActivityLaunchAnimator(
|
|||||||
fun onLaunchAnimationCancelled(newKeyguardOccludedState: Boolean? = null) {}
|
fun onLaunchAnimationCancelled(newKeyguardOccludedState: Boolean? = null) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Runner(
|
@VisibleForTesting
|
||||||
|
inner class Runner(
|
||||||
|
controller: Controller,
|
||||||
|
callback: Callback,
|
||||||
|
/** The animator to use to animate the window launch. */
|
||||||
|
launchAnimator: LaunchAnimator = DEFAULT_LAUNCH_ANIMATOR,
|
||||||
|
/** Listener for animation lifecycle events. */
|
||||||
|
listener: Listener? = null
|
||||||
|
) : IRemoteAnimationRunner.Stub() {
|
||||||
|
private val context = controller.launchContainer.context
|
||||||
|
internal val delegate: AnimationDelegate
|
||||||
|
|
||||||
|
init {
|
||||||
|
delegate = AnimationDelegate(controller, callback, launchAnimator, listener)
|
||||||
|
}
|
||||||
|
|
||||||
|
@BinderThread
|
||||||
|
override fun onAnimationStart(
|
||||||
|
transit: Int,
|
||||||
|
apps: Array<out RemoteAnimationTarget>?,
|
||||||
|
wallpapers: Array<out RemoteAnimationTarget>?,
|
||||||
|
nonApps: Array<out RemoteAnimationTarget>?,
|
||||||
|
finishedCallback: IRemoteAnimationFinishedCallback?
|
||||||
|
) {
|
||||||
|
context.mainExecutor.execute {
|
||||||
|
delegate.onAnimationStart(transit, apps, wallpapers, nonApps, finishedCallback)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@BinderThread
|
||||||
|
override fun onAnimationCancelled(isKeyguardOccluded: Boolean) {
|
||||||
|
context.mainExecutor.execute { delegate.onAnimationCancelled(isKeyguardOccluded) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class AnimationDelegate
|
||||||
|
@JvmOverloads
|
||||||
|
constructor(
|
||||||
private val controller: Controller,
|
private val controller: Controller,
|
||||||
private val callback: Callback,
|
private val callback: Callback,
|
||||||
/** The animator to use to animate the window launch. */
|
/** The animator to use to animate the window launch. */
|
||||||
private val launchAnimator: LaunchAnimator = DEFAULT_LAUNCH_ANIMATOR,
|
private val launchAnimator: LaunchAnimator = DEFAULT_LAUNCH_ANIMATOR,
|
||||||
/** Listener for animation lifecycle events. */
|
/** Listener for animation lifecycle events. */
|
||||||
private val listener: Listener? = null
|
private val listener: Listener? = null
|
||||||
) : IRemoteAnimationRunner.Stub() {
|
) : RemoteAnimationDelegate<IRemoteAnimationFinishedCallback> {
|
||||||
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 =
|
||||||
@@ -419,6 +458,7 @@ class ActivityLaunchAnimator(
|
|||||||
// posting it.
|
// posting it.
|
||||||
private var onTimeout = Runnable { onAnimationTimedOut() }
|
private var onTimeout = Runnable { onAnimationTimedOut() }
|
||||||
|
|
||||||
|
@UiThread
|
||||||
internal fun postTimeout() {
|
internal fun postTimeout() {
|
||||||
launchContainer.postDelayed(onTimeout, LAUNCH_TIMEOUT)
|
launchContainer.postDelayed(onTimeout, LAUNCH_TIMEOUT)
|
||||||
}
|
}
|
||||||
@@ -427,19 +467,20 @@ class ActivityLaunchAnimator(
|
|||||||
launchContainer.removeCallbacks(onTimeout)
|
launchContainer.removeCallbacks(onTimeout)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@UiThread
|
||||||
override fun onAnimationStart(
|
override fun onAnimationStart(
|
||||||
@WindowManager.TransitionOldType transit: Int,
|
@WindowManager.TransitionOldType transit: Int,
|
||||||
apps: Array<out RemoteAnimationTarget>?,
|
apps: Array<out RemoteAnimationTarget>?,
|
||||||
wallpapers: Array<out RemoteAnimationTarget>?,
|
wallpapers: Array<out RemoteAnimationTarget>?,
|
||||||
nonApps: Array<out RemoteAnimationTarget>?,
|
nonApps: Array<out RemoteAnimationTarget>?,
|
||||||
iCallback: IRemoteAnimationFinishedCallback?
|
callback: IRemoteAnimationFinishedCallback?
|
||||||
) {
|
) {
|
||||||
removeTimeout()
|
removeTimeout()
|
||||||
|
|
||||||
// The animation was started too late and we already notified the controller that it
|
// The animation was started too late and we already notified the controller that it
|
||||||
// timed out.
|
// timed out.
|
||||||
if (timedOut) {
|
if (timedOut) {
|
||||||
iCallback?.invoke()
|
callback?.invoke()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -449,7 +490,7 @@ class ActivityLaunchAnimator(
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
context.mainExecutor.execute { startAnimation(apps, nonApps, iCallback) }
|
startAnimation(apps, nonApps, callback)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun startAnimation(
|
private fun startAnimation(
|
||||||
@@ -687,6 +728,7 @@ class ActivityLaunchAnimator(
|
|||||||
controller.onLaunchAnimationCancelled()
|
controller.onLaunchAnimationCancelled()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@UiThread
|
||||||
override fun onAnimationCancelled(isKeyguardOccluded: Boolean) {
|
override fun onAnimationCancelled(isKeyguardOccluded: Boolean) {
|
||||||
if (timedOut) {
|
if (timedOut) {
|
||||||
return
|
return
|
||||||
@@ -695,11 +737,10 @@ class ActivityLaunchAnimator(
|
|||||||
Log.i(TAG, "Remote animation was cancelled")
|
Log.i(TAG, "Remote animation was cancelled")
|
||||||
cancelled = true
|
cancelled = true
|
||||||
removeTimeout()
|
removeTimeout()
|
||||||
context.mainExecutor.execute {
|
|
||||||
animation?.cancel()
|
animation?.cancel()
|
||||||
controller.onLaunchAnimationCancelled(newKeyguardOccludedState = isKeyguardOccluded)
|
controller.onLaunchAnimationCancelled(newKeyguardOccludedState = isKeyguardOccluded)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private fun IRemoteAnimationFinishedCallback.invoke() {
|
private fun IRemoteAnimationFinishedCallback.invoke() {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -0,0 +1,30 @@
|
|||||||
|
package com.android.systemui.animation
|
||||||
|
|
||||||
|
import android.annotation.UiThread
|
||||||
|
import android.view.IRemoteAnimationFinishedCallback
|
||||||
|
import android.view.RemoteAnimationTarget
|
||||||
|
import android.view.WindowManager
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A component capable of running remote animations.
|
||||||
|
*
|
||||||
|
* Expands the IRemoteAnimationRunner API by allowing for different types of more specialized
|
||||||
|
* callbacks.
|
||||||
|
*/
|
||||||
|
interface RemoteAnimationDelegate<in T : IRemoteAnimationFinishedCallback> {
|
||||||
|
/**
|
||||||
|
* Called on the UI thread when the animation targets are received. Sets up and kicks off the
|
||||||
|
* animation.
|
||||||
|
*/
|
||||||
|
@UiThread
|
||||||
|
fun onAnimationStart(
|
||||||
|
@WindowManager.TransitionOldType transit: Int,
|
||||||
|
apps: Array<out RemoteAnimationTarget>?,
|
||||||
|
wallpapers: Array<out RemoteAnimationTarget>?,
|
||||||
|
nonApps: Array<out RemoteAnimationTarget>?,
|
||||||
|
callback: T?
|
||||||
|
)
|
||||||
|
|
||||||
|
/** Called on the UI thread when a signal is received to cancel the animation. */
|
||||||
|
@UiThread fun onAnimationCancelled(isKeyguardOccluded: Boolean)
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user