diff options
author | Raj Yengisetty <rajesh@cyngn.com> | 2014-06-11 11:48:36 -0700 |
---|---|---|
committer | Abhisek Devkota <ciwrl@cyanogenmod.com> | 2014-06-13 22:30:02 +0000 |
commit | 087502d2d3ff3a638e59d9873930a7e0c553ff66 (patch) | |
tree | c4b39cc73293a05ed17e407c0327ca0f3eed171a /src | |
parent | 8816c012cae3581a545781a424a16c13c773536c (diff) | |
download | android_packages_apps_Trebuchet-087502d2d3ff3a638e59d9873930a7e0c553ff66.tar.gz android_packages_apps_Trebuchet-087502d2d3ff3a638e59d9873930a7e0c553ff66.tar.bz2 android_packages_apps_Trebuchet-087502d2d3ff3a638e59d9873930a7e0c553ff66.zip |
Trebuchet : Default workspace improvements
This reverts commit b54b34edd5c87e6d0702793b423b14dc24fb1076
Fix bug for mdpi devices crash loop.
Revert requires overlays to know if GSF installed,
adding a run time check to load default workspaces.
Add in additional overlays per density for new LauncherModel
and LauncherProvider 4.4.3 logic.
Change-Id: I5709182521e80d273e892eb3310abd68acac95ad
Diffstat (limited to 'src')
-rw-r--r-- | src/com/android/launcher3/LauncherModel.java | 151 | ||||
-rw-r--r-- | src/com/android/launcher3/LauncherProvider.java | 68 |
2 files changed, 112 insertions, 107 deletions
diff --git a/src/com/android/launcher3/LauncherModel.java b/src/com/android/launcher3/LauncherModel.java index 9579272d7..9fe0bf3a5 100644 --- a/src/com/android/launcher3/LauncherModel.java +++ b/src/com/android/launcher3/LauncherModel.java @@ -1447,75 +1447,6 @@ public class LauncherModel extends BroadcastReceiver { return false; } - // check & update map of what's occupied; used to discard overlapping/invalid items - public boolean checkItemPlacement(HashMap<Long, ItemInfo[][]> occupied, ItemInfo item, - AtomicBoolean deleteOnItemOverlap) { - LauncherAppState app = LauncherAppState.getInstance(); - DeviceProfile grid = app.getDynamicGrid().getDeviceProfile(); - - long containerIndex = item.screenId; - if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) { - if (occupied.containsKey((long) LauncherSettings.Favorites.CONTAINER_HOTSEAT)) { - if (occupied.get((long) LauncherSettings.Favorites.CONTAINER_HOTSEAT) - [(int) item.screenId][0] != null) { - Log.e(TAG, "Error loading shortcut into hotseat " + item - + " into position (" + item.screenId + ":" + item.cellX + "," - + item.cellY + ") occupied by " - + occupied.get((long) LauncherSettings.Favorites.CONTAINER_HOTSEAT) - [(int) item.screenId][0]); - if (occupied.get((long) LauncherSettings.Favorites.CONTAINER_HOTSEAT) - [(int) item.screenId][0].itemType == LauncherSettings.Favorites.ITEM_TYPE_ALLAPPS) { - deleteOnItemOverlap.set(true); - } - return false; - } else { - ItemInfo[][] hotseatItems = occupied.get( - (long) LauncherSettings.Favorites.CONTAINER_HOTSEAT); - hotseatItems[(int) item.screenId][0] = item; - return true; - } - } else { - ItemInfo[][] items = new ItemInfo[(int) grid.numHotseatIcons][1]; - items[(int) item.screenId][0] = item; - occupied.put((long) LauncherSettings.Favorites.CONTAINER_HOTSEAT, items); - return true; - } - } else if (item.container != LauncherSettings.Favorites.CONTAINER_DESKTOP) { - // Skip further checking if it is not the hotseat or workspace container - return true; - } - - int countX = (int) grid.numColumns; - int countY = (int) grid.numRows; - - if (!occupied.containsKey(item.screenId)) { - ItemInfo[][] items = new ItemInfo[countX + 1][countY + 1]; - 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++) { - 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; - } - } - } - 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; - } - } - - return true; - } - /** * Runnable for the thread that loads the contents of the launcher: * - workspace icons @@ -1778,6 +1709,88 @@ public class LauncherModel extends BroadcastReceiver { } } + private boolean checkItemPlacement(HashMap<Long, ItemInfo[][]> occupied, ItemInfo item, + AtomicBoolean deleteOnInvalidPlacement) { + LauncherAppState app = LauncherAppState.getInstance(); + DeviceProfile grid = app.getDynamicGrid().getDeviceProfile(); + final int countX = (int) grid.numColumns; + final int countY = (int) grid.numRows; + long containerIndex = item.screenId; + if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) { + // Return early if we detect that an item is under the hotseat button + if (mCallbacks == null) { + deleteOnInvalidPlacement.set(true); + Log.e(TAG, "Error loading shortcut into hotseat " + item + + " into position (" + item.screenId + ":" + item.cellX + "," + + item.cellY + ") occupied by all apps"); + return false; + } + final ItemInfo[][] hotseatItems = + occupied.get((long) LauncherSettings.Favorites.CONTAINER_HOTSEAT); + if (item.screenId >= grid.numHotseatIcons) { + Log.e(TAG, "Error loading shortcut " + item + + " into hotseat position " + item.screenId + + ", position out of bounds: (0 to " + (grid.numHotseatIcons - 1) + + ")"); + return false; + } + if (hotseatItems != null) { + if (hotseatItems[(int) item.screenId][0] != null) { + Log.e(TAG, "Error loading shortcut into hotseat " + item + + " into position (" + item.screenId + ":" + item.cellX + "," + + item.cellY + ") occupied by " + + occupied.get(LauncherSettings.Favorites.CONTAINER_HOTSEAT) + [(int) item.screenId][0]); + return false; + } else { + hotseatItems[(int) item.screenId][0] = item; + return true; + } + } else { + final ItemInfo[][] items = new ItemInfo[(int) grid.numHotseatIcons][1]; + items[(int) item.screenId][0] = item; + occupied.put((long) LauncherSettings.Favorites.CONTAINER_HOTSEAT, items); + return true; + } + } else if (item.container != LauncherSettings.Favorites.CONTAINER_DESKTOP) { + // Skip further checking if it is not the hotseat or workspace container + return true; + } + if (!occupied.containsKey(item.screenId)) { + ItemInfo[][] items = new ItemInfo[countX + 1][countY + 1]; + occupied.put(item.screenId, items); + } + 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; + } + // 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 (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; + } + } + } + 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; + } + } + return true; + } + /** Clears all the sBg data structures */ private void clearSBgDataStructures() { synchronized (sBgLock) { diff --git a/src/com/android/launcher3/LauncherProvider.java b/src/com/android/launcher3/LauncherProvider.java index 07f587fb5..9a2cb5070 100644 --- a/src/com/android/launcher3/LauncherProvider.java +++ b/src/com/android/launcher3/LauncherProvider.java @@ -32,6 +32,7 @@ import android.content.Intent; import android.content.OperationApplicationException; import android.content.SharedPreferences; import android.content.pm.ActivityInfo; +import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.content.res.Resources; import android.content.res.TypedArray; @@ -64,10 +65,8 @@ import java.io.File; import java.io.IOException; import java.net.URISyntaxException; import java.util.ArrayList; -import java.util.HashMap; import java.util.HashSet; import java.util.List; -import java.util.concurrent.atomic.AtomicBoolean; public class LauncherProvider extends ContentProvider { private static final String TAG = "Launcher.LauncherProvider"; @@ -304,7 +303,13 @@ public class LauncherProvider extends ContentProvider { if (workspaceResId == 0) { TelephonyManager tm = (TelephonyManager) getContext().getSystemService(Context.TELEPHONY_SERVICE); if (tm.getPhoneType() == TelephonyManager.PHONE_TYPE_NONE) { - workspaceResId = sp.getInt(DEFAULT_WORKSPACE_RESOURCE_ID, R.xml.default_workspace_no_telephony); + if (areGAppsInstalled()) { + workspaceResId = sp.getInt(DEFAULT_WORKSPACE_RESOURCE_ID, + R.xml.default_workspace_no_telephony_gapps); + } else { + workspaceResId = sp.getInt(DEFAULT_WORKSPACE_RESOURCE_ID, + R.xml.default_workspace_no_telephony); + } } else { workspaceResId = sp.getInt(DEFAULT_WORKSPACE_RESOURCE_ID, getDefaultWorkspaceResourceId()); } @@ -323,16 +328,34 @@ public class LauncherProvider extends ContentProvider { } } + private boolean areGAppsInstalled() { + PackageManager pm = getContext().getPackageManager(); + try { + PackageInfo info = pm.getPackageInfo("com.google.android.gsf",PackageManager.GET_META_DATA); + } catch (PackageManager.NameNotFoundException e) { + return false; + } + return true; + } + public void migrateLauncher2Shortcuts() { mOpenHelper.migrateLauncher2Shortcuts(mOpenHelper.getWritableDatabase(), LauncherSettings.Favorites.OLD_CONTENT_URI); } - private static int getDefaultWorkspaceResourceId() { + private int getDefaultWorkspaceResourceId() { if (LauncherAppState.isDisableAllApps()) { - return R.xml.default_workspace_no_all_apps; + if (areGAppsInstalled()){ + return R.xml.default_workspace_no_all_apps_gapps; + } else { + return R.xml.default_workspace_no_all_apps; + } } else { - return R.xml.default_workspace; + if (areGAppsInstalled()){ + return R.xml.default_workspace_gapps; + } else { + return R.xml.default_workspace; + } } } @@ -1224,10 +1247,6 @@ public class LauncherProvider extends ContentProvider { final int depth = parser.getDepth(); - final HashMap<Long, ItemInfo[][]> occupied = new HashMap<Long, ItemInfo[][]>(); - LauncherModel model = LauncherAppState.getInstance().getModel(); - AtomicBoolean deleteItem = new AtomicBoolean(); - int type; while (((type = parser.next()) != XmlPullParser.END_TAG || parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) { @@ -1279,18 +1298,6 @@ public class LauncherProvider extends ContentProvider { values.put(LauncherSettings.Favorites.CELLX, x); values.put(LauncherSettings.Favorites.CELLY, y); - ItemInfo info = new ItemInfo(); - info.container = container; - info.spanX = a.getInt(R.styleable.Favorite_spanX, 1); - info.spanY = a.getInt(R.styleable.Favorite_spanY, 1); - info.cellX = a.getInt(R.styleable.Favorite_x, 0); - info.cellY = a.getInt(R.styleable.Favorite_y, 0); - info.screenId = a.getInt(R.styleable.Favorite_screen, 0); - - if (!model.checkItemPlacement(occupied, info, deleteItem)) { - continue; - } - if (LOGD) { final String title = a.getString(R.styleable.Favorite_title); final String pkg = a.getString(R.styleable.Favorite_packageName); @@ -1377,22 +1384,7 @@ public class LauncherProvider extends ContentProvider { added = false; } } - if (added) { - i++; - } else { - long containerIndex = info.screenId; - if (info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) { - occupied.get((long) LauncherSettings.Favorites.CONTAINER_HOTSEAT) - [(int) info.screenId][0] = null; - } else { - ItemInfo[][] screens = occupied.get(info.screenId); - for (int gridX = info.cellX; gridX < (info.cellX+info.spanX); gridX++) { - for (int gridY = info.cellY; gridY < (info.cellY+info.spanY); gridY++) { - screens[gridX][gridY] = null; - } - } - } - } + if (added) i++; a.recycle(); } } catch (XmlPullParserException e) { |