From ccb98dc3f24e5f403c72fb563fab9a6664c95338 Mon Sep 17 00:00:00 2001 From: William Xiao Date: Wed, 24 Apr 2024 16:06:46 -0700 Subject: 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 --- packages/SystemUI/res/values/dimens.xml | 4 +-- .../shade/GlanceableHubContainerController.kt | 27 +++++++++++++++ .../shade/GlanceableHubContainerControllerTest.kt | 39 +++++++++++++++------- tests/testables/src/android/testing/ViewUtils.java | 15 ++++++--- 4 files changed, 67 insertions(+), 18 deletions(-) diff --git a/packages/SystemUI/res/values/dimens.xml b/packages/SystemUI/res/values/dimens.xml index df57f2a27761..1b2362dd4f2f 100644 --- a/packages/SystemUI/res/values/dimens.xml +++ b/packages/SystemUI/res/values/dimens.xml @@ -1793,9 +1793,9 @@ the lockscreen --> 40dp - 68dp + 64dp - 68dp + 140dp 70dp diff --git a/packages/SystemUI/src/com/android/systemui/shade/GlanceableHubContainerController.kt b/packages/SystemUI/src/com/android/systemui/shade/GlanceableHubContainerController.kt index a5a547403af9..ff5fdc6d2d29 100644 --- a/packages/SystemUI/src/com/android/systemui/shade/GlanceableHubContainerController.kt +++ b/packages/SystemUI/src/com/android/systemui/shade/GlanceableHubContainerController.kt @@ -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), diff --git a/packages/SystemUI/tests/src/com/android/systemui/shade/GlanceableHubContainerControllerTest.kt b/packages/SystemUI/tests/src/com/android/systemui/shade/GlanceableHubContainerControllerTest.kt index 03f5ecfa92d2..7b5c1d3fe139 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/shade/GlanceableHubContainerControllerTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/shade/GlanceableHubContainerControllerTest.kt @@ -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 diff --git a/tests/testables/src/android/testing/ViewUtils.java b/tests/testables/src/android/testing/ViewUtils.java index 80c2e8ddd907..0fad79d40c7a 100644 --- a/tests/testables/src/android/testing/ViewUtils.java +++ b/tests/testables/src/android/testing/ViewUtils.java @@ -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); } -- cgit v1.2.3-59-g8ed1b