Merging WindowSizeStrategy with BaseActivityInterface

Also converting BaseActivityInterface to an abstract class instead of interface
so that it can hold member variables

Change-Id: I04cab934137eb1d6f470c6a7618c50a2ed2c71c1
This commit is contained in:
Sunny Goyal 2020-05-13 10:29:47 -07:00
parent f95f152971
commit d9c0349c1a
21 changed files with 327 additions and 349 deletions

View File

@ -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.<RecentsView>getOverviewPanel().getTaskSize(out);
int taskHeight = out.height();

View File

@ -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 <T> activity that contains the overview
*/
final class AppToOverviewAnimationProvider<T extends BaseDraggingActivity> extends
final class AppToOverviewAnimationProvider<T extends StatefulActivity<?>> extends
RemoteAnimationProvider {
private static final long RECENTS_LAUNCH_DURATION = 250;
private static final String TAG = "AppToOverviewAnimationProvider";
private final BaseActivityInterface<T> mActivityInterface;
private final BaseActivityInterface<?, T> 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<T> activityInterface, int targetTaskId) {
AppToOverviewAnimationProvider(
BaseActivityInterface<?, T> activityInterface, int targetTaskId) {
mActivityInterface = activityInterface;
mTargetTaskId = targetTaskId;
}

View File

@ -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<T extends BaseDraggingActivity, Q extends RecentsView>
public abstract class BaseSwipeUpHandler<T extends StatefulActivity<?>, Q extends RecentsView>
implements RecentsAnimationListener {
private static final String TAG = "BaseSwipeUpHandler";
@ -97,7 +96,7 @@ public abstract class BaseSwipeUpHandler<T extends BaseDraggingActivity, Q exten
protected final Context mContext;
protected final RecentsAnimationDeviceState mDeviceState;
protected final GestureState mGestureState;
protected final BaseActivityInterface<T> mActivityInterface;
protected final BaseActivityInterface<?, T> mActivityInterface;
protected final InputConsumerController mInputConsumer;
protected final TaskViewSimulator mTaskViewSimulator;
@ -132,15 +131,14 @@ public abstract class BaseSwipeUpHandler<T extends BaseDraggingActivity, Q exten
private boolean mRecentsViewScrollLinked = false;
protected BaseSwipeUpHandler(Context context, RecentsAnimationDeviceState deviceState,
GestureState gestureState, InputConsumerController inputConsumer,
WindowSizeStrategy windowSizeStrategy) {
GestureState gestureState, InputConsumerController inputConsumer) {
mContext = context;
mDeviceState = deviceState;
mGestureState = gestureState;
mActivityInterface = gestureState.getActivityInterface();
mActivityInitListener = mActivityInterface.createActivityInitListener(this::onActivityInit);
mInputConsumer = inputConsumer;
mTaskViewSimulator = new TaskViewSimulator(context, windowSizeStrategy);
mTaskViewSimulator = new TaskViewSimulator(context, gestureState.getActivityInterface());
}
/**

View File

@ -20,20 +20,22 @@ import static com.android.launcher3.anim.Interpolators.LINEAR;
import static com.android.quickstep.SysUINavigationMode.Mode.NO_BUTTON;
import static com.android.quickstep.fallback.RecentsState.BACKGROUND_APP;
import static com.android.quickstep.fallback.RecentsState.DEFAULT;
import static com.android.quickstep.util.WindowSizeStrategy.FALLBACK_RECENTS_SIZE_STRATEGY;
import static com.android.quickstep.views.RecentsView.CONTENT_ALPHA;
import static com.android.quickstep.views.RecentsView.FULLSCREEN_PROGRESS;
import android.content.Context;
import android.graphics.PointF;
import android.graphics.Rect;
import androidx.annotation.Nullable;
import com.android.launcher3.DeviceProfile;
import com.android.launcher3.R;
import com.android.launcher3.anim.AnimatorPlaybackController;
import com.android.launcher3.anim.PendingAnimation;
import com.android.launcher3.userevent.nano.LauncherLogProto;
import com.android.quickstep.fallback.FallbackRecentsView;
import com.android.quickstep.fallback.RecentsState;
import com.android.quickstep.util.ActivityInitListener;
import com.android.quickstep.views.RecentsView;
import com.android.systemui.shared.system.RemoteAnimationTargetCompat;
@ -46,19 +48,18 @@ import java.util.function.Predicate;
* currently running one and apps should interact with the {@link RecentsActivity} as opposed
* to the in-launcher one.
*/
public final class FallbackActivityInterface implements
BaseActivityInterface<RecentsActivity> {
public final class FallbackActivityInterface extends
BaseActivityInterface<RecentsState, RecentsActivity> {
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;
}
}

View File

@ -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<RecentsActivity, Fa
public FallbackSwipeHandler(Context context, RecentsAnimationDeviceState deviceState,
GestureState gestureState, InputConsumerController inputConsumer,
boolean isLikelyToStartNewTask, boolean continuingLastGesture) {
super(context, deviceState, gestureState, inputConsumer, FALLBACK_RECENTS_SIZE_STRATEGY);
super(context, deviceState, gestureState, inputConsumer);
mInQuickSwitchMode = isLikelyToStartNewTask || continuingLastGesture;
mContinuingLastGesture = continuingLastGesture;

View File

@ -21,16 +21,21 @@ import static com.android.launcher3.LauncherState.OVERVIEW;
import static com.android.launcher3.anim.Interpolators.ACCEL_2;
import static com.android.launcher3.anim.Interpolators.INSTANT;
import static com.android.launcher3.anim.Interpolators.LINEAR;
import static com.android.launcher3.config.FeatureFlags.ENABLE_OVERVIEW_ACTIONS;
import static com.android.launcher3.uioverrides.states.QuickstepAtomicAnimationFactory.INDEX_RECENTS_FADE_ANIM;
import static com.android.launcher3.uioverrides.states.QuickstepAtomicAnimationFactory.INDEX_RECENTS_TRANSLATE_X_ANIM;
import static com.android.launcher3.uioverrides.states.QuickstepAtomicAnimationFactory.INDEX_SHELF_ANIM;
import static com.android.quickstep.LauncherSwipeHandler.RECENTS_ATTACH_DURATION;
import static com.android.quickstep.util.WindowSizeStrategy.LAUNCHER_ACTIVITY_SIZE_STRATEGY;
import static com.android.quickstep.SysUINavigationMode.getMode;
import static com.android.quickstep.SysUINavigationMode.removeShelfFromOverview;
import static com.android.quickstep.util.LayoutUtils.getDefaultSwipeHeight;
import static com.android.quickstep.views.RecentsView.ADJACENT_PAGE_OFFSET;
import static com.android.quickstep.views.RecentsView.FULLSCREEN_PROGRESS;
import android.animation.Animator;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.PointF;
import android.graphics.Rect;
import android.util.Log;
import android.view.MotionEvent;
@ -44,6 +49,7 @@ import com.android.launcher3.DeviceProfile;
import com.android.launcher3.Launcher;
import com.android.launcher3.LauncherInitListener;
import com.android.launcher3.LauncherState;
import com.android.launcher3.R;
import com.android.launcher3.allapps.DiscoveryBounce;
import com.android.launcher3.anim.AnimatorPlaybackController;
import com.android.launcher3.anim.PendingAnimation;
@ -60,7 +66,6 @@ import com.android.quickstep.util.ShelfPeekAnim.ShelfAnimState;
import com.android.quickstep.views.LauncherRecentsView;
import com.android.quickstep.views.RecentsView;
import com.android.systemui.plugins.shared.LauncherOverlayManager;
import com.android.systemui.shared.recents.model.ThumbnailData;
import com.android.systemui.shared.system.RemoteAnimationTargetCompat;
import java.util.function.Consumer;
@ -69,11 +74,18 @@ import java.util.function.Predicate;
/**
* {@link BaseActivityInterface} for the in-launcher recents.
*/
public final class LauncherActivityInterface implements BaseActivityInterface<Launcher> {
public final class LauncherActivityInterface extends
BaseActivityInterface<LauncherState, Launcher> {
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<La
}
}
@Override
public void onTransitionCancelled(boolean activityVisible) {
Launcher launcher = getCreatedActivity();
if (launcher == null) {
return;
}
LauncherState startState = launcher.getStateManager().getRestState();
launcher.getStateManager().goToState(startState, activityVisible);
}
@Override
public void onSwipeUpToRecentsComplete() {
// Re apply state in case we did something funky during the transition.
super.onSwipeUpToRecentsComplete();
Launcher launcher = getCreatedActivity();
if (launcher == null) {
return;
if (launcher != null) {
DiscoveryBounce.showForOverviewIfNeeded(launcher);
}
launcher.getStateManager().reapplyState();
DiscoveryBounce.showForOverviewIfNeeded(launcher);
}
@Override
@ -113,15 +113,7 @@ public final class LauncherActivityInterface implements BaseActivityInterface<La
// Ensure recents is at the correct position for NORMAL state. For example, when we detach
// recents, we assume the first task is invisible, making translation off by one task.
launcher.getStateManager().reapplyState();
setLauncherHideBackArrow(false);
}
private void setLauncherHideBackArrow(boolean hideBackArrow) {
Launcher launcher = getCreatedActivity();
if (launcher == null) {
return;
}
launcher.getRootView().setForceHideBackArrow(hideBackArrow);
launcher.getRootView().setForceHideBackArrow(false);
}
@Override
@ -336,15 +328,6 @@ public final class LauncherActivityInterface implements BaseActivityInterface<La
launcher.getStateManager().goToState(OVERVIEW);
}
@Override
public void onLaunchTaskSuccess() {
Launcher launcher = getCreatedActivity();
if (launcher == null) {
return;
}
launcher.getStateManager().moveToRestState();
}
@Override
public void closeOverlay() {
Launcher launcher = getCreatedActivity();
@ -359,23 +342,6 @@ public final class LauncherActivityInterface implements BaseActivityInterface<La
}
}
@Override
public void switchRunningTaskViewToScreenshot(ThumbnailData thumbnailData,
Runnable onFinishRunnable) {
Launcher launcher = getCreatedActivity();
if (launcher == null) {
return;
}
RecentsView recentsView = launcher.getOverviewPanel();
if (recentsView == null) {
if (onFinishRunnable != null) {
onFinishRunnable.run();
}
return;
}
recentsView.switchToScreenshot(thumbnailData, onFinishRunnable);
}
@Override
public void setOnDeferredActivityLaunchCallback(Runnable r) {
Launcher launcher = getCreatedActivity();
@ -404,4 +370,50 @@ public final class LauncherActivityInterface implements BaseActivityInterface<La
}
return launcher.getDepthController();
}
@Override
public void getMultiWindowSize(Context context, DeviceProfile dp, PointF out) {
DeviceProfile fullDp = dp.getFullScreenProfile();
// Use availableWidthPx and availableHeightPx instead of widthPx and heightPx to
// account for system insets
out.set(fullDp.availableWidthPx, fullDp.availableHeightPx);
float halfDividerSize = context.getResources()
.getDimension(R.dimen.multi_window_task_divider_size) / 2;
if (fullDp.isLandscape) {
out.x = out.x / 2 - halfDividerSize;
} else {
out.y = out.y / 2 - halfDividerSize;
}
}
@Override
protected 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.
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 actionsHeight = actionsBottomMargin
+ res.getDimensionPixelSize(R.dimen.overview_actions_height);
return actionsHeight;
} 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);
}
}
}
}

View File

@ -35,7 +35,6 @@ import static com.android.quickstep.MultiStateCallback.DEBUG_STATES;
import static com.android.quickstep.SysUINavigationMode.Mode.TWO_BUTTONS;
import static com.android.quickstep.util.ShelfPeekAnim.ShelfAnimState.HIDE;
import static com.android.quickstep.util.ShelfPeekAnim.ShelfAnimState.PEEK;
import static com.android.quickstep.util.WindowSizeStrategy.LAUNCHER_ACTIVITY_SIZE_STRATEGY;
import static com.android.quickstep.views.RecentsView.UPDATE_SYSUI_FLAGS_THRESHOLD;
import android.animation.Animator;
@ -60,7 +59,6 @@ import androidx.annotation.NonNull;
import androidx.annotation.UiThread;
import com.android.launcher3.AbstractFloatingView;
import com.android.launcher3.BaseDraggingActivity;
import com.android.launcher3.DeviceProfile;
import com.android.launcher3.Launcher;
import com.android.launcher3.R;
@ -69,6 +67,7 @@ import com.android.launcher3.anim.AnimationSuccessListener;
import com.android.launcher3.anim.AnimatorPlaybackController;
import com.android.launcher3.anim.Interpolators;
import com.android.launcher3.logging.UserEventDispatcher;
import com.android.launcher3.statemanager.StatefulActivity;
import com.android.launcher3.userevent.nano.LauncherLogProto.Action.Direction;
import com.android.launcher3.userevent.nano.LauncherLogProto.Action.Touch;
import com.android.launcher3.userevent.nano.LauncherLogProto.ContainerType;
@ -198,7 +197,7 @@ public class LauncherSwipeHandler extends BaseSwipeUpHandler<Launcher, RecentsVi
TaskAnimationManager taskAnimationManager, GestureState gestureState,
long touchTimeMs, boolean continuingLastGesture,
InputConsumerController inputConsumer) {
super(context, deviceState, gestureState, inputConsumer, LAUNCHER_ACTIVITY_SIZE_STRATEGY);
super(context, deviceState, gestureState, inputConsumer);
mTaskAnimationManager = taskAnimationManager;
mTouchTimeMs = touchTimeMs;
mContinuingLastGesture = continuingLastGesture;
@ -684,7 +683,7 @@ public class LauncherSwipeHandler extends BaseSwipeUpHandler<Launcher, RecentsVi
setTargetAlphaProvider(LauncherSwipeHandler::getHiddenTargetAlpha);
}
BaseDraggingActivity activity = mActivityInterface.getCreatedActivity();
StatefulActivity activity = mActivityInterface.getCreatedActivity();
return activity == null ? InputConsumer.NO_OP
: new OverviewInputConsumer(mGestureState, activity, null, true);
}

View File

@ -28,9 +28,10 @@ import android.os.SystemClock;
import android.view.ViewConfiguration;
import androidx.annotation.BinderThread;
import com.android.launcher3.BaseDraggingActivity;
import com.android.launcher3.appprediction.PredictionUiStateManager;
import com.android.launcher3.logging.UserEventDispatcher;
import com.android.launcher3.statemanager.StatefulActivity;
import com.android.launcher3.userevent.nano.LauncherLogProto;
import com.android.quickstep.util.ActivityInitListener;
import com.android.quickstep.util.RemoteAnimationProvider;
@ -111,7 +112,7 @@ public class OverviewCommandHelper {
protected void onTransitionComplete() {
// TODO(b/138729100) This doesn't execute first time launcher is run
if (mTriggeredFromAltTab) {
RecentsView rv = (RecentsView) mActivityInterface.getVisibleRecentsView();
RecentsView rv = mActivityInterface.getVisibleRecentsView();
if (rv == null) {
return;
}
@ -136,7 +137,7 @@ public class OverviewCommandHelper {
@Override
protected boolean handleCommand(long elapsedTime) {
RecentsView recents = (RecentsView) mActivityInterface.getVisibleRecentsView();
RecentsView recents = mActivityInterface.getVisibleRecentsView();
if (recents == null) {
return false;
}
@ -150,9 +151,9 @@ public class OverviewCommandHelper {
}
}
private class RecentsActivityCommand<T extends BaseDraggingActivity> implements Runnable {
private class RecentsActivityCommand<T extends StatefulActivity<?>> implements Runnable {
protected final BaseActivityInterface<T> mActivityInterface;
protected final BaseActivityInterface<?, T> mActivityInterface;
private final long mCreateTime;
private final AppToOverviewAnimationProvider<T> mAnimationProvider;

View File

@ -261,10 +261,6 @@ public final class RecentsActivity extends StatefulActivity<RecentsState> {
AccessibilityManagerCompat.sendStateEventToTest(getBaseContext(), OVERVIEW_STATE_ORDINAL);
}
public void onTaskLaunched() {
mFallbackRecentsView.resetTaskVisuals();
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

View File

@ -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<O
public InputConsumer createOverviewInputConsumer(GestureState previousGestureState,
GestureState gestureState, MotionEvent event,
boolean forceOverviewInputConsumer) {
BaseDraggingActivity activity = gestureState.getActivityInterface().getCreatedActivity();
StatefulActivity activity = gestureState.getActivityInterface().getCreatedActivity();
if (activity == null) {
return mResetGestureInputConsumer;
}
@ -754,7 +755,7 @@ public class TouchInteractionService extends Service implements PluginListener<O
return;
}
final BaseActivityInterface<BaseDraggingActivity> activityInterface =
final BaseActivityInterface activityInterface =
mOverviewComponentObserver.getActivityInterface();
final Intent overviewIntent = new Intent(
mOverviewComponentObserver.getOverviewIntentIgnoreSysUiState());

View File

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

View File

@ -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<T extends BaseDraggingActivity>
public class OverviewInputConsumer<T extends StatefulActivity<?>>
implements InputConsumer {
private final T mActivity;
private final BaseActivityInterface<T> mActivityInterface;
private final BaseActivityInterface<?, T> mActivityInterface;
private final BaseDragLayer mTarget;
private final InputMonitorCompat mInputMonitor;

View File

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

View File

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

View File

@ -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<T extends BaseActivity> 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<T extends BaseActivity> 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);

View File

@ -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<T extends BaseDraggingActivity> {
public abstract class BaseActivityInterface<STATE_TYPE extends BaseState<STATE_TYPE>,
ACTIVITY_TYPE extends StatefulActivity<STATE_TYPE>> {
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<AnimatorPlaybackController> callback);
ActivityInitListener createActivityInitListener(Predicate<Boolean> onInitListener);
public abstract ActivityInitListener createActivityInitListener(
Predicate<Boolean> 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 extends View> T getVisibleRecentsView();
public abstract <T extends RecentsView> 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<T extends BaseDraggingActivity> {
*/
default void setRecentsAttachedToAppWindow(boolean attached, boolean animate) { }
}
protected static boolean showOverviewActions(Context context) {
return ENABLE_OVERVIEW_ACTIONS.get() && removeShelfFromOverview(context);
}
}

View File

@ -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 <T extends BaseDraggingActivity> BaseActivityInterface<T> getActivityInterface() {
public <T extends StatefulActivity<?>> BaseActivityInterface<?, T> getActivityInterface() {
return mActivityInterface;
}

View File

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

View File

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

View File

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

View File

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