diff options
author | 2025-03-20 17:05:12 +0000 | |
---|---|---|
committer | 2025-03-24 07:03:03 -0700 | |
commit | 83829be2a6b5884f2700d2a882af4d1a982798e6 (patch) | |
tree | 2e516e052007756bb0fc01c22d2d4b3ef0dd15a7 /packages/SystemUI/src | |
parent | 546dbf9141f9e843896da815908f62161fa01799 (diff) |
[SB][Chips] Reduce padding in the normal icon + text chips.
This is to make the call chip padding & screen record chip padding look
similar (b/397494654). Mostly, this re-writes a few things:
- Renames the old padding dimen to _legacy
- Updates the ChipIcon data class to say whether it has embedded
padding
- Adds some comments about how paddings work (when I originally wrote
this CL, I tried to simplify things but ended up making it worse
because I forgot why the paddings were in certain places)
- Always apply the minimum width, but make sure the min width uses
2*padding
Luckily the screenshot tests will show that most chips are unchanged.
Fixes: 397494654
Bug: 364653005
Flag: com.android.systemui.status_bar_chips_modernization
Test: Trigger screen record chip -> verify it has slightly less side
padding
Test: Verify other chips still have the same padding as before
Change-Id: Iab3d4f043f008fdef1a158e37391007afe6630ce
Diffstat (limited to 'packages/SystemUI/src')
4 files changed, 31 insertions, 26 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/chips/ui/binder/OngoingActivityChipBinder.kt b/packages/SystemUI/src/com/android/systemui/statusbar/chips/ui/binder/OngoingActivityChipBinder.kt index 77e0dde3dec5..4fab008d5bca 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/chips/ui/binder/OngoingActivityChipBinder.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/chips/ui/binder/OngoingActivityChipBinder.kt @@ -437,7 +437,9 @@ object OngoingActivityChipBinder { private fun View.setBackgroundPaddingForNormalIcon() { val sidePadding = - context.resources.getDimensionPixelSize(R.dimen.ongoing_activity_chip_side_padding) + context.resources.getDimensionPixelSize( + R.dimen.ongoing_activity_chip_side_padding_legacy + ) setPaddingRelative(sidePadding, paddingTop, sidePadding, paddingBottom) } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/chips/ui/compose/ChipContent.kt b/packages/SystemUI/src/com/android/systemui/statusbar/chips/ui/compose/ChipContent.kt index 18cecb4abc31..76c20e20f41d 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/chips/ui/compose/ChipContent.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/chips/ui/compose/ChipContent.kt @@ -50,21 +50,21 @@ import kotlin.math.min fun ChipContent(viewModel: OngoingActivityChipModel.Active, modifier: Modifier = Modifier) { val context = LocalContext.current val density = LocalDensity.current - val isTextOnly = viewModel.icon == null - val hasEmbeddedIcon = - viewModel.icon is OngoingActivityChipModel.ChipIcon.StatusBarView || - viewModel.icon is OngoingActivityChipModel.ChipIcon.StatusBarNotificationIcon val textStyle = MaterialTheme.typography.labelLargeEmphasized val textColor = Color(viewModel.colors.text(context)) val maxTextWidth = dimensionResource(id = R.dimen.ongoing_activity_chip_max_text_width) + val icon = viewModel.icon val startPadding = - if (isTextOnly || hasEmbeddedIcon) { - 0.dp - } else { + if (icon != null && !icon.hasEmbeddedPadding) { + // Add padding only if this text is next to an icon that doesn't embed its own padding dimensionResource(id = R.dimen.ongoing_activity_chip_icon_text_padding) + } else { + 0.dp } + // Include endPadding in the Text instead of the outer OngoingActivityChip so that if the text + // is hidden because it's too large, then the remaining icon is still centered val endPadding = - if (hasEmbeddedIcon) { + if (icon?.hasEmbeddedPadding == true) { dimensionResource( id = R.dimen.ongoing_activity_chip_text_end_padding_for_embedded_padding_icon ) diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/chips/ui/compose/OngoingActivityChip.kt b/packages/SystemUI/src/com/android/systemui/statusbar/chips/ui/compose/OngoingActivityChip.kt index 167035b2d17d..18a72a22c39c 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/chips/ui/compose/OngoingActivityChip.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/chips/ui/compose/OngoingActivityChip.kt @@ -41,6 +41,8 @@ import androidx.compose.ui.res.dimensionResource import androidx.compose.ui.semantics.contentDescription import androidx.compose.ui.semantics.semantics import androidx.compose.ui.unit.Dp +import androidx.compose.ui.unit.dp +import androidx.compose.ui.unit.times import androidx.compose.ui.viewinterop.AndroidView import com.android.compose.animation.Expandable import com.android.compose.modifiers.thenIf @@ -87,14 +89,15 @@ fun OngoingActivityChip( } val isClickable = onClick != null - val chipSidePadding = dimensionResource(id = R.dimen.ongoing_activity_chip_side_padding) + val chipSidePaddingTotal = 20.dp val minWidth = if (isClickable) { dimensionResource(id = R.dimen.min_clickable_item_size) } else if (model.icon != null) { - dimensionResource(id = R.dimen.ongoing_activity_chip_icon_size) + chipSidePadding + dimensionResource(id = R.dimen.ongoing_activity_chip_icon_size) + chipSidePaddingTotal } else { - dimensionResource(id = R.dimen.ongoing_activity_chip_min_text_width) + chipSidePadding + dimensionResource(id = R.dimen.ongoing_activity_chip_min_text_width) + + chipSidePaddingTotal } Expandable( @@ -109,7 +112,7 @@ fun OngoingActivityChip( this.contentDescription = contentDescription } } - .thenIf(isClickable) { Modifier.widthIn(min = minWidth) } + .widthIn(min = minWidth) // For non-privacy-related chips, only show the chip if there's enough space for at // least the minimum width. .thenIf(!model.isImportantForPrivacy) { @@ -138,7 +141,7 @@ fun OngoingActivityChip( defaultMinSize = false, transitionControllerFactory = model.transitionManager?.controllerFactory, ) { - ChipBody(model, iconViewStore, isClickable = isClickable, minWidth = minWidth) + ChipBody(model, iconViewStore, minWidth = minWidth) } } @@ -146,14 +149,9 @@ fun OngoingActivityChip( private fun ChipBody( model: OngoingActivityChipModel.Active, iconViewStore: NotificationIconContainerViewBinder.IconViewStore?, - isClickable: Boolean, minWidth: Dp, modifier: Modifier = Modifier, ) { - val hasEmbeddedIcon = - model.icon is OngoingActivityChipModel.ChipIcon.StatusBarView || - model.icon is OngoingActivityChipModel.ChipIcon.StatusBarNotificationIcon - Row( horizontalArrangement = Arrangement.Center, verticalAlignment = Alignment.CenterVertically, @@ -162,15 +160,17 @@ private fun ChipBody( .fillMaxHeight() // Set the minWidth here as well as on the Expandable so that the content within // this row is still centered correctly horizontally - .thenIf(isClickable) { Modifier.widthIn(min = minWidth) } + .widthIn(min = minWidth) .padding( + // Always keep start & end padding the same so that if the text has to hide for + // some reason, the content is still centered horizontal = - if (hasEmbeddedIcon) { + if (model.icon?.hasEmbeddedPadding == true) { dimensionResource( R.dimen.ongoing_activity_chip_side_padding_for_embedded_padding_icon ) } else { - dimensionResource(id = R.dimen.ongoing_activity_chip_side_padding) + 6.dp } ), ) { diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/chips/ui/model/OngoingActivityChipModel.kt b/packages/SystemUI/src/com/android/systemui/statusbar/chips/ui/model/OngoingActivityChipModel.kt index 2c4746f5fafb..c334c1a6b8ad 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/chips/ui/model/OngoingActivityChipModel.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/chips/ui/model/OngoingActivityChipModel.kt @@ -281,7 +281,10 @@ sealed class OngoingActivityChipModel { } /** Represents an icon to show on the chip. */ - sealed interface ChipIcon { + sealed class ChipIcon( + /** True if this icon will have padding embedded within its view. */ + open val hasEmbeddedPadding: Boolean + ) { /** * The icon is a custom icon, which is set on [impl]. The icon was likely created by an * external app. @@ -289,7 +292,7 @@ sealed class OngoingActivityChipModel { data class StatusBarView( val impl: StatusBarIconView, val contentDescription: ContentDescription, - ) : ChipIcon { + ) : ChipIcon(hasEmbeddedPadding = true) { init { StatusBarConnectedDisplays.assertInLegacyMode() } @@ -302,7 +305,7 @@ sealed class OngoingActivityChipModel { data class StatusBarNotificationIcon( val notificationKey: String, val contentDescription: ContentDescription, - ) : ChipIcon { + ) : ChipIcon(hasEmbeddedPadding = true) { init { StatusBarConnectedDisplays.unsafeAssertInNewMode() } @@ -312,7 +315,7 @@ sealed class OngoingActivityChipModel { * This icon is a single color and it came from basic resource or drawable icon that System * UI created internally. */ - data class SingleColorIcon(val impl: Icon) : ChipIcon + data class SingleColorIcon(val impl: Icon) : ChipIcon(hasEmbeddedPadding = false) } /** Defines the behavior of the chip when it is clicked. */ |