From 56fd56875a0cf2f5e9efb5c633d4376f74f84339 Mon Sep 17 00:00:00 2001 From: Bryce Lee Date: Tue, 17 Aug 2021 20:06:22 -0700 Subject: [PATCH] Set communal view alpha. This changelist alters the communal view's alpha during transitions such as the shade expansion to be consistent with the rest of the keyguard content, which dims out during these events. Bug: 197035411 Test: CommunalHostViewControllerTest#testAlphaPropagation Test: NotificationPanelViewTest#testCommunalAlphaUpdate Change-Id: I8c499d7c8746efe3b560935af09ff9da12c0e849 --- .../communal/CommunalHostViewController.java | 15 +++++++++++++++ .../service/CommunalSurfaceViewController.java | 1 + .../phone/NotificationPanelViewController.java | 7 +++++++ .../communal/CommunalHostViewControllerTest.java | 15 +++++++++++++++ .../phone/NotificationPanelViewTest.java | 9 +++++++++ 5 files changed, 47 insertions(+) diff --git a/packages/SystemUI/src/com/android/systemui/communal/CommunalHostViewController.java b/packages/SystemUI/src/com/android/systemui/communal/CommunalHostViewController.java index 07f765b010276..ba6373c5bd20c 100644 --- a/packages/SystemUI/src/com/android/systemui/communal/CommunalHostViewController.java +++ b/packages/SystemUI/src/com/android/systemui/communal/CommunalHostViewController.java @@ -160,6 +160,21 @@ public class CommunalHostViewController extends ViewController statusBarState, keyguardFadingAway, goingToFullShade, oldStatusBarState); } + /** + * Set keyguard status view alpha. + */ + public void setAlpha(float alpha) { + if (!mKeyguardVisibilityHelper.isVisibilityAnimating()) { + mView.setAlpha(alpha); + + // Some communal view implementations, such as SurfaceViews, do not behave correctly + // inheriting the alpha of their parent. Directly set child alpha here to work around + // this. + for (int i = mView.getChildCount() - 1; i >= 0; --i) { + mView.getChildAt(i).setAlpha(alpha); + } + } + } @Override public void init() { super.init(); diff --git a/packages/SystemUI/src/com/android/systemui/communal/service/CommunalSurfaceViewController.java b/packages/SystemUI/src/com/android/systemui/communal/service/CommunalSurfaceViewController.java index 89239cfd13491..231a91f6bf7f6 100644 --- a/packages/SystemUI/src/com/android/systemui/communal/service/CommunalSurfaceViewController.java +++ b/packages/SystemUI/src/com/android/systemui/communal/service/CommunalSurfaceViewController.java @@ -209,6 +209,7 @@ public class CommunalSurfaceViewController extends ViewController { if (surfacePackage != null) { mView.setChildSurfacePackage(surfacePackage); mView.setZOrderOnTop(true); + mView.setUseAlpha(); mView.postInvalidate(); mCommunalStateController.setCommunalViewShowing(true); } else { diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelViewController.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelViewController.java index 0faf520103dee..b3c24c9f1b927 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelViewController.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelViewController.java @@ -1574,6 +1574,12 @@ public class NotificationPanelViewController extends PanelViewController { return true; } + private void updateCommunal() { + if (mCommunalViewController != null) { + mCommunalViewController.setAlpha(mKeyguardOnlyContentAlpha); + } + } + private void updateClock() { float alpha = mClockPositionResult.clockAlpha * mKeyguardOnlyContentAlpha; mKeyguardStatusViewController.setAlpha(alpha); @@ -2675,6 +2681,7 @@ public class NotificationPanelViewController extends PanelViewController { updateKeyguardBottomAreaAlpha(); } updateClock(); + updateCommunal(); } private void trackMovement(MotionEvent event) { diff --git a/packages/SystemUI/tests/src/com/android/systemui/communal/CommunalHostViewControllerTest.java b/packages/SystemUI/tests/src/com/android/systemui/communal/CommunalHostViewControllerTest.java index b7128325a6407..3b750e7c1c2d4 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/communal/CommunalHostViewControllerTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/communal/CommunalHostViewControllerTest.java @@ -77,6 +77,9 @@ public class CommunalHostViewControllerTest extends SysuiTestCase { @Mock private CommunalSource mCommunalSource; + @Mock + private View mChildView; + @Before public void setup() { MockitoAnnotations.initMocks(this); @@ -211,4 +214,16 @@ public class CommunalHostViewControllerTest extends SysuiTestCase { // Verify state controller is notified communal view is hidden. verify(mCommunalStateController).setCommunalViewShowing(false); } + + @Test + public void testAlphaPropagation() { + final float alpha = 0.8f; + + // Ensure alpha setting is propagated to children. + when(mCommunalView.getChildCount()).thenReturn(1); + when(mCommunalView.getChildAt(0)).thenReturn(mChildView); + mController.setAlpha(alpha); + verify(mChildView).setAlpha(alpha); + verify(mCommunalView).setAlpha(alpha); + } } diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/NotificationPanelViewTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/NotificationPanelViewTest.java index dc220362c086d..38341b83446ab 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/NotificationPanelViewTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/NotificationPanelViewTest.java @@ -29,6 +29,7 @@ import static com.google.common.truth.Truth.assertThat; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyBoolean; +import static org.mockito.ArgumentMatchers.anyFloat; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.atLeast; @@ -901,6 +902,14 @@ public class NotificationPanelViewTest extends SysuiTestCase { anyBoolean(), anyBoolean(), anyInt()); } + @Test + public void testCommunalAlphaUpdate() { + // Verify keyguard content alpha changes are propagate. Note the actual value set is not + // checked since an interpolation is applied to the incoming value. + mNotificationPanelViewController.setKeyguardOnlyContentAlpha(0.8f); + verify(mCommunalHostViewController).setAlpha(anyFloat()); + } + private void triggerPositionClockAndNotifications() { mNotificationPanelViewController.closeQs(); }