From bef187f9180fa8744fe608637f5e25a029e1eee5 Mon Sep 17 00:00:00 2001 From: Lyn Han Date: Wed, 25 May 2022 15:29:43 -0700 Subject: [PATCH] Remove divider height before first view in shade to save vertical space on lockscreen. Bug: 214257536 Test: NotificationStackSizeCalculatorTest Change-Id: I3132cf4bad09983661e1cd5b3eef8b3caf81799b --- .../stack/NotificationStackSizeCalculator.kt | 26 ++++++++++++------- .../NotificationStackSizeCalculatorTest.kt | 12 ++++----- 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationStackSizeCalculator.kt b/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationStackSizeCalculator.kt index 6287857e7be97..22234b1ef17d2 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationStackSizeCalculator.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationStackSizeCalculator.kt @@ -58,7 +58,7 @@ constructor( private var maxKeyguardNotifications by notNull() /** Minimum space between two notifications, see [calculateGapAndDividerHeight]. */ - private var dividerHeight by notNull() + private var dividerHeight by notNull() init { updateResources() @@ -142,9 +142,13 @@ constructor( if (i == children.lastIndex) { 0f // No shelf needed. } else { + val firstViewInShelfIndex = i + 1 val spaceBeforeShelf = calculateGapAndDividerHeight( - stack, previous = currentNotification, current = children[i + 1], i) + stack, + previous = currentNotification, + current = children[firstViewInShelfIndex], + currentIndex = firstViewInShelfIndex) spaceBeforeShelf + shelfIntrinsicHeight } @@ -156,16 +160,17 @@ constructor( maxKeyguardNotifications = infiniteIfNegative(resources.getInteger(R.integer.keyguard_max_notification_count)) - dividerHeight = max(1, resources.getDimensionPixelSize(R.dimen.notification_divider_height)) + dividerHeight = + max(1f, resources.getDimensionPixelSize(R.dimen.notification_divider_height).toFloat()) } private val NotificationStackScrollLayout.childrenSequence: Sequence get() = children.map { it as ExpandableView } @VisibleForTesting - fun onLockscreen() : Boolean { - return statusBarStateController.state == KEYGUARD - && lockscreenShadeTransitionController.fractionToShade == 0f + fun onLockscreen(): Boolean { + return statusBarStateController.state == KEYGUARD && + lockscreenShadeTransitionController.fractionToShade == 0f } @VisibleForTesting @@ -207,11 +212,12 @@ constructor( stack: NotificationStackScrollLayout, previous: ExpandableView?, current: ExpandableView?, - visibleIndex: Int + currentIndex: Int ): Float { - var height = stack.calculateGapHeight(previous, current, visibleIndex) - height += dividerHeight - return height + if (currentIndex == 0) { + return 0f + } + return stack.calculateGapHeight(previous, current, currentIndex) + dividerHeight } private fun NotificationStackScrollLayout.showableChildren() = diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/stack/NotificationStackSizeCalculatorTest.kt b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/stack/NotificationStackSizeCalculatorTest.kt index 663490ebfde0f..ef680210e3fe2 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/stack/NotificationStackSizeCalculatorTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/stack/NotificationStackSizeCalculatorTest.kt @@ -125,8 +125,7 @@ class NotificationStackSizeCalculatorTest : SysuiTestCase() { // Each row in separate section. setGapHeight(gapHeight) val spaceUsed = - listOf( - dividerHeight + rowHeight, + listOf(rowHeight, dividerHeight + gapHeight + rowHeight, dividerHeight + gapHeight + shelfHeight) .sum() @@ -149,9 +148,8 @@ class NotificationStackSizeCalculatorTest : SysuiTestCase() { val rowHeight = rowHeight val shelfHeight = shelfHeight val spaceUsed = - listOf( - dividerHeight + rowHeight, - dividerHeight + shelfHeight) + listOf(rowHeight, + dividerHeight + shelfHeight) .sum() val availableSpace = spaceUsed + 1 val rows = listOf(createMockRow(rowHeight), createMockRow(rowHeight)) @@ -195,7 +193,7 @@ class NotificationStackSizeCalculatorTest : SysuiTestCase() { val space = sizeCalculator.spaceNeeded(expandableView, visibleIndex = 0, previousView = null, stack = stackLayout, onLockscreen = true) - assertThat(space).isEqualTo(5 + dividerHeight) + assertThat(space).isEqualTo(5) } @Test @@ -209,7 +207,7 @@ class NotificationStackSizeCalculatorTest : SysuiTestCase() { val space = sizeCalculator.spaceNeeded(expandableView, visibleIndex = 0, previousView = null, stack = stackLayout, onLockscreen = false) - assertThat(space).isEqualTo(10 + dividerHeight) + assertThat(space).isEqualTo(10) } private fun computeMaxKeyguardNotifications(