Merge "Moving prediction icons back into recycler view." into ub-launcher3-burnaby
diff --git a/src/com/android/launcher3/Folder.java b/src/com/android/launcher3/Folder.java
index 476ebd1..f2c5d93 100644
--- a/src/com/android/launcher3/Folder.java
+++ b/src/com/android/launcher3/Folder.java
@@ -62,6 +62,7 @@
 
 import java.util.ArrayList;
 import java.util.Collections;
+import java.util.Comparator;
 
 /**
  * Represents a set of icons chosen by the user or generated by the system.
@@ -363,7 +364,7 @@
     void bind(FolderInfo info) {
         mInfo = info;
         ArrayList<ShortcutInfo> children = info.contents;
-        Collections.sort(children, Utilities.RANK_COMPARATOR);
+        Collections.sort(children, ITEM_POS_COMPARATOR);
 
         ArrayList<ShortcutInfo> overflow = mContent.bindItems(children);
 
@@ -1396,4 +1397,19 @@
             onDragOver(mDragObject, 1);
         }
     }
+
+    // Compares item position based on rank and position giving priority to the rank.
+    private static final Comparator<ItemInfo> ITEM_POS_COMPARATOR = new Comparator<ItemInfo>() {
+
+        @Override
+        public int compare(ItemInfo lhs, ItemInfo rhs) {
+            if (lhs.rank != rhs.rank) {
+                return lhs.rank - rhs.rank;
+            } else if (lhs.cellY != rhs.cellY) {
+                return lhs.cellY - rhs.cellY;
+            } else {
+                return lhs.cellX - rhs.cellX;
+            }
+        }
+    };
 }
diff --git a/src/com/android/launcher3/Utilities.java b/src/com/android/launcher3/Utilities.java
index 19334ed..8f4f0f9 100644
--- a/src/com/android/launcher3/Utilities.java
+++ b/src/com/android/launcher3/Utilities.java
@@ -59,7 +59,6 @@
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.util.ArrayList;
-import java.util.Comparator;
 import java.util.Locale;
 import java.util.Set;
 import java.util.regex.Matcher;
@@ -573,13 +572,6 @@
         }
     }
 
-    public static final Comparator<ItemInfo> RANK_COMPARATOR = new Comparator<ItemInfo>() {
-        @Override
-        public int compare(ItemInfo lhs, ItemInfo rhs) {
-            return lhs.rank - rhs.rank;
-        }
-    };
-
     /**
      * Find the first vacant cell, if there is one.
      *
diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java
index fb0a54d..451f124 100644
--- a/src/com/android/launcher3/Workspace.java
+++ b/src/com/android/launcher3/Workspace.java
@@ -1976,7 +1976,7 @@
     public Animator setStateWithAnimation(State toState, int toPage, boolean animated,
             boolean hasOverlaySearchBar, HashMap<View, Integer> layerViews) {
         // Create the animation to the new state
-        Animator workspaceAnim =  mStateTransitionAnimation.getAnimationToState(getState(),
+        Animator workspaceAnim =  mStateTransitionAnimation.getAnimationToState(mState,
                 toState, toPage, animated, hasOverlaySearchBar, layerViews);
 
         // Update the current state
@@ -1996,6 +1996,9 @@
             for (int i = numCustomPages(); i < total; i++) {
                 updateAccessibilityFlags((CellLayout) getPageAt(i), i);
             }
+            setImportantForAccessibility((mState == State.NORMAL || mState == State.OVERVIEW)
+                    ? IMPORTANT_FOR_ACCESSIBILITY_AUTO
+                            : IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS);
         } else {
             int accessible = mState == State.NORMAL ?
                     IMPORTANT_FOR_ACCESSIBILITY_AUTO :