From 805da853843c03d4dd0d36bdfba7c8d7b860104e Mon Sep 17 00:00:00 2001 From: omarmt Date: Thu, 15 Dec 2022 10:14:02 +0000 Subject: [PATCH] Do not reset roundness on ExpandableOutlineView.initDimens() Manual test steps: - Post some notifications in different sections - Change the wallpaper of your device Previous behavior: Notifications no longer stayed rounded New behavior: Notifications remain rounded Test: atest ActivatableNotificationViewTest.roundnessShouldBeTheSame_after_onDensityOrFontScale() Bug: 262573700 Change-Id: I12550d1201b8e43ca7af92a1ba5fd1e164446bd0 --- .../systemui/statusbar/notification/Roundable.kt | 14 ++++++++++++-- .../notification/row/ExpandableOutlineView.java | 6 +++++- .../row/ActivatableNotificationViewTest.kt | 14 ++++++++++++++ 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/Roundable.kt b/packages/SystemUI/src/com/android/systemui/statusbar/notification/Roundable.kt index 0eb00008e289e..dc9b41690d61f 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/Roundable.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/Roundable.kt @@ -306,9 +306,12 @@ interface Roundable { */ class RoundableState( internal val targetView: View, - roundable: Roundable, - internal val maxRadius: Float, + private val roundable: Roundable, + maxRadius: Float, ) { + internal var maxRadius = maxRadius + private set + /** Animatable for top roundness */ private val topAnimatable = topAnimatable(roundable) @@ -356,6 +359,13 @@ class RoundableState( PropertyAnimator.setProperty(targetView, bottomAnimatable, value, DURATION, animated) } + fun setMaxRadius(radius: Float) { + if (maxRadius != radius) { + maxRadius = radius + roundable.applyRoundnessAndInvalidate() + } + } + fun debugString() = buildString { append("TargetView: ${targetView.hashCode()} ") append("Top: $topRoundness ") diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/ExpandableOutlineView.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/ExpandableOutlineView.java index 0213b969551ef..20412452b7f99 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/ExpandableOutlineView.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/ExpandableOutlineView.java @@ -214,7 +214,11 @@ public abstract class ExpandableOutlineView extends ExpandableView { } else { maxRadius = res.getDimensionPixelSize(R.dimen.notification_corner_radius); } - mRoundableState = new RoundableState(this, this, maxRadius); + if (mRoundableState == null) { + mRoundableState = new RoundableState(this, this, maxRadius); + } else { + mRoundableState.setMaxRadius(maxRadius); + } setClipToOutline(mAlwaysRoundBothCorners); } diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/ActivatableNotificationViewTest.kt b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/ActivatableNotificationViewTest.kt index 5f5769572008f..3f61af0425de0 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/ActivatableNotificationViewTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/ActivatableNotificationViewTest.kt @@ -26,6 +26,7 @@ import com.android.systemui.R import com.android.systemui.SysuiTestCase import com.android.systemui.statusbar.notification.FakeShadowView import com.android.systemui.statusbar.notification.NotificationUtils +import com.android.systemui.statusbar.notification.SourceType import com.android.systemui.util.mockito.mock import com.google.common.truth.Truth.assertThat import org.junit.Before @@ -83,4 +84,17 @@ class ActivatableNotificationViewTest : SysuiTestCase() { mView.updateBackgroundColors() assertThat(mView.currentBackgroundTint).isEqualTo(mNormalColor) } + + @Test + fun roundnessShouldBeTheSame_after_onDensityOrFontScaleChanged() { + val roundableState = mView.roundableState + assertThat(mView.topRoundness).isEqualTo(0f) + mView.requestTopRoundness(1f, SourceType.from("")) + assertThat(mView.topRoundness).isEqualTo(1f) + + mView.onDensityOrFontScaleChanged() + + assertThat(mView.topRoundness).isEqualTo(1f) + assertThat(mView.roundableState.hashCode()).isEqualTo(roundableState.hashCode()) + } } \ No newline at end of file