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

Commit fd197e73 authored by Jeremy Sim's avatar Jeremy Sim
Browse files

Improve the fling gesture for dividers

Previously, flinging the divider would always send it all the way to the other side of the screen (mFirstSplitTarget and mLastSplitTarget to be precise). With more snap targets on-screen with flexible split, this started to feel janky.

Now, a fling gesture will send it to the closest snap target in the direction of the fling.

Fixes: 428784487
Flag: com.android.wm.shell.enable_flexible_two_app_split
Test: Manual
Change-Id: Ie1b7544c99cdef134023fd11bfae74add2684794
parent 84512d9b
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