Merge "Cleaning up scrollbar logic to properly calculate stable extents." into ub-launcher3-calgary
diff --git a/src/com/android/launcher3/LauncherStateTransitionAnimation.java b/src/com/android/launcher3/LauncherStateTransitionAnimation.java
index e94153d..6843d60 100644
--- a/src/com/android/launcher3/LauncherStateTransitionAnimation.java
+++ b/src/com/android/launcher3/LauncherStateTransitionAnimation.java
@@ -252,7 +252,10 @@
         playCommonTransitionAnimations(toWorkspaceState, fromView, toView,
                 animated, initialized, animation, revealDuration, layerViews);
         if (!animated || !initialized) {
-
+            if (FeatureFlags.LAUNCHER3_ALL_APPS_PULL_UP &&
+                    toWorkspaceState == Workspace.State.NORMAL_HIDDEN) {
+                mAllAppsController.finishPullUp();
+            }
             toView.setTranslationX(0.0f);
             toView.setTranslationY(0.0f);
             toView.setScaleX(1.0f);
@@ -672,7 +675,8 @@
         playCommonTransitionAnimations(toWorkspaceState, fromView, toView,
                 animated, initialized, animation, revealDuration, layerViews);
         if (!animated || !initialized) {
-            if (FeatureFlags.LAUNCHER3_ALL_APPS_PULL_UP) {
+            if (FeatureFlags.LAUNCHER3_ALL_APPS_PULL_UP &&
+                    fromWorkspaceState == Workspace.State.NORMAL_HIDDEN) {
                 mAllAppsController.finishPullDown();
             }
             fromView.setVisibility(View.GONE);
diff --git a/src/com/android/launcher3/allapps/AllAppsContainerView.java b/src/com/android/launcher3/allapps/AllAppsContainerView.java
index a9cc8f3..fc1288d 100644
--- a/src/com/android/launcher3/allapps/AllAppsContainerView.java
+++ b/src/com/android/launcher3/allapps/AllAppsContainerView.java
@@ -269,8 +269,9 @@
         if (mAppsRecyclerView.getScrollBar().isNearThumb(point[0], point[1])) {
             return false;
         }
-        // If scroller is at the very top, then it's okay for the container to be pulled down.
-        if (Float.compare(0f, mAppsRecyclerView.getScrollBar().getThumbOffset().y) == 0) {
+        // IF scroller is at the very top OR there is no scroll bar because there is probably not
+        // enough items to scroll, THEN it's okay for the container to be pulled down.
+        if (mAppsRecyclerView.getScrollBar().getThumbOffset().y <= 0) {
             return true;
         }
         return false;
@@ -290,6 +291,7 @@
      */
     public void reset() {
         // Reset the search bar and base recycler view after transitioning home
+        scrollToTop();
         mSearchBarController.reset();
         mAppsRecyclerView.reset();
     }
@@ -380,14 +382,13 @@
 
     @Override
     protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
-        updatePaddingsAndMargins();
-        mContentBounds.set(mHorizontalPadding, 0,
-                MeasureSpec.getSize(widthMeasureSpec) - mHorizontalPadding,
-                MeasureSpec.getSize(heightMeasureSpec));
+        int widthPx = MeasureSpec.getSize(widthMeasureSpec);
+        int heightPx = MeasureSpec.getSize(heightMeasureSpec);
+        updatePaddingsAndMargins(widthPx, heightPx);
+        mContentBounds.set(mHorizontalPadding, 0, widthPx - mHorizontalPadding, heightPx);
 
         DeviceProfile grid = mLauncher.getDeviceProfile();
-        int availableWidth = (!mContentBounds.isEmpty() ? mContentBounds.width() :
-                MeasureSpec.getSize(widthMeasureSpec))
+        int availableWidth = (!mContentBounds.isEmpty() ? mContentBounds.width() : widthPx)
                 - 2 * mAppsRecyclerView.getMaxScrollbarWidth();
         grid.updateAppsViewNumCols(getResources(), availableWidth);
         if (FeatureFlags.LAUNCHER3_ALL_APPS_PULL_UP) {
@@ -453,7 +454,7 @@
      * container view, we inset the background and padding of the recycler view to allow for the
      * recycler view to handle touch events (for fast scrolling) all the way to the edge.
      */
-    private void updatePaddingsAndMargins() {
+    private void updatePaddingsAndMargins(int widthPx, int heightPx) {
         Rect bgPadding = new Rect();
         getRevealView().getBackground().getPadding(bgPadding);
 
@@ -480,11 +481,7 @@
         // Clip the view to the left and right edge of the background to
         // to prevent shadows from rendering beyond the edges
         final Rect newClipBounds = new Rect(
-                bgPadding.left,
-                0,
-                getWidth() - bgPadding.right,
-                getHeight()
-        );
+                bgPadding.left, 0, widthPx - bgPadding.right, heightPx);
         setClipBounds(newClipBounds);
 
         // Allow the overscroll effect to reach the edges of the view
diff --git a/src/com/android/launcher3/allapps/AllAppsTransitionController.java b/src/com/android/launcher3/allapps/AllAppsTransitionController.java
index b42b762..028f065 100644
--- a/src/com/android/launcher3/allapps/AllAppsTransitionController.java
+++ b/src/com/android/launcher3/allapps/AllAppsTransitionController.java
@@ -256,7 +256,7 @@
     }
 
     private void updateLightStatusBar(float progress) {
-        boolean enable = (progress < mStatusBarHeight / 2);
+        boolean enable = progress <= mStatusBarHeight / 2;
         // Do not modify status bar on landscape as all apps is not full bleed.
         if (mLauncher.getDeviceProfile().isVerticalBarLayout()) {
             return;
@@ -404,7 +404,7 @@
         }
     }
 
-    private void finishPullUp() {
+    public void finishPullUp() {
         mHotseat.setVisibility(View.INVISIBLE);
         setProgress(0f);
     }