Don't show read only names in an EditText (E13)

Bug 19110128
Bug 23589603

Change-Id: Icc958271fa5c213c98180b22d4c321dea128cb93
diff --git a/res/layout/structured_name_editor_view.xml b/res/layout/structured_name_editor_view.xml
index 2984104..830f4d8 100644
--- a/res/layout/structured_name_editor_view.xml
+++ b/res/layout/structured_name_editor_view.xml
@@ -19,44 +19,35 @@
     xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
-    android:orientation="vertical">
+    android:minHeight="@dimen/editor_min_line_item_height"
+    android:orientation="horizontal">
 
-    <LinearLayout
-        android:layout_width="match_parent"
-        android:layout_height="wrap_content"
-        android:minHeight="@dimen/editor_min_line_item_height"
-        android:orientation="horizontal">
+    <!-- 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/spinner"
+        layout="@layout/edit_spinner"
+        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/spinner"
-            layout="@layout/edit_spinner"
-            android:visibility="gone" />
+    <ImageView
+        android:id="@+id/kind_icon"
+        android:src="@drawable/ic_person_black_24dp"
+        android:contentDescription="@string/header_name_entry"
+        style="@style/EditKindIconStyle"/>
 
-        <ImageView
-            android:id="@+id/kind_icon"
-            android:src="@drawable/ic_person_black_24dp"
-            android:contentDescription="@string/header_name_entry"
-            style="@style/EditKindIconStyle" />
+    <include
+        layout="@layout/edit_field_list_with_anchor_view"/>
 
-        <include
-            layout="@layout/edit_field_list_with_anchor_view" />
+    <include
+        android:id="@+id/expansion_view_container"
+        layout="@layout/name_edit_expansion_view"
+        android:visibility="gone"/>
 
-        <include
-            android:id="@+id/expansion_view_container"
-            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"
-            android:visibility="gone" />
-
-    </LinearLayout>
-
-    <include layout="@layout/account_type_info"/>
+    <!-- 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"
+        android:visibility="gone"/>
 
 </com.android.contacts.editor.StructuredNameEditorView>
diff --git a/res/layout/structured_name_readonly_editor_view.xml b/res/layout/structured_name_readonly_editor_view.xml
new file mode 100644
index 0000000..4778570
--- /dev/null
+++ b/res/layout/structured_name_readonly_editor_view.xml
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+  Copyright (C) 2015 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="@dimen/editor_min_line_item_height"
+        android:orientation="vertical">
+
+    <TextView
+            android:id="@+id/display_name"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:layout_marginStart="4dp"
+            android:layout_marginBottom="6dp"
+            android:singleLine="true"
+            android:textSize="@dimen/editor_form_text_size"
+            android:textColor="?android:attr/textColorSecondary"
+            android:enabled="false"/>
+
+    <include layout="@layout/account_type_info"
+            android:layout_marginStart="12dp" />
+
+</LinearLayout>
diff --git a/res/values/styles.xml b/res/values/styles.xml
index 66ddac6..14dfee2 100644
--- a/res/values/styles.xml
+++ b/res/values/styles.xml
@@ -329,7 +329,7 @@
     <style name="AccountTypeIconStyle">
         <item name="android:layout_width">12dp</item>
         <item name="android:layout_height">12dp</item>
-        <item name="android:layout_marginStart">2dp</item>
+        <item name="android:layout_marginStart">4dp</item>
         <item name="android:layout_marginEnd">4dp</item>
     </style>
 
diff --git a/src/com/android/contacts/editor/CompactKindSectionView.java b/src/com/android/contacts/editor/CompactKindSectionView.java
index b506666..a5f159c 100644
--- a/src/com/android/contacts/editor/CompactKindSectionView.java
+++ b/src/com/android/contacts/editor/CompactKindSectionView.java
@@ -26,6 +26,7 @@
 import android.view.ViewGroup;
 import android.widget.ImageView;
 import android.widget.LinearLayout;
+import android.widget.TextView;
 
 import com.android.contacts.R;
 import com.android.contacts.common.model.RawContactDelta;
@@ -254,6 +255,28 @@
             ValuesDelta valuesDelta, RawContactDelta rawContactDelta) {
         final boolean readOnly = !accountType.areContactsWritable();
 
+        if (readOnly) {
+            final View nameView = mLayoutInflater.inflate(
+                    R.layout.structured_name_readonly_editor_view, mEditors,
+                    /* attachToRoot =*/ false);
+
+            // Display name
+            ((TextView) nameView.findViewById(R.id.display_name))
+                    .setText(valuesDelta.getDisplayName());
+
+            // Account type info
+            final LinearLayout accountTypeLayout = (LinearLayout)
+                    nameView.findViewById(R.id.account_type);
+            accountTypeLayout.setVisibility(View.VISIBLE);
+            ((ImageView) accountTypeLayout.findViewById(R.id.account_type_icon))
+                    .setImageDrawable(accountType.getDisplayIcon(getContext()));
+            ((TextView) accountTypeLayout.findViewById(R.id.account_type_name))
+                    .setText(accountType.getDisplayLabel(getContext()));
+
+            mEditors.addView(nameView);
+            return;
+        }
+
         // Structured name
         final StructuredNameEditorView nameView = (StructuredNameEditorView) mLayoutInflater
                 .inflate(R.layout.structured_name_editor_view, mEditors, /* attachToRoot =*/ false);
@@ -263,15 +286,12 @@
         nameView.setValues(
                 accountType.getKindForMimetype(DataKind.PSEUDO_MIME_TYPE_DISPLAY_NAME),
                 valuesDelta, rawContactDelta, readOnly, mViewIdGenerator);
-        if (readOnly) nameView.setAccountType(accountType);
 
         // Correct start margin since there is a second icon in the structured name layout
         nameView.findViewById(R.id.kind_icon).setVisibility(View.GONE);
         mEditors.addView(nameView);
 
         // Phonetic name
-        if (readOnly) return;
-
         final PhoneticNameEditorView phoneticNameView = (PhoneticNameEditorView) mLayoutInflater
                 .inflate(R.layout.phonetic_name_editor_view, mEditors, /* attachToRoot =*/ false);
         phoneticNameView.setEditorListener(new OtherNameKindEditorListener());
@@ -378,6 +398,7 @@
 
         for (int i = 0; i < mEditors.getChildCount(); i++) {
             final View view = mEditors.getChildAt(i);
+            if (!(view instanceof Editor)) continue; // Skip read-only names
             final Editor editor = (Editor) view;
             if (view instanceof StructuredNameEditorView) {
                 // We always show one empty structured name view