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

Commit 8f1ac1ef authored by Kevin's avatar Kevin
Browse files

Refactor lambda to use listener instead

We should not use an in-line lambda here as we allocate a new
RemoteAnimationProvider object to do so which hooks into the already
existing AppToOverviewAnimationProvider. This can be a problem if
AppToOverviewAnimationProvider overrides methods as we would not use the
overridden methods but instead the default ones.

Instead, we use the same AppToOverviewAnimationProvider object but hook
into the activity ready and window animation calls with a listener to
add on the logging logic.

Bug: 132112131
Test: Manual test; app to overview functions as before
Change-Id: Ie70541691ed420c33770d6ed4f54d9555374dc0a
parent 7b485485
Loading
Loading
Loading
Loading
+33 −0
Original line number Diff line number Diff line
@@ -42,12 +42,22 @@ final class AppToOverviewAnimationProvider<T extends BaseDraggingActivity> imple
    private final ActivityControlHelper<T> mHelper;
    private final int mTargetTaskId;
    private IconRecentsView mRecentsView;
    private AppToOverviewAnimationListener mAnimationReadyListener;

    AppToOverviewAnimationProvider(ActivityControlHelper<T> helper, int targetTaskId) {
        mHelper = helper;
        mTargetTaskId = targetTaskId;
    }

    /**
     * Set listener to various points in the animation preparing to animate.
     *
     * @param listener listener
     */
    void setAnimationListener(AppToOverviewAnimationListener listener) {
        mAnimationReadyListener = listener;
    }

    /**
     * Callback for when the activity is ready/initialized.
     *
@@ -55,6 +65,9 @@ final class AppToOverviewAnimationProvider<T extends BaseDraggingActivity> imple
     * @param wasVisible true if it was visible before
     */
    boolean onActivityReady(T activity, Boolean wasVisible) {
        if (mAnimationReadyListener != null) {
            mAnimationReadyListener.onActivityReady(activity);
        }
        ActivityControlHelper.AnimationFactory factory =
                mHelper.prepareRecentsUI(activity, wasVisible,
                        false /* animate activity */, (controller) -> {
@@ -79,6 +92,9 @@ final class AppToOverviewAnimationProvider<T extends BaseDraggingActivity> imple
     */
    @Override
    public AnimatorSet createWindowAnimation(RemoteAnimationTargetCompat[] targetCompats) {
        if (mAnimationReadyListener != null) {
            mAnimationReadyListener.onWindowAnimationCreated();
        }
        AnimatorSet anim = new AnimatorSet();
        if (mRecentsView == null) {
            if (Log.isLoggable(TAG, Log.WARN)) {
@@ -131,4 +147,21 @@ final class AppToOverviewAnimationProvider<T extends BaseDraggingActivity> imple
    long getRecentsLaunchDuration() {
        return REMOTE_APP_TO_OVERVIEW_DURATION;
    }

    /**
     * Listener for various points in the app to overview animation preparing to animate.
     */
    interface AppToOverviewAnimationListener {
        /**
         * Logic for when activity we're animating to is ready
         *
         * @param activity activity to animate to
         */
        void onActivityReady(BaseDraggingActivity activity);

        /**
         * Logic for when we've created the app to recents animation.
         */
        void onWindowAnimationCreated();
    }
}
+30 −30
Original line number Diff line number Diff line
@@ -18,7 +18,6 @@ package com.android.quickstep;
import static com.android.systemui.shared.system.ActivityManagerWrapper
        .CLOSE_SYSTEM_WINDOWS_REASON_RECENTS;

import android.animation.AnimatorSet;
import android.annotation.TargetApi;
import android.content.Context;
import android.os.Build;
@@ -30,10 +29,10 @@ import com.android.launcher3.MainThreadExecutor;
import com.android.launcher3.logging.UserEventDispatcher;
import com.android.launcher3.userevent.nano.LauncherLogProto;
import com.android.quickstep.ActivityControlHelper.ActivityInitListener;
import com.android.quickstep.AppToOverviewAnimationProvider.AppToOverviewAnimationListener;
import com.android.quickstep.views.IconRecentsView;
import com.android.systemui.shared.system.ActivityManagerWrapper;
import com.android.systemui.shared.system.LatencyTrackerCompat;
import com.android.systemui.shared.system.RemoteAnimationTargetCompat;

/**
 * Helper class to handle various atomic commands for switching between Overview.
@@ -105,7 +104,6 @@ public class OverviewCommandHelper {

        protected final ActivityControlHelper<T> mHelper;
        private final long mCreateTime;
        private final AppToOverviewAnimationProvider<T> mAnimationProvider;

        private final long mToggleClickedTime = SystemClock.uptimeMillis();
        private boolean mUserEventLogged;
@@ -114,8 +112,6 @@ public class OverviewCommandHelper {
        public RecentsActivityCommand() {
            mHelper = mOverviewComponentObserver.getActivityControlHelper();
            mCreateTime = SystemClock.elapsedRealtime();
            mAnimationProvider =
                    new AppToOverviewAnimationProvider<>(mHelper, RecentsModel.getRunningTaskId());

            // Preload the plan
            mRecentsModel.getTasks(null);
@@ -136,27 +132,12 @@ public class OverviewCommandHelper {
                return;
            }

            // Otherwise, start overview.
            mListener = mHelper.createActivityInitListener(this::onActivityReady);
            mListener.registerAndStartActivity(mOverviewComponentObserver.getOverviewIntent(),
                    this::createWindowAnimation, mContext, mMainThreadExecutor.getHandler(),
                    mAnimationProvider.getRecentsLaunchDuration());
        }

        protected boolean handleCommand(long elapsedTime) {
            IconRecentsView recents = mHelper.getVisibleRecentsView();
            if (recents != null) {
                recents.handleOverviewCommand();
                return true;
            } else if (elapsedTime < ViewConfiguration.getDoubleTapTimeout()) {
                // The user tried to launch back into overview too quickly, either after
                // launching an app, or before overview has actually shown, just ignore for now
                return true;
            }
            return false;
        }

        private boolean onActivityReady(T activity, Boolean wasVisible) {
            AppToOverviewAnimationProvider<T> provider =
                    new AppToOverviewAnimationProvider<>(mHelper, RecentsModel.getRunningTaskId());
            provider.setAnimationListener(
                    new AppToOverviewAnimationListener() {
                        @Override
                        public void onActivityReady(BaseDraggingActivity activity) {
                            if (!mUserEventLogged) {
                                activity.getUserEventDispatcher().logActionCommand(
                                        LauncherLogProto.Action.Command.RECENTS_BUTTON,
@@ -164,18 +145,37 @@ public class OverviewCommandHelper {
                                        LauncherLogProto.ContainerType.TASKSWITCHER);
                                mUserEventLogged = true;
                            }
            return mAnimationProvider.onActivityReady(activity, wasVisible);
                        }

        private AnimatorSet createWindowAnimation(RemoteAnimationTargetCompat[] targetCompats) {
                        @Override
                        public void onWindowAnimationCreated() {
                            if (LatencyTrackerCompat.isEnabled(mContext)) {
                                LatencyTrackerCompat.logToggleRecents(
                                        (int) (SystemClock.uptimeMillis() - mToggleClickedTime));
                            }

                            mListener.unregister();
                        }
                    });

            return mAnimationProvider.createWindowAnimation(targetCompats);
            // Otherwise, start overview.
            mListener = mHelper.createActivityInitListener(provider::onActivityReady);
            mListener.registerAndStartActivity(mOverviewComponentObserver.getOverviewIntent(),
                    provider, mContext, mMainThreadExecutor.getHandler(),
                    provider.getRecentsLaunchDuration());
        }

        protected boolean handleCommand(long elapsedTime) {
            IconRecentsView recents = mHelper.getVisibleRecentsView();
            if (recents != null) {
                recents.handleOverviewCommand();
                return true;
            } else if (elapsedTime < ViewConfiguration.getDoubleTapTimeout()) {
                // The user tried to launch back into overview too quickly, either after
                // launching an app, or before overview has actually shown, just ignore for now
                return true;
            }
            return false;
        }
    }
}