summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcretin45 <cretin45@gmail.com>2016-05-20 17:46:16 (GMT)
committerEd Carrigan <cretin45@gmail.com>2016-05-20 18:55:55 (GMT)
commitbd59e144cb501808ec8afd0c8d43deab70e7933d (patch)
tree0749dca57dbc60ee7d04161853d66d3bf896b369
parent3c4b2628b72d150ebee3c69b5f08343f35d51483 (diff)
downloadandroid_packages_apps_Trebuchet-bd59e144cb501808ec8afd0c8d43deab70e7933d.zip
android_packages_apps_Trebuchet-bd59e144cb501808ec8afd0c8d43deab70e7933d.tar.gz
android_packages_apps_Trebuchet-bd59e144cb501808ec8afd0c8d43deab70e7933d.tar.bz2
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 (cherry picked from commit dccaadbe194f435d7bc06843650ab7d4fe21551c)
-rw-r--r--src/com/android/launcher3/Launcher.java2
-rw-r--r--src/com/android/launcher3/LauncherModel.java55
2 files changed, 49 insertions, 8 deletions
diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java
index d4571f9..2eb442b 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 5e2a641..66aa235 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++;
+ }
+ }
+ }
+ }
}
}
}