auto import from //depot/cupcake/@137055
diff --git a/src/com/android/launcher/LauncherModel.java b/src/com/android/launcher/LauncherModel.java
index 783eef2..40b5402 100644
--- a/src/com/android/launcher/LauncherModel.java
+++ b/src/com/android/launcher/LauncherModel.java
@@ -57,6 +57,7 @@
     private boolean mDesktopItemsLoaded;
 
     private ArrayList<ItemInfo> mDesktopItems;
+    private ArrayList<LauncherGadgetInfo> mDesktopGadgets;
     private HashMap<Long, FolderInfo> mFolders;
 
     private ArrayList<ApplicationInfo> mApplications;
@@ -202,6 +203,7 @@
             final ApplicationsAdapter applicationList = mApplicationList;
             final int count = buffer.size();
 
+            applicationList.setNotifyOnChange(false);
             applicationList.clear();
             for (int i = 0; i < count; i++) {
                 applicationList.setNotifyOnChange(false);
@@ -222,7 +224,7 @@
     }
 
     boolean isDesktopLoaded() {
-        return mDesktopItems != null && mDesktopItemsLoaded;
+        return mDesktopItems != null && mDesktopGadgets != null && mDesktopItemsLoaded;
     }
     
     /**
@@ -232,7 +234,7 @@
     void loadUserItems(boolean isLaunching, Launcher launcher, boolean localeChanged,
             boolean loadApplications) {
 
-        if (isLaunching && mDesktopItems != null && mDesktopItemsLoaded) {
+        if (isLaunching && isDesktopLoaded()) {
             if (loadApplications) startApplicationsLoader(launcher);
             // We have already loaded our data from the DB
             launcher.onDesktopItemsLoaded();
@@ -358,9 +360,11 @@
             }
 
             mDesktopItems = new ArrayList<ItemInfo>();
+            mDesktopGadgets = new ArrayList<LauncherGadgetInfo>();
             mFolders = new HashMap<Long, FolderInfo>();
 
             final ArrayList<ItemInfo> desktopItems = mDesktopItems;
+            final ArrayList<LauncherGadgetInfo> desktopGadgets = mDesktopGadgets;
 
             final Cursor c = contentResolver.query(
                     LauncherSettings.Favorites.CONTENT_URI, null, null, null, null);
@@ -386,8 +390,8 @@
 
                 ApplicationInfo info;
                 String intentDescription;
-                Widget widgetInfo = null;
-                LauncherGadgetInfo gadgetInfo = null;
+                Widget widgetInfo;
+                LauncherGadgetInfo gadgetInfo;
                 int container;
                 long id;
                 Intent intent;
@@ -536,7 +540,7 @@
                             }
                             gadgetInfo.container = c.getInt(containerIndex);
                             
-                            desktopItems.add(gadgetInfo);
+                            desktopGadgets.add(gadgetInfo);
                             break;
                         }
                     } catch (Exception e) {
@@ -643,6 +647,7 @@
         mApplicationsAdapter = null;
         unbindAppDrawables(mApplications);
         unbindDrawables(mDesktopItems);
+        unbindGadgetHostViews(mDesktopGadgets);
     }
     
     /**
@@ -658,6 +663,7 @@
                 case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
                 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
                     ((ApplicationInfo)item).icon.setCallback(null);
+                    break;
                 }
             }
         }
@@ -677,6 +683,19 @@
     }
 
     /**
+     * Remove any {@link LauncherGadgetHostView} references in our gadgets.
+     */
+    private void unbindGadgetHostViews(ArrayList<LauncherGadgetInfo> gadgets) {
+        if (gadgets != null) {
+            final int count = gadgets.size();
+            for (int i = 0; i < count; i++) {
+                LauncherGadgetInfo launcherInfo = gadgets.get(i);
+                launcherInfo.hostView = null;
+            }
+        }
+    }
+
+    /**
      * @return The current list of applications
      */
     public ArrayList<ApplicationInfo> getApplications() {
@@ -696,6 +715,13 @@
     public ArrayList<ItemInfo> getDesktopItems() {
         return mDesktopItems;
     }
+    
+    /**
+     * @return The current list of desktop items
+     */
+    public ArrayList<LauncherGadgetInfo> getDesktopGadgets() {
+        return mDesktopGadgets;
+    }
 
     /**
      * Add an item to the desktop
@@ -716,6 +742,20 @@
     }
 
     /**
+     * Add a gadget to the desktop
+     */
+    public void addDesktopGadget(LauncherGadgetInfo info) {
+        mDesktopGadgets.add(info);
+    }
+    
+    /**
+     * Remove a gadget from the desktop
+     */
+    public void removeDesktopGadget(LauncherGadgetInfo info) {
+        mDesktopGadgets.remove(info);
+    }
+
+    /**
      * Make an ApplicationInfo object for an application
      */
     private static ApplicationInfo getApplicationInfo(PackageManager manager, Intent intent) {