Merge "Fixing bug 4998211, widgets with configuration not dropping in correct spot"
diff --git a/src/com/android/launcher2/AppsCustomizePagedView.java b/src/com/android/launcher2/AppsCustomizePagedView.java
index 8a4bdc7..f059469 100644
--- a/src/com/android/launcher2/AppsCustomizePagedView.java
+++ b/src/com/android/launcher2/AppsCustomizePagedView.java
@@ -734,15 +734,11 @@
                 mPageLayoutPaddingRight, mPageLayoutPaddingBottom);
 
         // Note: We force a measure here to get around the fact that when we do layout calculations
-        // immediately after syncing, we don't have a proper width.  That said, we already know the
-        // expected page width, so we can actually optimize by hiding all the TextView-based
-        // children that are expensive to measure, and let that happen naturally later.
-        setVisibilityOnChildren(layout, View.GONE);
+        // immediately after syncing, we don't have a proper width.
         int widthSpec = MeasureSpec.makeMeasureSpec(getMeasuredWidth(), MeasureSpec.AT_MOST);
         int heightSpec = MeasureSpec.makeMeasureSpec(getMeasuredHeight(), MeasureSpec.AT_MOST);
         layout.setMinimumWidth(getPageContentWidth());
         layout.measure(widthSpec, heightSpec);
-        setVisibilityOnChildren(layout, View.VISIBLE);
     }
     private void renderDrawableToBitmap(Drawable d, Bitmap bitmap, int x, int y, int w, int h,
             float scaleX, float scaleY) {
@@ -893,7 +889,8 @@
     private void onSyncWidgetPageItems(AsyncTaskPageData data) {
         int page = data.page;
         PagedViewGridLayout layout = (PagedViewGridLayout) getChildAt(page);
-        layout.removeAllViews();
+        // Only set the column count once we have items
+        layout.setColumnCount(layout.getCellCountX());
 
         ArrayList<Object> items = data.items;
         int count = items.size();
@@ -935,8 +932,8 @@
             int ix = i % cellCountX;
             int iy = i / cellCountX;
             GridLayout.LayoutParams lp = new GridLayout.LayoutParams(
-                    new GridLayout.Group(iy, 1, GridLayout.LEFT),
-                    new GridLayout.Group(ix, 1, GridLayout.TOP));
+                    GridLayout.spec(iy, GridLayout.LEFT, GridLayout.CAN_STRETCH),
+                    GridLayout.spec(ix, GridLayout.TOP, GridLayout.CAN_STRETCH));
             lp.width = cellWidth;
             lp.height = cellHeight;
             if (ix > 0) lp.leftMargin = mWidgetWidthGap;
diff --git a/src/com/android/launcher2/Launcher.java b/src/com/android/launcher2/Launcher.java
index 452421c..bb8e497 100644
--- a/src/com/android/launcher2/Launcher.java
+++ b/src/com/android/launcher2/Launcher.java
@@ -317,6 +317,7 @@
         // If we have a saved version of these external icons, we load them up immediately
         if (sGlobalSearchIcon == null || sVoiceSearchIcon == null || sAppMarketIcon == null) {
             updateIconsAffectedByPackageManagerChanges();
+            updateGlobalSearchIcon();
         }
         if (sGlobalSearchIcon != null) {
              updateGlobalSearchIcon(sGlobalSearchIcon);
@@ -3152,10 +3153,14 @@
      */
     private void updateIconsAffectedByPackageManagerChanges() {
         updateAppMarketIcon();
-        updateGlobalSearchIcon();
         updateVoiceSearchIcon();
     }
 
+    @Override
+    public void bindSearchablesChanged() {
+        updateGlobalSearchIcon();
+    }
+
     /**
      * Add the icons for all apps.
      *
@@ -3166,6 +3171,7 @@
             mAppsCustomizeContent.setApps(apps);
         }
         updateIconsAffectedByPackageManagerChanges();
+        updateGlobalSearchIcon();
     }
 
     /**
diff --git a/src/com/android/launcher2/LauncherApplication.java b/src/com/android/launcher2/LauncherApplication.java
index db3a4cb..94163ac 100644
--- a/src/com/android/launcher2/LauncherApplication.java
+++ b/src/com/android/launcher2/LauncherApplication.java
@@ -17,6 +17,7 @@
 package com.android.launcher2;
 
 import android.app.Application;
+import android.app.SearchManager;
 import android.content.ContentResolver;
 import android.content.Intent;
 import android.content.IntentFilter;
@@ -57,6 +58,9 @@
         filter.addAction(Intent.ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE);
         filter.addAction(Intent.ACTION_LOCALE_CHANGED);
         registerReceiver(mModel, filter);
+        filter = new IntentFilter();
+        filter.addAction(SearchManager.INTENT_GLOBAL_SEARCH_ACTIVITY_CHANGED);
+        registerReceiver(mModel, filter);
 
         // Register for changes to the favorites
         ContentResolver resolver = getContentResolver();
diff --git a/src/com/android/launcher2/LauncherModel.java b/src/com/android/launcher2/LauncherModel.java
index 331f124..b4e632a 100644
--- a/src/com/android/launcher2/LauncherModel.java
+++ b/src/com/android/launcher2/LauncherModel.java
@@ -16,6 +16,7 @@
 
 package com.android.launcher2;
 
+import android.app.SearchManager;
 import android.appwidget.AppWidgetManager;
 import android.appwidget.AppWidgetProviderInfo;
 import android.content.BroadcastReceiver;
@@ -129,6 +130,7 @@
         public void bindAppsRemoved(ArrayList<ApplicationInfo> apps, boolean permanent);
         public void bindPackagesUpdated();
         public boolean isAllAppsVisible();
+        public void bindSearchablesChanged();
     }
 
     LauncherModel(LauncherApplication app, IconCache iconCache) {
@@ -513,6 +515,7 @@
      * Call from the handler for ACTION_PACKAGE_ADDED, ACTION_PACKAGE_REMOVED and
      * ACTION_PACKAGE_CHANGED.
      */
+    @Override
     public void onReceive(Context context, Intent intent) {
         if (DEBUG_LOADERS) Log.d(TAG, "onReceive intent=" + intent);
 
@@ -570,6 +573,9 @@
             mAllAppsLoaded = false;
             mWorkspaceLoaded = false;
             startLoaderFromBackground();
+        } else if (SearchManager.INTENT_GLOBAL_SEARCH_ACTIVITY_CHANGED.equals(action)) {
+            Callbacks callbacks = mCallbacks.get();
+            callbacks.bindSearchablesChanged();
         }
     }
 
diff --git a/src/com/android/launcher2/PagedViewGridLayout.java b/src/com/android/launcher2/PagedViewGridLayout.java
index a2ab763..4131d8b 100644
--- a/src/com/android/launcher2/PagedViewGridLayout.java
+++ b/src/com/android/launcher2/PagedViewGridLayout.java
@@ -35,7 +35,6 @@
         super(context, null, 0);
         mCellCountX = cellCountX;
         mCellCountY = cellCountY;
-        setColumnCount(mCellCountX);
     }
 
     int getCellCountX() {