Fix app pairs launch from in-app Taskbar

This CL adds a handler function in SplitAnimationController that manages the complicated logic flow for launching an app pair when already inside of an app.

To give an idea of the complicated logic:
If the user tapped on an app pair while already in an app pair, there are 4 general cases:
  a) Clicked app pair A|B, but both apps are already running on screen
  b) App A is already on-screen, but App B isn't
  c) App B is on-screen, but App A isn't
  d) Neither is on-screen

If the user tapped an app pair while inside a single app, there are 3 cases:
   a) The on-screen app is App A of the app pair
   b) The on-screen app is App B of the app pair
   c) It is neither

For each case, we call a different animation and launch the app pair in a different way.

When merged, this patch will fix all animation glitches that are currently happening in these situations, and get us 90% of the way to having the ideal animation in all cases. There are still a few complicated cases that need a polished animation (like when you launch app pairs with custom ratios), which will be implemented in a following patch soon (I thought this CL was big enough already as is).

Bug: 316485863
Fixes: 315190686
Test: Manual testing of all the different launch combinations
Flag: ACONFIG com.android.wm.shell.enable_app_pairs TEAMFOOD
Change-Id: I5c0e03512bb706360c575d833cac6ed02a5de936
This commit is contained in:
Jeremy Sim committed 2024-02-09 13:41:29 +08:00
1 parent 6474a3b455
commit cf9132e07c
5 files changed
+587 -19

No files matched your search

@@ -391,14 +391,6 @@ class SplitAnimationController(val splitSelectStateController: SplitSelectStateC
"trying to launch an app pair icon, but encountered an unexpected null"
}
// If launching an app pair from Taskbar inside of an app context, use fade-in animation
// TODO (b/316485863): Replace with desired app pair launch animation
if (launchingIconView.context is TaskbarActivityContext) {
composeFadeInSplitLaunchAnimator(
initialTaskId, secondTaskId, info, t, finishCallback)
return
}
composeIconSplitLaunchAnimator(launchingIconView, info, t, finishCallback)
} else {
// Fallback case: simple fade-in animation
@@ -483,6 +475,10 @@ class SplitAnimationController(val splitSelectStateController: SplitSelectStateC
* We want to animate the Root (grandparent) so that it affects both apps and the divider.
* To do this, we find one of the nodes with WINDOWING_MODE_MULTI_WINDOW (one of the
* left-side ones, for simplicity) and traverse the tree until we find the grandparent.
*
* This function is only called when we are animating the app pair in from scratch. It is NOT
* called when we are animating in from an existing visible TaskView tile or an app that is
* already on screen.
*/
@VisibleForTesting
fun composeIconSplitLaunchAnimator(
@@ -491,6 +487,14 @@ class SplitAnimationController(val splitSelectStateController: SplitSelectStateC
t: Transaction,
finishCallback: Runnable
) {
// If launching an app pair from Taskbar inside of an app context (no access to Launcher),
// use the scale-up animation
if (launchingIconView.context is TaskbarActivityContext) {
composeScaleUpLaunchAnimation(transitionInfo, t, finishCallback)
return
}
// Else we are in Launcher and can launch with the full icon stretch-and-split animation.
val launcher = Launcher.getLauncher(launchingIconView.context)
val dp = launcher.deviceProfile
@@ -649,6 +653,91 @@ class SplitAnimationController(val splitSelectStateController: SplitSelectStateC
launchAnimation.start()
}
/**
* This is a scale-up-and-fade-in animation (34% to 100%) for launching an app in Overview when
* there is no visible associated tile to expand from.
*/
@VisibleForTesting
fun composeScaleUpLaunchAnimation(
transitionInfo: TransitionInfo,
t: Transaction,
finishCallback: Runnable
) {
val launchAnimation = AnimatorSet()
val progressUpdater = ValueAnimator.ofFloat(0f, 1f)
progressUpdater.setDuration(QuickstepTransitionManager.APP_LAUNCH_DURATION)
progressUpdater.interpolator = Interpolators.EMPHASIZED
var rootCandidate: Change? = null
for (change in transitionInfo.changes) {
val taskInfo: RunningTaskInfo = change.taskInfo ?: continue
// TODO (b/316490565): Replace this logic when SplitBounds is available to
// startAnimation() and we can know the precise taskIds of launching tasks.
// Find a change that has WINDOWING_MODE_MULTI_WINDOW.
if (
taskInfo.windowingMode == WINDOWING_MODE_MULTI_WINDOW &&
(change.mode == TRANSIT_OPEN || change.mode == TRANSIT_TO_FRONT)
) {
// Found one!
rootCandidate = change
break
}
}
// If we could not find a proper root candidate, something went wrong.
check(rootCandidate != null) { "Could not find a split root candidate" }
// Recurse up the tree until parent is null, then we've found our root.
var parentToken: WindowContainerToken? = rootCandidate.parent
while (parentToken != null) {
rootCandidate = transitionInfo.getChange(parentToken) ?: break
parentToken = rootCandidate.parent
}
// Make sure nothing weird happened, like getChange() returning null.
check(rootCandidate != null) { "Failed to find a root leash" }
// Starting position is a 34% size tile centered in the middle of the screen.
// Ending position is the full device screen.
val screenBounds = rootCandidate.endAbsBounds
val startingScale = 0.34f
val startX =
screenBounds.left +
((screenBounds.right - screenBounds.left) * ((1 - startingScale) / 2f))
val startY =
screenBounds.top +
((screenBounds.bottom - screenBounds.top) * ((1 - startingScale) / 2f))
val endX = screenBounds.left
val endY = screenBounds.top
progressUpdater.addUpdateListener { valueAnimator: ValueAnimator ->
val progress = valueAnimator.animatedFraction
val x = startX + ((endX - startX) * progress)
val y = startY + ((endY - startY) * progress)
val scale = startingScale + ((1 - startingScale) * progress)
t.setPosition(rootCandidate.leash, x, y)
t.setScale(rootCandidate.leash, scale, scale)
t.setAlpha(rootCandidate.leash, progress)
t.apply()
}
// When animation ends, run finishCallback
progressUpdater.addListener(
object : AnimatorListenerAdapter() {
override fun onAnimationEnd(animation: Animator) {
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.