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
diff --git a/res/values/attrs.xml b/res/values/attrs.xml
index 9c20e1f..8469233 100644
--- a/res/values/attrs.xml
+++ b/res/values/attrs.xml
@@ -177,7 +177,7 @@
<attr name="minWidthDps" format="float" />
<attr name="minHeightDps" format="float" />
- <!-- These min cell values are only used if GridDisplayOption#isScalable is true-->
+ <!-- These min cell values are only used if GridDisplayOption#isScalable is true -->
<attr name="minCellHeightDps" format="float" />
<attr name="minCellWidthDps" format="float" />
<!-- twoPanelPortraitMinCellWidthDps defaults to minCellHeightDps, if not specified -->
@@ -223,6 +223,12 @@
<!-- allAppsIconTextSize defaults to iconTextSize, if not specified -->
<attr name="allAppsIconTextSize" format="float" />
+ <!-- Margin on left and right of the workspace when GridDisplayOption#isScalable is true -->
+ <attr name="horizontalMargin" format="float"/>
+ <!-- twoPanelLandscapeHorizontalMargin defaults to horizontalMargin if not specified -->
+ <attr name="twoPanelLandscapeHorizontalMargin" format="float"/>
+ <!-- twoPanelPortraitHorizontalMargin defaults to horizontalMargin if not specified -->
+ <attr name="twoPanelPortraitHorizontalMargin" format="float"/>
</declare-styleable>
<declare-styleable name="CellLayout">
diff --git a/res/values/dimens.xml b/res/values/dimens.xml
index 1cf49fc..b1294b4 100644
--- a/res/values/dimens.xml
+++ b/res/values/dimens.xml
@@ -29,9 +29,6 @@
<dimen name="dynamic_grid_cell_layout_padding">5.5dp</dimen>
<dimen name="dynamic_grid_cell_padding_x">8dp</dimen>
- <dimen name="two_panels_home_side_padding_landscape">36dp</dimen>
- <dimen name="two_panels_home_side_padding_portrait">9dp</dimen>
-
<!-- Hotseat -->
<dimen name="dynamic_grid_hotseat_top_padding">8dp</dimen>
<dimen name="dynamic_grid_hotseat_bottom_padding">2dp</dimen>
@@ -41,7 +38,6 @@
<dimen name="dynamic_grid_hotseat_side_padding">0dp</dimen>
<!-- Scalable Grid -->
- <dimen name="scalable_grid_left_right_margin">22dp</dimen>
<dimen name="scalable_grid_qsb_bottom_margin">42dp</dimen>
<!-- Workspace page indicator -->
diff --git a/src/com/android/launcher3/DeviceProfile.java b/src/com/android/launcher3/DeviceProfile.java
index 192fe30..07221fc 100644
--- a/src/com/android/launcher3/DeviceProfile.java
+++ b/src/com/android/launcher3/DeviceProfile.java
@@ -97,8 +97,8 @@
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 @@
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 @@
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 @@
allAppsLeftRightPadding = Math.max(1, (availableWidthPx - usedWidth) / 2);
} else {
allAppsLeftRightPadding =
- desiredWorkspaceLeftRightMarginPx + cellLayoutPaddingLeftRightPx;
+ desiredWorkspaceHorizontalMarginPx + cellLayoutPaddingLeftRightPx;
}
}
@@ -581,7 +601,7 @@
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 @@
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 @@
int paddingBottom = hotseatTop + workspacePageIndicatorHeight
+ workspaceBottomPadding - mWorkspacePageIndicatorOverlapWorkspace;
- padding.set(desiredWorkspaceLeftRightMarginPx,
+ padding.set(desiredWorkspaceHorizontalMarginPx,
(isScalableGrid ? workspaceTopPadding : edgeMarginPx),
- desiredWorkspaceLeftRightMarginPx,
+ desiredWorkspaceHorizontalMarginPx,
paddingBottom);
}
}
@@ -1081,8 +1102,8 @@
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 8631040..92cc9e8 100644
--- a/src/com/android/launcher3/InvariantDeviceProfile.java
+++ b/src/com/android/launcher3/InvariantDeviceProfile.java
@@ -118,6 +118,9 @@
public float twoPanelLandscapeMinCellHeightDps;
public float twoPanelLandscapeMinCellWidthDps;
public float borderSpacing;
+ public float horizontalMargin;
+ public float twoPanelLandscapeHorizontalMargin;
+ public float twoPanelPortraitHorizontalMargin;
private SparseArray<TypedValue> mExtraAttrs;
@@ -289,6 +292,10 @@
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 @@
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 @@
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 @@
twoPanelLandscapeMinCellWidthDps *= w;
borderSpacing *= w;
allAppsCellSpacing *= w;
+ horizontalMargin *= w;
+ twoPanelLandscapeHorizontalMargin *= w;
+ twoPanelPortraitHorizontalMargin *= w;
return this;
}
@@ -836,6 +858,9 @@
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 f78f6dd..1820933 100644
--- a/src/com/android/launcher3/secondarydisplay/SecondaryDragLayer.java
+++ b/src/com/android/launcher3/secondarydisplay/SecondaryDragLayer.java
@@ -112,7 +112,7 @@
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;