From e5152328e2943c48bd3bace24f96e46acfa73ee7 Mon Sep 17 00:00:00 2001 From: Marcello Galhardo Date: Wed, 7 Sep 2022 12:01:17 +0000 Subject: [PATCH] Fix alpha not fading on notifications after the first shade expansion The problem has regressed due to b/239903210 fix. During the development, we have made a refactoring where we centralized all the `alpha` handling logic. While centralising the code, we inlined a function which had an early return statement and caused the code execution to stop before expected. By changing the early return to a `continue` we ensure the fade works correctly. Test: manual Test: atest ~/tm-qpr-dev/frameworks/base/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/stack/StackScrollAlgorithmTest.kt Fixes: 245506240 Change-Id: Iee6c2ed0e5ef83e5cb659ee0363cbd80a3c2166e --- .../stack/StackScrollAlgorithm.java | 2 +- .../stack/StackScrollAlgorithmTest.kt | 29 ++++++++++++++++++- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/StackScrollAlgorithm.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/StackScrollAlgorithm.java index 353355bef7bb0..eeed07014c11a 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/StackScrollAlgorithm.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/StackScrollAlgorithm.java @@ -163,7 +163,7 @@ public class StackScrollAlgorithm { // which is more expensive. if (shelfState.hidden) { // When the shelf is hidden, it won't clip views, so we don't hide rows - return; + continue; } final float shelfTop = shelfState.yTranslation; diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/stack/StackScrollAlgorithmTest.kt b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/stack/StackScrollAlgorithmTest.kt index 35d2363b1c2a7..24eff5ff1162f 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/stack/StackScrollAlgorithmTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/stack/StackScrollAlgorithmTest.kt @@ -179,7 +179,28 @@ class StackScrollAlgorithmTest : SysuiTestCase() { } @Test - fun resetViewStates_hiddenShelf_viewAlphaDoesNotChange() { + fun resetViewStates_hiddenShelf_allRowsBecomesTransparent() { + hostView.removeAllViews() + val row1 = mockExpandableNotificationRow() + hostView.addView(row1) + val row2 = mockExpandableNotificationRow() + hostView.addView(row2) + + ambientState.setStatusBarState(StatusBarState.KEYGUARD) + ambientState.hideAmount = 0.25f + notificationShelf.viewState.hidden = true + ambientState.shelf = notificationShelf + stackScrollAlgorithm.initView(context) + + stackScrollAlgorithm.resetViewStates(ambientState, /* speedBumpIndex= */ 0) + + val expected = 1f - ambientState.hideAmount + assertThat(row1.viewState.alpha).isEqualTo(expected) + assertThat(row2.viewState.alpha).isEqualTo(expected) + } + + @Test + fun resetViewStates_hiddenShelf_shelfAlphaDoesNotChange() { val expected = notificationShelf.viewState.alpha notificationShelf.viewState.hidden = true ambientState.shelf = notificationShelf @@ -459,3 +480,9 @@ class StackScrollAlgorithmTest : SysuiTestCase() { assertEquals(1f, currentRoundness) } } + +private fun mockExpandableNotificationRow(): ExpandableNotificationRow { + return mock(ExpandableNotificationRow::class.java).apply { + whenever(viewState).thenReturn(ExpandableViewState()) + } +}