Merge "Fixing split shade going full black when changing density" into sc-v2-dev

This commit is contained in:
Michał Brzeziński
2021-12-17 00:37:58 +00:00
committed by Android (Google) Code Review
2 changed files with 44 additions and 16 deletions

View File

@@ -411,7 +411,7 @@ public class NotificationStackScrollLayout extends ViewGroup implements Dumpable
private NotificationShelf mShelf;
private int mMaxDisplayedNotifications = -1;
private float mKeyguardBottomPadding = -1;
private int mStatusBarHeight;
@VisibleForTesting int mStatusBarHeight;
private int mMinInteractionHeight;
private final Rect mClipRect = new Rect();
private boolean mIsClipped;
@@ -4851,8 +4851,12 @@ public class NotificationStackScrollLayout extends ViewGroup implements Dumpable
@ShadeViewRefactor(RefactorComponent.COORDINATOR)
public int getMinExpansionHeight() {
// shelf height is defined in dp but status bar height can be defined in px, that makes
// relation between them variable - sometimes one might be bigger than the other when
// changing density. That’s why we need to ensure we’re not subtracting negative value below
return mShelf.getIntrinsicHeight()
- (mShelf.getIntrinsicHeight() - mStatusBarHeight + mWaterfallTopInset) / 2
- Math.max(0,
(mShelf.getIntrinsicHeight() - mStatusBarHeight + mWaterfallTopInset) / 2)
+ mWaterfallTopInset;
}

View File

@@ -22,6 +22,7 @@ import static android.view.View.GONE;
import static com.android.systemui.statusbar.notification.stack.NotificationStackScrollLayout.ROWS_ALL;
import static com.android.systemui.statusbar.notification.stack.NotificationStackScrollLayout.ROWS_GENTLE;
import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth.assertWithMessage;
import static junit.framework.Assert.assertEquals;
@@ -103,6 +104,7 @@ public class NotificationStackScrollLayoutTest extends SysuiTestCase {
@Mock private NotificationSwipeHelper mNotificationSwipeHelper;
@Mock private NotificationStackScrollLayoutController mStackScrollLayoutController;
@Mock private UnlockedScreenOffAnimationController mUnlockedScreenOffAnimationController;
@Mock private NotificationShelf mNotificationShelf;
@Before
@UiThreadTest
@@ -124,13 +126,13 @@ public class NotificationStackScrollLayoutTest extends SysuiTestCase {
mDependency.injectTestDependency(GroupMembershipManager.class, mGroupMembershipManger);
mDependency.injectTestDependency(GroupExpansionManager.class, mGroupExpansionManager);
mDependency.injectTestDependency(AmbientState.class, mAmbientState);
mDependency.injectTestDependency(NotificationShelf.class, mNotificationShelf);
mDependency.injectTestDependency(
UnlockedScreenOffAnimationController.class, mUnlockedScreenOffAnimationController);
NotificationShelfController notificationShelfController =
mock(NotificationShelfController.class);
NotificationShelf notificationShelf = mock(NotificationShelf.class);
when(notificationShelfController.getView()).thenReturn(notificationShelf);
when(notificationShelfController.getView()).thenReturn(mNotificationShelf);
when(mNotificationSectionsManager.createSectionsForBuckets()).thenReturn(
new NotificationSection[]{
mNotificationSection
@@ -160,7 +162,7 @@ public class NotificationStackScrollLayoutTest extends SysuiTestCase {
anyBoolean());
doNothing().when(mGroupExpansionManager).collapseGroups();
doNothing().when(mExpandHelper).cancelImmediately();
doNothing().when(notificationShelf).setAnimationsEnabled(anyBoolean());
doNothing().when(mNotificationShelf).setAnimationsEnabled(anyBoolean());
}
@Test
@@ -203,21 +205,43 @@ public class NotificationStackScrollLayoutTest extends SysuiTestCase {
@Test
@UiThreadTest
public void testSetExpandedHeight_blockingHelperManagerReceivedCallbacks() {
final float[] expectedHeight = {0f};
final float[] expectedAppear = {0f};
public void testSetExpandedHeight_listenerReceivedCallbacks() {
final float expectedHeight = 0f;
mStackScroller.addOnExpandedHeightChangedListener((height, appear) -> {
Assert.assertEquals(expectedHeight[0], height, 0);
Assert.assertEquals(expectedAppear[0], appear, .1);
Assert.assertEquals(expectedHeight, height, 0);
});
expectedHeight[0] = 1f;
expectedAppear[0] = 1f;
mStackScroller.setExpandedHeight(expectedHeight[0]);
mStackScroller.setExpandedHeight(expectedHeight);
}
expectedHeight[0] = 100f;
expectedAppear[0] = 0f;
mStackScroller.setExpandedHeight(expectedHeight[0]);
@Test
public void testAppearFractionCalculation() {
// appear start position
when(mNotificationShelf.getIntrinsicHeight()).thenReturn(100);
// because it's the same as shelf height, appear start position equals shelf height
mStackScroller.mStatusBarHeight = 100;
// appear end position
when(mEmptyShadeView.getHeight()).thenReturn(200);
assertEquals(0f, mStackScroller.calculateAppearFraction(100));
assertEquals(1f, mStackScroller.calculateAppearFraction(200));
assertEquals(0.5f, mStackScroller.calculateAppearFraction(150));
}
@Test
public void testAppearFractionCalculationIsNotNegativeWhenShelfBecomesSmaller() {
// this situation might occur if status bar height is defined in pixels while shelf height
// in dp and screen density changes - appear start position
// (calculated in NSSL#getMinExpansionHeight) that is adjusting for status bar might
// increase and become bigger that end position, which should be prevented
// appear start position
when(mNotificationShelf.getIntrinsicHeight()).thenReturn(80);
mStackScroller.mStatusBarHeight = 100;
// appear end position
when(mEmptyShadeView.getHeight()).thenReturn(90);
assertThat(mStackScroller.calculateAppearFraction(100)).isAtLeast(0);
}
@Test