Refactor device padding to be set per grid option

- Fixes bug where devices with scaled grids were not
  getting the correct deivce padding.
- Also fix bug where device padding was invalid.
  Added validation check when processing paddings to prevent
  this from happening again.

Bug: 175329686
Test: manual, enable debug flag,
      run and verify no crash from validation check

Change-Id: I35b019c40667c08de4fad95ac4b05b2d8f8a0e74
This commit is contained in:
Jon Miranda
2021-03-22 17:13:34 -04:00
parent dedbc8ac36
commit c9e69fa98d
5 changed files with 74 additions and 14 deletions

View File

@@ -132,6 +132,7 @@ public class InvariantDeviceProfile {
* Do not query directly. see {@link DeviceProfile#isScalableGrid}.
*/
protected boolean isScalable;
public int devicePaddingId;
public String dbFile;
public int defaultLayoutId;
@@ -140,7 +141,7 @@ public class InvariantDeviceProfile {
public DeviceProfile landscapeProfile;
public DeviceProfile portraitProfile;
public DevicePaddings devicePaddings;
@Nullable public DevicePaddings devicePaddings;
public Point defaultWallpaperSize;
public Rect defaultWidgetPadding;
@@ -165,6 +166,7 @@ public class InvariantDeviceProfile {
numHotseatIcons = p.numHotseatIcons;
numAllAppsColumns = p.numAllAppsColumns;
isScalable = p.isScalable;
devicePaddingId = p.devicePaddingId;
minCellHeight = p.minCellHeight;
minCellWidth = p.minCellWidth;
borderSpacing = p.borderSpacing;
@@ -231,7 +233,6 @@ public class InvariantDeviceProfile {
result.minCellWidth = defaultDisplayOption.minCellWidth;
result.borderSpacing = defaultDisplayOption.borderSpacing;
devicePaddings = new DevicePaddings(context);
initGrid(context, myInfo, result);
}
@@ -262,7 +263,6 @@ public class InvariantDeviceProfile {
ArrayList<DisplayOption> allOptions = getPredefinedDeviceProfiles(context, gridName);
DisplayOption displayOption = invDistWeightedInterpolate(displayInfo, allOptions);
devicePaddings = new DevicePaddings(context);
initGrid(context, displayInfo, displayOption);
return displayOption.grid.name;
}
@@ -280,6 +280,7 @@ public class InvariantDeviceProfile {
numFolderColumns = closestProfile.numFolderColumns;
numAllAppsColumns = closestProfile.numAllAppsColumns;
isScalable = closestProfile.isScalable;
devicePaddingId = closestProfile.devicePaddingId;
mExtraAttrs = closestProfile.extraAttrs;
@@ -302,6 +303,10 @@ public class InvariantDeviceProfile {
allAppsIconTextSize = iconTextSize;
}
if (devicePaddingId != 0) {
devicePaddings = new DevicePaddings(context, devicePaddingId);
}
// If the partner customization apk contains any grid overrides, apply them
// Supported overrides: numRows, numColumns, iconSize
applyPartnerDeviceProfileOverrides(context, displayInfo.metrics);
@@ -615,6 +620,7 @@ public class InvariantDeviceProfile {
private final int demoModeLayoutId;
private final boolean isScalable;
private final int devicePaddingId;
private final SparseArray<TypedValue> extraAttrs;
@@ -641,6 +647,8 @@ public class InvariantDeviceProfile {
isScalable = a.getBoolean(
R.styleable.GridDisplayOption_isScalable, false);
devicePaddingId = a.getResourceId(
R.styleable.GridDisplayOption_devicePaddingId, 0);
a.recycle();