Make update items/photos highlight when they're clickable

- Highlighting used to work not because "stream_item_content" had the proper
background but because it was the default behavior for ListView items.

- Implement StreamItemAdapter.isEnabled() and make all list items disabled,
so they don't highlight when not necessary. i.e. when items don't have a
click listener set.

- Instead set a click listener to the "stream_item_content" view.

- And change the background to "?android:attr/selectableItemBackground",
which is the default background for list items.

- Also make photo views highlightable when they're clickable.

Bug 5180619

Change-Id: I06bff9d1a0e5385fa66edd4577ddefb43587621c
diff --git a/res/layout/stream_item_container.xml b/res/layout/stream_item_container.xml
index 1f96aad..a88dd9a 100644
--- a/res/layout/stream_item_container.xml
+++ b/res/layout/stream_item_container.xml
@@ -27,7 +27,7 @@
         android:paddingBottom="@dimen/detail_update_section_item_last_row_extra_vertical_padding"
         android:paddingLeft="@dimen/detail_update_section_item_horizontal_padding"
         android:paddingRight="@dimen/detail_update_section_item_horizontal_padding"
-        android:background="@drawable/list_selector"
+        android:background="?android:attr/selectableItemBackground"
         />
 
     <View
diff --git a/res/layout/stream_item_photo.xml b/res/layout/stream_item_photo.xml
new file mode 100644
index 0000000..1fc3d0b
--- /dev/null
+++ b/res/layout/stream_item_photo.xml
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2011 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">
+    <ImageView
+        android:id="@+id/image"
+        android:layout_width="match_parent"
+        android:layout_height="match_parent"/>
+    <View
+        android:id="@+id/push_layer"
+        android:layout_width="match_parent"
+        android:layout_height="match_parent"
+        android:background="?android:attr/selectableItemBackground"/>
+</FrameLayout>
diff --git a/res/layout/stream_item_row_image_and_text.xml b/res/layout/stream_item_row_image_and_text.xml
index b6f6599..8c67ce1 100644
--- a/res/layout/stream_item_row_image_and_text.xml
+++ b/res/layout/stream_item_row_image_and_text.xml
@@ -27,8 +27,9 @@
         android:layout_weight="1"
         ex:ratio="1"
         ex:direction="widthToHeight">
-        <ImageView
+        <include
             android:id="@+id/stream_item_first_image"
+            layout="@layout/stream_item_photo"
             android:layout_width="match_parent"
             android:layout_height="match_parent"/>
     </view>
diff --git a/res/layout/stream_item_row_two_images.xml b/res/layout/stream_item_row_two_images.xml
index 6e34b25..f127129 100644
--- a/res/layout/stream_item_row_two_images.xml
+++ b/res/layout/stream_item_row_two_images.xml
@@ -27,8 +27,9 @@
         android:layout_weight="1"
         ex:ratio="1"
         ex:direction="widthToHeight">
-        <ImageView
+        <include
             android:id="@+id/stream_item_first_image"
+            layout="@layout/stream_item_photo"
             android:layout_width="match_parent"
             android:layout_height="match_parent"/>
     </view>
@@ -40,8 +41,9 @@
         android:layout_weight="1"
         ex:ratio="1"
         ex:direction="widthToHeight">
-        <ImageView
+        <include
             android:id="@+id/stream_item_second_image"
+            layout="@layout/stream_item_photo"
             android:layout_width="match_parent"
             android:layout_height="match_parent"/>
     </view>
diff --git a/src/com/android/contacts/detail/ContactDetailDisplayUtils.java b/src/com/android/contacts/detail/ContactDetailDisplayUtils.java
index 18a4750..86cb7fa 100644
--- a/src/com/android/contacts/detail/ContactDetailDisplayUtils.java
+++ b/src/com/android/contacts/detail/ContactDetailDisplayUtils.java
@@ -319,16 +319,21 @@
     private static void loadPhoto(ContactPhotoManager contactPhotoManager,
             final StreamItemEntry streamItem, final StreamItemPhotoEntry streamItemPhoto,
             View photoContainer, int imageViewId, View.OnClickListener photoClickListener) {
-        ImageView imageView = (ImageView) photoContainer.findViewById(imageViewId);
+        final View frame = photoContainer.findViewById(imageViewId);
+        final View pushLayerView = frame.findViewById(R.id.push_layer);
+        final ImageView imageView = (ImageView) frame.findViewById(R.id.image);
         if (photoClickListener != null) {
-            imageView.setOnClickListener(photoClickListener);
-            imageView.setTag(new StreamPhotoTag(streamItem, streamItemPhoto));
-            imageView.setFocusable(true);
+            pushLayerView.setOnClickListener(photoClickListener);
+            pushLayerView.setTag(new StreamPhotoTag(streamItem, streamItemPhoto));
+            pushLayerView.setFocusable(true);
+            pushLayerView.setEnabled(true);
         } else {
-            imageView.setOnClickListener(null);
-            imageView.setTag(null);
-            imageView.setFocusable(false);
-            imageView.setClickable(false); // setOnClickListener makes it clickable, so overwrite it
+            pushLayerView.setOnClickListener(null);
+            pushLayerView.setTag(null);
+            pushLayerView.setFocusable(false);
+            // setOnClickListener makes it clickable, so we need to overwrite it
+            pushLayerView.setClickable(false);
+            pushLayerView.setEnabled(false);
         }
         contactPhotoManager.loadPhoto(imageView, Uri.parse(streamItemPhoto.getPhotoUri()));
     }
diff --git a/src/com/android/contacts/detail/StreamItemAdapter.java b/src/com/android/contacts/detail/StreamItemAdapter.java
index 9094c5c..074db80 100644
--- a/src/com/android/contacts/detail/StreamItemAdapter.java
+++ b/src/com/android/contacts/detail/StreamItemAdapter.java
@@ -79,6 +79,20 @@
     }
 
     @Override
+    public boolean isEnabled(int position) {
+        // Make all list items disabled, so they're not clickable.
+        // We make child views clickable in getvView() if the account type supports
+        // viewStreamItemActivity or viewStreamItemPhotoActivity.
+        return false;
+    }
+
+    @Override
+    public boolean areAllItemsEnabled() {
+        // See isEnabled().
+        return false;
+    }
+
+    @Override
     public View getView(int position, View convertView, ViewGroup parent) {
         if (position == 0) {
             return mInflater.inflate(R.layout.updates_header_contact, null);
@@ -90,19 +104,29 @@
         final AccountTypeManager manager = AccountTypeManager.getInstance(mContext);
         final AccountType accountType =
                 manager.getAccountType(streamItem.getAccountType(), streamItem.getDataSet());
+
         final View view = ContactDetailDisplayUtils.createStreamItemView(
                 mInflater, mContext, streamItem, null,
+                // Only pass the photo click listener if the account type has the photo
+                // view activity.
                 (accountType.getViewStreamItemPhotoActivity() == null) ? null : mPhotoClickListener
                 );
+        final View contentView = view.findViewById(R.id.stream_item_content);
+
+        // If the account type has the stream item view activity, make the stream container
+        // clickable.
         if (accountType.getViewStreamItemActivity() != null) {
-            view.setTag(streamItem);
-            view.setFocusable(true);
-            view.setOnClickListener(mItemClickListener);
+            contentView.setTag(streamItem);
+            contentView.setFocusable(true);
+            contentView.setOnClickListener(mItemClickListener);
+            contentView.setEnabled(true);
         } else {
-            view.setTag(null);
-            view.setFocusable(false);
-            view.setOnClickListener(null);
-            view.setClickable(false); // setOnClickListener makes it clickable, so overwrite it
+            contentView.setTag(null);
+            contentView.setFocusable(false);
+            contentView.setOnClickListener(null);
+            // setOnClickListener makes it clickable, so we need to overwrite it.
+            contentView.setClickable(false);
+            contentView.setEnabled(false);
         }
         return view;
     }