From 21970ccd290c6d95ba87c8b7c213adc4fdde6ffc Mon Sep 17 00:00:00 2001 From: Tony Wickham Date: Wed, 15 Sep 2021 15:44:05 -0700 Subject: [PATCH] Remove nonOverlappingTaskarInsets - Override our insets in LauncherRootView to explicitly only care about nav bar size, ignoring any insets due to taskbar. - Previously we used nonOverlappingTaskbarInsets to belatedly subtract from measurements in e.g. DeviceProfile, but now we can revert most of those calculations since we effectively subtract taskbar insets at the root. Test: visual in different orientations and navigation modes, and testPressHomeOnAllAppsContextMenu to ensure REQUEST_WINDOW_INSETS still works for automated tests Fixes: 200607741 Change-Id: I8de5a268c686a1354b4beaa30e101bab6bed5af9 --- src/com/android/launcher3/DeviceProfile.java | 27 +++++-------------- .../android/launcher3/LauncherRootView.java | 19 +++---------- src/com/android/launcher3/Workspace.java | 2 -- .../WorkspacePageIndicator.java | 4 +-- .../launcher3/states/SpringLoadedState.java | 3 +-- .../testing/TestInformationHandler.java | 4 +-- 6 files changed, 13 insertions(+), 46 deletions(-) diff --git a/src/com/android/launcher3/DeviceProfile.java b/src/com/android/launcher3/DeviceProfile.java index 3121bfc9ee..ce8cf3c218 100644 --- a/src/com/android/launcher3/DeviceProfile.java +++ b/src/com/android/launcher3/DeviceProfile.java @@ -33,7 +33,6 @@ import android.graphics.Point; import android.graphics.PointF; import android.graphics.Rect; import android.util.DisplayMetrics; -import android.util.Pair; import android.view.Surface; import com.android.launcher3.CellLayout.ContainerType; @@ -215,8 +214,6 @@ public class DeviceProfile { // Whether Taskbar will inset the bottom of apps by taskbarSize. public boolean isTaskbarPresentInApps; public int taskbarSize; - // How much of the bottom inset is due to Taskbar rather than other system elements. - public int nonOverlappingTaskbarInset; // DragController public int flingToDeleteThresholdVelocity; @@ -239,7 +236,7 @@ public class DeviceProfile { widthPx = windowBounds.bounds.width(); heightPx = windowBounds.bounds.height(); availableWidthPx = windowBounds.availableSize.x; - int nonFinalAvailableHeightPx = windowBounds.availableSize.y; + availableHeightPx = windowBounds.availableSize.y; mInfo = info; // If the device's pixel density was scaled (usually via settings for A11y), use the @@ -266,15 +263,8 @@ public class DeviceProfile { isTaskbarPresent = isTablet && ApiWrapper.TASKBAR_DRAWN_IN_PROCESS && FeatureFlags.ENABLE_TASKBAR.get(); if (isTaskbarPresent) { - // Taskbar will be added later, but provides bottom insets that we should subtract - // from availableHeightPx. taskbarSize = res.getDimensionPixelSize(R.dimen.taskbar_size); - nonOverlappingTaskbarInset = taskbarSize - windowBounds.insets.bottom; - if (nonOverlappingTaskbarInset > 0) { - nonFinalAvailableHeightPx -= nonOverlappingTaskbarInset; - } } - availableHeightPx = nonFinalAvailableHeightPx; edgeMarginPx = res.getDimensionPixelSize(R.dimen.dynamic_grid_edge_margin); @@ -842,7 +832,7 @@ public class DeviceProfile { padding.right = hotseatBarSizePx; } } else { - int hotseatTop = isTaskbarPresent ? taskbarSize : hotseatBarSizePx; + int hotseatTop = hotseatBarSizePx; int paddingBottom = hotseatTop + workspacePageIndicatorHeight + workspaceBottomPadding - mWorkspacePageIndicatorOverlapWorkspace; if (isTablet) { @@ -853,8 +843,7 @@ public class DeviceProfile { ((inv.numColumns - 1) * cellWidthPx))); availablePaddingX = (int) Math.min(availablePaddingX, widthPx * MAX_HORIZONTAL_PADDING_PERCENT); - int hotseatVerticalPadding = isTaskbarPresent ? 0 - : hotseatBarTopPaddingPx + hotseatBarBottomPaddingPx; + int hotseatVerticalPadding = hotseatBarTopPaddingPx + hotseatBarBottomPaddingPx; int availablePaddingY = Math.max(0, heightPx - edgeMarginPx - paddingBottom - (2 * inv.numRows * cellHeightPx) - hotseatVerticalPadding); padding.set(availablePaddingX / 2, edgeMarginPx + availablePaddingY / 2, @@ -886,9 +875,9 @@ public class DeviceProfile { mInsets.right + hotseatBarSidePaddingStartPx, mInsets.bottom); } } else if (isTaskbarPresent) { - int hotseatHeight = workspacePadding.bottom + taskbarSize; + int hotseatHeight = workspacePadding.bottom; int taskbarOffset = getTaskbarOffsetY(); - int hotseatTopDiff = hotseatHeight - taskbarSize - taskbarOffset; + int hotseatTopDiff = hotseatHeight - taskbarOffset; int endOffset = ApiWrapper.getHotseatEndOffset(context); int requiredWidth = iconSizePx * numShownHotseatIcons; @@ -938,7 +927,8 @@ public class DeviceProfile { : hotseatBarSizePx - hotseatCellHeightPx - hotseatQsbHeight; if (isScalableGrid && qsbBottomMarginPx > mInsets.bottom) { - return Math.min(qsbBottomMarginPx, freeSpace); + // Note that taskbarSize = 0 unless isTaskbarPresent. + return Math.min(qsbBottomMarginPx + taskbarSize, freeSpace); } else { return (int) (freeSpace * QSB_CENTER_FACTOR) + (isTaskbarPresent ? taskbarSize : mInsets.bottom); @@ -1116,10 +1106,7 @@ public class DeviceProfile { writer.println(prefix + "\tisTaskbarPresent:" + isTaskbarPresent); writer.println(prefix + "\tisTaskbarPresentInApps:" + isTaskbarPresentInApps); - writer.println(prefix + pxToDpStr("taskbarSize", taskbarSize)); - writer.println(prefix + pxToDpStr("nonOverlappingTaskbarInset", - nonOverlappingTaskbarInset)); writer.println(prefix + pxToDpStr("workspacePadding.left", workspacePadding.left)); writer.println(prefix + pxToDpStr("workspacePadding.top", workspacePadding.top)); diff --git a/src/com/android/launcher3/LauncherRootView.java b/src/com/android/launcher3/LauncherRootView.java index 28afc5768b..7de2ee4eed 100644 --- a/src/com/android/launcher3/LauncherRootView.java +++ b/src/com/android/launcher3/LauncherRootView.java @@ -47,15 +47,8 @@ public class LauncherRootView extends InsettableFrameLayout { } private void handleSystemWindowInsets(Rect insets) { - DeviceProfile dp = mActivity.getDeviceProfile(); - - // Taskbar provides insets, but we don't want that for most Launcher elements so remove it. - mTempRect.set(insets); - insets = mTempRect; - insets.bottom = Math.max(0, insets.bottom - dp.nonOverlappingTaskbarInset); - // Update device profile before notifying the children. - dp.updateInsets(insets); + mActivity.getDeviceProfile().updateInsets(insets); boolean resetState = !insets.equals(mInsets); setInsets(insets); @@ -86,10 +79,6 @@ public class LauncherRootView extends InsettableFrameLayout { * get its insets, we calculate them ourselves so they are stable regardless of whether taskbar * is currently attached. * - * TODO(b/198798034): Currently we always calculate nav insets as taskbarSize, but then we - * subtract nonOverlappingTaskbarInset in handleSystemWindowInsets(). Instead, we should just - * calculate the normal nav bar height here, and remove nonOverlappingTaskbarInset altogether. - * * @param oldInsets The system-provided insets, which we are modifying. * @return The updated insets. */ @@ -108,10 +97,8 @@ public class LauncherRootView extends InsettableFrameLayout { Insets oldNavInsets = oldInsets.getInsets(WindowInsets.Type.navigationBars()); Rect newNavInsets = new Rect(oldNavInsets.left, oldNavInsets.top, oldNavInsets.right, oldNavInsets.bottom); - if (dp.isTaskbarPresent) { - // TODO (see javadoc): Remove this block and fall into the next one instead. - newNavInsets.bottom = dp.taskbarSize; - } else if (dp.isLandscape) { + + if (dp.isLandscape) { if (dp.isTablet) { newNavInsets.bottom = ResourceUtils.getNavbarSize( "navigation_bar_height_landscape", resources); diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java index bd2a14fd2d..1d62480cd3 100644 --- a/src/com/android/launcher3/Workspace.java +++ b/src/com/android/launcher3/Workspace.java @@ -314,8 +314,6 @@ public class Workspace extends PagedView Rect padding = grid.workspacePadding; setPadding(padding.left, padding.top, padding.right, padding.bottom); mInsets.set(insets); - // Increase our bottom insets so we don't overlap with the taskbar. - mInsets.bottom += grid.nonOverlappingTaskbarInset; if (mWorkspaceFadeInAdjacentScreens) { // In landscape mode the page spacing is set to the default. diff --git a/src/com/android/launcher3/pageindicators/WorkspacePageIndicator.java b/src/com/android/launcher3/pageindicators/WorkspacePageIndicator.java index f73d782685..c685891dac 100644 --- a/src/com/android/launcher3/pageindicators/WorkspacePageIndicator.java +++ b/src/com/android/launcher3/pageindicators/WorkspacePageIndicator.java @@ -268,9 +268,7 @@ public class WorkspacePageIndicator extends View implements Insettable, PageIndi } else { lp.leftMargin = lp.rightMargin = 0; lp.gravity = Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM; - lp.bottomMargin = grid.isTaskbarPresent - ? grid.workspacePadding.bottom + grid.taskbarSize - : grid.hotseatBarSizePx + insets.bottom; + lp.bottomMargin = grid.hotseatBarSizePx + insets.bottom; } setLayoutParams(lp); } diff --git a/src/com/android/launcher3/states/SpringLoadedState.java b/src/com/android/launcher3/states/SpringLoadedState.java index 8db1dbe69d..5fe5450a12 100644 --- a/src/com/android/launcher3/states/SpringLoadedState.java +++ b/src/com/android/launcher3/states/SpringLoadedState.java @@ -59,11 +59,10 @@ public class SpringLoadedState extends LauncherState { float scale = grid.workspaceSpringLoadShrinkFactor; Rect insets = launcher.getDragLayer().getInsets(); - int insetsBottom = grid.isTaskbarPresent ? grid.taskbarSize : insets.bottom; float scaledHeight = scale * ws.getNormalChildHeight(); float shrunkTop = insets.top + grid.dropTargetBarSizePx; - float shrunkBottom = ws.getMeasuredHeight() - insetsBottom + float shrunkBottom = ws.getMeasuredHeight() - insets.bottom - grid.workspacePadding.bottom - grid.workspaceSpringLoadedBottomSpace; float totalShrunkSpace = shrunkBottom - shrunkTop; diff --git a/src/com/android/launcher3/testing/TestInformationHandler.java b/src/com/android/launcher3/testing/TestInformationHandler.java index 86acff718f..5a9c074f96 100644 --- a/src/com/android/launcher3/testing/TestInformationHandler.java +++ b/src/com/android/launcher3/testing/TestInformationHandler.java @@ -116,9 +116,7 @@ public class TestInformationHandler implements ResourceBasedOverride { return getUIProperty(Bundle::putParcelable, activity -> { WindowInsets insets = activity.getWindow() .getDecorView().getRootWindowInsets(); - return Insets.subtract( - insets.getSystemWindowInsets(), - Insets.of(0, 0, 0, mDeviceProfile.nonOverlappingTaskbarInset)); + return insets.getSystemWindowInsets(); }, this::getCurrentActivity); }