Fix NPE when dragging widget with preview not yet loaded (issue 6282761)

Change-Id: I95638884bd6548f391135427a20566933ab757c0
diff --git a/src/com/android/launcher2/AppsCustomizePagedView.java b/src/com/android/launcher2/AppsCustomizePagedView.java
index 54af080..21872b9 100644
--- a/src/com/android/launcher2/AppsCustomizePagedView.java
+++ b/src/com/android/launcher2/AppsCustomizePagedView.java
@@ -641,12 +641,19 @@
         }
     }
 
-    private void beginDraggingWidget(View v) {
+    private boolean beginDraggingWidget(View v) {
         mDraggingWidget = true;
         // Get the widget preview as the drag representation
         ImageView image = (ImageView) v.findViewById(R.id.widget_preview);
         PendingAddItemInfo createItemInfo = (PendingAddItemInfo) v.getTag();
 
+        // If the ImageView doesn't have a drawable yet, the widget preview hasn't been loaded and
+        // we abort the drag.
+        if (image.getDrawable() == null) {
+            mDraggingWidget = false;
+            return false;
+        }
+
         // Compose the drag image
         Bitmap preview;
         Bitmap outline;
@@ -712,6 +719,7 @@
                 DragController.DRAG_ACTION_COPY, null, scale);
         outline.recycle();
         preview.recycle();
+        return true;
     }
 
     @Override
@@ -721,7 +729,9 @@
         if (v instanceof PagedViewIcon) {
             beginDraggingApplication(v);
         } else if (v instanceof PagedViewWidget) {
-            beginDraggingWidget(v);
+            if (!beginDraggingWidget(v)) {
+                return false;
+            }
         }
 
         // We delay entering spring-loaded mode slightly to make sure the UI