From 3e531f56bf0f1a87e3d509f9c1643f847afa8600 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A1s=20Kurucz?= Date: Wed, 7 Sep 2022 12:42:55 +0000 Subject: [PATCH] Fix alpha fading of NotificationShelf in LS While we are on the LS and we close the Shade, the NotificationShelf alpha was not animating. Now we share the same logic for calculating the alpha values for the ExpandableNotificationRows and the NotificationShelf. Added new testCases to StackScrollAlgorithmTest to check an intermediate state of the animated alpha values. Previously it was only checking the end state, which is 0.0f. Test: atest NotificationShelfTest Test: atest StackScrollAlgorithmTest Fixes: 237339523 Change-Id: I97b734d296397b6e2587512ff96ab62d976b6192 --- .../systemui/statusbar/NotificationShelf.java | 14 +++- .../stack/NotificationShelfTest.kt | 83 ++++++++++++++++--- .../stack/StackScrollAlgorithmTest.kt | 68 +++++++++++---- 3 files changed, 140 insertions(+), 25 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationShelf.java b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationShelf.java index cea3debe63792..41c0367772b56 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationShelf.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationShelf.java @@ -16,6 +16,8 @@ package com.android.systemui.statusbar; +import static com.android.keyguard.BouncerPanelExpansionCalculator.aboutToShowBouncerProgress; + import android.content.Context; import android.content.res.Configuration; import android.content.res.Resources; @@ -90,6 +92,12 @@ public class NotificationShelf extends ActivatableNotificationView implements super(context, attrs); } + @VisibleForTesting + public NotificationShelf(Context context, AttributeSet attrs, boolean showNotificationShelf) { + super(context, attrs); + mShowNotificationShelf = showNotificationShelf; + } + @Override @VisibleForTesting public void onFinishInflate() { @@ -175,7 +183,11 @@ public class NotificationShelf extends ActivatableNotificationView implements if (ambientState.isExpansionChanging() && !ambientState.isOnKeyguard()) { float expansion = ambientState.getExpansionFraction(); - viewState.alpha = ShadeInterpolation.getContentAlpha(expansion); + if (ambientState.isBouncerInTransit()) { + viewState.alpha = aboutToShowBouncerProgress(expansion); + } else { + viewState.alpha = ShadeInterpolation.getContentAlpha(expansion); + } } else { viewState.alpha = 1f - ambientState.getHideAmount(); } diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/stack/NotificationShelfTest.kt b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/stack/NotificationShelfTest.kt index 3f190367f284d..77418138158bb 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/stack/NotificationShelfTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/stack/NotificationShelfTest.kt @@ -3,15 +3,22 @@ package com.android.systemui.statusbar.notification.stack import android.testing.AndroidTestingRunner import android.testing.TestableLooper.RunWithLooper import androidx.test.filters.SmallTest +import com.android.keyguard.BouncerPanelExpansionCalculator.aboutToShowBouncerProgress import com.android.systemui.SysuiTestCase +import com.android.systemui.animation.ShadeInterpolation import com.android.systemui.statusbar.NotificationShelf import com.android.systemui.statusbar.StatusBarIconView +import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow import com.android.systemui.statusbar.notification.row.ExpandableView -import junit.framework.Assert.* +import com.android.systemui.statusbar.notification.stack.StackScrollAlgorithm.StackScrollAlgorithmState +import com.android.systemui.util.mockito.mock +import junit.framework.Assert.assertEquals +import junit.framework.Assert.assertFalse +import junit.framework.Assert.assertTrue import org.junit.Before import org.junit.Test import org.junit.runner.RunWith -import org.mockito.Mockito.* +import org.mockito.Mockito.mock import org.mockito.Mockito.`when` as whenever /** @@ -22,13 +29,18 @@ import org.mockito.Mockito.`when` as whenever @RunWithLooper class NotificationShelfTest : SysuiTestCase() { - private val shelf = NotificationShelf(context, /* attrs */ null) + private val shelf = NotificationShelf( + context, + /* attrs */ null, + /* showNotificationShelf */true + ) private val shelfState = shelf.viewState as NotificationShelf.ShelfState private val ambientState = mock(AmbientState::class.java) + private val hostLayoutController: NotificationStackScrollLayoutController = mock() @Before fun setUp() { - shelf.bind(ambientState, /* hostLayoutController */ null) + shelf.bind(ambientState, /* hostLayoutController */ hostLayoutController) shelf.layout(/* left */ 0, /* top */ 0, /* right */ 30, /* bottom */5) } @@ -37,7 +49,7 @@ class NotificationShelfTest : SysuiTestCase() { setFractionToShade(0f) setOnLockscreen(true) - shelf.updateActualWidth(/* fractionToShade */ 0f, /* shortestWidth */ 10f); + shelf.updateActualWidth(/* fractionToShade */ 0f, /* shortestWidth */ 10f) assertTrue(shelf.actualWidth == 10) shelf.updateActualWidth(/* fractionToShade */ 0.5f, /* shortestWidth */ 10f) @@ -155,7 +167,7 @@ class NotificationShelfTest : SysuiTestCase() { whenever(expandableView.actualHeight).thenReturn(20) whenever(expandableView.minHeight).thenReturn(20) - whenever(expandableView.shelfTransformationTarget).thenReturn(null) // use translationY + whenever(expandableView.shelfTransformationTarget).thenReturn(null) // use translationY whenever(expandableView.isInShelf).thenReturn(true) whenever(ambientState.isOnKeyguard).thenReturn(true) @@ -182,7 +194,7 @@ class NotificationShelfTest : SysuiTestCase() { whenever(expandableView.actualHeight).thenReturn(20) whenever(expandableView.minHeight).thenReturn(20) - whenever(expandableView.shelfTransformationTarget).thenReturn(null) // use translationY + whenever(expandableView.shelfTransformationTarget).thenReturn(null) // use translationY whenever(expandableView.isInShelf).thenReturn(true) whenever(ambientState.isOnKeyguard).thenReturn(true) @@ -209,7 +221,7 @@ class NotificationShelfTest : SysuiTestCase() { whenever(expandableView.actualHeight).thenReturn(25) whenever(expandableView.minHeight).thenReturn(25) - whenever(expandableView.shelfTransformationTarget).thenReturn(null) // use translationY + whenever(expandableView.shelfTransformationTarget).thenReturn(null) // use translationY whenever(expandableView.isInShelf).thenReturn(true) whenever(ambientState.isOnKeyguard).thenReturn(true) @@ -236,7 +248,7 @@ class NotificationShelfTest : SysuiTestCase() { whenever(expandableView.actualHeight).thenReturn(10) whenever(expandableView.minHeight).thenReturn(10) - whenever(expandableView.shelfTransformationTarget).thenReturn(null) // use translationY + whenever(expandableView.shelfTransformationTarget).thenReturn(null) // use translationY whenever(expandableView.isInShelf).thenReturn(false) whenever(ambientState.isExpansionChanging).thenReturn(false) @@ -251,6 +263,42 @@ class NotificationShelfTest : SysuiTestCase() { assertEquals(0f, amountInShelf) } + @Test + fun updateState_expansionChanging_shelfTransparent() { + updateState_expansionChanging_shelfAlphaUpdated( + expansionFraction = 0.25f, + expectedAlpha = 0.0f + ) + } + + @Test + fun updateState_expansionChangingWhileBouncerInTransit_shelfTransparent() { + whenever(ambientState.isBouncerInTransit).thenReturn(true) + + updateState_expansionChanging_shelfAlphaUpdated( + expansionFraction = 0.85f, + expectedAlpha = 0.0f + ) + } + + @Test + fun updateState_expansionChanging_shelfAlphaUpdated() { + updateState_expansionChanging_shelfAlphaUpdated( + expansionFraction = 0.6f, + expectedAlpha = ShadeInterpolation.getContentAlpha(0.6f) + ) + } + + @Test + fun updateState_expansionChangingWhileBouncerInTransit_shelfAlphaUpdated() { + whenever(ambientState.isBouncerInTransit).thenReturn(true) + + updateState_expansionChanging_shelfAlphaUpdated( + expansionFraction = 0.95f, + expectedAlpha = aboutToShowBouncerProgress(0.95f) + ) + } + private fun setFractionToShade(fraction: Float) { whenever(ambientState.fractionToShade).thenReturn(fraction) } @@ -258,4 +306,19 @@ class NotificationShelfTest : SysuiTestCase() { private fun setOnLockscreen(isOnLockscreen: Boolean) { whenever(ambientState.isOnKeyguard).thenReturn(isOnLockscreen) } -} \ No newline at end of file + + private fun updateState_expansionChanging_shelfAlphaUpdated( + expansionFraction: Float, + expectedAlpha: Float + ) { + whenever(ambientState.lastVisibleBackgroundChild) + .thenReturn(ExpandableNotificationRow(mContext, null)) + whenever(ambientState.isExpansionChanging).thenReturn(true) + whenever(ambientState.expansionFraction).thenReturn(expansionFraction) + whenever(hostLayoutController.speedBumpIndex).thenReturn(0) + + shelf.updateState(StackScrollAlgorithmState(), ambientState) + + assertEquals(expectedAlpha, shelf.viewState.alpha) + } +} 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..4c1fb5652680a 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 @@ -20,7 +20,10 @@ import junit.framework.Assert.assertFalse import junit.framework.Assert.assertTrue import org.junit.Before import org.junit.Test +import org.mockito.Mockito.any +import org.mockito.Mockito.eq import org.mockito.Mockito.mock +import org.mockito.Mockito.verify import org.mockito.Mockito.`when` as whenever @SmallTest @@ -35,7 +38,6 @@ class StackScrollAlgorithmTest : SysuiTestCase() { private val emptyShadeView = EmptyShadeView(context, /* attrs= */ null).apply { layout(/* l= */ 0, /* t= */ 0, /* r= */ 100, /* b= */ 100) } - private val ambientState = AmbientState( context, dumpManager, @@ -115,29 +117,54 @@ class StackScrollAlgorithmTest : SysuiTestCase() { } @Test - fun resetViewStates_isExpansionChanging_viewBecomesTransparent() { + fun resetViewStates_expansionChanging_notificationBecomesTransparent() { whenever(mStatusBarKeyguardViewManager.isBouncerInTransit).thenReturn(false) - ambientState.isExpansionChanging = true - ambientState.expansionFraction = 0.25f - stackScrollAlgorithm.initView(context) - - stackScrollAlgorithm.resetViewStates(ambientState, /* speedBumpIndex= */ 0) - - val expected = getContentAlpha(0.25f) - assertThat(notificationRow.viewState.alpha).isEqualTo(expected) + resetViewStates_expansionChanging_notificationAlphaUpdated( + expansionFraction = 0.25f, + expectedAlpha = 0.0f + ) } @Test - fun resetViewStates_isExpansionChangingWhileBouncerInTransit_viewBecomesTransparent() { + fun resetViewStates_expansionChangingWhileBouncerInTransit_viewBecomesTransparent() { whenever(mStatusBarKeyguardViewManager.isBouncerInTransit).thenReturn(true) + resetViewStates_expansionChanging_notificationAlphaUpdated( + expansionFraction = 0.85f, + expectedAlpha = 0.0f + ) + } + + @Test + fun resetViewStates_expansionChanging_notificationAlphaUpdated() { + whenever(mStatusBarKeyguardViewManager.isBouncerInTransit).thenReturn(false) + resetViewStates_expansionChanging_notificationAlphaUpdated( + expansionFraction = 0.6f, + expectedAlpha = getContentAlpha(0.6f) + ) + } + + @Test + fun resetViewStates_expansionChangingWhileBouncerInTransit_notificationAlphaUpdated() { + whenever(mStatusBarKeyguardViewManager.isBouncerInTransit).thenReturn(true) + resetViewStates_expansionChanging_notificationAlphaUpdated( + expansionFraction = 0.95f, + expectedAlpha = aboutToShowBouncerProgress(0.95f) + ) + } + + @Test + fun resetViewStates_expansionChanging_shelfUpdated() { + ambientState.shelf = notificationShelf ambientState.isExpansionChanging = true - ambientState.expansionFraction = 0.25f + ambientState.expansionFraction = 0.6f stackScrollAlgorithm.initView(context) stackScrollAlgorithm.resetViewStates(ambientState, /* speedBumpIndex= */ 0) - val expected = aboutToShowBouncerProgress(0.25f) - assertThat(notificationRow.viewState.alpha).isEqualTo(expected) + verify(notificationShelf).updateState( + /* algorithmState= */any(), + /* ambientState= */eq(ambientState) + ) } @Test @@ -458,4 +485,17 @@ class StackScrollAlgorithmTest : SysuiTestCase() { /* originalCornerRoundness= */ 1f) assertEquals(1f, currentRoundness) } + + private fun resetViewStates_expansionChanging_notificationAlphaUpdated( + expansionFraction: Float, + expectedAlpha: Float + ) { + ambientState.isExpansionChanging = true + ambientState.expansionFraction = expansionFraction + stackScrollAlgorithm.initView(context) + + stackScrollAlgorithm.resetViewStates(ambientState, /* speedBumpIndex= */ 0) + + assertThat(notificationRow.viewState.alpha).isEqualTo(expectedAlpha) + } }