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

Commit 67fde754 authored by Jeremy Sim's avatar Jeremy Sim
Browse files

Minor cleanup of SnapTarget

This CL removes a unused field on the SnapTarget class, taskPosition, in preparation for flexible split.
Also streamlines 2 test cases on SplitLayoutTests in a way that I think makes more sense.

Bug: 349828130
Test: Behavior is unchanged and continues to pass tests
Flag: com.android.wm.shell.enable_flexible_split
Change-Id: I0f12391b8037d5966b37ff94af38d455edb4d725
parent 7eedb2d0
Loading
Loading
Loading
Loading
+12 −18
Original line number Diff line number Diff line
@@ -235,7 +235,7 @@ public class DividerSnapAlgorithm {

    private SnapTarget snap(int position, boolean hardDismiss) {
        if (shouldApplyFreeSnapMode(position)) {
            return new SnapTarget(position, position, SNAP_TO_NONE);
            return new SnapTarget(position, SNAP_TO_NONE);
        }
        int minIndex = -1;
        float minDistance = Float.MAX_VALUE;
@@ -263,7 +263,7 @@ public class DividerSnapAlgorithm {
        if (dockedSide == DOCKED_RIGHT) {
            startPos += mInsets.left;
        }
        mTargets.add(new SnapTarget(startPos, startPos, SNAP_TO_START_AND_DISMISS, 0.35f));
        mTargets.add(new SnapTarget(startPos, SNAP_TO_START_AND_DISMISS, 0.35f));
        switch (mSnapMode) {
            case SNAP_MODE_16_9:
                addRatio16_9Targets(isHorizontalDivision, dividerMax);
@@ -278,7 +278,7 @@ public class DividerSnapAlgorithm {
                addMinimizedTarget(isHorizontalDivision, dockedSide);
                break;
        }
        mTargets.add(new SnapTarget(dividerMax, dividerMax, SNAP_TO_END_AND_DISMISS, 0.35f));
        mTargets.add(new SnapTarget(dividerMax, SNAP_TO_END_AND_DISMISS, 0.35f));
    }

    private void addNonDismissingTargets(boolean isHorizontalDivision, int topPosition,
@@ -325,14 +325,14 @@ public class DividerSnapAlgorithm {
     */
    private void maybeAddTarget(int position, int smallerSize, @SnapPosition int snapPosition) {
        if (smallerSize >= mMinimalSizeResizableTask) {
            mTargets.add(new SnapTarget(position, position, snapPosition));
            mTargets.add(new SnapTarget(position, snapPosition));
        }
    }

    private void addMiddleTarget(boolean isHorizontalDivision) {
        int position = DockedDividerUtils.calculateMiddlePosition(isHorizontalDivision,
                mInsets, mDisplayWidth, mDisplayHeight, mDividerSize);
        mTargets.add(new SnapTarget(position, position, SNAP_TO_50_50));
        mTargets.add(new SnapTarget(position, SNAP_TO_50_50));
    }

    private void addMinimizedTarget(boolean isHorizontalDivision, int dockedSide) {
@@ -346,7 +346,7 @@ public class DividerSnapAlgorithm {
                position = mDisplayWidth - position - mInsets.right - mDividerSize;
            }
        }
        mTargets.add(new SnapTarget(position, position, SNAP_TO_MINIMIZE));
        mTargets.add(new SnapTarget(position, SNAP_TO_MINIMIZE));
    }

    public SnapTarget getMiddleTarget() {
@@ -377,20 +377,15 @@ public class DividerSnapAlgorithm {
    }

    /**
     * Represents a snap target for the divider.
     * An object, calculated at boot time, representing a legal position for the split screen
     * divider (i.e. the divider can be dragged to this spot).
     */
    public static class SnapTarget {
        /** Position of this snap target. The right/bottom edge of the top/left task snaps here. */
        public final int position;

        /**
         * Like {@link #position}, but used to calculate the task bounds which might be different
         * from the stack bounds.
         */
        public final int taskPosition;

        /**
         * An int describing the placement of the divider in this snap target.
         * An int (enum) describing the placement of the divider in this snap target.
         */
        public final @SnapPosition int snapPosition;

@@ -402,14 +397,13 @@ public class DividerSnapAlgorithm {
         */
        private final float distanceMultiplier;

        public SnapTarget(int position, int taskPosition, @SnapPosition int snapPosition) {
            this(position, taskPosition, snapPosition, 1f);
        public SnapTarget(int position, @SnapPosition int snapPosition) {
            this(position, snapPosition, 1f);
        }

        public SnapTarget(int position, int taskPosition, @SnapPosition int snapPosition,
        public SnapTarget(int position, @SnapPosition int snapPosition,
                float distanceMultiplier) {
            this.position = position;
            this.taskPosition = taskPosition;
            this.snapPosition = snapPosition;
            this.distanceMultiplier = distanceMultiplier;
        }
+6 −5
Original line number Diff line number Diff line
@@ -72,11 +72,12 @@ import com.android.wm.shell.common.DisplayImeController;
import com.android.wm.shell.common.DisplayInsetsController;
import com.android.wm.shell.common.DisplayLayout;
import com.android.wm.shell.common.pip.PipUtils;
import com.android.wm.shell.common.split.DividerSnapAlgorithm.SnapTarget;
import com.android.wm.shell.protolog.ShellProtoLogGroup;
import com.android.wm.shell.shared.animation.Interpolators;
import com.android.wm.shell.shared.split.SplitScreenConstants.PersistentSnapPosition;
import com.android.wm.shell.shared.split.SplitScreenConstants.SnapPosition;
import com.android.wm.shell.shared.split.SplitScreenConstants.SplitPosition;
import com.android.wm.shell.protolog.ShellProtoLogGroup;
import com.android.wm.shell.splitscreen.StageTaskListener;

import java.io.PrintWriter;
@@ -543,7 +544,7 @@ public final class SplitLayout implements DisplayInsetsController.OnInsetsChange
     * to middle position if the provided SnapTarget is not supported.
     */
    public void setDivideRatio(@PersistentSnapPosition int snapPosition) {
        final DividerSnapAlgorithm.SnapTarget snapTarget = mDividerSnapAlgorithm.findSnapTarget(
        final SnapTarget snapTarget = mDividerSnapAlgorithm.findSnapTarget(
                snapPosition);

        setDividerPosition(snapTarget != null
@@ -577,7 +578,7 @@ public final class SplitLayout implements DisplayInsetsController.OnInsetsChange
     * Sets new divider position and updates bounds correspondingly. Notifies listener if the new
     * target indicates dismissing split.
     */
    public void snapToTarget(int currentPosition, DividerSnapAlgorithm.SnapTarget snapTarget) {
    public void snapToTarget(int currentPosition, SnapTarget snapTarget) {
        switch (snapTarget.snapPosition) {
            case SNAP_TO_START_AND_DISMISS:
                flingDividerPosition(currentPosition, snapTarget.position, FLING_RESIZE_DURATION,
@@ -613,10 +614,10 @@ public final class SplitLayout implements DisplayInsetsController.OnInsetsChange
    }

    /**
     * Returns {@link DividerSnapAlgorithm.SnapTarget} which matches passing position and velocity.
     * Returns {@link SnapTarget} which matches passing position and velocity.
     * If hardDismiss is set to {@code true}, it will be harder to reach dismiss target.
     */
    public DividerSnapAlgorithm.SnapTarget findSnapTarget(int position, float velocity,
    public SnapTarget findSnapTarget(int position, float velocity,
            boolean hardDismiss) {
        return mDividerSnapAlgorithm.calculateSnapTarget(position, velocity, hardDismiss);
    }
+4 −11
Original line number Diff line number Diff line
@@ -20,8 +20,6 @@ import static android.content.res.Configuration.ORIENTATION_LANDSCAPE;
import static android.content.res.Configuration.ORIENTATION_PORTRAIT;

import static com.android.wm.shell.shared.split.SplitScreenConstants.SNAP_TO_50_50;
import static com.android.wm.shell.shared.split.SplitScreenConstants.SNAP_TO_END_AND_DISMISS;
import static com.android.wm.shell.shared.split.SplitScreenConstants.SNAP_TO_START_AND_DISMISS;

import static com.google.common.truth.Truth.assertThat;

@@ -150,8 +148,8 @@ public class SplitLayoutTests extends ShellTestCase {
    @UiThreadTest
    public void testSnapToDismissStart() {
        // verify it callbacks properly when the snap target indicates dismissing split.
        DividerSnapAlgorithm.SnapTarget snapTarget = getSnapTarget(0 /* position */,
                SNAP_TO_START_AND_DISMISS);
        DividerSnapAlgorithm.SnapTarget snapTarget =
                mSplitLayout.mDividerSnapAlgorithm.getDismissStartTarget();

        mSplitLayout.snapToTarget(mSplitLayout.getDividerPosition(), snapTarget);
        waitDividerFlingFinished();
@@ -162,8 +160,8 @@ public class SplitLayoutTests extends ShellTestCase {
    @UiThreadTest
    public void testSnapToDismissEnd() {
        // verify it callbacks properly when the snap target indicates dismissing split.
        DividerSnapAlgorithm.SnapTarget snapTarget = getSnapTarget(0 /* position */,
                SNAP_TO_END_AND_DISMISS);
        DividerSnapAlgorithm.SnapTarget snapTarget =
                mSplitLayout.mDividerSnapAlgorithm.getDismissEndTarget();

        mSplitLayout.snapToTarget(mSplitLayout.getDividerPosition(), snapTarget);
        waitDividerFlingFinished();
@@ -203,9 +201,4 @@ public class SplitLayoutTests extends ShellTestCase {
                new Rect(0, 0, 1080, 2160));
        return configuration;
    }

    private static DividerSnapAlgorithm.SnapTarget getSnapTarget(int position, int flag) {
        return new DividerSnapAlgorithm.SnapTarget(
                position /* position */, position /* taskPosition */, flag);
    }
}