From 8f1ac1efeb5862dcabc1382755232f74ad207012 Mon Sep 17 00:00:00 2001 From: Kevin Date: Fri, 10 May 2019 12:03:29 -0700 Subject: [PATCH] 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 --- .../AppToOverviewAnimationProvider.java | 33 ++++++++++ .../quickstep/OverviewCommandHelper.java | 60 +++++++++---------- 2 files changed, 63 insertions(+), 30 deletions(-) diff --git a/go/quickstep/src/com/android/quickstep/AppToOverviewAnimationProvider.java b/go/quickstep/src/com/android/quickstep/AppToOverviewAnimationProvider.java index 62e40d1947..c03222db14 100644 --- a/go/quickstep/src/com/android/quickstep/AppToOverviewAnimationProvider.java +++ b/go/quickstep/src/com/android/quickstep/AppToOverviewAnimationProvider.java @@ -42,12 +42,22 @@ final class AppToOverviewAnimationProvider imple private final ActivityControlHelper mHelper; private final int mTargetTaskId; private IconRecentsView mRecentsView; + private AppToOverviewAnimationListener mAnimationReadyListener; AppToOverviewAnimationProvider(ActivityControlHelper 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 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 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 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(); + } } diff --git a/go/quickstep/src/com/android/quickstep/OverviewCommandHelper.java b/go/quickstep/src/com/android/quickstep/OverviewCommandHelper.java index 379cc100e8..0fa3d866f6 100644 --- a/go/quickstep/src/com/android/quickstep/OverviewCommandHelper.java +++ b/go/quickstep/src/com/android/quickstep/OverviewCommandHelper.java @@ -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 mHelper; private final long mCreateTime; - private final AppToOverviewAnimationProvider 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,11 +132,37 @@ public class OverviewCommandHelper { return; } + AppToOverviewAnimationProvider 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, + mHelper.getContainerType(), + LauncherLogProto.ContainerType.TASKSWITCHER); + mUserEventLogged = true; + } + } + + @Override + public void onWindowAnimationCreated() { + if (LatencyTrackerCompat.isEnabled(mContext)) { + LatencyTrackerCompat.logToggleRecents( + (int) (SystemClock.uptimeMillis() - mToggleClickedTime)); + } + + mListener.unregister(); + } + }); + // Otherwise, start overview. - mListener = mHelper.createActivityInitListener(this::onActivityReady); + mListener = mHelper.createActivityInitListener(provider::onActivityReady); mListener.registerAndStartActivity(mOverviewComponentObserver.getOverviewIntent(), - this::createWindowAnimation, mContext, mMainThreadExecutor.getHandler(), - mAnimationProvider.getRecentsLaunchDuration()); + provider, mContext, mMainThreadExecutor.getHandler(), + provider.getRecentsLaunchDuration()); } protected boolean handleCommand(long elapsedTime) { @@ -155,27 +177,5 @@ public class OverviewCommandHelper { } return false; } - - private boolean onActivityReady(T activity, Boolean wasVisible) { - if (!mUserEventLogged) { - activity.getUserEventDispatcher().logActionCommand( - LauncherLogProto.Action.Command.RECENTS_BUTTON, - mHelper.getContainerType(), - LauncherLogProto.ContainerType.TASKSWITCHER); - mUserEventLogged = true; - } - return mAnimationProvider.onActivityReady(activity, wasVisible); - } - - private AnimatorSet createWindowAnimation(RemoteAnimationTargetCompat[] targetCompats) { - if (LatencyTrackerCompat.isEnabled(mContext)) { - LatencyTrackerCompat.logToggleRecents( - (int) (SystemClock.uptimeMillis() - mToggleClickedTime)); - } - - mListener.unregister(); - - return mAnimationProvider.createWindowAnimation(targetCompats); - } } }