Merge "Move spring loaded scale calculation to DeviceProfile." into tm-dev am: 84bff57d8d

Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Launcher3/+/17909525

Change-Id: Ib0ac0582eed1ea17a6ec9452bdafebc9d4219667
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
TreeHugger Robot
2022-04-27 16:42:03 +00:00
committed by Automerger Merge Worker
3 changed files with 33 additions and 21 deletions
+30 -7
View File
@@ -654,7 +654,7 @@ public class DeviceProfile {
Point workspacePadding = getTotalWorkspacePadding(); Point workspacePadding = getTotalWorkspacePadding();
// Check to see if the icons fit within the available height. // Check to see if the icons fit within the available height.
float usedHeight = getCellLayoutHeight(); float usedHeight = getCellLayoutHeightSpecification();
final int maxHeight = getWorkspaceHeight(workspacePadding); final int maxHeight = getWorkspaceHeight(workspacePadding);
float extraHeight = Math.max(0, maxHeight - usedHeight); float extraHeight = Math.max(0, maxHeight - usedHeight);
float scaleY = maxHeight / usedHeight; float scaleY = maxHeight / usedHeight;
@@ -665,7 +665,8 @@ public class DeviceProfile {
// We scale to fit the cellWidth and cellHeight in the available space. // We scale to fit the cellWidth and cellHeight in the available space.
// The benefit of scalable grids is that we can get consistent aspect ratios between // The benefit of scalable grids is that we can get consistent aspect ratios between
// devices. // devices.
float usedWidth = getCellLayoutWidth() + (desiredWorkspaceHorizontalMarginPx * 2); float usedWidth =
getCellLayoutWidthSpecification() + (desiredWorkspaceHorizontalMarginPx * 2);
// We do not subtract padding here, as we also scale the workspace padding if needed. // We do not subtract padding here, as we also scale the workspace padding if needed.
scaleX = availableWidthPx / usedWidth; scaleX = availableWidthPx / usedWidth;
shouldScale = true; shouldScale = true;
@@ -674,19 +675,19 @@ public class DeviceProfile {
if (shouldScale) { if (shouldScale) {
float scale = Math.min(scaleX, scaleY); float scale = Math.min(scaleX, scaleY);
updateIconSize(scale, res); updateIconSize(scale, res);
extraHeight = Math.max(0, maxHeight - getCellLayoutHeight()); extraHeight = Math.max(0, maxHeight - getCellLayoutHeightSpecification());
} }
updateAvailableFolderCellDimensions(res); updateAvailableFolderCellDimensions(res);
return Math.round(extraHeight); return Math.round(extraHeight);
} }
private int getCellLayoutHeight() { private int getCellLayoutHeightSpecification() {
return (cellHeightPx * inv.numRows) + (cellLayoutBorderSpacePx.y * (inv.numRows - 1)) return (cellHeightPx * inv.numRows) + (cellLayoutBorderSpacePx.y * (inv.numRows - 1))
+ cellLayoutPaddingPx.top + cellLayoutPaddingPx.bottom; + cellLayoutPaddingPx.top + cellLayoutPaddingPx.bottom;
} }
private int getCellLayoutWidth() { private int getCellLayoutWidthSpecification() {
int numColumns = isTwoPanels ? inv.numColumns * 2 : inv.numColumns; int numColumns = isTwoPanels ? inv.numColumns * 2 : inv.numColumns;
return (cellWidthPx * numColumns) + (cellLayoutBorderSpacePx.x * (numColumns - 1)) return (cellWidthPx * numColumns) + (cellLayoutBorderSpacePx.x * (numColumns - 1))
+ cellLayoutPaddingPx.left + cellLayoutPaddingPx.right; + cellLayoutPaddingPx.left + cellLayoutPaddingPx.right;
@@ -916,7 +917,7 @@ public class DeviceProfile {
/** /**
* Gets the scaled bottom of the workspace in px for the spring-loaded edit state. * Gets the scaled bottom of the workspace in px for the spring-loaded edit state.
*/ */
public float getWorkspaceSpringLoadShrunkBottom() { private float getWorkspaceSpringLoadShrunkBottom() {
int topOfHotseat = hotseatBarSizePx + springLoadedHotseatBarTopMarginPx; int topOfHotseat = hotseatBarSizePx + springLoadedHotseatBarTopMarginPx;
workspaceSpringLoadShrunkBottom = workspaceSpringLoadShrunkBottom =
heightPx - (isVerticalBarLayout() ? getVerticalHotseatLastItemBottomOffset() heightPx - (isVerticalBarLayout() ? getVerticalHotseatLastItemBottomOffset()
@@ -927,10 +928,30 @@ public class DeviceProfile {
/** /**
* Gets the minimum visible amount of the next workspace page when in the spring-loaded state. * Gets the minimum visible amount of the next workspace page when in the spring-loaded state.
*/ */
public float getWorkspaceSpringLoadedMinimumNextPageVisible() { private float getWorkspaceSpringLoadedMinimumNextPageVisible() {
return getCellSize().x / 2f; return getCellSize().x / 2f;
} }
/**
* Gets the scale of the workspace for the spring-loaded edit state.
*/
public float getWorkspaceSpringLoadScale() {
float cellLayoutHeight = availableHeightPx - workspacePadding.top - workspacePadding.bottom;
float scale = (getWorkspaceSpringLoadShrunkBottom() - getWorkspaceSpringLoadShrunkTop())
/ cellLayoutHeight;
scale = Math.min(scale, 1f);
// Reduce scale if next pages would not be visible after scaling the workspace
int workspaceWidth = getWorkspaceWidth();
float scaledWorkspaceWidth = workspaceWidth * scale;
float maxAvailableWidth =
workspaceWidth - (2 * getWorkspaceSpringLoadedMinimumNextPageVisible());
if (scaledWorkspaceWidth > maxAvailableWidth) {
scale *= maxAvailableWidth / scaledWorkspaceWidth;
}
return scale;
}
public int getWorkspaceWidth() { public int getWorkspaceWidth() {
return getWorkspaceWidth(getTotalWorkspacePadding()); return getWorkspaceWidth(getTotalWorkspacePadding());
} }
@@ -1356,6 +1377,8 @@ public class DeviceProfile {
prefix + pxToDpStr("workspaceSpringLoadShrunkTop", workspaceSpringLoadShrunkTop)); prefix + pxToDpStr("workspaceSpringLoadShrunkTop", workspaceSpringLoadShrunkTop));
writer.println(prefix + pxToDpStr("workspaceSpringLoadShrunkBottom", writer.println(prefix + pxToDpStr("workspaceSpringLoadShrunkBottom",
workspaceSpringLoadShrunkBottom)); workspaceSpringLoadShrunkBottom));
writer.println(
prefix + pxToDpStr("getWorkspaceSpringLoadScale()", getWorkspaceSpringLoadScale()));
} }
private static Context getContext(Context c, Info info, int orientation, WindowBounds bounds) { private static Context getContext(Context c, Info info, int orientation, WindowBounds bounds) {
+2 -4
View File
@@ -237,10 +237,8 @@ public class DropTargetBar extends FrameLayout
rightButton.getMeasuredHeight()); rightButton.getMeasuredHeight());
} else if (dp.isPhone) { } else if (dp.isPhone) {
// Buttons aligned to outer edges of scaled workspace. // Buttons aligned to outer edges of scaled workspace.
float shrunkTop = dp.getWorkspaceSpringLoadShrunkTop(); float scale = dp.getWorkspaceSpringLoadScale();
float shrunkBottom = dp.getWorkspaceSpringLoadShrunkBottom();
float scale =
(shrunkBottom - shrunkTop) / launcher.getWorkspace().getNormalChildHeight();
int workspaceWidth = (int) (launcher.getWorkspace().getNormalChildWidth() * scale); int workspaceWidth = (int) (launcher.getWorkspace().getNormalChildWidth() * scale);
int start = barCenter - (workspaceWidth / 2); int start = barCenter - (workspaceWidth / 2);
int end = barCenter + (workspaceWidth / 2); int end = barCenter + (workspaceWidth / 2);
@@ -52,16 +52,7 @@ public class SpringLoadedState extends LauncherState {
} }
float shrunkTop = grid.getWorkspaceSpringLoadShrunkTop(); float shrunkTop = grid.getWorkspaceSpringLoadShrunkTop();
float shrunkBottom = grid.getWorkspaceSpringLoadShrunkBottom(); float scale = grid.getWorkspaceSpringLoadScale();
float scale = Math.min((shrunkBottom - shrunkTop) / ws.getNormalChildHeight(), 1f);
// Reduce scale if next pages would not be visible after scaling the workspace
float scaledWorkspaceWidth = ws.getWidth() * scale;
float maxAvailableWidth =
ws.getWidth() - (2 * grid.getWorkspaceSpringLoadedMinimumNextPageVisible());
if (scaledWorkspaceWidth > maxAvailableWidth) {
scale *= maxAvailableWidth / scaledWorkspaceWidth;
}
float halfHeight = ws.getHeight() / 2; float halfHeight = ws.getHeight() / 2;
float myCenter = ws.getTop() + halfHeight; float myCenter = ws.getTop() + halfHeight;