Merge "Fix alpha fading of NotificationShelf in LS" into tm-qpr-dev

This commit is contained in:
András Kurucz
2022-09-09 13:34:49 +00:00
committed by Android (Google) Code Review
3 changed files with 140 additions and 25 deletions

View File

@@ -16,6 +16,8 @@
package com.android.systemui.statusbar; package com.android.systemui.statusbar;
import static com.android.keyguard.BouncerPanelExpansionCalculator.aboutToShowBouncerProgress;
import android.content.Context; import android.content.Context;
import android.content.res.Configuration; import android.content.res.Configuration;
import android.content.res.Resources; import android.content.res.Resources;
@@ -90,6 +92,12 @@ public class NotificationShelf extends ActivatableNotificationView implements
super(context, attrs); super(context, attrs);
} }
@VisibleForTesting
public NotificationShelf(Context context, AttributeSet attrs, boolean showNotificationShelf) {
super(context, attrs);
mShowNotificationShelf = showNotificationShelf;
}
@Override @Override
@VisibleForTesting @VisibleForTesting
public void onFinishInflate() { public void onFinishInflate() {
@@ -175,7 +183,11 @@ public class NotificationShelf extends ActivatableNotificationView implements
if (ambientState.isExpansionChanging() && !ambientState.isOnKeyguard()) { if (ambientState.isExpansionChanging() && !ambientState.isOnKeyguard()) {
float expansion = ambientState.getExpansionFraction(); float expansion = ambientState.getExpansionFraction();
if (ambientState.isBouncerInTransit()) {
viewState.alpha = aboutToShowBouncerProgress(expansion);
} else {
viewState.alpha = ShadeInterpolation.getContentAlpha(expansion); viewState.alpha = ShadeInterpolation.getContentAlpha(expansion);
}
} else { } else {
viewState.alpha = 1f - ambientState.getHideAmount(); viewState.alpha = 1f - ambientState.getHideAmount();
} }

View File

@@ -3,15 +3,22 @@ package com.android.systemui.statusbar.notification.stack
import android.testing.AndroidTestingRunner import android.testing.AndroidTestingRunner
import android.testing.TestableLooper.RunWithLooper import android.testing.TestableLooper.RunWithLooper
import androidx.test.filters.SmallTest import androidx.test.filters.SmallTest
import com.android.keyguard.BouncerPanelExpansionCalculator.aboutToShowBouncerProgress
import com.android.systemui.SysuiTestCase import com.android.systemui.SysuiTestCase
import com.android.systemui.animation.ShadeInterpolation
import com.android.systemui.statusbar.NotificationShelf import com.android.systemui.statusbar.NotificationShelf
import com.android.systemui.statusbar.StatusBarIconView import com.android.systemui.statusbar.StatusBarIconView
import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow
import com.android.systemui.statusbar.notification.row.ExpandableView 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.Before
import org.junit.Test import org.junit.Test
import org.junit.runner.RunWith import org.junit.runner.RunWith
import org.mockito.Mockito.* import org.mockito.Mockito.mock
import org.mockito.Mockito.`when` as whenever import org.mockito.Mockito.`when` as whenever
/** /**
@@ -22,13 +29,18 @@ import org.mockito.Mockito.`when` as whenever
@RunWithLooper @RunWithLooper
class NotificationShelfTest : SysuiTestCase() { 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 shelfState = shelf.viewState as NotificationShelf.ShelfState
private val ambientState = mock(AmbientState::class.java) private val ambientState = mock(AmbientState::class.java)
private val hostLayoutController: NotificationStackScrollLayoutController = mock()
@Before @Before
fun setUp() { fun setUp() {
shelf.bind(ambientState, /* hostLayoutController */ null) shelf.bind(ambientState, /* hostLayoutController */ hostLayoutController)
shelf.layout(/* left */ 0, /* top */ 0, /* right */ 30, /* bottom */5) shelf.layout(/* left */ 0, /* top */ 0, /* right */ 30, /* bottom */5)
} }
@@ -37,7 +49,7 @@ class NotificationShelfTest : SysuiTestCase() {
setFractionToShade(0f) setFractionToShade(0f)
setOnLockscreen(true) setOnLockscreen(true)
shelf.updateActualWidth(/* fractionToShade */ 0f, /* shortestWidth */ 10f); shelf.updateActualWidth(/* fractionToShade */ 0f, /* shortestWidth */ 10f)
assertTrue(shelf.actualWidth == 10) assertTrue(shelf.actualWidth == 10)
shelf.updateActualWidth(/* fractionToShade */ 0.5f, /* shortestWidth */ 10f) shelf.updateActualWidth(/* fractionToShade */ 0.5f, /* shortestWidth */ 10f)
@@ -251,6 +263,42 @@ class NotificationShelfTest : SysuiTestCase() {
assertEquals(0f, amountInShelf) 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) { private fun setFractionToShade(fraction: Float) {
whenever(ambientState.fractionToShade).thenReturn(fraction) whenever(ambientState.fractionToShade).thenReturn(fraction)
} }
@@ -258,4 +306,19 @@ class NotificationShelfTest : SysuiTestCase() {
private fun setOnLockscreen(isOnLockscreen: Boolean) { private fun setOnLockscreen(isOnLockscreen: Boolean) {
whenever(ambientState.isOnKeyguard).thenReturn(isOnLockscreen) whenever(ambientState.isOnKeyguard).thenReturn(isOnLockscreen)
} }
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)
}
} }

View File

@@ -20,7 +20,10 @@ import junit.framework.Assert.assertFalse
import junit.framework.Assert.assertTrue import junit.framework.Assert.assertTrue
import org.junit.Before import org.junit.Before
import org.junit.Test import org.junit.Test
import org.mockito.Mockito.any
import org.mockito.Mockito.eq
import org.mockito.Mockito.mock import org.mockito.Mockito.mock
import org.mockito.Mockito.verify
import org.mockito.Mockito.`when` as whenever import org.mockito.Mockito.`when` as whenever
@SmallTest @SmallTest
@@ -35,7 +38,6 @@ class StackScrollAlgorithmTest : SysuiTestCase() {
private val emptyShadeView = EmptyShadeView(context, /* attrs= */ null).apply { private val emptyShadeView = EmptyShadeView(context, /* attrs= */ null).apply {
layout(/* l= */ 0, /* t= */ 0, /* r= */ 100, /* b= */ 100) layout(/* l= */ 0, /* t= */ 0, /* r= */ 100, /* b= */ 100)
} }
private val ambientState = AmbientState( private val ambientState = AmbientState(
context, context,
dumpManager, dumpManager,
@@ -115,29 +117,54 @@ class StackScrollAlgorithmTest : SysuiTestCase() {
} }
@Test @Test
fun resetViewStates_isExpansionChanging_viewBecomesTransparent() { fun resetViewStates_expansionChanging_notificationBecomesTransparent() {
whenever(mStatusBarKeyguardViewManager.isBouncerInTransit).thenReturn(false) whenever(mStatusBarKeyguardViewManager.isBouncerInTransit).thenReturn(false)
ambientState.isExpansionChanging = true resetViewStates_expansionChanging_notificationAlphaUpdated(
ambientState.expansionFraction = 0.25f expansionFraction = 0.25f,
stackScrollAlgorithm.initView(context) expectedAlpha = 0.0f
)
stackScrollAlgorithm.resetViewStates(ambientState, /* speedBumpIndex= */ 0)
val expected = getContentAlpha(0.25f)
assertThat(notificationRow.viewState.alpha).isEqualTo(expected)
} }
@Test @Test
fun resetViewStates_isExpansionChangingWhileBouncerInTransit_viewBecomesTransparent() { fun resetViewStates_expansionChangingWhileBouncerInTransit_viewBecomesTransparent() {
whenever(mStatusBarKeyguardViewManager.isBouncerInTransit).thenReturn(true) 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.isExpansionChanging = true
ambientState.expansionFraction = 0.25f ambientState.expansionFraction = 0.6f
stackScrollAlgorithm.initView(context) stackScrollAlgorithm.initView(context)
stackScrollAlgorithm.resetViewStates(ambientState, /* speedBumpIndex= */ 0) stackScrollAlgorithm.resetViewStates(ambientState, /* speedBumpIndex= */ 0)
val expected = aboutToShowBouncerProgress(0.25f) verify(notificationShelf).updateState(
assertThat(notificationRow.viewState.alpha).isEqualTo(expected) /* algorithmState= */any(),
/* ambientState= */eq(ambientState)
)
} }
@Test @Test
@@ -479,6 +506,19 @@ class StackScrollAlgorithmTest : SysuiTestCase() {
/* originalCornerRoundness= */ 1f) /* originalCornerRoundness= */ 1f)
assertEquals(1f, currentRoundness) 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)
}
} }
private fun mockExpandableNotificationRow(): ExpandableNotificationRow { private fun mockExpandableNotificationRow(): ExpandableNotificationRow {