diff options
| author | 2025-03-07 15:04:41 -0800 | |
|---|---|---|
| committer | 2025-03-07 15:04:41 -0800 | |
| commit | 7c7cc44627a56b2404656b2d0c69fabcee4328d5 (patch) | |
| tree | 4f600fa895b200429cde62ffdc0a24b45f04ee51 | |
| parent | 93780a19de44071f186f1f0b9398ad789267713d (diff) | |
[Media] Limit output device chip width to 40% of card
Fix: 401264395
Test: provided a very long text for the chip from the fake interactor
used in the Compose Gallery app; saw that it was properly kept in check
and ellipsizing the end of the text
Flag: EXEMPT not yet
Change-Id: Ib2ae8a31b8e72c7cf8d45ae98f9fb254d8d55dfa
| -rw-r--r-- | packages/SystemUI/src/com/android/systemui/media/remedia/ui/compose/Media.kt | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/media/remedia/ui/compose/Media.kt b/packages/SystemUI/src/com/android/systemui/media/remedia/ui/compose/Media.kt index 17423e235af6..7543e0f2af2e 100644 --- a/packages/SystemUI/src/com/android/systemui/media/remedia/ui/compose/Media.kt +++ b/packages/SystemUI/src/com/android/systemui/media/remedia/ui/compose/Media.kt @@ -46,6 +46,7 @@ import androidx.compose.foundation.interaction.MutableInteractionSource import androidx.compose.foundation.interaction.PressInteraction import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.BoxWithConstraints import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Spacer @@ -54,6 +55,7 @@ import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.size +import androidx.compose.foundation.layout.widthIn import androidx.compose.foundation.shape.CircleShape import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.material3.ButtonDefaults @@ -404,7 +406,7 @@ private fun ContentScope.CardForegroundContent( ) ) { // Always add the first/top row, regardless of presentation style. - Box(modifier = Modifier.fillMaxWidth()) { + BoxWithConstraints(modifier = Modifier.fillMaxWidth()) { // Icon. Icon( icon = viewModel.icon, @@ -421,7 +423,20 @@ private fun ContentScope.CardForegroundContent( modifier = Modifier.align(Alignment.TopEnd), ) { viewModel.outputSwitcherChips.fastForEach { chip -> - OutputSwitcherChip(viewModel = chip, colorScheme = colorScheme) + OutputSwitcherChip( + viewModel = chip, + colorScheme = colorScheme, + modifier = + Modifier + // Each chip must be limited to 40% of the width of the card at + // most. + // + // The underlying assumption is that there'll never be more than one + // chip with text and one more icon-only chip. Only the one with + // text + // can ever end up being too wide. + .widthIn(max = this@BoxWithConstraints.maxWidth * 0.4f), + ) } } } @@ -1024,6 +1039,8 @@ private fun OutputSwitcherChip( text = viewModel.text, style = MaterialTheme.typography.bodySmall, color = colorScheme.onPrimary, + maxLines = 1, + overflow = TextOverflow.Ellipsis, ) } } |