From d90faab65576a8ad7eb42767d6205d168694cd2f Mon Sep 17 00:00:00 2001 From: Thales Lima Date: Tue, 21 Sep 2021 17:18:47 +0100 Subject: [PATCH] launcher: create attrs for more horizontal margin options According to new specs, margins are different depending on orientation and fold/unfolded. Also change the name of the variable to horizontalMargin, since it applies the same padding to both sides. Bug: 191879424 Test: manual and checking paddings in HSV Change-Id: I8990c02b928a22b9f3b0cf3cbc3abf08df4daa9d --- res/values/attrs.xml | 8 ++- res/values/dimens.xml | 4 -- src/com/android/launcher3/DeviceProfile.java | 49 +++++++++++++------ .../launcher3/InvariantDeviceProfile.java | 25 ++++++++++ .../secondarydisplay/SecondaryDragLayer.java | 2 +- 5 files changed, 68 insertions(+), 20 deletions(-) diff --git a/res/values/attrs.xml b/res/values/attrs.xml index 9c20e1fc13..8469233890 100644 --- a/res/values/attrs.xml +++ b/res/values/attrs.xml @@ -177,7 +177,7 @@ - + @@ -223,6 +223,12 @@ + + + + + + diff --git a/res/values/dimens.xml b/res/values/dimens.xml index 1cf49fca33..b1294b4c58 100644 --- a/res/values/dimens.xml +++ b/res/values/dimens.xml @@ -29,9 +29,6 @@ 5.5dp 8dp - 36dp - 9dp - 8dp 2dp @@ -41,7 +38,6 @@ 0dp - 22dp 42dp diff --git a/src/com/android/launcher3/DeviceProfile.java b/src/com/android/launcher3/DeviceProfile.java index 192fe303a7..07221fc471 100644 --- a/src/com/android/launcher3/DeviceProfile.java +++ b/src/com/android/launcher3/DeviceProfile.java @@ -97,8 +97,8 @@ public class DeviceProfile { private static final int PORTRAIT_TABLET_LEFT_RIGHT_PADDING_MULTIPLIER = 4; // Workspace - public final int desiredWorkspaceLeftRightOriginalPx; - public int desiredWorkspaceLeftRightMarginPx; + public final int desiredWorkspaceHorizontalMarginOriginalPx; + public int desiredWorkspaceHorizontalMarginPx; public final int cellLayoutBorderSpacingOriginalPx; public int cellLayoutBorderSpacingPx; public final int cellLayoutPaddingLeftRightPx; @@ -270,11 +270,8 @@ public class DeviceProfile { edgeMarginPx = res.getDimensionPixelSize(R.dimen.dynamic_grid_edge_margin); - desiredWorkspaceLeftRightMarginPx = isVerticalBarLayout() ? 0 : isScalableGrid - ? res.getDimensionPixelSize(R.dimen.scalable_grid_left_right_margin) - : res.getDimensionPixelSize(R.dimen.dynamic_grid_left_right_margin); - desiredWorkspaceLeftRightOriginalPx = desiredWorkspaceLeftRightMarginPx; - + desiredWorkspaceHorizontalMarginPx = getHorizontalMarginPx(inv, res); + desiredWorkspaceHorizontalMarginOriginalPx = desiredWorkspaceHorizontalMarginPx; allAppsOpenVerticalTranslate = res.getDimensionPixelSize( R.dimen.all_apps_open_vertical_translate); @@ -446,6 +443,29 @@ public class DeviceProfile { new DotRenderer(allAppsIconSizePx, dotPath, DEFAULT_DOT_SIZE); } + private int getHorizontalMarginPx(InvariantDeviceProfile idp, Resources res) { + if (isVerticalBarLayout()) { + return 0; + } + + int horizontalMarginPx; + + if (isScalableGrid) { + if (isTwoPanels) { + if (isLandscape) { + horizontalMarginPx = pxFromDp(idp.twoPanelLandscapeHorizontalMargin, mMetrics); + } else { + horizontalMarginPx = pxFromDp(idp.twoPanelPortraitHorizontalMargin, mMetrics); + } + } else { + horizontalMarginPx = pxFromDp(idp.horizontalMargin, mMetrics); + } + } else { + horizontalMarginPx = res.getDimensionPixelSize(R.dimen.dynamic_grid_left_right_margin); + } + return horizontalMarginPx; + } + private void updateHotseatIconSize(int hotseatIconSizePx) { // Ensure there is enough space for folder icons, which have a slightly larger radius. hotseatCellHeightPx = (int) Math.ceil(hotseatIconSizePx * ICON_OVERLAP_FACTOR); @@ -554,7 +574,7 @@ public class DeviceProfile { allAppsLeftRightPadding = Math.max(1, (availableWidthPx - usedWidth) / 2); } else { allAppsLeftRightPadding = - desiredWorkspaceLeftRightMarginPx + cellLayoutPaddingLeftRightPx; + desiredWorkspaceHorizontalMarginPx + cellLayoutPaddingLeftRightPx; } } @@ -581,7 +601,7 @@ public class DeviceProfile { int numColumns = isTwoPanels ? inv.numColumns * 2 : inv.numColumns; float usedWidth = (cellWidthPx * numColumns) + (cellLayoutBorderSpacingPx * (numColumns - 1)) - + (desiredWorkspaceLeftRightMarginPx * 2); + + (desiredWorkspaceHorizontalMarginPx * 2); // We do not subtract padding here, as we also scale the workspace padding if needed. scaleX = availableWidthPx / usedWidth; shouldScale = true; @@ -647,7 +667,8 @@ public class DeviceProfile { int cellContentHeight = iconSizePx + iconDrawablePaddingPx + Utilities.calculateTextHeight(iconTextSizePx); cellYPaddingPx = Math.max(0, cellHeightPx - cellContentHeight) / 2; - desiredWorkspaceLeftRightMarginPx = (int) (desiredWorkspaceLeftRightOriginalPx * scale); + desiredWorkspaceHorizontalMarginPx = + (int) (desiredWorkspaceHorizontalMarginOriginalPx * scale); } else { cellWidthPx = iconSizePx + iconDrawablePaddingPx; cellHeightPx = (int) Math.ceil(iconSizePx * ICON_OVERLAP_FACTOR) @@ -851,9 +872,9 @@ public class DeviceProfile { int paddingBottom = hotseatTop + workspacePageIndicatorHeight + workspaceBottomPadding - mWorkspacePageIndicatorOverlapWorkspace; - padding.set(desiredWorkspaceLeftRightMarginPx, + padding.set(desiredWorkspaceHorizontalMarginPx, (isScalableGrid ? workspaceTopPadding : edgeMarginPx), - desiredWorkspaceLeftRightMarginPx, + desiredWorkspaceHorizontalMarginPx, paddingBottom); } } @@ -1081,8 +1102,8 @@ public class DeviceProfile { writer.println(prefix + pxToDpStr("cellLayoutBorderSpacingPx", cellLayoutBorderSpacingPx)); - writer.println(prefix + pxToDpStr("desiredWorkspaceLeftRightMarginPx", - desiredWorkspaceLeftRightMarginPx)); + writer.println(prefix + pxToDpStr("desiredWorkspaceHorizontalMarginPx", + desiredWorkspaceHorizontalMarginPx)); writer.println(prefix + pxToDpStr("allAppsIconSizePx", allAppsIconSizePx)); writer.println(prefix + pxToDpStr("allAppsIconTextSizePx", allAppsIconTextSizePx)); diff --git a/src/com/android/launcher3/InvariantDeviceProfile.java b/src/com/android/launcher3/InvariantDeviceProfile.java index 86310407b1..92cc9e82b1 100644 --- a/src/com/android/launcher3/InvariantDeviceProfile.java +++ b/src/com/android/launcher3/InvariantDeviceProfile.java @@ -118,6 +118,9 @@ public class InvariantDeviceProfile { public float twoPanelLandscapeMinCellHeightDps; public float twoPanelLandscapeMinCellWidthDps; public float borderSpacing; + public float horizontalMargin; + public float twoPanelLandscapeHorizontalMargin; + public float twoPanelPortraitHorizontalMargin; private SparseArray mExtraAttrs; @@ -289,6 +292,10 @@ public class InvariantDeviceProfile { borderSpacing = displayOption.borderSpacing; allAppsCellSpacing = displayOption.allAppsCellSpacing; + horizontalMargin = displayOption.horizontalMargin; + twoPanelLandscapeHorizontalMargin = displayOption.twoPanelLandscapeHorizontalMargin; + twoPanelPortraitHorizontalMargin = displayOption.twoPanelPortraitHorizontalMargin; + numShownHotseatIcons = closestProfile.numHotseatIcons; numDatabaseHotseatIcons = isSplitDisplay ? closestProfile.numDatabaseHotseatIcons : closestProfile.numHotseatIcons; @@ -728,6 +735,10 @@ public class InvariantDeviceProfile { private float allAppsCellSpacing; private float borderSpacing; + private float horizontalMargin; + private float twoPanelLandscapeHorizontalMargin; + private float twoPanelPortraitHorizontalMargin; + private final float[] iconSizes = new float[COUNT_TOTAL]; private final float[] textSizes = new float[COUNT_TOTAL]; @@ -790,6 +801,14 @@ public class InvariantDeviceProfile { a.getFloat(R.styleable.ProfileDisplayOption_twoPanelLandscapeIconTextSize, textSizes[INDEX_LANDSCAPE]); + horizontalMargin = a.getFloat(R.styleable.ProfileDisplayOption_horizontalMargin, 0); + twoPanelLandscapeHorizontalMargin = a.getFloat( + R.styleable.ProfileDisplayOption_twoPanelLandscapeHorizontalMargin, + horizontalMargin); + twoPanelPortraitHorizontalMargin = a.getFloat( + R.styleable.ProfileDisplayOption_twoPanelPortraitHorizontalMargin, + horizontalMargin); + a.recycle(); } @@ -820,6 +839,9 @@ public class InvariantDeviceProfile { twoPanelLandscapeMinCellWidthDps *= w; borderSpacing *= w; allAppsCellSpacing *= w; + horizontalMargin *= w; + twoPanelLandscapeHorizontalMargin *= w; + twoPanelPortraitHorizontalMargin *= w; return this; } @@ -836,6 +858,9 @@ public class InvariantDeviceProfile { twoPanelLandscapeMinCellWidthDps += p.twoPanelLandscapeMinCellWidthDps; borderSpacing += p.borderSpacing; allAppsCellSpacing += p.allAppsCellSpacing; + horizontalMargin += p.horizontalMargin; + twoPanelLandscapeHorizontalMargin += p.twoPanelLandscapeHorizontalMargin; + twoPanelPortraitHorizontalMargin += p.twoPanelPortraitHorizontalMargin; return this; } } diff --git a/src/com/android/launcher3/secondarydisplay/SecondaryDragLayer.java b/src/com/android/launcher3/secondarydisplay/SecondaryDragLayer.java index f78f6dd40c..1820933509 100644 --- a/src/com/android/launcher3/secondarydisplay/SecondaryDragLayer.java +++ b/src/com/android/launcher3/secondarydisplay/SecondaryDragLayer.java @@ -112,7 +112,7 @@ public class SecondaryDragLayer extends BaseDragLayer for (int i = 0; i < count; i++) { final View child = getChildAt(i); if (child == mAppsView) { - int padding = 2 * (grid.desiredWorkspaceLeftRightMarginPx + int padding = 2 * (grid.desiredWorkspaceHorizontalMarginPx + grid.cellLayoutPaddingLeftRightPx); int maxWidth = grid.allAppsCellWidthPx * grid.numShownAllAppsColumns + padding;