Build out the bottom sheet for suggested contacts in Speed Dial.

The bottom sheet should include:
 - contact row
 - voice call
 - video call
 - sms
 - divider
 - add favorite (follow up)
 - remove (follow up)
 - contact info

Bug: 77761183
Test: WIP
PiperOrigin-RevId: 194440839
Change-Id: I78e0e0fc0a4834338a59b458fe7639786de57877
diff --git a/java/com/android/dialer/callintent/CallIntentBuilder.java b/java/com/android/dialer/callintent/CallIntentBuilder.java
index 0f9f890..92efd39 100644
--- a/java/com/android/dialer/callintent/CallIntentBuilder.java
+++ b/java/com/android/dialer/callintent/CallIntentBuilder.java
@@ -152,6 +152,7 @@
     return isVideoCall;
   }
 
+  /** Default false. Should only be set to true if the number has a lookup URI. */
   public CallIntentBuilder setAllowAssistedDial(boolean allowAssistedDial) {
     this.allowAssistedDial = allowAssistedDial;
     return this;
diff --git a/java/com/android/dialer/historyitemactions/HistoryItemActionBottomSheet.java b/java/com/android/dialer/historyitemactions/HistoryItemActionBottomSheet.java
index 79205a7..28663c1 100644
--- a/java/com/android/dialer/historyitemactions/HistoryItemActionBottomSheet.java
+++ b/java/com/android/dialer/historyitemactions/HistoryItemActionBottomSheet.java
@@ -17,8 +17,10 @@
 package com.android.dialer.historyitemactions;
 
 import android.content.Context;
+import android.content.res.ColorStateList;
 import android.os.Bundle;
 import android.support.design.widget.BottomSheetDialog;
+import android.support.v4.content.ContextCompat;
 import android.text.TextUtils;
 import android.view.LayoutInflater;
 import android.view.View;
@@ -109,6 +111,12 @@
     ((TextView) moduleView.findViewById(R.id.module_text)).setText(module.getStringId());
     ((ImageView) moduleView.findViewById(R.id.module_image))
         .setImageResource(module.getDrawableId());
+    if (module.tintDrawable()) {
+      ((ImageView) moduleView.findViewById(R.id.module_image))
+          .setImageTintList(
+              ColorStateList.valueOf(
+                  ContextCompat.getColor(getContext(), R.color.secondary_text_color)));
+    }
     moduleView.setOnClickListener(this);
     moduleView.setTag(module);
     return moduleView;
diff --git a/java/com/android/dialer/historyitemactions/HistoryItemActionModule.java b/java/com/android/dialer/historyitemactions/HistoryItemActionModule.java
index d64cbca..e948924 100644
--- a/java/com/android/dialer/historyitemactions/HistoryItemActionModule.java
+++ b/java/com/android/dialer/historyitemactions/HistoryItemActionModule.java
@@ -32,6 +32,11 @@
   @DrawableRes
   int getDrawableId();
 
+  /** Returns true if tint can be applied to the drawable. */
+  default boolean tintDrawable() {
+    return true;
+  }
+
   /** @return true if the bottom sheet should close, false otherwise */
   boolean onClick();
 }
diff --git a/java/com/android/dialer/historyitemactions/res/layout/module_layout.xml b/java/com/android/dialer/historyitemactions/res/layout/module_layout.xml
index 9aee679..0630519 100644
--- a/java/com/android/dialer/historyitemactions/res/layout/module_layout.xml
+++ b/java/com/android/dialer/historyitemactions/res/layout/module_layout.xml
@@ -28,7 +28,6 @@
       android:layout_height="@dimen/contact_actions_image_size"
       android:layout_marginStart="@dimen/contact_actions_image_margin"
       android:layout_marginEnd="@dimen/contact_actions_image_margin"
-      android:tint="@color/dialer_secondary_text_color"
       android:scaleType="center"/>
 
   <TextView
diff --git a/java/com/android/dialer/speeddial/SpeedDialFragment.java b/java/com/android/dialer/speeddial/SpeedDialFragment.java
index b76db1c..018f978 100644
--- a/java/com/android/dialer/speeddial/SpeedDialFragment.java
+++ b/java/com/android/dialer/speeddial/SpeedDialFragment.java
@@ -16,6 +16,7 @@
 
 package com.android.dialer.speeddial;
 
+import android.content.Context;
 import android.content.Intent;
 import android.net.Uri;
 import android.os.Bundle;
@@ -41,6 +42,12 @@
 import com.android.dialer.common.concurrent.SupportUiListener;
 import com.android.dialer.constants.ActivityRequestCodes;
 import com.android.dialer.duo.DuoComponent;
+import com.android.dialer.historyitemactions.DividerModule;
+import com.android.dialer.historyitemactions.HistoryItemActionBottomSheet;
+import com.android.dialer.historyitemactions.HistoryItemActionModule;
+import com.android.dialer.historyitemactions.HistoryItemBottomSheetHeaderInfo;
+import com.android.dialer.historyitemactions.IntentModule;
+import com.android.dialer.historyitemactions.SharedModules;
 import com.android.dialer.logging.DialerImpression;
 import com.android.dialer.logging.Logger;
 import com.android.dialer.precall.PreCall;
@@ -54,8 +61,11 @@
 import com.android.dialer.speeddial.loader.SpeedDialUiItem;
 import com.android.dialer.speeddial.loader.UiItemLoaderComponent;
 import com.android.dialer.util.IntentUtil;
+import com.google.common.base.Optional;
 import com.google.common.collect.ImmutableList;
 import com.google.common.util.concurrent.Futures;
+import java.util.ArrayList;
+import java.util.List;
 
 /**
  * Fragment for displaying:
@@ -301,8 +311,61 @@
   private final class SpeedDialSuggestedListener implements SuggestedContactsListener {
 
     @Override
-    public void onOverFlowMenuClicked(SpeedDialUiItem speedDialUiItem) {
-      // TODO(calderwoodra) show overflow menu for suggested contacts
+    public void onOverFlowMenuClicked(
+        SpeedDialUiItem speedDialUiItem, HistoryItemBottomSheetHeaderInfo headerInfo) {
+      List<HistoryItemActionModule> modules = new ArrayList<>();
+      Channel defaultChannel = speedDialUiItem.defaultChannel();
+
+      // Add voice call module
+      Channel voiceChannel = speedDialUiItem.getDeterministicVoiceChannel();
+      if (voiceChannel != null) {
+        modules.add(
+            IntentModule.newCallModule(
+                getContext(),
+                new CallIntentBuilder(voiceChannel.number(), CallInitiationType.Type.SPEED_DIAL)
+                    .setAllowAssistedDial(true)));
+      } else {
+        modules.add(new DisambigDialogModule(speedDialUiItem, /* isVideo = */ false));
+      }
+
+      // Add video if we can determine the correct channel
+      Channel videoChannel = speedDialUiItem.getDeterministicVideoChannel();
+      if (videoChannel != null) {
+        modules.add(
+            IntentModule.newCallModule(
+                getContext(),
+                new CallIntentBuilder(videoChannel.number(), CallInitiationType.Type.SPEED_DIAL)
+                    .setIsVideoCall(true)
+                    .setAllowAssistedDial(true)));
+      } else if (speedDialUiItem.hasVideoChannels()) {
+        modules.add(new DisambigDialogModule(speedDialUiItem, /* isVideo = */ true));
+      }
+
+      // Add sms module
+      Optional<HistoryItemActionModule> smsModule =
+          SharedModules.createModuleForSendingTextMessage(
+              getContext(), defaultChannel.number(), false);
+      if (smsModule.isPresent()) {
+        modules.add(smsModule.get());
+      }
+
+      modules.add(new DividerModule());
+
+      // TODO(calderwoodra): add to favorites module
+      // TODO(calderwoodra): remove from strequent module
+
+      // Contact info module
+      modules.add(
+          new ContactInfoModule(
+              getContext(),
+              new Intent(
+                  Intent.ACTION_VIEW,
+                  Uri.withAppendedPath(
+                      Contacts.CONTENT_URI, String.valueOf(speedDialUiItem.contactId()))),
+              R.string.contact_menu_contact_info,
+              R.drawable.context_menu_contact_icon));
+
+      HistoryItemActionBottomSheet.show(getContext(), headerInfo, modules);
     }
 
     @Override
@@ -321,6 +384,53 @@
           new CallIntentBuilder(channel.number(), CallInitiationType.Type.SPEED_DIAL)
               .setIsVideoCall(channel.isVideoTechnology()));
     }
+
+    private final class ContactInfoModule extends IntentModule {
+
+      public ContactInfoModule(Context context, Intent intent, int text, int image) {
+        super(context, intent, text, image);
+      }
+
+      @Override
+      public boolean tintDrawable() {
+        return false;
+      }
+    }
+
+    private final class DisambigDialogModule implements HistoryItemActionModule {
+
+      private final SpeedDialUiItem speedDialUiItem;
+      private final boolean isVideo;
+
+      DisambigDialogModule(SpeedDialUiItem speedDialUiItem, boolean isVideo) {
+        this.speedDialUiItem = speedDialUiItem;
+        this.isVideo = isVideo;
+      }
+
+      @Override
+      public int getStringId() {
+        if (isVideo) {
+          return R.string.contact_menu_video_call;
+        } else {
+          return R.string.contact_menu_voice_call;
+        }
+      }
+
+      @Override
+      public int getDrawableId() {
+        if (isVideo) {
+          return R.drawable.quantum_ic_videocam_vd_theme_24;
+        } else {
+          return R.drawable.quantum_ic_phone_vd_theme_24;
+        }
+      }
+
+      @Override
+      public boolean onClick() {
+        DisambigDialog.show(speedDialUiItem, getChildFragmentManager());
+        return true;
+      }
+    }
   }
 
   private static final class SpeedDialContextMenuItemListener implements ContextMenuItemListener {
diff --git a/java/com/android/dialer/speeddial/SuggestionViewHolder.java b/java/com/android/dialer/speeddial/SuggestionViewHolder.java
index 546ffbd..578e0b3 100644
--- a/java/com/android/dialer/speeddial/SuggestionViewHolder.java
+++ b/java/com/android/dialer/speeddial/SuggestionViewHolder.java
@@ -17,27 +17,25 @@
 package com.android.dialer.speeddial;
 
 import android.content.Context;
-import android.provider.ContactsContract.Contacts;
 import android.support.v7.widget.RecyclerView;
 import android.text.TextUtils;
 import android.view.View;
 import android.view.View.OnClickListener;
-import android.widget.QuickContactBadge;
 import android.widget.TextView;
 import com.android.dialer.common.Assert;
-import com.android.dialer.glidephotomanager.GlidePhotoManagerComponent;
-import com.android.dialer.glidephotomanager.PhotoInfo;
+import com.android.dialer.historyitemactions.HistoryItemBottomSheetHeaderInfo;
 import com.android.dialer.location.GeoUtil;
 import com.android.dialer.phonenumberutil.PhoneNumberHelper;
 import com.android.dialer.speeddial.database.SpeedDialEntry.Channel;
 import com.android.dialer.speeddial.loader.SpeedDialUiItem;
+import com.android.dialer.widget.ContactPhotoView;
 
 /** ViewHolder for displaying suggested contacts in {@link SpeedDialFragment}. */
 public class SuggestionViewHolder extends RecyclerView.ViewHolder implements OnClickListener {
 
   private final SuggestedContactsListener listener;
 
-  private final QuickContactBadge photoView;
+  private final ContactPhotoView photoView;
   private final TextView nameOrNumberView;
   private final TextView numberView;
 
@@ -71,34 +69,31 @@
     nameOrNumberView.setText(speedDialUiItem.name());
     numberView.setText(secondaryInfo);
 
-    GlidePhotoManagerComponent.get(context)
-        .glidePhotoManager()
-        .loadQuickContactBadge(
-            photoView,
-            PhotoInfo.newBuilder()
-                .setPhotoId(speedDialUiItem.photoId())
-                .setPhotoUri(speedDialUiItem.photoUri())
-                .setName(speedDialUiItem.name())
-                .setIsVideo(speedDialUiItem.defaultChannel().isVideoTechnology())
-                .setLookupUri(
-                    Contacts.getLookupUri(speedDialUiItem.contactId(), speedDialUiItem.lookupKey())
-                        .toString())
-                .build());
+    photoView.setPhoto(speedDialUiItem.getPhotoInfo());
   }
 
   @Override
   public void onClick(View v) {
     if (v.getId() == R.id.overflow) {
-      listener.onOverFlowMenuClicked(speedDialUiItem);
+      listener.onOverFlowMenuClicked(speedDialUiItem, getHeaderInfo());
     } else {
       listener.onRowClicked(speedDialUiItem.defaultChannel());
     }
   }
 
+  private HistoryItemBottomSheetHeaderInfo getHeaderInfo() {
+    return HistoryItemBottomSheetHeaderInfo.newBuilder()
+        .setPhotoInfo(speedDialUiItem.getPhotoInfo())
+        .setPrimaryText(nameOrNumberView.getText().toString())
+        .setSecondaryText(numberView.getText().toString())
+        .build();
+  }
+
   /** Listener/Callback for {@link SuggestionViewHolder} parents. */
   public interface SuggestedContactsListener {
 
-    void onOverFlowMenuClicked(SpeedDialUiItem speedDialUiItem);
+    void onOverFlowMenuClicked(
+        SpeedDialUiItem speedDialUiItem, HistoryItemBottomSheetHeaderInfo headerInfo);
 
     /** Called when a suggested contact is clicked. */
     void onRowClicked(Channel channel);
diff --git a/java/com/android/dialer/speeddial/loader/SpeedDialUiItem.java b/java/com/android/dialer/speeddial/loader/SpeedDialUiItem.java
index a2bdfb8..c5a3ea3 100644
--- a/java/com/android/dialer/speeddial/loader/SpeedDialUiItem.java
+++ b/java/com/android/dialer/speeddial/loader/SpeedDialUiItem.java
@@ -18,10 +18,12 @@
 
 import android.database.Cursor;
 import android.provider.ContactsContract.CommonDataKinds.Phone;
+import android.provider.ContactsContract.Contacts;
 import android.provider.ContactsContract.Data;
 import android.support.annotation.Nullable;
 import android.text.TextUtils;
 import com.android.dialer.common.Assert;
+import com.android.dialer.glidephotomanager.PhotoInfo;
 import com.android.dialer.speeddial.database.SpeedDialEntry;
 import com.android.dialer.speeddial.database.SpeedDialEntry.Channel;
 import com.google.auto.value.AutoValue;
@@ -139,6 +141,16 @@
     return builder.build();
   }
 
+  public PhotoInfo getPhotoInfo() {
+    return PhotoInfo.newBuilder()
+        .setPhotoId(photoId())
+        .setPhotoUri(photoUri())
+        .setName(name())
+        .setIsVideo(defaultChannel() != null && defaultChannel().isVideoTechnology())
+        .setLookupUri(Contacts.getLookupUri(contactId(), lookupKey()).toString())
+        .build();
+  }
+
   public SpeedDialEntry buildSpeedDialEntry() {
     return SpeedDialEntry.builder()
         .setId(speedDialEntryId())
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 ff95b59..8686060 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
@@ -21,7 +21,7 @@
     android:minHeight="72dp"
     android:background="?android:attr/selectableItemBackground">
 
-  <QuickContactBadge
+  <com.android.dialer.widget.ContactPhotoView
       android:id="@+id/avatar"
       android:layout_width="48dp"
       android:layout_height="48dp"
@@ -59,5 +59,6 @@
       android:scaleType="center"
       android:tint="@color/secondary_text_color"
       android:src="@drawable/quantum_ic_more_vert_white_24"
-      android:background="?android:selectableItemBackgroundBorderless"/>
+      android:background="?android:selectableItemBackgroundBorderless"
+      android:contentDescription="@string/content_description_overflow"/>
 </RelativeLayout>
\ No newline at end of file