Merge "Editor name fields" into lmp-mr1-dev
diff --git a/res/layout/edit_field_list.xml b/res/layout/edit_field_list.xml
index 0073112..066810a 100644
--- a/res/layout/edit_field_list.xml
+++ b/res/layout/edit_field_list.xml
@@ -20,6 +20,7 @@
 <LinearLayout
     xmlns:android="http://schemas.android.com/apk/res/android"
     android:id="@+id/editors"
-    android:layout_width="match_parent"
+    android:layout_width="0dip"
     android:layout_height="wrap_content"
+    android:layout_weight="1"
     android:orientation="vertical" />
diff --git a/res/layout/phonetic_name_editor_view.xml b/res/layout/phonetic_name_editor_view.xml
index d67dcf5..efaf644 100644
--- a/res/layout/phonetic_name_editor_view.xml
+++ b/res/layout/phonetic_name_editor_view.xml
@@ -20,33 +20,29 @@
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     android:minHeight="@dimen/editor_min_line_item_height"
-    android:orientation="vertical">
+    android:layout_marginStart="@dimen/editor_kind_icon_total_width">
 
+    <!-- This isn't used in PhoneticNameEditorView. It is only included so that
+        StructuredNameEditorView's base classes don't need extra null checks. -->
     <include
         android:id="@+id/spinner"
         layout="@layout/edit_spinner"
         android:visibility="gone" />
 
-    <LinearLayout
-        android:layout_width="match_parent"
-        android:layout_height="wrap_content"
-        android:orientation="horizontal"
-        android:gravity="center_vertical">
+    <include
+        android:id="@+id/editors"
+        layout="@layout/edit_field_list" />
 
-        <include
-            android:id="@+id/editors"
-            layout="@layout/edit_field_list" />
+    <include
+        android:id="@+id/expansion_view_container"
+        layout="@layout/name_edit_expansion_view"
+        android:visibility="visible" />
 
-        <include
-            android:id="@+id/expansion_view_container"
-            layout="@layout/name_edit_expansion_view"
-            android:visibility="gone" />
-
-        <include
-            android:id="@+id/delete_button_container"
-            layout="@layout/edit_delete_button"
-            android:visibility="gone" />
-
-    </LinearLayout>
+    <!-- This isn't used in PhoneticNameEditorView. It is only included so that
+        StructuredNameEditorView's base classes don't need extra null checks. -->
+    <include
+        android:id="@+id/delete_button_container"
+        layout="@layout/edit_delete_button"
+        android:visibility="gone" />
 
 </com.android.contacts.editor.PhoneticNameEditorView>
diff --git a/res/layout/raw_contact_editor_view.xml b/res/layout/raw_contact_editor_view.xml
index 03996b5..ace6c8f 100644
--- a/res/layout/raw_contact_editor_view.xml
+++ b/res/layout/raw_contact_editor_view.xml
@@ -38,6 +38,10 @@
         layout="@layout/phonetic_name_editor_view" />
 
     <include
+        android:id="@+id/edit_nick_name"
+        layout="@layout/item_kind_section" />
+
+    <include
         android:id="@+id/edit_photo"
         android:layout_marginRight="8dip"
         android:layout_marginEnd="8dip"
diff --git a/res/layout/structured_name_editor_view.xml b/res/layout/structured_name_editor_view.xml
index fc57159..b6d6eca 100644
--- a/res/layout/structured_name_editor_view.xml
+++ b/res/layout/structured_name_editor_view.xml
@@ -42,6 +42,8 @@
         layout="@layout/name_edit_expansion_view"
         android:visibility="gone" />
 
+    <!-- This isn't used in StructuredNameEditorView. It is only included so that
+        StructuredNameEditorView's base classes don't need extra null checks. -->
     <include
         android:id="@+id/delete_button_container"
         layout="@layout/edit_delete_button"
diff --git a/res/values/dimens.xml b/res/values/dimens.xml
index 69b56dc..53855ba 100644
--- a/res/values/dimens.xml
+++ b/res/values/dimens.xml
@@ -57,6 +57,9 @@
     <!-- Width and height of the mime-type icons inside the editor -->
     <dimen name="editor_kind_icon_size">24dp</dimen>
 
+    <!-- Total width of data-kind icon, including its start and end padding -->
+    <dimen name="editor_kind_icon_total_width">72dp</dimen>
+
     <!-- Padding below every editor view, such as LabeledEditorView -->
     <dimen name="editor_padding_between_editor_views">24dp</dimen>
 
diff --git a/src/com/android/contacts/editor/PhoneticNameEditorView.java b/src/com/android/contacts/editor/PhoneticNameEditorView.java
index 420575c..e645687 100644
--- a/src/com/android/contacts/editor/PhoneticNameEditorView.java
+++ b/src/com/android/contacts/editor/PhoneticNameEditorView.java
@@ -151,4 +151,12 @@
         return !TextUtils.isEmpty(family) || !TextUtils.isEmpty(middle)
                 || !TextUtils.isEmpty(given);
     }
+
+    /** {@inheritDoc} */
+    @Override
+    protected void onFinishInflate() {
+        super.onFinishInflate();
+        // Remove padding below this view.
+        setPadding(getPaddingLeft(), getPaddingTop(), getPaddingRight(), 0);
+    }
 }
diff --git a/src/com/android/contacts/editor/RawContactEditorView.java b/src/com/android/contacts/editor/RawContactEditorView.java
index f0fbc4a..4a05d7a 100644
--- a/src/com/android/contacts/editor/RawContactEditorView.java
+++ b/src/com/android/contacts/editor/RawContactEditorView.java
@@ -64,6 +64,7 @@
 
     private StructuredNameEditorView mName;
     private PhoneticNameEditorView mPhoneticName;
+    private KindSectionView mNickNameSectionView;
     private GroupMembershipView mGroupMembershipView;
 
     private ViewGroup mFields;
@@ -127,6 +128,8 @@
         mPhoneticName = (PhoneticNameEditorView)findViewById(R.id.edit_phonetic_name);
         mPhoneticName.setDeletable(false);
 
+        mNickNameSectionView = (KindSectionView)findViewById(R.id.edit_nick_name);
+
         mFields = (ViewGroup)findViewById(R.id.sect_fields);
 
         mAccountIcon = (ImageView) findViewById(R.id.account_icon);
@@ -243,6 +246,11 @@
                 mPhoneticName.setValues(
                         type.getKindForMimetype(DataKind.PSEUDO_MIME_TYPE_PHONETIC_NAME),
                         primary, state, false, vig);
+                // Special case for nick name, so it gets inserted in the header section. It
+                // should look like it belongs to the same KindSectionView as the other name fields.
+                mNickNameSectionView.setEnabled(isEnabled());
+                mNickNameSectionView.setState(type.getKindForMimetype(Nickname.CONTENT_ITEM_TYPE),
+                        state, false, vig);
             } else if (Photo.CONTENT_ITEM_TYPE.equals(mimeType)) {
                 // Handle special case editor for photos
                 final ValuesDelta primary = state.getPrimaryEntry(mimeType);
@@ -255,8 +263,7 @@
             } else if (DataKind.PSEUDO_MIME_TYPE_DISPLAY_NAME.equals(mimeType)
                     || DataKind.PSEUDO_MIME_TYPE_PHONETIC_NAME.equals(mimeType)
                     || Nickname.CONTENT_ITEM_TYPE.equals(mimeType)) {
-                // Don't create fields for each of these mime-types. Instead, a single merged
-                // field is created for these mime-types.
+                // Don't create fields for each of these mime-types. They are handled specially.
                 continue;
             } else {
                 // Otherwise use generic section-based editors
diff --git a/src/com/android/contacts/editor/StructuredNameEditorView.java b/src/com/android/contacts/editor/StructuredNameEditorView.java
index a607cca..b24f7f1 100644
--- a/src/com/android/contacts/editor/StructuredNameEditorView.java
+++ b/src/com/android/contacts/editor/StructuredNameEditorView.java
@@ -275,4 +275,12 @@
             return 0;
         }
     }
+
+    /** {@inheritDoc} */
+    @Override
+    protected void onFinishInflate() {
+        super.onFinishInflate();
+        // Remove padding below this view.
+        setPadding(getPaddingLeft(), getPaddingTop(), getPaddingRight(), 0);
+    }
 }