Create new layout for xlarge contact-detail-items

Change-Id: Ifb70f51a9a24cf2bfac5a36e8a703713626d3926
diff --git a/res/layout-xlarge/contact_browser.xml b/res/layout-xlarge/contact_browser.xml
index 4643e44..7b90089 100644
--- a/res/layout-xlarge/contact_browser.xml
+++ b/res/layout-xlarge/contact_browser.xml
@@ -25,7 +25,6 @@
         android:id="@+id/list_container"
         android:layout_width="380dip"
         android:layout_height="match_parent" 
-        android:layout_marginLeft="20dip"
         android:layout_marginRight="50dip"/>
 
     <!--  Holder for detail- or editor-fragment. -->
diff --git a/res/layout-xlarge/contact_detail_list_item.xml b/res/layout-xlarge/contact_detail_list_item.xml
new file mode 100644
index 0000000..dd5c4be
--- /dev/null
+++ b/res/layout-xlarge/contact_detail_list_item.xml
@@ -0,0 +1,101 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/*
+ * Copyright 2010, The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+-->
+
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="match_parent"
+    android:layout_height="wrap_content"
+    android:minHeight="?android:attr/listPreferredItemHeight"
+    android:orientation="horizontal"
+    android:paddingLeft="9dip"
+    android:gravity="center_vertical"
+>
+    <TextView android:id="@+id/kind"
+        android:layout_width="100dip"
+        android:layout_height="wrap_content"
+        android:textAppearance="?android:attr/textAppearanceSmall"
+    />
+
+    <TextView android:id="@+id/type"
+        android:layout_width="100dip"
+        android:layout_height="wrap_content"
+        android:textAppearance="?android:attr/textAppearanceSmall"
+    />
+
+    <TextView android:id="@+id/data"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_gravity="center_vertical"
+        android:layout_weight="1"
+        android:layout_marginLeft="8dip"
+        android:textAppearance="?android:attr/textAppearanceLarge"
+    />
+
+    <ImageView android:id="@+id/primary_icon"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_gravity="center_vertical"
+        android:paddingLeft="3dip"
+        android:src="@drawable/ic_default_number"
+    />
+
+    <TextView
+        android:id="@+id/footer"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_gravity="center_vertical"
+        android:textAppearance="?android:attr/textAppearanceSmall"
+        android:visibility="gone" />
+
+    <ImageView android:id="@+id/presence_icon"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_marginLeft="5dip"
+        android:gravity="center"
+        android:scaleType="centerInside"
+    />
+
+    <ImageView android:id="@+id/action_icon"
+        android:layout_width="30dip"
+        android:layout_height="30dip"
+        android:layout_marginLeft="14dip"
+        android:layout_marginRight="14dip"
+        android:gravity="center"
+        android:scaleType="centerInside"
+    />
+    
+    <View android:id="@+id/divider"
+        android:layout_width="1px"
+        android:layout_height="match_parent"
+        android:layout_marginTop="5dip"
+        android:layout_marginBottom="5dip"
+        android:background="@drawable/divider_vertical_dark"
+    />
+
+    <ImageView android:id="@+id/secondary_action_button"
+        android:layout_width="wrap_content"
+        android:layout_height="match_parent"
+        android:layout_centerVertical="true"
+        android:paddingLeft="14dip"
+        android:paddingRight="14dip"
+        android:gravity="center"
+        android:scaleType="center"
+        android:background="@android:drawable/list_selector_background"
+    />
+
+</LinearLayout>
diff --git a/res/layout/list_item_text_icons.xml b/res/layout/contact_detail_list_item.xml
similarity index 97%
rename from res/layout/list_item_text_icons.xml
rename to res/layout/contact_detail_list_item.xml
index 69e064e..a110ec2 100644
--- a/res/layout/list_item_text_icons.xml
+++ b/res/layout/contact_detail_list_item.xml
@@ -37,7 +37,7 @@
         android:gravity="center_vertical"
     >
 
-        <TextView android:id="@android:id/text1"
+        <TextView android:id="@+id/kind_and_type"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:textAppearance="?android:attr/textAppearanceLarge"
@@ -49,7 +49,7 @@
             android:orientation="horizontal"
         >
             
-            <TextView android:id="@android:id/text2"
+            <TextView android:id="@+id/data"
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
                 android:layout_gravity="center_vertical"
diff --git a/src/com/android/contacts/views/detail/ContactDetailFragment.java b/src/com/android/contacts/views/detail/ContactDetailFragment.java
index ae14568..2bb5e52 100644
--- a/src/com/android/contacts/views/detail/ContactDetailFragment.java
+++ b/src/com/android/contacts/views/detail/ContactDetailFragment.java
@@ -26,6 +26,7 @@
 import com.android.contacts.TypePrecedence;
 import com.android.contacts.model.ContactsSource;
 import com.android.contacts.model.ContactsSource.DataKind;
+import com.android.contacts.model.ContactsSource.EditType;
 import com.android.contacts.model.Sources;
 import com.android.contacts.util.Constants;
 import com.android.contacts.util.DataStatus;
@@ -299,7 +300,7 @@
                 if (mimeType == null) continue;
 
                 final DataKind kind = sources.getKindOrFallback(accountType, mimeType, mContext,
-                        ContactsSource.LEVEL_MIMETYPES);
+                        ContactsSource.LEVEL_CONSTRAINTS);
                 if (kind == null) continue;
 
                 final ViewEntry entry = ViewEntry.fromValues(mContext, mimeType, kind, dataId,
@@ -380,8 +381,8 @@
                         entry.intent = imActions.getPrimaryIntent();
                         entry.secondaryIntent = imActions.getSecondaryIntent();
                     }
-                    if (TextUtils.isEmpty(entry.label)) {
-                        entry.label = mContext.getString(R.string.chat).toLowerCase();
+                    if (TextUtils.isEmpty(entry.kindAndType)) {
+                        entry.kindAndType = mContext.getString(R.string.chat).toLowerCase();
                     }
 
                     // Apply presence and status details when available
@@ -391,7 +392,7 @@
                     }
                     mImEntries.add(entry);
                 } else if (Organization.CONTENT_ITEM_TYPE.equals(mimeType) &&
-                        (hasData || !TextUtils.isEmpty(entry.label))) {
+                        (hasData || !TextUtils.isEmpty(entry.typeString))) {
                     // Build organization entries
                     final boolean isNameRawContact =
                             (mContactData.getNameRawContactId() == rawContactId);
@@ -400,13 +401,14 @@
                             isNameRawContact
                             && mContactData.getDisplayNameSource()
                                 == DisplayNameSources.ORGANIZATION
-                            && (!hasData || TextUtils.isEmpty(entry.label));
+                            && (!hasData || TextUtils.isEmpty(entry.typeString));
 
                     if (!duplicatesTitle) {
                         entry.uri = null;
 
-                        if (TextUtils.isEmpty(entry.label)) {
-                            entry.label = entry.data;
+                        if (TextUtils.isEmpty(entry.typeString)) {
+                            entry.kindAndType = entry.data;
+                            entry.typeString = entry.data;
                             entry.data = "";
                         }
 
@@ -474,8 +476,7 @@
         }
     }
 
-    private static String buildActionString(DataKind kind, ContentValues values,
-            boolean lowerCase, Context context) {
+    private static String buildActionString(DataKind kind, ContentValues values, Context context) {
         if (kind.actionHeader == null) {
             return null;
         }
@@ -483,7 +484,7 @@
         if (actionHeader == null) {
             return null;
         }
-        return lowerCase ? actionHeader.toString().toLowerCase() : actionHeader.toString();
+        return actionHeader.toString();
     }
 
     private static String buildDataString(DataKind kind, ContentValues values,
@@ -499,9 +500,10 @@
      * A basic structure with the data for a contact entry in the list.
      */
     private static class ViewEntry implements Collapsible<ViewEntry> {
-        // Copied from baseclass
         public int type = -1;
-        public String label;
+        public String kindAndType;
+        public String kind;
+        public String typeString;
         public String data;
         public Uri uri;
         public long id = 0;
@@ -515,7 +517,6 @@
         public int secondaryActionIcon = -1;
         public Intent intent;
         public Intent secondaryIntent = null;
-        public int maxLabelLines = 1;
         public ArrayList<Long> ids = new ArrayList<Long>();
         public int collapseCount = 0;
 
@@ -536,12 +537,31 @@
             entry.id = dataId;
             entry.uri = ContentUris.withAppendedId(Data.CONTENT_URI, entry.id);
             entry.mimetype = mimeType;
-            entry.label = buildActionString(kind, values, false, context);
+            entry.kindAndType = buildActionString(kind, values, context);
+            entry.kind = kind.titleRes == -1 ? "" : context.getString(kind.titleRes);
             entry.data = buildDataString(kind, values, context);
 
             if (kind.typeColumn != null && values.containsKey(kind.typeColumn)) {
                 entry.type = values.getAsInteger(kind.typeColumn);
+
+                // get type string
+                entry.typeString = "";
+                for (EditType type : kind.typeList) {
+                    if (type.rawValue == entry.type) {
+                        if (type.customColumn == null) {
+                            // Non-custom type. Get its description from the resource
+                            entry.typeString = context.getString(type.labelRes);
+                        } else {
+                            // Custom type. Read it from the database
+                            entry.typeString = values.getAsString(type.customColumn);
+                        }
+                        break;
+                    }
+                }
+            } else {
+                entry.typeString = "";
             }
+
             if (kind.iconRes > 0) {
                 entry.resPackageName = kind.resPackageName;
                 entry.actionIcon = kind.iconRes;
@@ -578,12 +598,13 @@
             if (TypePrecedence.getTypePrecedence(mimetype, type)
                     > TypePrecedence.getTypePrecedence(entry.mimetype, entry.type)) {
                 type = entry.type;
-                label = entry.label;
+                kindAndType = entry.kindAndType;
+                kind = entry.kind;
+                typeString = entry.typeString;
             }
 
             // Choose the max of the maxLines and maxLabelLines values.
             maxLines = Math.max(maxLines, entry.maxLines);
-            maxLabelLines = Math.max(maxLabelLines, entry.maxLabelLines);
 
             // Choose the presence with the highest precedence.
             if (StatusUpdates.getPresencePrecedence(presence)
@@ -626,7 +647,9 @@
 
     /** Cache of the children views of a row */
     private static class ViewCache {
-        public TextView label;
+        public TextView kindAndType;
+        public TextView kind;
+        public TextView type;
         public TextView data;
         public TextView footer;
         public ImageView actionIcon;
@@ -649,12 +672,14 @@
                 viewCache = (ViewCache) v.getTag();
             } else {
                 // Create a new view if needed
-                v = mInflater.inflate(R.layout.list_item_text_icons, parent, false);
+                v = mInflater.inflate(R.layout.contact_detail_list_item, parent, false);
 
                 // Cache the children
                 viewCache = new ViewCache();
-                viewCache.label = (TextView) v.findViewById(android.R.id.text1);
-                viewCache.data = (TextView) v.findViewById(android.R.id.text2);
+                viewCache.kindAndType = (TextView) v.findViewById(R.id.kind_and_type);
+                viewCache.kind = (TextView) v.findViewById(R.id.kind);
+                viewCache.type = (TextView) v.findViewById(R.id.type);
+                viewCache.data = (TextView) v.findViewById(R.id.data);
                 viewCache.footer = (TextView) v.findViewById(R.id.footer);
                 viewCache.actionIcon = (ImageView) v.findViewById(R.id.action_icon);
                 viewCache.primaryIcon = (ImageView) v.findViewById(R.id.primary_icon);
@@ -666,30 +691,34 @@
                 v.setTag(viewCache);
             }
 
+            final ViewEntry previousEntry = position == 0 ? null : getEntry(position - 1);
+            final boolean isFirstOfItsKind =
+                    previousEntry == null ? true : !previousEntry.kind.equals(entry.kind);
+
             // Bind the data to the view
-            bindView(v, entry);
+            bindView(v, entry, isFirstOfItsKind);
             return v;
         }
 
-        protected void bindView(View view, ViewEntry entry) {
+        protected void bindView(View view, ViewEntry entry, boolean isFirstOfItsKind) {
             final Resources resources = mContext.getResources();
             ViewCache views = (ViewCache) view.getTag();
 
-            // Set the label
-            TextView label = views.label;
-            setMaxLines(label, entry.maxLabelLines);
-            label.setText(entry.label);
+            // Set the label. This is either a combination field or separate fields for kind of type
+            if (views.kindAndType != null) views.kindAndType.setText(entry.kindAndType);
+            if (views.kind != null) views.kind.setText(isFirstOfItsKind ? entry.kind : "");
+            if (views.type != null) views.type.setText(entry.typeString);
 
-            // Set the data
-            TextView data = views.data;
-            if (data != null) {
+            // Set the content
+            final TextView content = views.data;
+            if (content != null) {
                 if (entry.mimetype.equals(Phone.CONTENT_ITEM_TYPE)
                         || entry.mimetype.equals(Constants.MIME_SMS_ADDRESS)) {
-                    data.setText(PhoneNumberUtils.formatNumber(entry.data));
+                    content.setText(PhoneNumberUtils.formatNumber(entry.data));
                 } else {
-                    data.setText(entry.data);
+                    content.setText(entry.data);
                 }
-                setMaxLines(data, entry.maxLines);
+                setMaxLines(content, entry.maxLines);
             }
 
             // Set the footer