Add badge icon for work contact in search result

BUG=26021888
BUG=28016344
(cherry picked from commit 6e00763823cd1b27ff88d25d0eb11f8addc3b2e6)

Change-Id: If0e2f7b1c58cd064ebfdae8a9b735b391c5009fc
diff --git a/res/drawable-hdpi/ic_work_profile.png b/res/drawable-hdpi/ic_work_profile.png
new file mode 100644
index 0000000..5c2e457
--- /dev/null
+++ b/res/drawable-hdpi/ic_work_profile.png
Binary files differ
diff --git a/res/drawable-mdpi/ic_work_profile.png b/res/drawable-mdpi/ic_work_profile.png
new file mode 100644
index 0000000..b7ffd2b
--- /dev/null
+++ b/res/drawable-mdpi/ic_work_profile.png
Binary files differ
diff --git a/res/drawable-xhdpi/ic_work_profile.png b/res/drawable-xhdpi/ic_work_profile.png
new file mode 100644
index 0000000..b47b485
--- /dev/null
+++ b/res/drawable-xhdpi/ic_work_profile.png
Binary files differ
diff --git a/res/drawable-xxhdpi/ic_work_profile.png b/res/drawable-xxhdpi/ic_work_profile.png
new file mode 100644
index 0000000..de257e7
--- /dev/null
+++ b/res/drawable-xxhdpi/ic_work_profile.png
Binary files differ
diff --git a/res/drawable-xxxhdpi/ic_work_profile.png b/res/drawable-xxxhdpi/ic_work_profile.png
new file mode 100644
index 0000000..72292bd
--- /dev/null
+++ b/res/drawable-xxxhdpi/ic_work_profile.png
Binary files differ
diff --git a/res/layout/contact_list_item_view.xml b/res/layout/contact_list_item_view.xml
index 3015ae3..71a7370 100644
--- a/res/layout/contact_list_item_view.xml
+++ b/res/layout/contact_list_item_view.xml
@@ -63,15 +63,30 @@
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:layout_gravity="center_vertical" >
-        <TextView
-            android:id="@+id/contact_name"
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
-            android:paddingBottom="4dp"
-            android:singleLine="true"
-            android:maxLines="1"
-            android:ellipsize="end"
-            style="@style/ContactListItem" />
+
+    <LinearLayout
+        android:orientation="horizontal"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content">
+            <TextView
+                android:id="@+id/contact_name"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:layout_weight="1"
+                android:paddingBottom="4dp"
+                android:singleLine="true"
+                android:maxLines="1"
+                android:ellipsize="end"
+                style="@style/ContactListItem" />
+
+            <ImageView android:id="@+id/work_profile_icon"
+                android:src="@drawable/ic_work_profile"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:scaleType="center"
+                android:layout_gravity="center_vertical"
+                android:visibility="gone" />
+        </LinearLayout>
 
         <LinearLayout
             android:orientation="horizontal"
diff --git a/src/com/android/messaging/datamodel/data/ContactListItemData.java b/src/com/android/messaging/datamodel/data/ContactListItemData.java
index dcc7e20..b9c7e85 100644
--- a/src/com/android/messaging/datamodel/data/ContactListItemData.java
+++ b/src/com/android/messaging/datamodel/data/ContactListItemData.java
@@ -46,6 +46,9 @@
     // existing chip for which we show full contact detail for the selected contact).
     private boolean mSingleRecipient;
 
+    // Is the contact in managed profile.
+    private boolean mIsWorkContact;
+
     /**
      * Bind to a contact cursor in the contact list.
      */
@@ -77,6 +80,8 @@
         mRecipientEntry = ContactUtil.createRecipientEntry(displayName,
                 DisplayNameSources.STRUCTURED_NAME, destination, destinationType, destinationLabel,
                 contactId, lookupKey, dataId, photoThumbnailUri, isFirstLevel);
+
+        mIsWorkContact = ContactUtil.isEnterpriseContactId(contactId);
     }
 
     /**
@@ -84,13 +89,15 @@
      * optional styled name & destination for showing bold search match.
      */
     public void bind(final RecipientEntry entry, final CharSequence styledName,
-            final CharSequence styledDestination, final boolean singleRecipient) {
+                     final CharSequence styledDestination, final boolean singleRecipient,
+                     final boolean isWorkContact) {
         Assert.isTrue(entry.isValid());
         mRecipientEntry = entry;
         mStyledName = styledName;
         mStyledDestination = styledDestination;
         mAlphabetHeader = null;
         mSingleRecipient = singleRecipient;
+        mIsWorkContact = isWorkContact;
     }
 
     public CharSequence getDisplayName() {
@@ -157,4 +164,11 @@
     public RecipientEntry getRecipientEntry() {
         return mRecipientEntry;
     }
+
+    /**
+     * @return whether the contact is in managed profile.
+     */
+    public boolean getIsWorkContact() {
+        return mIsWorkContact;
+    }
 }
diff --git a/src/com/android/messaging/ui/contact/ContactDropdownLayouter.java b/src/com/android/messaging/ui/contact/ContactDropdownLayouter.java
index 7df62de..051ebeb 100644
--- a/src/com/android/messaging/ui/contact/ContactDropdownLayouter.java
+++ b/src/com/android/messaging/ui/contact/ContactDropdownLayouter.java
@@ -34,6 +34,7 @@
 import com.android.messaging.util.Assert;
 import com.android.messaging.util.AvatarUriUtil;
 import com.android.messaging.util.ContactRecipientEntryUtils;
+import com.android.messaging.util.ContactUtil;
 
 /**
  * An implementation for {@link DropdownChipLayouter}. Layouts the dropdown
@@ -99,8 +100,9 @@
         Assert.isTrue(itemView instanceof ContactListItemView);
         final ContactListItemView contactListItemView = (ContactListItemView) itemView;
         contactListItemView.setImageClickHandlerDisabled(true);
+        boolean isWorkContact = ContactUtil.isEnterpriseContactId(entry.getContactId());
         contactListItemView.bind(entry, styledResults[0], styledResults[1],
-                mClivHostInterface, (type == AdapterType.SINGLE_RECIPIENT));
+                mClivHostInterface, (type == AdapterType.SINGLE_RECIPIENT), isWorkContact);
         return itemView;
     }
 
diff --git a/src/com/android/messaging/ui/contact/ContactListItemView.java b/src/com/android/messaging/ui/contact/ContactListItemView.java
index 6904da6..b0e8957 100644
--- a/src/com/android/messaging/ui/contact/ContactListItemView.java
+++ b/src/com/android/messaging/ui/contact/ContactListItemView.java
@@ -53,6 +53,7 @@
     private TextView mAlphabetHeaderTextView;
     private ContactIconView mContactIconView;
     private ImageView mContactCheckmarkView;
+    private ImageView mWorkProfileIcon;
     private HostInterface mHostInterface;
     private boolean mShouldShowAlphabetHeader;
 
@@ -69,6 +70,7 @@
         mAlphabetHeaderTextView = (TextView) findViewById(R.id.alphabet_header);
         mContactIconView = (ContactIconView) findViewById(R.id.contact_icon);
         mContactCheckmarkView = (ImageView) findViewById(R.id.contact_checkmark);
+        mWorkProfileIcon = (ImageView) findViewById(R.id.work_profile_icon);
     }
 
     /**
@@ -100,11 +102,12 @@
      * @param isSingleRecipient whether this item is shown as the only line item in the single
      *        recipient drop down from the chips view. If this is the case, we always show the
      *        contact avatar even if it's not a first-level entry.
+     * @param isWorkContact whether the contact is in managed profile.
      */
     public void bind(final RecipientEntry recipientEntry, final CharSequence styledName,
             final CharSequence styledDestination, final HostInterface hostInterface,
-            final boolean isSingleRecipient) {
-        mData.bind(recipientEntry, styledName, styledDestination, isSingleRecipient);
+            final boolean isSingleRecipient, final boolean isWorkContact) {
+        mData.bind(recipientEntry, styledName, styledDestination, isSingleRecipient, isWorkContact);
         mHostInterface = hostInterface;
         mShouldShowAlphabetHeader = false;
         updateViewAppearance();
@@ -152,7 +155,11 @@
             mContactDetailsTextView.setVisibility(VISIBLE);
             mContactDetailTypeTextView.setVisibility(VISIBLE);
         }
-
+        if (mData.getIsWorkContact()) {
+            mWorkProfileIcon.setVisibility(VISIBLE);
+        } else {
+            mWorkProfileIcon.setVisibility(GONE);
+        }
         if (mShouldShowAlphabetHeader) {
             mAlphabetHeaderTextView.setVisibility(VISIBLE);
             mAlphabetHeaderTextView.setText(mData.getAlphabetHeader());