Refactoring DeviceProfile
-> Pulling out the parts of device profile which can (and need to be)
initialized and accessed without access to an Activity context,
ie. the invariant bits.
-> The invariant bits are stored in InvariantDeviceProfile which is
initialized statically from LauncherAppState.
-> The DeviceProfile contains the Activity context-dependent bits,
and we will create one of these for each Activity instance, and
this instance is accessed through the Launcher activity.
-> It's possible that we can continue to refactor this such that
all appropriate dimensions can be computed without an Activity
context (by only specifying orientation). This would be an
extension of this CL and allow us to know exactly how launcher
will look in both orientations from any context.
Sets the stage for some improvements around b/19514688
Change-Id: Ia7daccf14d8ca2b9cb340b8780b684769e9f1892
diff --git a/src/com/android/launcher3/LauncherModel.java b/src/com/android/launcher3/LauncherModel.java
index 1b92602..8d321e6 100644
--- a/src/com/android/launcher3/LauncherModel.java
+++ b/src/com/android/launcher3/LauncherModel.java
@@ -422,9 +422,9 @@
private static boolean findNextAvailableIconSpaceInScreen(ArrayList<ItemInfo> occupiedPos,
int[] xy, int spanX, int spanY) {
LauncherAppState app = LauncherAppState.getInstance();
- DeviceProfile grid = app.getDynamicGrid().getDeviceProfile();
- final int xCount = (int) grid.numColumns;
- final int yCount = (int) grid.numRows;
+ InvariantDeviceProfile profile = app.getInvariantDeviceProfile();
+ final int xCount = (int) profile.numColumns;
+ final int yCount = (int) profile.numRows;
boolean[][] occupied = new boolean[xCount][yCount];
if (occupiedPos != null) {
for (ItemInfo r : occupiedPos) {
@@ -1663,9 +1663,9 @@
// check & update map of what's occupied; used to discard overlapping/invalid items
private boolean checkItemPlacement(LongArrayMap<ItemInfo[][]> occupied, ItemInfo item) {
LauncherAppState app = LauncherAppState.getInstance();
- DeviceProfile grid = app.getDynamicGrid().getDeviceProfile();
- final int countX = (int) grid.numColumns;
- final int countY = (int) grid.numRows;
+ InvariantDeviceProfile profile = app.getInvariantDeviceProfile();
+ final int countX = (int) profile.numColumns;
+ final int countY = (int) profile.numRows;
long containerIndex = item.screenId;
if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
@@ -1681,10 +1681,10 @@
final ItemInfo[][] hotseatItems =
occupied.get((long) LauncherSettings.Favorites.CONTAINER_HOTSEAT);
- if (item.screenId >= grid.numHotseatIcons) {
+ if (item.screenId >= profile.numHotseatIcons) {
Log.e(TAG, "Error loading shortcut " + item
+ " into hotseat position " + item.screenId
- + ", position out of bounds: (0 to " + (grid.numHotseatIcons - 1)
+ + ", position out of bounds: (0 to " + (profile.numHotseatIcons - 1)
+ ")");
return false;
}
@@ -1702,7 +1702,7 @@
return true;
}
} else {
- final ItemInfo[][] items = new ItemInfo[(int) grid.numHotseatIcons][1];
+ final ItemInfo[][] items = new ItemInfo[(int) profile.numHotseatIcons][1];
items[(int) item.screenId][0] = item;
occupied.put((long) LauncherSettings.Favorites.CONTAINER_HOTSEAT, items);
return true;
@@ -1776,9 +1776,9 @@
new IntentFilter(StartupReceiver.SYSTEM_READY)) != null;
LauncherAppState app = LauncherAppState.getInstance();
- DeviceProfile grid = app.getDynamicGrid().getDeviceProfile();
- int countX = (int) grid.numColumns;
- int countY = (int) grid.numRows;
+ InvariantDeviceProfile profile = app.getInvariantDeviceProfile();
+ int countX = (int) profile.numColumns;
+ int countY = (int) profile.numRows;
if ((mFlags & LOADER_FLAG_CLEAR_WORKSPACE) != 0) {
Launcher.addDumpLog(TAG, "loadWorkspace: resetting launcher database", true);
@@ -2190,13 +2190,6 @@
appWidgetInfo = new LauncherAppWidgetInfo(appWidgetId,
provider.provider);
- if (!customWidget) {
- int[] minSpan =
- Launcher.getMinSpanForWidget(context, provider);
- appWidgetInfo.minSpanX = minSpan[0];
- appWidgetInfo.minSpanY = minSpan[1];
- }
-
int status = restoreStatus;
if (!wasProviderReady) {
// If provider was not previously ready, update the
@@ -2244,12 +2237,6 @@
appWidgetInfo.spanX = c.getInt(spanXIndex);
appWidgetInfo.spanY = c.getInt(spanYIndex);
- if (!customWidget) {
- int[] minSpan = Launcher.getMinSpanForWidget(context, provider);
- appWidgetInfo.minSpanX = minSpan[0];
- appWidgetInfo.minSpanY = minSpan[1];
- }
-
container = c.getInt(containerIndex);
if (container != LauncherSettings.Favorites.CONTAINER_DESKTOP &&
container != LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
@@ -2512,13 +2499,13 @@
* right) */
private void sortWorkspaceItemsSpatially(ArrayList<ItemInfo> workspaceItems) {
final LauncherAppState app = LauncherAppState.getInstance();
- final DeviceProfile grid = app.getDynamicGrid().getDeviceProfile();
+ final InvariantDeviceProfile profile = app.getInvariantDeviceProfile();
// XXX: review this
Collections.sort(workspaceItems, new Comparator<ItemInfo>() {
@Override
public int compare(ItemInfo lhs, ItemInfo rhs) {
- int cellCountX = (int) grid.numColumns;
- int cellCountY = (int) grid.numRows;
+ int cellCountX = (int) profile.numColumns;
+ int cellCountY = (int) profile.numRows;
int screenOffset = cellCountX * cellCountY;
int containerOffset = screenOffset * (Launcher.SCREEN_COUNT + 1); // +1 hotseat
long lr = (lhs.container * containerOffset + lhs.screenId * screenOffset +