Add RTT icon to RTT call log.

This is for old call log UI.
This change also improves scaling for vector drawable icons.

Bug: 67596257
Test: manual
PiperOrigin-RevId: 192359601
Change-Id: I3322fe08b668f01c1e3a7ce3264c2988e2703aae
diff --git a/java/com/android/dialer/app/calllog/PhoneCallDetailsHelper.java b/java/com/android/dialer/app/calllog/PhoneCallDetailsHelper.java
index bca4265..230c023 100644
--- a/java/com/android/dialer/app/calllog/PhoneCallDetailsHelper.java
+++ b/java/com/android/dialer/app/calllog/PhoneCallDetailsHelper.java
@@ -25,6 +25,7 @@
 import android.provider.CallLog.Calls;
 import android.provider.ContactsContract.CommonDataKinds.Phone;
 import android.support.v4.content.ContextCompat;
+import android.support.v4.os.BuildCompat;
 import android.telecom.PhoneAccount;
 import android.telecom.PhoneAccountHandle;
 import android.telephony.PhoneNumberUtils;
@@ -161,6 +162,9 @@
     views.callTypeIcons.setShowAssistedDialed(
         (details.features & TelephonyManagerCompat.FEATURES_ASSISTED_DIALING)
             == TelephonyManagerCompat.FEATURES_ASSISTED_DIALING);
+    if (BuildCompat.isAtLeastP()) {
+      views.callTypeIcons.setShowRtt((details.features & Calls.FEATURES_RTT) == Calls.FEATURES_RTT);
+    }
     views.callTypeIcons.requestLayout();
     views.callTypeIcons.setVisibility(View.VISIBLE);
 
diff --git a/java/com/android/dialer/calldetails/CallDetailsEntryViewHolder.java b/java/com/android/dialer/calldetails/CallDetailsEntryViewHolder.java
index f50876d..edf25df 100644
--- a/java/com/android/dialer/calldetails/CallDetailsEntryViewHolder.java
+++ b/java/com/android/dialer/calldetails/CallDetailsEntryViewHolder.java
@@ -22,6 +22,7 @@
 import android.support.annotation.ColorInt;
 import android.support.annotation.NonNull;
 import android.support.v4.content.ContextCompat;
+import android.support.v4.os.BuildCompat;
 import android.support.v7.widget.RecyclerView.ViewHolder;
 import android.text.TextUtils;
 import android.view.View;
@@ -102,6 +103,9 @@
         (entry.getFeatures() & Calls.FEATURES_HD_CALL) == Calls.FEATURES_HD_CALL);
     callTypeIcon.setShowWifi(
         MotorolaUtils.shouldShowWifiIconInCallLog(context, entry.getFeatures()));
+    if (BuildCompat.isAtLeastP()) {
+      callTypeIcon.setShowRtt((entry.getFeatures() & Calls.FEATURES_RTT) == Calls.FEATURES_RTT);
+    }
 
     callTypeText.setText(
         callTypeHelper.getCallTypeText(callType, isVideoCall, isPulledCall, isDuoCall));
diff --git a/java/com/android/dialer/calllogutils/CallTypeIconsView.java b/java/com/android/dialer/calllogutils/CallTypeIconsView.java
index 1795438..b4cfe81 100644
--- a/java/com/android/dialer/calllogutils/CallTypeIconsView.java
+++ b/java/com/android/dialer/calllogutils/CallTypeIconsView.java
@@ -49,6 +49,7 @@
   private boolean showHd;
   private boolean showWifi;
   private boolean showAssistedDialed;
+  private boolean showRtt;
   private int width;
   private int height;
 
@@ -145,6 +146,15 @@
     }
   }
 
+  public void setShowRtt(boolean showRtt) {
+    this.showRtt = showRtt;
+    if (showRtt) {
+      width += resources.rttCall.getIntrinsicWidth() + resources.iconMargin;
+      height = Math.max(height, resources.rttCall.getIntrinsicHeight());
+      invalidate();
+    }
+  }
+
   public int getCount() {
     return callTypes.size();
   }
@@ -188,7 +198,7 @@
     // If we are using large icons, we should only show one icon (video, hd or call type) with
     // priority give to HD or Video. So we skip the call type icon if we plan to show them.
 
-    if (!useLargeIcons || !(showHd || showVideo || showWifi || showAssistedDialed)) {
+    if (!useLargeIcons || !(showHd || showVideo || showWifi || showAssistedDialed || showRtt)) {
       for (Integer callType : callTypes) {
         final Drawable drawable = getCallTypeDrawable(callType);
         final int right = left + drawable.getIntrinsicWidth();
@@ -214,6 +224,10 @@
     if (showAssistedDialed) {
       left = addDrawable(canvas, resources.assistedDialedCall, left) + resources.iconMargin;
     }
+    // If showing RTT call icon, draw it scaled appropriately.
+    if (showRtt) {
+      left = addDrawable(canvas, resources.rttCall, left) + resources.iconMargin;
+    }
   }
 
   private int addDrawable(Canvas canvas, Drawable drawable, int left) {
@@ -252,6 +266,9 @@
     // Drawable representing an assisted dialed call.
     final Drawable assistedDialedCall;
 
+    // Drawable representing a RTT call.
+    final Drawable rttCall;
+
     /** The margin to use for icons. */
     final int iconMargin;
 
@@ -317,6 +334,11 @@
       assistedDialedCall.setColorFilter(
           r.getColor(R.color.icon_color_grey), PorterDuff.Mode.MULTIPLY);
 
+      iconId = R.drawable.quantum_ic_rtt_vd_theme_24;
+      drawable = largeIcons ? r.getDrawable(iconId) : getScaledBitmap(context, iconId);
+      rttCall = drawable.mutate();
+      rttCall.setColorFilter(r.getColor(R.color.icon_color_grey), PorterDuff.Mode.MULTIPLY);
+
       iconMargin = largeIcons ? 0 : r.getDimensionPixelSize(R.dimen.call_log_icon_margin);
     }
 
@@ -324,18 +346,19 @@
     // icons to be the same height, while preserving their width aspect ratio.
     private Drawable getScaledBitmap(Context context, int resourceId) {
       Drawable drawable = context.getDrawable(resourceId);
-      Bitmap icon =
-          Bitmap.createBitmap(
-              drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
+
+      int scaledHeight = context.getResources().getDimensionPixelSize(R.dimen.call_type_icon_size);
+      int scaledWidth =
+          (int)
+              ((float) drawable.getIntrinsicWidth()
+                  * ((float) scaledHeight / (float) drawable.getIntrinsicHeight()));
+
+      Bitmap icon = Bitmap.createBitmap(scaledWidth, scaledHeight, Bitmap.Config.ARGB_8888);
       Canvas canvas = new Canvas(icon);
       drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
       drawable.draw(canvas);
 
-      int scaledHeight = context.getResources().getDimensionPixelSize(R.dimen.call_type_icon_size);
-      int scaledWidth =
-          (int) ((float) icon.getWidth() * ((float) scaledHeight / (float) icon.getHeight()));
-      Bitmap scaledIcon = Bitmap.createScaledBitmap(icon, scaledWidth, scaledHeight, false);
-      return new BitmapDrawable(context.getResources(), scaledIcon);
+      return new BitmapDrawable(context.getResources(), icon);
     }
   }
 }