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

Commit 04484049 authored by Jordan Silva's avatar Jordan Silva
Browse files

Extracting handheld task dismiss translation to smaller functions (2/4)

This CL extracts the logic to translate the tasks used when Overview grid is disabled (i.e., for handheld) to 2 smaller functions that will be used for desktop and grid translation in the follow up CL.

Bug: 353948136
Bug: 353948182
Flag: com.android.launcher3.enable_large_desktop_windowing_tile
Test: OverviewDesktopTaskImageTest
Change-Id: Ie25fffaaca4580a8a483003d220b4bf6cdccbc66
parent 6f231f69
Loading
Loading
Loading
Loading
+88 −66
Original line number Diff line number Diff line
@@ -3802,74 +3802,15 @@ public abstract class RecentsView<
                    }
                }
            } else if (!showAsGrid) {
                // Compute scroll offsets from task dismissal for animation.
                // If we just take newScroll - oldScroll, everything to the right of dragged task
                // translates to the left. We need to offset this in some cases:
                // - In RTL, add page offset to all pages, since we want pages to move to the right
                // Additionally, add a page offset if:
                // - Current page is rightmost page (leftmost for RTL)
                // - Dragging an adjacent page on the left side (right side for RTL)
                int offset = mIsRtl ? scrollDiffPerPage : 0;
                if (mCurrentPage == dismissedIndex) {
                    int lastPage = taskCount - 1;
                    if (mCurrentPage == lastPage) {
                        offset += mIsRtl ? -scrollDiffPerPage : scrollDiffPerPage;
                    }
                } else {
                    // Dismissing an adjacent page.
                    int negativeAdjacent = mCurrentPage - 1; // (Right in RTL, left in LTR)
                    if (dismissedIndex == negativeAdjacent) {
                        offset += mIsRtl ? -scrollDiffPerPage : scrollDiffPerPage;
                    }
                }

                int offset = getOffsetToDismissedTask(scrollDiffPerPage, dismissedIndex, taskCount);
                int scrollDiff = newScroll[i] - oldScroll[i] + offset;
                if (scrollDiff != 0) {
                    FloatProperty translationProperty = child instanceof TaskView
                            ? ((TaskView) child).getPrimaryDismissTranslationProperty()
                            : getPagedOrientationHandler().getPrimaryViewTranslate();

                    float additionalDismissDuration =
                            ADDITIONAL_DISMISS_TRANSLATION_INTERPOLATION_OFFSET * Math.abs(
                                    i - dismissedIndex);

                    // We are in non-grid layout.
                    // If dismissing for split select, use split timings.
                    // If not, use dismiss timings.
                    float animationStartProgress = isSplitSelectionActive()
                            ? Utilities.boundToRange(splitTimings.getGridSlideStartOffset(), 0f, 1f)
                            : Utilities.boundToRange(
                                    INITIAL_DISMISS_TRANSLATION_INTERPOLATION_OFFSET
                                            + additionalDismissDuration, 0f, 1f);

                    float animationEndProgress = isSplitSelectionActive()
                            ? Utilities.boundToRange(splitTimings.getGridSlideStartOffset()
                            + splitTimings.getGridSlideDurationOffset(), 0f, 1f)
                            : 1f;

                    // Slide tiles in horizontally to fill dismissed area
                    anim.setFloat(child, translationProperty, scrollDiff,
                            clampToProgress(
                                    splitTimings.getGridSlidePrimaryInterpolator(),
                                    animationStartProgress,
                                    animationEndProgress
                            )
                    );

                    if (mEnableDrawingLiveTile && child instanceof TaskView
                            && ((TaskView) child).isRunningTask()) {
                        anim.addOnFrameCallback(() -> {
                            runActionOnRemoteHandles(
                                    remoteTargetHandle ->
                                            remoteTargetHandle.getTaskViewSimulator()
                                                    .taskPrimaryTranslation.value =
                                                    getPagedOrientationHandler().getPrimaryValue(
                                                            child.getTranslationX(),
                                                            child.getTranslationY()
                                                    ));
                            redrawLiveTile();
                        });
                    }
                    translateTaskWhenDismissed(
                            child,
                            Math.abs(i - dismissedIndex),
                            mIsRtl ? -scrollDiff : scrollDiff,
                            anim,
                            splitTimings);
                    needsCurveUpdates = true;
                }
            } else if (child instanceof TaskView) {
@@ -4184,6 +4125,87 @@ public abstract class RecentsView<
        });
    }

    /**
     * Compute scroll offsets from task dismissal for animation.
     * If we just take newScroll - oldScroll, everything to the right of dragged task
     * translates to the left. We need to offset this in some cases:
     * - In RTL, add page offset to all pages, since we want pages to move to the right
     * Additionally, add a page offset if:
     * - Current page is rightmost page (leftmost for RTL)
     * - Dragging an adjacent page on the left side (right side for RTL)
     */
    private int getOffsetToDismissedTask(int scrollDiffPerPage, int dismissedIndex, int taskCount) {
        int offset = mIsRtl ? scrollDiffPerPage : 0;
        if (mCurrentPage == dismissedIndex) {
            int lastPage = taskCount - 1;
            if (mCurrentPage == lastPage) {
                offset += mIsRtl ? -scrollDiffPerPage : scrollDiffPerPage;
            }
        } else {
            // Dismissing an adjacent page.
            int negativeAdjacent = mCurrentPage - 1; // (Right in RTL, left in LTR)
            if (dismissedIndex == negativeAdjacent) {
                offset += mIsRtl ? -scrollDiffPerPage : scrollDiffPerPage;
            }
        }
        return offset;
    }

    private void translateTaskWhenDismissed(
            View view,
            int indexDiff,
            int scrollDiffPerPage,
            PendingAnimation pendingAnimation,
            SplitAnimationTimings splitTimings) {
        FloatProperty translationProperty = view instanceof TaskView
                ? ((TaskView) view).getPrimaryDismissTranslationProperty()
                : getPagedOrientationHandler().getPrimaryViewTranslate();

        float additionalDismissDuration =
                ADDITIONAL_DISMISS_TRANSLATION_INTERPOLATION_OFFSET * indexDiff;

        // We are in non-grid layout.
        // If dismissing for split select, use split timings.
        // If not, use dismiss timings.
        float animationStartProgress = isSplitSelectionActive()
                ? Utilities.boundToRange(splitTimings.getGridSlideStartOffset(), 0f, 1f)
                : Utilities.boundToRange(
                        INITIAL_DISMISS_TRANSLATION_INTERPOLATION_OFFSET
                                + additionalDismissDuration, 0f, 1f);

        float animationEndProgress = isSplitSelectionActive()
                ? Utilities.boundToRange(splitTimings.getGridSlideStartOffset()
                + splitTimings.getGridSlideDurationOffset(), 0f, 1f)
                : 1f;

        // Slide tiles in horizontally to fill dismissed area
        pendingAnimation.setFloat(
                view,
                translationProperty,
                scrollDiffPerPage,
                clampToProgress(
                        splitTimings.getGridSlidePrimaryInterpolator(),
                        animationStartProgress,
                        animationEndProgress
                )
        );

        if (mEnableDrawingLiveTile && view instanceof TaskView
                && ((TaskView) view).isRunningTask()) {
            pendingAnimation.addOnFrameCallback(() -> {
                runActionOnRemoteHandles(
                        remoteTargetHandle ->
                                remoteTargetHandle.getTaskViewSimulator()
                                        .taskPrimaryTranslation.value =
                                        getPagedOrientationHandler().getPrimaryValue(
                                                view.getTranslationX(),
                                                view.getTranslationY()
                                        ));
                redrawLiveTile();
            });
        }
    }

    /**
     * Hides all overview actions if user is halfway through split selection, shows otherwise.
     * We only show split option if: