App Pairs: Launch animation
[App Pairs 7/?] This patch implements the app pair launch animation from icon. Adds a new function, composeFadeInSplitLaunchAnimator(), in SplitAnimationController, that builds the combined launcher + shell animation. Bug: 309618233 Flag: ACONFIG com.android.wm.shell.enable_app_pairs DEVELOPMENT Test: Manual Change-Id: I8e95f629ae2a71f1bd6cbb356f5e33233e5c2906
This commit is contained in:
1 parent
d761f5c3bd
commit
23fcbf2f73
22 files changed
+1409
-266
No files matched your search
@@ -21,20 +21,37 @@ import android.animation.Animator
|
||||
import android.animation.AnimatorListenerAdapter
|
||||
import android.animation.AnimatorSet
|
||||
import android.animation.ObjectAnimator
|
||||
import android.animation.ValueAnimator
|
||||
import android.app.ActivityManager.RunningTaskInfo
|
||||
import android.graphics.Bitmap
|
||||
import android.graphics.Rect
|
||||
import android.graphics.RectF
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.view.RemoteAnimationTarget
|
||||
import android.view.SurfaceControl
|
||||
import android.view.SurfaceControl.Transaction
|
||||
import android.view.View
|
||||
import android.view.WindowManager
|
||||
import android.window.TransitionInfo
|
||||
import android.window.TransitionInfo.Change
|
||||
import androidx.annotation.VisibleForTesting
|
||||
import com.android.app.animation.Interpolators
|
||||
import com.android.launcher3.DeviceProfile
|
||||
import com.android.launcher3.Launcher
|
||||
import com.android.launcher3.QuickstepTransitionManager
|
||||
import com.android.launcher3.Utilities
|
||||
import com.android.launcher3.anim.PendingAnimation
|
||||
import com.android.launcher3.apppairs.AppPairIcon
|
||||
import com.android.launcher3.config.FeatureFlags
|
||||
import com.android.launcher3.statehandlers.DepthController
|
||||
import com.android.launcher3.statemanager.StateManager
|
||||
import com.android.launcher3.statemanager.StatefulActivity
|
||||
import com.android.launcher3.util.SplitConfigurationOptions.SplitSelectSource
|
||||
import com.android.launcher3.views.BaseDragLayer
|
||||
import com.android.quickstep.TaskViewUtils
|
||||
import com.android.quickstep.views.FloatingAppPairView
|
||||
import com.android.quickstep.views.FloatingTaskView
|
||||
import com.android.quickstep.views.GroupedTaskView
|
||||
import com.android.quickstep.views.RecentsView
|
||||
import com.android.quickstep.views.SplitInstructionsView
|
||||
import com.android.quickstep.views.TaskThumbnailView
|
||||
@@ -308,6 +325,407 @@ class SplitAnimationController(val splitSelectStateController: SplitSelectStateC
|
||||
pendingAnimation.buildAnim().start()
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when launching a specific pair of apps, e.g. when tapping a pair of apps in Overview,
|
||||
* or launching an app pair from its Home icon. Selects the appropriate launch animation and
|
||||
* plays it.
|
||||
*/
|
||||
fun playSplitLaunchAnimation(
|
||||
launchingTaskView: GroupedTaskView?,
|
||||
launchingIconView: AppPairIcon?,
|
||||
initialTaskId: Int,
|
||||
secondTaskId: Int,
|
||||
apps: Array<RemoteAnimationTarget>?,
|
||||
wallpapers: Array<RemoteAnimationTarget>?,
|
||||
nonApps: Array<RemoteAnimationTarget>?,
|
||||
stateManager: StateManager<*>,
|
||||
depthController: DepthController?,
|
||||
info: TransitionInfo?,
|
||||
t: Transaction?,
|
||||
finishCallback: Runnable
|
||||
) {
|
||||
if (info == null && t == null) {
|
||||
// (Legacy animation) Tapping a split tile in Overview
|
||||
// TODO (b/315490678): Ensure that this works with app pairs flow
|
||||
check(apps != null && wallpapers != null && nonApps != null) {
|
||||
"trying to call composeRecentsSplitLaunchAnimatorLegacy, but encountered an " +
|
||||
"unexpected null"
|
||||
}
|
||||
|
||||
composeRecentsSplitLaunchAnimatorLegacy(
|
||||
launchingTaskView,
|
||||
initialTaskId,
|
||||
secondTaskId,
|
||||
apps,
|
||||
wallpapers,
|
||||
nonApps,
|
||||
stateManager,
|
||||
depthController,
|
||||
finishCallback
|
||||
)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
if (launchingTaskView != null) {
|
||||
// Tapping a split tile in Overview
|
||||
check(info != null && t != null) {
|
||||
"trying to launch a GroupedTaskView, but encountered an unexpected null"
|
||||
}
|
||||
|
||||
composeRecentsSplitLaunchAnimator(
|
||||
launchingTaskView,
|
||||
stateManager,
|
||||
depthController,
|
||||
info,
|
||||
t,
|
||||
finishCallback
|
||||
)
|
||||
} else if (launchingIconView != null) {
|
||||
// Tapping an app pair icon
|
||||
check(info != null && t != null) {
|
||||
"trying to launch an app pair icon, but encountered an unexpected null"
|
||||
}
|
||||
|
||||
composeIconSplitLaunchAnimator(
|
||||
launchingIconView,
|
||||
initialTaskId,
|
||||
secondTaskId,
|
||||
info,
|
||||
t,
|
||||
finishCallback
|
||||
)
|
||||
} else {
|
||||
// Fallback case: simple fade-in animation
|
||||
check(info != null && t != null) {
|
||||
"trying to call composeFadeInSplitLaunchAnimator, but encountered an " +
|
||||
"unexpected null"
|
||||
}
|
||||
|
||||
composeFadeInSplitLaunchAnimator(initialTaskId, secondTaskId, info, t, finishCallback)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* When the user taps a split tile in Overview, this will play the tasks' launch animation from
|
||||
* the position of the tapped tile.
|
||||
*/
|
||||
@VisibleForTesting
|
||||
fun composeRecentsSplitLaunchAnimator(
|
||||
launchingTaskView: GroupedTaskView,
|
||||
stateManager: StateManager<*>,
|
||||
depthController: DepthController?,
|
||||
info: TransitionInfo,
|
||||
t: Transaction,
|
||||
finishCallback: Runnable
|
||||
) {
|
||||
TaskViewUtils.composeRecentsSplitLaunchAnimator(
|
||||
launchingTaskView,
|
||||
stateManager,
|
||||
depthController,
|
||||
info,
|
||||
t,
|
||||
finishCallback
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* LEGACY VERSION: When the user taps a split tile in Overview, this will play the tasks' launch
|
||||
* animation from the position of the tapped tile.
|
||||
*/
|
||||
@VisibleForTesting
|
||||
fun composeRecentsSplitLaunchAnimatorLegacy(
|
||||
launchingTaskView: GroupedTaskView?,
|
||||
initialTaskId: Int,
|
||||
secondTaskId: Int,
|
||||
apps: Array<RemoteAnimationTarget>,
|
||||
wallpapers: Array<RemoteAnimationTarget>,
|
||||
nonApps: Array<RemoteAnimationTarget>,
|
||||
stateManager: StateManager<*>,
|
||||
depthController: DepthController?,
|
||||
finishCallback: Runnable
|
||||
) {
|
||||
TaskViewUtils.composeRecentsSplitLaunchAnimatorLegacy(
|
||||
launchingTaskView,
|
||||
initialTaskId,
|
||||
secondTaskId,
|
||||
apps,
|
||||
wallpapers,
|
||||
nonApps,
|
||||
stateManager,
|
||||
depthController,
|
||||
finishCallback
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* When the user taps an app pair icon to launch split, this will play the tasks' launch
|
||||
* animation from the position of the icon.
|
||||
*/
|
||||
@VisibleForTesting
|
||||
fun composeIconSplitLaunchAnimator(
|
||||
launchingIconView: AppPairIcon,
|
||||
initialTaskId: Int,
|
||||
secondTaskId: Int,
|
||||
transitionInfo: TransitionInfo,
|
||||
t: Transaction,
|
||||
finishCallback: Runnable
|
||||
) {
|
||||
val launcher = Launcher.getLauncher(launchingIconView.context)
|
||||
val dp = launcher.deviceProfile
|
||||
|
||||
// Create an AnimatorSet that will run both shell and launcher transitions together
|
||||
val launchAnimation = AnimatorSet()
|
||||
val progressUpdater = ValueAnimator.ofFloat(0f, 1f)
|
||||
val timings = AnimUtils.getDeviceAppPairLaunchTimings(dp.isTablet)
|
||||
progressUpdater.setDuration(timings.getDuration().toLong())
|
||||
progressUpdater.interpolator = Interpolators.LINEAR
|
||||
|
||||
// Find the root shell leash that we want to fade in (parent of both app windows and
|
||||
// the divider). For simplicity, we search using the initialTaskId.
|
||||
var rootShellLayer: SurfaceControl? = null
|
||||
var dividerPos = 0
|
||||
|
||||
for (change in transitionInfo.changes) {
|
||||
val taskInfo: RunningTaskInfo = change.taskInfo ?: continue
|
||||
val taskId = taskInfo.taskId
|
||||
val mode = change.mode
|
||||
|
||||
if (taskId == initialTaskId || taskId == secondTaskId) {
|
||||
check(
|
||||
mode == WindowManager.TRANSIT_OPEN || mode == WindowManager.TRANSIT_TO_FRONT
|
||||
) {
|
||||
"Expected task to be showing, but it is $mode"
|
||||
}
|
||||
}
|
||||
|
||||
if (taskId == initialTaskId) {
|
||||
var splitRoot1 = change
|
||||
val parentToken = change.parent
|
||||
if (parentToken != null) {
|
||||
splitRoot1 = transitionInfo.getChange(parentToken) ?: change
|
||||
}
|
||||
|
||||
val topLevelToken = splitRoot1.parent
|
||||
if (topLevelToken != null) {
|
||||
rootShellLayer = transitionInfo.getChange(topLevelToken)?.leash
|
||||
}
|
||||
|
||||
dividerPos =
|
||||
if (dp.isLeftRightSplit) change.endAbsBounds.right
|
||||
else change.endAbsBounds.bottom
|
||||
}
|
||||
}
|
||||
|
||||
check(rootShellLayer != null) {
|
||||
"Could not find a TransitionInfo.Change matching the initialTaskId"
|
||||
}
|
||||
|
||||
// Shell animation: the apps are revealed toward end of the launch animation
|
||||
progressUpdater.addUpdateListener { valueAnimator: ValueAnimator ->
|
||||
val progress =
|
||||
Interpolators.clampToProgress(
|
||||
Interpolators.LINEAR,
|
||||
valueAnimator.animatedFraction,
|
||||
timings.appRevealStartOffset,
|
||||
timings.appRevealEndOffset
|
||||
)
|
||||
|
||||
// Set the alpha of the shell layer (2 apps + divider)
|
||||
t.setAlpha(rootShellLayer, progress)
|
||||
t.apply()
|
||||
}
|
||||
|
||||
// Create a new floating view in Launcher, positioned above the launching icon
|
||||
val drawableArea = launchingIconView.iconDrawableArea
|
||||
val appIcon1 = launchingIconView.info.contents[0].newIcon(launchingIconView.context)
|
||||
val appIcon2 = launchingIconView.info.contents[1].newIcon(launchingIconView.context)
|
||||
appIcon1.setBounds(0, 0, dp.iconSizePx, dp.iconSizePx)
|
||||
appIcon2.setBounds(0, 0, dp.iconSizePx, dp.iconSizePx)
|
||||
val floatingView =
|
||||
FloatingAppPairView.getFloatingAppPairView(
|
||||
launcher,
|
||||
drawableArea,
|
||||
appIcon1,
|
||||
appIcon2,
|
||||
dividerPos
|
||||
)
|
||||
|
||||
// Launcher animation: animate the floating view, expanding to fill the display surface
|
||||
progressUpdater.addUpdateListener(
|
||||
object : MultiValueUpdateListener() {
|
||||
var mDx =
|
||||
FloatProp(
|
||||
floatingView.startingPosition.left,
|
||||
dp.widthPx / 2f - floatingView.startingPosition.width() / 2f,
|
||||
0f /* delay */,
|
||||
timings.getDuration().toFloat(),
|
||||
Interpolators.clampToProgress(
|
||||
timings.getStagedRectXInterpolator(),
|
||||
timings.stagedRectSlideStartOffset,
|
||||
timings.stagedRectSlideEndOffset
|
||||
)
|
||||
)
|
||||
var mDy =
|
||||
FloatProp(
|
||||
floatingView.startingPosition.top,
|
||||
dp.heightPx / 2f - floatingView.startingPosition.height() / 2f,
|
||||
0f /* delay */,
|
||||
timings.getDuration().toFloat(),
|
||||
Interpolators.clampToProgress(
|
||||
Interpolators.EMPHASIZED,
|
||||
timings.stagedRectSlideStartOffset,
|
||||
timings.stagedRectSlideEndOffset
|
||||
)
|
||||
)
|
||||
var mScaleX =
|
||||
FloatProp(
|
||||
1f /* start */,
|
||||
dp.widthPx / floatingView.startingPosition.width(),
|
||||
0f /* delay */,
|
||||
timings.getDuration().toFloat(),
|
||||
Interpolators.clampToProgress(
|
||||
Interpolators.EMPHASIZED,
|
||||
timings.stagedRectSlideStartOffset,
|
||||
timings.stagedRectSlideEndOffset
|
||||
)
|
||||
)
|
||||
var mScaleY =
|
||||
FloatProp(
|
||||
1f /* start */,
|
||||
dp.heightPx / floatingView.startingPosition.height(),
|
||||
0f /* delay */,
|
||||
timings.getDuration().toFloat(),
|
||||
Interpolators.clampToProgress(
|
||||
Interpolators.EMPHASIZED,
|
||||
timings.stagedRectSlideStartOffset,
|
||||
timings.stagedRectSlideEndOffset
|
||||
)
|
||||
)
|
||||
|
||||
override fun onUpdate(percent: Float, initOnly: Boolean) {
|
||||
floatingView.progress = percent
|
||||
floatingView.x = mDx.value
|
||||
floatingView.y = mDy.value
|
||||
floatingView.scaleX = mScaleX.value
|
||||
floatingView.scaleY = mScaleY.value
|
||||
floatingView.invalidate()
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
// When animation ends, remove the floating view and run finishCallback
|
||||
progressUpdater.addListener(
|
||||
object : AnimatorListenerAdapter() {
|
||||
override fun onAnimationEnd(animation: Animator) {
|
||||
safeRemoveViewFromDragLayer(launcher, floatingView)
|
||||
finishCallback.run()
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
launchAnimation.play(progressUpdater)
|
||||
launchAnimation.start()
|
||||
}
|
||||
|
||||
/**
|
||||
* If we are launching split screen without any special animation from a starting View, we
|
||||
* simply fade in the starting apps and fade out launcher.
|
||||
*/
|
||||
@VisibleForTesting
|
||||
fun composeFadeInSplitLaunchAnimator(
|
||||
initialTaskId: Int,
|
||||
secondTaskId: Int,
|
||||
transitionInfo: TransitionInfo,
|
||||
t: Transaction,
|
||||
finishCallback: Runnable
|
||||
) {
|
||||
var splitRoot1: Change? = null
|
||||
var splitRoot2: Change? = null
|
||||
val openingTargets = ArrayList<SurfaceControl>()
|
||||
for (change in transitionInfo.changes) {
|
||||
val taskInfo: RunningTaskInfo = change.taskInfo ?: continue
|
||||
val taskId = taskInfo.taskId
|
||||
val mode = change.mode
|
||||
|
||||
// Find the target tasks' root tasks since those are the split stages that need to
|
||||
// be animated (the tasks themselves are children and thus inherit animation).
|
||||
if (taskId == initialTaskId || taskId == secondTaskId) {
|
||||
check(
|
||||
mode == WindowManager.TRANSIT_OPEN || mode == WindowManager.TRANSIT_TO_FRONT
|
||||
) {
|
||||
"Expected task to be showing, but it is $mode"
|
||||
}
|
||||
}
|
||||
|
||||
if (taskId == initialTaskId) {
|
||||
splitRoot1 = change
|
||||
val parentToken1 = change.parent
|
||||
if (parentToken1 != null) {
|
||||
splitRoot1 = transitionInfo.getChange(parentToken1) ?: change
|
||||
}
|
||||
|
||||
if (splitRoot1?.leash != null) {
|
||||
openingTargets.add(splitRoot1.leash)
|
||||
}
|
||||
}
|
||||
|
||||
if (taskId == secondTaskId) {
|
||||
splitRoot2 = change
|
||||
val parentToken2 = change.parent
|
||||
if (parentToken2 != null) {
|
||||
splitRoot2 = transitionInfo.getChange(parentToken2) ?: change
|
||||
}
|
||||
|
||||
if (splitRoot2?.leash != null) {
|
||||
openingTargets.add(splitRoot2.leash)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val animTransaction = Transaction()
|
||||
val animator = ValueAnimator.ofFloat(0f, 1f)
|
||||
animator.setDuration(QuickstepTransitionManager.SPLIT_LAUNCH_DURATION.toLong())
|
||||
animator.addUpdateListener { valueAnimator: ValueAnimator ->
|
||||
val progress = valueAnimator.animatedFraction
|
||||
for (leash in openingTargets) {
|
||||
animTransaction.setAlpha(leash, progress)
|
||||
}
|
||||
animTransaction.apply()
|
||||
}
|
||||
|
||||
animator.addListener(
|
||||
object : AnimatorListenerAdapter() {
|
||||
override fun onAnimationStart(animation: Animator) {
|
||||
for (leash in openingTargets) {
|
||||
animTransaction.show(leash).setAlpha(leash, 0.0f)
|
||||
}
|
||||
animTransaction.apply()
|
||||
}
|
||||
|
||||
override fun onAnimationEnd(animation: Animator) {
|
||||
finishCallback.run()
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
if (splitRoot1 != null) {
|
||||
// Set the highest level split root alpha; we could technically use the parent of
|
||||
// either splitRoot1 or splitRoot2
|
||||
val parentToken = splitRoot1.parent
|
||||
var rootLayer: Change? = null
|
||||
if (parentToken != null) {
|
||||
rootLayer = transitionInfo.getChange(parentToken)
|
||||
}
|
||||
if (rootLayer != null && rootLayer.leash != null) {
|
||||
t.setAlpha(rootLayer.leash, 1f)
|
||||
}
|
||||
}
|
||||
|
||||
t.apply()
|
||||
animator.start()
|
||||
}
|
||||
|
||||
private fun safeRemoveViewFromDragLayer(launcher: StatefulActivity<*>, view: View?) {
|
||||
if (view != null) {
|
||||
launcher.dragLayer.removeView(view)
|
||||
|
||||
Reference in new issue
Block a user