Make sure all overlay panels are visible as user free scrolls.

Previously there was a workaround to ensure that adjacent panels were visible
while in the overview or spring-loaded states, but it incorrectly kept only
those original pages visible even while the user scrolled to other pages. So now
we only use the workaround when first entering the overview or spring-loaded
states, and then fall back to the default getVisiblePages() implementation in
PageView when in free scoll mode.

Bug: 23766408
Change-Id: I692ec00b9cd6d7889c374aee41b85abd0a5d8d3c
diff --git a/src/com/android/launcher3/PagedView.java b/src/com/android/launcher3/PagedView.java
index 5d2e1cc..5f54e1d 100644
--- a/src/com/android/launcher3/PagedView.java
+++ b/src/com/android/launcher3/PagedView.java
@@ -372,7 +372,10 @@
     }
 
     /**
-     * Returns the index of the currently displayed page.
+     * Returns the index of the currently displayed page. When in free scroll mode, this is the page
+     * that the user was on before entering free scroll mode (e.g. the home screen page they
+     * long-pressed on to enter the overview). Try using {@link #getPageNearestToCenterOfScreen()}
+     * to get the page the user is currently scrolling over.
      */
     public int getCurrentPage() {
         return mCurrentPage;
@@ -1039,11 +1042,10 @@
 
         if (pageCount > 0) {
             int viewportWidth = getViewportWidth();
-            int curScreen = 0;
+            int lastVisiblePageIndex = 0;
 
-            int count = getChildCount();
-            for (int i = 0; i < count; i++) {
-                View currPage = getPageAt(i);
+            for (int currPageIndex = 0; currPageIndex < pageCount; currPageIndex++) {
+                View currPage = getPageAt(currPageIndex);
 
                 sTmpIntPoint[0] = 0;
                 Utilities.getDescendantCoordRelativeToParent(currPage, this, sTmpIntPoint, false);
@@ -1064,13 +1066,13 @@
                         break;
                     }
                 }
-                curScreen = i;
                 if (range[0] < 0) {
-                    range[0] = curScreen;
+                    range[0] = currPageIndex;
                 }
+                lastVisiblePageIndex = currPageIndex;
             }
 
-            range[1] = curScreen;
+            range[1] = lastVisiblePageIndex;
         } else {
             range[0] = -1;
             range[1] = -1;