am a4d0ef3c: am 7c9f3348: Merge remote-tracking branch \'goog/ub-now-lunchbox\' into lunchbox-release

* commit 'a4d0ef3c84cb5a9951d7d967c2c99d54d573f927':
diff --git a/src/com/android/launcher3/AppsCustomizePagedView.java b/src/com/android/launcher3/AppsCustomizePagedView.java
index 5c8828a..251ae21 100644
--- a/src/com/android/launcher3/AppsCustomizePagedView.java
+++ b/src/com/android/launcher3/AppsCustomizePagedView.java
@@ -828,7 +828,6 @@
                 }
             });
         } else {
-            mLauncher.getWorkspace().removeExtraEmptyScreen(true, null);
             mLauncher.unlockScreenOrientation(false);
         }
     }
diff --git a/src/com/android/launcher3/LauncherClings.java b/src/com/android/launcher3/LauncherClings.java
index 894f64d..952edfd 100644
--- a/src/com/android/launcher3/LauncherClings.java
+++ b/src/com/android/launcher3/LauncherClings.java
@@ -297,12 +297,18 @@
 
     public static void synchonouslyMarkFirstRunClingDismissed(Context ctx) {
         SharedPreferences prefs = ctx.getSharedPreferences(
-                LauncherAppState.getSharedPreferencesKey(),Context.MODE_PRIVATE);
+                LauncherAppState.getSharedPreferencesKey(), Context.MODE_PRIVATE);
         SharedPreferences.Editor editor = prefs.edit();
         editor.putBoolean(LauncherClings.FIRST_RUN_CLING_DISMISSED_KEY, true);
         editor.commit();
     }
 
+    public void markFolderClingDismissed() {
+        SharedPreferences.Editor editor = mLauncher.getSharedPrefs().edit();
+        editor.putBoolean(LauncherClings.FOLDER_CLING_DISMISSED_KEY, true);
+        editor.apply();
+    }
+
     /** Removes the cling outright from the DragLayer */
     private void removeCling(int id) {
         final View cling = mLauncher.findViewById(id);
diff --git a/src/com/android/launcher3/LauncherProvider.java b/src/com/android/launcher3/LauncherProvider.java
index b952729..a080dd8 100644
--- a/src/com/android/launcher3/LauncherProvider.java
+++ b/src/com/android/launcher3/LauncherProvider.java
@@ -50,6 +50,7 @@
 import android.text.TextUtils;
 import android.util.AttributeSet;
 import android.util.Log;
+import android.util.SparseArray;
 import android.util.Xml;
 
 import com.android.launcher3.LauncherSettings.Favorites;
@@ -1578,6 +1579,7 @@
 
                         final ArrayList<ContentValues> shortcuts = new ArrayList<ContentValues>();
                         final ArrayList<ContentValues> folders = new ArrayList<ContentValues>();
+                        final SparseArray<ContentValues> hotseat = new SparseArray<ContentValues>();
 
                         while (c.moveToNext()) {
                             final int itemType = c.getInt(itemTypeIndex);
@@ -1593,7 +1595,11 @@
                             int container = c.getInt(containerIndex);
                             final String intentStr = c.getString(intentIndex);
                             Launcher.addDumpLog(TAG, "migrating \""
-                                + c.getString(titleIndex) + "\": " + intentStr, true);
+                                + c.getString(titleIndex) + "\" ("
+                                + cellX + "," + cellY + "@"
+                                + LauncherSettings.Favorites.containerToString(container)
+                                + "/" + screen
+                                + "): " + intentStr, true);
 
                             if (itemType != Favorites.ITEM_TYPE_FOLDER) {
 
@@ -1654,11 +1660,8 @@
                             values.put(LauncherSettings.Favorites.DISPLAY_MODE,
                                     c.getInt(displayModeIndex));
 
-                            if (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT
-                                    && (screen >= hotseatWidth ||
-                                        screen == grid.hotseatAllAppsRank)) {
-                                // no room for you in the hotseat? it's off to the desktop with you
-                                container = Favorites.CONTAINER_DESKTOP;
+                            if (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
+                                hotseat.put(screen, values);
                             }
 
                             if (container != LauncherSettings.Favorites.CONTAINER_DESKTOP) {
@@ -1680,6 +1683,31 @@
                             }
                         }
 
+                        // Now that we have all the hotseat icons, let's go through them left-right
+                        // and assign valid locations for them in the new hotseat
+                        final int N = hotseat.size();
+                        for (int idx=0; idx<N; idx++) {
+                            int hotseatX = hotseat.keyAt(idx);
+                            ContentValues values = hotseat.valueAt(idx);
+
+                            if (hotseatX == grid.hotseatAllAppsRank) {
+                                // let's drop this in the next available hole in the hotseat
+                                while (++hotseatX < hotseatWidth) {
+                                    if (hotseat.get(hotseatX) == null) {
+                                        // found a spot! move it here
+                                        values.put(LauncherSettings.Favorites.SCREEN,
+                                                hotseatX);
+                                        break;
+                                    }
+                                }
+                            }
+                            if (hotseatX >= hotseatWidth) {
+                                // no room for you in the hotseat? it's off to the desktop with you
+                                values.put(LauncherSettings.Favorites.CONTAINER,
+                                           Favorites.CONTAINER_DESKTOP);
+                            }
+                        }
+
                         final ArrayList<ContentValues> allItems = new ArrayList<ContentValues>();
                         // Folders first
                         allItems.addAll(folders);
diff --git a/src/com/android/launcher3/LauncherSettings.java b/src/com/android/launcher3/LauncherSettings.java
index f4ee300..2a768a2 100644
--- a/src/com/android/launcher3/LauncherSettings.java
+++ b/src/com/android/launcher3/LauncherSettings.java
@@ -171,6 +171,14 @@
         static final int CONTAINER_DESKTOP = -100;
         static final int CONTAINER_HOTSEAT = -101;
 
+        static final String containerToString(int container) {
+            switch (container) {
+                case CONTAINER_DESKTOP: return "desktop";
+                case CONTAINER_HOTSEAT: return "hotseat";
+                default: return String.valueOf(container);
+            }
+        }
+
         /**
          * The screen holding the favorite (if container is CONTAINER_DESKTOP)
          * <P>Type: INTEGER</P>
diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java
index 86c603e..567abfa 100644
--- a/src/com/android/launcher3/Workspace.java
+++ b/src/com/android/launcher3/Workspace.java
@@ -2632,6 +2632,9 @@
         if (child instanceof BubbleTextView) {
             BubbleTextView icon = (BubbleTextView) child;
             icon.clearPressedOrFocusedBackground();
+        } else if (child instanceof FolderIcon) {
+            // Dismiss the folder cling if we haven't already
+            mLauncher.getLauncherClings().markFolderClingDismissed();
         }
 
         if (child.getTag() == null || !(child.getTag() instanceof ItemInfo)) {