Changes page alignment in PagedView calcualtion

- Align pages to right (instead of left) in RTL, to make scroll calculation for grid overview easier for out of orientation tasks
- Changed TaskView pivot direction to be consistent with page alignment
- Add scroll offset for ClearAllButton to align to left in RTL
- Fixed Workspace scroll issues in RTL, and removed needs to use panelCount when calculating page scroll

Bug: 175939487
Test: Test carousel/grid overveiw, Workspace, Folder scroll view for normal/RTL
Change-Id: Ic0ba88e5d58638e1149d97a68a978d80fbf26774
diff --git a/quickstep/src/com/android/quickstep/views/ClearAllButton.java b/quickstep/src/com/android/quickstep/views/ClearAllButton.java
index 12b59d0..ff78995 100644
--- a/quickstep/src/com/android/quickstep/views/ClearAllButton.java
+++ b/quickstep/src/com/android/quickstep/views/ClearAllButton.java
@@ -52,7 +52,7 @@
     private float mGridTranslationPrimary;
     private float mGridTranslationSecondary;
     private float mGridScrollOffset;
-    private float mOffsetTranslationPrimary;
+    private float mScrollOffsetPrimary;
 
     private int mSidePadding;
 
@@ -144,9 +144,8 @@
         mGridScrollOffset = gridScrollOffset;
     }
 
-    public void setOffsetTranslationPrimary(float offsetTranslationPrimary) {
-        mOffsetTranslationPrimary = offsetTranslationPrimary;
-        applyPrimaryTranslation();
+    public void setScrollOffsetPrimary(float scrollOffsetPrimary) {
+        mScrollOffsetPrimary = scrollOffsetPrimary;
     }
 
     public float getScrollAdjustment(boolean gridEnabled) {
@@ -154,7 +153,7 @@
         if (gridEnabled) {
             scrollAdjustment += mGridTranslationPrimary + mGridScrollOffset;
         }
-        scrollAdjustment += mOffsetTranslationPrimary;
+        scrollAdjustment += mScrollOffsetPrimary;
         return scrollAdjustment;
     }
 
@@ -181,8 +180,7 @@
         PagedOrientationHandler orientationHandler = recentsView.getPagedOrientationHandler();
         orientationHandler.getPrimaryViewTranslate().set(this,
                 orientationHandler.getPrimaryValue(0f, getOriginalTranslationY())
-                        + mNormalTranslationPrimary + mOffsetTranslationPrimary + getGridTrans(
-                        mGridTranslationPrimary));
+                        + mNormalTranslationPrimary + getGridTrans(mGridTranslationPrimary));
     }
 
     private void applySecondaryTranslation() {
diff --git a/quickstep/src/com/android/quickstep/views/RecentsView.java b/quickstep/src/com/android/quickstep/views/RecentsView.java
index a35580f..ad266ce 100644
--- a/quickstep/src/com/android/quickstep/views/RecentsView.java
+++ b/quickstep/src/com/android/quickstep/views/RecentsView.java
@@ -1192,7 +1192,6 @@
             // Compensate page spacing widening caused by RecentsView scaling.
             widthDiff += mPageSpacing * (1 - 1 / mFullscreenScale);
             float fullscreenTranslationX = mIsRtl ? widthDiff : -widthDiff;
-            fullscreenTranslations[i] += fullscreenTranslationX;
             accumulatedTranslationX += fullscreenTranslationX;
         }
 
@@ -1203,6 +1202,11 @@
                     fullscreenTranslations[i] - fullscreenTranslations[firstNonHomeTaskIndex]);
         }
 
+        // Align ClearAllButton to the left (RTL) or right (non-RTL), which is different from other
+        // TaskViews.
+        int clearAllWidthDiff = mTaskWidth - mClearAllButton.getWidth();
+        mClearAllButton.setScrollOffsetPrimary(mIsRtl ? clearAllWidthDiff : -clearAllWidthDiff);
+
         updateGridProperties(false);
     }
 
@@ -1746,20 +1750,12 @@
             }
         }
 
-        // If the first non-home task does not take full width of task Rect, shift all tasks
-        // accordingly without affecting scrolls.
-        int firstTaskWidth = getTaskViewAt(firstNonHomeTaskIndex).getLayoutParams().width;
-        float firstNonHomeTaskOffset = firstTaskWidth == ViewGroup.LayoutParams.MATCH_PARENT ? 0
-                : mTaskWidth - firstTaskWidth;
-        float offsetTranslation = mIsRtl ? firstNonHomeTaskOffset : -firstNonHomeTaskOffset;
-
         // We need to maintain first non-home task's grid translation at 0, now shift translation
         // of all the TaskViews to achieve that.
         for (int i = firstNonHomeTaskIndex; i < taskCount; i++) {
             TaskView taskView = getTaskViewAt(i);
             taskView.setGridTranslationX(
                     gridTranslations[i] - gridTranslations[firstNonHomeTaskIndex]);
-            taskView.setGridOffsetTranslationX(offsetTranslation);
         }
 
         // Use the accumulated translation of the longer row.
@@ -1803,7 +1799,6 @@
         mClearAllButton.setGridScrollOffset(
                 mIsRtl ? mLastComputedTaskSize.left - mLastComputedGridSize.left
                         : mLastComputedTaskSize.right - mLastComputedGridSize.right);
-        mClearAllButton.setOffsetTranslationPrimary(offsetTranslation);
 
         setGridProgress(mGridProgress);
     }
diff --git a/quickstep/src/com/android/quickstep/views/TaskView.java b/quickstep/src/com/android/quickstep/views/TaskView.java
index d497a96..21b1164 100644
--- a/quickstep/src/com/android/quickstep/views/TaskView.java
+++ b/quickstep/src/com/android/quickstep/views/TaskView.java
@@ -295,8 +295,6 @@
     // The following grid translations scales with mGridProgress.
     private float mGridTranslationX;
     private float mGridTranslationY;
-    // Offset translation does not affect scroll calculation.
-    private float mGridOffsetTranslationX;
 
     private ObjectAnimator mIconAndDimAnimator;
     private float mIconScaleAnimStartProgress = 0;
@@ -792,8 +790,7 @@
 
     @Override
     public void onRecycle() {
-        mFullscreenTranslationX = mGridTranslationX =
-                mGridTranslationY = mGridOffsetTranslationX = mBoxTranslationY = 0f;
+        mFullscreenTranslationX = mGridTranslationX = mGridTranslationY = mBoxTranslationY = 0f;
         resetViewTransforms();
         // Clear any references to the thumbnail (it will be re-read either from the cache or the
         // system on next bind)
@@ -874,7 +871,7 @@
     protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
         super.onLayout(changed, left, top, right, bottom);
         if (mActivity.getDeviceProfile().isTablet && FeatureFlags.ENABLE_OVERVIEW_GRID.get()) {
-            setPivotX(getLayoutDirection() == LAYOUT_DIRECTION_RTL ? (right - left) : 0);
+            setPivotX(getLayoutDirection() == LAYOUT_DIRECTION_RTL ? 0 : right - left);
             setPivotY(mSnapshotView.getTop());
         } else {
             setPivotX((right - left) * 0.5f);
@@ -979,11 +976,6 @@
         return mGridTranslationY;
     }
 
-    public void setGridOffsetTranslationX(float gridOffsetTranslationX) {
-        mGridOffsetTranslationX = gridOffsetTranslationX;
-        applyTranslationX();
-    }
-
     public float getScrollAdjustment(boolean fullscreenEnabled, boolean gridEnabled) {
         float scrollAdjustment = 0;
         if (fullscreenEnabled) {
@@ -996,11 +988,7 @@
     }
 
     public float getOffsetAdjustment(boolean fullscreenEnabled,boolean gridEnabled) {
-        float offsetAdjustment = getScrollAdjustment(fullscreenEnabled, gridEnabled);
-        if (gridEnabled) {
-            offsetAdjustment += mGridOffsetTranslationX;
-        }
-        return offsetAdjustment;
+        return getScrollAdjustment(fullscreenEnabled, gridEnabled);
     }
 
     public float getSizeAdjustment(boolean fullscreenEnabled) {
@@ -1019,7 +1007,7 @@
     private void applyTranslationX() {
         setTranslationX(mDismissTranslationX + mTaskOffsetTranslationX + mTaskResistanceTranslationX
                 + getFullscreenTrans(mFullscreenTranslationX)
-                + getGridTrans(mGridTranslationX + mGridOffsetTranslationX));
+                + getGridTrans(mGridTranslationX));
     }
 
     private void applyTranslationY() {
diff --git a/src/com/android/launcher3/PagedView.java b/src/com/android/launcher3/PagedView.java
index 76885cc..01f7c71 100644
--- a/src/com/android/launcher3/PagedView.java
+++ b/src/com/android/launcher3/PagedView.java
@@ -715,13 +715,10 @@
                 final int primaryDimension = bounds.primaryDimension;
                 final int childPrimaryEnd = bounds.childPrimaryEnd;
 
-                // In case the pages are of different width, align the page to left or right edge
-                // based on the orientation.
-                // In case we have multiple panels on the screen, scrollOffsetEnd is the scroll
-                // needed for the whole visible area, so we have to divide it by panelCount.
-                final int pageScroll = mIsRtl
-                        ? (childStart - scrollOffsetStart)
-                        : Math.max(0, childPrimaryEnd - scrollOffsetEnd / getPanelCount());
+                // In case the pages are of different width, align the page to left edge for non-RTL
+                // or right edge for RTL.
+                final int pageScroll =
+                        mIsRtl ? childPrimaryEnd - scrollOffsetEnd : childStart - scrollOffsetStart;
                 if (outPageScrolls[i] != pageScroll) {
                     pageScrollChanged = true;
                     outPageScrolls[i] = pageScroll;