From d9c0349c1afb9e2071e44e971082a65b8aa3a539 Mon Sep 17 00:00:00 2001 From: Sunny Goyal Date: Wed, 13 May 2020 10:29:47 -0700 Subject: [PATCH] Merging WindowSizeStrategy with BaseActivityInterface Also converting BaseActivityInterface to an abstract class instead of interface so that it can hold member variables Change-Id: I04cab934137eb1d6f470c6a7618c50a2ed2c71c1 --- .../states/OverviewModalTaskState.java | 3 - .../AppToOverviewAnimationProvider.java | 9 +- .../android/quickstep/BaseSwipeUpHandler.java | 12 +- .../quickstep/FallbackActivityInterface.java | 43 ++-- .../quickstep/FallbackSwipeHandler.java | 3 +- .../quickstep/LauncherActivityInterface.java | 120 ++++----- .../quickstep/LauncherSwipeHandler.java | 7 +- .../quickstep/OverviewCommandHelper.java | 11 +- .../android/quickstep/RecentsActivity.java | 4 - .../quickstep/TouchInteractionService.java | 5 +- .../fallback/FallbackRecentsView.java | 4 +- .../inputconsumers/OverviewInputConsumer.java | 6 +- .../quickstep/util/TaskViewSimulator.java | 7 +- .../quickstep/views/LauncherRecentsView.java | 4 +- .../android/quickstep/views/RecentsView.java | 6 +- .../quickstep/BaseActivityInterface.java | 227 +++++++++++++++--- .../com/android/quickstep/GestureState.java | 7 +- .../quickstep/OverviewComponentObserver.java | 4 +- .../android/quickstep/util/LayoutUtils.java | 4 +- .../quickstep/util/RecentsOrientedState.java | 5 +- .../quickstep/util/WindowSizeStrategy.java | 185 -------------- 21 files changed, 327 insertions(+), 349 deletions(-) delete mode 100644 quickstep/src/com/android/quickstep/util/WindowSizeStrategy.java diff --git a/quickstep/recents_ui_overrides/src/com/android/launcher3/uioverrides/states/OverviewModalTaskState.java b/quickstep/recents_ui_overrides/src/com/android/launcher3/uioverrides/states/OverviewModalTaskState.java index 0be248691e..d5b06871b9 100644 --- a/quickstep/recents_ui_overrides/src/com/android/launcher3/uioverrides/states/OverviewModalTaskState.java +++ b/quickstep/recents_ui_overrides/src/com/android/launcher3/uioverrides/states/OverviewModalTaskState.java @@ -16,7 +16,6 @@ package com.android.launcher3.uioverrides.states; import android.content.Context; -import android.content.res.Resources; import android.graphics.Rect; import com.android.launcher3.BaseDraggingActivity; @@ -58,8 +57,6 @@ public class OverviewModalTaskState extends OverviewState { } public static float[] getOverviewScaleAndOffsetForModalState(BaseDraggingActivity activity) { - Resources res = activity.getResources(); - Rect out = new Rect(); activity.getOverviewPanel().getTaskSize(out); int taskHeight = out.height(); diff --git a/quickstep/recents_ui_overrides/src/com/android/quickstep/AppToOverviewAnimationProvider.java b/quickstep/recents_ui_overrides/src/com/android/quickstep/AppToOverviewAnimationProvider.java index 1dd5fb7a57..f38ff10cc2 100644 --- a/quickstep/recents_ui_overrides/src/com/android/quickstep/AppToOverviewAnimationProvider.java +++ b/quickstep/recents_ui_overrides/src/com/android/quickstep/AppToOverviewAnimationProvider.java @@ -31,9 +31,9 @@ import android.util.Log; import android.view.View; import com.android.launcher3.AbstractFloatingView; -import com.android.launcher3.BaseDraggingActivity; import com.android.launcher3.anim.AnimationSuccessListener; import com.android.launcher3.statehandlers.DepthController; +import com.android.launcher3.statemanager.StatefulActivity; import com.android.quickstep.util.AppWindowAnimationHelper; import com.android.quickstep.util.RemoteAnimationProvider; import com.android.quickstep.util.TransformParams; @@ -47,20 +47,21 @@ import com.android.systemui.shared.system.TransactionCompat; * * @param activity that contains the overview */ -final class AppToOverviewAnimationProvider extends +final class AppToOverviewAnimationProvider> extends RemoteAnimationProvider { private static final long RECENTS_LAUNCH_DURATION = 250; private static final String TAG = "AppToOverviewAnimationProvider"; - private final BaseActivityInterface mActivityInterface; + private final BaseActivityInterface mActivityInterface; // The id of the currently running task that is transitioning to overview. private final int mTargetTaskId; private T mActivity; private RecentsView mRecentsView; - AppToOverviewAnimationProvider(BaseActivityInterface activityInterface, int targetTaskId) { + AppToOverviewAnimationProvider( + BaseActivityInterface activityInterface, int targetTaskId) { mActivityInterface = activityInterface; mTargetTaskId = targetTaskId; } diff --git a/quickstep/recents_ui_overrides/src/com/android/quickstep/BaseSwipeUpHandler.java b/quickstep/recents_ui_overrides/src/com/android/quickstep/BaseSwipeUpHandler.java index 76c6060e8b..bbee67ce94 100644 --- a/quickstep/recents_ui_overrides/src/com/android/quickstep/BaseSwipeUpHandler.java +++ b/quickstep/recents_ui_overrides/src/com/android/quickstep/BaseSwipeUpHandler.java @@ -44,12 +44,12 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.annotation.UiThread; -import com.android.launcher3.BaseDraggingActivity; import com.android.launcher3.DeviceProfile; import com.android.launcher3.InvariantDeviceProfile; import com.android.launcher3.Utilities; import com.android.launcher3.anim.AnimationSuccessListener; import com.android.launcher3.anim.AnimatorPlaybackController; +import com.android.launcher3.statemanager.StatefulActivity; import com.android.launcher3.touch.PagedOrientationHandler; import com.android.launcher3.util.VibratorWrapper; import com.android.launcher3.views.FloatingIconView; @@ -60,7 +60,6 @@ import com.android.quickstep.util.RectFSpringAnim; import com.android.quickstep.util.TaskViewSimulator; import com.android.quickstep.util.TransformParams; import com.android.quickstep.util.TransformParams.BuilderProxy; -import com.android.quickstep.util.WindowSizeStrategy; import com.android.quickstep.views.RecentsView; import com.android.quickstep.views.TaskView; import com.android.systemui.shared.recents.model.ThumbnailData; @@ -76,7 +75,7 @@ import java.util.function.Consumer; * Base class for swipe up handler with some utility methods */ @TargetApi(Build.VERSION_CODES.Q) -public abstract class BaseSwipeUpHandler +public abstract class BaseSwipeUpHandler, Q extends RecentsView> implements RecentsAnimationListener { private static final String TAG = "BaseSwipeUpHandler"; @@ -97,7 +96,7 @@ public abstract class BaseSwipeUpHandler mActivityInterface; + protected final BaseActivityInterface mActivityInterface; protected final InputConsumerController mInputConsumer; protected final TaskViewSimulator mTaskViewSimulator; @@ -132,15 +131,14 @@ public abstract class BaseSwipeUpHandler { +public final class FallbackActivityInterface extends + BaseActivityInterface { - public FallbackActivityInterface() { } + public static final FallbackActivityInterface INSTANCE = new FallbackActivityInterface(); - @Override - public void onTransitionCancelled(boolean activityVisible) { - // TODO: + private FallbackActivityInterface() { + super(false); } @Override public int getSwipeUpDestinationAndLength(DeviceProfile dp, Context context, Rect outRect) { - FALLBACK_RECENTS_SIZE_STRATEGY.calculateTaskSize(context, dp, outRect); + calculateTaskSize(context, dp, outRect); if (dp.isVerticalBarLayout() && SysUINavigationMode.INSTANCE.get(context).getMode() != NO_BUTTON) { Rect targetInsets = dp.getInsets(); @@ -69,17 +70,6 @@ public final class FallbackActivityInterface implements } } - @Override - public void onSwipeUpToRecentsComplete() { - RecentsActivity activity = getCreatedActivity(); - if (activity == null) { - return; - } - RecentsView recentsView = activity.getOverviewPanel(); - recentsView.getClearAllButton().setVisibilityAlpha(1); - recentsView.setDisallowScrollToClearAll(false); - } - @Override public void onAssistantVisibilityChanged(float visibility) { // This class becomes active when the screen is locked. @@ -198,11 +188,14 @@ public final class FallbackActivityInterface implements } @Override - public void onLaunchTaskSuccess() { - RecentsActivity activity = getCreatedActivity(); - if (activity == null) { - return; - } - activity.onTaskLaunched(); + public void getMultiWindowSize(Context context, DeviceProfile dp, PointF out) { + out.set(dp.widthPx, dp.heightPx); + } + + @Override + protected float getExtraSpace(Context context, DeviceProfile dp) { + return showOverviewActions(context) + ? context.getResources().getDimensionPixelSize(R.dimen.overview_actions_height) + : 0; } } diff --git a/quickstep/recents_ui_overrides/src/com/android/quickstep/FallbackSwipeHandler.java b/quickstep/recents_ui_overrides/src/com/android/quickstep/FallbackSwipeHandler.java index 77e50caae7..db41bd6fd4 100644 --- a/quickstep/recents_ui_overrides/src/com/android/quickstep/FallbackSwipeHandler.java +++ b/quickstep/recents_ui_overrides/src/com/android/quickstep/FallbackSwipeHandler.java @@ -24,7 +24,6 @@ import static com.android.quickstep.GestureState.GestureEndTarget.RECENTS; import static com.android.quickstep.MultiStateCallback.DEBUG_STATES; import static com.android.quickstep.RecentsActivity.EXTRA_TASK_ID; import static com.android.quickstep.RecentsActivity.EXTRA_THUMBNAIL; -import static com.android.quickstep.util.WindowSizeStrategy.FALLBACK_RECENTS_SIZE_STRATEGY; import static com.android.quickstep.views.RecentsView.UPDATE_SYSUI_FLAGS_THRESHOLD; import android.animation.Animator; @@ -114,7 +113,7 @@ public class FallbackSwipeHandler extends BaseSwipeUpHandler { +public final class LauncherActivityInterface extends + BaseActivityInterface { + + public static final LauncherActivityInterface INSTANCE = new LauncherActivityInterface(); + + private LauncherActivityInterface() { + super(true); + } @Override public int getSwipeUpDestinationAndLength(DeviceProfile dp, Context context, Rect outRect) { - LAUNCHER_ACTIVITY_SIZE_STRATEGY.calculateTaskSize(context, dp, outRect); + calculateTaskSize(context, dp, outRect); if (dp.isVerticalBarLayout() && SysUINavigationMode.getMode(context) != Mode.NO_BUTTON) { Rect targetInsets = dp.getInsets(); int hotseatInset = dp.isSeascape() ? targetInsets.left : targetInsets.right; @@ -83,25 +95,13 @@ public final class LauncherActivityInterface implements BaseActivityInterface implements Runnable { + private class RecentsActivityCommand> implements Runnable { - protected final BaseActivityInterface mActivityInterface; + protected final BaseActivityInterface mActivityInterface; private final long mCreateTime; private final AppToOverviewAnimationProvider mAnimationProvider; diff --git a/quickstep/recents_ui_overrides/src/com/android/quickstep/RecentsActivity.java b/quickstep/recents_ui_overrides/src/com/android/quickstep/RecentsActivity.java index 03d522e85d..a4670fd40b 100644 --- a/quickstep/recents_ui_overrides/src/com/android/quickstep/RecentsActivity.java +++ b/quickstep/recents_ui_overrides/src/com/android/quickstep/RecentsActivity.java @@ -261,10 +261,6 @@ public final class RecentsActivity extends StatefulActivity { AccessibilityManagerCompat.sendStateEventToTest(getBaseContext(), OVERVIEW_STATE_ORDINAL); } - public void onTaskLaunched() { - mFallbackRecentsView.resetTaskVisuals(); - } - @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); diff --git a/quickstep/recents_ui_overrides/src/com/android/quickstep/TouchInteractionService.java b/quickstep/recents_ui_overrides/src/com/android/quickstep/TouchInteractionService.java index 258d60c208..acc7794631 100644 --- a/quickstep/recents_ui_overrides/src/com/android/quickstep/TouchInteractionService.java +++ b/quickstep/recents_ui_overrides/src/com/android/quickstep/TouchInteractionService.java @@ -63,6 +63,7 @@ import com.android.launcher3.config.FeatureFlags; import com.android.launcher3.logging.UserEventDispatcher; import com.android.launcher3.model.AppLaunchTracker; import com.android.launcher3.provider.RestoreDbTask; +import com.android.launcher3.statemanager.StatefulActivity; import com.android.launcher3.testing.TestLogging; import com.android.launcher3.testing.TestProtocol; import com.android.launcher3.tracing.nano.LauncherTraceProto; @@ -705,7 +706,7 @@ public class TouchInteractionService extends Service implements PluginListener activityInterface = + final BaseActivityInterface activityInterface = mOverviewComponentObserver.getActivityInterface(); final Intent overviewIntent = new Intent( mOverviewComponentObserver.getOverviewIntentIgnoreSysUiState()); diff --git a/quickstep/recents_ui_overrides/src/com/android/quickstep/fallback/FallbackRecentsView.java b/quickstep/recents_ui_overrides/src/com/android/quickstep/fallback/FallbackRecentsView.java index 1ab317b9eb..f958e6d734 100644 --- a/quickstep/recents_ui_overrides/src/com/android/quickstep/fallback/FallbackRecentsView.java +++ b/quickstep/recents_ui_overrides/src/com/android/quickstep/fallback/FallbackRecentsView.java @@ -17,7 +17,6 @@ package com.android.quickstep.fallback; import static com.android.quickstep.fallback.RecentsState.DEFAULT; import static com.android.quickstep.fallback.RecentsState.MODAL_TASK; -import static com.android.quickstep.util.WindowSizeStrategy.FALLBACK_RECENTS_SIZE_STRATEGY; import android.annotation.TargetApi; import android.app.ActivityManager.RunningTaskInfo; @@ -26,6 +25,7 @@ import android.os.Build; import android.util.AttributeSet; import com.android.launcher3.statemanager.StateManager.StateListener; +import com.android.quickstep.FallbackActivityInterface; import com.android.quickstep.RecentsActivity; import com.android.quickstep.views.OverviewActionsView; import com.android.quickstep.views.RecentsView; @@ -45,7 +45,7 @@ public class FallbackRecentsView extends RecentsView } public FallbackRecentsView(Context context, AttributeSet attrs, int defStyleAttr) { - super(context, attrs, defStyleAttr, FALLBACK_RECENTS_SIZE_STRATEGY); + super(context, attrs, defStyleAttr, FallbackActivityInterface.INSTANCE); mActivity.getStateManager().addStateListener(this); } diff --git a/quickstep/recents_ui_overrides/src/com/android/quickstep/inputconsumers/OverviewInputConsumer.java b/quickstep/recents_ui_overrides/src/com/android/quickstep/inputconsumers/OverviewInputConsumer.java index c82d4b5edd..11fee2f32a 100644 --- a/quickstep/recents_ui_overrides/src/com/android/quickstep/inputconsumers/OverviewInputConsumer.java +++ b/quickstep/recents_ui_overrides/src/com/android/quickstep/inputconsumers/OverviewInputConsumer.java @@ -24,8 +24,8 @@ import android.view.MotionEvent; import androidx.annotation.Nullable; -import com.android.launcher3.BaseDraggingActivity; import com.android.launcher3.Utilities; +import com.android.launcher3.statemanager.StatefulActivity; import com.android.launcher3.testing.TestLogging; import com.android.launcher3.testing.TestProtocol; import com.android.launcher3.views.BaseDragLayer; @@ -41,11 +41,11 @@ import java.util.function.Predicate; /** * Input consumer for handling touch on the recents/Launcher activity. */ -public class OverviewInputConsumer +public class OverviewInputConsumer> implements InputConsumer { private final T mActivity; - private final BaseActivityInterface mActivityInterface; + private final BaseActivityInterface mActivityInterface; private final BaseDragLayer mTarget; private final InputMonitorCompat mInputMonitor; diff --git a/quickstep/recents_ui_overrides/src/com/android/quickstep/util/TaskViewSimulator.java b/quickstep/recents_ui_overrides/src/com/android/quickstep/util/TaskViewSimulator.java index b8f0f4ddf7..a3db940211 100644 --- a/quickstep/recents_ui_overrides/src/com/android/quickstep/util/TaskViewSimulator.java +++ b/quickstep/recents_ui_overrides/src/com/android/quickstep/util/TaskViewSimulator.java @@ -15,8 +15,6 @@ */ package com.android.quickstep.util; -import static android.view.Surface.ROTATION_0; - import static com.android.launcher3.states.RotationHelper.deltaRotation; import static com.android.launcher3.touch.PagedOrientationHandler.MATRIX_POST_TRANSLATE; import static com.android.quickstep.util.RecentsOrientedState.postDisplayRotation; @@ -33,6 +31,7 @@ import com.android.launcher3.R; import com.android.launcher3.Utilities; import com.android.launcher3.touch.PagedOrientationHandler; import com.android.quickstep.AnimatedFloat; +import com.android.quickstep.BaseActivityInterface; import com.android.quickstep.views.RecentsView.ScrollState; import com.android.quickstep.views.TaskThumbnailView.PreviewPositionHelper; import com.android.quickstep.views.TaskView; @@ -52,7 +51,7 @@ public class TaskViewSimulator implements TransformParams.BuilderProxy { private final RecentsOrientedState mOrientationState; private final Context mContext; - private final WindowSizeStrategy mSizeStrategy; + private final BaseActivityInterface mSizeStrategy; private final Rect mTaskRect = new Rect(); private final PointF mPivot = new PointF(); @@ -81,7 +80,7 @@ public class TaskViewSimulator implements TransformParams.BuilderProxy { private boolean mLayoutValid = false; private boolean mScrollValid = false; - public TaskViewSimulator(Context context, WindowSizeStrategy sizeStrategy) { + public TaskViewSimulator(Context context, BaseActivityInterface sizeStrategy) { mContext = context; mSizeStrategy = sizeStrategy; diff --git a/quickstep/recents_ui_overrides/src/com/android/quickstep/views/LauncherRecentsView.java b/quickstep/recents_ui_overrides/src/com/android/quickstep/views/LauncherRecentsView.java index 250c78bdac..3d894033d1 100644 --- a/quickstep/recents_ui_overrides/src/com/android/quickstep/views/LauncherRecentsView.java +++ b/quickstep/recents_ui_overrides/src/com/android/quickstep/views/LauncherRecentsView.java @@ -25,7 +25,6 @@ import static com.android.launcher3.LauncherState.SPRING_LOADED; import static com.android.launcher3.QuickstepAppTransitionManagerImpl.ALL_APPS_PROGRESS_OFF_SCREEN; import static com.android.launcher3.allapps.AllAppsTransitionController.ALL_APPS_PROGRESS; import static com.android.launcher3.config.FeatureFlags.ENABLE_QUICKSTEP_LIVE_TILE; -import static com.android.quickstep.util.WindowSizeStrategy.LAUNCHER_ACTIVITY_SIZE_STRATEGY; import android.animation.AnimatorSet; import android.animation.ObjectAnimator; @@ -47,6 +46,7 @@ import com.android.launcher3.statemanager.StateManager.StateListener; import com.android.launcher3.uioverrides.plugins.PluginManagerWrapper; import com.android.launcher3.util.TraceHelper; import com.android.launcher3.views.ScrimView; +import com.android.quickstep.LauncherActivityInterface; import com.android.quickstep.SysUINavigationMode; import com.android.quickstep.util.TransformParams; import com.android.systemui.plugins.PluginListener; @@ -89,7 +89,7 @@ public class LauncherRecentsView extends RecentsView } public LauncherRecentsView(Context context, AttributeSet attrs, int defStyleAttr) { - super(context, attrs, defStyleAttr, LAUNCHER_ACTIVITY_SIZE_STRATEGY); + super(context, attrs, defStyleAttr, LauncherActivityInterface.INSTANCE); mActivity.getStateManager().addStateListener(this); } diff --git a/quickstep/recents_ui_overrides/src/com/android/quickstep/views/RecentsView.java b/quickstep/recents_ui_overrides/src/com/android/quickstep/views/RecentsView.java index 54ed40f3e9..253e83cab4 100644 --- a/quickstep/recents_ui_overrides/src/com/android/quickstep/views/RecentsView.java +++ b/quickstep/recents_ui_overrides/src/com/android/quickstep/views/RecentsView.java @@ -115,6 +115,7 @@ import com.android.launcher3.util.MultiValueAlpha; import com.android.launcher3.util.OverScroller; import com.android.launcher3.util.Themes; import com.android.launcher3.util.ViewPool; +import com.android.quickstep.BaseActivityInterface; import com.android.quickstep.RecentsAnimationController; import com.android.quickstep.RecentsAnimationTargets; import com.android.quickstep.RecentsModel; @@ -128,7 +129,6 @@ import com.android.quickstep.util.LayoutUtils; import com.android.quickstep.util.RecentsOrientedState; import com.android.quickstep.util.SplitScreenBounds; import com.android.quickstep.util.TransformParams; -import com.android.quickstep.util.WindowSizeStrategy; import com.android.systemui.plugins.ResourceProvider; import com.android.systemui.shared.recents.IPinnedStackAnimationListener; import com.android.systemui.shared.recents.model.Task; @@ -209,7 +209,7 @@ public abstract class RecentsView extends PagedView impl }; protected final RecentsOrientedState mOrientationState; - protected final WindowSizeStrategy mSizeStrategy; + protected final BaseActivityInterface mSizeStrategy; protected RecentsAnimationController mRecentsAnimationController; protected RecentsAnimationTargets mRecentsAnimationTargets; protected AppWindowAnimationHelper mAppWindowAnimationHelper; @@ -381,7 +381,7 @@ public abstract class RecentsView extends PagedView impl }; public RecentsView(Context context, AttributeSet attrs, int defStyleAttr, - WindowSizeStrategy sizeStrategy) { + BaseActivityInterface sizeStrategy) { super(context, attrs, defStyleAttr); setPageSpacing(getResources().getDimensionPixelSize(R.dimen.recents_page_spacing)); setEnableFreeScroll(true); diff --git a/quickstep/src/com/android/quickstep/BaseActivityInterface.java b/quickstep/src/com/android/quickstep/BaseActivityInterface.java index 43328b6885..2699a916a0 100644 --- a/quickstep/src/com/android/quickstep/BaseActivityInterface.java +++ b/quickstep/src/com/android/quickstep/BaseActivityInterface.java @@ -15,23 +15,34 @@ */ package com.android.quickstep; +import static com.android.launcher3.config.FeatureFlags.ENABLE_OVERVIEW_ACTIONS; +import static com.android.quickstep.SysUINavigationMode.getMode; +import static com.android.quickstep.SysUINavigationMode.removeShelfFromOverview; + import android.annotation.TargetApi; import android.content.Context; +import android.content.res.Resources; +import android.graphics.PointF; import android.graphics.Rect; import android.os.Build; import android.view.MotionEvent; -import android.view.View; import android.view.animation.Interpolator; import androidx.annotation.Nullable; import androidx.annotation.UiThread; -import com.android.launcher3.BaseDraggingActivity; import com.android.launcher3.DeviceProfile; +import com.android.launcher3.R; import com.android.launcher3.anim.AnimatorPlaybackController; import com.android.launcher3.statehandlers.DepthController; +import com.android.launcher3.statemanager.BaseState; +import com.android.launcher3.statemanager.StatefulActivity; +import com.android.launcher3.util.WindowBounds; +import com.android.quickstep.SysUINavigationMode.Mode; import com.android.quickstep.util.ActivityInitListener; import com.android.quickstep.util.ShelfPeekAnim; +import com.android.quickstep.util.SplitScreenBounds; +import com.android.quickstep.views.RecentsView; import com.android.systemui.shared.recents.model.ThumbnailData; import com.android.systemui.shared.system.RemoteAnimationTargetCompat; @@ -42,84 +53,232 @@ import java.util.function.Predicate; * Utility class which abstracts out the logical differences between Launcher and RecentsActivity. */ @TargetApi(Build.VERSION_CODES.P) -public interface BaseActivityInterface { +public abstract class BaseActivityInterface, + ACTIVITY_TYPE extends StatefulActivity> { - void onTransitionCancelled(boolean activityVisible); + private final PointF mTempPoint = new PointF(); + public final boolean rotationSupportedByActivity; - int getSwipeUpDestinationAndLength(DeviceProfile dp, Context context, Rect outRect); + protected BaseActivityInterface(boolean rotationSupportedByActivity) { + this.rotationSupportedByActivity = rotationSupportedByActivity; + } - void onSwipeUpToRecentsComplete(); + public void onTransitionCancelled(boolean activityVisible) { + ACTIVITY_TYPE activity = getCreatedActivity(); + if (activity == null) { + return; + } + STATE_TYPE startState = activity.getStateManager().getRestState(); + activity.getStateManager().goToState(startState, activityVisible); + } - default void onSwipeUpToHomeComplete() { } - void onAssistantVisibilityChanged(float visibility); + public abstract int getSwipeUpDestinationAndLength( + DeviceProfile dp, Context context, Rect outRect); - AnimationFactory prepareRecentsUI( + public void onSwipeUpToRecentsComplete() { + // Re apply state in case we did something funky during the transition. + ACTIVITY_TYPE activity = getCreatedActivity(); + if (activity == null) { + return; + } + activity.getStateManager().reapplyState(); + } + + public void onSwipeUpToHomeComplete() { } + + public abstract void onAssistantVisibilityChanged(float visibility); + + public abstract AnimationFactory prepareRecentsUI( boolean activityVisible, Consumer callback); - ActivityInitListener createActivityInitListener(Predicate onInitListener); + public abstract ActivityInitListener createActivityInitListener( + Predicate onInitListener); /** * Sets a callback to be run when an activity launch happens while launcher is not yet resumed. */ - default void setOnDeferredActivityLaunchCallback(Runnable r) {} + public void setOnDeferredActivityLaunchCallback(Runnable r) {} @Nullable - T getCreatedActivity(); + public abstract ACTIVITY_TYPE getCreatedActivity(); @Nullable - default DepthController getDepthController() { + public DepthController getDepthController() { return null; } - default boolean isResumed() { - BaseDraggingActivity activity = getCreatedActivity(); + public final boolean isResumed() { + ACTIVITY_TYPE activity = getCreatedActivity(); return activity != null && activity.hasBeenResumed(); } - default boolean isStarted() { - BaseDraggingActivity activity = getCreatedActivity(); + public final boolean isStarted() { + ACTIVITY_TYPE activity = getCreatedActivity(); return activity != null && activity.isStarted(); } @UiThread @Nullable - T getVisibleRecentsView(); + public abstract T getVisibleRecentsView(); @UiThread - boolean switchToRecentsIfVisible(Runnable onCompleteCallback); + public abstract boolean switchToRecentsIfVisible(Runnable onCompleteCallback); - Rect getOverviewWindowBounds(Rect homeBounds, RemoteAnimationTargetCompat target); + public abstract Rect getOverviewWindowBounds( + Rect homeBounds, RemoteAnimationTargetCompat target); - boolean allowMinimizeSplitScreen(); + public abstract boolean allowMinimizeSplitScreen(); - default boolean deferStartingActivity(RecentsAnimationDeviceState deviceState, MotionEvent ev) { + public boolean deferStartingActivity(RecentsAnimationDeviceState deviceState, MotionEvent ev) { return true; } /** * Updates the prediction state to the overview state. */ - default void updateOverviewPredictionState() { - // By default overview predictions are not supported + public void updateOverviewPredictionState() { + // By public overview predictions are not supported } /** * Used for containerType in {@link com.android.launcher3.logging.UserEventDispatcher} */ - int getContainerType(); + public abstract int getContainerType(); - boolean isInLiveTileMode(); + public abstract boolean isInLiveTileMode(); - void onLaunchTaskFailed(); + public abstract void onLaunchTaskFailed(); - void onLaunchTaskSuccess(); + public void onLaunchTaskSuccess() { + ACTIVITY_TYPE activity = getCreatedActivity(); + if (activity == null) { + return; + } + activity.getStateManager().moveToRestState(); + } - default void closeOverlay() { } + public void closeOverlay() { } - default void switchRunningTaskViewToScreenshot(ThumbnailData thumbnailData, - Runnable runnable) {} + public void switchRunningTaskViewToScreenshot(ThumbnailData thumbnailData, Runnable runnable) { + ACTIVITY_TYPE activity = getCreatedActivity(); + if (activity == null) { + return; + } + RecentsView recentsView = activity.getOverviewPanel(); + if (recentsView == null) { + if (runnable != null) { + runnable.run(); + } + return; + } + recentsView.switchToScreenshot(thumbnailData, runnable); + } - interface AnimationFactory { + /** + * Sets the expected window size in multi-window mode + */ + public abstract void getMultiWindowSize(Context context, DeviceProfile dp, PointF out); + + /** + * Calculates the taskView size for the provided device configuration + */ + public final void calculateTaskSize(Context context, DeviceProfile dp, Rect outRect) { + calculateTaskSize(context, dp, getExtraSpace(context, dp), outRect); + } + + protected abstract float getExtraSpace(Context context, DeviceProfile dp); + + private void calculateTaskSize( + Context context, DeviceProfile dp, float extraVerticalSpace, Rect outRect) { + Resources res = context.getResources(); + final boolean showLargeTaskSize = showOverviewActions(context); + + final int paddingResId; + if (dp.isMultiWindowMode) { + paddingResId = R.dimen.multi_window_task_card_horz_space; + } else if (dp.isVerticalBarLayout()) { + paddingResId = R.dimen.landscape_task_card_horz_space; + } else if (showLargeTaskSize) { + paddingResId = R.dimen.portrait_task_card_horz_space_big_overview; + } else { + paddingResId = R.dimen.portrait_task_card_horz_space; + } + float paddingHorz = res.getDimension(paddingResId); + float paddingVert = showLargeTaskSize + ? 0 : res.getDimension(R.dimen.task_card_vert_space); + + calculateTaskSizeInternal(context, dp, extraVerticalSpace, paddingHorz, paddingVert, + res.getDimension(R.dimen.task_thumbnail_top_margin), outRect); + } + + private void calculateTaskSizeInternal(Context context, DeviceProfile dp, + float extraVerticalSpace, float paddingHorz, float paddingVert, float topIconMargin, + Rect outRect) { + float taskWidth, taskHeight; + Rect insets = dp.getInsets(); + if (dp.isMultiWindowMode) { + WindowBounds bounds = SplitScreenBounds.INSTANCE.getSecondaryWindowBounds(context); + taskWidth = bounds.availableSize.x; + taskHeight = bounds.availableSize.y; + } else { + taskWidth = dp.availableWidthPx; + taskHeight = dp.availableHeightPx; + } + + // Note this should be same as dp.availableWidthPx and dp.availableHeightPx unless + // we override the insets ourselves. + int launcherVisibleWidth = dp.widthPx - insets.left - insets.right; + int launcherVisibleHeight = dp.heightPx - insets.top - insets.bottom; + + float availableHeight = launcherVisibleHeight + - topIconMargin - extraVerticalSpace - paddingVert; + float availableWidth = launcherVisibleWidth - paddingHorz; + + float scale = Math.min(availableWidth / taskWidth, availableHeight / taskHeight); + float outWidth = scale * taskWidth; + float outHeight = scale * taskHeight; + + // Center in the visible space + float x = insets.left + (launcherVisibleWidth - outWidth) / 2; + float y = insets.top + Math.max(topIconMargin, + (launcherVisibleHeight - extraVerticalSpace - outHeight) / 2); + outRect.set(Math.round(x), Math.round(y), + Math.round(x) + Math.round(outWidth), Math.round(y) + Math.round(outHeight)); + } + + /** + * Calculates the modal taskView size for the provided device configuration + */ + public void calculateModalTaskSize(Context context, DeviceProfile dp, Rect outRect) { + float paddingHorz = context.getResources().getDimension(dp.isMultiWindowMode + ? R.dimen.multi_window_task_card_horz_space + : dp.isVerticalBarLayout() + ? R.dimen.landscape_task_card_horz_space + : R.dimen.portrait_modal_task_card_horz_space); + float extraVerticalSpace = getOverviewActionsHeight(context); + float paddingVert = 0; + float topIconMargin = 0; + calculateTaskSizeInternal(context, dp, extraVerticalSpace, paddingHorz, paddingVert, + topIconMargin, outRect); + } + + /** Gets the space that the overview actions will take, including margins. */ + public float getOverviewActionsHeight(Context context) { + Resources res = context.getResources(); + float actionsBottomMargin = 0; + if (getMode(context) == Mode.THREE_BUTTONS) { + actionsBottomMargin = res.getDimensionPixelSize( + R.dimen.overview_actions_bottom_margin_three_button); + } else { + actionsBottomMargin = res.getDimensionPixelSize( + R.dimen.overview_actions_bottom_margin_gesture); + } + float overviewActionsHeight = actionsBottomMargin + + res.getDimensionPixelSize(R.dimen.overview_actions_height); + return overviewActionsHeight; + } + + public interface AnimationFactory { default void onRemoteAnimationReceived(RemoteAnimationTargets targets) { } @@ -137,4 +296,8 @@ public interface BaseActivityInterface { */ default void setRecentsAttachedToAppWindow(boolean attached, boolean animate) { } } + + protected static boolean showOverviewActions(Context context) { + return ENABLE_OVERVIEW_ACTIONS.get() && removeShelfFromOverview(context); + } } diff --git a/quickstep/src/com/android/quickstep/GestureState.java b/quickstep/src/com/android/quickstep/GestureState.java index 9b515ae788..295b465120 100644 --- a/quickstep/src/com/android/quickstep/GestureState.java +++ b/quickstep/src/com/android/quickstep/GestureState.java @@ -17,10 +17,12 @@ package com.android.quickstep; import static com.android.quickstep.MultiStateCallback.DEBUG_STATES; +import android.annotation.TargetApi; import android.app.ActivityManager; import android.content.Intent; +import android.os.Build; -import com.android.launcher3.BaseDraggingActivity; +import com.android.launcher3.statemanager.StatefulActivity; import com.android.launcher3.userevent.nano.LauncherLogProto.ContainerType; import com.android.systemui.shared.recents.model.ThumbnailData; import com.android.systemui.shared.system.RemoteAnimationTargetCompat; @@ -32,6 +34,7 @@ import java.util.ArrayList; * Manages the state for an active system gesture, listens for events from the system and Launcher, * and fires events when the states change. */ +@TargetApi(Build.VERSION_CODES.R) public class GestureState implements RecentsAnimationCallbacks.RecentsAnimationListener { /** @@ -189,7 +192,7 @@ public class GestureState implements RecentsAnimationCallbacks.RecentsAnimationL /** * @return the interface to the activity handing the UI updates for this gesture. */ - public BaseActivityInterface getActivityInterface() { + public > BaseActivityInterface getActivityInterface() { return mActivityInterface; } diff --git a/quickstep/src/com/android/quickstep/OverviewComponentObserver.java b/quickstep/src/com/android/quickstep/OverviewComponentObserver.java index 231ee72f1c..0449d0ca2a 100644 --- a/quickstep/src/com/android/quickstep/OverviewComponentObserver.java +++ b/quickstep/src/com/android/quickstep/OverviewComponentObserver.java @@ -140,7 +140,7 @@ public final class OverviewComponentObserver { if (!mDeviceState.isHomeDisabled() && (defaultHome == null || mIsDefaultHome)) { // User default home is same as out home app. Use Overview integrated in Launcher. - mActivityInterface = new LauncherActivityInterface(); + mActivityInterface = LauncherActivityInterface.INSTANCE; mIsHomeAndOverviewSame = true; mOverviewIntent = mMyHomeIntent; mCurrentHomeIntent.setComponent(mMyHomeIntent.getComponent()); @@ -150,7 +150,7 @@ public final class OverviewComponentObserver { } else { // The default home app is a different launcher. Use the fallback Overview instead. - mActivityInterface = new FallbackActivityInterface(); + mActivityInterface = FallbackActivityInterface.INSTANCE; mIsHomeAndOverviewSame = false; mOverviewIntent = mFallbackIntent; mCurrentHomeIntent.setComponent(defaultHome); diff --git a/quickstep/src/com/android/quickstep/util/LayoutUtils.java b/quickstep/src/com/android/quickstep/util/LayoutUtils.java index fa53be2b08..c1b276aa5a 100644 --- a/quickstep/src/com/android/quickstep/util/LayoutUtils.java +++ b/quickstep/src/com/android/quickstep/util/LayoutUtils.java @@ -17,7 +17,6 @@ package com.android.quickstep.util; import static com.android.launcher3.config.FeatureFlags.ENABLE_OVERVIEW_ACTIONS; import static com.android.quickstep.SysUINavigationMode.removeShelfFromOverview; -import static com.android.quickstep.util.WindowSizeStrategy.LAUNCHER_ACTIVITY_SIZE_STRATEGY; import android.content.Context; import android.graphics.Rect; @@ -26,6 +25,7 @@ import android.view.ViewGroup; import com.android.launcher3.DeviceProfile; import com.android.launcher3.R; +import com.android.quickstep.LauncherActivityInterface; import com.android.quickstep.SysUINavigationMode; public class LayoutUtils { @@ -45,7 +45,7 @@ public class LayoutUtils { // Track the bottom of the window. if (ENABLE_OVERVIEW_ACTIONS.get() && removeShelfFromOverview(context)) { Rect taskSize = new Rect(); - LAUNCHER_ACTIVITY_SIZE_STRATEGY.calculateTaskSize(context, dp, taskSize); + LauncherActivityInterface.INSTANCE.calculateTaskSize(context, dp, taskSize); return (dp.heightPx - taskSize.height()) / 2; } int shelfHeight = dp.hotseatBarSizePx + dp.getInsets().bottom; diff --git a/quickstep/src/com/android/quickstep/util/RecentsOrientedState.java b/quickstep/src/com/android/quickstep/util/RecentsOrientedState.java index e7ff48f52b..e03f4b80ea 100644 --- a/quickstep/src/com/android/quickstep/util/RecentsOrientedState.java +++ b/quickstep/src/com/android/quickstep/util/RecentsOrientedState.java @@ -52,6 +52,7 @@ import com.android.launcher3.Utilities; import com.android.launcher3.testing.TestProtocol; import com.android.launcher3.touch.PagedOrientationHandler; import com.android.launcher3.util.WindowBounds; +import com.android.quickstep.BaseActivityInterface; import java.lang.annotation.Retention; import java.util.function.IntConsumer; @@ -121,7 +122,7 @@ public final class RecentsOrientedState implements SharedPreferences.OnSharedPre private final ContentResolver mContentResolver; private final SharedPreferences mSharedPrefs; private final OrientationEventListener mOrientationListener; - private final WindowSizeStrategy mSizeStrategy; + private final BaseActivityInterface mSizeStrategy; private final Matrix mTmpMatrix = new Matrix(); @@ -133,7 +134,7 @@ public final class RecentsOrientedState implements SharedPreferences.OnSharedPre * is enabled * @see #setRotationWatcherEnabled(boolean) */ - public RecentsOrientedState(Context context, WindowSizeStrategy sizeStrategy, + public RecentsOrientedState(Context context, BaseActivityInterface sizeStrategy, IntConsumer rotationChangeListener) { mContext = context; mContentResolver = context.getContentResolver(); diff --git a/quickstep/src/com/android/quickstep/util/WindowSizeStrategy.java b/quickstep/src/com/android/quickstep/util/WindowSizeStrategy.java deleted file mode 100644 index b088ba8e58..0000000000 --- a/quickstep/src/com/android/quickstep/util/WindowSizeStrategy.java +++ /dev/null @@ -1,185 +0,0 @@ -/* - * Copyright (C) 2020 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.android.quickstep.util; - -import static com.android.launcher3.config.FeatureFlags.ENABLE_OVERVIEW_ACTIONS; -import static com.android.quickstep.SysUINavigationMode.getMode; -import static com.android.quickstep.SysUINavigationMode.removeShelfFromOverview; -import static com.android.quickstep.util.LayoutUtils.getDefaultSwipeHeight; - -import android.annotation.TargetApi; -import android.content.Context; -import android.content.res.Resources; -import android.graphics.Rect; -import android.os.Build; - -import com.android.launcher3.DeviceProfile; -import com.android.launcher3.R; -import com.android.launcher3.util.WindowBounds; -import com.android.quickstep.SysUINavigationMode.Mode; - -/** - * Utility class to wrap different layout behavior for Launcher and RecentsView - * TODO: Merge is with {@link com.android.quickstep.BaseActivityInterface} once we remove the - * state dependent members from {@link com.android.quickstep.LauncherActivityInterface} - */ -@TargetApi(Build.VERSION_CODES.R) -public abstract class WindowSizeStrategy { - - public final boolean rotationSupportedByActivity; - - private WindowSizeStrategy(boolean rotationSupportedByActivity) { - this.rotationSupportedByActivity = rotationSupportedByActivity; - } - - /** - * Calculates the taskView size for the provided device configuration - */ - public final void calculateTaskSize(Context context, DeviceProfile dp, Rect outRect) { - calculateTaskSize(context, dp, getExtraSpace(context, dp), outRect); - } - - abstract float getExtraSpace(Context context, DeviceProfile dp); - - private void calculateTaskSize( - Context context, DeviceProfile dp, float extraVerticalSpace, Rect outRect) { - Resources res = context.getResources(); - final boolean showLargeTaskSize = showOverviewActions(context); - - final int paddingResId; - if (dp.isMultiWindowMode) { - paddingResId = R.dimen.multi_window_task_card_horz_space; - } else if (dp.isVerticalBarLayout()) { - paddingResId = R.dimen.landscape_task_card_horz_space; - } else if (showLargeTaskSize) { - paddingResId = R.dimen.portrait_task_card_horz_space_big_overview; - } else { - paddingResId = R.dimen.portrait_task_card_horz_space; - } - float paddingHorz = res.getDimension(paddingResId); - float paddingVert = showLargeTaskSize - ? 0 : res.getDimension(R.dimen.task_card_vert_space); - - calculateTaskSizeInternal(context, dp, extraVerticalSpace, paddingHorz, paddingVert, - res.getDimension(R.dimen.task_thumbnail_top_margin), outRect); - } - - private void calculateTaskSizeInternal(Context context, DeviceProfile dp, - float extraVerticalSpace, float paddingHorz, float paddingVert, float topIconMargin, - Rect outRect) { - float taskWidth, taskHeight; - Rect insets = dp.getInsets(); - if (dp.isMultiWindowMode) { - WindowBounds bounds = SplitScreenBounds.INSTANCE.getSecondaryWindowBounds(context); - taskWidth = bounds.availableSize.x; - taskHeight = bounds.availableSize.y; - } else { - taskWidth = dp.availableWidthPx; - taskHeight = dp.availableHeightPx; - } - - // Note this should be same as dp.availableWidthPx and dp.availableHeightPx unless - // we override the insets ourselves. - int launcherVisibleWidth = dp.widthPx - insets.left - insets.right; - int launcherVisibleHeight = dp.heightPx - insets.top - insets.bottom; - - float availableHeight = launcherVisibleHeight - - topIconMargin - extraVerticalSpace - paddingVert; - float availableWidth = launcherVisibleWidth - paddingHorz; - - float scale = Math.min(availableWidth / taskWidth, availableHeight / taskHeight); - float outWidth = scale * taskWidth; - float outHeight = scale * taskHeight; - - // Center in the visible space - float x = insets.left + (launcherVisibleWidth - outWidth) / 2; - float y = insets.top + Math.max(topIconMargin, - (launcherVisibleHeight - extraVerticalSpace - outHeight) / 2); - outRect.set(Math.round(x), Math.round(y), - Math.round(x) + Math.round(outWidth), Math.round(y) + Math.round(outHeight)); - } - - /** - * Calculates the modal taskView size for the provided device configuration - */ - public void calculateModalTaskSize(Context context, DeviceProfile dp, Rect outRect) { - float paddingHorz = context.getResources().getDimension(dp.isMultiWindowMode - ? R.dimen.multi_window_task_card_horz_space - : dp.isVerticalBarLayout() - ? R.dimen.landscape_task_card_horz_space - : R.dimen.portrait_modal_task_card_horz_space); - float extraVerticalSpace = getOverviewActionsHeight(context); - float paddingVert = 0; - float topIconMargin = 0; - calculateTaskSizeInternal(context, dp, extraVerticalSpace, paddingHorz, paddingVert, - topIconMargin, outRect); - } - - /** Gets the space that the overview actions will take, including margins. */ - public float getOverviewActionsHeight(Context context) { - Resources res = context.getResources(); - float actionsBottomMargin = 0; - if (getMode(context) == Mode.THREE_BUTTONS) { - actionsBottomMargin = res.getDimensionPixelSize( - R.dimen.overview_actions_bottom_margin_three_button); - } else { - actionsBottomMargin = res.getDimensionPixelSize( - R.dimen.overview_actions_bottom_margin_gesture); - } - float overviewActionsHeight = actionsBottomMargin - + res.getDimensionPixelSize(R.dimen.overview_actions_height); - return overviewActionsHeight; - } - - public static final WindowSizeStrategy LAUNCHER_ACTIVITY_SIZE_STRATEGY = - new WindowSizeStrategy(true) { - - @Override - float getExtraSpace(Context context, DeviceProfile dp) { - if (dp.isVerticalBarLayout()) { - return 0; - } else { - Resources res = context.getResources(); - if (showOverviewActions(context)) { - //TODO: this needs to account for the swipe gesture height and accessibility - // UI when shown. - return getOverviewActionsHeight(context); - } else { - return getDefaultSwipeHeight(context, dp) + dp.workspacePageIndicatorHeight - + res.getDimensionPixelSize( - R.dimen.dynamic_grid_hotseat_extra_vertical_size) - + res.getDimensionPixelSize( - R.dimen.dynamic_grid_hotseat_bottom_padding); - } - } - } - }; - - public static final WindowSizeStrategy FALLBACK_RECENTS_SIZE_STRATEGY = - new WindowSizeStrategy(false) { - - @Override - float getExtraSpace(Context context, DeviceProfile dp) { - return showOverviewActions(context) - ? context.getResources().getDimensionPixelSize(R.dimen.overview_actions_height) - : 0; - } - }; - - static boolean showOverviewActions(Context context) { - return ENABLE_OVERVIEW_ACTIONS.get() && removeShelfFromOverview(context); - } -}