summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/com/android/launcher2/AllAppsList.java4
-rw-r--r--src/com/android/launcher2/ApplicationInfo.java12
-rw-r--r--src/com/android/launcher2/AppsCustomizePagedView.java7
-rw-r--r--src/com/android/launcher2/FolderInfo.java3
-rw-r--r--src/com/android/launcher2/InstallWidgetReceiver.java2
-rw-r--r--src/com/android/launcher2/ItemInfo.java11
-rw-r--r--src/com/android/launcher2/Launcher.java13
-rw-r--r--src/com/android/launcher2/LauncherAppWidgetInfo.java6
-rw-r--r--src/com/android/launcher2/LauncherModel.java292
-rw-r--r--src/com/android/launcher2/PendingAddItemInfo.java8
-rw-r--r--src/com/android/launcher2/ShortcutInfo.java12
-rw-r--r--src/com/android/launcher2/Workspace.java4
12 files changed, 190 insertions, 184 deletions
diff --git a/src/com/android/launcher2/AllAppsList.java b/src/com/android/launcher2/AllAppsList.java
index 7c107a79a..051b0bd1d 100644
--- a/src/com/android/launcher2/AllAppsList.java
+++ b/src/com/android/launcher2/AllAppsList.java
@@ -91,7 +91,7 @@ class AllAppsList {
if (matches.size() > 0) {
for (ResolveInfo info : matches) {
- add(new ApplicationInfo(context.getPackageManager(), info, mIconCache, null, "15"));
+ add(new ApplicationInfo(context.getPackageManager(), info, mIconCache, null));
}
}
}
@@ -142,7 +142,7 @@ class AllAppsList {
info.activityInfo.applicationInfo.packageName,
info.activityInfo.name);
if (applicationInfo == null) {
- add(new ApplicationInfo(context.getPackageManager(), info, mIconCache, null, "16"));
+ add(new ApplicationInfo(context.getPackageManager(), info, mIconCache, null));
} else {
mIconCache.remove(applicationInfo.componentName);
mIconCache.getTitleAndIcon(applicationInfo, info, null);
diff --git a/src/com/android/launcher2/ApplicationInfo.java b/src/com/android/launcher2/ApplicationInfo.java
index bbca66445..1fc1d1f55 100644
--- a/src/com/android/launcher2/ApplicationInfo.java
+++ b/src/com/android/launcher2/ApplicationInfo.java
@@ -60,8 +60,7 @@ class ApplicationInfo extends ItemInfo {
int flags = 0;
- ApplicationInfo(String whereCreated) {
- super(whereCreated);
+ ApplicationInfo() {
itemType = LauncherSettings.BaseLauncherColumns.ITEM_TYPE_SHORTCUT;
}
@@ -69,8 +68,7 @@ class ApplicationInfo extends ItemInfo {
* Must not hold the Context.
*/
public ApplicationInfo(PackageManager pm, ResolveInfo info, IconCache iconCache,
- HashMap<Object, CharSequence> labelCache, String whereCreated) {
- super(whereCreated);
+ HashMap<Object, CharSequence> labelCache) {
final String packageName = info.activityInfo.applicationInfo.packageName;
this.componentName = new ComponentName(packageName, info.activityInfo.name);
@@ -95,8 +93,8 @@ class ApplicationInfo extends ItemInfo {
iconCache.getTitleAndIcon(this, info, labelCache);
}
- public ApplicationInfo(ApplicationInfo info, String whereCreated) {
- super(info, whereCreated);
+ public ApplicationInfo(ApplicationInfo info) {
+ super(info);
componentName = info.componentName;
title = info.title.toString();
intent = new Intent(info.intent);
@@ -135,6 +133,6 @@ class ApplicationInfo extends ItemInfo {
}
public ShortcutInfo makeShortcut() {
- return new ShortcutInfo(this, "18");
+ return new ShortcutInfo(this);
}
}
diff --git a/src/com/android/launcher2/AppsCustomizePagedView.java b/src/com/android/launcher2/AppsCustomizePagedView.java
index 8d49b4ccc..a58341527 100644
--- a/src/com/android/launcher2/AppsCustomizePagedView.java
+++ b/src/com/android/launcher2/AppsCustomizePagedView.java
@@ -1020,8 +1020,9 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen
if (rawInfo instanceof AppWidgetProviderInfo) {
// Fill in the widget information
AppWidgetProviderInfo info = (AppWidgetProviderInfo) rawInfo;
- createItemInfo = new PendingAddWidgetInfo(info, null, null, "13");
- int[] cellSpans = mLauncher.getSpanForWidget(info, null);
+ createItemInfo = new PendingAddWidgetInfo(info, null, null);
+ int[] cellSpans = CellLayout.rectToCell(getResources(),
+ info.minWidth, info.minHeight, null);
FastBitmapDrawable preview = new FastBitmapDrawable(data.generatedImages.get(i));
widget.applyFromAppWidgetProviderInfo(info, preview, -1, cellSpans,
mHolographicOutlineHelper);
@@ -1029,7 +1030,7 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen
} else if (rawInfo instanceof ResolveInfo) {
// Fill in the shortcuts information
ResolveInfo info = (ResolveInfo) rawInfo;
- createItemInfo = new PendingAddItemInfo("14");
+ createItemInfo = new PendingAddItemInfo();
createItemInfo.itemType = LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT;
createItemInfo.componentName = new ComponentName(info.activityInfo.packageName,
info.activityInfo.name);
diff --git a/src/com/android/launcher2/FolderInfo.java b/src/com/android/launcher2/FolderInfo.java
index 0f8b9e06f..3ae31d278 100644
--- a/src/com/android/launcher2/FolderInfo.java
+++ b/src/com/android/launcher2/FolderInfo.java
@@ -42,8 +42,7 @@ class FolderInfo extends ItemInfo {
ArrayList<FolderListener> listeners = new ArrayList<FolderListener>();
- FolderInfo(String whereCreated) {
- super(whereCreated);
+ FolderInfo() {
itemType = LauncherSettings.Favorites.ITEM_TYPE_FOLDER;
}
diff --git a/src/com/android/launcher2/InstallWidgetReceiver.java b/src/com/android/launcher2/InstallWidgetReceiver.java
index 1b54e908c..6b3763ce0 100644
--- a/src/com/android/launcher2/InstallWidgetReceiver.java
+++ b/src/com/android/launcher2/InstallWidgetReceiver.java
@@ -187,7 +187,7 @@ public class InstallWidgetReceiver {
final AppWidgetProviderInfo widgetInfo = mActivities.get(which).widgetInfo;
final PendingAddWidgetInfo createInfo = new PendingAddWidgetInfo(widgetInfo, mMimeType,
- mClipData, "4");
+ mClipData);
mLauncher.addAppWidgetFromDrop(createInfo, LauncherSettings.Favorites.CONTAINER_DESKTOP,
mTargetLayoutScreen, null, mTargetLayoutPos);
}
diff --git a/src/com/android/launcher2/ItemInfo.java b/src/com/android/launcher2/ItemInfo.java
index 5c05f163f..8d4662495 100644
--- a/src/com/android/launcher2/ItemInfo.java
+++ b/src/com/android/launcher2/ItemInfo.java
@@ -86,16 +86,10 @@ class ItemInfo {
*/
int[] dropPos = null;
- /*
- * A tag to know where this item was created
- */
- String whereCreated;
-
- ItemInfo(String whereCreated) {
- this.whereCreated = whereCreated;
+ ItemInfo() {
}
- ItemInfo(ItemInfo info, String whereCreated) {
+ ItemInfo(ItemInfo info) {
id = info.id;
cellX = info.cellX;
cellY = info.cellY;
@@ -104,7 +98,6 @@ class ItemInfo {
screen = info.screen;
itemType = info.itemType;
container = info.container;
- this.whereCreated = whereCreated;
}
/**
diff --git a/src/com/android/launcher2/Launcher.java b/src/com/android/launcher2/Launcher.java
index 637d95607..6ff46f85e 100644
--- a/src/com/android/launcher2/Launcher.java
+++ b/src/com/android/launcher2/Launcher.java
@@ -177,7 +177,7 @@ public final class Launcher extends Activity
private AppWidgetManager mAppWidgetManager;
private LauncherAppWidgetHost mAppWidgetHost;
- private ItemInfo mPendingAddInfo = new ItemInfo("1");
+ private ItemInfo mPendingAddInfo = new ItemInfo();
private int[] mTmpAddItemCellCoordinates = new int[2];
private FolderInfo mFolderInfo;
@@ -946,7 +946,7 @@ public final class Launcher extends Activity
}
// Build Launcher-specific widget info and save to database
- LauncherAppWidgetInfo launcherInfo = new LauncherAppWidgetInfo(appWidgetId, "2");
+ LauncherAppWidgetInfo launcherInfo = new LauncherAppWidgetInfo(appWidgetId);
launcherInfo.spanX = spanXY[0];
launcherInfo.spanY = spanXY[1];
@@ -1490,7 +1490,7 @@ public final class Launcher extends Activity
FolderIcon addFolder(CellLayout layout, long container, final int screen, int cellX,
int cellY) {
- final FolderInfo folderInfo = new FolderInfo("3");
+ final FolderInfo folderInfo = new FolderInfo();
folderInfo.title = getText(R.string.folder_name);
// Update the model
@@ -1602,7 +1602,9 @@ public final class Launcher extends Activity
* leak the previous Home screen on orientation change.
*/
private void unbindWorkspaceAndHotseatItems() {
- LauncherModel.unbindWorkspaceItems();
+ if (mModel != null) {
+ mModel.unbindWorkspaceItems();
+ }
}
/**
@@ -2754,9 +2756,6 @@ public final class Launcher extends Activity
if (mHotseat != null) {
mHotseat.resetLayout();
}
-
- // This wasn't being called before which resulted in a leak of AppWidgetHostViews
- unbindWorkspaceAndHotseatItems();
}
/**
diff --git a/src/com/android/launcher2/LauncherAppWidgetInfo.java b/src/com/android/launcher2/LauncherAppWidgetInfo.java
index 69eae178e..844abb519 100644
--- a/src/com/android/launcher2/LauncherAppWidgetInfo.java
+++ b/src/com/android/launcher2/LauncherAppWidgetInfo.java
@@ -51,8 +51,7 @@ class LauncherAppWidgetInfo extends ItemInfo {
/**
* Constructor for use with AppWidgets that haven't been instantiated yet.
*/
- LauncherAppWidgetInfo(ComponentName providerName, String whereCreated) {
- super(whereCreated);
+ LauncherAppWidgetInfo(ComponentName providerName) {
itemType = LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET;
this.providerName = providerName;
@@ -62,8 +61,7 @@ class LauncherAppWidgetInfo extends ItemInfo {
spanY = -1;
}
- LauncherAppWidgetInfo(int appWidgetId, String whereCreated) {
- super(whereCreated);
+ LauncherAppWidgetInfo(int appWidgetId) {
itemType = LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET;
this.appWidgetId = appWidgetId;
}
diff --git a/src/com/android/launcher2/LauncherModel.java b/src/com/android/launcher2/LauncherModel.java
index 239970e84..c7bd670da 100644
--- a/src/com/android/launcher2/LauncherModel.java
+++ b/src/com/android/launcher2/LauncherModel.java
@@ -155,10 +155,31 @@ public class LauncherModel extends BroadcastReceiver {
return Bitmap.createBitmap(mDefaultIcon);
}
- public static void unbindWorkspaceItems() {
- for (ItemInfo item: sWorkspaceItems) {
- item.unbind();
- }
+ public void unbindWorkspaceItems() {
+ sWorker.post(new Runnable() {
+ @Override
+ public void run() {
+ unbindWorkspaceItemsOnMainThread();
+ }
+ });
+ }
+
+ /** Unbinds all the sWorkspaceItems on the main thread, and return a copy of sWorkspaceItems
+ * that is save to reference from the main thread. */
+ private ArrayList<ItemInfo> unbindWorkspaceItemsOnMainThread() {
+ // Ensure that we don't use the same workspace items data structure on the main thread
+ // by making a copy of workspace items first.
+ final ArrayList<ItemInfo> workspaceItems = new ArrayList<ItemInfo>(sWorkspaceItems);
+ mHandler.post(new Runnable() {
+ @Override
+ public void run() {
+ for (ItemInfo item : workspaceItems) {
+ item.unbind();
+ }
+ }
+ });
+
+ return workspaceItems;
}
/**
@@ -176,6 +197,46 @@ public class LauncherModel extends BroadcastReceiver {
}
}
+ static void updateItemInDatabaseHelper(Context context, final ContentValues values,
+ final ItemInfo item, final String callingFunction) {
+ final long itemId = item.id;
+ final Uri uri = LauncherSettings.Favorites.getContentUri(itemId, false);
+ final ContentResolver cr = context.getContentResolver();
+
+ Runnable r = new Runnable() {
+ public void run() {
+ cr.update(uri, values, null, null);
+
+ ItemInfo modelItem = sItemsIdMap.get(itemId);
+ if (item != modelItem) {
+ // the modelItem needs to match up perfectly with item if our model is to be
+ // consistent with the database-- for now, just require modelItem == item
+ String msg = "item: " + ((item != null) ? item.toString() : "null") +
+ "modelItem: " + ((modelItem != null) ? modelItem.toString() : "null") +
+ "Error: ItemInfo passed to " + callingFunction + " doesn't match original";
+ throw new RuntimeException(msg);
+ }
+
+ // Items are added/removed from the corresponding FolderInfo elsewhere, such
+ // as in Workspace.onDrop. Here, we just add/remove them from the list of items
+ // that are on the desktop, as appropriate
+ if (modelItem.container == LauncherSettings.Favorites.CONTAINER_DESKTOP ||
+ modelItem.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
+ if (!sWorkspaceItems.contains(modelItem)) {
+ sWorkspaceItems.add(modelItem);
+ }
+ } else {
+ sWorkspaceItems.remove(modelItem);
+ }
+ }
+ };
+
+ if (sWorkerThread.getThreadId() == Process.myTid()) {
+ r.run();
+ } else {
+ sWorker.post(r);
+ }
+ }
/**
* Move an item in the DB to a new <container, screen, cellX, cellY>
*/
@@ -184,6 +245,7 @@ public class LauncherModel extends BroadcastReceiver {
item.container = container;
item.cellX = cellX;
item.cellY = cellY;
+
// We store hotseat items in canonical form which is this orientation invariant position
// in the hotseat
if (context instanceof Launcher && screen < 0 &&
@@ -193,43 +255,13 @@ public class LauncherModel extends BroadcastReceiver {
item.screen = screen;
}
- final Uri uri = LauncherSettings.Favorites.getContentUri(item.id, false);
final ContentValues values = new ContentValues();
- final ContentResolver cr = context.getContentResolver();
-
values.put(LauncherSettings.Favorites.CONTAINER, item.container);
values.put(LauncherSettings.Favorites.CELLX, item.cellX);
values.put(LauncherSettings.Favorites.CELLY, item.cellY);
values.put(LauncherSettings.Favorites.SCREEN, item.screen);
- sWorker.post(new Runnable() {
- public void run() {
- cr.update(uri, values, null, null);
- ItemInfo modelItem = sItemsIdMap.get(item.id);
- if (item != modelItem) {
- // the modelItem needs to match up perfectly with item if our model is to be
- // consistent with the database-- for now, just require modelItem == item
- String msg = "item: " + ((item != null) ? item.toString() : "null") +
- " modelItem: " + ((modelItem != null) ? modelItem.toString() : "null") +
- " creation tag of item: " + ((item != null) ? item.whereCreated : "null") +
- " creation tag of modelItem: " + ((modelItem != null) ? modelItem.whereCreated : "null") +
- " Error: ItemInfo passed to moveItemInDatabase doesn't match original";
- throw new RuntimeException(msg);
- }
-
- // Items are added/removed from the corresponding FolderInfo elsewhere, such
- // as in Workspace.onDrop. Here, we just add/remove them from the list of items
- // that are on the desktop, as appropriate
- if (modelItem.container == LauncherSettings.Favorites.CONTAINER_DESKTOP ||
- modelItem.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
- if (!sWorkspaceItems.contains(modelItem)) {
- sWorkspaceItems.add(modelItem);
- }
- } else {
- sWorkspaceItems.remove(modelItem);
- }
- }
- });
+ updateItemInDatabaseHelper(context, values, item, "moveItemInDatabase");
}
/**
@@ -242,32 +274,24 @@ public class LauncherModel extends BroadcastReceiver {
item.cellX = cellX;
item.cellY = cellY;
- final Uri uri = LauncherSettings.Favorites.getContentUri(item.id, false);
final ContentValues values = new ContentValues();
- final ContentResolver cr = context.getContentResolver();
-
values.put(LauncherSettings.Favorites.CONTAINER, item.container);
values.put(LauncherSettings.Favorites.SPANX, spanX);
values.put(LauncherSettings.Favorites.SPANY, spanY);
values.put(LauncherSettings.Favorites.CELLX, cellX);
values.put(LauncherSettings.Favorites.CELLY, cellY);
+ updateItemInDatabaseHelper(context, values, item, "resizeItemInDatabase");
+ }
- sWorker.post(new Runnable() {
- public void run() {
- cr.update(uri, values, null, null);
- ItemInfo modelItem = sItemsIdMap.get(item.id);
- if (item != modelItem) {
- // the modelItem needs to match up perfectly with item if our model is to be
- // consistent with the database-- for now, just require modelItem == item
- String msg = "item: " + ((item != null) ? item.toString() : "null") +
- " modelItem: " + ((modelItem != null) ? modelItem.toString() : "null") +
- " creation tag of item: " + ((item != null) ? item.whereCreated : "null") +
- " creation tag of modelItem: " + ((modelItem != null) ? modelItem.whereCreated : "null") +
- " Error: ItemInfo passed to resizeItemInDatabase doesn't match original";
- throw new RuntimeException(msg);
- }
- }
- });
+
+ /**
+ * Update an item to the database in a specified container.
+ */
+ static void updateItemInDatabase(Context context, final ItemInfo item) {
+ final ContentValues values = new ContentValues();
+ item.onAddToDatabase(values);
+ item.updateValuesWithCoordinates(values, item.cellX, item.cellY);
+ updateItemInDatabaseHelper(context, values, item, "updateItemInDatabase");
}
/**
@@ -310,7 +334,7 @@ public class LauncherModel extends BroadcastReceiver {
try {
while (c.moveToNext()) {
- ItemInfo item = new ItemInfo("17");
+ ItemInfo item = new ItemInfo();
item.cellX = c.getInt(cellXIndex);
item.cellY = c.getInt(cellYIndex);
item.spanX = c.getInt(spanXIndex);
@@ -399,7 +423,7 @@ public class LauncherModel extends BroadcastReceiver {
values.put(LauncherSettings.Favorites._ID, item.id);
item.updateValuesWithCoordinates(values, item.cellX, item.cellY);
- sWorker.post(new Runnable() {
+ Runnable r = new Runnable() {
public void run() {
cr.insert(notify ? LauncherSettings.Favorites.CONTENT_URI :
LauncherSettings.Favorites.CONTENT_URI_NO_NOTIFICATION, values);
@@ -426,7 +450,13 @@ public class LauncherModel extends BroadcastReceiver {
break;
}
}
- });
+ };
+
+ if (sWorkerThread.getThreadId() == Process.myTid()) {
+ r.run();
+ } else {
+ sWorker.post(r);
+ }
}
/**
@@ -456,30 +486,31 @@ public class LauncherModel extends BroadcastReceiver {
}
/**
- * Update an item to the database in a specified container.
+ * Removes the specified item from the database
+ * @param context
+ * @param item
*/
- static void updateItemInDatabase(Context context, final ItemInfo item) {
- final ContentValues values = new ContentValues();
+ static void deleteItemFromDatabase(Context context, final ItemInfo item) {
final ContentResolver cr = context.getContentResolver();
-
- item.onAddToDatabase(values);
- item.updateValuesWithCoordinates(values, item.cellX, item.cellY);
-
+ final Uri uriToDelete = LauncherSettings.Favorites.getContentUri(item.id, false);
Runnable r = new Runnable() {
public void run() {
- cr.update(LauncherSettings.Favorites.getContentUri(item.id, false),
- values, null, null);
- final ItemInfo modelItem = sItemsIdMap.get(item.id);
- if (item != modelItem) {
- // the modelItem needs to match up perfectly with item if our model is to be
- // consistent with the database-- for now, just require modelItem == item
- String msg = "item: " + ((item != null) ? item.toString() : "null") +
- " modelItem: " + ((modelItem != null) ? modelItem.toString() : "null") +
- " creation tag of item: " + ((item != null) ? item.whereCreated : "null") +
- " creation tag of modelItem: " + ((modelItem != null) ? modelItem.whereCreated : "null") +
- " Error: ItemInfo passed to updateItemInDatabase doesn't match original";
- throw new RuntimeException(msg);
+ cr.delete(uriToDelete, null, null);
+ switch (item.itemType) {
+ case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:
+ sFolders.remove(item.id);
+ sWorkspaceItems.remove(item);
+ break;
+ case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
+ case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
+ sWorkspaceItems.remove(item);
+ break;
+ case LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET:
+ sAppWidgets.remove((LauncherAppWidgetInfo) item);
+ break;
}
+ sItemsIdMap.remove(item.id);
+ sDbIconCache.remove(item);
}
};
if (sWorkerThread.getThreadId() == Process.myTid()) {
@@ -490,57 +521,32 @@ public class LauncherModel extends BroadcastReceiver {
}
/**
- * Removes the specified item from the database
- * @param context
- * @param item
- */
- static void deleteItemFromDatabase(Context context, final ItemInfo item) {
- final ContentResolver cr = context.getContentResolver();
- final Uri uriToDelete = LauncherSettings.Favorites.getContentUri(item.id, false);
- sWorker.post(new Runnable() {
- public void run() {
- cr.delete(uriToDelete, null, null);
- switch (item.itemType) {
- case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:
- sFolders.remove(item.id);
- sWorkspaceItems.remove(item);
- break;
- case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
- case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
- sWorkspaceItems.remove(item);
- break;
- case LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET:
- sAppWidgets.remove((LauncherAppWidgetInfo) item);
- break;
- }
- sItemsIdMap.remove(item.id);
- sDbIconCache.remove(item);
- }
- });
- }
-
- /**
* Remove the contents of the specified folder from the database
*/
static void deleteFolderContentsFromDatabase(Context context, final FolderInfo info) {
final ContentResolver cr = context.getContentResolver();
- sWorker.post(new Runnable() {
- public void run() {
- cr.delete(LauncherSettings.Favorites.getContentUri(info.id, false), null, null);
- sItemsIdMap.remove(info.id);
- sFolders.remove(info.id);
- sDbIconCache.remove(info);
- sWorkspaceItems.remove(info);
-
- cr.delete(LauncherSettings.Favorites.CONTENT_URI_NO_NOTIFICATION,
- LauncherSettings.Favorites.CONTAINER + "=" + info.id, null);
- for (ItemInfo childInfo : info.contents) {
- sItemsIdMap.remove(childInfo.id);
- sDbIconCache.remove(childInfo);
- }
+ Runnable r = new Runnable() {
+ public void run() {
+ cr.delete(LauncherSettings.Favorites.getContentUri(info.id, false), null, null);
+ sItemsIdMap.remove(info.id);
+ sFolders.remove(info.id);
+ sDbIconCache.remove(info);
+ sWorkspaceItems.remove(info);
+
+ cr.delete(LauncherSettings.Favorites.CONTENT_URI_NO_NOTIFICATION,
+ LauncherSettings.Favorites.CONTAINER + "=" + info.id, null);
+ for (ItemInfo childInfo : info.contents) {
+ sItemsIdMap.remove(childInfo.id);
+ sDbIconCache.remove(childInfo);
}
- });
+ }
+ };
+ if (sWorkerThread.getThreadId() == Process.myTid()) {
+ r.run();
+ } else {
+ sWorker.post(r);
+ }
}
/**
@@ -867,17 +873,28 @@ public class LauncherModel extends BroadcastReceiver {
private boolean checkItemPlacement(ItemInfo occupied[][][], ItemInfo item) {
int containerIndex = item.screen;
if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
- // We use the last index to refer to the hotseat
- containerIndex = Launcher.SCREEN_COUNT;
// Return early if we detect that an item is under the hotseat button
if (Hotseat.isAllAppsButtonRank(item.screen)) {
return false;
}
+
+ // We use the last index to refer to the hotseat and the screen as the rank, so
+ // test and update the occupied state accordingly
+ if (occupied[Launcher.SCREEN_COUNT][item.screen][0] != null) {
+ Log.e(TAG, "Error loading shortcut into hotseat " + item
+ + " into position (" + item.screen + ":" + item.cellX + "," + item.cellY
+ + ") occupied by " + occupied[Launcher.SCREEN_COUNT][item.screen][0]);
+ return false;
+ } else {
+ occupied[Launcher.SCREEN_COUNT][item.screen][0] = item;
+ return true;
+ }
} else if (item.container != LauncherSettings.Favorites.CONTAINER_DESKTOP) {
// Skip further checking if it is not the hotseat or workspace container
return true;
}
+ // 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 (occupied[containerIndex][x][y] != null) {
@@ -917,9 +934,12 @@ public class LauncherModel extends BroadcastReceiver {
final ArrayList<Long> itemsToRemove = new ArrayList<Long>();
final Cursor c = contentResolver.query(
- LauncherSettings.Favorites.CONTENT_URI, null, null, null, null);
+ LauncherSettings.Favorites.CONTENT_URI, null, null, null,
+ LauncherSettings.Favorites._ID + " DESC");
// +1 for the hotseat (it can be larger than the workspace)
+ // Load workspace in reverse order to ensure that latest items are loaded first (and
+ // before any earlier duplicates)
final ItemInfo occupied[][][] =
new ItemInfo[Launcher.SCREEN_COUNT + 1][mCellCountX + 1][mCellCountY + 1];
@@ -1070,7 +1090,7 @@ public class LauncherModel extends BroadcastReceiver {
+ id + " appWidgetId=" + appWidgetId);
itemsToRemove.add(id);
} else {
- appWidgetInfo = new LauncherAppWidgetInfo(appWidgetId, "5");
+ appWidgetInfo = new LauncherAppWidgetInfo(appWidgetId);
appWidgetInfo.id = id;
appWidgetInfo.screen = c.getInt(screenIndex);
appWidgetInfo.cellX = c.getInt(cellXIndex);
@@ -1165,8 +1185,12 @@ public class LauncherModel extends BroadcastReceiver {
}
}
});
+
+ // Unbind previously bound workspace items to prevent a leak of AppWidgetHostViews.
+ final ArrayList<ItemInfo> workspaceItems = unbindWorkspaceItemsOnMainThread();
+
// Add the items to the workspace.
- N = sWorkspaceItems.size();
+ N = workspaceItems.size();
for (int i=0; i<N; i+=ITEMS_CHUNK) {
final int start = i;
final int chunkSize = (i+ITEMS_CHUNK <= N) ? ITEMS_CHUNK : (N-i);
@@ -1174,16 +1198,18 @@ public class LauncherModel extends BroadcastReceiver {
public void run() {
Callbacks callbacks = tryGetCallbacks(oldCallbacks);
if (callbacks != null) {
- callbacks.bindItems(sWorkspaceItems, start, start+chunkSize);
+ callbacks.bindItems(workspaceItems, start, start+chunkSize);
}
}
});
}
+ // Ensure that we don't use the same folders data structure on the main thread
+ final HashMap<Long, FolderInfo> folders = new HashMap<Long, FolderInfo>(sFolders);
mHandler.post(new Runnable() {
public void run() {
Callbacks callbacks = tryGetCallbacks(oldCallbacks);
if (callbacks != null) {
- callbacks.bindFolders(sFolders);
+ callbacks.bindFolders(folders);
}
}
});
@@ -1356,7 +1382,7 @@ public class LauncherModel extends BroadcastReceiver {
for (int j=0; i<N && j<batchSize; j++) {
// This builds the icon bitmaps.
mAllAppsList.add(new ApplicationInfo(packageManager, apps.get(i),
- mIconCache, mLabelCache, "6"));
+ mIconCache, mLabelCache));
i++;
}
@@ -1552,7 +1578,7 @@ public class LauncherModel extends BroadcastReceiver {
public ShortcutInfo getShortcutInfo(PackageManager manager, Intent intent, Context context,
Cursor c, int iconIndex, int titleIndex, HashMap<Object, CharSequence> labelCache) {
Bitmap icon = null;
- final ShortcutInfo info = new ShortcutInfo("7");
+ final ShortcutInfo info = new ShortcutInfo();
ComponentName componentName = intent.getComponent();
if (componentName == null) {
@@ -1617,7 +1643,7 @@ public class LauncherModel extends BroadcastReceiver {
int titleIndex) {
Bitmap icon = null;
- final ShortcutInfo info = new ShortcutInfo("8");
+ final ShortcutInfo info = new ShortcutInfo();
info.itemType = LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT;
// TODO: If there's an explicit component and we can't install that, delete it.
@@ -1776,7 +1802,7 @@ public class LauncherModel extends BroadcastReceiver {
}
}
- final ShortcutInfo info = new ShortcutInfo("9");
+ final ShortcutInfo info = new ShortcutInfo();
if (icon == null) {
if (fallbackIcon != null) {
@@ -1844,7 +1870,7 @@ public class LauncherModel extends BroadcastReceiver {
FolderInfo folderInfo = folders.get(id);
if (folderInfo == null) {
// No placeholder -- create a new instance
- folderInfo = new FolderInfo("10");
+ folderInfo = new FolderInfo();
folders.put(id, folderInfo);
}
return folderInfo;
diff --git a/src/com/android/launcher2/PendingAddItemInfo.java b/src/com/android/launcher2/PendingAddItemInfo.java
index 6ee300bfa..7b564e051 100644
--- a/src/com/android/launcher2/PendingAddItemInfo.java
+++ b/src/com/android/launcher2/PendingAddItemInfo.java
@@ -28,10 +28,6 @@ class PendingAddItemInfo extends ItemInfo {
* The component that will be created.
*/
ComponentName componentName;
-
- public PendingAddItemInfo(String whereCreated) {
- super(whereCreated);
- }
}
class PendingAddWidgetInfo extends PendingAddItemInfo {
@@ -43,9 +39,7 @@ class PendingAddWidgetInfo extends PendingAddItemInfo {
String mimeType;
Parcelable configurationData;
- public PendingAddWidgetInfo(
- AppWidgetProviderInfo i, String dataMimeType, Parcelable data, String whereCreated) {
- super(whereCreated);
+ public PendingAddWidgetInfo(AppWidgetProviderInfo i, String dataMimeType, Parcelable data) {
itemType = LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET;
componentName = i.provider;
minWidth = i.minWidth;
diff --git a/src/com/android/launcher2/ShortcutInfo.java b/src/com/android/launcher2/ShortcutInfo.java
index 6d4853ff4..c0f80aeec 100644
--- a/src/com/android/launcher2/ShortcutInfo.java
+++ b/src/com/android/launcher2/ShortcutInfo.java
@@ -62,14 +62,12 @@ class ShortcutInfo extends ItemInfo {
*/
private Bitmap mIcon;
- ShortcutInfo(String whereCreated) {
- super(whereCreated);
+ ShortcutInfo() {
itemType = LauncherSettings.BaseLauncherColumns.ITEM_TYPE_SHORTCUT;
- this.whereCreated = whereCreated;
}
- public ShortcutInfo(ShortcutInfo info, String whereCreated) {
- super(info, whereCreated);
+ public ShortcutInfo(ShortcutInfo info) {
+ super(info);
title = info.title.toString();
intent = new Intent(info.intent);
if (info.iconResource != null) {
@@ -82,8 +80,8 @@ class ShortcutInfo extends ItemInfo {
}
/** TODO: Remove this. It's only called by ApplicationInfo.makeShortcut. */
- public ShortcutInfo(ApplicationInfo info, String whereCreated) {
- super(info, whereCreated);
+ public ShortcutInfo(ApplicationInfo info) {
+ super(info);
title = info.title.toString();
intent = new Intent(info.intent);
customIcon = false;
diff --git a/src/com/android/launcher2/Workspace.java b/src/com/android/launcher2/Workspace.java
index 29da4bf2f..e8c511650 100644
--- a/src/com/android/launcher2/Workspace.java
+++ b/src/com/android/launcher2/Workspace.java
@@ -2309,7 +2309,7 @@ public class Workspace extends SmoothPagedView
// that widget
final AppWidgetProviderInfo widgetInfo = widgets.get(0).widgetInfo;
final PendingAddWidgetInfo createInfo =
- new PendingAddWidgetInfo(widgetInfo, mimeType, data, "11");
+ new PendingAddWidgetInfo(widgetInfo, mimeType, data);
mLauncher.addAppWidgetFromDrop(createInfo,
LauncherSettings.Favorites.CONTAINER_DESKTOP, mCurrentPage, null, pos);
} else {
@@ -2825,7 +2825,7 @@ public class Workspace extends SmoothPagedView
case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
if (info.container == NO_ID && info instanceof ApplicationInfo) {
// Came from all apps -- make a copy
- info = new ShortcutInfo((ApplicationInfo) info, "12");
+ info = new ShortcutInfo((ApplicationInfo) info);
}
view = mLauncher.createShortcut(R.layout.application, cellLayout,
(ShortcutInfo) info);