From 971e7cc322d0e140a8d1de7cfbce1321b3a81dd0 Mon Sep 17 00:00:00 2001 From: Fabian Kozynski Date: Thu, 3 Mar 2022 13:50:27 -0500 Subject: [PATCH] Fix bottom margin of footer actions In split shade, the bottom margin should match that of the notification scrim. Test: manual in split shade and not Test: atest NotificationQSContainerControllerTest Fixes: 221823497 Change-Id: I76f7551cf2fe48356ddd6adf7f7c04256055ad30 --- .../NotificationsQSContainerController.kt | 27 ++++++++++++++++++- .../NotificationsQuickSettingsContainer.java | 17 ++++++++++++ .../NotificationQSContainerControllerTest.kt | 22 ++++++++++----- 3 files changed, 59 insertions(+), 7 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationsQSContainerController.kt b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationsQSContainerController.kt index 7c9e597e74a13..ebb09b1af5e92 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationsQSContainerController.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationsQSContainerController.kt @@ -1,6 +1,7 @@ package com.android.systemui.statusbar.phone import android.view.WindowInsets +import com.android.systemui.R import com.android.systemui.flags.FeatureFlags import com.android.systemui.flags.Flags import com.android.systemui.navigationbar.NavigationModeController @@ -41,6 +42,7 @@ class NotificationsQSContainerController @Inject constructor( private var isQSCustomizerAnimating = false private var notificationsBottomMargin = 0 + private var scrimShadeBottomMargin = 0 private var bottomStableInsets = 0 private var bottomCutoutInsets = 0 @@ -67,17 +69,36 @@ class NotificationsQSContainerController @Inject constructor( public override fun onViewAttached() { updateMargins() + updateResources() overviewProxyService.addCallback(taskbarVisibilityListener) mView.setInsetsChangedListener(windowInsetsListener) mView.setQSFragmentAttachedListener { qs: QS -> qs.setContainerController(this) } + mView.setConfigurationChangedListener { updateResources() } } override fun onViewDetached() { overviewProxyService.removeCallback(taskbarVisibilityListener) mView.removeOnInsetsChangedListener() mView.removeQSFragmentAttachedListener() + mView.setConfigurationChangedListener(null) } + private fun updateResources() { + val previousScrimShadeBottomMargin = scrimShadeBottomMargin + scrimShadeBottomMargin = resources.getDimensionPixelSize( + R.dimen.split_shade_notifications_scrim_margin_bottom + ) + + if (previousScrimShadeBottomMargin != scrimShadeBottomMargin) { + updateBottomSpacing() + } + } + + /** + * Update the notification bottom margin. + * + * Will not call updateBottomSpacing + */ fun updateMargins() { notificationsBottomMargin = mView.defaultNotificationsMarginBottom } @@ -111,7 +132,11 @@ class NotificationsQSContainerController @Inject constructor( qsScrollPaddingBottom = bottomStableInsets } else if (newFooter && !(isQSCustomizing || isQSDetailShowing)) { // With the new footer, we also want this padding in the bottom in these cases - qsScrollPaddingBottom = bottomStableInsets + qsScrollPaddingBottom = if (splitShadeEnabled) { + notificationsMargin - scrimShadeBottomMargin + } else { + bottomStableInsets + } } mView.setPadding(0, 0, 0, containerPadding) mView.setNotificationsMarginBottom(notificationsMargin) diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationsQuickSettingsContainer.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationsQuickSettingsContainer.java index 95e3b70b4c5ec..c2b5f5657fb09 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationsQuickSettingsContainer.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationsQuickSettingsContainer.java @@ -18,11 +18,13 @@ package com.android.systemui.statusbar.phone; import android.app.Fragment; import android.content.Context; +import android.content.res.Configuration; import android.graphics.Canvas; import android.util.AttributeSet; import android.view.View; import android.view.WindowInsets; +import androidx.annotation.Nullable; import androidx.constraintlayout.widget.ConstraintLayout; import com.android.systemui.R; @@ -54,6 +56,9 @@ public class NotificationsQuickSettingsContainer extends ConstraintLayout private View mQSScrollView; private View mQSContainer; + @Nullable + private Consumer mConfigurationChangedListener; + public NotificationsQuickSettingsContainer(Context context, AttributeSet attrs) { super(context, attrs); } @@ -79,6 +84,18 @@ public class NotificationsQuickSettingsContainer extends ConstraintLayout invalidate(); } + @Override + protected void onConfigurationChanged(Configuration newConfig) { + super.onConfigurationChanged(newConfig); + if (mConfigurationChangedListener != null) { + mConfigurationChangedListener.accept(newConfig); + } + } + + public void setConfigurationChangedListener(Consumer listener) { + mConfigurationChangedListener = listener; + } + public void setNotificationsMarginBottom(int margin) { LayoutParams params = (LayoutParams) mStackScroller.getLayoutParams(); params.bottomMargin = margin; diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/NotificationQSContainerControllerTest.kt b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/NotificationQSContainerControllerTest.kt index 00af446ded3d1..5fb4144bec3c7 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/NotificationQSContainerControllerTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/NotificationQSContainerControllerTest.kt @@ -5,6 +5,7 @@ import android.testing.TestableLooper import android.view.WindowInsets import android.view.WindowManagerPolicyConstants import androidx.test.filters.SmallTest +import com.android.systemui.R import com.android.systemui.SysuiTestCase import com.android.systemui.flags.FeatureFlags import com.android.systemui.flags.Flags @@ -40,6 +41,7 @@ class NotificationQSContainerControllerTest : SysuiTestCase() { const val GESTURES_NAVIGATION = WindowManagerPolicyConstants.NAV_BAR_MODE_GESTURAL const val BUTTONS_NAVIGATION = WindowManagerPolicyConstants.NAV_BAR_MODE_3BUTTON const val NOTIFICATIONS_MARGIN = 50 + const val SCRIM_MARGIN = 10 } @Mock @@ -65,12 +67,18 @@ class NotificationQSContainerControllerTest : SysuiTestCase() { @Before fun setup() { MockitoAnnotations.initMocks(this) + mContext.ensureTestableResources() + whenever(notificationsQSContainer.resources).thenReturn(mContext.resources) notificationsQSContainerController = NotificationsQSContainerController( notificationsQSContainer, navigationModeController, overviewProxyService, featureFlags ) + + mContext.orCreateTestableResources + .addOverride(R.dimen.split_shade_notifications_scrim_margin_bottom, SCRIM_MARGIN) + whenever(notificationsQSContainer.defaultNotificationsMarginBottom) .thenReturn(NOTIFICATIONS_MARGIN) whenever(navigationModeController.addListener(navigationModeCaptor.capture())) @@ -115,14 +123,14 @@ class NotificationQSContainerControllerTest : SysuiTestCase() { insets = windowInsets().withStableBottom()) then(expectedContainerPadding = 0, // taskbar should disappear when shade is expanded expectedNotificationsMargin = NOTIFICATIONS_MARGIN, - expectedQsPadding = STABLE_INSET_BOTTOM) + expectedQsPadding = NOTIFICATIONS_MARGIN - SCRIM_MARGIN) given(taskbarVisible = true, navigationMode = BUTTONS_NAVIGATION, insets = windowInsets().withStableBottom()) then(expectedContainerPadding = STABLE_INSET_BOTTOM, expectedNotificationsMargin = NOTIFICATIONS_MARGIN, - expectedQsPadding = STABLE_INSET_BOTTOM) + expectedQsPadding = NOTIFICATIONS_MARGIN - SCRIM_MARGIN) } @Test @@ -153,14 +161,14 @@ class NotificationQSContainerControllerTest : SysuiTestCase() { navigationMode = GESTURES_NAVIGATION, insets = windowInsets().withStableBottom()) then(expectedContainerPadding = 0, - expectedQsPadding = STABLE_INSET_BOTTOM) + expectedQsPadding = NOTIFICATIONS_MARGIN - SCRIM_MARGIN) given(taskbarVisible = false, navigationMode = BUTTONS_NAVIGATION, insets = windowInsets().withStableBottom()) then(expectedContainerPadding = 0, // qs goes full height as it's not obscuring nav buttons expectedNotificationsMargin = STABLE_INSET_BOTTOM + NOTIFICATIONS_MARGIN, - expectedQsPadding = STABLE_INSET_BOTTOM) + expectedQsPadding = STABLE_INSET_BOTTOM + NOTIFICATIONS_MARGIN - SCRIM_MARGIN) } @Test @@ -188,14 +196,15 @@ class NotificationQSContainerControllerTest : SysuiTestCase() { given(taskbarVisible = false, navigationMode = GESTURES_NAVIGATION, insets = windowInsets().withCutout()) - then(expectedContainerPadding = CUTOUT_HEIGHT) + then(expectedContainerPadding = CUTOUT_HEIGHT, + expectedQsPadding = NOTIFICATIONS_MARGIN - SCRIM_MARGIN) given(taskbarVisible = false, navigationMode = BUTTONS_NAVIGATION, insets = windowInsets().withCutout().withStableBottom()) then(expectedContainerPadding = 0, expectedNotificationsMargin = STABLE_INSET_BOTTOM + NOTIFICATIONS_MARGIN, - expectedQsPadding = STABLE_INSET_BOTTOM) + expectedQsPadding = STABLE_INSET_BOTTOM + NOTIFICATIONS_MARGIN - SCRIM_MARGIN) } @Test @@ -392,6 +401,7 @@ class NotificationQSContainerControllerTest : SysuiTestCase() { @Test fun testNotificationsMarginBottomIsUpdated() { + Mockito.clearInvocations(notificationsQSContainer) notificationsQSContainerController.splitShadeEnabled = true verify(notificationsQSContainer).setNotificationsMarginBottom(NOTIFICATIONS_MARGIN)