Disable network connection title

In contact details, the name of a particular network
connection has been made to show in secondary text
color and unselectable.

Bug: 6000520
Change-Id: I89d84ad64ad827ce820c854715ca34175e3c7813
diff --git a/res/layout/contact_detail_add_connection_entry_view.xml b/res/layout/contact_detail_add_connection_entry_view.xml
new file mode 100644
index 0000000..208a8d4
--- /dev/null
+++ b/res/layout/contact_detail_add_connection_entry_view.xml
@@ -0,0 +1,54 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/*
+ * Copyright 2012, 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.
+ */
+-->
+
+<FrameLayout
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="match_parent"
+    android:layout_height="wrap_content"
+    android:paddingLeft="@dimen/detail_item_side_margin"
+    android:paddingRight="@dimen/detail_item_side_margin">
+    <LinearLayout
+        android:id="@+id/primary_action_view"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:paddingTop="@dimen/detail_item_vertical_margin"
+        android:paddingBottom="@dimen/detail_item_vertical_margin"
+        android:focusable="true"
+        android:background="?android:attr/selectableItemBackground"
+        android:minHeight="@dimen/detail_min_line_item_height"
+        android:orientation="horizontal"
+        android:gravity="center_vertical">
+
+        <ImageView
+            android:id="@+id/add_connection_icon"
+            android:layout_width="@dimen/detail_network_icon_size"
+            android:layout_height="@dimen/detail_network_icon_size"
+            android:layout_marginLeft="@dimen/detail_item_icon_margin"
+            android:layout_marginRight="@dimen/detail_item_icon_margin"
+            android:layout_gravity="center_vertical"
+            android:scaleType="centerInside" />
+
+        <TextView
+            android:id="@+id/add_connection_label"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_gravity="center_vertical"
+            android:textAppearance="?android:attr/textAppearanceMedium"/>
+    </LinearLayout>
+</FrameLayout>
diff --git a/res/layout/contact_detail_network_title_entry_view.xml b/res/layout/contact_detail_network_title_entry_view.xml
index 1907a7a..09b8b34 100644
--- a/res/layout/contact_detail_network_title_entry_view.xml
+++ b/res/layout/contact_detail_network_title_entry_view.xml
@@ -49,6 +49,7 @@
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:layout_gravity="center_vertical"
-            android:textAppearance="?android:attr/textAppearanceMedium" />
+            android:textAppearance="?android:attr/textAppearanceMedium"
+            android:textColor="?android:attr/textColorSecondary" />
     </LinearLayout>
 </FrameLayout>
diff --git a/src/com/android/contacts/detail/ContactDetailFragment.java b/src/com/android/contacts/detail/ContactDetailFragment.java
index 197ba4f..f180c1b 100644
--- a/src/com/android/contacts/detail/ContactDetailFragment.java
+++ b/src/com/android/contacts/detail/ContactDetailFragment.java
@@ -811,7 +811,7 @@
         for (AccountType accountType : mOtherEntriesMap.keySet()) {
 
             // Add a title for each third party app
-            mAllEntries.add(NetworkTitleViewEntry.fromAccountType(mContext, accountType));
+            mAllEntries.add(new NetworkTitleViewEntry(mContext, accountType));
 
             for (DetailViewEntry detailEntry : mOtherEntriesMap.get(accountType)) {
                 // Add indented separator
@@ -867,7 +867,7 @@
         };
 
         // Finally create the entry.
-        mAllEntries.add(NetworkTitleViewEntry.forMoreNetworks(mContext, onClickListener));
+        mAllEntries.add(new AddConnectionViewEntry(mContext, onClickListener));
     }
 
     /**
@@ -1124,35 +1124,43 @@
     }
 
     /**
-     * A title for a section of contact details from a single 3rd party network.  It's also
-     * used for the "More networks" entry, which has the same layout.
+     * A title for a section of contact details from a single 3rd party network.
      */
     private static class NetworkTitleViewEntry extends ViewEntry {
         private final Drawable mIcon;
         private final CharSequence mLabel;
-        private final View.OnClickListener mOnClickListener;
 
-        private NetworkTitleViewEntry(Drawable icon, CharSequence label, View.OnClickListener
-                onClickListener) {
+        public NetworkTitleViewEntry(Context context, AccountType type) {
             super(ViewAdapter.VIEW_TYPE_NETWORK_TITLE_ENTRY);
-            this.mIcon = icon;
-            this.mLabel = label;
-            this.mOnClickListener = onClickListener;
+            this.mIcon = type.getDisplayIcon(context);
+            this.mLabel = type.getDisplayLabel(context);
             this.isEnabled = false;
         }
 
-        public static NetworkTitleViewEntry fromAccountType(Context context, AccountType type) {
-            return new NetworkTitleViewEntry(
-                    type.getDisplayIcon(context), type.getDisplayLabel(context), null);
+        public Drawable getIcon() {
+            return mIcon;
         }
 
-        public static NetworkTitleViewEntry forMoreNetworks(Context context, View.OnClickListener
-                onClickListener) {
-            // TODO Icon is temporary.  Need proper one.
-            return new NetworkTitleViewEntry(
-                    context.getResources().getDrawable(R.drawable.ic_menu_add_field_holo_light),
-                    context.getString(R.string.add_connection_button),
-                    onClickListener);
+        public CharSequence getLabel() {
+            return mLabel;
+        }
+    }
+
+    /**
+     * This is used for the "Add Connections" entry.
+     */
+    private static class AddConnectionViewEntry extends ViewEntry {
+        private final Drawable mIcon;
+        private final CharSequence mLabel;
+        private final View.OnClickListener mOnClickListener;
+
+        private AddConnectionViewEntry(Context context, View.OnClickListener onClickListener) {
+            super(ViewAdapter.VIEW_TYPE_ADD_CONNECTION_ENTRY);
+            this.mIcon = context.getResources().getDrawable(
+                    R.drawable.ic_menu_add_field_holo_light);
+            this.mLabel = context.getString(R.string.add_connection_button);
+            this.mOnClickListener = onClickListener;
+            this.isEnabled = true;
         }
 
         @Override
@@ -1349,6 +1357,14 @@
         }
     }
 
+    private static class KindTitleViewCache {
+        public final TextView titleView;
+
+        public KindTitleViewCache(View view) {
+            titleView = (TextView)view.findViewById(R.id.title);
+        }
+    }
+
     /**
      * Cache of the children views for a view that displays a {@link NetworkTitleViewEntry}
      */
@@ -1363,6 +1379,21 @@
     }
 
     /**
+     * Cache of the children views for a view that displays a {@link AddConnectionViewEntry}
+     */
+    private static class AddConnectionViewCache {
+        public final TextView name;
+        public final ImageView icon;
+        public final View primaryActionView;
+
+        public AddConnectionViewCache(View view) {
+            name = (TextView) view.findViewById(R.id.add_connection_label);
+            icon = (ImageView) view.findViewById(R.id.add_connection_icon);
+            primaryActionView = view.findViewById(R.id.primary_action_view);
+        }
+    }
+
+    /**
      * Cache of the children views of a contact detail entry represented by a
      * {@link DetailViewEntry}
      */
@@ -1406,8 +1437,9 @@
         public static final int VIEW_TYPE_HEADER_ENTRY = 1;
         public static final int VIEW_TYPE_KIND_TITLE_ENTRY = 2;
         public static final int VIEW_TYPE_NETWORK_TITLE_ENTRY = 3;
-        public static final int VIEW_TYPE_SEPARATOR_ENTRY = 4;
-        private static final int VIEW_TYPE_COUNT = 5;
+        public static final int VIEW_TYPE_ADD_CONNECTION_ENTRY = 4;
+        public static final int VIEW_TYPE_SEPARATOR_ENTRY = 5;
+        private static final int VIEW_TYPE_COUNT = 6;
 
         @Override
         public View getView(int position, View convertView, ViewGroup parent) {
@@ -1422,6 +1454,8 @@
                     return getDetailEntryView(position, convertView, parent);
                 case VIEW_TYPE_NETWORK_TITLE_ENTRY:
                     return getNetworkTitleEntryView(position, convertView, parent);
+                case VIEW_TYPE_ADD_CONNECTION_ENTRY:
+                    return getAddConnectionEntryView(position, convertView, parent);
                 default:
                     throw new IllegalStateException("Invalid view type ID " +
                             getItemViewType(position));
@@ -1519,11 +1553,19 @@
 
         private View getKindTitleEntryView(int position, View convertView, ViewGroup parent) {
             final KindTitleViewEntry entry = (KindTitleViewEntry) getItem(position);
+            final View result;
+            final KindTitleViewCache viewCache;
 
-            final View result = (convertView != null) ? convertView :
-                    mInflater.inflate(R.layout.list_separator, parent, false);
-            final TextView titleTextView = (TextView) result.findViewById(R.id.title);
-            titleTextView.setText(entry.getTitle());
+            if (convertView != null) {
+                result = convertView;
+                viewCache = (KindTitleViewCache)result.getTag();
+            } else {
+                result = mInflater.inflate(R.layout.list_separator, parent, false);
+                viewCache = new KindTitleViewCache(result);
+                result.setTag(viewCache);
+            }
+
+            viewCache.titleView.setText(entry.getTitle());
 
             return result;
         }
@@ -1541,8 +1583,6 @@
                         parent, false);
                 viewCache = new NetworkTitleViewCache(result);
                 result.setTag(viewCache);
-                result.findViewById(R.id.primary_action_view).setOnClickListener(
-                        entry.mOnClickListener);
             }
 
             viewCache.name.setText(entry.getLabel());
@@ -1551,6 +1591,27 @@
             return result;
         }
 
+        private View getAddConnectionEntryView(int position, View convertView, ViewGroup parent) {
+            final AddConnectionViewEntry entry = (AddConnectionViewEntry) getItem(position);
+            final View result;
+            final AddConnectionViewCache viewCache;
+
+            if (convertView != null) {
+                result = convertView;
+                viewCache = (AddConnectionViewCache) result.getTag();
+            } else {
+                result = mInflater.inflate(R.layout.contact_detail_add_connection_entry_view,
+                        parent, false);
+                viewCache = new AddConnectionViewCache(result);
+                result.setTag(viewCache);
+            }
+            viewCache.name.setText(entry.getLabel());
+            viewCache.icon.setImageDrawable(entry.getIcon());
+            viewCache.primaryActionView.setOnClickListener(entry.mOnClickListener);
+
+            return result;
+        }
+
         private View getDetailEntryView(int position, View convertView, ViewGroup parent) {
             final DetailViewEntry entry = (DetailViewEntry) getItem(position);
             final View v;