summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorStephen Bird <sbird@cyngn.com>2015-05-21 11:00:44 -0700
committerStephen Bird <sbird@cyngn.com>2015-06-05 01:07:05 +0000
commit416bb9198c56dec89e8d01cff3824d80094388a5 (patch)
tree9c16c994912ffefebe5f5e63d483b0e37669f1b1 /src
parent288ca2e698c935bfb3024341ca9709eaa8435877 (diff)
downloadandroid_packages_apps_Trebuchet-416bb9198c56dec89e8d01cff3824d80094388a5.tar.gz
android_packages_apps_Trebuchet-416bb9198c56dec89e8d01cff3824d80094388a5.tar.bz2
android_packages_apps_Trebuchet-416bb9198c56dec89e8d01cff3824d80094388a5.zip
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) (cherry picked from commit 641637f927e833cc2b50064d001aafd77de16508)
Diffstat (limited to 'src')
-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 09b77f756..91af5873e 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 167251af8..a618150f0 100644
--- a/src/com/android/launcher3/Launcher.java
+++ b/src/com/android/launcher3/Launcher.java
@@ -472,7 +472,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);
@@ -557,8 +557,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,
@@ -5021,6 +5023,9 @@ public class Launcher extends Activity
PackageInstallerCompat.getInstance(this).onFinishBind();
mModel.recheckRestoredItems(this);
mWorkspace.stripEmptyScreens();
+ if (mWorkspace.isInOverviewMode()) {
+ mWorkspace.resetOverviewMode();
+ }
}
private void sendLoadingCompleteBroadcastIfNecessary() {
@@ -5655,7 +5660,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 a8bcb2c66..3fa5863c9 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 a93fff47b..ccca0d6bb 100644
--- a/src/com/android/launcher3/Workspace.java
+++ b/src/com/android/launcher3/Workspace.java
@@ -2175,6 +2175,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);
}