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

Commit 8be6c710 authored by Alex Chau's avatar Alex Chau
Browse files

Don't create gap between last task and clear all button

- If a task is too close to ClearAllButton when being snapped to, change the snap position to barely not seeing ClearAllButton
- When snapping to the above tasks from quick switch, apply a horizontal grid translation to smoothly snap into  position
- Apply the above grid translation to TaskViewSimulator as well

Bug: 192254835
Test: manual
Change-Id: I32d562a1726f7c8b41ac10c7deece890df7e1304
parent cd777a3f
Loading
Loading
Loading
Loading
+3 −5
Original line number Diff line number Diff line
@@ -1026,9 +1026,6 @@ public abstract class AbsSwipeUpHandler<T extends StatefulActivity<S>,
            if (mRecentsView != null) {
                int nearestPage = mRecentsView.getDestinationPage();
                boolean isScrolling = false;
                // Update page scroll before snapping to page to make sure we snapped to the
                // position calculated with target gesture in mind.
                mRecentsView.updateScrollSynchronously();
                if (mRecentsView.getNextPage() != nearestPage) {
                    // We shouldn't really scroll to the next page when swiping up to recents.
                    // Only allow settling on the next page if it's nearest to the center.
@@ -1187,7 +1184,8 @@ public abstract class AbsSwipeUpHandler<T extends StatefulActivity<S>,
            mLauncherTransitionController = null;

            if (mRecentsView != null) {
                mRecentsView.onPrepareGestureEndAnimation(null, mGestureState.getEndTarget());
                mRecentsView.onPrepareGestureEndAnimation(null, mGestureState.getEndTarget(),
                        mTaskViewSimulator);
            }
        } else {
            AnimatorSet animatorSet = new AnimatorSet();
@@ -1229,7 +1227,7 @@ public abstract class AbsSwipeUpHandler<T extends StatefulActivity<S>,
            animatorSet.play(windowAnim);
            if (mRecentsView != null) {
                mRecentsView.onPrepareGestureEndAnimation(
                        animatorSet, mGestureState.getEndTarget());
                        animatorSet, mGestureState.getEndTarget(), mTaskViewSimulator);
            }
            animatorSet.setDuration(duration).setInterpolator(interpolator);
            animatorSet.start();
+4 −2
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@ import com.android.launcher3.statemanager.StateManager.StateListener;
import com.android.quickstep.FallbackActivityInterface;
import com.android.quickstep.GestureState;
import com.android.quickstep.RecentsActivity;
import com.android.quickstep.util.TaskViewSimulator;
import com.android.quickstep.views.OverviewActionsView;
import com.android.quickstep.views.RecentsView;
import com.android.quickstep.views.SplitPlaceholderView;
@@ -89,8 +90,9 @@ public class FallbackRecentsView extends RecentsView<RecentsActivity, RecentsSta
     */
    @Override
    public void onPrepareGestureEndAnimation(
            @Nullable AnimatorSet animatorSet, GestureState.GestureEndTarget endTarget) {
        super.onPrepareGestureEndAnimation(animatorSet, endTarget);
            @Nullable AnimatorSet animatorSet, GestureState.GestureEndTarget endTarget,
            TaskViewSimulator taskViewSimulator) {
        super.onPrepareGestureEndAnimation(animatorSet, endTarget, taskViewSimulator);
        if (mHomeTaskInfo != null && endTarget == RECENTS && animatorSet != null) {
            TaskView tv = getTaskView(mHomeTaskInfo.taskId);
            if (tv != null) {
+48 −28
Original line number Diff line number Diff line
@@ -1770,24 +1770,33 @@ public abstract class RecentsView<ACTIVITY_TYPE extends StatefulActivity<STATE_T
     * Called when a gesture from an app has finished, and an end target has been determined.
     */
    public void onPrepareGestureEndAnimation(
            @Nullable AnimatorSet animatorSet, GestureState.GestureEndTarget endTarget) {
            @Nullable AnimatorSet animatorSet, GestureState.GestureEndTarget endTarget,
            TaskViewSimulator taskViewSimulator) {
        mCurrentGestureEndTarget = endTarget;
        if (endTarget == GestureState.GestureEndTarget.RECENTS) {
            setEnableFreeScroll(true);
            updateGridProperties();
        }

        if (mSizeStrategy.stateFromGestureEndTarget(endTarget)
                .displayOverviewTasksAsGrid(mActivity.getDeviceProfile())) {
            TaskView runningTaskView = getRunningTaskView();
            float runningTaskPrimaryGridTranslation = 0;
            if (indexOfChild(runningTaskView) != getNextPage()) {
                // Apply the gird translation to running task unless it's being snapped to.
                runningTaskPrimaryGridTranslation = mOrientationHandler.getPrimaryValue(
                        runningTaskView.getGridTranslationX(),
                        runningTaskView.getGridTranslationY());
            }
            if (animatorSet == null) {
                setGridProgress(1);
                taskViewSimulator.taskPrimaryTranslation.value = runningTaskPrimaryGridTranslation;
            } else {
                animatorSet.play(ObjectAnimator.ofFloat(this, RECENTS_GRID_PROGRESS, 1));
                animatorSet.play(taskViewSimulator.taskPrimaryTranslation.animateToValue(
                        runningTaskPrimaryGridTranslation));
            }
        }
        mCurrentGestureEndTarget = endTarget;
        if (endTarget == GestureState.GestureEndTarget.NEW_TASK
                || endTarget == GestureState.GestureEndTarget.LAST_TASK) {
            // When switching to tasks in quick switch, ensures the snapped page's scroll maintain
            // invariant between quick switch and overview, to ensure a smooth animation transition.
            updateGridProperties();
        } else if (endTarget == GestureState.GestureEndTarget.RECENTS) {
            setEnableFreeScroll(true);
        }
    }

    /**
@@ -2075,12 +2084,6 @@ public abstract class RecentsView<ACTIVITY_TYPE extends StatefulActivity<STATE_T
            snappedTaskGridTranslationX = gridTranslations[snappedPage - mTaskViewStartIndex];
        }

        for (int i = 0; i < taskCount; i++) {
            TaskView taskView = getTaskViewAt(i);
            taskView.setGridTranslationX(gridTranslations[i] - snappedTaskGridTranslationX
                    + snappedTaskNonGridScrollAdjustment);
        }

        // Use the accumulated translation of the row containing the last task.
        float clearAllAccumulatedTranslation = topSet.contains(taskCount - 1)
                ? topAccumulatedTranslationX : bottomAccumulatedTranslationX;
@@ -2123,17 +2126,23 @@ public abstract class RecentsView<ACTIVITY_TYPE extends StatefulActivity<STATE_T
        // Make sure there are enough space between snapped page and ClearAllButton, for the case
        // of swiping up after quick switch.
        if (snappedTaskView != null) {
            int distanceFromClearAll = longRowWidth - snappedTaskRowWidth;
            int distanceFromClearAll = longRowWidth - snappedTaskRowWidth + mPageSpacing;
            // ClearAllButton should be off screen when snapped task is in its snapped position.
            int minimumDistance =
                    mTaskWidth - snappedTaskView.getLayoutParams().width
                            + (mLastComputedGridSize.width() - mTaskWidth) / 2;
            if (distanceFromClearAll < minimumDistance) {
                int distanceDifference = minimumDistance - distanceFromClearAll;
                clearAllTotalTranslationX += mIsRtl ? -distanceDifference : distanceDifference;
                snappedTaskGridTranslationX += mIsRtl ? distanceDifference : -distanceDifference;
            }
        }

        for (int i = 0; i < taskCount; i++) {
            TaskView taskView = getTaskViewAt(i);
            taskView.setGridTranslationX(gridTranslations[i] - snappedTaskGridTranslationX
                    + snappedTaskNonGridScrollAdjustment);
        }

        mClearAllButton.setGridTranslationPrimary(
                clearAllTotalTranslationX - snappedTaskGridTranslationX);
        mClearAllButton.setGridScrollOffset(
@@ -2865,6 +2874,7 @@ public abstract class RecentsView<ACTIVITY_TYPE extends StatefulActivity<STATE_T
        mLastComputedTaskStartPushOutDistance = null;
        mLastComputedTaskEndPushOutDistance = null;
        updatePageOffsets();
        mLiveTileTaskViewSimulator.setScroll(getScrollOffset());
        setImportantForAccessibility(isModal() ? IMPORTANT_FOR_ACCESSIBILITY_NO
                : IMPORTANT_FOR_ACCESSIBILITY_AUTO);
    }
@@ -3627,18 +3637,28 @@ public abstract class RecentsView<ACTIVITY_TYPE extends StatefulActivity<STATE_T
        }

        boolean pageScrollChanged = false;
        final int childCount = getChildCount();
        for (int i = 0; i < childCount; i++) {
            View child = getChildAt(i);
            float scrollDiff = 0;
            if (child instanceof TaskView) {
                scrollDiff = ((TaskView) child).getScrollAdjustment(showAsFullscreen, showAsGrid);
            } else if (child instanceof ClearAllButton) {
                scrollDiff = ((ClearAllButton) child).getScrollAdjustment(showAsFullscreen,
                        showAsGrid);

        int clearAllIndex = indexOfChild(mClearAllButton);
        int clearAllScroll = 0;
        int clearAllWidth = mOrientationHandler.getPrimarySize(mClearAllButton);
        if (clearAllIndex != -1 && clearAllIndex < outPageScrolls.length) {
            float scrollDiff = mClearAllButton.getScrollAdjustment(showAsFullscreen, showAsGrid);
            clearAllScroll = newPageScrolls[clearAllIndex] + (int) scrollDiff;
            if (outPageScrolls[clearAllIndex] != clearAllScroll) {
                pageScrollChanged = true;
                outPageScrolls[clearAllIndex] = clearAllScroll;
            }
        }

            final int pageScroll = newPageScrolls[i] + (int) scrollDiff;
        final int taskCount = getTaskViewCount();
        for (int i = 0; i < taskCount; i++) {
            TaskView taskView = getTaskViewAt(i);
            float scrollDiff = taskView.getScrollAdjustment(showAsFullscreen, showAsGrid);
            int pageScroll = newPageScrolls[i + mTaskViewStartIndex] + (int) scrollDiff;
            if ((mIsRtl && pageScroll < clearAllScroll)
                    || (!mIsRtl && pageScroll > clearAllScroll)) {
                pageScroll = clearAllScroll + (mIsRtl ? clearAllWidth : -clearAllWidth);
            }
            if (outPageScrolls[i] != pageScroll) {
                pageScrollChanged = true;
                outPageScrolls[i] = pageScroll;