Merge changes from topics "presubmit-am-121da4597331411b86c0a3f45eabcc4c", "presubmit-am-85bb9a360df04e4fa2dd6536bf36fa36" into tm-dev

* changes:
  Add missing divider height before notification shelf
  Rename notification padding to divider height
This commit is contained in:
Lyn Han
2022-04-09 01:34:30 +00:00
committed by Android (Google) Code Review
2 changed files with 25 additions and 21 deletions

View File

@@ -52,9 +52,9 @@ constructor(
private var maxKeyguardNotifications by notNull<Int>() private var maxKeyguardNotifications by notNull<Int>()
/** /**
* Minimum space between two notifications. There might be more space, see [calculateGapHeight]. * Minimum space between two notifications, see [calculateGapAndDividerHeight].
*/ */
private var notificationPadding by notNull<Int>() private var dividerHeight by notNull<Int>()
init { init {
updateResources() updateResources()
@@ -84,16 +84,20 @@ constructor(
val onLockscreen = true val onLockscreen = true
val showableRows = children.filter { it.isShowable(onLockscreen) } val showableRows = children.filter { it.isShowable(onLockscreen) }
val showableRowsCount = showableRows.count() val showableRowsCount = showableRows.count()
log { "\tshowableRowsCount=$showableRowsCount "}
showableRows.forEachIndexed { i, current -> showableRows.forEachIndexed { i, current ->
val spaceNeeded = current.spaceNeeded(count, previous, stack, onLockscreen) val spaceNeeded = current.spaceNeeded(count, previous, stack, onLockscreen)
val spaceAfter = remainingSpace - spaceNeeded
previous = current previous = current
log { "\ti=$i spaceNeeded=$spaceNeeded remainingSpace=$remainingSpace" } log { "\ti=$i spaceNeeded=$spaceNeeded remainingSpace=$remainingSpace " +
"spaceAfter=$spaceAfter" }
if (remainingSpace - spaceNeeded >= 0 && count < maxKeyguardNotifications) { if (remainingSpace - spaceNeeded >= 0 && count < maxKeyguardNotifications) {
count += 1 count += 1
remainingSpace -= spaceNeeded remainingSpace -= spaceNeeded
} else if (remainingSpace - spaceNeeded > -shelfHeight && i == showableRowsCount - 1) { } else if (remainingSpace - spaceNeeded > -shelfHeight && i == showableRowsCount - 1) {
log { "Showing all notifications. Shelf is not be needed." } log { "Show all notifications. Shelf not needed." }
// If this is the last one, and it fits using the space shelf would use, then we can // If this is the last one, and it fits using the space shelf would use, then we can
// display it, as the shelf will not be needed (as all notifications are shown). // display it, as the shelf will not be needed (as all notifications are shown).
return count + 1 return count + 1
@@ -139,8 +143,7 @@ constructor(
height += spaceNeeded height += spaceNeeded
count += 1 count += 1
} else { } else {
val gapBeforeFirstViewInShelf = current.calculateGapHeight(stack, previous, count) height += current.calculateGapAndDividerHeight(stack, previous, count)
height += gapBeforeFirstViewInShelf
height += shelfHeight height += shelfHeight
log { "returning height with shelf -> $height" } log { "returning height with shelf -> $height" }
return height return height
@@ -155,7 +158,7 @@ constructor(
maxKeyguardNotifications = maxKeyguardNotifications =
infiniteIfNegative(resources.getInteger(R.integer.keyguard_max_notification_count)) infiniteIfNegative(resources.getInteger(R.integer.keyguard_max_notification_count))
notificationPadding = dividerHeight =
max(1, resources.getDimensionPixelSize(R.dimen.notification_divider_height)) max(1, resources.getDimensionPixelSize(R.dimen.notification_divider_height))
} }
@@ -177,12 +180,7 @@ constructor(
} else { } else {
intrinsicHeight.toFloat() intrinsicHeight.toFloat()
} }
if (visibleIndex != 0) { size += calculateGapAndDividerHeight(stack, previousView, visibleIndex)
size += notificationPadding
}
val gapHeight = calculateGapHeight(stack, previousView, visibleIndex)
log { "\ti=$visibleIndex gapHeight=$gapHeight"}
size += gapHeight
return size return size
} }
@@ -202,11 +200,17 @@ constructor(
return true return true
} }
private fun ExpandableView.calculateGapHeight( private fun ExpandableView.calculateGapAndDividerHeight(
stack: NotificationStackScrollLayout, stack: NotificationStackScrollLayout,
previous: ExpandableView?, previous: ExpandableView?,
visibleIndex: Int visibleIndex: Int
) = stack.calculateGapHeight(previous, /* current= */ this, visibleIndex) ) : Float {
var height = stack.calculateGapHeight(previous, /* current= */ this, visibleIndex)
if (visibleIndex != 0) {
height += dividerHeight
}
return height
}
/** /**
* Can a view be shown on the lockscreen when calculating the number of allowed notifications to * Can a view be shown on the lockscreen when calculating the number of allowed notifications to

View File

@@ -57,7 +57,7 @@ class NotificationStackSizeCalculatorTest : SysuiTestCase() {
.thenReturn(GAP_HEIGHT) .thenReturn(GAP_HEIGHT)
with(testableResources) { with(testableResources) {
addOverride(R.integer.keyguard_max_notification_count, -1) addOverride(R.integer.keyguard_max_notification_count, -1)
addOverride(R.dimen.notification_divider_height, NOTIFICATION_PADDING.toInt()) addOverride(R.dimen.notification_divider_height, DIVIDER_HEIGHT.toInt())
} }
sizeCalculator = sizeCalculator =
@@ -109,7 +109,7 @@ class NotificationStackSizeCalculatorTest : SysuiTestCase() {
fun computeMaxKeyguardNotifications_spaceForOne_shelfUsableForLastNotification_returnsTwo() { fun computeMaxKeyguardNotifications_spaceForOne_shelfUsableForLastNotification_returnsTwo() {
val rowHeight = ROW_HEIGHT val rowHeight = ROW_HEIGHT
val totalSpaceForEachRow = GAP_HEIGHT + rowHeight val totalSpaceForEachRow = GAP_HEIGHT + rowHeight
val shelfHeight = totalSpaceForEachRow + NOTIFICATION_PADDING val shelfHeight = totalSpaceForEachRow + DIVIDER_HEIGHT
val spaceForOne = totalSpaceForEachRow val spaceForOne = totalSpaceForEachRow
val rows = val rows =
listOf( listOf(
@@ -127,7 +127,7 @@ class NotificationStackSizeCalculatorTest : SysuiTestCase() {
fun computeMaxKeyguardNotifications_spaceForTwo_returnsTwo() { fun computeMaxKeyguardNotifications_spaceForTwo_returnsTwo() {
val rowHeight = ROW_HEIGHT val rowHeight = ROW_HEIGHT
val totalSpaceForEachRow = GAP_HEIGHT + rowHeight val totalSpaceForEachRow = GAP_HEIGHT + rowHeight
val spaceForTwo = totalSpaceForEachRow * 2 + NOTIFICATION_PADDING val spaceForTwo = totalSpaceForEachRow * 2 + DIVIDER_HEIGHT
val rows = val rows =
listOf( listOf(
createMockRow(rowHeight), createMockRow(rowHeight),
@@ -143,7 +143,7 @@ class NotificationStackSizeCalculatorTest : SysuiTestCase() {
fun computeHeight_returnsAtMostSpaceAvailable_withGapBeforeShelf() { fun computeHeight_returnsAtMostSpaceAvailable_withGapBeforeShelf() {
val rowHeight = ROW_HEIGHT val rowHeight = ROW_HEIGHT
val shelfHeight = SHELF_HEIGHT val shelfHeight = SHELF_HEIGHT
val totalSpaceForEachRow = GAP_HEIGHT + rowHeight + NOTIFICATION_PADDING val totalSpaceForEachRow = GAP_HEIGHT + rowHeight + DIVIDER_HEIGHT
val availableSpace = totalSpaceForEachRow * 2 val availableSpace = totalSpaceForEachRow * 2
// All rows in separate sections (default setup). // All rows in separate sections (default setup).
@@ -164,7 +164,7 @@ class NotificationStackSizeCalculatorTest : SysuiTestCase() {
fun computeHeight_returnsAtMostSpaceAvailable_noGapBeforeShelf() { fun computeHeight_returnsAtMostSpaceAvailable_noGapBeforeShelf() {
val rowHeight = ROW_HEIGHT val rowHeight = ROW_HEIGHT
val shelfHeight = SHELF_HEIGHT val shelfHeight = SHELF_HEIGHT
val totalSpaceForEachRow = GAP_HEIGHT + rowHeight + NOTIFICATION_PADDING val totalSpaceForEachRow = GAP_HEIGHT + rowHeight + DIVIDER_HEIGHT
val availableSpace = totalSpaceForEachRow * 1 val availableSpace = totalSpaceForEachRow * 1
// Both rows are in the same section. // Both rows are in the same section.
@@ -223,7 +223,7 @@ class NotificationStackSizeCalculatorTest : SysuiTestCase() {
/** Default dimensions for tests that don't overwrite them. */ /** Default dimensions for tests that don't overwrite them. */
companion object { companion object {
const val GAP_HEIGHT = 12f const val GAP_HEIGHT = 12f
const val NOTIFICATION_PADDING = 3f const val DIVIDER_HEIGHT = 3f
const val SHELF_HEIGHT = 14f const val SHELF_HEIGHT = 14f
const val ROW_HEIGHT = SHELF_HEIGHT * 3 const val ROW_HEIGHT = SHELF_HEIGHT * 3
} }