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;
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();
}

View File

@@ -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)
}
}
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 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
@@ -479,6 +506,19 @@ 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)
}
}
private fun mockExpandableNotificationRow(): ExpandableNotificationRow {