Adding proper chat capability icons to contact list

Change-Id: If25b3041649b5c9442abe73729c234934314c316
diff --git a/src/com/android/contacts/ContactPresenceIconUtil.java b/src/com/android/contacts/ContactPresenceIconUtil.java
index 81a1bed..1811e81 100644
--- a/src/com/android/contacts/ContactPresenceIconUtil.java
+++ b/src/com/android/contacts/ContactPresenceIconUtil.java
@@ -47,7 +47,7 @@
         }
     }
 
-    public static Drawable getCapabilityIcon(Context context, int status, int chatCapability) {
+    public static Drawable getChatCapabilityIcon(Context context, int status, int chatCapability) {
         int resourceId = 0;
         if ((chatCapability & Im.CAPABILITY_HAS_CAMERA) != 0) {
             switch(status) {
@@ -75,6 +75,8 @@
                     resourceId = android.R.drawable.presence_audio_busy;
                     break;
             }
+        } else {
+            resourceId = StatusUpdates.getPresenceIconResourceId(status);
         }
 
         if (resourceId != 0) {
diff --git a/src/com/android/contacts/detail/ContactDetailFragment.java b/src/com/android/contacts/detail/ContactDetailFragment.java
index 7ff8acd..e56be7b 100644
--- a/src/com/android/contacts/detail/ContactDetailFragment.java
+++ b/src/com/android/contacts/detail/ContactDetailFragment.java
@@ -951,7 +951,7 @@
             if (entry.secondaryActionIcon != -1) {
                 secondaryActionIcon = resources.getDrawable(entry.secondaryActionIcon);
             } else if (entry.chatCapability != 0) {
-                secondaryActionIcon = ContactPresenceIconUtil.getCapabilityIcon(
+                secondaryActionIcon = ContactPresenceIconUtil.getChatCapabilityIcon(
                         mContext, entry.presence, entry.chatCapability);
             }
 
diff --git a/src/com/android/contacts/list/ContactListAdapter.java b/src/com/android/contacts/list/ContactListAdapter.java
index c647402..3fad688 100644
--- a/src/com/android/contacts/list/ContactListAdapter.java
+++ b/src/com/android/contacts/list/ContactListAdapter.java
@@ -43,11 +43,12 @@
         Contacts.SORT_KEY_PRIMARY,              // 3
         Contacts.STARRED,                       // 4
         Contacts.CONTACT_PRESENCE,              // 5
-        Contacts.PHOTO_ID,                      // 6
-        Contacts.PHOTO_THUMBNAIL_URI,           // 7
-        Contacts.LOOKUP_KEY,                    // 8
-        Contacts.PHONETIC_NAME,                 // 9
-        Contacts.HAS_PHONE_NUMBER,              // 10
+        Contacts.CONTACT_CHAT_CAPABILITY,       // 6
+        Contacts.PHOTO_ID,                      // 7
+        Contacts.PHOTO_THUMBNAIL_URI,           // 8
+        Contacts.LOOKUP_KEY,                    // 9
+        Contacts.PHONETIC_NAME,                 // 10
+        Contacts.HAS_PHONE_NUMBER,              // 11
     };
 
     protected static final String[] PROJECTION_DATA = new String[] {
@@ -57,11 +58,12 @@
         Data.SORT_KEY_PRIMARY,                  // 3
         Data.STARRED,                           // 4
         Data.CONTACT_PRESENCE,                  // 5
-        Data.PHOTO_ID,                          // 6
-        Data.PHOTO_THUMBNAIL_URI,               // 7
-        Data.LOOKUP_KEY,                        // 8
-        Data.PHONETIC_NAME,                     // 9
-        Data.HAS_PHONE_NUMBER,                  // 10
+        Data.CONTACT_CHAT_CAPABILITY,           // 6
+        Data.PHOTO_ID,                          // 7
+        Data.PHOTO_THUMBNAIL_URI,               // 8
+        Data.LOOKUP_KEY,                        // 9
+        Data.PHONETIC_NAME,                     // 10
+        Data.HAS_PHONE_NUMBER,                  // 11
     };
 
     protected static final String[] FILTER_PROJECTION = new String[] {
@@ -71,14 +73,15 @@
         Contacts.SORT_KEY_PRIMARY,              // 3
         Contacts.STARRED,                       // 4
         Contacts.CONTACT_PRESENCE,              // 5
-        Contacts.PHOTO_ID,                      // 6
-        Contacts.PHOTO_THUMBNAIL_URI,           // 7
-        Contacts.LOOKUP_KEY,                    // 8
-        Contacts.PHONETIC_NAME,                 // 9
-        Contacts.HAS_PHONE_NUMBER,              // 10
-        SearchSnippetColumns.SNIPPET_MIMETYPE,  // 11
-        SearchSnippetColumns.SNIPPET_DATA1,     // 12
-        SearchSnippetColumns.SNIPPET_DATA4,     // 13
+        Contacts.CONTACT_CHAT_CAPABILITY,       // 6
+        Contacts.PHOTO_ID,                      // 7
+        Contacts.PHOTO_THUMBNAIL_URI,           // 8
+        Contacts.LOOKUP_KEY,                    // 9
+        Contacts.PHONETIC_NAME,                 // 10
+        Contacts.HAS_PHONE_NUMBER,              // 11
+        SearchSnippetColumns.SNIPPET_MIMETYPE,  // 12
+        SearchSnippetColumns.SNIPPET_DATA1,     // 13
+        SearchSnippetColumns.SNIPPET_DATA4,     // 14
     };
 
     protected static final int CONTACT_ID_COLUMN_INDEX = 0;
@@ -87,14 +90,15 @@
     protected static final int CONTACT_SORT_KEY_PRIMARY_COLUMN_INDEX = 3;
     protected static final int CONTACT_STARRED_COLUMN_INDEX = 4;
     protected static final int CONTACT_PRESENCE_STATUS_COLUMN_INDEX = 5;
-    protected static final int CONTACT_PHOTO_ID_COLUMN_INDEX = 6;
-    protected static final int CONTACT_PHOTO_URI_COLUMN_INDEX = 7;
-    protected static final int CONTACT_LOOKUP_KEY_COLUMN_INDEX = 8;
-    protected static final int CONTACT_PHONETIC_NAME_COLUMN_INDEX = 9;
-    protected static final int CONTACT_HAS_PHONE_COLUMN_INDEX = 10;
-    protected static final int CONTACT_SNIPPET_MIMETYPE_COLUMN_INDEX = 11;
-    protected static final int CONTACT_SNIPPET_DATA1_COLUMN_INDEX = 12;
-    protected static final int CONTACT_SNIPPET_DATA4_COLUMN_INDEX = 13;
+    protected static final int CONTACT_CHAT_CAPABILITY_COLUMN_INDEX = 6;
+    protected static final int CONTACT_PHOTO_ID_COLUMN_INDEX = 7;
+    protected static final int CONTACT_PHOTO_URI_COLUMN_INDEX = 8;
+    protected static final int CONTACT_LOOKUP_KEY_COLUMN_INDEX = 9;
+    protected static final int CONTACT_PHONETIC_NAME_COLUMN_INDEX = 10;
+    protected static final int CONTACT_HAS_PHONE_COLUMN_INDEX = 11;
+    protected static final int CONTACT_SNIPPET_MIMETYPE_COLUMN_INDEX = 12;
+    protected static final int CONTACT_SNIPPET_DATA1_COLUMN_INDEX = 13;
+    protected static final int CONTACT_SNIPPET_DATA4_COLUMN_INDEX = 14;
 
     private CharSequence mUnknownNameText;
     private int mDisplayNameColumnIndex;
@@ -261,7 +265,8 @@
     }
 
     protected void bindPresence(final ContactListItemView view, Cursor cursor) {
-        view.showPresence(cursor, CONTACT_PRESENCE_STATUS_COLUMN_INDEX);
+        view.showPresence(cursor, CONTACT_PRESENCE_STATUS_COLUMN_INDEX,
+                CONTACT_CHAT_CAPABILITY_COLUMN_INDEX);
     }
 
     protected void bindSearchSnippet(final ContactListItemView view, Cursor cursor) {
diff --git a/src/com/android/contacts/list/ContactListItemView.java b/src/com/android/contacts/list/ContactListItemView.java
index 8f03c56..2d75eca 100644
--- a/src/com/android/contacts/list/ContactListItemView.java
+++ b/src/com/android/contacts/list/ContactListItemView.java
@@ -845,21 +845,18 @@
     /**
      * Sets the proper icon (star or presence or nothing)
      */
-    public void showPresence(Cursor cursor, int presenceColumnIndex) {
-        int serverStatus;
+    public void showPresence(Cursor cursor, int presenceColumnIndex, int capabilityColumnIndex) {
+        Drawable icon = null;
         if (!cursor.isNull(presenceColumnIndex)) {
-            serverStatus = cursor.getInt(presenceColumnIndex);
-
-            // TODO consider caching these drawables
-            Drawable icon = ContactPresenceIconUtil.getPresenceIcon(getContext(), serverStatus);
-            if (icon != null) {
-                setPresence(icon);
-            } else {
-                setPresence(null);
+            int status = cursor.getInt(presenceColumnIndex);
+            int chatCapability = 0;
+            if (capabilityColumnIndex != 0 && !cursor.isNull(presenceColumnIndex)) {
+                chatCapability = cursor.getInt(capabilityColumnIndex);
             }
-        } else {
-            setPresence(null);
+            icon = ContactPresenceIconUtil.getChatCapabilityIcon(
+                    getContext(), status, chatCapability);
         }
+        setPresence(icon);
     }
 
     /**
diff --git a/src/com/android/contacts/list/LegacyContactListAdapter.java b/src/com/android/contacts/list/LegacyContactListAdapter.java
index 39c0b53..6747d1f 100644
--- a/src/com/android/contacts/list/LegacyContactListAdapter.java
+++ b/src/com/android/contacts/list/LegacyContactListAdapter.java
@@ -90,6 +90,6 @@
     }
 
     protected void bindPresence(final ContactListItemView view, Cursor cursor) {
-        view.showPresence(cursor, PERSON_PRESENCE_STATUS_COLUMN_INDEX);
+        view.showPresence(cursor, PERSON_PRESENCE_STATUS_COLUMN_INDEX, 0);
     }
 }