From 43acb5fdd5c4e7c98fcbbf104d4af0876ed6f531 Mon Sep 17 00:00:00 2001 From: Evan Rosky Date: Thu, 25 May 2023 16:05:54 -0700 Subject: [PATCH] Use activity-exit animation for translucent-only close This is parity w/ legacy. Many translucent tasks are designed with the expectation of sliding-down for closing animation. Bug: 282655010 Test: launch a translucent task (in 3 button nav) and press home button. Change-Id: I9b04f5534742a9b853d870cff48a1f4eda4d97f2 --- .../transition/DefaultTransitionHandler.java | 35 +++++++++++++++++++ .../transition/TransitionAnimationHelper.java | 9 ++--- .../wm/shell/transition/Transitions.java | 4 +-- 3 files changed, 42 insertions(+), 6 deletions(-) diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/transition/DefaultTransitionHandler.java b/libs/WindowManager/Shell/src/com/android/wm/shell/transition/DefaultTransitionHandler.java index 6a2468a7eaa26..392c2a47a9a3f 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/transition/DefaultTransitionHandler.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/transition/DefaultTransitionHandler.java @@ -326,6 +326,7 @@ public class DefaultTransitionHandler implements Transitions.TransitionHandler { final int wallpaperTransit = getWallpaperTransitType(info); boolean isDisplayRotationAnimationStarted = false; final boolean isDreamTransition = isDreamTransition(info); + final boolean isOnlyTranslucent = isOnlyTranslucent(info); for (int i = info.getChanges().size() - 1; i >= 0; --i) { final TransitionInfo.Change change = info.getChanges().get(i); @@ -451,6 +452,17 @@ public class DefaultTransitionHandler implements Transitions.TransitionHandler { final int layer = zSplitLine + numChanges - i; startTransaction.setLayer(change.getLeash(), layer); } + } else if (isOnlyTranslucent && TransitionUtil.isOpeningType(info.getType()) + && TransitionUtil.isClosingType(mode)) { + // If there is a closing translucent task in an OPENING transition, we will + // actually select a CLOSING animation, so move the closing task into + // the animating part of the z-order. + + // See Transitions#setupAnimHierarchy for details about these variables. + final int numChanges = info.getChanges().size(); + final int zSplitLine = numChanges + 1; + final int layer = zSplitLine + numChanges - i; + startTransaction.setLayer(change.getLeash(), layer); } } @@ -542,6 +554,29 @@ public class DefaultTransitionHandler implements Transitions.TransitionHandler { return false; } + /** + * Does `info` only contain translucent visibility changes (CHANGEs are ignored). We select + * different animations and z-orders for these + */ + private static boolean isOnlyTranslucent(@NonNull TransitionInfo info) { + int translucentOpen = 0; + int translucentClose = 0; + for (int i = info.getChanges().size() - 1; i >= 0; --i) { + final TransitionInfo.Change change = info.getChanges().get(i); + if (change.getMode() == TRANSIT_CHANGE) continue; + if (change.hasFlags(FLAG_TRANSLUCENT)) { + if (TransitionUtil.isOpeningType(change.getMode())) { + translucentOpen += 1; + } else { + translucentClose += 1; + } + } else { + return false; + } + } + return (translucentOpen + translucentClose) > 0; + } + @Override public void mergeAnimation(@NonNull IBinder transition, @NonNull TransitionInfo info, @NonNull SurfaceControl.Transaction t, @NonNull IBinder mergeTarget, diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/transition/TransitionAnimationHelper.java b/libs/WindowManager/Shell/src/com/android/wm/shell/transition/TransitionAnimationHelper.java index 19d8384ace412..560b51452bb16 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/transition/TransitionAnimationHelper.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/transition/TransitionAnimationHelper.java @@ -102,10 +102,11 @@ public class TransitionAnimationHelper { // We will translucent open animation for translucent activities and tasks. Choose // WindowAnimation_activityOpenEnterAnimation and set translucent here, then // TransitionAnimation loads appropriate animation later. - if ((changeFlags & FLAG_TRANSLUCENT) != 0 && enter) { - translucent = true; - } - if (isTask && !translucent) { + translucent = (changeFlags & FLAG_TRANSLUCENT) != 0; + if (isTask && translucent && !enter) { + // For closing translucent tasks, use the activity close animation + animAttr = R.styleable.WindowAnimation_activityCloseExitAnimation; + } else if (isTask && !translucent) { animAttr = enter ? R.styleable.WindowAnimation_taskOpenEnterAnimation : R.styleable.WindowAnimation_taskOpenExitAnimation; diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/transition/Transitions.java b/libs/WindowManager/Shell/src/com/android/wm/shell/transition/Transitions.java index 3b306e7936409..a74e2b1d1f68c 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/transition/Transitions.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/transition/Transitions.java @@ -567,8 +567,8 @@ public class Transitions implements RemoteCallable, layer = zSplitLine + numChanges - i; } } else { // CHANGE or other - if (isClosing) { - // Put below CLOSE mode. + if (isClosing || TransitionUtil.isOrderOnly(change)) { + // Put below CLOSE mode (in the "static" section). layer = zSplitLine - i; } else { // Put above CLOSE mode.