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

Commit d19771c9 authored by Jerry Chang's avatar Jerry Chang Committed by Wale Ogunwale
Browse files

Add double tap callback for divider bar

Add a callback in split layout to notify registered listener when users
double tapped the divider bar. Use this callback to switch side stage
position.

Bug: 176061049
Test: atest SplitLayoutTests
Test: manual check stage position changed when double tapped divider bar
Change-Id: Id3929b01a194b8eb0838cc892156bbbe48dc8690
parent 884719cd
Loading
Loading
Loading
Loading
+15 −0
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import static android.view.WindowManager.LayoutParams.FLAG_SLIPPERY;

import android.content.Context;
import android.util.AttributeSet;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.SurfaceControlViewHost;
import android.view.VelocityTracker;
@@ -54,6 +55,7 @@ public class DividerView extends FrameLayout implements View.OnTouchListener {
    private VelocityTracker mVelocityTracker;
    private boolean mMoving;
    private int mStartPos;
    private GestureDetector mDoubleTapDetector;

    public DividerView(@NonNull Context context) {
        super(context);
@@ -88,6 +90,7 @@ public class DividerView extends FrameLayout implements View.OnTouchListener {
        mBackground = findViewById(R.id.docked_divider_background);
        mTouchElevation = getResources().getDimensionPixelSize(
                R.dimen.docked_stack_divider_lift_elevation);
        mDoubleTapDetector = new GestureDetector(getContext(), new DoubleTapListener());
        setOnTouchListener(this);
    }

@@ -136,6 +139,8 @@ public class DividerView extends FrameLayout implements View.OnTouchListener {
                mSplitLayout.snapToTarget(position, snapTarget);
                break;
        }

        mDoubleTapDetector.onTouchEvent(event);
        return true;
    }

@@ -200,4 +205,14 @@ public class DividerView extends FrameLayout implements View.OnTouchListener {
    private boolean isLandscape() {
        return getResources().getConfiguration().orientation == ORIENTATION_LANDSCAPE;
    }

    private class DoubleTapListener extends GestureDetector.SimpleOnGestureListener {
        @Override
        public boolean onDoubleTap(MotionEvent e) {
            if (mSplitLayout != null) {
                mSplitLayout.onDoubleTappedDivider();
            }
            return false;
        }
    }
}
+10 −0
Original line number Diff line number Diff line
@@ -201,6 +201,10 @@ public class SplitLayout {
        }
    }

    void onDoubleTappedDivider() {
        mLayoutChangeListener.onDoubleTappedDivider();
    }

    /**
     * Returns {@link DividerSnapAlgorithm.SnapTarget} which matches passing position and velocity.
     */
@@ -249,9 +253,15 @@ public class SplitLayout {
    public interface LayoutChangeListener {
        /** Calls when dismissing split. */
        void onSnappedToDismiss(boolean snappedToEnd);

        /** Calls when the bounds is changing due to animation or dragging divider bar. */
        void onBoundsChanging(SplitLayout layout);

        /** Calls when the target bounds changed. */
        void onBoundsChanged(SplitLayout layout);

        /** Calls when user double tapped on the divider bar. */
        default void onDoubleTappedDivider() {
        }
    }
}
+6 −0
Original line number Diff line number Diff line
@@ -270,6 +270,12 @@ class StageCoordinator implements SplitLayout.LayoutChangeListener,

    }

    @Override
    public void onDoubleTappedDivider() {
        setSideStagePosition(mSideStagePosition == SIDE_STAGE_POSITION_TOP_OR_LEFT
                ? SIDE_STAGE_POSITION_BOTTOM_OR_RIGHT : SIDE_STAGE_POSITION_TOP_OR_LEFT);
    }

    @Override
    public void onBoundsChanged(SplitLayout layout) {
        final SurfaceControl dividerLeash = mSplitLayout.getDividerLeash();
+6 −0
Original line number Diff line number Diff line
@@ -82,6 +82,12 @@ public class SplitLayoutTests extends ShellTestCase {
        verify(mLayoutChangeListener).onBoundsChanged(any(SplitLayout.class));
    }

    @Test
    public void testOnDoubleTappedDivider() {
        mSplitLayout.onDoubleTappedDivider();
        verify(mLayoutChangeListener).onDoubleTappedDivider();
    }

    @Test
    @UiThreadTest
    public void testSnapToDismissTarget() {