Merge "Change AllApps padding to use a Rect" into main

This commit is contained in:
Thales Lima
2023-11-01 12:21:53 +00:00
committed by Android (Google) Code Review
17 changed files with 70 additions and 53 deletions
@@ -121,13 +121,13 @@ public class AllAppsState extends LauncherState {
@Override
public int getFloatingSearchBarRestingMarginStart(Launcher launcher) {
DeviceProfile dp = launcher.getDeviceProfile();
return dp.allAppsLeftRightMargin + dp.getAllAppsIconStartMargin();
return dp.allAppsLeftRightMargin + dp.getAllAppsIconStartMargin(launcher);
}
@Override
public int getFloatingSearchBarRestingMarginEnd(Launcher launcher) {
DeviceProfile dp = launcher.getDeviceProfile();
return dp.allAppsLeftRightMargin + dp.getAllAppsIconStartMargin();
return dp.allAppsLeftRightMargin + dp.getAllAppsIconStartMargin(launcher);
}
@Override
+19 -15
View File
@@ -235,14 +235,13 @@ public class DeviceProfile {
// All apps
public Point allAppsBorderSpacePx;
public int allAppsShiftRange;
public int allAppsTopPadding;
public Rect allAppsPadding = new Rect();
public int allAppsOpenDuration;
public int allAppsCloseDuration;
public int allAppsCellHeightPx;
public int allAppsCellWidthPx;
public int allAppsIconSizePx;
public int allAppsIconDrawablePaddingPx;
public int allAppsLeftRightPadding;
public int allAppsLeftRightMargin;
public final int numShownAllAppsColumns;
public float allAppsIconTextSizePx;
@@ -678,10 +677,10 @@ public class DeviceProfile {
res.getDimensionPixelOffset(R.dimen.bottom_sheet_handle_area_height);
int contentHeight = heightPx - collapseHandleHeight - hotseatQsbHeight;
int targetContentHeight = (int) (allAppsCellHeightPx * ALL_APPS_TABLET_MAX_ROWS);
allAppsTopPadding = Math.max(mInsets.top, contentHeight - targetContentHeight);
allAppsShiftRange = heightPx - allAppsTopPadding;
allAppsPadding.top = Math.max(mInsets.top, contentHeight - targetContentHeight);
allAppsShiftRange = heightPx - allAppsPadding.top;
} else {
allAppsTopPadding = 0;
allAppsPadding.top = 0;
allAppsShiftRange =
res.getDimensionPixelSize(R.dimen.all_apps_starting_vertical_translate);
}
@@ -718,7 +717,7 @@ public class DeviceProfile {
* reasonable over estimation is fine.
*/
public int getMaxAllAppsRowCount() {
return (int) (Math.ceil((availableHeightPx - allAppsTopPadding)
return (int) (Math.ceil((availableHeightPx - allAppsPadding.top)
/ (float) allAppsCellHeightPx));
}
@@ -1259,7 +1258,8 @@ public class DeviceProfile {
allAppsCellHeightPx = mAllAppsResponsiveHeightSpec.getCellSizePx()
+ mAllAppsResponsiveHeightSpec.getGutterPx();
allAppsCellWidthPx = mAllAppsResponsiveWidthSpec.getCellSizePx();
allAppsLeftRightPadding = mAllAppsResponsiveWidthSpec.getStartPaddingPx();
allAppsPadding.left = mAllAppsResponsiveWidthSpec.getStartPaddingPx();
allAppsPadding.right = mAllAppsResponsiveWidthSpec.getEndPaddingPx();
}
/**
@@ -1278,10 +1278,10 @@ public class DeviceProfile {
if (isTablet) {
int usedWidth = (allAppsCellWidthPx * numShownAllAppsColumns)
+ (allAppsBorderSpacePx.x * (numShownAllAppsColumns - 1))
+ allAppsLeftRightPadding * 2;
+ allAppsPadding.left + allAppsPadding.right;
allAppsLeftRightMargin = Math.max(1, (availableWidthPx - usedWidth) / 2);
} else {
allAppsLeftRightPadding =
allAppsPadding.left = allAppsPadding.right =
Math.max(0, desiredWorkspaceHorizontalMarginPx + cellLayoutHorizontalPadding
- (allAppsBorderSpacePx.x / 2));
}
@@ -1292,7 +1292,7 @@ public class DeviceProfile {
inv.allAppsStyle != INVALID_RESOURCE_HANDLE ? inv.allAppsStyle
: R.style.AllAppsStyleDefault, R.styleable.AllAppsStyle);
allAppsLeftRightPadding = allAppsStyle.getDimensionPixelSize(
allAppsPadding.left = allAppsPadding.right = allAppsStyle.getDimensionPixelSize(
R.styleable.AllAppsStyle_horizontalPadding, 0);
allAppsStyle.recycle();
}
@@ -1699,13 +1699,14 @@ public class DeviceProfile {
}
/** The margin between the edge of all apps and the edge of the first icon. */
public int getAllAppsIconStartMargin() {
public int getAllAppsIconStartMargin(Context context) {
int allAppsSpacing;
if (isVerticalBarLayout()) {
// On phones, the landscape layout uses a different setup.
allAppsSpacing = workspacePadding.left + workspacePadding.right;
} else {
allAppsSpacing = allAppsLeftRightPadding * 2 + allAppsLeftRightMargin * 2;
allAppsSpacing =
allAppsPadding.left + allAppsPadding.right + allAppsLeftRightMargin * 2;
}
int cellWidth = DeviceProfile.calculateCellWidth(
@@ -1714,7 +1715,9 @@ public class DeviceProfile {
numShownAllAppsColumns);
int iconVisibleSize = Math.round(ICON_VISIBLE_AREA_FACTOR * allAppsIconSizePx);
int iconAlignmentMargin = (cellWidth - iconVisibleSize) / 2;
return allAppsLeftRightPadding + iconAlignmentMargin;
return (Utilities.isRtl(context.getResources()) ? allAppsPadding.right
: allAppsPadding.left) + iconAlignmentMargin;
}
private int getAdditionalQsbSpace() {
@@ -1963,7 +1966,6 @@ public class DeviceProfile {
writer.println(prefix + "\tbottomSheetDepth: " + bottomSheetDepth);
writer.println(prefix + pxToDpStr("allAppsShiftRange", allAppsShiftRange));
writer.println(prefix + pxToDpStr("allAppsTopPadding", allAppsTopPadding));
writer.println(prefix + "\tallAppsOpenDuration: " + allAppsOpenDuration);
writer.println(prefix + "\tallAppsCloseDuration: " + allAppsCloseDuration);
writer.println(prefix + pxToDpStr("allAppsIconSizePx", allAppsIconSizePx));
@@ -1975,7 +1977,9 @@ public class DeviceProfile {
writer.println(prefix + pxToDpStr("allAppsBorderSpacePxX", allAppsBorderSpacePx.x));
writer.println(prefix + pxToDpStr("allAppsBorderSpacePxY", allAppsBorderSpacePx.y));
writer.println(prefix + "\tnumShownAllAppsColumns: " + numShownAllAppsColumns);
writer.println(prefix + pxToDpStr("allAppsLeftRightPadding", allAppsLeftRightPadding));
writer.println(prefix + pxToDpStr("allAppsPadding.top", allAppsPadding.top));
writer.println(prefix + pxToDpStr("allAppsPadding.left", allAppsPadding.left));
writer.println(prefix + pxToDpStr("allAppsPadding.right", allAppsPadding.right));
writer.println(prefix + pxToDpStr("allAppsLeftRightMargin", allAppsLeftRightMargin));
writer.println(prefix + pxToDpStr("hotseatBarSizePx", hotseatBarSizePx));
@@ -797,7 +797,7 @@ public class ActivityAllAppsContainerView<T extends Context & ActivityContext>
*/
public int getFloatingSearchBarRestingMarginStart() {
DeviceProfile dp = mActivityContext.getDeviceProfile();
return dp.allAppsLeftRightMargin + dp.getAllAppsIconStartMargin();
return dp.allAppsLeftRightMargin + dp.getAllAppsIconStartMargin(mActivityContext);
}
/**
@@ -810,7 +810,7 @@ public class ActivityAllAppsContainerView<T extends Context & ActivityContext>
*/
public int getFloatingSearchBarRestingMarginEnd() {
DeviceProfile dp = mActivityContext.getDeviceProfile();
return dp.allAppsLeftRightMargin + dp.getAllAppsIconStartMargin();
return dp.allAppsLeftRightMargin + dp.getAllAppsIconStartMargin(mActivityContext);
}
private void layoutBelowSearchContainer(View v, boolean includeTabsMargin) {
@@ -1101,7 +1101,7 @@ public class ActivityAllAppsContainerView<T extends Context & ActivityContext>
if (grid.isVerticalBarLayout()) {
setPadding(grid.workspacePadding.left, 0, grid.workspacePadding.right, 0);
} else {
int topPadding = grid.allAppsTopPadding;
int topPadding = grid.allAppsPadding.top;
if (isSearchBarFloating() && !grid.isTablet) {
topPadding += getResources().getDimensionPixelSize(
R.dimen.all_apps_additional_top_padding_floating_search);
@@ -1162,8 +1162,8 @@ public class ActivityAllAppsContainerView<T extends Context & ActivityContext>
int bottomPadding = Math.max(mInsets.bottom, mNavBarScrimHeight);
mAH.forEach(adapterHolder -> {
adapterHolder.mPadding.bottom = bottomPadding;
adapterHolder.mPadding.left =
adapterHolder.mPadding.right = grid.allAppsLeftRightPadding;
adapterHolder.mPadding.left = grid.allAppsPadding.left;
adapterHolder.mPadding.right = grid.allAppsPadding.right;
adapterHolder.applyPadding();
});
}
@@ -451,9 +451,9 @@ public class FloatingHeaderView extends LinearLayout implements
@Override
public void setInsets(Rect insets) {
int leftRightPadding = ActivityContext.lookupContext(getContext())
.getDeviceProfile().allAppsLeftRightPadding;
setPadding(leftRightPadding, getPaddingTop(), leftRightPadding, getPaddingBottom());
Rect allAppsPadding = ActivityContext.lookupContext(getContext())
.getDeviceProfile().allAppsPadding;
setPadding(allAppsPadding.left, getPaddingTop(), allAppsPadding.right, getPaddingBottom());
}
public <T extends FloatingHeaderRow> T findFixedRowByType(Class<T> type) {
@@ -117,12 +117,13 @@ public class WorkModeSwitch extends LinearLayout implements Insettable,
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
super.onLayout(changed, left, top, right, bottom);
View parent = (View) getParent();
int allAppsLeftRightPadding = mActivityContext.getDeviceProfile().allAppsLeftRightPadding;
boolean isRtl = Utilities.isRtl(getResources());
Rect allAppsPadding = mActivityContext.getDeviceProfile().allAppsPadding;
int size = parent.getWidth() - parent.getPaddingLeft() - parent.getPaddingRight()
- 2 * allAppsLeftRightPadding;
- (allAppsPadding.left + allAppsPadding.right);
int tabWidth = getTabWidth(getContext(), size);
int shift = (size - tabWidth) / 2 + allAppsLeftRightPadding;
setTranslationX(Utilities.isRtl(getResources()) ? shift : -shift);
int shift = (size - tabWidth) / 2 + (isRtl ? allAppsPadding.left : allAppsPadding.right);
setTranslationX(isRtl ? shift : -shift);
}
@Override
@@ -55,7 +55,6 @@ DeviceProfile:
bottomSheetWorkspaceScale: 1.0
bottomSheetDepth: 0.0
allAppsShiftRange: 788.0px (300.1905dp)
allAppsTopPadding: 0.0px (0.0dp)
allAppsOpenDuration: 600
allAppsCloseDuration: 300
allAppsIconSizePx: 147.0px (56.0dp)
@@ -66,7 +65,9 @@ DeviceProfile:
allAppsBorderSpacePxX: 42.0px (16.0dp)
allAppsBorderSpacePxY: 42.0px (16.0dp)
numShownAllAppsColumns: 5
allAppsLeftRightPadding: 0.0px (0.0dp)
allAppsPadding.top: 0.0px (0.0dp)
allAppsPadding.left: 0.0px (0.0dp)
allAppsPadding.right: 0.0px (0.0dp)
allAppsLeftRightMargin: 0.0px (0.0dp)
hotseatBarSizePx: 273.0px (104.0dp)
inv.hotseatColumnSpan: 5
@@ -55,7 +55,6 @@ DeviceProfile:
bottomSheetWorkspaceScale: 1.0
bottomSheetDepth: 0.0
allAppsShiftRange: 788.0px (300.1905dp)
allAppsTopPadding: 0.0px (0.0dp)
allAppsOpenDuration: 600
allAppsCloseDuration: 300
allAppsIconSizePx: 147.0px (56.0dp)
@@ -66,7 +65,9 @@ DeviceProfile:
allAppsBorderSpacePxX: 42.0px (16.0dp)
allAppsBorderSpacePxY: 42.0px (16.0dp)
numShownAllAppsColumns: 5
allAppsLeftRightPadding: 0.0px (0.0dp)
allAppsPadding.top: 0.0px (0.0dp)
allAppsPadding.left: 0.0px (0.0dp)
allAppsPadding.right: 0.0px (0.0dp)
allAppsLeftRightMargin: 0.0px (0.0dp)
hotseatBarSizePx: 294.0px (112.0dp)
inv.hotseatColumnSpan: 5
@@ -55,7 +55,6 @@ DeviceProfile:
bottomSheetWorkspaceScale: 1.0
bottomSheetDepth: 0.0
allAppsShiftRange: 788.0px (300.1905dp)
allAppsTopPadding: 0.0px (0.0dp)
allAppsOpenDuration: 600
allAppsCloseDuration: 300
allAppsIconSizePx: 147.0px (56.0dp)
@@ -66,7 +65,9 @@ DeviceProfile:
allAppsBorderSpacePxX: 42.0px (16.0dp)
allAppsBorderSpacePxY: 42.0px (16.0dp)
numShownAllAppsColumns: 5
allAppsLeftRightPadding: 0.0px (0.0dp)
allAppsPadding.top: 0.0px (0.0dp)
allAppsPadding.left: 0.0px (0.0dp)
allAppsPadding.right: 0.0px (0.0dp)
allAppsLeftRightMargin: 0.0px (0.0dp)
hotseatBarSizePx: 252.0px (96.0dp)
inv.hotseatColumnSpan: 5
@@ -55,7 +55,6 @@ DeviceProfile:
bottomSheetWorkspaceScale: 1.0
bottomSheetDepth: 0.0
allAppsShiftRange: 788.0px (300.1905dp)
allAppsTopPadding: 0.0px (0.0dp)
allAppsOpenDuration: 600
allAppsCloseDuration: 300
allAppsIconSizePx: 147.0px (56.0dp)
@@ -66,7 +65,9 @@ DeviceProfile:
allAppsBorderSpacePxX: 42.0px (16.0dp)
allAppsBorderSpacePxY: 42.0px (16.0dp)
numShownAllAppsColumns: 5
allAppsLeftRightPadding: 0.0px (0.0dp)
allAppsPadding.top: 0.0px (0.0dp)
allAppsPadding.left: 0.0px (0.0dp)
allAppsPadding.right: 0.0px (0.0dp)
allAppsLeftRightMargin: 0.0px (0.0dp)
hotseatBarSizePx: 252.0px (96.0dp)
inv.hotseatColumnSpan: 5
@@ -55,7 +55,6 @@ DeviceProfile:
bottomSheetWorkspaceScale: 0.97
bottomSheetDepth: 0.0
allAppsShiftRange: 1496.0px (748.0dp)
allAppsTopPadding: 104.0px (52.0dp)
allAppsOpenDuration: 500
allAppsCloseDuration: 500
allAppsIconSizePx: 120.0px (60.0dp)
@@ -66,7 +65,9 @@ DeviceProfile:
allAppsBorderSpacePxX: 32.0px (16.0dp)
allAppsBorderSpacePxY: 32.0px (16.0dp)
numShownAllAppsColumns: 6
allAppsLeftRightPadding: 32.0px (16.0dp)
allAppsPadding.top: 104.0px (52.0dp)
allAppsPadding.left: 32.0px (16.0dp)
allAppsPadding.right: 32.0px (16.0dp)
allAppsLeftRightMargin: 412.0px (206.0dp)
hotseatBarSizePx: 200.0px (100.0dp)
inv.hotseatColumnSpan: 4
@@ -55,7 +55,6 @@ DeviceProfile:
bottomSheetWorkspaceScale: 0.97
bottomSheetDepth: 0.0
allAppsShiftRange: 1496.0px (748.0dp)
allAppsTopPadding: 104.0px (52.0dp)
allAppsOpenDuration: 500
allAppsCloseDuration: 500
allAppsIconSizePx: 120.0px (60.0dp)
@@ -66,7 +65,9 @@ DeviceProfile:
allAppsBorderSpacePxX: 32.0px (16.0dp)
allAppsBorderSpacePxY: 32.0px (16.0dp)
numShownAllAppsColumns: 6
allAppsLeftRightPadding: 32.0px (16.0dp)
allAppsPadding.top: 104.0px (52.0dp)
allAppsPadding.left: 32.0px (16.0dp)
allAppsPadding.right: 32.0px (16.0dp)
allAppsLeftRightMargin: 412.0px (206.0dp)
hotseatBarSizePx: 200.0px (100.0dp)
inv.hotseatColumnSpan: 4
@@ -55,7 +55,6 @@ DeviceProfile:
bottomSheetWorkspaceScale: 0.97
bottomSheetDepth: 0.0
allAppsShiftRange: 2019.0px (1009.5dp)
allAppsTopPadding: 541.0px (270.5dp)
allAppsOpenDuration: 500
allAppsCloseDuration: 500
allAppsIconSizePx: 120.0px (60.0dp)
@@ -66,7 +65,9 @@ DeviceProfile:
allAppsBorderSpacePxX: 16.0px (8.0dp)
allAppsBorderSpacePxY: 32.0px (16.0dp)
numShownAllAppsColumns: 6
allAppsLeftRightPadding: 32.0px (16.0dp)
allAppsPadding.top: 541.0px (270.5dp)
allAppsPadding.left: 32.0px (16.0dp)
allAppsPadding.right: 32.0px (16.0dp)
allAppsLeftRightMargin: 152.0px (76.0dp)
hotseatBarSizePx: 272.0px (136.0dp)
inv.hotseatColumnSpan: 6
@@ -55,7 +55,6 @@ DeviceProfile:
bottomSheetWorkspaceScale: 0.97
bottomSheetDepth: 0.0
allAppsShiftRange: 2019.0px (1009.5dp)
allAppsTopPadding: 541.0px (270.5dp)
allAppsOpenDuration: 500
allAppsCloseDuration: 500
allAppsIconSizePx: 120.0px (60.0dp)
@@ -66,7 +65,9 @@ DeviceProfile:
allAppsBorderSpacePxX: 16.0px (8.0dp)
allAppsBorderSpacePxY: 32.0px (16.0dp)
numShownAllAppsColumns: 6
allAppsLeftRightPadding: 32.0px (16.0dp)
allAppsPadding.top: 541.0px (270.5dp)
allAppsPadding.left: 32.0px (16.0dp)
allAppsPadding.right: 32.0px (16.0dp)
allAppsLeftRightMargin: 152.0px (76.0dp)
hotseatBarSizePx: 272.0px (136.0dp)
inv.hotseatColumnSpan: 6
@@ -55,7 +55,6 @@ DeviceProfile:
bottomSheetWorkspaceScale: 0.97
bottomSheetDepth: 1.0
allAppsShiftRange: 1730.0px (659.0476dp)
allAppsTopPadding: 110.0px (41.904762dp)
allAppsOpenDuration: 500
allAppsCloseDuration: 500
allAppsIconSizePx: 141.0px (53.714287dp)
@@ -66,7 +65,9 @@ DeviceProfile:
allAppsBorderSpacePxX: 42.0px (16.0dp)
allAppsBorderSpacePxY: 42.0px (16.0dp)
numShownAllAppsColumns: 8
allAppsLeftRightPadding: 42.0px (16.0dp)
allAppsPadding.top: 110.0px (41.904762dp)
allAppsPadding.left: 42.0px (16.0dp)
allAppsPadding.right: 42.0px (16.0dp)
allAppsLeftRightMargin: 183.0px (69.71429dp)
hotseatBarSizePx: 267.0px (101.71429dp)
inv.hotseatColumnSpan: 4
@@ -55,7 +55,6 @@ DeviceProfile:
bottomSheetWorkspaceScale: 0.97
bottomSheetDepth: 1.0
allAppsShiftRange: 1730.0px (659.0476dp)
allAppsTopPadding: 110.0px (41.904762dp)
allAppsOpenDuration: 500
allAppsCloseDuration: 500
allAppsIconSizePx: 141.0px (53.714287dp)
@@ -66,7 +65,9 @@ DeviceProfile:
allAppsBorderSpacePxX: 42.0px (16.0dp)
allAppsBorderSpacePxY: 42.0px (16.0dp)
numShownAllAppsColumns: 8
allAppsLeftRightPadding: 42.0px (16.0dp)
allAppsPadding.top: 110.0px (41.904762dp)
allAppsPadding.left: 42.0px (16.0dp)
allAppsPadding.right: 42.0px (16.0dp)
allAppsLeftRightMargin: 183.0px (69.71429dp)
hotseatBarSizePx: 267.0px (101.71429dp)
inv.hotseatColumnSpan: 4
@@ -55,7 +55,6 @@ DeviceProfile:
bottomSheetWorkspaceScale: 0.97
bottomSheetDepth: 1.0
allAppsShiftRange: 2075.0px (790.4762dp)
allAppsTopPadding: 133.0px (50.666668dp)
allAppsOpenDuration: 500
allAppsCloseDuration: 500
allAppsIconSizePx: 141.0px (53.714287dp)
@@ -66,7 +65,9 @@ DeviceProfile:
allAppsBorderSpacePxX: 42.0px (16.0dp)
allAppsBorderSpacePxY: 42.0px (16.0dp)
numShownAllAppsColumns: 8
allAppsLeftRightPadding: 42.0px (16.0dp)
allAppsPadding.top: 133.0px (50.666668dp)
allAppsPadding.left: 42.0px (16.0dp)
allAppsPadding.right: 42.0px (16.0dp)
allAppsLeftRightMargin: 1.0px (0.3809524dp)
hotseatBarSizePx: 267.0px (101.71429dp)
inv.hotseatColumnSpan: 4
@@ -55,7 +55,6 @@ DeviceProfile:
bottomSheetWorkspaceScale: 0.97
bottomSheetDepth: 1.0
allAppsShiftRange: 2075.0px (790.4762dp)
allAppsTopPadding: 133.0px (50.666668dp)
allAppsOpenDuration: 500
allAppsCloseDuration: 500
allAppsIconSizePx: 141.0px (53.714287dp)
@@ -66,7 +65,9 @@ DeviceProfile:
allAppsBorderSpacePxX: 42.0px (16.0dp)
allAppsBorderSpacePxY: 42.0px (16.0dp)
numShownAllAppsColumns: 8
allAppsLeftRightPadding: 42.0px (16.0dp)
allAppsPadding.top: 133.0px (50.666668dp)
allAppsPadding.left: 42.0px (16.0dp)
allAppsPadding.right: 42.0px (16.0dp)
allAppsLeftRightMargin: 1.0px (0.3809524dp)
hotseatBarSizePx: 267.0px (101.71429dp)
inv.hotseatColumnSpan: 4