From 3913716ece8acd426d53f8b807ba64d9f3c27cdb Mon Sep 17 00:00:00 2001 From: Luca Zuccarini Date: Fri, 16 Dec 2022 10:12:17 +0000 Subject: [PATCH] Make LauncherAnimationRunner compatible with RemoteAnimationRunner. Nothing changes in its current usage and behavior, but instead of a RemoteAnimationFactory we can now also pass a RemoteAnimationRunner. Bug: 250588519 Test: manual Change-Id: I51f5a95360401d5f17104519ef91a81aef60923f --- .../launcher3/LauncherAnimationRunner.java | 33 ++++++++++++--- .../launcher3/QuickstepTransitionManager.java | 4 +- .../android/quickstep/RecentsActivity.java | 40 +++++++++---------- 3 files changed, 48 insertions(+), 29 deletions(-) diff --git a/quickstep/src/com/android/launcher3/LauncherAnimationRunner.java b/quickstep/src/com/android/launcher3/LauncherAnimationRunner.java index 95a94ec149..9f9f2c8654 100644 --- a/quickstep/src/com/android/launcher3/LauncherAnimationRunner.java +++ b/quickstep/src/com/android/launcher3/LauncherAnimationRunner.java @@ -28,12 +28,15 @@ import android.annotation.TargetApi; import android.content.Context; import android.os.Build; import android.os.Handler; +import android.os.RemoteException; +import android.view.IRemoteAnimationFinishedCallback; import android.view.RemoteAnimationTarget; import androidx.annotation.BinderThread; import androidx.annotation.Nullable; import androidx.annotation.UiThread; +import com.android.systemui.animation.RemoteAnimationDelegate; import com.android.systemui.shared.system.RemoteAnimationRunnerCompat; import java.lang.ref.WeakReference; @@ -89,7 +92,7 @@ public class LauncherAnimationRunner extends RemoteAnimationRunnerCompat { Runnable r = () -> { finishExistingAnimation(); mAnimationResult = new AnimationResult(() -> mAnimationResult = null, runnable); - getFactory().onCreateAnimation(transit, appTargets, wallpaperTargets, nonAppTargets, + getFactory().onAnimationStart(transit, appTargets, wallpaperTargets, nonAppTargets, mAnimationResult); }; if (mStartAtFrontOfQueue) { @@ -124,7 +127,11 @@ public class LauncherAnimationRunner extends RemoteAnimationRunnerCompat { }); } - public static final class AnimationResult { + /** + * Used by RemoteAnimationFactory implementations to run the actual animation and its lifecycle + * callbacks. + */ + public static final class AnimationResult extends IRemoteAnimationFinishedCallback.Stub { private final Runnable mSyncFinishRunnable; private final Runnable mASyncFinishRunnable; @@ -199,25 +206,41 @@ public class LauncherAnimationRunner extends RemoteAnimationRunnerCompat { } } } + + /** + * When used as a simple IRemoteAnimationFinishedCallback, this method is used to run the + * animation finished runnable. + */ + @Override + public void onAnimationFinished() throws RemoteException { + mASyncFinishRunnable.run(); + } } /** * Used with LauncherAnimationRunner as an interface for the runner to call back to the * implementation. */ - @FunctionalInterface - public interface RemoteAnimationFactory { + public interface RemoteAnimationFactory extends RemoteAnimationDelegate { /** * Called on the UI thread when the animation targets are received. The implementation must * call {@link AnimationResult#setAnimation} with the target animation to be run. */ - void onCreateAnimation(int transit, + @Override + @UiThread + void onAnimationStart(int transit, RemoteAnimationTarget[] appTargets, RemoteAnimationTarget[] wallpaperTargets, RemoteAnimationTarget[] nonAppTargets, LauncherAnimationRunner.AnimationResult result); + @Override + @UiThread + default void onAnimationCancelled(boolean isKeyguardOccluded) { + onAnimationCancelled(); + } + /** * Called when the animation is cancelled. This can happen with or without * the create being called. diff --git a/quickstep/src/com/android/launcher3/QuickstepTransitionManager.java b/quickstep/src/com/android/launcher3/QuickstepTransitionManager.java index 2aa0af4113..668567eae4 100644 --- a/quickstep/src/com/android/launcher3/QuickstepTransitionManager.java +++ b/quickstep/src/com/android/launcher3/QuickstepTransitionManager.java @@ -1665,7 +1665,7 @@ public class QuickstepTransitionManager implements OnDeviceProfileChangeListener } @Override - public void onCreateAnimation(int transit, + public void onAnimationStart(int transit, RemoteAnimationTarget[] appTargets, RemoteAnimationTarget[] wallpaperTargets, RemoteAnimationTarget[] nonAppTargets, @@ -1707,7 +1707,7 @@ public class QuickstepTransitionManager implements OnDeviceProfileChangeListener } @Override - public void onCreateAnimation(int transit, + public void onAnimationStart(int transit, RemoteAnimationTarget[] appTargets, RemoteAnimationTarget[] wallpaperTargets, RemoteAnimationTarget[] nonAppTargets, diff --git a/quickstep/src/com/android/quickstep/RecentsActivity.java b/quickstep/src/com/android/quickstep/RecentsActivity.java index dc405ff8ba..6f86bf5de6 100644 --- a/quickstep/src/com/android/quickstep/RecentsActivity.java +++ b/quickstep/src/com/android/quickstep/RecentsActivity.java @@ -240,7 +240,7 @@ public final class RecentsActivity extends StatefulActivity { mActivityLaunchAnimationRunner = new RemoteAnimationFactory() { @Override - public void onCreateAnimation(int transit, RemoteAnimationTarget[] appTargets, + public void onAnimationStart(int transit, RemoteAnimationTarget[] appTargets, RemoteAnimationTarget[] wallpaperTargets, RemoteAnimationTarget[] nonAppTargets, AnimationResult result) { mHandler.removeCallbacks(mAnimationStartTimeoutRunnable); @@ -407,28 +407,24 @@ public final class RecentsActivity extends StatefulActivity { } private final RemoteAnimationFactory mAnimationToHomeFactory = - new RemoteAnimationFactory() { - @Override - public void onCreateAnimation(int transit, RemoteAnimationTarget[] appTargets, - RemoteAnimationTarget[] wallpaperTargets, - RemoteAnimationTarget[] nonAppTargets, AnimationResult result) { - AnimatorPlaybackController controller = getStateManager() - .createAnimationToNewWorkspace(RecentsState.BG_LAUNCHER, HOME_APPEAR_DURATION); - controller.dispatchOnStart(); + (transit, appTargets, wallpaperTargets, nonAppTargets, result) -> { + AnimatorPlaybackController controller = + getStateManager().createAnimationToNewWorkspace( + RecentsState.BG_LAUNCHER, HOME_APPEAR_DURATION); + controller.dispatchOnStart(); - RemoteAnimationTargets targets = new RemoteAnimationTargets( - appTargets, wallpaperTargets, nonAppTargets, MODE_OPENING); - for (RemoteAnimationTarget app : targets.apps) { - new Transaction().setAlpha(app.leash, 1).apply(); - } - AnimatorSet anim = new AnimatorSet(); - anim.play(controller.getAnimationPlayer()); - anim.setDuration(HOME_APPEAR_DURATION); - result.setAnimation(anim, RecentsActivity.this, - () -> getStateManager().goToState(RecentsState.HOME, false), - true /* skipFirstFrame */); - } - }; + RemoteAnimationTargets targets = new RemoteAnimationTargets( + appTargets, wallpaperTargets, nonAppTargets, MODE_OPENING); + for (RemoteAnimationTarget app : targets.apps) { + new Transaction().setAlpha(app.leash, 1).apply(); + } + AnimatorSet anim = new AnimatorSet(); + anim.play(controller.getAnimationPlayer()); + anim.setDuration(HOME_APPEAR_DURATION); + result.setAnimation(anim, RecentsActivity.this, + () -> getStateManager().goToState(RecentsState.HOME, false), + true /* skipFirstFrame */); + }; @Override protected void collectStateHandlers(List out) {