launcher: create more space options

The grid doesn't have a constant space between cells anymore, so we need
new attributes for the different spaces in different situations.

Bug: 191879424
Test: checking cell size and extra space in dumpsys
Change-Id: I4b6aae5b3fea281490c00cd13d0cd3a25372f21b
This commit is contained in:
Thales Lima 2021-09-30 11:29:06 +01:00
parent bfb6996484
commit 78d00adcbe
14 changed files with 246 additions and 125 deletions

View File

@ -191,7 +191,32 @@
if not specified -->
<attr name="twoPanelLandscapeMinCellWidthDps" format="float" />
<attr name="borderSpacingDps" format="float" />
<!-- These border spaces are only used if GridDisplayOption#isScalable is true -->
<!-- space to be used horizontally and vertically -->
<attr name="borderSpaceDps" format="float" />
<!-- space to the right of the cell, defaults to borderSpaceDps if not specified -->
<attr name="borderSpaceHorizontalDps" format="float" />
<!-- space below the cell, defaults to borderSpaceDps if not specified -->
<attr name="borderSpaceVerticalDps" format="float" />
<!-- space to be used horizontally and vertically in two panels,
defaults to borderSpaceDps if not specified -->
<attr name="twoPanelPortraitBorderSpaceDps" format="float" />
<!-- space to the right of the cell in two panels, defaults to
twoPanelPortraitBorderSpaceDps if not specified -->
<attr name="twoPanelPortraitBorderSpaceHorizontalDps" format="float" />
<!-- space below the cell in two panels, defaults to twoPanelPortraitBorderSpaceDps
if not specified -->
<attr name="twoPanelPortraitBorderSpaceVerticalDps" format="float" />
<!-- space to be used horizontally and vertically in two panels,
defaults to borderSpaceDps if not specified -->
<attr name="twoPanelLandscapeBorderSpaceDps" format="float" />
<!-- space to the right of the cell in two panels, defaults to
twoPanelLandscapeBorderSpaceDps if not specified -->
<attr name="twoPanelLandscapeBorderSpaceHorizontalDps" format="float" />
<!-- space below the cell in two panels, defaults to twoPanelLandscapeBorderSpaceDps
if not specified -->
<attr name="twoPanelLandscapeBorderSpaceVerticalDps" format="float" />
<attr name="allAppsCellSpacingDps" format="float" />

View File

@ -422,8 +422,8 @@ public class AppWidgetResizeFrame extends AbstractFloatingView implements View.O
*/
private void resizeWidgetIfNeeded(boolean onDismiss) {
DeviceProfile dp = mLauncher.getDeviceProfile();
float xThreshold = mCellLayout.getCellWidth() + dp.cellLayoutBorderSpacingPx;
float yThreshold = mCellLayout.getCellHeight() + dp.cellLayoutBorderSpacingPx;
float xThreshold = mCellLayout.getCellWidth() + dp.cellLayoutBorderSpacePx.x;
float yThreshold = mCellLayout.getCellHeight() + dp.cellLayoutBorderSpacePx.y;
int hSpanInc = getSpanIncrement((mDeltaX + mDeltaXAddOn) / xThreshold - mRunningHInc);
int vSpanInc = getSpanIncrement((mDeltaY + mDeltaYAddOn) / yThreshold - mRunningVInc);
@ -508,8 +508,8 @@ public class AppWidgetResizeFrame extends AbstractFloatingView implements View.O
private void onTouchUp() {
DeviceProfile dp = mLauncher.getDeviceProfile();
int xThreshold = mCellLayout.getCellWidth() + dp.cellLayoutBorderSpacingPx;
int yThreshold = mCellLayout.getCellHeight() + dp.cellLayoutBorderSpacingPx;
int xThreshold = mCellLayout.getCellWidth() + dp.cellLayoutBorderSpacePx.x;
int yThreshold = mCellLayout.getCellHeight() + dp.cellLayoutBorderSpacePx.y;
mDeltaXAddOn = mRunningHInc * xThreshold;
mDeltaYAddOn = mRunningVInc * yThreshold;

View File

@ -91,7 +91,7 @@ public class CellLayout extends ViewGroup {
private int mFixedCellWidth;
private int mFixedCellHeight;
@ViewDebug.ExportedProperty(category = "launcher")
private final int mBorderSpacing;
private final Point mBorderSpace;
@ViewDebug.ExportedProperty(category = "launcher")
private int mCountX;
@ -236,9 +236,9 @@ public class CellLayout extends ViewGroup {
mActivity = ActivityContext.lookupContext(context);
DeviceProfile deviceProfile = mActivity.getDeviceProfile();
mBorderSpacing = mContainerType == FOLDER
? deviceProfile.folderCellLayoutBorderSpacingPx
: deviceProfile.cellLayoutBorderSpacingPx;
mBorderSpace = mContainerType == FOLDER
? new Point(deviceProfile.folderCellLayoutBorderSpacePx)
: new Point(deviceProfile.cellLayoutBorderSpacePx);
mCellWidth = mCellHeight = -1;
mFixedCellWidth = mFixedCellHeight = -1;
@ -308,7 +308,7 @@ public class CellLayout extends ViewGroup {
mShortcutsAndWidgets = new ShortcutAndWidgetContainer(context, mContainerType);
mShortcutsAndWidgets.setCellDimensions(mCellWidth, mCellHeight, mCountX, mCountY,
mBorderSpacing);
mBorderSpace);
addView(mShortcutsAndWidgets);
}
@ -368,7 +368,7 @@ public class CellLayout extends ViewGroup {
mFixedCellWidth = mCellWidth = width;
mFixedCellHeight = mCellHeight = height;
mShortcutsAndWidgets.setCellDimensions(mCellWidth, mCellHeight, mCountX, mCountY,
mBorderSpacing);
mBorderSpace);
}
public void setGridSize(int x, int y) {
@ -378,7 +378,7 @@ public class CellLayout extends ViewGroup {
mTmpOccupied = new GridOccupancy(mCountX, mCountY);
mTempRectStack.clear();
mShortcutsAndWidgets.setCellDimensions(mCellWidth, mCellHeight, mCountX, mCountY,
mBorderSpacing);
mBorderSpace);
requestLayout();
}
@ -541,9 +541,9 @@ public class CellLayout extends ViewGroup {
if (mVisualizeCells) {
for (int i = 0; i < mCountX; i++) {
for (int j = 0; j < mCountY; j++) {
int transX = i * mCellWidth + (i * mBorderSpacing) + getPaddingLeft()
int transX = i * mCellWidth + (i * mBorderSpace.x) + getPaddingLeft()
+ paddingX;
int transY = j * mCellHeight + (j * mBorderSpacing) + getPaddingTop()
int transY = j * mCellHeight + (j * mBorderSpace.y) + getPaddingTop()
+ paddingY;
mVisualizeGridRect.offsetTo(transX, transY);
@ -567,12 +567,12 @@ public class CellLayout extends ViewGroup {
// TODO b/194414754 clean this up, reconcile with cellToRect
mVisualizeGridRect.set(paddingX, paddingY,
mCellWidth * spanX + mBorderSpacing * (spanX - 1) - paddingX,
mCellHeight * spanY + mBorderSpacing * (spanY - 1) - paddingY);
mCellWidth * spanX + mBorderSpace.x * (spanX - 1) - paddingX,
mCellHeight * spanY + mBorderSpace.y * (spanY - 1) - paddingY);
int transX = x * mCellWidth + (x * mBorderSpacing)
int transX = x * mCellWidth + (x * mBorderSpace.x)
+ getPaddingLeft() + paddingX;
int transY = y * mCellHeight + (y * mBorderSpacing)
int transY = y * mCellHeight + (y * mBorderSpace.y)
+ getPaddingTop() + paddingY;
mVisualizeGridRect.offsetTo(transX, transY);
@ -858,15 +858,15 @@ public class CellLayout extends ViewGroup {
int childHeightSize = heightSize - (getPaddingTop() + getPaddingBottom());
if (mFixedCellWidth < 0 || mFixedCellHeight < 0) {
int cw = DeviceProfile.calculateCellWidth(childWidthSize, mBorderSpacing,
int cw = DeviceProfile.calculateCellWidth(childWidthSize, mBorderSpace.x,
mCountX);
int ch = DeviceProfile.calculateCellHeight(childHeightSize, mBorderSpacing,
int ch = DeviceProfile.calculateCellHeight(childHeightSize, mBorderSpace.y,
mCountY);
if (cw != mCellWidth || ch != mCellHeight) {
mCellWidth = cw;
mCellHeight = ch;
mShortcutsAndWidgets.setCellDimensions(mCellWidth, mCellHeight, mCountX, mCountY,
mBorderSpacing);
mBorderSpace);
}
}
@ -920,7 +920,7 @@ public class CellLayout extends ViewGroup {
*/
public int getUnusedHorizontalSpace() {
return getMeasuredWidth() - getPaddingLeft() - getPaddingRight() - (mCountX * mCellWidth)
- ((mCountX - 1) * mBorderSpacing);
- ((mCountX - 1) * mBorderSpace.x);
}
@Override
@ -2592,11 +2592,11 @@ public class CellLayout extends ViewGroup {
+ (int) Math.ceil(getUnusedHorizontalSpace() / 2f);
final int vStartPadding = getPaddingTop();
int x = hStartPadding + (cellX * mBorderSpacing) + (cellX * cellWidth);
int y = vStartPadding + (cellY * mBorderSpacing) + (cellY * cellHeight);
int x = hStartPadding + (cellX * mBorderSpace.x) + (cellX * cellWidth);
int y = vStartPadding + (cellY * mBorderSpace.y) + (cellY * cellHeight);
int width = cellHSpan * cellWidth + ((cellHSpan - 1) * mBorderSpacing);
int height = cellVSpan * cellHeight + ((cellVSpan - 1) * mBorderSpacing);
int width = cellHSpan * cellWidth + ((cellHSpan - 1) * mBorderSpace.x);
int height = cellVSpan * cellHeight + ((cellVSpan - 1) * mBorderSpace.y);
resultRect.set(x, y, x + width, y + height);
}
@ -2615,12 +2615,12 @@ public class CellLayout extends ViewGroup {
public int getDesiredWidth() {
return getPaddingLeft() + getPaddingRight() + (mCountX * mCellWidth)
+ ((mCountX - 1) * mBorderSpacing);
+ ((mCountX - 1) * mBorderSpace.x);
}
public int getDesiredHeight() {
return getPaddingTop() + getPaddingBottom() + (mCountY * mCellHeight)
+ ((mCountY - 1) * mBorderSpacing);
+ ((mCountY - 1) * mBorderSpace.y);
}
public boolean isOccupied(int x, int y) {
@ -2736,20 +2736,20 @@ public class CellLayout extends ViewGroup {
}
public void setup(int cellWidth, int cellHeight, boolean invertHorizontally, int colCount,
int rowCount, int borderSpacing, @Nullable Rect inset) {
int rowCount, Point borderSpace, @Nullable Rect inset) {
setup(cellWidth, cellHeight, invertHorizontally, colCount, rowCount, 1.0f, 1.0f,
borderSpacing, inset);
borderSpace, inset);
}
/**
* Use this method, as opposed to {@link #setup(int, int, boolean, int, int, int, Rect)},
* Use this method, as opposed to {@link #setup(int, int, boolean, int, int, Point, Rect)},
* if the view needs to be scaled.
*
* ie. In multi-window mode, we setup widgets so that they are measured and laid out
* using their full/invariant device profile sizes.
*/
public void setup(int cellWidth, int cellHeight, boolean invertHorizontally, int colCount,
int rowCount, float cellScaleX, float cellScaleY, int borderSpacing,
int rowCount, float cellScaleX, float cellScaleY, Point borderSpace,
@Nullable Rect inset) {
if (isLockedToGrid) {
final int myCellHSpan = cellHSpan;
@ -2761,16 +2761,16 @@ public class CellLayout extends ViewGroup {
myCellX = colCount - myCellX - cellHSpan;
}
int hBorderSpacing = (myCellHSpan - 1) * borderSpacing;
int vBorderSpacing = (myCellVSpan - 1) * borderSpacing;
int hBorderSpacing = (myCellHSpan - 1) * borderSpace.x;
int vBorderSpacing = (myCellVSpan - 1) * borderSpace.y;
float myCellWidth = ((myCellHSpan * cellWidth) + hBorderSpacing) / cellScaleX;
float myCellHeight = ((myCellVSpan * cellHeight) + vBorderSpacing) / cellScaleY;
width = Math.round(myCellWidth) - leftMargin - rightMargin;
height = Math.round(myCellHeight) - topMargin - bottomMargin;
x = leftMargin + (myCellX * cellWidth) + (myCellX * borderSpacing);
y = topMargin + (myCellY * cellHeight) + (myCellY * borderSpacing);
x = leftMargin + (myCellX * cellWidth) + (myCellX * borderSpace.x);
y = topMargin + (myCellY * cellHeight) + (myCellY * borderSpace.y);
if (inset != null) {
x -= inset.left;

View File

@ -99,8 +99,8 @@ public class DeviceProfile {
// Workspace
public final int desiredWorkspaceHorizontalMarginOriginalPx;
public int desiredWorkspaceHorizontalMarginPx;
public final int cellLayoutBorderSpacingOriginalPx;
public int cellLayoutBorderSpacingPx;
public Point cellLayoutBorderSpaceOriginalPx;
public Point cellLayoutBorderSpacePx;
public final int cellLayoutPaddingLeftRightPx;
public final int cellLayoutBottomPaddingPx;
public final int edgeMarginPx;
@ -137,7 +137,8 @@ public class DeviceProfile {
public int folderIconOffsetYPx;
// Folder content
public int folderCellLayoutBorderSpacingPx;
public Point folderCellLayoutBorderSpacePx;
public int folderCellLayoutBorderSpaceOriginalPx;
public int folderContentPaddingLeftRight;
public int folderContentPaddingTop;
@ -281,10 +282,12 @@ public class DeviceProfile {
res.getDimensionPixelSize(R.dimen.folder_content_padding_left_right);
folderContentPaddingTop = res.getDimensionPixelSize(R.dimen.folder_content_padding_top);
setCellLayoutBorderSpacing(pxFromDp(inv.borderSpacing, mMetrics, 1f));
cellLayoutBorderSpacePx = getCellLayoutBorderSpace(inv);
allAppsCellSpacingPx = pxFromDp(inv.allAppsCellSpacing, mMetrics, 1f);
cellLayoutBorderSpacingOriginalPx = cellLayoutBorderSpacingPx;
folderCellLayoutBorderSpacingPx = cellLayoutBorderSpacingPx;
cellLayoutBorderSpaceOriginalPx = new Point(cellLayoutBorderSpacePx);
folderCellLayoutBorderSpaceOriginalPx = pxFromDp(inv.folderBorderSpace, mMetrics, 1f);
folderCellLayoutBorderSpacePx = new Point(folderCellLayoutBorderSpaceOriginalPx,
folderCellLayoutBorderSpaceOriginalPx);
int cellLayoutPaddingLeftRightMultiplier = !isVerticalBarLayout() && isTablet
? PORTRAIT_TABLET_LEFT_RIGHT_PADDING_MULTIPLIER : 1;
@ -479,8 +482,33 @@ public class DeviceProfile {
}
}
private void setCellLayoutBorderSpacing(int borderSpacing) {
cellLayoutBorderSpacingPx = isScalableGrid ? borderSpacing : 0;
private Point getCellLayoutBorderSpace(InvariantDeviceProfile idp) {
if (!isScalableGrid) {
return new Point(0, 0);
}
int horizontalSpacePx;
int verticalSpacePx;
if (isTwoPanels) {
if (isLandscape) {
horizontalSpacePx = pxFromDp(idp.twoPanelLandscapeBorderSpace.x, mMetrics);
verticalSpacePx = pxFromDp(idp.twoPanelLandscapeBorderSpace.y, mMetrics);
} else {
horizontalSpacePx = pxFromDp(idp.twoPanelPortraitBorderSpace.x, mMetrics);
verticalSpacePx = pxFromDp(idp.twoPanelPortraitBorderSpace.y, mMetrics);
}
} else {
horizontalSpacePx = pxFromDp(idp.borderSpace.x, mMetrics);
verticalSpacePx = pxFromDp(idp.borderSpace.y, mMetrics);
}
return new Point(horizontalSpacePx, verticalSpacePx);
}
private Point getCellLayoutBorderSpaceScaled(InvariantDeviceProfile idp, float scale) {
Point original = getCellLayoutBorderSpace(idp);
return new Point((int) (original.x * scale), (int) (original.y * scale));
}
public Info getDisplayInfo() {
@ -497,10 +525,10 @@ public class DeviceProfile {
// Check all sides to ensure that the widget won't overlap into another cell, or into
// status bar.
return workspaceTopPadding > widgetPadding.top
&& cellLayoutBorderSpacingPx > widgetPadding.left
&& cellLayoutBorderSpacingPx > widgetPadding.top
&& cellLayoutBorderSpacingPx > widgetPadding.right
&& cellLayoutBorderSpacingPx > widgetPadding.bottom;
&& cellLayoutBorderSpacePx.x > widgetPadding.left
&& cellLayoutBorderSpacePx.y > widgetPadding.top
&& cellLayoutBorderSpacePx.x > widgetPadding.right
&& cellLayoutBorderSpacePx.y > widgetPadding.bottom;
}
public Builder toBuilder(Context context) {
@ -600,7 +628,7 @@ public class DeviceProfile {
// devices.
int numColumns = isTwoPanels ? inv.numColumns * 2 : inv.numColumns;
float usedWidth = (cellWidthPx * numColumns)
+ (cellLayoutBorderSpacingPx * (numColumns - 1))
+ (cellLayoutBorderSpacePx.x * (numColumns - 1))
+ (desiredWorkspaceHorizontalMarginPx * 2);
// We do not subtract padding here, as we also scale the workspace padding if needed.
scaleX = availableWidthPx / usedWidth;
@ -618,7 +646,7 @@ public class DeviceProfile {
}
private int getCellLayoutHeight() {
return (cellHeightPx * inv.numRows) + (cellLayoutBorderSpacingPx * (inv.numRows - 1));
return (cellHeightPx * inv.numRows) + (cellLayoutBorderSpacePx.y * (inv.numRows - 1));
}
/**
@ -658,7 +686,7 @@ public class DeviceProfile {
iconTextSizePx = (int) (pxFromSp(invIconTextSizeSp, mMetrics) * iconScale);
iconDrawablePaddingPx = (int) (iconDrawablePaddingOriginalPx * iconScale);
setCellLayoutBorderSpacing((int) (cellLayoutBorderSpacingOriginalPx * scale));
cellLayoutBorderSpacePx = getCellLayoutBorderSpaceScaled(inv, scale);
if (isScalableGrid) {
PointF minCellHeightAndWidth = getMinCellHeightAndWidth();
@ -757,14 +785,14 @@ public class DeviceProfile {
// Check if the icons fit within the available height.
float contentUsedHeight = folderCellHeightPx * inv.numFolderRows
+ ((inv.numFolderRows - 1) * folderCellLayoutBorderSpacingPx);
+ ((inv.numFolderRows - 1) * folderCellLayoutBorderSpacePx.y);
int contentMaxHeight = availableHeightPx - totalWorkspacePadding.y - folderBottomPanelSize
- folderMargin - folderContentPaddingTop;
float scaleY = contentMaxHeight / contentUsedHeight;
// Check if the icons fit within the available width.
float contentUsedWidth = folderCellWidthPx * inv.numFolderColumns
+ ((inv.numFolderColumns - 1) * folderCellLayoutBorderSpacingPx);
+ ((inv.numFolderColumns - 1) * folderCellLayoutBorderSpacePx.x);
int contentMaxWidth = availableWidthPx - totalWorkspacePadding.x - folderMargin
- folderContentPaddingLeftRight * 2;
float scaleX = contentMaxWidth / contentUsedWidth;
@ -790,10 +818,10 @@ public class DeviceProfile {
folderCellWidthPx = (int) Math.max(minWidth, cellWidthPx * scale);
folderCellHeightPx = (int) Math.max(minHeight, cellHeightPx * scale);
int borderSpacing = (int) (cellLayoutBorderSpacingOriginalPx * scale);
folderCellLayoutBorderSpacingPx = borderSpacing;
folderContentPaddingLeftRight = borderSpacing;
folderContentPaddingTop = borderSpacing;
int scaledSpace = (int) (folderCellLayoutBorderSpaceOriginalPx * scale);
folderCellLayoutBorderSpacePx = new Point(scaledSpace, scaledSpace);
folderContentPaddingLeftRight = scaledSpace;
folderContentPaddingTop = scaledSpace;
} else {
int cellPaddingX = (int) (res.getDimensionPixelSize(R.dimen.folder_cell_x_padding)
* scale);
@ -838,9 +866,9 @@ public class DeviceProfile {
int cellLayoutTotalPadding =
isTwoPanels ? 4 * cellLayoutPaddingLeftRightPx : 2 * cellLayoutPaddingLeftRightPx;
int screenWidthPx = availableWidthPx - padding.x - cellLayoutTotalPadding;
result.x = calculateCellWidth(screenWidthPx, cellLayoutBorderSpacingPx, numColumns);
result.x = calculateCellWidth(screenWidthPx, cellLayoutBorderSpacePx.x, numColumns);
result.y = calculateCellHeight(availableHeightPx - padding.y
- cellLayoutBottomPaddingPx, cellLayoutBorderSpacingPx, inv.numRows);
- cellLayoutBottomPaddingPx, cellLayoutBorderSpacePx.y, inv.numRows);
return result;
}
@ -1097,11 +1125,18 @@ public class DeviceProfile {
writer.println(prefix + pxToDpStr("folderChildTextSizePx", folderChildTextSizePx));
writer.println(prefix + pxToDpStr("folderChildDrawablePaddingPx",
folderChildDrawablePaddingPx));
writer.println(prefix + pxToDpStr("folderCellLayoutBorderSpacingPx",
folderCellLayoutBorderSpacingPx));
writer.println(prefix + pxToDpStr("folderCellLayoutBorderSpaceOriginalPx",
folderCellLayoutBorderSpaceOriginalPx));
writer.println(prefix + pxToDpStr("folderCellLayoutBorderSpacePx Horizontal",
folderCellLayoutBorderSpacePx.x));
writer.println(prefix + pxToDpStr("folderCellLayoutBorderSpacePx Vertical",
folderCellLayoutBorderSpacePx.y));
writer.println(prefix + pxToDpStr("cellLayoutBorderSpacePx Horizontal",
cellLayoutBorderSpacePx.x));
writer.println(prefix + pxToDpStr("cellLayoutBorderSpacePx Vertical",
cellLayoutBorderSpacePx.y));
writer.println(prefix + pxToDpStr("cellLayoutBorderSpacingPx",
cellLayoutBorderSpacingPx));
writer.println(prefix + pxToDpStr("desiredWorkspaceHorizontalMarginPx",
desiredWorkspaceHorizontalMarginPx));

View File

@ -31,6 +31,7 @@ import android.content.res.Resources;
import android.content.res.TypedArray;
import android.content.res.XmlResourceParser;
import android.graphics.Point;
import android.graphics.PointF;
import android.graphics.Rect;
import android.text.TextUtils;
import android.util.AttributeSet;
@ -117,7 +118,12 @@ public class InvariantDeviceProfile {
public float twoPanelPortraitMinCellWidthDps;
public float twoPanelLandscapeMinCellHeightDps;
public float twoPanelLandscapeMinCellWidthDps;
public float borderSpacing;
public PointF borderSpace;
public PointF twoPanelPortraitBorderSpace;
public PointF twoPanelLandscapeBorderSpace;
public float folderBorderSpace;
public float horizontalMargin;
public float twoPanelLandscapeHorizontalMargin;
public float twoPanelPortraitHorizontalMargin;
@ -217,15 +223,15 @@ public class InvariantDeviceProfile {
.add(myDisplayOption);
result.iconSizes[DisplayOption.INDEX_DEFAULT] =
defaultDisplayOption.iconSizes[DisplayOption.INDEX_DEFAULT];
for (int i = 1; i < DisplayOption.COUNT_TOTAL; i++) {
for (int i = 1; i < DisplayOption.COUNT_SIZES; i++) {
result.iconSizes[i] = Math.min(
defaultDisplayOption.iconSizes[i], myDisplayOption.iconSizes[i]);
}
result.minCellHeight = defaultDisplayOption.minCellHeight;
result.minCellWidth = defaultDisplayOption.minCellWidth;
result.borderSpacing = defaultDisplayOption.borderSpacing;
result.allAppsCellSpacing = defaultDisplayOption.allAppsCellSpacing;
result.borderSpaces[DisplayOption.INDEX_ALL_APPS] =
defaultDisplayOption.borderSpaces[DisplayOption.INDEX_ALL_APPS];
initGrid(context, myInfo, result, false);
}
@ -289,8 +295,14 @@ public class InvariantDeviceProfile {
twoPanelPortraitMinCellWidthDps = displayOption.twoPanelPortraitMinCellWidthDps;
twoPanelLandscapeMinCellHeightDps = displayOption.twoPanelLandscapeMinCellHeightDps;
twoPanelLandscapeMinCellWidthDps = displayOption.twoPanelLandscapeMinCellWidthDps;
borderSpacing = displayOption.borderSpacing;
allAppsCellSpacing = displayOption.allAppsCellSpacing;
borderSpace = displayOption.borderSpaces[DisplayOption.INDEX_DEFAULT];
twoPanelPortraitBorderSpace =
displayOption.borderSpaces[DisplayOption.INDEX_TWO_PANEL_PORTRAIT];
twoPanelLandscapeBorderSpace =
displayOption.borderSpaces[DisplayOption.INDEX_TWO_PANEL_LANDSCAPE];
allAppsCellSpacing = displayOption.borderSpaces[DisplayOption.INDEX_ALL_APPS].x;
folderBorderSpace = displayOption.folderBorderSpace;
horizontalMargin = displayOption.horizontalMargin;
twoPanelLandscapeHorizontalMargin = displayOption.twoPanelLandscapeHorizontalMargin;
@ -556,7 +568,7 @@ public class InvariantDeviceProfile {
// predefined size to avoid cache invalidation
out.iconSizes[DisplayOption.INDEX_DEFAULT] =
closestPoint.iconSizes[DisplayOption.INDEX_DEFAULT];
for (int i = DisplayOption.INDEX_DEFAULT + 1; i < DisplayOption.COUNT_TOTAL; i++) {
for (int i = DisplayOption.INDEX_DEFAULT + 1; i < DisplayOption.COUNT_SIZES; i++) {
out.iconSizes[i] = Math.min(out.iconSizes[i],
out.iconSizes[DisplayOption.INDEX_DEFAULT]);
}
@ -712,13 +724,12 @@ public class InvariantDeviceProfile {
@VisibleForTesting
static final class DisplayOption {
static final int COUNT_SIZES = 5;
static final int INDEX_DEFAULT = 0;
static final int INDEX_LANDSCAPE = 1;
static final int INDEX_ALL_APPS = 2;
static final int INDEX_TWO_PANEL_PORTRAIT = 3;
static final int INDEX_TWO_PANEL_LANDSCAPE = 4;
static final int COUNT_TOTAL = 5;
static final int INDEX_TWO_PANEL_PORTRAIT = 2;
static final int INDEX_TWO_PANEL_LANDSCAPE = 3;
static final int INDEX_ALL_APPS = 4;
public final GridOption grid;
@ -732,15 +743,16 @@ public class InvariantDeviceProfile {
private float twoPanelPortraitMinCellWidthDps;
private float twoPanelLandscapeMinCellHeightDps;
private float twoPanelLandscapeMinCellWidthDps;
private float allAppsCellSpacing;
private float borderSpacing;
private float folderBorderSpace;
private final PointF[] borderSpaces = new PointF[COUNT_SIZES];
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];
private final float[] iconSizes = new float[COUNT_SIZES];
private final float[] textSizes = new float[COUNT_SIZES];
DisplayOption(GridOption grid, Context context, AttributeSet attrs, int defaultFlagValue) {
this.grid = grid;
@ -767,9 +779,40 @@ public class InvariantDeviceProfile {
twoPanelLandscapeMinCellWidthDps = a.getFloat(
R.styleable.ProfileDisplayOption_twoPanelLandscapeMinCellWidthDps,
twoPanelPortraitMinCellWidthDps);
borderSpacing = a.getFloat(R.styleable.ProfileDisplayOption_borderSpacingDps, 0);
allAppsCellSpacing = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellSpacingDps,
borderSpacing);
float borderSpace = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceDps, 0);
float twoPanelPortraitBorderSpaceDps = a.getFloat(
R.styleable.ProfileDisplayOption_twoPanelPortraitBorderSpaceDps, borderSpace);
float twoPanelLandscapeBorderSpaceDps = a.getFloat(
R.styleable.ProfileDisplayOption_twoPanelLandscapeBorderSpaceDps, borderSpace);
float x;
float y;
x = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceHorizontalDps, borderSpace);
y = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceVerticalDps, borderSpace);
borderSpaces[INDEX_DEFAULT] = new PointF(x, y);
borderSpaces[INDEX_LANDSCAPE] = new PointF(x, y);
x = a.getFloat(
R.styleable.ProfileDisplayOption_twoPanelPortraitBorderSpaceHorizontalDps,
twoPanelPortraitBorderSpaceDps);
y = a.getFloat(
R.styleable.ProfileDisplayOption_twoPanelPortraitBorderSpaceVerticalDps,
twoPanelPortraitBorderSpaceDps);
borderSpaces[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y);
x = a.getFloat(
R.styleable.ProfileDisplayOption_twoPanelLandscapeBorderSpaceHorizontalDps,
twoPanelLandscapeBorderSpaceDps);
y = a.getFloat(
R.styleable.ProfileDisplayOption_twoPanelLandscapeBorderSpaceVerticalDps,
twoPanelLandscapeBorderSpaceDps);
borderSpaces[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y);
x = y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellSpacingDps,
borderSpace);
borderSpaces[INDEX_ALL_APPS] = new PointF(x, y);
folderBorderSpace = borderSpace;
iconSizes[INDEX_DEFAULT] =
a.getFloat(R.styleable.ProfileDisplayOption_iconImageSize, 0);
@ -823,13 +866,19 @@ public class InvariantDeviceProfile {
canBeDefault = false;
minCellHeight = 0;
minCellWidth = 0;
borderSpacing = 0;
for (int i = 0; i < COUNT_SIZES; i++) {
iconSizes[i] = 0;
textSizes[i] = 0;
borderSpaces[i] = new PointF();
}
}
private DisplayOption multiply(float w) {
for (int i = 0; i < COUNT_TOTAL; i++) {
for (int i = 0; i < COUNT_SIZES; i++) {
iconSizes[i] *= w;
textSizes[i] *= w;
borderSpaces[i].x *= w;
borderSpaces[i].y *= w;
}
minCellHeight *= w;
minCellWidth *= w;
@ -837,8 +886,9 @@ public class InvariantDeviceProfile {
twoPanelPortraitMinCellWidthDps *= w;
twoPanelLandscapeMinCellHeightDps *= w;
twoPanelLandscapeMinCellWidthDps *= w;
borderSpacing *= w;
allAppsCellSpacing *= w;
folderBorderSpace *= w;
horizontalMargin *= w;
twoPanelLandscapeHorizontalMargin *= w;
twoPanelPortraitHorizontalMargin *= w;
@ -846,9 +896,11 @@ public class InvariantDeviceProfile {
}
private DisplayOption add(DisplayOption p) {
for (int i = 0; i < COUNT_TOTAL; i++) {
for (int i = 0; i < COUNT_SIZES; i++) {
iconSizes[i] += p.iconSizes[i];
textSizes[i] += p.textSizes[i];
borderSpaces[i].x += p.borderSpaces[i].x;
borderSpaces[i].y += p.borderSpaces[i].y;
}
minCellHeight += p.minCellHeight;
minCellWidth += p.minCellWidth;
@ -856,8 +908,9 @@ public class InvariantDeviceProfile {
twoPanelPortraitMinCellWidthDps += p.twoPanelPortraitMinCellWidthDps;
twoPanelLandscapeMinCellHeightDps += p.twoPanelLandscapeMinCellHeightDps;
twoPanelLandscapeMinCellWidthDps += p.twoPanelLandscapeMinCellWidthDps;
borderSpacing += p.borderSpacing;
allAppsCellSpacing += p.allAppsCellSpacing;
folderBorderSpace += p.folderBorderSpace;
horizontalMargin += p.horizontalMargin;
twoPanelLandscapeHorizontalMargin += p.twoPanelLandscapeHorizontalMargin;
twoPanelPortraitHorizontalMargin += p.twoPanelPortraitHorizontalMargin;

View File

@ -23,6 +23,7 @@ import static com.android.launcher3.CellLayout.WORKSPACE;
import android.app.WallpaperManager;
import android.content.Context;
import android.graphics.Point;
import android.graphics.Rect;
import android.view.MotionEvent;
import android.view.View;
@ -48,7 +49,7 @@ public class ShortcutAndWidgetContainer extends ViewGroup implements FolderIcon.
private int mCellWidth;
private int mCellHeight;
private int mBorderSpacing;
private Point mBorderSpace;
private int mCountX;
private int mCountY;
@ -64,12 +65,12 @@ public class ShortcutAndWidgetContainer extends ViewGroup implements FolderIcon.
}
public void setCellDimensions(int cellWidth, int cellHeight, int countX, int countY,
int borderSpacing) {
Point borderSpace) {
mCellWidth = cellWidth;
mCellHeight = cellHeight;
mCountX = countX;
mCountY = countY;
mBorderSpacing = borderSpacing;
mBorderSpace = borderSpace;
}
public View getChildAt(int cellX, int cellY) {
@ -108,10 +109,10 @@ public class ShortcutAndWidgetContainer extends ViewGroup implements FolderIcon.
DeviceProfile profile = mActivity.getDeviceProfile();
((NavigableAppWidgetHostView) child).getWidgetInset(profile, mTempRect);
lp.setup(mCellWidth, mCellHeight, invertLayoutHorizontally(), mCountX, mCountY,
profile.appWidgetScale.x, profile.appWidgetScale.y, mBorderSpacing, mTempRect);
profile.appWidgetScale.x, profile.appWidgetScale.y, mBorderSpace, mTempRect);
} else {
lp.setup(mCellWidth, mCellHeight, invertLayoutHorizontally(), mCountX, mCountY,
mBorderSpacing, null);
mBorderSpace, null);
}
}
@ -132,10 +133,10 @@ public class ShortcutAndWidgetContainer extends ViewGroup implements FolderIcon.
if (child instanceof NavigableAppWidgetHostView) {
((NavigableAppWidgetHostView) child).getWidgetInset(dp, mTempRect);
lp.setup(mCellWidth, mCellHeight, invertLayoutHorizontally(), mCountX, mCountY,
dp.appWidgetScale.x, dp.appWidgetScale.y, mBorderSpacing, mTempRect);
dp.appWidgetScale.x, dp.appWidgetScale.y, mBorderSpace, mTempRect);
} else {
lp.setup(mCellWidth, mCellHeight, invertLayoutHorizontally(), mCountX, mCountY,
mBorderSpacing, null);
mBorderSpace, null);
// Center the icon/folder
int cHeight = getCellContentHeight();
int cellPaddingY = dp.isScalableGrid && mContainerType == WORKSPACE
@ -143,8 +144,9 @@ public class ShortcutAndWidgetContainer extends ViewGroup implements FolderIcon.
: (int) Math.max(0, ((lp.height - cHeight) / 2f));
// No need to add padding when cell layout border spacing is present.
boolean noPaddingX = (dp.cellLayoutBorderSpacingPx > 0 && mContainerType == WORKSPACE)
|| (dp.folderCellLayoutBorderSpacingPx > 0 && mContainerType == FOLDER);
boolean noPaddingX =
(dp.cellLayoutBorderSpacePx.x > 0 && mContainerType == WORKSPACE)
|| (dp.folderCellLayoutBorderSpacePx.x > 0 && mContainerType == FOLDER);
int cellPaddingX = noPaddingX
? 0
: mContainerType == WORKSPACE

View File

@ -345,12 +345,12 @@ public class Workspace extends PagedView<WorkspacePageIndicator>
// Add missing cellLayout border in-between panels.
if (panelCount > 1) {
if (i % panelCount == leftPanelModulus) {
paddingRight += grid.cellLayoutBorderSpacingPx / 2;
paddingRight += grid.cellLayoutBorderSpacePx.x / 2;
} else if (i % panelCount == rightPanelModulus) { // right side panel
paddingLeft += grid.cellLayoutBorderSpacingPx / 2;
paddingLeft += grid.cellLayoutBorderSpacePx.x / 2;
} else { // middle panel
paddingLeft += grid.cellLayoutBorderSpacingPx / 2;
paddingRight += grid.cellLayoutBorderSpacingPx / 2;
paddingLeft += grid.cellLayoutBorderSpacePx.x / 2;
paddingRight += grid.cellLayoutBorderSpacePx.x / 2;
}
}
// SparseArrayMap doesn't keep the order

View File

@ -105,8 +105,8 @@ public class AppsSearchContainerLayout extends ExtendedEditText
int rowWidth = myRequestedWidth - mAppsView.getActiveRecyclerView().getPaddingLeft()
- mAppsView.getActiveRecyclerView().getPaddingRight();
int cellWidth = DeviceProfile.calculateCellWidth(rowWidth, dp.cellLayoutBorderSpacingPx,
dp.numShownHotseatIcons);
int cellWidth = DeviceProfile.calculateCellWidth(rowWidth,
dp.cellLayoutBorderSpacePx.x, dp.numShownHotseatIcons);
int iconVisibleSize = Math.round(ICON_VISIBLE_AREA_FACTOR * dp.iconSizePx);
int iconPadding = cellWidth - iconVisibleSize;

View File

@ -239,9 +239,9 @@ public class FolderAnimationManager {
mFolder, startRect, endRect, finalRadius, !mIsOpening));
// Create reveal animator for the folder content (capture the top 4 icons 2x2)
int width = mDeviceProfile.folderCellLayoutBorderSpacingPx
int width = mDeviceProfile.folderCellLayoutBorderSpacePx.x
+ mDeviceProfile.folderCellWidthPx * 2;
int height = mDeviceProfile.folderCellLayoutBorderSpacingPx
int height = mDeviceProfile.folderCellLayoutBorderSpacePx.y
+ mDeviceProfile.folderCellHeightPx * 2;
int page = mIsOpening ? mContent.getCurrentPage() : mContent.getDestinationPage();
int left = mContent.getPaddingLeft() + page * lp.width;

View File

@ -230,15 +230,16 @@ public class LauncherPreviewRenderer extends ContextWrapper
CellLayout firstScreen = mRootView.findViewById(R.id.workspace);
firstScreen.setPadding(mDp.workspacePadding.left + mDp.cellLayoutPaddingLeftRightPx,
mDp.workspacePadding.top,
(mDp.isTwoPanels ? mDp.cellLayoutBorderSpacingPx / 2 : mDp.workspacePadding.right)
+ mDp.cellLayoutPaddingLeftRightPx,
mDp.workspacePadding.bottom);
(mDp.isTwoPanels ? mDp.cellLayoutBorderSpacePx.x / 2
: mDp.workspacePadding.right) + mDp.cellLayoutPaddingLeftRightPx,
mDp.workspacePadding.bottom
);
mWorkspaceScreens.put(FIRST_SCREEN_ID, firstScreen);
if (mDp.isTwoPanels) {
CellLayout rightPanel = mRootView.findViewById(R.id.workspace_right);
rightPanel.setPadding(
mDp.cellLayoutBorderSpacingPx / 2 + mDp.cellLayoutPaddingLeftRightPx,
mDp.cellLayoutBorderSpacePx.x / 2 + mDp.cellLayoutPaddingLeftRightPx,
mDp.workspacePadding.top,
mDp.workspacePadding.right + mDp.cellLayoutPaddingLeftRightPx,
mDp.workspacePadding.bottom

View File

@ -1050,7 +1050,10 @@ public class LoaderTask implements Runnable {
deviceProfile.getCellSize(cellSize);
FileLog.d(TAG, "DeviceProfile available width: " + deviceProfile.availableWidthPx
+ ", available height: " + deviceProfile.availableHeightPx
+ ", cellLayoutBorderSpacingPx: " + deviceProfile.cellLayoutBorderSpacingPx
+ ", cellLayoutBorderSpacePx Horizontal: "
+ deviceProfile.cellLayoutBorderSpacePx.x
+ ", cellLayoutBorderSpacePx Vertical: "
+ deviceProfile.cellLayoutBorderSpacePx.y
+ ", cellSize: " + cellSize);
}

View File

@ -121,29 +121,29 @@ public class LauncherAppWidgetProviderInfo extends AppWidgetProviderInfo
localPadding.set(widgetPadding);
}
minSpanX = Math.max(minSpanX,
getSpanX(localPadding, minResizeWidth, dp.cellLayoutBorderSpacingPx,
getSpanX(localPadding, minResizeWidth, dp.cellLayoutBorderSpacePx.x,
cellSize.x));
minSpanY = Math.max(minSpanY,
getSpanY(localPadding, minResizeHeight, dp.cellLayoutBorderSpacingPx,
getSpanY(localPadding, minResizeHeight, dp.cellLayoutBorderSpacePx.y,
cellSize.y));
if (ATLEAST_S) {
if (maxResizeWidth > 0) {
maxSpanX = Math.min(maxSpanX,
getSpanX(localPadding, maxResizeWidth, dp.cellLayoutBorderSpacingPx,
cellSize.x));
maxSpanX = Math.min(maxSpanX, getSpanX(localPadding, maxResizeWidth,
dp.cellLayoutBorderSpacePx.x, cellSize.x));
}
if (maxResizeHeight > 0) {
maxSpanY = Math.min(maxSpanY,
getSpanY(localPadding, maxResizeHeight, dp.cellLayoutBorderSpacingPx,
cellSize.y));
maxSpanY = Math.min(maxSpanY, getSpanY(localPadding, maxResizeHeight,
dp.cellLayoutBorderSpacePx.y, cellSize.y));
}
}
spanX = Math.max(spanX,
getSpanX(localPadding, minWidth, dp.cellLayoutBorderSpacingPx, cellSize.x));
getSpanX(localPadding, minWidth, dp.cellLayoutBorderSpacePx.x,
cellSize.x));
spanY = Math.max(spanY,
getSpanY(localPadding, minHeight, dp.cellLayoutBorderSpacingPx, cellSize.y));
getSpanY(localPadding, minHeight, dp.cellLayoutBorderSpacePx.y,
cellSize.y));
}
if (ATLEAST_S) {

View File

@ -114,8 +114,8 @@ public final class WidgetSizes {
private static Size getWidgetSizePx(DeviceProfile profile, int spanX, int spanY,
@Nullable Point recycledCellSize) {
final int hBorderSpacing = (spanX - 1) * profile.cellLayoutBorderSpacingPx;
final int vBorderSpacing = (spanY - 1) * profile.cellLayoutBorderSpacingPx;
final int hBorderSpacing = (spanX - 1) * profile.cellLayoutBorderSpacePx.x;
final int vBorderSpacing = (spanY - 1) * profile.cellLayoutBorderSpacePx.y;
if (recycledCellSize == null) {
recycledCellSize = new Point();
}

View File

@ -46,6 +46,7 @@ import java.util.List;
@RunWith(AndroidJUnit4.class)
public final class LauncherAppWidgetProviderInfoTest {
private static final int SPACE_SIZE = 10;
private static final int CELL_SIZE = 50;
private static final int NUM_OF_COLS = 4;
private static final int NUM_OF_ROWS = 5;
@ -159,7 +160,7 @@ public final class LauncherAppWidgetProviderInfoTest {
AppWidgetHostView.getDefaultPaddingForWidget(mContext, null, padding);
int maxPadding = Math.max(Math.max(padding.left, padding.right),
Math.max(padding.top, padding.bottom));
dp.cellLayoutBorderSpacingPx = maxPadding + 1;
dp.cellLayoutBorderSpacePx.x = dp.cellLayoutBorderSpacePx.y = maxPadding + 1;
Mockito.when(dp.shouldInsetWidgets()).thenReturn(true);
LauncherAppWidgetProviderInfo info = new LauncherAppWidgetProviderInfo();
@ -182,7 +183,7 @@ public final class LauncherAppWidgetProviderInfoTest {
AppWidgetHostView.getDefaultPaddingForWidget(mContext, null, padding);
int maxPadding = Math.max(Math.max(padding.left, padding.right),
Math.max(padding.top, padding.bottom));
dp.cellLayoutBorderSpacingPx = maxPadding - 1;
dp.cellLayoutBorderSpacePx.x = dp.cellLayoutBorderSpacePx.y = maxPadding - 1;
Mockito.when(dp.shouldInsetWidgets()).thenReturn(false);
LauncherAppWidgetProviderInfo info = new LauncherAppWidgetProviderInfo();
info.minWidth = CELL_SIZE * 3;
@ -262,6 +263,7 @@ public final class LauncherAppWidgetProviderInfoTest {
return null;
}).when(profile).getCellSize(any(Point.class));
Mockito.when(profile.getCellSize()).thenReturn(new Point(CELL_SIZE, CELL_SIZE));
profile.cellLayoutBorderSpacePx = new Point(SPACE_SIZE, SPACE_SIZE);
Mockito.when(profile.shouldInsetWidgets()).thenReturn(true);
InvariantDeviceProfile idp = new InvariantDeviceProfile();