Calculate sizes for responsive grid
This shouldn't change anything in the grids, only calculate the sizes of the grid.
Bug: 277064708
Test: CalculatedWorkspaceSpecTest
Test: WorkspaceSpecsTest
Flag: ENABLE_RESPONSIVE_WORKSPACE
Change-Id: Id1f90ef44f5b869113d063bad17589e7e88d1d20
diff --git a/src/com/android/launcher3/DeviceProfile.java b/src/com/android/launcher3/DeviceProfile.java
index 0231090..fb41044 100644
--- a/src/com/android/launcher3/DeviceProfile.java
+++ b/src/com/android/launcher3/DeviceProfile.java
@@ -55,7 +55,10 @@
import com.android.launcher3.uioverrides.ApiWrapper;
import com.android.launcher3.util.DisplayController;
import com.android.launcher3.util.DisplayController.Info;
+import com.android.launcher3.util.ResourceHelper;
import com.android.launcher3.util.WindowBounds;
+import com.android.launcher3.workspace.CalculatedWorkspaceSpec;
+import com.android.launcher3.workspace.WorkspaceSpecs;
import java.io.PrintWriter;
import java.util.Locale;
@@ -101,9 +104,14 @@
public final float aspectRatio;
public final boolean isScalableGrid;
- public final boolean isResponsiveGrid;
private final int mTypeIndex;
+ // Responsive grid
+ private final boolean mIsResponsiveGrid;
+ private WorkspaceSpecs mWorkspaceSpecs;
+ private CalculatedWorkspaceSpec mResponsiveWidthSpec;
+ private CalculatedWorkspaceSpec mResponsiveHeightSpec;
+
/**
* The maximum amount of left/right workspace padding as a percentage of the screen width.
* To be clear, this means that up to 7% of the screen width can be used as left padding, and
@@ -294,9 +302,8 @@
this.rotationHint = windowBounds.rotationHint;
mInsets.set(windowBounds.insets);
- // TODO(b/241386436):
- // for testing that the flag works only, shouldn't change any launcher behaviour
- isResponsiveGrid = inv.workspaceSpecsId != INVALID_RESOURCE_HANDLE;
+ // TODO(b/241386436): shouldn't change any launcher behaviour
+ mIsResponsiveGrid = inv.workspaceSpecsId != INVALID_RESOURCE_HANDLE;
isScalableGrid = inv.isScalable && !isVerticalBarLayout() && !isMultiWindowMode;
// Determine device posture.
@@ -335,6 +342,14 @@
}
}
+ if (mIsResponsiveGrid) {
+ mWorkspaceSpecs = new WorkspaceSpecs(new ResourceHelper(context, inv.workspaceSpecsId));
+ mResponsiveWidthSpec = mWorkspaceSpecs.getCalculatedWidthSpec(inv.numColumns,
+ availableWidthPx);
+ mResponsiveHeightSpec = mWorkspaceSpecs.getCalculatedHeightSpec(inv.numRows,
+ availableHeightPx);
+ }
+
if (DisplayController.isTransientTaskbar(context)) {
float invTransientIconSizeDp = inv.transientTaskbarIconSize[mTypeIndex];
taskbarIconSize = pxFromDp(invTransientIconSizeDp, mMetrics);
@@ -1582,7 +1597,7 @@
writer.println(prefix + "\taspectRatio:" + aspectRatio);
- writer.println(prefix + "\tisResponsiveGrid:" + isResponsiveGrid);
+ writer.println(prefix + "\tisResponsiveGrid:" + mIsResponsiveGrid);
writer.println(prefix + "\tisScalableGrid:" + isScalableGrid);
writer.println(prefix + "\tinv.numRows: " + inv.numRows);