Merge "Fix rendering bug while dragging" into jb-dev
diff --git a/res/values-sw600dp-port/dimens.xml b/res/values-sw600dp-port/dimens.xml
index 1a25409..8ad6d2e 100644
--- a/res/values-sw600dp-port/dimens.xml
+++ b/res/values-sw600dp-port/dimens.xml
@@ -17,9 +17,9 @@
 <resources>
 <!-- AppsCustomize -->
     <dimen name="apps_customize_cell_width">96dp</dimen>
-    <dimen name="apps_customize_cell_height">96dp</dimen>
+    <dimen name="apps_customize_cell_height">108dp</dimen>
     <dimen name="apps_customize_pageLayoutWidthGap">24dp</dimen>
-    <dimen name="apps_customize_pageLayoutHeightGap">36dp</dimen>
+    <dimen name="apps_customize_pageLayoutHeightGap">24dp</dimen>
     <dimen name="apps_customize_pageLayoutPaddingTop">25dp</dimen>
     <dimen name="apps_customize_pageLayoutPaddingBottom">10dp</dimen>
 
diff --git a/res/values-sw600dp/config.xml b/res/values-sw600dp/config.xml
index 00b2e15..a701e69 100644
--- a/res/values-sw600dp/config.xml
+++ b/res/values-sw600dp/config.xml
@@ -1,6 +1,4 @@
 <resources>
-    <bool name="allow_rotation">true</bool>
-
     <integer name="cell_count_x">6</integer>
     <integer name="cell_count_y">6</integer>
     <integer name="hotseat_cell_count">7</integer>
diff --git a/res/values-sw600dp/dimens.xml b/res/values-sw600dp/dimens.xml
index fbd743b..99e8909 100644
--- a/res/values-sw600dp/dimens.xml
+++ b/res/values-sw600dp/dimens.xml
@@ -54,7 +54,7 @@
 
 <!-- AppsCustomize -->
     <dimen name="apps_customize_cell_width">96dp</dimen>
-    <dimen name="apps_customize_cell_height">98dp</dimen>
+    <dimen name="apps_customize_cell_height">96dp</dimen>
     <dimen name="apps_customize_pageLayoutPaddingLeft">12dp</dimen>
     <dimen name="apps_customize_pageLayoutPaddingRight">12dp</dimen>
     <dimen name="apps_customize_tab_bar_height">60dp</dimen>
diff --git a/res/values-sw720dp/config.xml b/res/values-sw720dp/config.xml
index c52328f..7a6f6d8 100644
--- a/res/values-sw720dp/config.xml
+++ b/res/values-sw720dp/config.xml
@@ -1,6 +1,7 @@
 <resources>
     <bool name="config_largeHeap">true</bool>
     <bool name="is_large_screen">true</bool>
+    <bool name="allow_rotation">true</bool>
 
 <!-- AllApps/Customize/AppsCustomize -->
     <!-- Out of 100, the percent to shrink the workspace during spring loaded mode. -->
diff --git a/res/values-sw720dp/dimens.xml b/res/values-sw720dp/dimens.xml
index d06f0aa..cfd76dc 100644
--- a/res/values-sw720dp/dimens.xml
+++ b/res/values-sw720dp/dimens.xml
@@ -36,6 +36,8 @@
     <dimen name="folder_preview_size">75dp</dimen>
 
 <!-- AppsCustomize -->
+    <dimen name="apps_customize_cell_width">96dp</dimen>
+    <dimen name="apps_customize_cell_height">96dp</dimen>
     <integer name="apps_customize_maxCellCountX">-1</integer>
     <integer name="apps_customize_maxCellCountY">-1</integer>
     <dimen name="app_widget_preview_padding_left">0dp</dimen>
diff --git a/src/com/android/launcher2/AppsCustomizePagedView.java b/src/com/android/launcher2/AppsCustomizePagedView.java
index 6679d6c..71362e8 100644
--- a/src/com/android/launcher2/AppsCustomizePagedView.java
+++ b/src/com/android/launcher2/AppsCustomizePagedView.java
@@ -669,6 +669,12 @@
             return false;
         }
 
+        // This can happen in some weird cases involving multi-touch. We can't start dragging the
+        // widget if this is null, so we break out.
+        if (mCreateWidgetInfo == null) {
+            return false;
+        }
+
         // Compose the drag image
         Bitmap preview;
         Bitmap outline;
diff --git a/src/com/android/launcher2/Launcher.java b/src/com/android/launcher2/Launcher.java
index 2e7caff..91184c9 100644
--- a/src/com/android/launcher2/Launcher.java
+++ b/src/com/android/launcher2/Launcher.java
@@ -1129,8 +1129,7 @@
 
             launcherInfo.hostView.setTag(launcherInfo);
             launcherInfo.hostView.setVisibility(View.VISIBLE);
-            AppWidgetResizeFrame.updateWidgetSizeRanges(launcherInfo.hostView,
-                    this, launcherInfo.spanX, launcherInfo.spanY);
+            launcherInfo.notifyWidgetSizeChanged(this);
             mWorkspace.addInScreen(launcherInfo.hostView, container, screen, cellXY[0], cellXY[1],
                     launcherInfo.spanX, launcherInfo.spanY, isWorkspaceLocked());
 
@@ -3160,17 +3159,14 @@
 
         item.hostView.setAppWidget(appWidgetId, appWidgetInfo);
         item.hostView.setTag(item);
+        item.onBindAppWidget(this);
 
         workspace.addInScreen(item.hostView, item.container, item.screen, item.cellX,
                 item.cellY, item.spanX, item.spanY, false);
-
         addWidgetToAutoAdvanceIfNeeded(item.hostView, appWidgetInfo);
 
         workspace.requestLayout();
 
-        AppWidgetResizeFrame.updateWidgetSizeRanges(item.hostView,
-                this, item.spanX, item.spanY);
-
         if (DEBUG_WIDGETS) {
             Log.d(TAG, "bound widget id="+item.appWidgetId+" in "
                     + (SystemClock.uptimeMillis()-start) + "ms");
diff --git a/src/com/android/launcher2/LauncherAppWidgetInfo.java b/src/com/android/launcher2/LauncherAppWidgetInfo.java
index e5b9473..f001b2b 100644
--- a/src/com/android/launcher2/LauncherAppWidgetInfo.java
+++ b/src/com/android/launcher2/LauncherAppWidgetInfo.java
@@ -42,6 +42,8 @@
     int minWidth = -1;
     int minHeight = -1;
 
+    private boolean mHasNotifiedInitialWidgetSizeChanged;
+
     /**
      * View that holds this widget after it's been created.  This view isn't created
      * until Launcher knows it's needed.
@@ -65,6 +67,24 @@
         values.put(LauncherSettings.Favorites.APPWIDGET_ID, appWidgetId);
     }
 
+    /**
+     * When we bind the widget, we should notify the widget that the size has changed if we have not
+     * done so already (only really for default workspace widgets).
+     */
+    void onBindAppWidget(Launcher launcher) {
+        if (!mHasNotifiedInitialWidgetSizeChanged) {
+            notifyWidgetSizeChanged(launcher);
+        }
+    }
+
+    /**
+     * Trigger an update callback to the widget to notify it that its size has changed.
+     */
+    void notifyWidgetSizeChanged(Launcher launcher) {
+        AppWidgetResizeFrame.updateWidgetSizeRanges(hostView, launcher, spanX, spanY);
+        mHasNotifiedInitialWidgetSizeChanged = true;
+    }
+
     @Override
     public String toString() {
         return "AppWidget(id=" + Integer.toString(appWidgetId) + ")";
diff --git a/src/com/android/launcher2/PagedViewWidget.java b/src/com/android/launcher2/PagedViewWidget.java
index f78aa4c..a6ea78f 100644
--- a/src/com/android/launcher2/PagedViewWidget.java
+++ b/src/com/android/launcher2/PagedViewWidget.java
@@ -141,8 +141,8 @@
 
     class CheckForShortPress implements Runnable {
         public void run() {
+            if (sShortpressTarget != null) return;
             if (mShortPressListener != null) {
-                if (sShortpressTarget != null) return;
                 mShortPressListener.onShortPress(PagedViewWidget.this);
             }
             sShortpressTarget = PagedViewWidget.this;