diff --git a/res/xml/paddings_handhelds.xml b/res/xml/paddings_handhelds.xml
new file mode 100644
index 0000000000..b9549a6133
--- /dev/null
+++ b/res/xml/paddings_handhelds.xml
@@ -0,0 +1,33 @@
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/com/android/launcher3/DeviceProfile.java b/src/com/android/launcher3/DeviceProfile.java
index 3cb3461f8f..92530eaae6 100644
--- a/src/com/android/launcher3/DeviceProfile.java
+++ b/src/com/android/launcher3/DeviceProfile.java
@@ -498,10 +498,11 @@ public class DeviceProfile {
extraSpace = updateAvailableDimensions(res);
// Now that we have all of the variables calculated, we can tune certain sizes.
- if (isScalableGrid && inv.devicePaddings != null) {
+ if (isScalableGrid && inv.devicePaddingId != INVALID_RESOURCE_HANDLE) {
// Paddings were created assuming no scaling, so we first unscale the extra space.
int unscaledExtraSpace = (int) (extraSpace / cellScaleToFit);
- DevicePadding padding = inv.devicePaddings.getDevicePadding(unscaledExtraSpace);
+ DevicePaddings devicePaddings = new DevicePaddings(context, inv.devicePaddingId);
+ DevicePadding padding = devicePaddings.getDevicePadding(unscaledExtraSpace);
int paddingWorkspaceTop = padding.getWorkspaceTopPadding(unscaledExtraSpace);
int paddingWorkspaceBottom = padding.getWorkspaceBottomPadding(unscaledExtraSpace);
@@ -1565,10 +1566,11 @@ public class DeviceProfile {
writer.println(prefix + pxToDpStr("extraSpace", extraSpace));
writer.println(prefix + pxToDpStr("unscaled extraSpace", extraSpace / iconScale));
- if (inv.devicePaddings != null) {
+ if (inv.devicePaddingId != INVALID_RESOURCE_HANDLE) {
int unscaledExtraSpace = (int) (extraSpace / iconScale);
+ DevicePaddings devicePaddings = new DevicePaddings(context, inv.devicePaddingId);
writer.println(prefix + pxToDpStr("maxEmptySpace",
- inv.devicePaddings.getDevicePadding(unscaledExtraSpace).getMaxEmptySpacePx()));
+ devicePaddings.getDevicePadding(unscaledExtraSpace).getMaxEmptySpacePx()));
}
writer.println(prefix + pxToDpStr("workspaceTopPadding", workspaceTopPadding));
writer.println(prefix + pxToDpStr("workspaceBottomPadding", workspaceBottomPadding));
diff --git a/src/com/android/launcher3/InvariantDeviceProfile.java b/src/com/android/launcher3/InvariantDeviceProfile.java
index 9c5ec38866..ef06ff12e3 100644
--- a/src/com/android/launcher3/InvariantDeviceProfile.java
+++ b/src/com/android/launcher3/InvariantDeviceProfile.java
@@ -47,9 +47,9 @@ import android.view.Display;
import androidx.annotation.DimenRes;
import androidx.annotation.IntDef;
-import androidx.annotation.Nullable;
import androidx.annotation.StyleRes;
import androidx.annotation.VisibleForTesting;
+import androidx.annotation.XmlRes;
import androidx.core.content.res.ResourcesCompat;
import com.android.launcher3.icons.DotRenderer;
@@ -172,7 +172,8 @@ public class InvariantDeviceProfile {
* Do not query directly. see {@link DeviceProfile#isScalableGrid}.
*/
protected boolean isScalable;
- public int devicePaddingId;
+ @XmlRes
+ public int devicePaddingId = INVALID_RESOURCE_HANDLE;
public String dbFile;
public int defaultLayoutId;
@@ -184,9 +185,6 @@ public class InvariantDeviceProfile {
*/
public List supportedProfiles = Collections.EMPTY_LIST;
- @Nullable
- public DevicePaddings devicePaddings;
-
public Point defaultWallpaperSize;
public Rect defaultWidgetPadding;
@@ -384,10 +382,6 @@ public class InvariantDeviceProfile {
allAppsIconSize = displayOption.allAppsIconSizes;
allAppsIconTextSize = displayOption.allAppsIconTextSizes;
- if (devicePaddingId != 0) {
- devicePaddings = new DevicePaddings(context, devicePaddingId);
- }
-
inlineQsb = closestProfile.inlineQsb;
// If the partner customization apk contains any grid overrides, apply them
@@ -825,7 +819,7 @@ public class InvariantDeviceProfile {
isScalable = a.getBoolean(
R.styleable.GridDisplayOption_isScalable, false);
devicePaddingId = a.getResourceId(
- R.styleable.GridDisplayOption_devicePaddingId, 0);
+ R.styleable.GridDisplayOption_devicePaddingId, INVALID_RESOURCE_HANDLE);
int deviceCategory = a.getInt(R.styleable.GridDisplayOption_deviceCategory,
DEVICE_CATEGORY_ALL);
diff --git a/tests/src/com/android/launcher3/DeviceProfileBaseTest.kt b/tests/src/com/android/launcher3/DeviceProfileBaseTest.kt
index fe30fdc81d..4e166ce418 100644
--- a/tests/src/com/android/launcher3/DeviceProfileBaseTest.kt
+++ b/tests/src/com/android/launcher3/DeviceProfileBaseTest.kt
@@ -16,7 +16,6 @@
package com.android.launcher3
import android.content.Context
-import android.graphics.Point
import android.graphics.PointF
import android.graphics.Rect
import android.util.SparseArray
@@ -26,7 +25,6 @@ import com.android.launcher3.util.DisplayController.Info
import com.android.launcher3.util.WindowBounds
import org.junit.Before
import org.mockito.ArgumentMatchers.any
-import org.mockito.ArgumentMatchers.anyInt
import org.mockito.Mockito.mock
import java.io.PrintWriter
import java.io.StringWriter
@@ -42,9 +40,6 @@ abstract class DeviceProfileBaseTest {
protected var transposeLayoutWithOrientation: Boolean = false
protected var useTwoPanels: Boolean = false
protected var isGestureMode: Boolean = true
- protected var devicePaddingsMock: DevicePaddings = mock(DevicePaddings::class.java)
- protected var staticdevicePaddingsMock: DevicePaddings.DevicePadding =
- mock(DevicePaddings.DevicePadding::class.java)
@Before
fun setUp() {
@@ -83,11 +78,6 @@ abstract class DeviceProfileBaseTest {
whenever(info.isTablet(any())).thenReturn(false)
whenever(info.getDensityDpi()).thenReturn(420)
whenever(info.smallestSizeDp(any())).thenReturn(411f)
- whenever(devicePaddingsMock.getDevicePadding(anyInt())).thenReturn(staticdevicePaddingsMock)
- whenever(staticdevicePaddingsMock.getWorkspaceTopPadding(anyInt())).thenReturn(95)
- whenever(staticdevicePaddingsMock.getWorkspaceBottomPadding(anyInt())).thenReturn(116)
- whenever(staticdevicePaddingsMock.maxEmptySpacePx)
- .thenReturn(if (isVerticalBar) if (isGestureMode) 131 else 184 else 315)
this.isGestureMode = isGestureMode
transposeLayoutWithOrientation = true
@@ -152,7 +142,7 @@ abstract class DeviceProfileBaseTest {
inlineQsb = BooleanArray(4) { false }
- devicePaddings = devicePaddingsMock
+ devicePaddingId = R.xml.paddings_handhelds
}
}
@@ -169,13 +159,6 @@ abstract class DeviceProfileBaseTest {
whenever(info.isTablet(any())).thenReturn(true)
whenever(info.getDensityDpi()).thenReturn(320)
whenever(info.smallestSizeDp(any())).thenReturn(800f)
- whenever(devicePaddingsMock.getDevicePadding(anyInt())).thenReturn(staticdevicePaddingsMock)
- whenever(staticdevicePaddingsMock.getWorkspaceTopPadding(anyInt()))
- .thenReturn(if (isLandscape) 32 else 159)
- whenever(staticdevicePaddingsMock.getWorkspaceBottomPadding(anyInt()))
- .thenReturn(if (isLandscape) 72 else 203)
- whenever(staticdevicePaddingsMock.maxEmptySpacePx).thenReturn(if (isLandscape) 200 else 19998)
-
this.isGestureMode = isGestureMode
useTwoPanels = false
@@ -246,7 +229,7 @@ abstract class DeviceProfileBaseTest {
false
)
- devicePaddings = devicePaddingsMock
+ devicePaddingId = R.xml.paddings_handhelds
}
}
@@ -263,15 +246,6 @@ abstract class DeviceProfileBaseTest {
whenever(info.isTablet(any())).thenReturn(true)
whenever(info.getDensityDpi()).thenReturn(420)
whenever(info.smallestSizeDp(any())).thenReturn(700f)
- whenever(devicePaddingsMock.getDevicePadding(anyInt())).thenReturn(staticdevicePaddingsMock)
-
- val topPadding = if (isLandscape) 18 else 89
- val bottomPadding = if (isLandscape) 39 else 146
- val maxEmptySpace = if (isLandscape) 131 else 236
- whenever(staticdevicePaddingsMock.getWorkspaceTopPadding(anyInt())).thenReturn(topPadding)
- whenever(staticdevicePaddingsMock.getWorkspaceBottomPadding(anyInt()))
- .thenReturn(bottomPadding)
- whenever(staticdevicePaddingsMock.maxEmptySpacePx).thenReturn(maxEmptySpace)
this.isGestureMode = isGestureMode
useTwoPanels = true
@@ -342,7 +316,7 @@ abstract class DeviceProfileBaseTest {
false
)
- devicePaddings = devicePaddingsMock
+ devicePaddingId = R.xml.paddings_handhelds
}
}