Merge "Calculate grid layout size separately from task size" into sc-dev

This commit is contained in:
TreeHugger Robot
2021-03-11 22:51:00 +00:00
committed by Android (Google) Code Review
4 changed files with 73 additions and 39 deletions

View File

@@ -29,7 +29,11 @@
<dimen name="overview_actions_bottom_margin_three_button">8dp</dimen>
<dimen name="overview_actions_horizontal_margin">16dp</dimen>
<dimen name="recents_row_spacing">48dp</dimen>
<dimen name="overview_grid_top_margin">77dp</dimen>
<dimen name="overview_grid_bottom_margin">90dp</dimen>
<dimen name="overview_grid_side_margin">54dp</dimen>
<dimen name="overview_grid_row_spacing">42dp</dimen>
<dimen name="recents_page_spacing">16dp</dimen>
<dimen name="recents_clear_all_deadzone_vertical_margin">70dp</dimen>

View File

@@ -257,6 +257,21 @@ public abstract class BaseActivityInterface<STATE_TYPE extends BaseState<STATE_T
Math.round(x) + Math.round(outWidth), Math.round(y) + Math.round(outHeight));
}
/**
* Calculates the overview grid size for the provided device configuration.
*/
public final void calculateGridSize(Context context, DeviceProfile dp, Rect outRect) {
Resources res = context.getResources();
int topMargin = res.getDimensionPixelSize(R.dimen.overview_grid_top_margin);
int bottomMargin = res.getDimensionPixelSize(R.dimen.overview_grid_bottom_margin);
int sideMargin = res.getDimensionPixelSize(R.dimen.overview_grid_side_margin);
Rect insets = dp.getInsets();
outRect.set(0, 0, dp.widthPx, dp.heightPx);
outRect.inset(Math.max(insets.left, sideMargin), Math.max(insets.top, topMargin),
Math.max(insets.right, sideMargin), Math.max(insets.bottom, bottomMargin));
}
/**
* Calculates the modal taskView size for the provided device configuration
*/

View File

@@ -79,6 +79,7 @@ public class TaskViewSimulator implements TransformParams.BuilderProxy {
private final boolean mIsRecentsRtl;
private final Rect mTaskRect = new Rect();
private final Rect mGridRect = new Rect();
private boolean mDrawsBelowRecents;
private final PointF mPivot = new PointF();
private DeviceProfile mDp;
@@ -124,7 +125,7 @@ public class TaskViewSimulator implements TransformParams.BuilderProxy {
Resources resources = context.getResources();
mIsRecentsRtl = mOrientationState.getOrientationHandler().getRecentsRtlSetting(resources);
mTaskThumbnailPadding = (int) resources.getDimension(R.dimen.task_thumbnail_top_margin);
mRowSpacing = (int) resources.getDimension(R.dimen.recents_row_spacing);
mRowSpacing = (int) resources.getDimension(R.dimen.overview_grid_row_spacing);
}
/**
@@ -266,6 +267,7 @@ public class TaskViewSimulator implements TransformParams.BuilderProxy {
mOrientationStateId = mOrientationState.getStateId();
getFullScreenScale();
mSizeStrategy.calculateGridSize(mContext, mDp, mGridRect);
mThumbnailData.rotation = mOrientationState.getDisplayRotation();
mPositionHelper.updateThumbnailMatrix(
@@ -304,24 +306,34 @@ public class TaskViewSimulator implements TransformParams.BuilderProxy {
mMatrix.postTranslate(insets.left, insets.top);
mMatrix.postScale(scale, scale);
// Apply TaskView matrix: gridProgress related properties
float interpolatedGridProgress = ACCEL_DEACCEL.getInterpolation(gridProgress.value);
// Apply TaskView matrix: gridProgress
final int boxLength = (int) Math.max(taskWidth, taskHeight);
float availableHeight =
mTaskThumbnailPadding + taskHeight + mSizeStrategy.getOverviewActionsHeight(
mContext);
float availableHeight = mGridRect.height();
float rowHeight = (availableHeight - mRowSpacing) / 2;
float gridScale = rowHeight / (boxLength + mTaskThumbnailPadding);
scale = Utilities.mapRange(interpolatedGridProgress, 1f, gridScale);
mMatrix.postScale(scale, scale, mIsRecentsRtl ? 0 : taskWidth, 0);
float taskWidthDiff = taskWidth * (1 - gridScale);
float taskWidthOffset = mIsRecentsRtl ? taskWidthDiff : -taskWidthDiff;
mOrientationState.getOrientationHandler().set(mMatrix, MATRIX_POST_TRANSLATE,
Utilities.mapRange(interpolatedGridProgress, 0, taskWidthOffset));
mOrientationState.getOrientationHandler().setSecondary(mMatrix, MATRIX_POST_TRANSLATE,
Utilities.mapRange(interpolatedGridProgress, 0, gridTranslationSecondary.value));
// Apply TaskView matrix: task rect and grid rect difference
float scaledWidth = taskWidth * gridScale;
float taskGridHorizontalDiff;
if (mIsRecentsRtl) {
float taskRight = mTaskRect.left + scaledWidth;
taskGridHorizontalDiff = mGridRect.right - taskRight;
} else {
float taskLeft = mTaskRect.right - scaledWidth;
taskGridHorizontalDiff = mGridRect.left - taskLeft;
}
float taskGridVerticalDiff =
mGridRect.top + mTaskThumbnailPadding * gridScale - mTaskRect.top;
mOrientationState.getOrientationHandler().set(mMatrix, MATRIX_POST_TRANSLATE,
Utilities.mapRange(interpolatedGridProgress, 0, taskGridHorizontalDiff));
mOrientationState.getOrientationHandler().setSecondary(mMatrix, MATRIX_POST_TRANSLATE,
Utilities.mapRange(interpolatedGridProgress, 0, taskGridVerticalDiff));
// Apply TaskView matrix: translate, scroll
mMatrix.postTranslate(mTaskRect.left, mTaskRect.top);
mOrientationState.getOrientationHandler().set(mMatrix, MATRIX_POST_TRANSLATE,

View File

@@ -264,6 +264,7 @@ public abstract class RecentsView<T extends StatefulActivity> extends PagedView
protected final TransformParams mLiveTileParams = new TransformParams();
protected final TaskViewSimulator mLiveTileTaskViewSimulator;
protected final Rect mLastComputedTaskSize = new Rect();
protected final Rect mLastComputedGridSize = new Rect();
// How much a task that is directly offscreen will be pushed out due to RecentsView scale/pivot.
protected Float mLastComputedTaskPushOutDistance = null;
protected boolean mEnableDrawingLiveTile = false;
@@ -471,7 +472,7 @@ public abstract class RecentsView<T extends StatefulActivity> extends PagedView
setLayoutDirection(mIsRtl ? View.LAYOUT_DIRECTION_RTL : View.LAYOUT_DIRECTION_LTR);
mTaskTopMargin = getResources()
.getDimensionPixelSize(R.dimen.task_thumbnail_top_margin);
mRowSpacing = (int) getResources().getDimension(R.dimen.recents_row_spacing);
mRowSpacing = getResources().getDimensionPixelSize(R.dimen.overview_grid_row_spacing);
mSquaredTouchSlop = squaredTouchSlop(context);
mEmptyIcon = context.getDrawable(R.drawable.ic_empty_recents);
@@ -1012,6 +1013,10 @@ public abstract class RecentsView<T extends StatefulActivity> extends PagedView
setPadding(mTempRect.left - mInsets.left, mTempRect.top - mInsets.top,
dp.widthPx - mInsets.right - mTempRect.right,
dp.heightPx - mInsets.bottom - mTempRect.bottom);
mSizeStrategy.calculateGridSize(mActivity, mActivity.getDeviceProfile(),
mLastComputedGridSize);
// Force TaskView to update size from thumbnail
updateTaskSize();
}
@@ -1521,22 +1526,10 @@ public abstract class RecentsView<T extends StatefulActivity> extends PagedView
}
final int boxLength = Math.max(mTaskWidth, mTaskHeight);
float availableHeight =
mTaskTopMargin + mTaskHeight + mSizeStrategy.getOverviewActionsHeight(mContext);
float availableHeight = mLastComputedGridSize.height();
float rowHeight = (availableHeight - mRowSpacing) / 2;
float gridScale = rowHeight / (boxLength + mTaskTopMargin);
TaskView firstTask = getTaskViewAt(0);
float firstTaskWidthOffset;
if (mIsRtl) {
// Move the first task to the right edge.
firstTaskWidthOffset = mTaskWidth - firstTask.getLayoutParams().width * gridScale;
} else {
// Move the first task to the left edge.
firstTaskWidthOffset = -firstTask.getLayoutParams().width * (1 - gridScale);
}
int topRowWidth = 0;
int bottomRowWidth = 0;
float topAccumulatedTranslationX = 0;
@@ -1546,13 +1539,22 @@ public abstract class RecentsView<T extends StatefulActivity> extends PagedView
for (int i = 0; i < taskCount; i++) {
TaskView taskView = getTaskViewAt(i);
taskView.setGridScale(gridScale);
gridTranslations[i] = 0;
float taskWidthDiff = mTaskWidth - taskView.getLayoutParams().width * gridScale;
float taskWidthOffset = mIsRtl ? taskWidthDiff : -taskWidthDiff;
// Visually we want to move all task by firstTaskWidthOffset, but calculate page scroll
// according to right edge (or left in nonRtl) of TaskView.
gridTranslations[i] = firstTaskWidthOffset - taskWidthOffset;
taskView.setGridOffsetTranslationX(taskWidthOffset);
float scaledWidth = taskView.getLayoutParams().width * gridScale;
float taskGridHorizontalDiff;
if (mIsRtl) {
float taskRight = mLastComputedTaskSize.left + scaledWidth;
taskGridHorizontalDiff = mLastComputedGridSize.right - taskRight;
} else {
float taskLeft = mLastComputedTaskSize.right - scaledWidth;
taskGridHorizontalDiff = mLastComputedGridSize.left - taskLeft;
}
gridTranslations[i] -= taskGridHorizontalDiff;
taskView.setGridOffsetTranslationX(taskGridHorizontalDiff);
float taskGridVerticalDiff = mLastComputedGridSize.top + mTaskTopMargin * gridScale
- mLastComputedTaskSize.top;
// Off-set gap due to task scaling.
float widthDiff = taskView.getLayoutParams().width * (1 - gridScale);
@@ -1567,7 +1569,7 @@ public abstract class RecentsView<T extends StatefulActivity> extends PagedView
topRowWidth += taskView.getLayoutParams().width * gridScale + mPageSpacing;
topSet.add(i);
taskView.setGridTranslationY(0);
taskView.setGridTranslationY(taskGridVerticalDiff);
// Move horizontally into empty space.
float widthOffset = 0;
@@ -1578,15 +1580,14 @@ public abstract class RecentsView<T extends StatefulActivity> extends PagedView
float gridTranslationX = mIsRtl ? widthOffset : -widthOffset;
gridTranslations[i] += gridTranslationX;
topAccumulatedTranslationX += gridTranslationX + gridScaleTranslationX;
bottomAccumulatedTranslationX += gridScaleTranslationX;
topAccumulatedTranslationX += gridTranslationX;
} else {
gridTranslations[i] += bottomAccumulatedTranslationX;
bottomRowWidth += taskView.getLayoutParams().width * gridScale + mPageSpacing;
// Move into bottom row.
float heightOffset = (boxLength + mTaskTopMargin) * gridScale + mRowSpacing;
taskView.setGridTranslationY(heightOffset);
taskView.setGridTranslationY(heightOffset + taskGridVerticalDiff);
// Move horizontally into empty space.
float widthOffset = 0;
@@ -1597,9 +1598,10 @@ public abstract class RecentsView<T extends StatefulActivity> extends PagedView
float gridTranslationX = mIsRtl ? widthOffset : -widthOffset;
gridTranslations[i] += gridTranslationX;
topAccumulatedTranslationX += gridScaleTranslationX;
bottomAccumulatedTranslationX += gridTranslationX + gridScaleTranslationX;
bottomAccumulatedTranslationX += gridTranslationX;
}
topAccumulatedTranslationX += gridScaleTranslationX;
bottomAccumulatedTranslationX += gridScaleTranslationX;
}
// Use the accumulated translation of the longer row.
@@ -1632,8 +1634,9 @@ public abstract class RecentsView<T extends StatefulActivity> extends PagedView
mIsRtl ? -shortTotalCompensation : shortTotalCompensation;
}
float clearAllTotalTranslationX = firstTaskWidthOffset + clearAllAccumulatedTranslation
+ clearAllShorterRowCompensation + clearAllShortTotalCompensation;
float clearAllTotalTranslationX =
clearAllAccumulatedTranslation + clearAllShorterRowCompensation
+ clearAllShortTotalCompensation;
// We need to maintain first task's grid translation at 0, now shift translation of all
// the TaskViews to achieve that.