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

Commit ca907069 authored by Sunny Goyal's avatar Sunny Goyal Committed by Android (Google) Code Review
Browse files

Merge "Simplifying fallback recents animation" into ub-launcher3-master

parents cf244630 9054843a
Loading
Loading
Loading
Loading
+27 −45
Original line number Diff line number Diff line
@@ -57,6 +57,7 @@ import com.android.launcher3.graphics.DrawableFactory;
import com.android.launcher3.shortcuts.DeepShortcutView;
import com.android.quickstep.RecentsAnimationInterpolator;
import com.android.quickstep.RecentsAnimationInterpolator.TaskWindowBounds;
import com.android.quickstep.util.RemoteAnimationProvider;
import com.android.quickstep.views.RecentsView;
import com.android.quickstep.views.TaskView;
import com.android.systemui.shared.recents.model.Task;
@@ -106,7 +107,7 @@ public class LauncherAppTransitionManagerImpl extends LauncherAppTransitionManag
    private DeviceProfile mDeviceProfile;
    private View mFloatingView;

    private RemoteAnimationRunnerCompat mRemoteAnimationOverride;
    private RemoteAnimationProvider mRemoteAnimationProvider;

    private final AnimatorListenerAdapter mReapplyStateListener = new AnimatorListenerAdapter() {
        @Override
@@ -179,8 +180,8 @@ public class LauncherAppTransitionManagerImpl extends LauncherAppTransitionManag
        return getDefaultActivityLaunchOptions(launcher, v);
    }

    public void setRemoteAnimationOverride(RemoteAnimationRunnerCompat remoteAnimationOverride) {
        mRemoteAnimationOverride = remoteAnimationOverride;
    public void setRemoteAnimationProvider(RemoteAnimationProvider animationProvider) {
        mRemoteAnimationProvider = animationProvider;
    }

    /**
@@ -683,52 +684,33 @@ public class LauncherAppTransitionManagerImpl extends LauncherAppTransitionManag
    private RemoteAnimationRunnerCompat getWallpaperOpenRunner() {
        return new LauncherAnimationRunner(mHandler) {
            @Override
            public void onAnimationStart(RemoteAnimationTargetCompat[] targetCompats,
                    Runnable runnable) {
                if (mLauncher.getStateManager().getState().overviewUi
                        && mRemoteAnimationOverride != null) {
                    // This transition is only used for the fallback activity and should not be
                    // managed here (but necessary to implement here since the defined remote
                    // animation currently takes precendence over the one defined in the activity
                    // options).
                    mRemoteAnimationOverride.onAnimationStart(targetCompats, runnable);
                    return;
                }
                super.onAnimationStart(targetCompats, runnable);
            }

            @Override
            public void onAnimationCancelled() {
                if (mLauncher.getStateManager().getState().overviewUi
                        && mRemoteAnimationOverride != null) {
                    // This transition is only used for the fallback activity and should not be
                    // managed here (but necessary to implement here since the defined remote
                    // animation currently takes precendence over the one defined in the activity
                    // options).
                    mRemoteAnimationOverride.onAnimationCancelled();
                    return;
                }
                super.onAnimationCancelled();
            public AnimatorSet getAnimator(RemoteAnimationTargetCompat[] targetCompats) {
                AnimatorSet anim = null;
                RemoteAnimationProvider provider = mRemoteAnimationProvider;
                if (provider != null) {
                    anim = provider.createWindowAnimation(targetCompats);
                }

            @Override
            public AnimatorSet getAnimator(RemoteAnimationTargetCompat[] targetCompats) {
                AnimatorSet anim = new AnimatorSet();
                if (anim == null) {
                    anim = new AnimatorSet();
                    anim.play(getClosingWindowAnimators(targetCompats));

                // Normally, we run the launcher content animation when we are transitioning home,
                // but if home is already visible, then we don't want to animate the contents of
                // launcher unless we know that we are animating home as a result of the home button
                // press with quickstep, which will result in launcher being started on touch down,
                // prior to the animation home (and won't be in the targets list because it is
                // already visible). In that case, we force invisibility on touch down, and only
                // reset it after the animation to home is initialized.
                    // Normally, we run the launcher content animation when we are transitioning
                    // home, but if home is already visible, then we don't want to animate the
                    // contents of launcher unless we know that we are animating home as a result
                    // of the home button press with quickstep, which will result in launcher being
                    // started on touch down, prior to the animation home (and won't be in the
                    // targets list because it is already visible). In that case, we force
                    // invisibility on touch down, and only reset it after the animation to home
                    // is initialized.
                    if (launcherIsATargetWithMode(targetCompats, MODE_OPENING)
                            || mLauncher.isForceInvisible()) {
                        // Only register the content animation for cancellation when state changes
                        mLauncher.getStateManager().setCurrentAnimation(anim);
                        createLauncherResumeAnimation(anim);
                    }
                }

                mLauncher.setForceInvisible(false);
                return anim;
            }
+38 −5
Original line number Diff line number Diff line
@@ -15,13 +15,16 @@
 */
package com.android.launcher3;

import static com.android.launcher3.states.RotationHelper.REQUEST_LOCK;

import android.annotation.TargetApi;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;

import com.android.launcher3.states.InternalStateHandler;
import com.android.quickstep.ActivityControlHelper.ActivityInitListener;
import com.android.quickstep.util.RemoteAnimationProvider;

import java.util.function.BiPredicate;

@@ -30,15 +33,33 @@ public class LauncherInitListener extends InternalStateHandler implements Activi

    private final BiPredicate<Launcher, Boolean> mOnInitListener;

    private RemoteAnimationProvider mRemoteAnimationProvider;

    public LauncherInitListener(BiPredicate<Launcher, Boolean> onInitListener) {
        mOnInitListener = onInitListener;
    }

    @Override
    protected boolean init(Launcher launcher, boolean alreadyOnHome) {
        // For the duration of the gesture, lock the screen orientation to ensure that we do not
        // rotate mid-quickscrub
        launcher.getRotationHelper().setStateHandlerRequest(REQUEST_LOCK);
        if (mRemoteAnimationProvider != null) {
            LauncherAppTransitionManagerImpl appTransitionManager =
                    (LauncherAppTransitionManagerImpl) launcher.getAppTransitionManager();

            // Set a one-time animation provider. After the first call, this will get cleared.
            // TODO: Probably also check the intended target id.
            appTransitionManager.setRemoteAnimationProvider((targets) -> {

                // On the first call clear the reference.
                appTransitionManager.setRemoteAnimationProvider(null);
                RemoteAnimationProvider provider = mRemoteAnimationProvider;
                mRemoteAnimationProvider = null;

                if (provider != null && launcher.getStateManager().getState().overviewUi) {
                    return provider.createWindowAnimation(targets);
                }
                return null;
            });
        }
        return mOnInitListener.test(launcher, alreadyOnHome);
    }

@@ -49,6 +70,18 @@ public class LauncherInitListener extends InternalStateHandler implements Activi

    @Override
    public void unregister() {
        mRemoteAnimationProvider = null;
        clearReference();
    }

    @Override
    public void registerAndStartActivity(Intent intent, RemoteAnimationProvider animProvider,
            Context context, Handler handler, long duration) {
        mRemoteAnimationProvider = animProvider;

        register();

        Bundle options = animProvider.toActivityOptions(handler, duration).toBundle();
        context.startActivity(addToIntent(new Intent((intent))), options);
    }
}
+4 −38
Original line number Diff line number Diff line
@@ -22,7 +22,6 @@ import static com.android.launcher3.anim.Interpolators.LINEAR;

import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.app.ActivityOptions;
import android.content.Context;
import android.content.Intent;
import android.graphics.Rect;
@@ -39,19 +38,17 @@ import com.android.launcher3.LauncherAppState;
import com.android.launcher3.LauncherAppTransitionManagerImpl;
import com.android.launcher3.LauncherInitListener;
import com.android.launcher3.LauncherState;
import com.android.launcher3.MainThreadExecutor;
import com.android.launcher3.allapps.AllAppsTransitionController;
import com.android.launcher3.anim.AnimatorPlaybackController;
import com.android.launcher3.util.ViewOnDrawExecutor;
import com.android.quickstep.fallback.FallbackRecentsView;
import com.android.quickstep.util.RemoteAnimationProvider;
import com.android.quickstep.views.LauncherLayoutListener;
import com.android.quickstep.views.RecentsView;
import com.android.quickstep.views.TaskView;
import com.android.systemui.shared.system.ActivityManagerWrapper;
import com.android.systemui.shared.system.ActivityOptionsCompat;
import com.android.systemui.shared.system.AssistDataReceiver;
import com.android.systemui.shared.system.RecentsAnimationListener;
import com.android.systemui.shared.system.RemoteAnimationAdapterCompat;

import java.util.function.BiPredicate;

@@ -85,9 +82,6 @@ public interface ActivityControlHelper<T extends BaseDraggingActivity> {
    void startRecentsFromSwipe(Intent intent, AssistDataReceiver assistDataReceiver,
            final RecentsAnimationListener remoteAnimationListener);

    void startRecentsFromButton(Context context, Intent intent,
            RecentsAnimationListener remoteAnimationListener);

    @UiThread
    @Nullable
    RecentsView getVisibleRecentsView();
@@ -214,24 +208,6 @@ public interface ActivityControlHelper<T extends BaseDraggingActivity> {
                    intent, assistDataReceiver, remoteAnimationListener, null, null);
        }

        @Override
        public void startRecentsFromButton(Context context, Intent intent,
                RecentsAnimationListener remoteAnimationListener) {
            // We should use the remove animation for the fallback activity recents button case,
            // it works better with PiP.  In Launcher, we have already registered the remote
            // animation definition, which takes priority over explicitly defined remote
            // animations in the provided activity options when starting the activity, so we
            // just register a remote animation factory to get a callback to handle this.
            LauncherAppTransitionManagerImpl appTransitionManager =
                    (LauncherAppTransitionManagerImpl) getLauncher().getAppTransitionManager();
            appTransitionManager.setRemoteAnimationOverride(new RecentsAnimationActivityOptions(
                    remoteAnimationListener, () -> {
                        // Once the controller is finished, also reset the remote animation override
                        appTransitionManager.setRemoteAnimationOverride(null);
                    }));
            context.startActivity(intent);
        }

        @Nullable
        @UiThread
        private Launcher getLauncher() {
@@ -360,19 +336,6 @@ public interface ActivityControlHelper<T extends BaseDraggingActivity> {
                    intent, assistDataReceiver, remoteAnimationListener, null, null);
        }

        @Override
        public void startRecentsFromButton(Context context, Intent intent,
                RecentsAnimationListener remoteAnimationListener) {
            // We should use the remove animation for the fallback activity recents button case,
            // it works better with PiP. For the fallback activity, we should not have registered
            // the launcher app transition manager, so we should just start the remote animation here.
            ActivityOptions options = ActivityOptionsCompat.makeRemoteAnimation(
                    new RemoteAnimationAdapterCompat(
                            new RecentsAnimationActivityOptions(remoteAnimationListener, null),
                            10000, 10000));
            context.startActivity(intent, options.toBundle());
        }

        @Nullable
        @Override
        public RecentsView getVisibleRecentsView() {
@@ -403,5 +366,8 @@ public interface ActivityControlHelper<T extends BaseDraggingActivity> {
        void register();

        void unregister();

        void registerAndStartActivity(Intent intent, RemoteAnimationProvider animProvider,
                Context context, Handler handler, long duration);
    }
}
+130 −228

File changed.

Preview size limit exceeded, changes collapsed.

+14 −0
Original line number Diff line number Diff line
@@ -16,9 +16,14 @@
package com.android.quickstep;

import android.annotation.TargetApi;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;

import com.android.quickstep.ActivityControlHelper.ActivityInitListener;
import com.android.quickstep.util.RemoteAnimationProvider;

import java.lang.ref.WeakReference;
import java.util.function.BiPredicate;
@@ -78,4 +83,13 @@ public class RecentsActivityTracker implements ActivityInitListener {
            return sCurrentActivity.get();
        }
    }

    @Override
    public void registerAndStartActivity(Intent intent, RemoteAnimationProvider animProvider,
            Context context, Handler handler, long duration) {
        register();

        Bundle options = animProvider.toActivityOptions(handler, duration).toBundle();
        context.startActivity(intent, options);
    }
}
Loading