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
This commit is contained in:
parent
7b48548546
commit
8f1ac1efeb
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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,11 +132,37 @@ public class OverviewCommandHelper {
|
|||
return;
|
||||
}
|
||||
|
||||
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,
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue