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

Commit c84c71b5 authored by Bryce Lee's avatar Bryce Lee
Browse files

Adjust back gesture exclusion areas on glanceable hub.

This changelist accounts for layout direction when setting insets for
excluding back gesture on the glanceable hub.

Test: atest GlanceableHubContainerControllerTest#gestureExclusionZone_setAfterInit_rtl
Test: atest GlanceableHubContainerControllerTest#gestureExclusionZone_setAfterInit_backGestureEnabled_rtl
Bug: 320786721
Flag: com.android.systemui.glanceable_hub_back_gesture

Change-Id: I12814d075aeebe9a362900f6e44e9a4a18ee821b
parent 29d9d43e
Loading
Loading
Loading
Loading
+13 −25
Original line number Diff line number Diff line
@@ -132,13 +132,6 @@ constructor(
     */
    private var touchMonitor: TouchMonitor? = null

    /**
     * The width of the area in which a right edge swipe can open the hub, in pixels. Read from
     * resources when [initView] is called.
     */
    // TODO(b/320786721): support RTL layouts
    private var rightEdgeSwipeRegionWidth: Int = 0

    /**
     * True if we are currently tracking a touch intercepted by the hub, either because the hub is
     * open or being opened.
@@ -265,11 +258,6 @@ constructor(

        communalContainerView = containerView

        rightEdgeSwipeRegionWidth =
            containerView.resources.getDimensionPixelSize(
                R.dimen.communal_right_edge_swipe_region_width
            )

        val topEdgeSwipeRegionWidth =
            containerView.resources.getDimensionPixelSize(
                R.dimen.communal_top_edge_swipe_region_height
@@ -286,7 +274,7 @@ constructor(
            // Run when the touch handling lifecycle is RESUMED, meaning the hub is visible and not
            // occluded.
            lifecycleRegistry.repeatOnLifecycle(Lifecycle.State.RESUMED) {
                // Avoid adding exclusion to right/left edges to allow back gestures.
                // Avoid adding exclusion to end/start edges to allow back gestures.
                val insets =
                    if (glanceableHubBackGesture()) {
                        containerView.rootWindowInsets.getInsets(WindowInsets.Type.systemGestures())
@@ -294,17 +282,22 @@ constructor(
                        Insets.NONE
                    }

                val ltr = containerView.layoutDirection == View.LAYOUT_DIRECTION_LTR

                val backGestureInset =
                    Rect(
                        if (ltr) 0 else insets.left,
                        0,
                        if (ltr) insets.right else containerView.right,
                        containerView.bottom,
                    )

                containerView.systemGestureExclusionRects =
                    if (Flags.hubmodeFullscreenVerticalSwipe()) {
                        listOf(
                            // Disable back gestures on the left side of the screen, to avoid
                            // conflicting with scene transitions.
                            Rect(
                                0,
                                0,
                                insets.right,
                                containerView.bottom,
                            )
                            backGestureInset
                        )
                    } else {
                        listOf(
@@ -318,12 +311,7 @@ constructor(
                            ),
                            // Disable back gestures on the left side of the screen, to avoid
                            // conflicting with scene transitions.
                            Rect(
                                0,
                                0,
                                insets.right,
                                containerView.bottom,
                            )
                            backGestureInset
                        )
                    }
            }
+54 −0
Original line number Diff line number Diff line
@@ -429,6 +429,7 @@ class GlanceableHubContainerControllerTest : SysuiTestCase() {
    fun gestureExclusionZone_setAfterInit() =
        with(kosmos) {
            testScope.runTest {
                whenever(containerView.layoutDirection).thenReturn(View.LAYOUT_DIRECTION_LTR)
                goToScene(CommunalScenes.Communal)

                assertThat(containerView.systemGestureExclusionRects)
@@ -449,11 +450,38 @@ class GlanceableHubContainerControllerTest : SysuiTestCase() {
            }
        }

    @Test
    @DisableFlags(FLAG_GLANCEABLE_HUB_BACK_GESTURE)
    fun gestureExclusionZone_setAfterInit_rtl() =
        with(kosmos) {
            testScope.runTest {
                whenever(containerView.layoutDirection).thenReturn(View.LAYOUT_DIRECTION_RTL)
                goToScene(CommunalScenes.Communal)

                assertThat(containerView.systemGestureExclusionRects)
                    .containsExactly(
                        Rect(
                            /* left= */ 0,
                            /* top= */ TOP_SWIPE_REGION_WIDTH,
                            /* right= */ CONTAINER_WIDTH,
                            /* bottom= */ CONTAINER_HEIGHT - BOTTOM_SWIPE_REGION_WIDTH
                        ),
                        Rect(
                            /* left= */ 0,
                            /* top= */ 0,
                            /* right= */ CONTAINER_WIDTH,
                            /* bottom= */ CONTAINER_HEIGHT
                        )
                    )
            }
        }

    @Test
    @EnableFlags(FLAG_GLANCEABLE_HUB_BACK_GESTURE)
    fun gestureExclusionZone_setAfterInit_backGestureEnabled() =
        with(kosmos) {
            testScope.runTest {
                whenever(containerView.layoutDirection).thenReturn(View.LAYOUT_DIRECTION_LTR)
                goToScene(CommunalScenes.Communal)

                assertThat(containerView.systemGestureExclusionRects)
@@ -474,6 +502,32 @@ class GlanceableHubContainerControllerTest : SysuiTestCase() {
            }
        }

    @Test
    @EnableFlags(FLAG_GLANCEABLE_HUB_BACK_GESTURE)
    fun gestureExclusionZone_setAfterInit_backGestureEnabled_rtl() =
        with(kosmos) {
            testScope.runTest {
                whenever(containerView.layoutDirection).thenReturn(View.LAYOUT_DIRECTION_RTL)
                goToScene(CommunalScenes.Communal)

                assertThat(containerView.systemGestureExclusionRects)
                    .containsExactly(
                        Rect(
                            /* left= */ FAKE_INSETS.left,
                            /* top= */ TOP_SWIPE_REGION_WIDTH,
                            /* right= */ CONTAINER_WIDTH - FAKE_INSETS.right,
                            /* bottom= */ CONTAINER_HEIGHT - BOTTOM_SWIPE_REGION_WIDTH
                        ),
                        Rect(
                            /* left= */ FAKE_INSETS.left,
                            /* top= */ 0,
                            /* right= */ CONTAINER_WIDTH,
                            /* bottom= */ CONTAINER_HEIGHT
                        )
                    )
            }
        }

    @Test
    fun gestureExclusionZone_unsetWhenShadeOpen() =
        with(kosmos) {