From ea5c1d29fec66a11b57be5a2f30d4c0744a4ae3a Mon Sep 17 00:00:00 2001 From: Pat Manning Date: Thu, 14 Apr 2022 10:58:16 +0100 Subject: [PATCH] Prevent edit state workspace scale from hiding next pages. Fix: 228969651 Test: manual Change-Id: I0cceb3bfab19e0721b21fb8c55fe1218b1f25af8 --- src/com/android/launcher3/DeviceProfile.java | 7 +++++++ .../android/launcher3/states/SpringLoadedState.java | 10 +++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/com/android/launcher3/DeviceProfile.java b/src/com/android/launcher3/DeviceProfile.java index 72d0f59fd9..e55daac547 100644 --- a/src/com/android/launcher3/DeviceProfile.java +++ b/src/com/android/launcher3/DeviceProfile.java @@ -928,6 +928,13 @@ public class DeviceProfile { return workspaceSpringLoadShrunkBottom; } + /** + * Gets the minimum visible amount of the next workspace page when in the spring-loaded state. + */ + public float getWorkspaceSpringLoadedMinimumNextPageVisible() { + return getCellSize().x / 2f; + } + public int getWorkspaceWidth() { return getWorkspaceWidth(getTotalWorkspacePadding()); } diff --git a/src/com/android/launcher3/states/SpringLoadedState.java b/src/com/android/launcher3/states/SpringLoadedState.java index 9be3cc5539..13e2b34367 100644 --- a/src/com/android/launcher3/states/SpringLoadedState.java +++ b/src/com/android/launcher3/states/SpringLoadedState.java @@ -53,7 +53,15 @@ public class SpringLoadedState extends LauncherState { float shrunkTop = grid.getWorkspaceSpringLoadShrunkTop(); float shrunkBottom = grid.getWorkspaceSpringLoadShrunkBottom(); - float scale = (shrunkBottom - shrunkTop) / ws.getNormalChildHeight(); + 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 myCenter = ws.getTop() + halfHeight;