Merge "Annotate RecentsView with @Nullable"
diff --git a/quickstep/src/com/android/quickstep/BaseActivityInterface.java b/quickstep/src/com/android/quickstep/BaseActivityInterface.java
index f9b749e..e15aa92 100644
--- a/quickstep/src/com/android/quickstep/BaseActivityInterface.java
+++ b/quickstep/src/com/android/quickstep/BaseActivityInterface.java
@@ -322,11 +322,11 @@
public final void calculateGridTaskSize(Context context, DeviceProfile dp, Rect outRect,
PagedOrientationHandler orientedState) {
Resources res = context.getResources();
- Rect gridRect = new Rect();
- calculateGridSize(context, dp, gridRect);
+ Rect taskRect = new Rect();
+ calculateTaskSize(context, dp, taskRect);
float rowHeight =
- (gridRect.height() + dp.overviewTaskThumbnailTopMarginPx - dp.overviewRowSpacing)
+ (taskRect.height() + dp.overviewTaskThumbnailTopMarginPx - dp.overviewRowSpacing)
/ 2f;
PointF taskDimension = getTaskDimension(context, dp);
@@ -336,7 +336,7 @@
int gravity = Gravity.TOP;
gravity |= orientedState.getRecentsRtlSetting(res) ? Gravity.RIGHT : Gravity.LEFT;
- Gravity.apply(gravity, outWidth, outHeight, gridRect, outRect);
+ Gravity.apply(gravity, outWidth, outHeight, taskRect, outRect);
}
/**
diff --git a/quickstep/src/com/android/quickstep/OverviewCommandHelper.java b/quickstep/src/com/android/quickstep/OverviewCommandHelper.java
index 26d935d..75e8dd1 100644
--- a/quickstep/src/com/android/quickstep/OverviewCommandHelper.java
+++ b/quickstep/src/com/android/quickstep/OverviewCommandHelper.java
@@ -117,11 +117,12 @@
mPendingCommands.clear();
}
+ @Nullable
private TaskView getNextTask(RecentsView view) {
final TaskView runningTaskView = view.getRunningTaskView();
if (runningTaskView == null) {
- return view.getTaskViewCount() > 0 ? view.getTaskViewAt(0) : null;
+ return view.getTaskViewAt(0);
} else {
final TaskView nextTask = view.getNextTaskView();
return nextTask != null ? nextTask : runningTaskView;
@@ -256,8 +257,8 @@
// Ensure that recents view has focus so that it receives the followup key inputs
TaskView taskView = rv.getNextTaskView();
if (taskView == null) {
- if (rv.getTaskViewCount() > 0) {
- taskView = rv.getTaskViewAt(0);
+ taskView = rv.getTaskViewAt(0);
+ if (taskView != null) {
taskView.requestFocus();
} else {
rv.requestFocus();
diff --git a/quickstep/src/com/android/quickstep/TaskViewUtils.java b/quickstep/src/com/android/quickstep/TaskViewUtils.java
index 67a94cc..ae3cc50 100644
--- a/quickstep/src/com/android/quickstep/TaskViewUtils.java
+++ b/quickstep/src/com/android/quickstep/TaskViewUtils.java
@@ -215,6 +215,7 @@
tvsLocal.taskSecondaryTranslation.value = gridTranslationSecondary;
}
tvsLocal.setScroll(startScroll);
+ tvsLocal.setIsGridTask(v.isGridTask());
// Fade in the task during the initial 20% of the animation
out.addFloat(targetHandle.getTransformParams(), TransformParams.TARGET_ALPHA, 0, 1,
diff --git a/quickstep/src/com/android/quickstep/util/SplitSelectStateController.java b/quickstep/src/com/android/quickstep/util/SplitSelectStateController.java
index e1afa97..b32c4e5 100644
--- a/quickstep/src/com/android/quickstep/util/SplitSelectStateController.java
+++ b/quickstep/src/com/android/quickstep/util/SplitSelectStateController.java
@@ -21,8 +21,10 @@
import static com.android.launcher3.util.SplitConfigurationOptions.STAGE_POSITION_BOTTOM_OR_RIGHT;
import static com.android.launcher3.util.SplitConfigurationOptions.STAGE_POSITION_TOP_OR_LEFT;
+import android.app.ActivityOptions;
import android.app.ActivityThread;
import android.graphics.Rect;
+import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import android.view.RemoteAnimationAdapter;
@@ -78,14 +80,15 @@
*/
public void setSecondTaskId(Task taskView, Consumer<Boolean> callback) {
mSecondTask = taskView;
- launchTasks(mInitialTask, mSecondTask, mStagePosition, callback);
+ launchTasks(mInitialTask, mSecondTask, mStagePosition, callback,
+ false /* freezeTaskList */);
}
/**
* @param stagePosition representing location of task1
*/
public void launchTasks(Task task1, Task task2, @StagePosition int stagePosition,
- Consumer<Boolean> callback) {
+ Consumer<Boolean> callback, boolean freezeTaskList) {
// Assume initial task is for top/left part of screen
final int[] taskIds = stagePosition == STAGE_POSITION_TOP_OR_LEFT
? new int[]{task1.key.id, task2.key.id}
@@ -105,8 +108,13 @@
300, 150,
ActivityThread.currentActivityThread().getApplicationThread());
- mSystemUiProxy.startTasksWithLegacyTransition(taskIds[0], null /* mainOptions */,
- taskIds[1], null /* sideOptions */, STAGE_POSITION_BOTTOM_OR_RIGHT, adapter);
+ ActivityOptions mainOpts = ActivityOptions.makeBasic();
+ if (freezeTaskList) {
+ mainOpts.setFreezeRecentTasksReordering();
+ }
+ mSystemUiProxy.startTasksWithLegacyTransition(taskIds[0], mainOpts.toBundle(),
+ taskIds[1], null /* sideOptions */, STAGE_POSITION_BOTTOM_OR_RIGHT,
+ adapter);
}
}
diff --git a/quickstep/src/com/android/quickstep/util/TaskViewSimulator.java b/quickstep/src/com/android/quickstep/util/TaskViewSimulator.java
index 280b5d7..146d235 100644
--- a/quickstep/src/com/android/quickstep/util/TaskViewSimulator.java
+++ b/quickstep/src/com/android/quickstep/util/TaskViewSimulator.java
@@ -101,6 +101,7 @@
private int mOrientationStateId;
private StagedSplitBounds mStagedSplitBounds;
private boolean mDrawsBelowRecents;
+ private boolean mIsGridTask;
public TaskViewSimulator(Context context, BaseActivityInterface sizeStrategy) {
mContext = context;
@@ -140,18 +141,23 @@
if (mDp == null) {
return 1;
}
- Rect fullTaskSize = new Rect();
- mSizeStrategy.calculateTaskSize(mContext, mDp, fullTaskSize);
+ if (mIsGridTask) {
+ mSizeStrategy.calculateGridTaskSize(mContext, mDp, mTaskRect,
+ mOrientationState.getOrientationHandler());
+ } else {
+ mSizeStrategy.calculateTaskSize(mContext, mDp, mTaskRect);
+ }
+ Rect fullTaskSize;
if (mStagedSplitBounds != null) {
// The task rect changes according to the staged split task sizes, but recents
// fullscreen scale and pivot remains the same since the task fits into the existing
// sized task space bounds
- mSizeStrategy.calculateTaskSize(mContext, mDp, mTaskRect);
+ fullTaskSize = new Rect(mTaskRect);
mOrientationState.getOrientationHandler()
.setSplitTaskSwipeRect(mDp, mTaskRect, mStagedSplitBounds, mStagePosition);
} else {
- mTaskRect.set(fullTaskSize);
+ fullTaskSize = mTaskRect;
}
return mOrientationState.getFullScreenScaleAndPivot(fullTaskSize, mDp, mPivot);
}
@@ -205,6 +211,13 @@
}
/**
+ * Sets whether the task is part of overview grid and not being focused.
+ */
+ public void setIsGridTask(boolean isGridTask) {
+ mIsGridTask = isGridTask;
+ }
+
+ /**
* Adds animation for all the components corresponding to transition from an app to overview.
*/
public void addAppToOverviewAnim(PendingAnimation pa, TimeInterpolator interpolator) {
diff --git a/quickstep/src/com/android/quickstep/views/GroupedTaskView.java b/quickstep/src/com/android/quickstep/views/GroupedTaskView.java
index db4b743..30b55a8 100644
--- a/quickstep/src/com/android/quickstep/views/GroupedTaskView.java
+++ b/quickstep/src/com/android/quickstep/views/GroupedTaskView.java
@@ -160,14 +160,15 @@
@Override
public RunnableList launchTaskAnimated() {
getRecentsView().getSplitPlaceholder().launchTasks(mTask, mSecondaryTask,
- STAGE_POSITION_TOP_OR_LEFT, null /*callback*/);
+ STAGE_POSITION_TOP_OR_LEFT, null /*callback*/,
+ false /* freezeTaskList */);
return null;
}
@Override
public void launchTask(@NonNull Consumer<Boolean> callback, boolean freezeTaskList) {
getRecentsView().getSplitPlaceholder().launchTasks(mTask, mSecondaryTask,
- STAGE_POSITION_TOP_OR_LEFT, callback);
+ STAGE_POSITION_TOP_OR_LEFT, callback, freezeTaskList);
}
@Override
diff --git a/quickstep/src/com/android/quickstep/views/RecentsView.java b/quickstep/src/com/android/quickstep/views/RecentsView.java
index a2392e9..92f1a67 100644
--- a/quickstep/src/com/android/quickstep/views/RecentsView.java
+++ b/quickstep/src/com/android/quickstep/views/RecentsView.java
@@ -1040,8 +1040,10 @@
@Nullable
private TaskView getLastGridTaskView() {
- IntArray topRowIdArray = getTopRowIdArray();
- IntArray bottomRowIdArray = getBottomRowIdArray();
+ return getLastGridTaskView(getTopRowIdArray(), getBottomRowIdArray());
+ }
+
+ private TaskView getLastGridTaskView(IntArray topRowIdArray, IntArray bottomRowIdArray) {
if (topRowIdArray.isEmpty() && bottomRowIdArray.isEmpty()) {
return null;
}
@@ -3172,38 +3174,23 @@
}
}
- TaskView newLastGridTaskView = getLastGridTaskView();
+ IntArray topRowIdArray = getTopRowIdArray();
+ IntArray bottomRowIdArray = getBottomRowIdArray();
if (finalSnapToLastTask) {
// If snapping to last task, find the last task after dismissal.
- pageToSnapTo = indexOfChild(newLastGridTaskView);
+ pageToSnapTo = indexOfChild(
+ getLastGridTaskView(topRowIdArray, bottomRowIdArray));
} else if (taskViewIdToSnapTo != -1) {
// If snapping to another page due to indices rearranging, find
// the new index after dismissal & rearrange using the task view id.
pageToSnapTo = indexOfChild(
getTaskViewFromTaskViewId(taskViewIdToSnapTo));
- int taskViewToSnapToScroll = getScrollForPage(pageToSnapTo);
- int lastGridTaskScroll = getScrollForPage(
- indexOfChild(newLastGridTaskView));
- if (!currentPageSnapsToEndOfGrid
- && taskViewToSnapToScroll == lastGridTaskScroll) {
+ if (!currentPageSnapsToEndOfGrid) {
// If it wasn't snapped to one of the last pages, but is now
// snapped to last pages, we'll need to compensate for the
- // difference as last pages' scroll is the position where
- // ClearAllButton is barely invisible, instead of aligned to
- // mLastComputedTaskSize.
- int normalTaskEnd = mIsRtl
- ? mLastComputedTaskSize.right
- : mLastComputedTaskSize.left;
- int lastTaskStart = mIsRtl
- ? mLastComputedGridSize.left
- : mLastComputedGridSize.right;
- // As snapped task is not the last task, it can only be the
- // second last task.
- int distanceToSnappedTaskEnd =
- (mPageSpacing + mLastComputedGridTaskSize.width()) * 2;
- int snappedTaskEnd = lastTaskStart + (mIsRtl
- ? distanceToSnappedTaskEnd : -distanceToSnappedTaskEnd);
- mCurrentPageScrollDiff += snappedTaskEnd - normalTaskEnd;
+ // offset from the page's scroll to its visual position.
+ mCurrentPageScrollDiff += getOffsetFromScrollPosition(
+ pageToSnapTo, topRowIdArray, bottomRowIdArray);
}
}
}
@@ -4643,7 +4630,58 @@
overScrollShift, getUndampedOverScrollShift());
}
return getScrollForPage(pageIndex) - mOrientationHandler.getPrimaryScroll(this)
- + overScrollShift;
+ + overScrollShift + getOffsetFromScrollPosition(pageIndex);
+ }
+
+ /**
+ * Returns how many pixels the page is offset from its scroll position.
+ */
+ private int getOffsetFromScrollPosition(int pageIndex) {
+ return getOffsetFromScrollPosition(pageIndex, getTopRowIdArray(), getBottomRowIdArray());
+ }
+
+ private int getOffsetFromScrollPosition(
+ int pageIndex, IntArray topRowIdArray, IntArray bottomRowIdArray) {
+ if (!showAsGrid()) {
+ return 0;
+ }
+
+ TaskView taskView = getTaskViewAt(pageIndex);
+ if (taskView == null) {
+ return 0;
+ }
+
+ TaskView lastGridTaskView = getLastGridTaskView(topRowIdArray, bottomRowIdArray);
+ if (lastGridTaskView == null) {
+ return 0;
+ }
+
+ if (getScrollForPage(pageIndex) != getScrollForPage(indexOfChild(lastGridTaskView))) {
+ return 0;
+ }
+
+ // Check distance from lastGridTaskView to taskView.
+ int lastGridTaskViewPosition =
+ getPositionInRow(lastGridTaskView, topRowIdArray, bottomRowIdArray);
+ int taskViewPosition = getPositionInRow(taskView, topRowIdArray, bottomRowIdArray);
+ int gridTaskSizeAndSpacing = mLastComputedGridTaskSize.width() + mPageSpacing;
+ int positionDiff = gridTaskSizeAndSpacing * (lastGridTaskViewPosition - taskViewPosition);
+
+ int lastTaskEnd = (mIsRtl
+ ? mLastComputedGridSize.left
+ : mLastComputedGridSize.right)
+ + (mIsRtl ? mPageSpacing : -mPageSpacing);
+ int taskEnd = lastTaskEnd + (mIsRtl ? positionDiff : -positionDiff);
+ int normalTaskEnd = mIsRtl
+ ? mLastComputedGridTaskSize.left
+ : mLastComputedGridTaskSize.right;
+ return taskEnd - normalTaskEnd;
+ }
+
+ private int getPositionInRow(
+ TaskView taskView, IntArray topRowIdArray, IntArray bottomRowIdArray) {
+ int position = topRowIdArray.indexOf(taskView.getTaskViewId());
+ return position != -1 ? position : bottomRowIdArray.indexOf(taskView.getTaskViewId());
}
/**
diff --git a/quickstep/src/com/android/quickstep/views/TaskView.java b/quickstep/src/com/android/quickstep/views/TaskView.java
index 1952c6d..3da7893 100644
--- a/quickstep/src/com/android/quickstep/views/TaskView.java
+++ b/quickstep/src/com/android/quickstep/views/TaskView.java
@@ -883,7 +883,7 @@
LayoutParams snapshotParams = (LayoutParams) mSnapshotView.getLayoutParams();
DeviceProfile deviceProfile = mActivity.getDeviceProfile();
snapshotParams.topMargin = deviceProfile.overviewTaskThumbnailTopMarginPx;
- boolean isGridTask = deviceProfile.overviewShowAsGrid && !isFocusedTask();
+ boolean isGridTask = isGridTask();
int taskIconHeight = deviceProfile.overviewTaskIconSizePx;
int taskMargin = isGridTask ? deviceProfile.overviewTaskMarginGridPx
: deviceProfile.overviewTaskMarginPx;
@@ -903,6 +903,14 @@
mSnapshotView.getTaskOverlay().updateOrientationState(orientationState);
}
+ /**
+ * Returns whether the task is part of overview grid and not being focused.
+ */
+ public boolean isGridTask() {
+ DeviceProfile deviceProfile = mActivity.getDeviceProfile();
+ return deviceProfile.overviewShowAsGrid && !isFocusedTask();
+ }
+
private void setIconAndDimTransitionProgress(float progress, boolean invert) {
if (invert) {
progress = 1 - progress;