Fixing issue where dragging final items out of hot seat folder can causes inconsistency issue.

- Fixing restoring of workspace screens on rotation (and flash of custom content page indicator)
- Fixing NPE on long pressing on empty screen to go into overview mode
diff --git a/src/com/android/launcher3/Folder.java b/src/com/android/launcher3/Folder.java
index 6308bb7..3aa9133 100644
--- a/src/com/android/launcher3/Folder.java
+++ b/src/com/android/launcher3/Folder.java
@@ -1062,9 +1062,10 @@
                     mLauncher.removeFolder(mInfo);
                 }
                 // We add the child after removing the folder to prevent both from existing at
-                // the same time in the CellLayout.
+                // the same time in the CellLayout.  We need to add the new item with addInScreenFromBind()
+                // to ensure that hotseat items are placed correctly.
                 if (child != null) {
-                    mLauncher.getWorkspace().addInScreen(child, mInfo.container, mInfo.screenId,
+                    mLauncher.getWorkspace().addInScreenFromBind(child, mInfo.container, mInfo.screenId,
                             mInfo.cellX, mInfo.cellY, mInfo.spanX, mInfo.spanY);
                 }
             }
diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java
index 7fc7033..ce4a78c 100644
--- a/src/com/android/launcher3/Launcher.java
+++ b/src/com/android/launcher3/Launcher.java
@@ -2537,14 +2537,16 @@
         boolean allowLongPress = isHotseatLayout(v) || mWorkspace.allowLongPress();
         if (allowLongPress && !mDragController.isDragging()) {
             if (itemUnderLongClick == null) {
-                // User long pressed on empty space
-                mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
-                        HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
-                // Disabling reordering until we sort out some issues.
-                if (mWorkspace.isInOverviewMode()) {
-                    mWorkspace.startReordering(v);
-                } else {
-                    mWorkspace.enterOverviewMode();
+                if (mWorkspace.hasNonCustomEmptyScreens()) {
+                    // User long pressed on empty space
+                    mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
+                            HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
+                    // Disabling reordering until we sort out some issues.
+                    if (mWorkspace.isInOverviewMode()) {
+                        mWorkspace.startReordering(v);
+                    } else {
+                        mWorkspace.enterOverviewMode();
+                    }
                 }
             } else {
                 if (!(itemUnderLongClick instanceof Folder)) {
@@ -3502,7 +3504,15 @@
     @Override
     public void bindScreens(ArrayList<Long> orderedScreenIds) {
         bindAddScreens(orderedScreenIds);
+
+        // Create the new empty page
         mWorkspace.addExtraEmptyScreen();
+
+        // Create the custom content page (this call updates mDefaultScreen which calls
+        // setCurrentPage() so ensure that all pages are added before calling this)
+        if (!mWorkspace.hasCustomContent() && hasCustomContentToLeft()) {
+            mWorkspace.createCustomContentPage();
+        }
     }
 
     @Override
@@ -3744,11 +3754,6 @@
             mSavedState = null;
         }
 
-        // Create the custom content page here before onLayout to prevent flashing
-        if (!mWorkspace.hasCustomContent() && hasCustomContentToLeft()) {
-            mWorkspace.createCustomContentPage();
-        }
-
         mWorkspace.restoreInstanceStateForRemainingPages();
 
         // If we received the result of any pending adds while the loader was running (e.g. the
diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java
index ba18b8d..d33e650 100644
--- a/src/com/android/launcher3/Workspace.java
+++ b/src/com/android/launcher3/Workspace.java
@@ -567,6 +567,18 @@
         return -1;
     }
 
+    public boolean hasNonCustomEmptyScreens() {
+        Log.w(TAG, "10249126 - hasNonCustomEmptyScreens()");
+        Iterator<Long> iter = mWorkspaceScreens.keySet().iterator();
+        while (iter.hasNext()) {
+            long id = iter.next();
+            if (id >= 0) {
+                return true;
+            }
+        }
+        return false;
+    }
+
     ArrayList<Long> getScreenOrder() {
         return mScreenOrder;
     }