diff options
5 files changed, 125 insertions, 10 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationShelf.java b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationShelf.java index 87ef92a28d5d..408293cffd99 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationShelf.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationShelf.java @@ -496,9 +496,6 @@ public class NotificationShelf extends ActivatableNotificationView implements return; } - final float smallCornerRadius = - getResources().getDimension(R.dimen.notification_corner_radius_small) - / getResources().getDimension(R.dimen.notification_corner_radius); final float viewEnd = viewStart + anv.getActualHeight(); final float cornerAnimationDistance = mCornerAnimationDistance * mAmbientState.getExpansionFraction(); @@ -509,7 +506,7 @@ public class NotificationShelf extends ActivatableNotificationView implements final float changeFraction = MathUtils.saturate( (viewEnd - cornerAnimationTop) / cornerAnimationDistance); anv.requestBottomRoundness( - anv.isLastInSection() ? 1f : changeFraction, + /* value = */ anv.isLastInSection() ? 1f : changeFraction, /* animate = */ false, SourceType.OnScroll); @@ -517,7 +514,7 @@ public class NotificationShelf extends ActivatableNotificationView implements // Fast scroll skips frames and leaves corners with unfinished rounding. // Reset top and bottom corners outside of animation bounds. anv.requestBottomRoundness( - anv.isLastInSection() ? 1f : smallCornerRadius, + /* value = */ anv.isLastInSection() ? 1f : 0f, /* animate = */ false, SourceType.OnScroll); } @@ -527,16 +524,16 @@ public class NotificationShelf extends ActivatableNotificationView implements final float changeFraction = MathUtils.saturate( (viewStart - cornerAnimationTop) / cornerAnimationDistance); anv.requestTopRoundness( - anv.isFirstInSection() ? 1f : changeFraction, - false, + /* value = */ anv.isFirstInSection() ? 1f : changeFraction, + /* animate = */ false, SourceType.OnScroll); } else if (viewStart < cornerAnimationTop) { // Fast scroll skips frames and leaves corners with unfinished rounding. // Reset top and bottom corners outside of animation bounds. anv.requestTopRoundness( - anv.isFirstInSection() ? 1f : smallCornerRadius, - false, + /* value = */ anv.isFirstInSection() ? 1f : 0f, + /* animate = */ false, SourceType.OnScroll); } } @@ -976,6 +973,16 @@ public class NotificationShelf extends ActivatableNotificationView implements mIndexOfFirstViewInShelf = mHostLayoutController.indexOfChild(firstViewInShelf); } + /** + * This method resets the OnScroll roundness of a view to 0f + * + * Note: This should be the only class that handles roundness {@code SourceType.OnScroll} + */ + public static void resetOnScrollRoundness(ExpandableView expandableView) { + expandableView.requestTopRoundness(0f, false, SourceType.OnScroll); + expandableView.requestBottomRoundness(0f, false, SourceType.OnScroll); + } + public class ShelfState extends ExpandableViewState { private boolean hasItemsInStableShelf; private ExpandableView firstViewInShelf; diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationChildrenContainer.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationChildrenContainer.java index 26f0ad9eca87..0554fb5b3689 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationChildrenContainer.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationChildrenContainer.java @@ -44,6 +44,7 @@ import com.android.internal.widget.NotificationExpandButton; import com.android.systemui.R; import com.android.systemui.statusbar.CrossFadeHelper; import com.android.systemui.statusbar.NotificationGroupingUtil; +import com.android.systemui.statusbar.NotificationShelf; import com.android.systemui.statusbar.notification.FeedbackIcon; import com.android.systemui.statusbar.notification.NotificationFadeAware; import com.android.systemui.statusbar.notification.NotificationUtils; @@ -308,6 +309,11 @@ public class NotificationChildrenContainer extends ViewGroup row.setContentTransformationAmount(0, false /* isLastChild */); row.setNotificationFaded(mContainingNotificationIsFaded); + + // This is a workaround, the NotificationShelf should be the owner of `OnScroll` roundness. + // Here we should reset the `OnScroll` roundness only on top-level rows. + NotificationShelf.resetOnScrollRoundness(row); + // It doesn't make sense to keep old animations around, lets cancel them! ExpandableViewState viewState = row.getViewState(); if (viewState != null) { @@ -1377,8 +1383,12 @@ public class NotificationChildrenContainer extends ViewGroup if (child.getVisibility() == View.GONE) { continue; } + child.requestTopRoundness( + /* value = */ 0f, + /* animate = */ isShown(), + SourceType.DefaultValue); child.requestBottomRoundness( - last ? getBottomRoundness() : 0f, + /* value = */ last ? getBottomRoundness() : 0f, /* animate = */ isShown(), SourceType.DefaultValue); last = false; diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/NotificationTestHelper.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/NotificationTestHelper.java index 421f918a135e..7478e4c1f878 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/NotificationTestHelper.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/NotificationTestHelper.java @@ -22,6 +22,7 @@ import static android.app.NotificationManager.IMPORTANCE_HIGH; import static com.android.systemui.statusbar.NotificationEntryHelper.modifyRanking; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyInt; @@ -60,6 +61,7 @@ import com.android.systemui.statusbar.NotificationRemoteInputManager; import com.android.systemui.statusbar.NotificationShadeWindowController; import com.android.systemui.statusbar.SmartReplyController; import com.android.systemui.statusbar.notification.ConversationNotificationProcessor; +import com.android.systemui.statusbar.notification.SourceType; import com.android.systemui.statusbar.notification.collection.NotificationEntry; import com.android.systemui.statusbar.notification.collection.NotificationEntryBuilder; import com.android.systemui.statusbar.notification.collection.notifcollection.CommonNotifCollection; @@ -194,6 +196,25 @@ public class NotificationTestHelper { } /** + * Creates a generic row with rounded border. + * + * @return a generic row with the set roundness. + * @throws Exception + */ + public ExpandableNotificationRow createRowWithRoundness( + float topRoundness, + float bottomRoundness, + SourceType sourceType + ) throws Exception { + ExpandableNotificationRow row = createRow(); + row.requestTopRoundness(topRoundness, false, sourceType); + row.requestBottomRoundness(bottomRoundness, /*animate = */ false, sourceType); + assertEquals(topRoundness, row.getTopRoundness(), /* delta = */ 0f); + assertEquals(bottomRoundness, row.getBottomRoundness(), /* delta = */ 0f); + return row; + } + + /** * Creates a generic row. * * @return a generic row with no special properties. diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/stack/NotificationChildrenContainerTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/stack/NotificationChildrenContainerTest.java index 7c41abba6176..438b528944be 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/stack/NotificationChildrenContainerTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/stack/NotificationChildrenContainerTest.java @@ -25,6 +25,7 @@ import android.view.View; import androidx.test.filters.SmallTest; import com.android.systemui.SysuiTestCase; +import com.android.systemui.statusbar.notification.SourceType; import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow; import com.android.systemui.statusbar.notification.row.NotificationTestHelper; @@ -151,4 +152,37 @@ public class NotificationChildrenContainerTest extends SysuiTestCase { Assert.assertNotNull("Children container must have a header after recreation", mChildrenContainer.getCurrentHeaderView()); } + + @Test + public void addNotification_shouldResetOnScrollRoundness() throws Exception { + ExpandableNotificationRow row = mNotificationTestHelper.createRowWithRoundness( + /* topRoundness = */ 1f, + /* bottomRoundness = */ 1f, + /* sourceType = */ SourceType.OnScroll); + + mChildrenContainer.addNotification(row, 0); + + Assert.assertEquals(0f, row.getTopRoundness(), /* delta = */ 0f); + Assert.assertEquals(0f, row.getBottomRoundness(), /* delta = */ 0f); + } + + @Test + public void addNotification_shouldNotResetOtherRoundness() throws Exception { + ExpandableNotificationRow row1 = mNotificationTestHelper.createRowWithRoundness( + /* topRoundness = */ 1f, + /* bottomRoundness = */ 1f, + /* sourceType = */ SourceType.DefaultValue); + ExpandableNotificationRow row2 = mNotificationTestHelper.createRowWithRoundness( + /* topRoundness = */ 1f, + /* bottomRoundness = */ 1f, + /* sourceType = */ SourceType.OnDismissAnimation); + + mChildrenContainer.addNotification(row1, 0); + mChildrenContainer.addNotification(row2, 0); + + Assert.assertEquals(1f, row1.getTopRoundness(), /* delta = */ 0f); + Assert.assertEquals(1f, row1.getBottomRoundness(), /* delta = */ 0f); + Assert.assertEquals(1f, row2.getTopRoundness(), /* delta = */ 0f); + Assert.assertEquals(1f, row2.getBottomRoundness(), /* delta = */ 0f); + } } 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 77418138158b..bda233611158 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 @@ -1,6 +1,7 @@ package com.android.systemui.statusbar.notification.stack import android.testing.AndroidTestingRunner +import android.testing.TestableLooper import android.testing.TestableLooper.RunWithLooper import androidx.test.filters.SmallTest import com.android.keyguard.BouncerPanelExpansionCalculator.aboutToShowBouncerProgress @@ -8,8 +9,10 @@ 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.SourceType import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow import com.android.systemui.statusbar.notification.row.ExpandableView +import com.android.systemui.statusbar.notification.row.NotificationTestHelper import com.android.systemui.statusbar.notification.stack.StackScrollAlgorithm.StackScrollAlgorithmState import com.android.systemui.util.mockito.mock import junit.framework.Assert.assertEquals @@ -37,6 +40,13 @@ class NotificationShelfTest : SysuiTestCase() { private val shelfState = shelf.viewState as NotificationShelf.ShelfState private val ambientState = mock(AmbientState::class.java) private val hostLayoutController: NotificationStackScrollLayoutController = mock() + private val notificationTestHelper by lazy { + allowTestableLooperAsMainThread() + NotificationTestHelper( + mContext, + mDependency, + TestableLooper.get(this)) + } @Before fun setUp() { @@ -299,6 +309,39 @@ class NotificationShelfTest : SysuiTestCase() { ) } + @Test + fun resetOnScrollRoundness_shouldSetOnScrollTo0() { + val row: ExpandableNotificationRow = notificationTestHelper.createRowWithRoundness( + /* topRoundness = */ 1f, + /* bottomRoundness = */ 1f, + /* sourceType = */ SourceType.OnScroll) + + NotificationShelf.resetOnScrollRoundness(row) + + assertEquals(0f, row.topRoundness) + assertEquals(0f, row.bottomRoundness) + } + + @Test + fun resetOnScrollRoundness_shouldNotResetOtherRoundness() { + val row1: ExpandableNotificationRow = notificationTestHelper.createRowWithRoundness( + /* topRoundness = */ 1f, + /* bottomRoundness = */ 1f, + /* sourceType = */ SourceType.DefaultValue) + val row2: ExpandableNotificationRow = notificationTestHelper.createRowWithRoundness( + /* topRoundness = */ 1f, + /* bottomRoundness = */ 1f, + /* sourceType = */ SourceType.OnDismissAnimation) + + NotificationShelf.resetOnScrollRoundness(row1) + NotificationShelf.resetOnScrollRoundness(row2) + + assertEquals(1f, row1.topRoundness) + assertEquals(1f, row1.bottomRoundness) + assertEquals(1f, row2.topRoundness) + assertEquals(1f, row2.bottomRoundness) + } + private fun setFractionToShade(fraction: Float) { whenever(ambientState.fractionToShade).thenReturn(fraction) } |