Move the group icon to the right hand side.

Change-Id: Ic9096b01ccda99372f96b5156260c71b6dfb1cda
diff --git a/res/layout/call_log_action_call.xml b/res/layout/call_log_action_call.xml
new file mode 100644
index 0000000..53c343c
--- /dev/null
+++ b/res/layout/call_log_action_call.xml
@@ -0,0 +1,41 @@
+<?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.
+-->
+
+<merge xmlns:android="http://schemas.android.com/apk/res/android">
+
+    <ImageView
+        android:id="@+id/call_icon"
+        android:layout_width="wrap_content"
+        android:layout_height="match_parent"
+        android:paddingLeft="14dip"
+        android:paddingRight="14dip"
+        android:layout_alignParentRight="true"
+        android:gravity="center_vertical"
+        android:background="@drawable/call_background"
+        android:src="@android:drawable/sym_action_call"
+    />
+
+    <View android:id="@+id/divider"
+        android:layout_width="1px"
+        android:layout_height="match_parent"
+        android:layout_marginTop="5dip"
+        android:layout_marginBottom="5dip"
+        android:layout_toLeftOf="@id/call_icon"
+        android:layout_marginLeft="11dip"
+        android:background="@drawable/divider_vertical_dark"
+    />
+
+</merge>
diff --git a/res/layout/call_log_action_group.xml b/res/layout/call_log_action_group.xml
new file mode 100644
index 0000000..0b130b6
--- /dev/null
+++ b/res/layout/call_log_action_group.xml
@@ -0,0 +1,41 @@
+<?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.
+-->
+
+<merge xmlns:android="http://schemas.android.com/apk/res/android">
+
+    <ImageView
+        android:id="@+id/groupIndicator"
+        android:layout_width="wrap_content"
+        android:layout_height="match_parent"
+        android:paddingLeft="12dip"
+        android:paddingRight="13dip"
+        android:layout_alignParentRight="true"
+        android:gravity="center_vertical"
+        android:background="@drawable/call_background"
+        android:src="@*android:drawable/expander_ic_minimized"
+    />
+
+    <View android:id="@+id/divider"
+        android:layout_width="1px"
+        android:layout_height="match_parent"
+        android:layout_marginTop="5dip"
+        android:layout_marginBottom="5dip"
+        android:layout_toLeftOf="@id/groupIndicator"
+        android:layout_marginLeft="11dip"
+        android:background="@drawable/divider_vertical_dark"
+    />
+
+</merge>
diff --git a/res/layout/call_log_list_child_item.xml b/res/layout/call_log_list_child_item.xml
index bb48fcf..68e1360 100644
--- a/res/layout/call_log_list_child_item.xml
+++ b/res/layout/call_log_list_child_item.xml
@@ -21,18 +21,7 @@
     android:background="@drawable/list_item_background_secondary"
 >
 
-    <ImageView android:id="@+id/call_icon"
-        android:layout_width="wrap_content"
-        android:layout_height="match_parent"
-        android:paddingLeft="14dip"
-        android:paddingRight="14dip"
-        android:layout_alignParentRight="true"
-
-        android:gravity="center_vertical"
-        android:src="@android:drawable/sym_action_call"
-        android:background="@drawable/call_background_secondary"
-    />
-
+    <include layout="@layout/call_log_action_call"/>
     <include layout="@layout/call_log_list_item_layout"/>
 
 </RelativeLayout>
diff --git a/res/layout/call_log_list_group_item.xml b/res/layout/call_log_list_group_item.xml
index 79423fa..d1bd165 100644
--- a/res/layout/call_log_list_group_item.xml
+++ b/res/layout/call_log_list_group_item.xml
@@ -20,27 +20,7 @@
     android:paddingLeft="7dip"
 >
 
-    <ImageView android:id="@+id/call_icon"
-        android:layout_width="wrap_content"
-        android:layout_height="match_parent"
-        android:paddingLeft="14dip"
-        android:paddingRight="14dip"
-        android:layout_alignParentRight="true"
-
-        android:gravity="center_vertical"
-        android:src="@android:drawable/sym_action_call"
-        android:background="@drawable/call_background"
-    />
-
-    <View android:id="@+id/divider"
-        android:layout_width="1px"
-        android:layout_height="match_parent"
-        android:layout_marginTop="5dip"
-        android:layout_marginBottom="5dip"
-        android:layout_toLeftOf="@id/call_icon"
-        android:layout_marginLeft="11dip"
-        android:background="@drawable/divider_vertical_dark"
-    />
+    <include layout="@layout/call_log_action_group"/>
 
     <TextView android:id="@+id/date"
         android:layout_width="wrap_content"
@@ -112,14 +92,4 @@
         android:ellipsize="marquee"
         android:gravity="center_vertical"
     />
-
-    <ImageView
-        android:id="@+id/groupIndicator"
-        android:layout_width="wrap_content"
-        android:layout_height="wrap_content"
-        android:layout_alignParentLeft="true"
-        android:layout_centerVertical="true"
-        android:src="@*android:drawable/expander_ic_minimized"
-        android:gravity="center_vertical"
-    />
 </RelativeLayout>
diff --git a/res/layout/call_log_list_item.xml b/res/layout/call_log_list_item.xml
index 4ea0563..10e09a4 100644
--- a/res/layout/call_log_list_item.xml
+++ b/res/layout/call_log_list_item.xml
@@ -20,18 +20,7 @@
     android:paddingLeft="7dip"
 >
 
-    <ImageView android:id="@+id/call_icon"
-        android:layout_width="wrap_content"
-        android:layout_height="match_parent"
-        android:paddingLeft="14dip"
-        android:paddingRight="14dip"
-        android:layout_alignParentRight="true"
-
-        android:gravity="center_vertical"
-        android:src="@android:drawable/sym_action_call"
-        android:background="@drawable/call_background"
-    />
-
+    <include layout="@layout/call_log_action_call"/>
     <include layout="@layout/call_log_list_item_layout"/>
 
 </RelativeLayout>
diff --git a/res/layout/call_log_list_item_layout.xml b/res/layout/call_log_list_item_layout.xml
index faaa893..8096ee6 100644
--- a/res/layout/call_log_list_item_layout.xml
+++ b/res/layout/call_log_list_item_layout.xml
@@ -16,16 +16,6 @@
 
 <merge xmlns:android="http://schemas.android.com/apk/res/android">
 
-    <View android:id="@+id/divider"
-        android:layout_width="1px"
-        android:layout_height="match_parent"
-        android:layout_marginTop="5dip"
-        android:layout_marginBottom="5dip"
-        android:layout_toLeftOf="@id/call_icon"
-        android:layout_marginLeft="11dip"
-        android:background="@drawable/divider_vertical_dark"
-    />
-
     <ImageView android:id="@+id/call_type_icon"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
diff --git a/src/com/android/contacts/calllog/CallLogFragment.java b/src/com/android/contacts/calllog/CallLogFragment.java
index 5872043..360f5a6 100644
--- a/src/com/android/contacts/calllog/CallLogFragment.java
+++ b/src/com/android/contacts/calllog/CallLogFragment.java
@@ -21,6 +21,7 @@
 import com.android.contacts.ContactsUtils;
 import com.android.contacts.R;
 import com.android.internal.telephony.CallerInfo;
+import com.google.common.annotations.VisibleForTesting;
 
 import android.app.ListFragment;
 import android.content.AsyncQueryHandler;
@@ -155,8 +156,14 @@
         public TextView numberView;
         public TextView dateView;
         public ImageView iconView;
+        /** The icon used to place a call to the contact. Only present for non-group entries. */
         public View callView;
+        /** The icon used to expand and collapse an entry. Only present for group entries. */
         public ImageView groupIndicator;
+        /**
+         * The text view containing the number of items in the group. Only present for group
+         * entries.
+         */
         public TextView groupSize;
     }
 
@@ -540,6 +547,7 @@
         }
 
 
+        @VisibleForTesting
         @Override
         public View newStandAloneView(Context context, ViewGroup parent) {
             LayoutInflater inflater =
@@ -549,13 +557,15 @@
             return view;
         }
 
+        @VisibleForTesting
         @Override
         public void bindStandAloneView(View view, Context context, Cursor cursor) {
             bindView(context, view, cursor);
         }
 
+        @VisibleForTesting
         @Override
-        protected View newChildView(Context context, ViewGroup parent) {
+        public View newChildView(Context context, ViewGroup parent) {
             LayoutInflater inflater =
                     (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
             View view = inflater.inflate(R.layout.call_log_list_child_item, parent, false);
@@ -563,13 +573,15 @@
             return view;
         }
 
+        @VisibleForTesting
         @Override
-        protected void bindChildView(View view, Context context, Cursor cursor) {
+        public void bindChildView(View view, Context context, Cursor cursor) {
             bindView(context, view, cursor);
         }
 
+        @VisibleForTesting
         @Override
-        protected View newGroupView(Context context, ViewGroup parent) {
+        public View newGroupView(Context context, ViewGroup parent) {
             LayoutInflater inflater =
                     (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
             View view = inflater.inflate(R.layout.call_log_list_group_item, parent, false);
@@ -577,8 +589,9 @@
             return view;
         }
 
+        @VisibleForTesting
         @Override
-        protected void bindGroupView(View view, Context context, Cursor cursor, int groupSize,
+        public void bindGroupView(View view, Context context, Cursor cursor, int groupSize,
                 boolean expanded) {
             final CallLogListItemViews views = (CallLogListItemViews) view.getTag();
             int groupIndicator = expanded
@@ -599,7 +612,9 @@
             views.dateView = (TextView) view.findViewById(R.id.date);
             views.iconView = (ImageView) view.findViewById(R.id.call_type_icon);
             views.callView = view.findViewById(R.id.call_icon);
-            views.callView.setOnClickListener(this);
+            if (views.callView != null) {
+                views.callView.setOnClickListener(this);
+            }
             views.groupIndicator = (ImageView) view.findViewById(R.id.groupIndicator);
             views.groupSize = (TextView) view.findViewById(R.id.groupSize);
             view.setTag(views);
@@ -615,7 +630,9 @@
             String callerNumberLabel = c.getString(CallLogQuery.CALLER_NUMBERLABEL);
             String countryIso = c.getString(CallLogQuery.COUNTRY_ISO);
             // Store away the number so we can call it directly if you click on the call icon
-            views.callView.setTag(number);
+            if (views.callView != null) {
+                views.callView.setTag(number);
+            }
 
             // Lookup contacts with this number
             ContactInfo info = mContactInfo.get(number);
@@ -663,7 +680,9 @@
             // Set the text lines and call icon.
             // Assumes the call back feature is on most of the
             // time. For private and unknown numbers: hide it.
-            views.callView.setVisibility(View.VISIBLE);
+            if (views.callView != null) {
+                views.callView.setVisibility(View.VISIBLE);
+            }
 
             if (!TextUtils.isEmpty(name)) {
                 views.line1View.setText(name);
@@ -711,10 +730,14 @@
             } else {
                 if (number.equals(CallerInfo.UNKNOWN_NUMBER)) {
                     number = getString(R.string.unknown);
-                    views.callView.setVisibility(View.INVISIBLE);
+                    if (views.callView != null) {
+                        views.callView.setVisibility(View.INVISIBLE);
+                    }
                 } else if (number.equals(CallerInfo.PRIVATE_NUMBER)) {
                     number = getString(R.string.private_num);
-                    views.callView.setVisibility(View.INVISIBLE);
+                    if (views.callView != null) {
+                        views.callView.setVisibility(View.INVISIBLE);
+                    }
                 } else if (number.equals(CallerInfo.PAYPHONE_NUMBER)) {
                     number = getString(R.string.payphone);
                 } else if (PhoneNumberUtils.extractNetworkPortion(number)
diff --git a/tests/src/com/android/contacts/activities/CallLogActivityTests.java b/tests/src/com/android/contacts/activities/CallLogActivityTests.java
index ef1afd0..eb0ec73 100644
--- a/tests/src/com/android/contacts/activities/CallLogActivityTests.java
+++ b/tests/src/com/android/contacts/activities/CallLogActivityTests.java
@@ -16,6 +16,7 @@
 
 package com.android.contacts.activities;
 
+import com.android.contacts.R;
 import com.android.contacts.calllog.CallLogFragment;
 import com.android.internal.telephony.CallerInfo;
 
@@ -138,6 +139,38 @@
         checkCallStatus();
     }
 
+    @MediumTest
+    public void testCallAndGroupViews_GroupView() {
+        mCursor.moveToFirst();
+        insert(CallerInfo.PRIVATE_NUMBER, NOW, 0, Calls.INCOMING_TYPE);
+        insert(CallerInfo.PRIVATE_NUMBER, NOW, 0, Calls.INCOMING_TYPE);
+        insert(CallerInfo.PRIVATE_NUMBER, NOW, 0, Calls.INCOMING_TYPE);
+        View view = mAdapter.newGroupView(getActivity(), mParentView);
+        mAdapter.bindGroupView(view, getActivity(), mCursor, 3, false);
+        assertNull(view.findViewById(R.id.call_icon));
+        assertNotNull(view.findViewById(R.id.groupIndicator));
+    }
+
+    @MediumTest
+    public void testCallAndGroupViews_StandAloneView() {
+        mCursor.moveToFirst();
+        insert(CallerInfo.PRIVATE_NUMBER, NOW, 0, Calls.INCOMING_TYPE);
+        View view = mAdapter.newStandAloneView(getActivity(), mParentView);
+        mAdapter.bindStandAloneView(view, getActivity(), mCursor);
+        assertNotNull(view.findViewById(R.id.call_icon));
+        assertNull(view.findViewById(R.id.groupIndicator));
+    }
+
+    @MediumTest
+    public void testCallAndGroupViews_ChildView() {
+        mCursor.moveToFirst();
+        insert(CallerInfo.PRIVATE_NUMBER, NOW, 0, Calls.INCOMING_TYPE);
+        View view = mAdapter.newChildView(getActivity(), mParentView);
+        mAdapter.bindChildView(view, getActivity(), mCursor);
+        assertNotNull(view.findViewById(R.id.call_icon));
+        assertNull(view.findViewById(R.id.groupIndicator));
+    }
+
     //
     // HELPERS to check conditions on the DB/views
     //
@@ -273,6 +306,8 @@
         row.add(number);
         if (NOW == date) {
             row.add(new Date().getTime());
+        } else {
+            row.add(date);
         }
         if (duration < 0) {
             duration = mRnd.nextInt(10 * 60);  // 0 - 10 minutes random.