Merge "Refactor lambda to use listener instead" into ub-launcher3-qt-dev

This commit is contained in:
TreeHugger Robot 2019-05-10 19:49:36 +00:00 committed by Android (Google) Code Review
commit 763a7bffa3
2 changed files with 63 additions and 30 deletions

View File

@ -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();
}
}

View File

@ -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);
}
}
}