[CredManUi] Truncate credential entry texts on the first page.

On the first page, the entry texts should be one line each and truncated
if exceeding the limit.

Bug: 269365202
Test: manual (see bug for screenshots)
Change-Id: Iafabcf391aa73172ee6372bb9bff4f32c1cbfde0
diff --git a/packages/CredentialManager/src/com/android/credentialmanager/common/ui/Entry.kt b/packages/CredentialManager/src/com/android/credentialmanager/common/ui/Entry.kt
index 92d2a04..0454c69 100644
--- a/packages/CredentialManager/src/com/android/credentialmanager/common/ui/Entry.kt
+++ b/packages/CredentialManager/src/com/android/credentialmanager/common/ui/Entry.kt
@@ -74,6 +74,7 @@
     passwordValue: String? = null,
     /** If true, draws a trailing lock icon. */
     isLockedAuthEntry: Boolean = false,
+    enforceOneLine: Boolean = false,
 ) {
     val iconPadding = Modifier.wrapContentSize().padding(
         // Horizontal padding should be 16dp, but the suggestion chip itself
@@ -93,10 +94,12 @@
                     // has 8dp horizontal elements padding
                     horizontal = 8.dp, vertical = 16.dp,
                 ),
+                // Make sure the trailing icon and text column are centered vertically.
                 verticalAlignment = Alignment.CenterVertically,
             ) {
-                Column(modifier = Modifier.wrapContentSize()) {
-                    SmallTitleText(entryHeadlineText)
+                // Apply weight so that the trailing icon can always show.
+                Column(modifier = Modifier.wrapContentHeight().fillMaxWidth().weight(1f)) {
+                    SmallTitleText(text = entryHeadlineText, enforceOneLine = enforceOneLine)
                     if (passwordValue != null) {
                         Row(modifier = Modifier.fillMaxWidth()) {
                             val visualTransformation = remember { PasswordVisualTransformation() }
@@ -110,7 +113,8 @@
                                     ).text.text
                                 )
                             }
-                            BodySmallText(displayedPassword.value)
+                            BodySmallText(
+                                text = displayedPassword.value, enforceOneLine = enforceOneLine)
                             ToggleVisibilityButton(
                                 modifier = Modifier.padding(start = 5.dp).size(24.dp),
                                 onToggle = {
@@ -125,14 +129,14 @@
                             )
                         }
                     } else if (entrySecondLineText != null) {
-                        BodySmallText(entrySecondLineText)
+                        BodySmallText(text = entrySecondLineText, enforceOneLine = enforceOneLine)
                     }
                     if (entryThirdLineText != null) {
-                        BodySmallText(entryThirdLineText)
+                        BodySmallText(text = entryThirdLineText, enforceOneLine = enforceOneLine)
                     }
                 }
                 if (isLockedAuthEntry) {
-                    Box(modifier = Modifier.wrapContentSize()) {
+                    Box(modifier = Modifier.wrapContentSize().padding(start = 16.dp)) {
                         Icon(
                             imageVector = Icons.Outlined.Lock,
                             // Decorative purpose only.
diff --git a/packages/CredentialManager/src/com/android/credentialmanager/common/ui/Texts.kt b/packages/CredentialManager/src/com/android/credentialmanager/common/ui/Texts.kt
index 8af729e..22871bc 100644
--- a/packages/CredentialManager/src/com/android/credentialmanager/common/ui/Texts.kt
+++ b/packages/CredentialManager/src/com/android/credentialmanager/common/ui/Texts.kt
@@ -23,6 +23,7 @@
 import androidx.compose.ui.Modifier
 import androidx.compose.ui.graphics.Color
 import androidx.compose.ui.text.style.TextAlign
+import androidx.compose.ui.text.style.TextOverflow
 
 /**
  * The headline for a screen. E.g. "Create a passkey for X", "Choose a saved sign-in for X".
@@ -57,12 +58,14 @@
  * Body-small typography; on-surface-variant color.
  */
 @Composable
-fun BodySmallText(text: String, modifier: Modifier = Modifier) {
+fun BodySmallText(text: String, modifier: Modifier = Modifier, enforceOneLine: Boolean = false) {
     Text(
         modifier = modifier.wrapContentSize(),
         text = text,
         color = MaterialTheme.colorScheme.onSurfaceVariant,
         style = MaterialTheme.typography.bodySmall,
+        overflow = TextOverflow.Ellipsis,
+        maxLines = if (enforceOneLine) 1 else Int.MAX_VALUE
     )
 }
 
@@ -83,12 +86,14 @@
  * Title-small typography; on-surface color.
  */
 @Composable
-fun SmallTitleText(text: String, modifier: Modifier = Modifier) {
+fun SmallTitleText(text: String, modifier: Modifier = Modifier, enforceOneLine: Boolean = false) {
     Text(
         modifier = modifier.wrapContentSize(),
         text = text,
         color = MaterialTheme.colorScheme.onSurface,
         style = MaterialTheme.typography.titleSmall,
+        overflow = TextOverflow.Ellipsis,
+        maxLines = if (enforceOneLine) 1 else Int.MAX_VALUE
     )
 }
 
diff --git a/packages/CredentialManager/src/com/android/credentialmanager/createflow/CreateCredentialComponents.kt b/packages/CredentialManager/src/com/android/credentialmanager/createflow/CreateCredentialComponents.kt
index b83c593..2cb0af4 100644
--- a/packages/CredentialManager/src/com/android/credentialmanager/createflow/CreateCredentialComponents.kt
+++ b/packages/CredentialManager/src/com/android/credentialmanager/createflow/CreateCredentialComponents.kt
@@ -637,6 +637,7 @@
         // This subtitle would never be null for create password
             requestDisplayInfo.subtitle ?: ""
         else null,
+        enforceOneLine = true,
     )
 }
 
diff --git a/packages/CredentialManager/src/com/android/credentialmanager/getflow/GetCredentialComponents.kt b/packages/CredentialManager/src/com/android/credentialmanager/getflow/GetCredentialComponents.kt
index 9a826f2..545c9e2 100644
--- a/packages/CredentialManager/src/com/android/credentialmanager/getflow/GetCredentialComponents.kt
+++ b/packages/CredentialManager/src/com/android/credentialmanager/getflow/GetCredentialComponents.kt
@@ -182,12 +182,14 @@
                             CredentialEntryRow(
                                 credentialEntryInfo = it.sortedCredentialEntryList.first(),
                                 onEntrySelected = onEntrySelected,
+                                enforceOneLine = true,
                             )
                         }
                         authenticationEntryList.forEach {
                             AuthenticationEntryRow(
                                 authenticationEntryInfo = it,
                                 onEntrySelected = onEntrySelected,
+                                enforceOneLine = true,
                             )
                         }
                     } else if (usernameForCredentialSize < 4) {
@@ -195,12 +197,14 @@
                             CredentialEntryRow(
                                 credentialEntryInfo = it.sortedCredentialEntryList.first(),
                                 onEntrySelected = onEntrySelected,
+                                enforceOneLine = true,
                             )
                         }
                         authenticationEntryList.take(4 - usernameForCredentialSize).forEach {
                             AuthenticationEntryRow(
                                 authenticationEntryInfo = it,
                                 onEntrySelected = onEntrySelected,
+                                enforceOneLine = true,
                             )
                         }
                     } else {
@@ -208,6 +212,7 @@
                             CredentialEntryRow(
                                 credentialEntryInfo = it.sortedCredentialEntryList.first(),
                                 onEntrySelected = onEntrySelected,
+                                enforceOneLine = true,
                             )
                         }
                     }
@@ -402,6 +407,7 @@
 fun CredentialEntryRow(
     credentialEntryInfo: CredentialEntryInfo,
     onEntrySelected: (BaseEntry) -> Unit,
+    enforceOneLine: Boolean = false,
 ) {
     Entry(
         onClick = { onEntrySelected(credentialEntryInfo) },
@@ -424,6 +430,7 @@
                     ) +
                     credentialEntryInfo.displayName
         },
+        enforceOneLine = enforceOneLine,
     )
 }
 
@@ -431,6 +438,7 @@
 fun AuthenticationEntryRow(
     authenticationEntryInfo: AuthenticationEntryInfo,
     onEntrySelected: (BaseEntry) -> Unit,
+    enforceOneLine: Boolean = false,
 ) {
     Entry(
         onClick = { onEntrySelected(authenticationEntryInfo) },
@@ -442,6 +450,7 @@
             else R.string.locked_credential_entry_label_subtext_tap_to_unlock
         ),
         isLockedAuthEntry = !authenticationEntryInfo.isUnlockedAndEmpty,
+        enforceOneLine = enforceOneLine,
     )
 }