Fixing Recents sometimes restoring in Clear-all-reveal position.

This happened if a task was added between openings of Recents.

Bug: 72222505
Test: Manual
Change-Id: Id4cc8e7cbdb493973d329466369b62e4ac8ee0b3
diff --git a/quickstep/src/com/android/quickstep/views/RecentsView.java b/quickstep/src/com/android/quickstep/views/RecentsView.java
index 6a4698f..01e5cba 100644
--- a/quickstep/src/com/android/quickstep/views/RecentsView.java
+++ b/quickstep/src/com/android/quickstep/views/RecentsView.java
@@ -345,14 +345,22 @@
 
     private float calculateClearAllButtonAlpha() {
         final int childCount = getChildCount();
-        if (mShowEmptyMessage || childCount == 0) return 0;
+        if (mShowEmptyMessage || childCount == 0 || mPageScrolls == null
+                || childCount != mPageScrolls.length) {
+            return 0;
+        }
 
         final int scrollEnd = getScrollEnd();
         final int oldestChildScroll = getScrollForPage(childCount - 1);
 
-        return Utilities.boundToRange(
-                ((float) (getScrollX() - oldestChildScroll)) /
-                        (scrollEnd - oldestChildScroll), 0, 1);
+        final int clearAllButtonMotionRange = scrollEnd - oldestChildScroll;
+        if (clearAllButtonMotionRange == 0) return 0;
+
+        final float alphaUnbound = ((float) (getScrollX() - oldestChildScroll)) /
+                clearAllButtonMotionRange;
+        if (alphaUnbound > 1) return 0;
+
+        return Math.max(alphaUnbound, 0);
     }
 
     private void updateClearAllButtonAlpha() {
diff --git a/src/com/android/launcher3/PagedView.java b/src/com/android/launcher3/PagedView.java
index eb816c5..a98867d 100644
--- a/src/com/android/launcher3/PagedView.java
+++ b/src/com/android/launcher3/PagedView.java
@@ -109,7 +109,7 @@
     private float mLastMotionXRemainder;
     private float mTotalMotionX;
 
-    private int[] mPageScrolls;
+    protected int[] mPageScrolls;
 
     protected final static int TOUCH_STATE_REST = 0;
     protected final static int TOUCH_STATE_SCROLLING = 1;