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

Commit ccb98dc3 authored by William Xiao's avatar William Xiao
Browse files

Set gesture exclusion zone on glanceable hub

Right now the bouncer swipe gesture area overlaps the bottom row of
widgets a tiny bit. Setting an exclusion zone prevents this from
happening.

Fix: 335505186
Fix: 337080140
Bug: 335505186
Test: atest GlanceableHubContainerControllerTest
Flag: communal.communal_hub
Change-Id: Iad4c2658a98771f5aad2e7098b0cfd102792bfaa
parent 64fed7b8
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -1793,9 +1793,9 @@
    the lockscreen -->
    <dimen name="communal_right_edge_swipe_region_width">40dp</dimen>
    <!-- Height of area at top of communal hub where swipes should open the notification shade -->
    <dimen name="communal_top_edge_swipe_region_height">68dp</dimen>
    <dimen name="communal_top_edge_swipe_region_height">64dp</dimen>
    <!-- Height of area at bottom of communal hub where swipes should open the bouncer -->
    <dimen name="communal_bottom_edge_swipe_region_height">68dp</dimen>
    <dimen name="communal_bottom_edge_swipe_region_height">140dp</dimen>

    <dimen name="drag_and_drop_icon_size">70dp</dimen>

+27 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.systemui.shade

import android.content.Context
import android.graphics.Rect
import android.os.PowerManager
import android.os.SystemClock
import android.view.GestureDetector
@@ -215,6 +216,32 @@ constructor(
                R.dimen.communal_right_edge_swipe_region_width
            )

        val topEdgeSwipeRegionWidth =
            containerView.resources.getDimensionPixelSize(
                R.dimen.communal_top_edge_swipe_region_height
            )
        val bottomEdgeSwipeRegionWidth =
            containerView.resources.getDimensionPixelSize(
                R.dimen.communal_bottom_edge_swipe_region_height
            )

        // BouncerSwipeTouchHandler has a larger gesture area than we want, set an exclusion area so
        // the gesture area doesn't overlap with widgets.
        // TODO(b/323035776): adjust gesture areaa for portrait mode
        containerView.repeatWhenAttached {
            repeatOnLifecycle(Lifecycle.State.CREATED) {
                val exclusionRect =
                    Rect(
                        0,
                        topEdgeSwipeRegionWidth,
                        containerView.right,
                        containerView.bottom - bottomEdgeSwipeRegionWidth
                    )

                containerView.systemGestureExclusionRects = listOf(exclusionRect)
            }
        }

        collectFlow(
            containerView,
            keyguardTransitionInteractor.isFinishedInStateWhere(KeyguardState::isBouncerState),
+27 −12
Original line number Diff line number Diff line
@@ -16,14 +16,13 @@

package com.android.systemui.shade

import android.content.Context
import android.graphics.Rect
import android.os.PowerManager
import android.testing.AndroidTestingRunner
import android.testing.TestableLooper
import android.testing.ViewUtils
import android.view.MotionEvent
import android.view.View
import android.view.WindowManager
import android.widget.FrameLayout
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleOwner
@@ -132,6 +131,11 @@ class GlanceableHubContainerControllerTest : SysuiTestCase() {
        testableLooper = TestableLooper.get(this)

        overrideResource(R.dimen.communal_right_edge_swipe_region_width, RIGHT_SWIPE_REGION_WIDTH)
        overrideResource(R.dimen.communal_top_edge_swipe_region_height, TOP_SWIPE_REGION_WIDTH)
        overrideResource(
            R.dimen.communal_bottom_edge_swipe_region_height,
            BOTTOM_SWIPE_REGION_WIDTH
        )

        // Make communal available so that communalInteractor.desiredScene accurately reflects
        // scene changes instead of just returning Blank.
@@ -421,6 +425,24 @@ class GlanceableHubContainerControllerTest : SysuiTestCase() {
            }
        }

    @Test
    fun gestureExclusionZone_setAfterInit() =
        with(kosmos) {
            testScope.runTest {
                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
                        )
                    )
            }
        }

    private fun initAndAttachContainerView() {
        containerView = View(context)

@@ -430,18 +452,9 @@ class GlanceableHubContainerControllerTest : SysuiTestCase() {
        underTest.initView(containerView)

        // Attach the view so that flows start collecting.
        ViewUtils.attachView(parentView)
        ViewUtils.attachView(parentView, CONTAINER_WIDTH, CONTAINER_HEIGHT)
        // Attaching is async so processAllMessages is required for view.repeatWhenAttached to run.
        testableLooper.processAllMessages()

        // Give the view a fixed size to simplify testing for edge swipes.
        val lp =
            parentView.layoutParams.apply {
                width = CONTAINER_WIDTH
                height = CONTAINER_HEIGHT
            }
        val wm = context.getSystemService(Context.WINDOW_SERVICE) as WindowManager
        wm.updateViewLayout(parentView, lp)
    }

    private fun goToScene(scene: SceneKey) {
@@ -453,6 +466,8 @@ class GlanceableHubContainerControllerTest : SysuiTestCase() {
        private const val CONTAINER_WIDTH = 100
        private const val CONTAINER_HEIGHT = 100
        private const val RIGHT_SWIPE_REGION_WIDTH = 20
        private const val TOP_SWIPE_REGION_WIDTH = 12
        private const val BOTTOM_SWIPE_REGION_WIDTH = 14

        /**
         * A touch down event right in the middle of the screen, to avoid being in any of the swipe
+11 −4
Original line number Diff line number Diff line
@@ -31,13 +31,20 @@ public class ViewUtils {
     * This is currently done by adding the view to a window.
     */
    public static void attachView(View view) {
        attachView(view, LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
    }

    /**
     * Causes the view (and its children) to have {@link View#onAttachedToWindow()} called.
     *
     * This is currently done by adding the view to a window.
     */
    public static void attachView(View view, int width, int height) {
        // Make sure hardware acceleration isn't turned on.
        view.getContext().getApplicationInfo().flags &=
                ~(ApplicationInfo.FLAG_HARDWARE_ACCELERATED);
        WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
                LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT,
                LayoutParams.TYPE_APPLICATION_OVERLAY,
                0, PixelFormat.TRANSLUCENT);
        WindowManager.LayoutParams lp = new WindowManager.LayoutParams(width, height,
                LayoutParams.TYPE_APPLICATION_OVERLAY, 0, PixelFormat.TRANSLUCENT);
        view.getContext().getSystemService(WindowManager.class).addView(view, lp);
    }