Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b5c4d110 authored by Alex Chau's avatar Alex Chau
Browse files

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
parent e6583cbb
Loading
Loading
Loading
Loading
+5 −7
Original line number Diff line number Diff line
@@ -52,7 +52,7 @@ public class ClearAllButton extends Button implements PageCallbacks {
    private float mGridTranslationPrimary;
    private float mGridTranslationSecondary;
    private float mGridScrollOffset;
    private float mOffsetTranslationPrimary;
    private float mScrollOffsetPrimary;

    private int mSidePadding;

@@ -144,9 +144,8 @@ public class ClearAllButton extends Button implements PageCallbacks {
        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 @@ public class ClearAllButton extends Button implements PageCallbacks {
        if (gridEnabled) {
            scrollAdjustment += mGridTranslationPrimary + mGridScrollOffset;
        }
        scrollAdjustment += mOffsetTranslationPrimary;
        scrollAdjustment += mScrollOffsetPrimary;
        return scrollAdjustment;
    }

@@ -181,8 +180,7 @@ public class ClearAllButton extends Button implements PageCallbacks {
        PagedOrientationHandler orientationHandler = recentsView.getPagedOrientationHandler();
        orientationHandler.getPrimaryViewTranslate().set(this,
                orientationHandler.getPrimaryValue(0f, getOriginalTranslationY())
                        + mNormalTranslationPrimary + mOffsetTranslationPrimary + getGridTrans(
                        mGridTranslationPrimary));
                        + mNormalTranslationPrimary + getGridTrans(mGridTranslationPrimary));
    }

    private void applySecondaryTranslation() {
+5 −10
Original line number Diff line number Diff line
@@ -1192,7 +1192,6 @@ public abstract class RecentsView<T extends StatefulActivity> extends PagedView
            // 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 @@ public abstract class RecentsView<T extends StatefulActivity> extends PagedView
                    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 @@ public abstract class RecentsView<T extends StatefulActivity> extends PagedView
            }
        }

        // 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 @@ public abstract class RecentsView<T extends StatefulActivity> extends PagedView
        mClearAllButton.setGridScrollOffset(
                mIsRtl ? mLastComputedTaskSize.left - mLastComputedGridSize.left
                        : mLastComputedTaskSize.right - mLastComputedGridSize.right);
        mClearAllButton.setOffsetTranslationPrimary(offsetTranslation);

        setGridProgress(mGridProgress);
    }
+4 −16
Original line number Diff line number Diff line
@@ -295,8 +295,6 @@ public class TaskView extends FrameLayout implements PageCallbacks, Reusable {
    // 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 @@ public class TaskView extends FrameLayout implements PageCallbacks, Reusable {

    @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 @@ public class TaskView extends FrameLayout implements PageCallbacks, Reusable {
    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 @@ public class TaskView extends FrameLayout implements PageCallbacks, Reusable {
        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 class TaskView extends FrameLayout implements PageCallbacks, Reusable {
    }

    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 @@ public class TaskView extends FrameLayout implements PageCallbacks, Reusable {
    private void applyTranslationX() {
        setTranslationX(mDismissTranslationX + mTaskOffsetTranslationX + mTaskResistanceTranslationX
                + getFullscreenTrans(mFullscreenTranslationX)
                + getGridTrans(mGridTranslationX + mGridOffsetTranslationX));
                + getGridTrans(mGridTranslationX));
    }

    private void applyTranslationY() {
+4 −7
Original line number Diff line number Diff line
@@ -715,13 +715,10 @@ public abstract class PagedView<T extends View & PageIndicator> extends ViewGrou
                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;