Use fixed width in overveiw grid

- Removed thumbnail ratio logic in TaskView, getVisibleThumbnailRatio will be clean up separately
- Removed quickswitch clipping and scaling, so overview and quickswitch looks identical. mClippedInsets will be clean up separately
- Put focused task in center of screen
- Refacotred CLearAllButton spacing

Bug: 187839470
Test: Manual
Change-Id: I2a7df1ac02acd5379af33f5b0e9abba0fab8e8d2
This commit is contained in:
Alex Chau 2021-05-14 17:43:03 +01:00 committed by Baligh Uddin
parent 194dcc0fd3
commit 5d35355fd1
5 changed files with 35 additions and 84 deletions

View File

@ -16,7 +16,7 @@
<resources>
<dimen name="task_thumbnail_icon_size">48dp</dimen>
<dimen name="task_thumbnail_icon_size_grid">32dp</dimen>
<dimen name="task_thumbnail_icon_size_grid">40dp</dimen>
<!-- For screens without rounded corners -->
<dimen name="task_corner_radius_small">2dp</dimen>
<!-- For Launchers that want to override the default dialog corner radius -->
@ -35,10 +35,10 @@
<dimen name="overview_actions_horizontal_margin">16dp</dimen>
<dimen name="overview_grid_top_margin">77dp</dimen>
<dimen name="overview_grid_bottom_margin">90dp</dimen>
<dimen name="overview_grid_bottom_margin">70dp</dimen>
<dimen name="overview_grid_side_margin">54dp</dimen>
<dimen name="overview_grid_row_spacing">42dp</dimen>
<dimen name="overview_grid_focus_vertical_margin">90dp</dimen>
<dimen name="overview_grid_focus_vertical_margin">40dp</dimen>
<dimen name="split_placeholder_size">110dp</dimen>
<!-- These speeds are in dp/s -->

View File

@ -197,17 +197,18 @@ public abstract class BaseActivityInterface<STATE_TYPE extends BaseState<STATE_T
Rect gridRect = new Rect();
calculateGridSize(context, dp, gridRect);
int verticalMargin = res.getDimensionPixelSize(
R.dimen.overview_grid_focus_vertical_margin);
float taskHeight = gridRect.height() - verticalMargin * 2;
int verticalMargin = Math.max(
res.getDimensionPixelSize(R.dimen.overview_grid_focus_vertical_margin),
res.getDimensionPixelSize(R.dimen.overview_actions_height));
float taskHeight =
gridRect.height() - verticalMargin * 2 - dp.overviewTaskThumbnailTopMarginPx;
PointF taskDimension = getTaskDimension(context, dp);
float scale = taskHeight / Math.max(taskDimension.x, taskDimension.y);
float scale = taskHeight / taskDimension.y;
int outWidth = Math.round(scale * taskDimension.x);
int outHeight = Math.round(scale * taskDimension.y);
int gravity = Gravity.CENTER_VERTICAL;
gravity |= orientedState.getRecentsRtlSetting(res) ? Gravity.RIGHT : Gravity.LEFT;
int gravity = Gravity.CENTER;
Gravity.apply(gravity, outWidth, outHeight, gridRect, outRect);
} else {
int taskMargin = dp.overviewTaskMarginPx;
@ -296,8 +297,7 @@ public abstract class BaseActivityInterface<STATE_TYPE extends BaseState<STATE_T
float rowHeight = (gridRect.height() - rowSpacing) / 2f;
PointF taskDimension = getTaskDimension(context, dp);
float scale = (rowHeight - dp.overviewTaskThumbnailTopMarginPx) / Math.max(
taskDimension.x, taskDimension.y);
float scale = (rowHeight - dp.overviewTaskThumbnailTopMarginPx) / taskDimension.y;
int outWidth = Math.round(scale * taskDimension.x);
int outHeight = Math.round(scale * taskDimension.y);

View File

@ -485,7 +485,6 @@ public abstract class RecentsView<ACTIVITY_TYPE extends StatefulActivity<STATE_T
protected boolean mRunningTaskTileHidden;
private Task mTmpRunningTask;
protected int mFocusedTaskId = -1;
private float mFocusedTaskRatio;
private boolean mRunningTaskIconScaledDown = false;
@ -1348,19 +1347,7 @@ public abstract class RecentsView<ACTIVITY_TYPE extends StatefulActivity<STATE_T
public Point getSelectedTaskSize() {
mSizeStrategy.calculateTaskSize(mActivity, mActivity.getDeviceProfile(), mTempRect,
mOrientationHandler);
int taskWidth = mTempRect.width();
int taskHeight = mTempRect.height();
if (mRunningTaskId != -1) {
int boxLength = Math.max(taskWidth, taskHeight);
if (mFocusedTaskRatio > 1) {
taskWidth = boxLength;
taskHeight = (int) (boxLength / mFocusedTaskRatio);
} else {
taskWidth = (int) (boxLength * mFocusedTaskRatio);
taskHeight = boxLength;
}
}
return new Point(taskWidth, taskHeight);
return new Point(mTempRect.width(), mTempRect.height());
}
/** Gets the last computed task size */
@ -1589,13 +1576,6 @@ public abstract class RecentsView<ACTIVITY_TYPE extends StatefulActivity<STATE_T
return getTaskView(mFocusedTaskId);
}
/**
* Returns the width to height ratio of the focused {@link TaskView}.
*/
public float getFocusedTaskRatio() {
return mFocusedTaskRatio;
}
/**
* Get the index of the task view whose id matches {@param taskId}.
* @return -1 if there is no task view for the task id, else the index of the task view.
@ -1775,7 +1755,7 @@ public abstract class RecentsView<ACTIVITY_TYPE extends StatefulActivity<STATE_T
int runningTaskId = runningTaskInfo == null ? -1 : runningTaskInfo.taskId;
setCurrentTask(runningTaskId);
if (mActivity.getDeviceProfile().isTablet && FeatureFlags.ENABLE_OVERVIEW_GRID.get()) {
setFocusedTask(runningTaskId);
mFocusedTaskId = runningTaskId;
}
setCurrentPage(getRunningTaskIndex());
setRunningTaskViewShowScreenshot(false);
@ -1804,15 +1784,6 @@ public abstract class RecentsView<ACTIVITY_TYPE extends StatefulActivity<STATE_T
mRunningTaskId = runningTaskId;
}
/**
* Sets the focused task id and store the width to height ratio of the focused task.
*/
protected void setFocusedTask(int focusedTaskId) {
mFocusedTaskId = focusedTaskId;
mFocusedTaskRatio =
mLastComputedTaskSize.width() / (float) mLastComputedTaskSize.height();
}
/**
* Hides the tile associated with {@link #mRunningTaskId}
*/
@ -1902,8 +1873,6 @@ public abstract class RecentsView<ACTIVITY_TYPE extends StatefulActivity<STATE_T
return;
}
final int boxLength = Math.max(mLastComputedGridTaskSize.width(),
mLastComputedGridTaskSize.height());
int taskTopMargin = mActivity.getDeviceProfile().overviewTaskThumbnailTopMarginPx;
/*
@ -1914,7 +1883,8 @@ public abstract class RecentsView<ACTIVITY_TYPE extends StatefulActivity<STATE_T
*/
final float taskGridVerticalDiff =
mLastComputedGridTaskSize.top - mLastComputedTaskSize.top;
final float heightOffset = (boxLength + taskTopMargin) + mRowSpacing;
final float heightOffset =
(mLastComputedGridTaskSize.height() + taskTopMargin) + mRowSpacing;
int topRowWidth = 0;
int bottomRowWidth = 0;
@ -2058,20 +2028,9 @@ public abstract class RecentsView<ACTIVITY_TYPE extends StatefulActivity<STATE_T
float clearAllShorterRowCompensation =
mIsRtl ? -shorterRowCompensation : shorterRowCompensation;
// If the total width is shorter than one grid's width, move ClearAllButton further away
// accordingly. Update longRowWidth if ClearAllButton has been moved.
float clearAllShortTotalCompensation = 0;
int longRowWidth = Math.max(topRowWidth, bottomRowWidth);
if (longRowWidth < mLastComputedGridSize.width()) {
float shortTotalCompensation = mLastComputedGridSize.width() - longRowWidth;
clearAllShortTotalCompensation =
mIsRtl ? -shortTotalCompensation : shortTotalCompensation;
longRowWidth = mLastComputedGridSize.width();
}
float clearAllTotalTranslationX =
clearAllAccumulatedTranslation + clearAllShorterRowCompensation
+ clearAllShortTotalCompensation + snappedTaskFullscreenScrollAdjustment;
+ snappedTaskFullscreenScrollAdjustment;
if (focusedTaskIndex < taskCount) {
// Shift by focused task's width and spacing if a task is focused.
clearAllTotalTranslationX +=
@ -2081,9 +2040,12 @@ public abstract class RecentsView<ACTIVITY_TYPE extends StatefulActivity<STATE_T
// Make sure there are enough space between snapped page and ClearAllButton, for the case
// of swiping up after quick switch.
if (snappedTaskView != null) {
int longRowWidth = Math.max(topRowWidth, bottomRowWidth);
int distanceFromClearAll = longRowWidth - snappedTaskRowWidth;
// ClearAllButton should be off screen when snapped task is in its snapped position.
int minimumDistance =
mLastComputedGridSize.width() - snappedTaskView.getLayoutParams().width;
mTaskWidth - snappedTaskView.getLayoutParams().width
+ (mLastComputedGridSize.width() - mTaskWidth) / 2;
if (distanceFromClearAll < minimumDistance) {
int distanceDifference = minimumDistance - distanceFromClearAll;
clearAllTotalTranslationX += mIsRtl ? -distanceDifference : distanceDifference;

View File

@ -411,7 +411,9 @@ public class TaskThumbnailView extends View implements PluginListener<OverviewSc
*/
public static class PreviewPositionHelper {
// Contains the portion of the thumbnail that is clipped when fullscreen progress = 0.
private static final RectF EMPTY_RECT_F = new RectF();
// Contains the portion of the thumbnail that is unclipped when fullscreen progress = 1.
private final RectF mClippedInsets = new RectF();
private final Matrix mMatrix = new Matrix();
private boolean mIsOrientationChanged;
@ -616,15 +618,17 @@ public class TaskThumbnailView extends View implements PluginListener<OverviewSc
break;
}
mClippedInsets.offsetTo(newLeftInset * scale, newTopInset * scale);
mMatrix.postTranslate(translateX - mClippedInsets.left,
translateY - mClippedInsets.top);
mMatrix.postTranslate(translateX, translateY);
if (TaskView.FULL_THUMBNAIL) {
mMatrix.postTranslate(-mClippedInsets.left, -mClippedInsets.top);
}
}
/**
* Insets to used for clipping the thumbnail (in case it is drawing outside its own space)
*/
public RectF getInsetsToDrawInFullscreen() {
return mClippedInsets;
return TaskView.FULL_THUMBNAIL ? mClippedInsets : EMPTY_RECT_F;
}
}
}

View File

@ -141,6 +141,11 @@ public class TaskView extends FrameLayout implements Reusable {
*/
public static final boolean CLIP_STATUS_AND_NAV_BARS = false;
/**
* Should the TaskView scale down to fit whole thumbnail in fullscreen.
*/
public static final boolean FULL_THUMBNAIL = false;
private static final float EDGE_SCALE_DOWN_FACTOR_CAROUSEL = 0.03f;
private static final float EDGE_SCALE_DOWN_FACTOR_GRID = 0.00f;
@ -1343,46 +1348,26 @@ public class TaskView extends FrameLayout implements Reusable {
int boxWidth;
int boxHeight;
float thumbnailRatio;
boolean isFocusedTask = isFocusedTask();
if (isFocusedTask) {
// Task will be focused and should use focused task size. Use focusTaskRatio
// that is associated with the original orientation of the focused task.
boxWidth = taskWidth;
boxHeight = taskHeight;
thumbnailRatio = getRecentsView().getFocusedTaskRatio();
} else {
// Otherwise task is in grid, and should use lastComputedGridTaskSize.
Rect lastComputedGridTaskSize = getRecentsView().getLastComputedGridTaskSize();
boxWidth = lastComputedGridTaskSize.width();
boxHeight = lastComputedGridTaskSize.height();
thumbnailRatio = mTask != null ? mTask.getVisibleThumbnailRatio(
TaskView.CLIP_STATUS_AND_NAV_BARS) : 0f;
}
int boxLength = Math.max(boxWidth, boxHeight);
// Bound width/height to the box size.
if (thumbnailRatio == 0f) {
expectedWidth = boxWidth;
expectedHeight = boxHeight + thumbnailPadding;
} else if (thumbnailRatio > 1) {
expectedWidth = boxLength;
expectedHeight = (int) (boxLength / thumbnailRatio) + thumbnailPadding;
} else {
expectedWidth = (int) (boxLength * thumbnailRatio);
expectedHeight = boxLength + thumbnailPadding;
}
expectedWidth = boxWidth;
expectedHeight = boxHeight + thumbnailPadding;
// Scale to to fit task Rect.
fullscreenScale = taskWidth / (float) boxWidth;
// In full screen, scale back TaskView to original size.
if (expectedWidth > boxWidth) {
fullscreenScale *= boxWidth / (float) expectedWidth;
} else if (expectedHeight - thumbnailPadding > boxHeight) {
fullscreenScale *= boxHeight / (float) (expectedHeight - thumbnailPadding);
}
// Align to top of task Rect.
boxTranslationY = (expectedHeight - thumbnailPadding - taskHeight) / 2.0f;
} else {