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

Commit 06ddebb3 authored by helencheuk's avatar helencheuk
Browse files

Fix wrong translation for swiping up split task

The wrong calculation is caused by using half size mTaskRect in Split task to calculate the translation X to middle
It should use the fullTaskSize instead of half size. This change refactors the code to store the full size so it does not need to re-calculate many times

Bug: 312371505
Test: Manual, swiping up split task diagonally from right side many times, test the case when mSplitBounds is not null in addAppToOverviewAnim
Test: Tested swipe up to overview for split task/single task in Phone, Tablet and Unfolded phone, with the flag on and off
Flag: ACONFIG com.android.launcher3.enable_grid_only_overview TEAMFOOD
Change-Id: Id2b008a7d9597271e077a125f3195b27196797d7
parent df20ea0e
Loading
Loading
Loading
Loading
+43 −32
Original line number Diff line number Diff line
@@ -74,6 +74,7 @@ public class TaskViewSimulator implements TransformParams.BuilderProxy {
    private final boolean mIsRecentsRtl;

    private final Rect mTaskRect = new Rect();
    private final Rect mFullTaskSize = new Rect();
    private final PointF mPivot = new PointF();
    private DeviceProfile mDp;
    @StagePosition
@@ -131,38 +132,27 @@ public class TaskViewSimulator implements TransformParams.BuilderProxy {
        mDp = dp;
        mLayoutValid = false;
        mOrientationState.setDeviceProfile(dp);
        calculateTaskSize();
    }

    /**
     * Sets the orientation state used for this animation
     */
    public void setOrientationState(@NonNull RecentsOrientedState orientationState) {
        mOrientationState = orientationState;
        mLayoutValid = false;
    }

    /**
     * @see com.android.quickstep.views.RecentsView#FULLSCREEN_PROGRESS
     */
    public float getFullScreenScale() {
    private void calculateTaskSize() {
        if (mDp == null) {
            return 1;
            return;
        }

        if (mIsGridTask) {
            mSizeStrategy.calculateGridTaskSize(mContext, mDp, mTaskRect,
            mSizeStrategy.calculateGridTaskSize(mContext, mDp, mFullTaskSize,
                    mOrientationState.getOrientationHandler());
        } else {
            mSizeStrategy.calculateTaskSize(mContext, mDp, mTaskRect,
            mSizeStrategy.calculateTaskSize(mContext, mDp, mFullTaskSize,
                    mOrientationState.getOrientationHandler());
        }

        Rect fullTaskSize;
        if (mSplitBounds != null) {
            // The task rect changes according to the staged split task sizes, but recents
            // fullscreen scale and pivot remains the same since the task fits into the existing
            // sized task space bounds
            fullTaskSize = new Rect(mTaskRect);
            mTaskRect.set(mFullTaskSize);
            mOrientationState.getOrientationHandler()
                    .setSplitTaskSwipeRect(mDp, mTaskRect, mSplitBounds, mStagePosition);
            mTaskRect.offset(mTaskRectTranslationX, mTaskRectTranslationY);
@@ -171,21 +161,40 @@ public class TaskViewSimulator implements TransformParams.BuilderProxy {
            // Full task size represents the whole screen size, but scaled down to fit in recents.
            // Task rect will represent the scaled down thumbnail position and is placed inside
            // full task size as it is on the home screen.
            fullTaskSize = new Rect(mTaskRect);
            PointF fullscreenTaskDimension = new PointF();
            BaseActivityInterface.getTaskDimension(mContext, mDp, fullscreenTaskDimension);
            // Calculate the scale down factor used in recents
            float scale = fullTaskSize.width() / fullscreenTaskDimension.x;
            float scale = mFullTaskSize.width() / fullscreenTaskDimension.x;
            mTaskRect.set(mThumbnailPosition);
            mTaskRect.scale(scale);
            // Ensure the task rect is inside the full task rect
            mTaskRect.offset(fullTaskSize.left, fullTaskSize.top);
            mTaskRect.offset(mFullTaskSize.left, mFullTaskSize.top);
        } else {
            fullTaskSize = new Rect(mTaskRect);
            mTaskRect.set(mFullTaskSize);
            mTaskRect.offset(mTaskRectTranslationX, mTaskRectTranslationY);
        }
        fullTaskSize.offset(mTaskRectTranslationX + mPivotOffsetX, mTaskRectTranslationY);
        return mOrientationState.getFullScreenScaleAndPivot(fullTaskSize, mDp, mPivot);
    }

    /**
     * Sets the orientation state used for this animation
     */
    public void setOrientationState(@NonNull RecentsOrientedState orientationState) {
        mOrientationState = orientationState;
        mLayoutValid = false;
    }

    /**
     * @see com.android.quickstep.views.RecentsView#FULLSCREEN_PROGRESS
     */
    public float getFullScreenScale() {
        if (mDp == null) {
            return 1;
        }
        // Copy mFullTaskSize instead of updating it directly so it could be reused next time
        // without recalculating
        Rect scaleRect = new Rect(mFullTaskSize);
        scaleRect.offset(mTaskRectTranslationX + mPivotOffsetX, mTaskRectTranslationY);
        return mOrientationState.getFullScreenScaleAndPivot(scaleRect, mDp, mPivot);
    }

    /**
@@ -209,14 +218,14 @@ public class TaskViewSimulator implements TransformParams.BuilderProxy {
        mSplitBounds = splitInfo;
        if (mSplitBounds == null) {
            mStagePosition = STAGE_POSITION_UNDEFINED;
            return;
        }
        mStagePosition = mThumbnailPosition.equals(splitInfo.leftTopBounds) ?
                STAGE_POSITION_TOP_OR_LEFT :
                STAGE_POSITION_BOTTOM_OR_RIGHT;
        } else {
            mStagePosition = mThumbnailPosition.equals(splitInfo.leftTopBounds)
                    ? STAGE_POSITION_TOP_OR_LEFT : STAGE_POSITION_BOTTOM_OR_RIGHT;
            mPositionHelper.setSplitBounds(convertLauncherSplitBoundsToShell(mSplitBounds),
                    mStagePosition);
        }
        calculateTaskSize();
    }

    /**
     * Sets the targets which the simulator will control
@@ -261,6 +270,8 @@ public class TaskViewSimulator implements TransformParams.BuilderProxy {
    public void setTaskRectTranslation(int taskRectTranslationX, int taskRectTranslationY) {
        mTaskRectTranslationX = taskRectTranslationX;
        mTaskRectTranslationY = taskRectTranslationY;
        // Re-calculate task size after changing translation
        calculateTaskSize();
    }

    /**
@@ -269,7 +280,7 @@ public class TaskViewSimulator implements TransformParams.BuilderProxy {
    public void addAppToOverviewAnim(PendingAnimation pa, TimeInterpolator interpolator) {
        pa.addFloat(fullScreenProgress, AnimatedFloat.VALUE, 1, 0, interpolator);
        if (enableGridOnlyOverview() && mDp.isTablet) {
            int translationXToMiddle = mDp.widthPx / 2 - mTaskRect.centerX();
            int translationXToMiddle = mDp.widthPx / 2 - mFullTaskSize.centerX();
            taskPrimaryTranslation.value = translationXToMiddle;
            mPivotOffsetX = translationXToMiddle;
        }