Improve ContactPhotoView

Bug: 70989658
Test: NewCallLogIntegrationTest + Manual
PiperOrigin-RevId: 196845473
Change-Id: Ic0cbcf668ea1921c88fb6b080308884fa1113e61
diff --git a/java/com/android/dialer/calllog/ui/res/layout/new_call_log_entry.xml b/java/com/android/dialer/calllog/ui/res/layout/new_call_log_entry.xml
index ad65899..7bd7f4f 100644
--- a/java/com/android/dialer/calllog/ui/res/layout/new_call_log_entry.xml
+++ b/java/com/android/dialer/calllog/ui/res/layout/new_call_log_entry.xml
@@ -26,14 +26,14 @@
       android:id="@+id/contact_photo_view"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
-      android:layout_marginStart="10dp"
-      android:layout_marginEnd="10dp"
+      android:layout_marginStart="8dp"
+      android:layout_marginEnd="8dp"
       android:layout_centerVertical="true"/>
 
   <LinearLayout
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
-      android:layout_marginTop="14dp"
+      android:layout_centerVertical="true"
       android:layout_toEndOf="@+id/contact_photo_view"
       android:layout_toStartOf="@+id/menu_button"
       android:orientation="vertical">
diff --git a/java/com/android/dialer/historyitemactions/res/layout/contact_layout.xml b/java/com/android/dialer/historyitemactions/res/layout/contact_layout.xml
index 0790cf4..89cb914 100644
--- a/java/com/android/dialer/historyitemactions/res/layout/contact_layout.xml
+++ b/java/com/android/dialer/historyitemactions/res/layout/contact_layout.xml
@@ -20,8 +20,8 @@
     android:layout_height="match_parent"
     android:paddingTop="12dp"
     android:paddingBottom="12dp"
-    android:paddingStart="10dp"
-    android:paddingEnd="10dp"
+    android:paddingStart="8dp"
+    android:paddingEnd="8dp"
     android:gravity="center_vertical"
     android:orientation="horizontal"
     android:background="#FFFFFF">
@@ -30,8 +30,7 @@
       android:id="@+id/contact_photo_view"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
-      android:layout_marginEnd="10dp"
-      android:minHeight="@dimen/contact_actions_image_size"/>
+      android:layout_marginEnd="8dp"/>
 
   <LinearLayout
       android:layout_width="wrap_content"
diff --git a/java/com/android/dialer/speeddial/res/layout/suggestion_row_layout.xml b/java/com/android/dialer/speeddial/res/layout/suggestion_row_layout.xml
index 8686060..f072c69 100644
--- a/java/com/android/dialer/speeddial/res/layout/suggestion_row_layout.xml
+++ b/java/com/android/dialer/speeddial/res/layout/suggestion_row_layout.xml
@@ -23,10 +23,10 @@
 
   <com.android.dialer.widget.ContactPhotoView
       android:id="@+id/avatar"
-      android:layout_width="48dp"
-      android:layout_height="48dp"
+      android:layout_width="wrap_content"
+      android:layout_height="wrap_content"
       android:layout_centerVertical="true"
-      android:layout_marginStart="16dp"/>
+      android:layout_marginStart="12dp"/>
 
   <LinearLayout
       android:orientation="vertical"
@@ -35,7 +35,7 @@
       android:layout_centerVertical="true"
       android:layout_toEndOf="@+id/avatar"
       android:layout_toStartOf="@+id/overflow"
-      android:layout_marginStart="8dp">
+      android:layout_marginStart="4dp">
 
     <TextView
         android:id="@+id/name"
diff --git a/java/com/android/dialer/widget/ContactPhotoView.java b/java/com/android/dialer/widget/ContactPhotoView.java
index a84111f..c0c9be7 100644
--- a/java/com/android/dialer/widget/ContactPhotoView.java
+++ b/java/com/android/dialer/widget/ContactPhotoView.java
@@ -21,6 +21,7 @@
 import android.util.AttributeSet;
 import android.view.LayoutInflater;
 import android.view.View;
+import android.view.ViewGroup;
 import android.widget.FrameLayout;
 import android.widget.ImageView;
 import android.widget.QuickContactBadge;
@@ -69,6 +70,21 @@
     hideBadge(); // Hide badges by default.
   }
 
+  @Override
+  protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
+    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
+
+    // We require both the height and the width to be WRAP_CONTENT to prevent users of
+    // this widget from clipping the view (by setting a size that is too small) or altering the
+    // relative position of the contact photo and its badge (by setting a size that is too large).
+    ViewGroup.LayoutParams layoutParams = Assert.isNotNull(getLayoutParams());
+    Assert.checkState(
+        layoutParams.height == LayoutParams.WRAP_CONTENT,
+        "The layout height must be WRAP_CONTENT!");
+    Assert.checkState(
+        layoutParams.width == LayoutParams.WRAP_CONTENT, "The layout width must be WRAP_CONTENT!");
+  }
+
   private void inflateLayout() {
     LayoutInflater inflater = Assert.isNotNull(getContext().getSystemService(LayoutInflater.class));
     inflater.inflate(R.layout.contact_photo_view, /* root = */ this);
diff --git a/java/com/android/dialer/widget/res/layout/contact_photo_view.xml b/java/com/android/dialer/widget/res/layout/contact_photo_view.xml
index a825ce3..0a8b80e 100644
--- a/java/com/android/dialer/widget/res/layout/contact_photo_view.xml
+++ b/java/com/android/dialer/widget/res/layout/contact_photo_view.xml
@@ -17,36 +17,53 @@
 <!-- A FrameLayout for displaying a contact photo and its optional badge -->
 <FrameLayout
     xmlns:android="http://schemas.android.com/apk/res/android"
-    android:layout_width="52dp"
-    android:layout_height="44dp"
+    xmlns:tools="http://schemas.android.com/tools"
+    android:layout_width="56dp"
+    android:layout_height="48dp"
     android:layout_gravity="center"
     android:focusable="false">
 
   <QuickContactBadge
       android:id="@+id/quick_contact_photo"
-      android:layout_width="40dp"
-      android:layout_height="40dp"
+      android:layout_width="48dp"
+      android:layout_height="48dp"
       android:layout_gravity="center"
+      android:padding="4dp"
       android:focusable="true"/>
 
+  <!--
+      A container layout that contains a background and badges
+      (video call badge, RTT call badge, etc)
+
+      The container and its children are too small to meet the accessibility requirement that the
+      touchable area of focusable items should be at least 48dp x 48dp. We have to set all of them
+      to be not focusable.
+  -->
   <FrameLayout
       android:id="@+id/contact_badge_container"
       android:layout_width="22dp"
       android:layout_height="22dp"
-      android:layout_gravity="bottom|end">
+      android:layout_gravity="bottom|end"
+      android:layout_marginEnd="2dp"
+      android:layout_marginBottom="2dp"
+      android:focusable="false">
 
     <ImageView
         android:id="@+id/contact_badge_background"
         android:layout_width="match_parent"
         android:layout_height="match_parent"
-        android:src="@drawable/contact_photo_badge_background"/>
+        android:src="@drawable/contact_photo_badge_background"
+        android:focusable="false"
+        tools:ignore="ContentDescription"/>
 
     <ImageView
         android:id="@+id/video_call_badge"
         android:layout_width="13dp"
         android:layout_height="13dp"
         android:layout_gravity="center"
-        android:src="@drawable/quantum_ic_videocam_vd_white_24"/>
+        android:src="@drawable/quantum_ic_videocam_vd_white_24"
+        android:focusable="false"
+        tools:ignore="ContentDescription"/>
 
     <ImageView
         android:id="@+id/rtt_call_badge"
@@ -54,6 +71,8 @@
         android:layout_height="13dp"
         android:layout_gravity="center"
         android:tint="@android:color/white"
-        android:src="@drawable/quantum_ic_rtt_vd_theme_24"/>
+        android:src="@drawable/quantum_ic_rtt_vd_theme_24"
+        android:focusable="false"
+        tools:ignore="ContentDescription"/>
   </FrameLayout>
 </FrameLayout>
\ No newline at end of file