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

Commit 9539c052 authored by Jeremy Sim's avatar Jeremy Sim Committed by Android (Google) Code Review
Browse files

Merge "Improve the fling gesture for dividers" into main

parents 0ecadf81 fd197e73
Loading
Loading
Loading
Loading
+32 −2
Original line number Diff line number Diff line
@@ -212,9 +212,9 @@ public class DividerSnapAlgorithm {
            return snap(position, hardToDismiss);
        }
        if (velocity < 0) {
            return mFirstSplitTarget;
            return Flags.enableFlexibleTwoAppSplit() ? snapToPrev(position) : mFirstSplitTarget;
        } else {
            return mLastSplitTarget;
            return Flags.enableFlexibleTwoAppSplit() ? snapToNext(position) : mLastSplitTarget;
        }
    }

@@ -331,6 +331,36 @@ public class DividerSnapAlgorithm {
        return mTargets.get(minIndex);
    }

    /**
     * From the given position, returns the closest SnapTarget on the left/top side. If there is
     * no such target, return the left/top-most target.
     */
    private SnapTarget snapToPrev(int position) {
        // Iterate backwards until we reach the first target "smaller" than the given position.
        for (int i = mTargets.size() - 1; i >= 0; i--) {
            SnapTarget currentTarget = mTargets.get(i);
            if (currentTarget.getPosition() < position) {
                return currentTarget;
            }
        }
        return mDismissStartTarget;
    }

    /**
     * From the given position, returns the closest SnapTarget on the right/bottom side. If there is
     * no such target, return the right/bottom-most target.
     */
    private SnapTarget snapToNext(int position) {
        // Iterate until we reach the first target "larger" than the given position.
        for (int i = 0; i < mTargets.size(); i++) {
            SnapTarget currentTarget = mTargets.get(i);
            if (currentTarget.getPosition() > position) {
                return currentTarget;
            }
        }
        return mDismissEndTarget;
    }

    private void calculateTargets() {
        mTargets.clear();
        int dividerMax = mIsLeftRightSplit