From dccaadbe194f435d7bc06843650ab7d4fe21551c Mon Sep 17 00:00:00 2001 From: cretin45 Date: Fri, 20 May 2016 10:46:16 -0700 Subject: Move icons to fit within Dynamic grid upon resize. Missed part of this patch during forward port: https://github.com/CyanogenMod/android_packages_apps_Trebuchet/commit/e25ab7bd9525d7a2c67eb8a6d8e88d54940dba58 Issue-id: CYNGNOS-2908 Change-Id: I49fb4e4a1b86d41be263d4f9b84020450f54d3f9 --- src/com/android/launcher3/Launcher.java | 2 +- src/com/android/launcher3/LauncherModel.java | 55 ++++++++++++++++++++++++---- 2 files changed, 49 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java index d4571f9a3..2eb442ba2 100644 --- a/src/com/android/launcher3/Launcher.java +++ b/src/com/android/launcher3/Launcher.java @@ -1947,7 +1947,7 @@ public class Launcher extends Activity if (gridSize != size.getValue() || customValuesChanged) { SettingsProvider.putInt(this, SettingsProvider.SETTINGS_UI_DYNAMIC_GRID_SIZE, size.getValue()); - reloadLauncher(false, true); + reloadLauncher(true, true); } // Must be called after reload and before settings invalidation. diff --git a/src/com/android/launcher3/LauncherModel.java b/src/com/android/launcher3/LauncherModel.java index 5e2a64184..66aa23567 100644 --- a/src/com/android/launcher3/LauncherModel.java +++ b/src/com/android/launcher3/LauncherModel.java @@ -1834,13 +1834,54 @@ public class LauncherModel extends BroadcastReceiver // Check if any workspace icons overlap with each other for (int x = item.cellX; x < (item.cellX+item.spanX); x++) { for (int y = item.cellY; y < (item.cellY+item.spanY); y++) { - if (!shouldResizeAndUpdateDB && screens[x][y] != null) { - Log.e(TAG, "Error loading shortcut " + item - + " into cell (" + containerIndex + "-" + item.screenId + ":" - + x + "," + y - + ") occupied by " - + screens[x][y]); - return false; + if (screens[x][y] != null) { + if (!shouldResizeAndUpdateDB) { + Log.e(TAG, "Error loading shortcut " + item + + " into cell (" + containerIndex + "-" + item.screenId + ":" + + x + "," + y + + ") occupied by " + + screens[x][y]); + return false; + } + ItemInfo occupiedItem = screens[x][y]; + // If an item is overlapping another because one of them + // was moved due to the size of the grid changing, + // move the current item to a free spot past this one. + if (occupiedItem.wasMovedDueToReducedSpace + || item.wasMovedDueToReducedSpace) { + // overlapping icon exists here + // we must find a free space. + boolean freeFound = false; + int nextX = 0; + int nextY = 0; + while (!freeFound) { + if (screens[nextX][nextY] == null) { + item.cellX = nextX; + item.cellY = nextY; + freeFound = true; + } else { + if (nextX + item.spanX == countX) { + if (nextY + item.spanY == countY) { + // If we've reached the bottom of the page and are still + // searching, add a new page to place this item. + item.screenId += 1; + nextY = 0; + nextX = 0; + if (!occupied.containsKey(item.screenId)) { + ItemInfo[][] items = new ItemInfo[countX][countY]; + occupied.put(item.screenId, items); + } + screens = occupied.get(item.screenId); + } else { + nextX = 0; + nextY++; + } + } else { + nextX++; + } + } + } + } } } } -- cgit v1.2.3