summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephen Bird <sbird@cyngn.com>2015-05-21 18:00:44 (GMT)
committerMatt Garnes <matt@cyngn.com>2015-06-05 00:53:08 (GMT)
commit641637f927e833cc2b50064d001aafd77de16508 (patch)
treeb233fbd01b7a8d5a11bd4ad6dbd6dc8703e57229
parent3e0d08d7ff471efc3ffd1b73135243fc5d0afc09 (diff)
downloadandroid_packages_apps_Trebuchet-641637f927e833cc2b50064d001aafd77de16508.zip
android_packages_apps_Trebuchet-641637f927e833cc2b50064d001aafd77de16508.tar.gz
android_packages_apps_Trebuchet-641637f927e833cc2b50064d001aafd77de16508.tar.bz2
Move icons to fit within Dynamic grid upon resize.
If the dynamic grid is made smaller, currently icons will simply be hidden from view. Instead, create extra screens and squeeze the icons in so that they will all be visible upon resize. In some cases, icons can end up creating screens when it's not necessary we should revisit this at a later time and look into making these icons show up in a more expected place. Change-Id: I9a46f1ac45c1a04e252ed8943afcfe952df1392d (cherry picked from commit e25ab7bd9525d7a2c67eb8a6d8e88d54940dba58)
-rw-r--r--src/com/android/launcher3/ItemInfo.java6
-rw-r--r--src/com/android/launcher3/Launcher.java13
-rw-r--r--src/com/android/launcher3/LauncherModel.java151
-rw-r--r--src/com/android/launcher3/Workspace.java7
4 files changed, 131 insertions, 46 deletions
diff --git a/src/com/android/launcher3/ItemInfo.java b/src/com/android/launcher3/ItemInfo.java
index 09b77f7..91af587 100644
--- a/src/com/android/launcher3/ItemInfo.java
+++ b/src/com/android/launcher3/ItemInfo.java
@@ -113,6 +113,12 @@ public class ItemInfo {
CharSequence contentDescription;
/**
+ * Indicates that this item has had it's position changed
+ * because the grid size was made smaller and it could no longer fit.
+ */
+ public boolean wasMovedDueToReducedSpace = false;
+
+ /**
* The position of the item in a drag-and-drop operation.
*/
int[] dropPos = null;
diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java
index b7aec45..29a2934 100644
--- a/src/com/android/launcher3/Launcher.java
+++ b/src/com/android/launcher3/Launcher.java
@@ -481,7 +481,7 @@ public class Launcher extends Activity
super.onCreate(savedInstanceState);
- initializeDynamicGrid();
+ initializeDynamicGrid(false);
mHideIconLabels = SettingsProvider.getBoolean(this,
SettingsProvider.SETTINGS_UI_HOMESCREEN_HIDE_ICON_LABELS,
R.bool.preferences_interface_homescreen_hide_icon_labels_default);
@@ -566,8 +566,10 @@ public class Launcher extends Activity
@Override
public void onLauncherProviderChange() { }
- private void initializeDynamicGrid() {
- LauncherAppState.setApplicationContext(getApplicationContext());
+ private void initializeDynamicGrid(boolean updateGrid) {
+ if (!updateGrid) {
+ LauncherAppState.setApplicationContext(getApplicationContext());
+ }
LauncherAppState app = LauncherAppState.getInstance();
mHideIconLabels = SettingsProvider.getBoolean(this,
@@ -5167,6 +5169,9 @@ public class Launcher extends Activity
PackageInstallerCompat.getInstance(this).onFinishBind();
mModel.recheckRestoredItems(this);
mWorkspace.stripEmptyScreens();
+ if (mWorkspace.isInOverviewMode()) {
+ mWorkspace.resetOverviewMode();
+ }
}
private void sendLoadingCompleteBroadcastIfNecessary() {
@@ -5814,7 +5819,7 @@ public class Launcher extends Activity
public void updateDynamicGrid(int page) {
mSearchDropTargetBar.setupQSB(Launcher.this);
- initializeDynamicGrid();
+ initializeDynamicGrid(true);
mGrid.layout(Launcher.this);
diff --git a/src/com/android/launcher3/LauncherModel.java b/src/com/android/launcher3/LauncherModel.java
index a8bcb2c..3fa5863 100644
--- a/src/com/android/launcher3/LauncherModel.java
+++ b/src/com/android/launcher3/LauncherModel.java
@@ -30,7 +30,6 @@ import android.content.Intent;
import android.content.Intent.ShortcutIconResource;
import android.content.IntentFilter;
import android.content.SharedPreferences;
-import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.ProviderInfo;
import android.content.pm.ResolveInfo;
@@ -48,8 +47,8 @@ import android.os.Process;
import android.os.RemoteException;
import android.os.SystemClock;
import android.provider.BaseColumns;
-import android.text.TextUtils;
import android.provider.Settings;
+import android.text.TextUtils;
import android.util.Log;
import android.util.Pair;
@@ -60,7 +59,6 @@ import com.android.launcher3.compat.PackageInstallerCompat;
import com.android.launcher3.compat.PackageInstallerCompat.PackageInstallInfo;
import com.android.launcher3.compat.UserHandleCompat;
import com.android.launcher3.compat.UserManagerCompat;
-
import com.android.launcher3.settings.SettingsProvider;
import java.lang.ref.WeakReference;
@@ -1511,11 +1509,7 @@ public class LauncherModel extends BroadcastReceiver
}
public void stopLoader() {
- synchronized (mLock) {
- if (mLoaderTask != null) {
- mLoaderTask.stopLocked();
- }
- }
+ resetLoadedState(true, true);
}
/** Loads the workspace screens db into a map of Rank -> ScreenId */
@@ -1883,38 +1877,114 @@ public class LauncherModel extends BroadcastReceiver
return true;
}
- if (!occupied.containsKey(item.screenId)) {
- ItemInfo[][] items = new ItemInfo[countX + 1][countY + 1];
- occupied.put(item.screenId, items);
+ // If the current item's position lies outside of the bounds
+ // of the current grid size, attempt to place it in the next
+ // available position.
+ if (item.cellX < 0 || item.cellY < 0 || item.cellX + item.spanX > countX
+ || item.cellY + item.spanY > countY) {
+ if (item.itemType != LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET) {
+ // Place the item at 0 0 of screen 0
+ // if items overlap here, they will be moved later on
+ item.cellX = 0;
+ item.cellY = 0;
+ item.screenId = 0;
+ item.wasMovedDueToReducedSpace = true;
+ item.requiresDbUpdate = true;
+ } else {
+ // see if widget can be shrunk to fit a screen, if not, just remove it
+ if (item.minSpanX > countX || item.minSpanY > countY) {
+ deleteOnInvalidPlacement.set(true);
+ return false;
+ }
+ // if the widget is larger than the grid, shrink it down
+ if (item.cellX + item.spanX > countX) {
+ item.cellX = 0;
+ item.spanY = (item.spanY / 2) > 0 ? item.spanY / 2 : 1;
+ item.spanX = item.minSpanX;
+ item.requiresDbUpdate = true;
+ item.wasMovedDueToReducedSpace = true;
+ }
+ if (item.cellY + item.spanY > countY) {
+ item.cellY = 0;
+ item.spanY = countY;
+ item.requiresDbUpdate = true;
+ item.wasMovedDueToReducedSpace = true;
+ }
+ if (item.cellY + item.spanY == countY && item.cellX + item.spanX == countX) {
+ // if the widget is the size of the grid, make a screen all it's own.
+ item.screenId = sBgWorkspaceScreens.size() + 1;
+ }
+ }
+ } else {
+ item.wasMovedDueToReducedSpace = false;
+ item.requiresDbUpdate = true;
}
- final ItemInfo[][] screens = occupied.get(item.screenId);
- if (item.container == LauncherSettings.Favorites.CONTAINER_DESKTOP &&
- item.cellX < 0 || item.cellY < 0 ||
- item.cellX + item.spanX > countX || item.cellY + item.spanY > countY) {
- Log.e(TAG, "Error loading shortcut " + item
- + " into cell (" + containerIndex + "-" + item.screenId + ":"
- + item.cellX + "," + item.cellY
- + ") out of screen bounds ( " + countX + "x" + countY + ")");
- return false;
+ if (!occupied.containsKey(item.screenId)) {
+ ItemInfo[][] items = new ItemInfo[countX][countY];
+ occupied.put(item.screenId, items);
}
+ ItemInfo[][] screens = occupied.get(item.screenId);
// 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++) {
+ for (int x = item.cellX; x < (item.cellX + item.spanX); x++) {
+ for (int y = item.cellY; y < (item.cellY + item.spanY); y++) {
if (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;
+ 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++;
+ }
+ }
+ }
+ }
}
}
}
- for (int x = item.cellX; x < (item.cellX+item.spanX); x++) {
- for (int y = item.cellY; y < (item.cellY+item.spanY); y++) {
+
+ for (int x = item.cellX; x < (item.cellX + item.spanX); x++) {
+ for (int y = item.cellY; y < (item.cellY + item.spanY); y++) {
screens[x][y] = item;
+ if (item.itemType == LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET) {
+ // fill up the entire grid where the widget technically is
+ for (int spanX = x; spanX < item.spanX; spanX++) {
+ screens[spanX][y] = item;
+ for (int spanY = y; spanY < item.spanX; spanY++) {
+ screens[spanX][spanY] = item;
+ }
+ }
+ }
}
}
@@ -2489,6 +2559,10 @@ public class LauncherModel extends BroadcastReceiver
}
LauncherAppState.getLauncherProvider().updateMaxItemId(maxItemId);
} else {
+
+
+
+
TreeMap<Integer, Long> orderedScreens = loadWorkspaceScreensDb(mContext);
for (Integer i : orderedScreens.keySet()) {
sBgWorkspaceScreens.add(orderedScreens.get(i));
@@ -2497,25 +2571,18 @@ public class LauncherModel extends BroadcastReceiver
Launcher.addDumpLog(TAG, "11683562 - sBgWorkspaceScreens: " +
TextUtils.join(", ", sBgWorkspaceScreens), true);
- // Remove any empty screens
- ArrayList<Long> unusedScreens = new ArrayList<Long>(sBgWorkspaceScreens);
+ // Make sure that we have all the screens we will need that may have been added
for (ItemInfo item: sBgItemsIdMap.values()) {
long screenId = item.screenId;
if (item.container == LauncherSettings.Favorites.CONTAINER_DESKTOP &&
- unusedScreens.contains(screenId)) {
- unusedScreens.remove(screenId);
+ !sBgWorkspaceScreens.contains(screenId)) {
+ sBgWorkspaceScreens.add(screenId);
}
}
- // If there are any empty screens remove them, and update.
- if (unusedScreens.size() != 0) {
- // Log to disk
- Launcher.addDumpLog(TAG, "11683562 - unusedScreens (to be removed): " +
- TextUtils.join(", ", unusedScreens), true);
- sBgWorkspaceScreens.removeAll(unusedScreens);
- updateWorkspaceScreenOrder(context, sBgWorkspaceScreens);
- }
+
+ updateWorkspaceScreenOrder(context, sBgWorkspaceScreens);
}
if (DEBUG_LOADERS) {
diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java
index 811c4b2..a8c7bcf 100644
--- a/src/com/android/launcher3/Workspace.java
+++ b/src/com/android/launcher3/Workspace.java
@@ -2173,6 +2173,13 @@ public class Workspace extends SmoothPagedView
return true;
}
+ public boolean resetOverviewMode() {
+ //reset overviewmode without any animations
+ exitOverviewMode(-1, false);
+ enableOverviewMode(true, -1, false);
+ return true;
+ }
+
public void exitOverviewMode(boolean animated) {
exitOverviewMode(-1, animated);
}