Credman - Remove divider from dropdown presentation

Bug: 319126175
Change-Id: I1768302f547388b1b1025a4f98af1ff867d6c5e7
diff --git a/packages/CredentialManager/res/drawable/fill_dialog_dynamic_list_item_one_dark.xml b/packages/CredentialManager/res/drawable/fill_dialog_dynamic_list_item_middle.xml
similarity index 60%
rename from packages/CredentialManager/res/drawable/fill_dialog_dynamic_list_item_one_dark.xml
rename to packages/CredentialManager/res/drawable/fill_dialog_dynamic_list_item_middle.xml
index 39f49ca..781373d 100644
--- a/packages/CredentialManager/res/drawable/fill_dialog_dynamic_list_item_one_dark.xml
+++ b/packages/CredentialManager/res/drawable/fill_dialog_dynamic_list_item_middle.xml
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="utf-8"?>
 <!--
-  ~ Copyright (C) 2023 The Android Open Source Project
+  ~ Copyright (C) 2024 The Android Open Source Project
   ~
   ~ Licensed under the Apache License, Version 2.0 (the "License");
   ~ you may not use this file except in compliance with the License.
@@ -15,16 +15,10 @@
   ~ limitations under the License.
   -->
 
-<ripple xmlns:android="http://schemas.android.com/apk/res/android"
-        xmlns:tools="http://schemas.android.com/tools" tools:ignore="NewApi"
-        android:color="@android:color/transparent">
-    <item
-        android:bottom="1dp"
-        android:shape="rectangle"
-        android:top="1dp">
-        <shape>
-            <corners android:radius="28dp" />
-            <solid android:color="@android:color/system_surface_container_high_dark" />
+<inset xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:androidprv="http://schemas.android.com/apk/prv/res/android"
+        xmlns:tools="http://schemas.android.com/tools" tools:ignore="NewApi">
+        <shape android:shape="rectangle">
+            <solid android:color="?androidprv:attr/materialColorSurfaceContainer" />
         </shape>
-    </item>
-</ripple>
\ No newline at end of file
+</inset>
\ No newline at end of file
diff --git a/packages/CredentialManager/res/drawable/fill_dialog_dynamic_list_item_one.xml b/packages/CredentialManager/res/drawable/fill_dialog_dynamic_list_item_one.xml
index f13402c..f28c354 100644
--- a/packages/CredentialManager/res/drawable/fill_dialog_dynamic_list_item_one.xml
+++ b/packages/CredentialManager/res/drawable/fill_dialog_dynamic_list_item_one.xml
@@ -15,16 +15,12 @@
   ~ limitations under the License.
   -->
 
-<ripple xmlns:android="http://schemas.android.com/apk/res/android"
-        xmlns:tools="http://schemas.android.com/tools" tools:ignore="NewApi"
-        android:color="@android:color/transparent">
-    <item
-        android:bottom="1dp"
-        android:shape="rectangle"
-        android:top="1dp">
-        <shape>
-            <corners android:radius="4dp" />
-            <solid android:color="@color/dropdown_container" />
+<inset xmlns:android="http://schemas.android.com/apk/res/android"
+        xmlns:androidprv="http://schemas.android.com/apk/prv/res/android"
+        xmlns:tools="http://schemas.android.com/tools" tools:ignore="NewApi">
+        <shape android:shape="rectangle">
+            <corners android:topLeftRadius="4dp" android:topRightRadius="4dp"
+            android:bottomLeftRadius="0dp" android:bottomRightRadius="0dp"/>
+            <solid android:color="?androidprv:attr/materialColorSurfaceContainer" />
         </shape>
-    </item>
-</ripple>
\ No newline at end of file
+</inset>
\ No newline at end of file
diff --git a/packages/CredentialManager/res/drawable/more_options_list_item.xml b/packages/CredentialManager/res/drawable/more_options_list_item.xml
index d7b509e..3f9d815 100644
--- a/packages/CredentialManager/res/drawable/more_options_list_item.xml
+++ b/packages/CredentialManager/res/drawable/more_options_list_item.xml
@@ -15,17 +15,16 @@
   ~ limitations under the License.
   -->
 
-<ripple xmlns:android="http://schemas.android.com/apk/res/android"
-        xmlns:tools="http://schemas.android.com/tools" tools:ignore="NewApi"
-        android:color="@android:color/transparent">
-    <item
-        android:bottom="1dp"
-        android:shape="rectangle"
-        android:top="1dp">
-        <shape>
-            <corners android:bottomLeftRadius="4dp"
-                     android:bottomRightRadius="4dp"/>
-            <solid android:color="@color/sign_in_options_container" />
-        </shape>
-    </item>
-</ripple>
\ No newline at end of file
+<inset xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:androidprv="http://schemas.android.com/apk/prv/res/android"
+    xmlns:tools="http://schemas.android.com/tools" tools:ignore="NewApi"
+    android:insetLeft="-2dp"
+    android:insetRight="-2dp"
+    android:insetBottom="-2dp">
+    <shape>
+        <corners android:topLeftRadius="0dp" android:topRightRadius="0dp"
+            android:bottomLeftRadius="4dp" android:bottomRightRadius="4dp"/>
+        <solid android:color="?androidprv:attr/materialColorSurfaceContainer"/>
+        <stroke android:color="?androidprv:attr/materialColorOutlineVariant" android:width="1dp"/>
+    </shape>
+</inset>
\ No newline at end of file
diff --git a/packages/CredentialManager/res/layout/credman_dropdown_bottom_sheet.xml b/packages/CredentialManager/res/layout/credman_dropdown_bottom_sheet.xml
index 910ff96..7f09dd5 100644
--- a/packages/CredentialManager/res/layout/credman_dropdown_bottom_sheet.xml
+++ b/packages/CredentialManager/res/layout/credman_dropdown_bottom_sheet.xml
@@ -14,30 +14,52 @@
   ~ limitations under the License.
   -->
 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:androidprv="http://schemas.android.com/apk/prv/res/android"
                 android:id="@android:id/content"
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
                 android:minHeight="@dimen/dropdown_touch_target_min_height"
                 android:orientation="horizontal"
-                android:layout_marginEnd="@dimen/dropdown_layout_horizontal_margin"
                 android:elevation="3dp">
 
-    <ImageView
-        android:id="@android:id/icon1"
+    <LinearLayout
+        android:id="@+id/credential_card"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
-        android:layout_centerVertical="true"
-        android:layout_alignParentStart="true"
-        android:contentDescription="@string/more_options_content_description"
-        android:background="@null"/>
-    <TextView
-        android:id="@android:id/text1"
-        android:layout_width="wrap_content"
+        android:orientation="horizontal">
+
+        <ImageView
+            android:id="@android:id/icon1"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_gravity="center"
+            android:paddingLeft="@dimen/autofill_view_left_padding"
+            android:src="@drawable/more_horiz_24px"
+            android:tint="?androidprv:attr/materialColorOnSurface"
+            android:layout_alignParentStart="true"
+            android:contentDescription="@string/more_options_content_description"
+            android:background="@null"/>
+
+    <LinearLayout
+        android:id="@+id/text_container"
+        android:layout_width="@dimen/autofill_dropdown_textview_max_width"
         android:layout_height="wrap_content"
-        android:layout_alignParentTop="true"
-        android:layout_toEndOf="@android:id/icon1"
-        android:minWidth="@dimen/autofill_dropdown_textview_min_width"
-        android:maxWidth="@dimen/autofill_dropdown_textview_max_width"
-        style="@style/autofill.TextTitle"/>
+        android:paddingLeft="@dimen/autofill_view_left_padding"
+        android:paddingRight="@dimen/autofill_view_right_padding"
+        android:paddingTop="@dimen/more_options_item_vertical_padding"
+        android:paddingBottom="@dimen/more_options_item_vertical_padding"
+        android:orientation="vertical">
+
+        <TextView
+            android:id="@android:id/text1"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_alignParentTop="true"
+            android:textColor="?androidprv:attr/materialColorOnSurface"
+            android:layout_toEndOf="@android:id/icon1"
+            style="@style/autofill.TextTitle"/>
+    </LinearLayout>
+
+    </LinearLayout>
 
 </RelativeLayout>
diff --git a/packages/CredentialManager/res/layout/credman_dropdown_presentation_layout.xml b/packages/CredentialManager/res/layout/credman_dropdown_presentation_layout.xml
index 4bf0e99..08948d7 100644
--- a/packages/CredentialManager/res/layout/credman_dropdown_presentation_layout.xml
+++ b/packages/CredentialManager/res/layout/credman_dropdown_presentation_layout.xml
@@ -14,37 +14,60 @@
   ~ limitations under the License.
   -->
 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:androidprv="http://schemas.android.com/apk/prv/res/android"
+    xmlns:app="http://schemas.android.com/apk/res-auto"
                 android:id="@android:id/content"
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
                 android:minHeight="@dimen/dropdown_touch_target_min_height"
-                android:layout_marginEnd="@dimen/dropdown_layout_horizontal_margin"
                 android:elevation="3dp">
 
-        <ImageView
-            android:id="@android:id/icon1"
+        <LinearLayout
+            android:id="@+id/credential_card"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
-            android:layout_centerVertical="true"
-            android:layout_alignParentStart="true"
-            android:background="@null"/>
-        <TextView
-            android:id="@android:id/text1"
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
-            android:layout_alignParentTop="true"
-            android:layout_toEndOf="@android:id/icon1"
-            android:minWidth="@dimen/autofill_dropdown_textview_min_width"
-            android:maxWidth="@dimen/autofill_dropdown_textview_max_width"
-            style="@style/autofill.TextTitle"/>
-        <TextView
-            android:id="@android:id/text2"
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
-            android:layout_below="@android:id/text1"
-            android:layout_toEndOf="@android:id/icon1"
-            android:minWidth="@dimen/autofill_dropdown_textview_min_width"
-            android:maxWidth="@dimen/autofill_dropdown_textview_max_width"
-            style="@style/autofill.TextSubtitle"/>
+            android:orientation="horizontal">
+
+                <ImageView
+                    android:id="@android:id/icon1"
+                    android:layout_width="wrap_content"
+                    android:layout_height="wrap_content"
+                    android:layout_gravity="center"
+                    android:layout_alignParentStart="true"
+                    android:paddingLeft="@dimen/autofill_view_left_padding"
+                    app:tint="?androidprv:attr/materialColorOnSurface"
+                    android:background="@null"/>
+
+                <LinearLayout
+                    android:id="@+id/text_container"
+                    android:layout_width="@dimen/autofill_dropdown_textview_max_width"
+                    android:layout_height="wrap_content"
+                    android:paddingLeft="@dimen/autofill_view_left_padding"
+                    android:paddingRight="@dimen/autofill_view_right_padding"
+                    android:paddingTop="@dimen/autofill_view_top_padding"
+                    android:paddingBottom="@dimen/autofill_view_bottom_padding"
+                    android:orientation="vertical">
+
+                        <TextView
+                            android:id="@android:id/text1"
+                            android:layout_width="wrap_content"
+                            android:layout_height="wrap_content"
+                            android:layout_alignParentTop="true"
+                            android:layout_toEndOf="@android:id/icon1"
+                            android:textColor="?androidprv:attr/materialColorOnSurface"
+                            style="@style/autofill.TextTitle"/>
+
+                        <TextView
+                            android:id="@android:id/text2"
+                            android:layout_width="wrap_content"
+                            android:layout_height="wrap_content"
+                            android:layout_below="@android:id/text1"
+                            android:layout_toEndOf="@android:id/icon1"
+                            android:textColor="?androidprv:attr/materialColorOnSurfaceVariant"
+                            style="@style/autofill.TextSubtitle"/>
+
+                </LinearLayout>
+
+        </LinearLayout>
 
 </RelativeLayout>
diff --git a/packages/CredentialManager/res/values/colors.xml b/packages/CredentialManager/res/values/colors.xml
index b4d2eeb..9d31b35 100644
--- a/packages/CredentialManager/res/values/colors.xml
+++ b/packages/CredentialManager/res/values/colors.xml
@@ -15,14 +15,12 @@
   -->
 
 <!-- Color palette -->
-<resources>
-    <!-- These colors are used for Remote Views. -->
-    <color name="text_primary">#1A1B20</color>
-    <color name="text_secondary">#44474F</color>
-    <color name="dropdown_container">#F3F3FA</color>
-    <color name="sign_in_options_container">#DADADA</color>
-    <color name="sign_in_options_icon_color">#1B1B1B</color>
+<resources
+    xmlns:androidprv="http://schemas.android.com/apk/prv/res/android">
 
-    <!-- These colors are used for Inline Suggestions. -->
-    <color name="inline_background">#FFFFFF</color>
+    <!-- These colors are used for Remote Views. -->
+    <color name="onSurface">?androidprv:attr/materialColorOnSurface</color>
+    <color name="onSurfaceVariant">?androidprv:attr/materialColorOnSurfaceVariant</color>
+    <color name="surfaceDim">?androidprv:attr/materialColorSurfaceDim</color>
+    <color name="surfaceContainer">?androidprv:attr/materialColorSurfaceContainer</color>
 </resources>
\ No newline at end of file
diff --git a/packages/CredentialManager/res/values/dimens.xml b/packages/CredentialManager/res/values/dimens.xml
index 82dee5c..314437e 100644
--- a/packages/CredentialManager/res/values/dimens.xml
+++ b/packages/CredentialManager/res/values/dimens.xml
@@ -18,16 +18,18 @@
 
 <resources>
     <dimen name="autofill_view_top_padding">12dp</dimen>
-    <dimen name="autofill_view_right_padding">12dp</dimen>
+    <dimen name="autofill_view_right_padding">16dp</dimen>
     <dimen name="autofill_view_bottom_padding">12dp</dimen>
     <dimen name="autofill_view_left_padding">16dp</dimen>
-    <dimen name="autofill_view_icon_to_text_padding">10dp</dimen>
+    <dimen name="autofill_view_icon_to_text_padding">16dp</dimen>
+    <dimen name="autofill_view_end_items_padding">8dp</dimen>
+    <dimen name="more_options_item_vertical_padding">14dp</dimen>
     <dimen name="autofill_icon_size">24dp</dimen>
     <dimen name="autofill_dropdown_textview_min_width">112dp</dimen>
     <dimen name="autofill_dropdown_textview_max_width">230dp</dimen>
     <dimen name="dropdown_layout_horizontal_margin">24dp</dimen>
     <integer name="autofill_max_visible_datasets">4</integer>
-    <dimen name="dropdown_touch_target_min_height">48dp</dimen>
+    <dimen name="dropdown_touch_target_min_height">49dp</dimen>
     <dimen name="horizontal_chip_padding">8dp</dimen>
     <dimen name="vertical_chip_padding">6dp</dimen>
 </resources>
\ No newline at end of file
diff --git a/packages/CredentialManager/src/com/android/credentialmanager/autofill/CredentialAutofillService.kt b/packages/CredentialManager/src/com/android/credentialmanager/autofill/CredentialAutofillService.kt
index d7a2e36..8d71850b 100644
--- a/packages/CredentialManager/src/com/android/credentialmanager/autofill/CredentialAutofillService.kt
+++ b/packages/CredentialManager/src/com/android/credentialmanager/autofill/CredentialAutofillService.kt
@@ -295,8 +295,9 @@
             }
             var dropdownPresentation: RemoteViews? = null
             if (i < maxDatasetDisplayLimit) {
-                dropdownPresentation = RemoteViewsFactory
-                        .createDropdownPresentation(this, icon, primaryEntry)
+                dropdownPresentation = RemoteViewsFactory.createDropdownPresentation(
+                    this, icon, primaryEntry, /*isFirstEntry= */ i == 0,
+                    /*isLastEntry= */ (totalEntryCount - i == 1))
             }
 
             val dataSetBuilder = Dataset.Builder()
diff --git a/packages/CredentialManager/src/com/android/credentialmanager/common/ui/RemoteViewsFactory.kt b/packages/CredentialManager/src/com/android/credentialmanager/common/ui/RemoteViewsFactory.kt
index 7966a86..a46e358 100644
--- a/packages/CredentialManager/src/com/android/credentialmanager/common/ui/RemoteViewsFactory.kt
+++ b/packages/CredentialManager/src/com/android/credentialmanager/common/ui/RemoteViewsFactory.kt
@@ -31,12 +31,13 @@
         private const val setMaxHeightMethodName = "setMaxHeight"
         private const val setBackgroundResourceMethodName = "setBackgroundResource"
         private const val bulletPoint = "\u2022"
-        private const val passwordCharacterLength = 15
 
         fun createDropdownPresentation(
             context: Context,
             icon: Icon,
-            credentialEntryInfo: CredentialEntryInfo
+            credentialEntryInfo: CredentialEntryInfo,
+            isFirstEntry: Boolean,
+            isLastEntry: Boolean,
         ): RemoteViews {
             var layoutId: Int = com.android.credentialmanager.R.layout
                     .credman_dropdown_presentation_layout
@@ -44,7 +45,6 @@
             if (credentialEntryInfo.credentialType == CredentialType.UNKNOWN) {
                 return remoteViews
             }
-            setRemoteViewsPaddings(remoteViews, context, /* primaryTextBottomPadding=*/0)
             val displayName = credentialEntryInfo.displayName ?: credentialEntryInfo.userName
             remoteViews.setTextViewText(android.R.id.text1, displayName)
             val secondaryText =
@@ -56,12 +56,6 @@
                 else (credentialEntryInfo.credentialTypeDisplayName + " " + bulletPoint + " "
                         + credentialEntryInfo.providerDisplayName)
             remoteViews.setTextViewText(android.R.id.text2, secondaryText)
-            val textColorPrimary = ContextCompat.getColor(context,
-                com.android.credentialmanager.R.color.text_primary)
-            remoteViews.setTextColor(android.R.id.text1, textColorPrimary)
-            val textColorSecondary = ContextCompat.getColor(context, com.android
-                    .credentialmanager.R.color.text_secondary)
-            remoteViews.setTextColor(android.R.id.text2, textColorSecondary)
             remoteViews.setImageViewIcon(android.R.id.icon1, icon);
             remoteViews.setBoolean(
                 android.R.id.icon1, setAdjustViewBoundsMethodName, true);
@@ -73,9 +67,23 @@
             remoteViews.setContentDescription(android.R.id.icon1, credentialEntryInfo
                     .providerDisplayName);
             val drawableId =
-                com.android.credentialmanager.R.drawable.fill_dialog_dynamic_list_item_one
+                if (isFirstEntry)
+                    com.android.credentialmanager.R.drawable.fill_dialog_dynamic_list_item_one else
+                    com.android.credentialmanager.R.drawable.fill_dialog_dynamic_list_item_middle
             remoteViews.setInt(
                 android.R.id.content, setBackgroundResourceMethodName, drawableId);
+            if (isFirstEntry) remoteViews.setViewPadding(
+                com.android.credentialmanager.R.id.credential_card,
+                /* left=*/0,
+                /* top=*/8,
+                /* right=*/0,
+                /* bottom=*/0)
+            if (isLastEntry) remoteViews.setViewPadding(
+                com.android.credentialmanager.R.id.credential_card,
+                /*left=*/0,
+                /* top=*/0,
+                /* right=*/0,
+                /* bottom=*/8)
             return remoteViews
         }
 
@@ -83,19 +91,9 @@
             var layoutId: Int = com.android.credentialmanager.R.layout
                     .credman_dropdown_bottom_sheet
             val remoteViews = RemoteViews(context.packageName, layoutId)
-            setRemoteViewsPaddings(remoteViews, context)
             remoteViews.setTextViewText(android.R.id.text1, ContextCompat.getString(context,
                 com.android.credentialmanager
                         .R.string.dropdown_presentation_more_sign_in_options_text))
-
-            val textColorPrimary = ContextCompat.getColor(context,
-                com.android.credentialmanager.R.color.text_primary)
-            remoteViews.setTextColor(android.R.id.text1, textColorPrimary)
-            val icon = Icon.createWithResource(context, com
-                    .android.credentialmanager.R.drawable.more_horiz_24px)
-            icon.setTint(ContextCompat.getColor(context,
-                com.android.credentialmanager.R.color.sign_in_options_icon_color))
-            remoteViews.setImageViewIcon(android.R.id.icon1, icon)
             remoteViews.setBoolean(
                 android.R.id.icon1, setAdjustViewBoundsMethodName, true);
             remoteViews.setInt(
@@ -109,50 +107,5 @@
                 android.R.id.content, setBackgroundResourceMethodName, drawableId);
             return remoteViews
         }
-
-        private fun setRemoteViewsPaddings(
-            remoteViews: RemoteViews, context: Context) {
-            val bottomPadding = context.resources.getDimensionPixelSize(
-                com.android.credentialmanager.R.dimen.autofill_view_bottom_padding)
-            setRemoteViewsPaddings(remoteViews, context, bottomPadding)
-        }
-
-        private fun setRemoteViewsPaddings(
-            remoteViews: RemoteViews, context: Context, primaryTextBottomPadding: Int) {
-            val leftPadding = context.resources.getDimensionPixelSize(
-                com.android.credentialmanager.R.dimen.autofill_view_left_padding)
-            val iconToTextPadding = context.resources.getDimensionPixelSize(
-                com.android.credentialmanager.R.dimen.autofill_view_icon_to_text_padding)
-            val rightPadding = context.resources.getDimensionPixelSize(
-                com.android.credentialmanager.R.dimen.autofill_view_right_padding)
-            val topPadding = context.resources.getDimensionPixelSize(
-                com.android.credentialmanager.R.dimen.autofill_view_top_padding)
-            val bottomPadding = context.resources.getDimensionPixelSize(
-                com.android.credentialmanager.R.dimen.autofill_view_bottom_padding)
-            remoteViews.setViewPadding(
-                android.R.id.icon1,
-                leftPadding,
-                /* top=*/0,
-                /* right=*/0,
-                /* bottom=*/0)
-            remoteViews.setViewPadding(
-                android.R.id.text1,
-                iconToTextPadding,
-                /* top=*/topPadding,
-                /* right=*/rightPadding,
-                primaryTextBottomPadding)
-            remoteViews.setViewPadding(
-                android.R.id.text2,
-                iconToTextPadding,
-                /* top=*/0,
-                /* right=*/rightPadding,
-                /* bottom=*/bottomPadding)
-        }
-
-        private fun isDarkMode(context: Context): Boolean {
-            val currentNightMode = context.resources.configuration.uiMode and
-                    Configuration.UI_MODE_NIGHT_MASK
-            return currentNightMode == Configuration.UI_MODE_NIGHT_YES
-        }
     }
 }