Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3913716e authored by Luca Zuccarini's avatar Luca Zuccarini
Browse files

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
parent d9ca71b1
Loading
Loading
Loading
Loading
+28 −5
Original line number Diff line number Diff line
@@ -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<AnimationResult> {

        /**
         * 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.
+2 −2
Original line number Diff line number Diff line
@@ -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,
+19 −23
Original line number Diff line number Diff line
@@ -240,7 +240,7 @@ public final class RecentsActivity extends StatefulActivity<RecentsState> {

        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,13 +407,10 @@ public final class RecentsActivity extends StatefulActivity<RecentsState> {
    }

    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);
            (transit, appTargets, wallpaperTargets, nonAppTargets, result) -> {
                AnimatorPlaybackController controller =
                        getStateManager().createAnimationToNewWorkspace(
                                RecentsState.BG_LAUNCHER, HOME_APPEAR_DURATION);
                controller.dispatchOnStart();

                RemoteAnimationTargets targets = new RemoteAnimationTargets(
@@ -427,7 +424,6 @@ public final class RecentsActivity extends StatefulActivity<RecentsState> {
                result.setAnimation(anim, RecentsActivity.this,
                        () -> getStateManager().goToState(RecentsState.HOME, false),
                        true /* skipFirstFrame */);
        }
            };

    @Override