Update Contact card UI.

1. Adds a separate entry for SMS (still up for debate)
2. Uses the proper icon resources for common contact types
3. Colorizes the icons if available

Change-Id: Ibf491e0e05d453d0d06b0ad16847e4eb34084811
diff --git a/res/drawable-hdpi/ic_email_24dp.png b/res/drawable-hdpi/ic_email_24dp.png
new file mode 100644
index 0000000..231b141
--- /dev/null
+++ b/res/drawable-hdpi/ic_email_24dp.png
Binary files differ
diff --git a/res/drawable-hdpi/ic_phone_24dp.png b/res/drawable-hdpi/ic_phone_24dp.png
new file mode 100644
index 0000000..a6a6448
--- /dev/null
+++ b/res/drawable-hdpi/ic_phone_24dp.png
Binary files differ
diff --git a/res/drawable-hdpi/ic_place_24dp.png b/res/drawable-hdpi/ic_place_24dp.png
new file mode 100644
index 0000000..8e21320
--- /dev/null
+++ b/res/drawable-hdpi/ic_place_24dp.png
Binary files differ
diff --git a/res/drawable-mdpi/ic_email_24dp.png b/res/drawable-mdpi/ic_email_24dp.png
new file mode 100644
index 0000000..c32d03a
--- /dev/null
+++ b/res/drawable-mdpi/ic_email_24dp.png
Binary files differ
diff --git a/res/drawable-mdpi/ic_phone_24dp.png b/res/drawable-mdpi/ic_phone_24dp.png
new file mode 100644
index 0000000..2286bb4
--- /dev/null
+++ b/res/drawable-mdpi/ic_phone_24dp.png
Binary files differ
diff --git a/res/drawable-mdpi/ic_place_24dp.png b/res/drawable-mdpi/ic_place_24dp.png
new file mode 100644
index 0000000..2ef1381
--- /dev/null
+++ b/res/drawable-mdpi/ic_place_24dp.png
Binary files differ
diff --git a/res/drawable-xhdpi/ic_email_24dp.png b/res/drawable-xhdpi/ic_email_24dp.png
new file mode 100644
index 0000000..adf14ef
--- /dev/null
+++ b/res/drawable-xhdpi/ic_email_24dp.png
Binary files differ
diff --git a/res/drawable-xhdpi/ic_phone_24dp.png b/res/drawable-xhdpi/ic_phone_24dp.png
new file mode 100644
index 0000000..cd9ff60
--- /dev/null
+++ b/res/drawable-xhdpi/ic_phone_24dp.png
Binary files differ
diff --git a/res/drawable-xhdpi/ic_place_24dp.png b/res/drawable-xhdpi/ic_place_24dp.png
new file mode 100644
index 0000000..0f8bc5b
--- /dev/null
+++ b/res/drawable-xhdpi/ic_place_24dp.png
Binary files differ
diff --git a/res/drawable-xxhdpi/ic_email_24dp.png b/res/drawable-xxhdpi/ic_email_24dp.png
new file mode 100644
index 0000000..d1fc5fc
--- /dev/null
+++ b/res/drawable-xxhdpi/ic_email_24dp.png
Binary files differ
diff --git a/res/drawable-xxhdpi/ic_phone_24dp.png b/res/drawable-xxhdpi/ic_phone_24dp.png
new file mode 100644
index 0000000..3c546e5
--- /dev/null
+++ b/res/drawable-xxhdpi/ic_phone_24dp.png
Binary files differ
diff --git a/res/drawable-xxhdpi/ic_place_24dp.png b/res/drawable-xxhdpi/ic_place_24dp.png
new file mode 100644
index 0000000..0eca249
--- /dev/null
+++ b/res/drawable-xxhdpi/ic_place_24dp.png
Binary files differ
diff --git a/res/layout/expanding_entry_card_item.xml b/res/layout/expanding_entry_card_item.xml
index 888d457..890f2da 100644
--- a/res/layout/expanding_entry_card_item.xml
+++ b/res/layout/expanding_entry_card_item.xml
@@ -26,30 +26,30 @@
     android:paddingBottom="@dimen/expanding_entry_card_item_padding_bottom">
 
     <ImageView
+        android:id="@+id/icon"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
-        android:id="@+id/icon"
         android:layout_alignParentLeft="true"
         android:layout_alignParentTop="true"
-        android:layout_marginRight="@dimen/expanding_entry_card_item_image_spacing"/>
+        android:layout_marginRight="@dimen/expanding_entry_card_item_image_spacing" />
 
     <TextView
+        android:id="@+id/header"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
-        android:id="@+id/header"
         android:layout_alignParentTop="true"
         android:layout_toRightOf="@+id/icon"
-        android:textStyle="bold"
+        android:singleLine="true"
         android:textColor="@android:color/black"
-        android:singleLine="true"/>
+        android:textStyle="bold" />
 
     <TextView
+        android:id="@+id/sub_header"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
-        android:id="@+id/sub_header"
         android:layout_below="@+id/header"
         android:layout_toRightOf="@+id/icon_sub_header"
-        android:textColor="@android:color/black"/>
+        android:textColor="@android:color/black" />
 
     <ImageView
         android:layout_width="wrap_content"
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 84f3247..6be304b 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -645,6 +645,8 @@
     <string name="expanding_entry_card_view_see_more">See more</string>
     <!-- Button Label to see less on an ExpandingEntryCardView [CHAR LIMIT=40] -->
     <string name="expanding_entry_card_view_see_less">See less</string>
+    <!-- Button Label to see all on an ExpandingEntryCardView [CHAR LIMIT=40] -->
+    <string name="expanding_entry_card_view_see_all">See all</string>
 
     <!-- Title of communication card. [CHAR LIMIT=60] -->
     <string name="communication_card_title">Contact</string>
@@ -656,4 +658,6 @@
     <string name="timestamp_string_yesterday">Yesterday</string>
     <!-- Timestamp string for interactions from tomorrow. [CHAR LIMIT=40] -->
     <string name="timestamp_string_tomorrow">Tomorrow</string>
+    <!-- Title of sms action entry. [CHAR LIMIT=60] -->
+    <string name="send_message">Send message</string>
 </resources>
diff --git a/src/com/android/contacts/quickcontact/QuickContactActivity.java b/src/com/android/contacts/quickcontact/QuickContactActivity.java
index 8341c7f..b672d93 100644
--- a/src/com/android/contacts/quickcontact/QuickContactActivity.java
+++ b/src/com/android/contacts/quickcontact/QuickContactActivity.java
@@ -25,11 +25,14 @@
 import android.content.Intent;
 import android.content.Loader;
 import android.content.pm.PackageManager;
+import android.content.res.ColorStateList;
 import android.graphics.Bitmap;
 import android.graphics.Color;
 import android.graphics.drawable.BitmapDrawable;
 import android.graphics.drawable.ColorDrawable;
 import android.graphics.drawable.Drawable;
+import android.graphics.PorterDuff;
+import android.graphics.PorterDuffColorFilter;
 import android.net.Uri;
 import android.os.AsyncTask;
 import android.os.Bundle;
@@ -74,6 +77,7 @@
 import com.android.contacts.interactions.ContactDeletionInteraction;
 import com.android.contacts.interactions.ContactInteraction;
 import com.android.contacts.interactions.SmsInteractionsLoader;
+import com.android.contacts.quickcontact.Action;
 import com.android.contacts.quickcontact.ExpandingEntryCardView.Entry;
 import com.android.contacts.util.ImageViewDrawableSetter;
 import com.android.contacts.util.SchedulingUtils;
@@ -140,6 +144,9 @@
     private Contact mContactData;
     private ContactLoader mContactLoader;
 
+    private PorterDuffColorFilter mColorFilter;
+    List<Drawable> mDrawablesToTint;
+
     private final ImageViewDrawableSetter mPhotoSetter = new ImageViewDrawableSetter();
 
     /**
@@ -292,6 +299,8 @@
 
         mCommunicationCard.setOnClickListener(mEntryClickHandler);
         mCommunicationCard.setTitle(getResources().getString(R.string.communication_card_title));
+        mCommunicationCard.setExpandButtonText(
+        getResources().getString(R.string.expanding_entry_card_view_see_all));
 
         mRecentCard.setOnClickListener(mEntryClickHandler);
         mRecentCard.setTitle(getResources().getString(R.string.recent_card_title));
@@ -323,6 +332,9 @@
             }
         }
 
+
+        mDrawablesToTint = new ArrayList<>();
+
         Trace.endSection();
     }
 
@@ -662,6 +674,9 @@
             @Override
             protected void onPostExecute(Integer color) {
                 super.onPostExecute(color);
+                mColorFilter = new PorterDuffColorFilter(color, PorterDuff.Mode.SRC_ATOP);
+                // Make sure the color is valid. Also check that the Photo has not changed. If it
+                // has changed, the new tint color needs to be extracted
                 if (color != 0 && imageViewDrawable == mPhotoView.getDrawable()) {
                     // TODO: animate from the previous tint.
                     mScroller.setHeaderTintColor(color);
@@ -675,6 +690,10 @@
                     mStatusBarColor = Color.HSVToColor(hsvComponents);
 
                     updateStatusBarColor();
+                    for (Drawable drawable : mDrawablesToTint) {
+                        applyThemeColorIfAvailable(drawable);
+                    }
+                    mDrawablesToTint.clear();
                 }
             }
         }.execute();
@@ -754,11 +773,44 @@
     private List<Entry> actionsToEntries(List<Action> actions) {
         List<Entry> entries = new ArrayList<>();
         for (Action action :  actions) {
-            entries.add(new Entry(ResolveCache.getInstance(this).getIcon(action),
-                    action.getMimeType(),
-                    action.getSubtitle() == null ? null : action.getSubtitle().toString(),
-                    action.getBody() == null ? null : action.getBody().toString(),
-                    action.getIntent(), /* isEditable= */ false));
+            String header = null;
+            String body = null;
+            String footer = null;
+            Drawable icon = null;
+            switch (action.getMimeType()) {
+                case Phone.CONTENT_ITEM_TYPE:
+                    header = action.getBody().toString();
+                    footer = action.getSubtitle().toString();
+                    icon = applyThemeColorIfAvailable(
+                            getResources().getDrawable(R.drawable.ic_phone_24dp));
+                    break;
+                case Email.CONTENT_ITEM_TYPE:
+                    header = action.getBody().toString();
+                    footer = action.getSubtitle().toString();
+                    icon = applyThemeColorIfAvailable(
+                            getResources().getDrawable(R.drawable.ic_email_24dp));
+                    break;
+                case StructuredPostal.CONTENT_ITEM_TYPE:
+                    header = action.getBody().toString();
+                    footer = action.getSubtitle().toString();
+                    icon = applyThemeColorIfAvailable(
+                            getResources().getDrawable(R.drawable.ic_place_24dp));
+                    break;
+                default:
+                    header = action.getSubtitle().toString();
+                    footer = action.getBody().toString();
+                    icon = ResolveCache.getInstance(this).getIcon(action);
+            }
+            entries.add(new Entry(icon, header, body, footer, action.getIntent(),
+                    /* isEditable= */ false));
+
+            // Add SMS in addition to phone calls
+            if (action.getMimeType().equals(Phone.CONTENT_ITEM_TYPE)) {
+                entries.add(new Entry(applyThemeColorIfAvailable(getResources().getDrawable(
+                        R.drawable.ic_message_24dp)),
+                        getResources().getString(R.string.send_message), null, header,
+                        action.getAlternateIntent(), /* isEditable = */ false));
+            }
         }
         return entries;
     }
@@ -766,7 +818,7 @@
     private List<Entry> contactInteractionsToEntries(List<ContactInteraction> interactions) {
         List<Entry> entries = new ArrayList<>();
         for (ContactInteraction interaction : interactions) {
-            entries.add(new Entry(interaction.getIcon(this),
+            entries.add(new Entry(applyThemeColorIfAvailable(interaction.getIcon(this)),
                     interaction.getViewHeader(this),
                     interaction.getViewBody(this),
                     interaction.getBodyIcon(this),
@@ -919,4 +971,18 @@
             mEntriesAndActionsTask.cancel(/* mayInterruptIfRunning = */ false);
         }
     }
+
+    /**
+     * Applies the theme color as extracted in
+     * {@link extractAndApplyTintFromPhotoViewAsynchonously()} if available. If the color is not
+     * available, store a reference to the drawable to tint when a color becomes available.
+     */
+    private Drawable applyThemeColorIfAvailable(Drawable drawable) {
+        if (mColorFilter != null) {
+            drawable.setColorFilter(mColorFilter);
+        } else {
+            mDrawablesToTint.add(drawable);
+        }
+        return drawable;
+    }
 }