Merge "Fix possible NPE on People" into ics-mr1
diff --git a/res/layout-sw580dp/detail_header_contact_with_updates.xml b/res/layout-sw580dp/detail_header_contact_with_updates.xml
index fa6f301..43cf4c0 100644
--- a/res/layout-sw580dp/detail_header_contact_with_updates.xml
+++ b/res/layout-sw580dp/detail_header_contact_with_updates.xml
@@ -56,6 +56,7 @@
             android:layout_width="0dip"
             android:layout_height="wrap_content"
             android:layout_weight="1"
+            android:paddingLeft="8dip"
             android:paddingRight="24dip"
             android:textAppearance="?android:attr/textAppearanceLarge"
             android:textSize="@dimen/detail_header_name_text_size" />
@@ -69,6 +70,7 @@
         android:id="@+id/company"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
+        android:paddingLeft="8dip"
         android:textAppearance="?android:attr/textAppearanceMedium"
         android:textColor="?android:attr/textColorSecondary" />
 
diff --git a/res/layout-sw580dp/detail_header_contact_without_updates.xml b/res/layout-sw580dp/detail_header_contact_without_updates.xml
index a55764d..9261f11 100644
--- a/res/layout-sw580dp/detail_header_contact_without_updates.xml
+++ b/res/layout-sw580dp/detail_header_contact_without_updates.xml
@@ -24,7 +24,7 @@
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     android:orientation="vertical"
-    android:paddingBottom="8dip">
+    android:paddingBottom="16dip">
 
     <!-- Ensure that the contact photo for a contact WITHOUT social updates is the same width and
     height as a contact WITH social updates (where the photo is 2/3 of the screen width). -->
@@ -70,6 +70,7 @@
             android:layout_width="0dip"
             android:layout_height="wrap_content"
             android:layout_weight="1"
+            android:paddingLeft="8dip"
             android:paddingRight="24dip"
             android:textAppearance="?android:attr/textAppearanceLarge"
             android:textSize="@dimen/detail_header_name_text_size" />
@@ -83,6 +84,7 @@
         android:id="@+id/company"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
+        android:paddingLeft="8dip"
         android:textAppearance="?android:attr/textAppearanceMedium"
         android:textColor="?android:attr/textColorSecondary" />
 
diff --git a/res/layout-sw680dp-w1000dp/contact_detail_list_item.xml b/res/layout-sw680dp-w1000dp/contact_detail_list_item.xml
index ccecc35..98ffce6 100644
--- a/res/layout-sw680dp-w1000dp/contact_detail_list_item.xml
+++ b/res/layout-sw680dp-w1000dp/contact_detail_list_item.xml
@@ -65,6 +65,7 @@
             android:id="@+id/presence_icon"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
+            android:layout_marginTop="1dip"
             android:layout_marginRight="4dip"
             android:layout_gravity="center_vertical"
             android:scaleType="centerInside" />
diff --git a/res/layout-sw680dp-w1000dp/detail_header_contact_with_updates.xml b/res/layout-sw680dp-w1000dp/detail_header_contact_with_updates.xml
index b9a9dbd..dfba659 100644
--- a/res/layout-sw680dp-w1000dp/detail_header_contact_with_updates.xml
+++ b/res/layout-sw680dp-w1000dp/detail_header_contact_with_updates.xml
@@ -24,6 +24,7 @@
     xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
+    android:paddingBottom="8dip"
     android:orientation="horizontal">
 
     <ImageView
diff --git a/res/layout-sw680dp-w1000dp/detail_header_contact_without_updates.xml b/res/layout-sw680dp-w1000dp/detail_header_contact_without_updates.xml
index 6ef4651..f9dcf3d 100644
--- a/res/layout-sw680dp-w1000dp/detail_header_contact_without_updates.xml
+++ b/res/layout-sw680dp-w1000dp/detail_header_contact_without_updates.xml
@@ -23,6 +23,8 @@
     xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
+    android:paddingLeft="8dip"
+    android:paddingBottom="16dip"
     android:orientation="vertical">
 
     <LinearLayout
@@ -48,6 +50,7 @@
         android:id="@+id/company"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
+        android:paddingTop="16dip"
         android:textAppearance="?android:attr/textAppearanceMedium"
         android:textColor="?android:attr/textColorSecondary" />
 
diff --git a/res/layout/contact_detail_list_item.xml b/res/layout/contact_detail_list_item.xml
index a410dc9..44f5a53 100644
--- a/res/layout/contact_detail_list_item.xml
+++ b/res/layout/contact_detail_list_item.xml
@@ -60,6 +60,7 @@
                     android:id="@+id/presence_icon"
                     android:layout_width="wrap_content"
                     android:layout_height="wrap_content"
+                    android:layout_marginTop="1dip"
                     android:layout_marginRight="4dip"
                     android:layout_gravity="center_vertical"
                     android:gravity="center"
diff --git a/res/layout/group_browse_list_account_header.xml b/res/layout/group_browse_list_account_header.xml
index 36c6d7a..709c276 100644
--- a/res/layout/group_browse_list_account_header.xml
+++ b/res/layout/group_browse_list_account_header.xml
@@ -30,8 +30,9 @@
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:minHeight="?attr/list_item_header_height"
-        android:paddingLeft="?attr/list_item_padding_left"
-        android:paddingRight="?attr/list_item_padding_right"
+        android:layout_marginLeft="?attr/list_item_padding_left"
+        android:layout_marginRight="?attr/list_item_padding_right"
+        android:background="@drawable/list_section_divider_holo_custom"
         android:orientation="horizontal">
 
         <TextView
@@ -54,16 +55,10 @@
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:layout_gravity="center_vertical"
-            android:textAppearance="?android:attr/textAppearanceSmall"
             android:textColor="@color/contact_count_text_color"
             android:textSize="12sp"
             android:singleLine="true"
             android:ellipsize="middle" />
     </LinearLayout>
 
-    <View
-        android:layout_width="match_parent"
-        android:layout_height="1dip"
-        android:background="@color/people_app_theme_color" />
-
 </LinearLayout>
diff --git a/res/values-sw680dp/styles.xml b/res/values-sw680dp/styles.xml
index 0d750d7..b7a7700 100644
--- a/res/values-sw680dp/styles.xml
+++ b/res/values-sw680dp/styles.xml
@@ -22,7 +22,7 @@
         <item name="android:textColorPrimary">@color/primary_text_color</item>
         <item name="android:textColorSecondary">@color/secondary_text_color</item>
         <item name="android:listViewStyle">@style/ListViewStyle</item>
-        <item name="list_item_height">66dip</item>
+        <item name="list_item_height">?android:attr/listPreferredItemHeight</item>
         <item name="activated_background">@drawable/list_item_activated_background</item>
         <item name="section_header_background">@drawable/list_title_holo</item>
         <item name="list_item_divider">?android:attr/listDivider</item>
diff --git a/src/com/android/contacts/ContactsActivity.java b/src/com/android/contacts/ContactsActivity.java
index 020d135..371b0b7 100644
--- a/src/com/android/contacts/ContactsActivity.java
+++ b/src/com/android/contacts/ContactsActivity.java
@@ -17,8 +17,8 @@
 package com.android.contacts;
 
 import com.android.contacts.test.InjectedServices;
+import com.android.contacts.activities.TransactionSafeActivity;
 
-import android.app.Activity;
 import android.app.Fragment;
 import android.app.FragmentManager;
 import android.app.FragmentTransaction;
@@ -31,7 +31,7 @@
 /**
  * A common superclass for Contacts activities that handles application-wide services.
  */
-public abstract class ContactsActivity extends Activity
+public abstract class ContactsActivity extends TransactionSafeActivity
     implements ContactSaveService.Listener
 {
 
diff --git a/src/com/android/contacts/GroupMemberLoader.java b/src/com/android/contacts/GroupMemberLoader.java
index 9012362..7689f8a 100644
--- a/src/com/android/contacts/GroupMemberLoader.java
+++ b/src/com/android/contacts/GroupMemberLoader.java
@@ -15,7 +15,6 @@
  */
 package com.android.contacts;
 
-import com.android.contacts.list.ContactListAdapter;
 import com.android.contacts.preference.ContactsPreferences;
 
 import android.content.Context;
@@ -35,51 +34,63 @@
  */
 public final class GroupMemberLoader extends CursorLoader {
 
-    /**
-     * Projection map is taken from {@link ContactListAdapter}
-     */
-    private static final String[] PROJECTION_DATA = new String[] {
-        // TODO: Pull Projection_data out into util class
-        Data.CONTACT_ID,                        // 0
-        Data.RAW_CONTACT_ID,                    // 1
-        Data.DISPLAY_NAME_PRIMARY,              // 2
-        Data.DISPLAY_NAME_ALTERNATIVE,          // 3
-        Data.SORT_KEY_PRIMARY,                  // 4
-        Data.STARRED,                           // 5
-        Data.CONTACT_PRESENCE,                  // 6
-        Data.CONTACT_CHAT_CAPABILITY,           // 7
-        Data.PHOTO_ID,                          // 8
-        Data.PHOTO_URI,                         // 9
-        Data.PHOTO_THUMBNAIL_URI,               // 10
-        Data.LOOKUP_KEY,                        // 11
-        Data.PHONETIC_NAME,                     // 12
-        Data.HAS_PHONE_NUMBER,                  // 13
-        Data.CONTACT_STATUS,                    // 14
-    };
+    public static class GroupEditorQuery {
+        private static final String[] PROJECTION = new String[] {
+            Data.CONTACT_ID,                        // 0
+            Data.RAW_CONTACT_ID,                    // 1
+            Data.DISPLAY_NAME_PRIMARY,              // 2
+            Data.PHOTO_URI,                         // 3
+            Data.LOOKUP_KEY,                        // 4
+        };
+
+        public static final int CONTACT_ID                   = 0;
+        public static final int RAW_CONTACT_ID               = 1;
+        public static final int CONTACT_DISPLAY_NAME_PRIMARY = 2;
+        public static final int CONTACT_PHOTO_URI            = 3;
+        public static final int CONTACT_LOOKUP_KEY           = 4;
+    }
+
+    public static class GroupDetailQuery {
+        private static final String[] PROJECTION = new String[] {
+            Data.PHOTO_ID,                          // 0
+            Data.PHOTO_URI,                         // 1
+            Data.LOOKUP_KEY,                        // 2
+            Data.DISPLAY_NAME_PRIMARY,              // 3
+            Data.CONTACT_PRESENCE,                  // 4
+            Data.CONTACT_STATUS,                    // 5
+        };
+
+        public static final int CONTACT_PHOTO_ID             = 0;
+        public static final int CONTACT_PHOTO_URI            = 1;
+        public static final int CONTACT_LOOKUP_KEY           = 2;
+        public static final int CONTACT_DISPLAY_NAME_PRIMARY = 3;
+        public static final int CONTACT_PRESENCE_STATUS      = 4;
+        public static final int CONTACT_STATUS               = 5;
+    }
 
     private final long mGroupId;
 
-    public static final int CONTACT_ID_COLUMN_INDEX = 0;
-    public static final int RAW_CONTACT_ID_COLUMN_INDEX = 1;
-    public static final int CONTACT_DISPLAY_NAME_PRIMARY_COLUMN_INDEX = 2;
-    public static final int CONTACT_DISPLAY_NAME_ALTERNATIVE_COLUMN_INDEX = 3;
-    public static final int CONTACT_SORT_KEY_PRIMARY_COLUMN_INDEX = 4;
-    public static final int CONTACT_STARRED_COLUMN_INDEX = 5;
-    public static final int CONTACT_PRESENCE_STATUS_COLUMN_INDEX = 6;
-    public static final int CONTACT_CHAT_CAPABILITY_COLUMN_INDEX = 7;
-    public static final int CONTACT_PHOTO_ID_COLUMN_INDEX = 8;
-    public static final int CONTACT_PHOTO_URI_COLUMN_INDEX = 9;
-    public static final int CONTACT_PHOTO_THUMBNAIL_URI_COLUMN_INDEX = 10;
-    public static final int CONTACT_LOOKUP_KEY_COLUMN_INDEX = 11;
-    public static final int CONTACT_PHONETIC_NAME_COLUMN_INDEX = 12;
-    public static final int CONTACT_HAS_PHONE_COLUMN_INDEX = 13;
-    public static final int CONTACT_STATUS_COLUMN_INDEX = 14;
+    /**
+     * @return GroupMemberLoader object which can be used in group editor.
+     */
+    public static GroupMemberLoader constructLoaderForGroupEditorQuery(
+            Context context, long groupId) {
+        return new GroupMemberLoader(context, groupId, GroupEditorQuery.PROJECTION);
+    }
 
-    public GroupMemberLoader(Context context, long groupId) {
+    /**
+     * @return GroupMemberLoader object used in group detail page.
+     */
+    public static GroupMemberLoader constructLoaderForGroupDetailQuery(
+            Context context, long groupId) {
+        return new GroupMemberLoader(context, groupId, GroupDetailQuery.PROJECTION);
+    }
+
+    private GroupMemberLoader(Context context, long groupId, String[] projection) {
         super(context);
         mGroupId = groupId;
         setUri(createUri());
-        setProjection(PROJECTION_DATA);
+        setProjection(projection);
         setSelection(createSelection());
         setSelectionArgs(createSelectionArgs());
 
diff --git a/src/com/android/contacts/activities/DialtactsActivity.java b/src/com/android/contacts/activities/DialtactsActivity.java
index 1de7b76..6d99129 100644
--- a/src/com/android/contacts/activities/DialtactsActivity.java
+++ b/src/com/android/contacts/activities/DialtactsActivity.java
@@ -26,6 +26,7 @@
 import com.android.contacts.list.OnPhoneNumberPickerActionListener;
 import com.android.contacts.list.PhoneFavoriteFragment;
 import com.android.contacts.list.PhoneNumberPickerFragment;
+import com.android.contacts.activities.TransactionSafeActivity;
 import com.android.contacts.util.AccountFilterUtil;
 import com.android.internal.telephony.ITelephony;
 
@@ -74,7 +75,7 @@
  * embedded using intents.
  * The dialer tab's title is 'phone', a more common name (see strings.xml).
  */
-public class DialtactsActivity extends Activity {
+public class DialtactsActivity extends TransactionSafeActivity {
     private static final String TAG = "DialtactsActivity";
 
     /** Used to open Call Setting */
diff --git a/src/com/android/contacts/activities/TransactionSafeActivity.java b/src/com/android/contacts/activities/TransactionSafeActivity.java
new file mode 100644
index 0000000..ab80b42
--- /dev/null
+++ b/src/com/android/contacts/activities/TransactionSafeActivity.java
@@ -0,0 +1,65 @@
+/*
+ * 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.
+ */
+
+package com.android.contacts.activities;
+
+import android.app.Activity;
+import android.os.Bundle;
+
+/**
+ * A common superclass that keeps track of whether an {@link Activity} has saved its state yet or
+ * not.
+ */
+public class TransactionSafeActivity extends Activity {
+
+    private boolean mIsSafeToCommitTransactions;
+
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        mIsSafeToCommitTransactions = true;
+    }
+
+    @Override
+    protected void onStart() {
+        super.onStart();
+        mIsSafeToCommitTransactions = true;
+    }
+
+    @Override
+    protected void onResume() {
+        super.onResume();
+        mIsSafeToCommitTransactions = true;
+    }
+
+    @Override
+    protected void onSaveInstanceState(Bundle outState) {
+        super.onSaveInstanceState(outState);
+        mIsSafeToCommitTransactions = false;
+    }
+
+    /**
+     * Returns true if it is safe to commit {@link FragmentTransaction}s at this time, based on
+     * whether {@link Activity#onSaveInstanceState} has been called or not.
+     *
+     * Make sure that the current activity calls into
+     * {@link super.onSaveInstanceState(Bundle outState)} (if that method is overridden),
+     * so the flag is properly set.
+     */
+    public boolean isSafeToCommitTransactions() {
+        return mIsSafeToCommitTransactions;
+    }
+}
diff --git a/src/com/android/contacts/group/GroupDetailFragment.java b/src/com/android/contacts/group/GroupDetailFragment.java
index c856594..5b275bd 100644
--- a/src/com/android/contacts/group/GroupDetailFragment.java
+++ b/src/com/android/contacts/group/GroupDetailFragment.java
@@ -254,7 +254,7 @@
 
         @Override
         public CursorLoader onCreateLoader(int id, Bundle args) {
-            return new GroupMemberLoader(mContext, mGroupId);
+            return GroupMemberLoader.constructLoaderForGroupDetailQuery(mContext, mGroupId);
         }
 
         @Override
diff --git a/src/com/android/contacts/group/GroupEditorFragment.java b/src/com/android/contacts/group/GroupEditorFragment.java
index bb56b6e..a3ebeb0 100644
--- a/src/com/android/contacts/group/GroupEditorFragment.java
+++ b/src/com/android/contacts/group/GroupEditorFragment.java
@@ -19,6 +19,7 @@
 import com.android.contacts.ContactPhotoManager;
 import com.android.contacts.ContactSaveService;
 import com.android.contacts.GroupMemberLoader;
+import com.android.contacts.GroupMemberLoader.GroupEditorQuery;
 import com.android.contacts.GroupMetaDataLoader;
 import com.android.contacts.R;
 import com.android.contacts.activities.GroupEditorActivity;
@@ -781,7 +782,7 @@
 
         @Override
         public CursorLoader onCreateLoader(int id, Bundle args) {
-            return new GroupMemberLoader(mContext, mGroupId);
+            return GroupMemberLoader.constructLoaderForGroupEditorQuery(mContext, mGroupId);
         }
 
         @Override
@@ -789,14 +790,11 @@
             List<Member> listExistingMembers = new ArrayList<Member>();
             data.moveToPosition(-1);
             while (data.moveToNext()) {
-                long contactId = data.getLong(GroupMemberLoader.CONTACT_ID_COLUMN_INDEX);
-                long rawContactId = data.getLong(GroupMemberLoader.RAW_CONTACT_ID_COLUMN_INDEX);
-                String lookupKey = data.getString(
-                        GroupMemberLoader.CONTACT_LOOKUP_KEY_COLUMN_INDEX);
-                String displayName = data.getString(
-                        GroupMemberLoader.CONTACT_DISPLAY_NAME_PRIMARY_COLUMN_INDEX);
-                String photoUri = data.getString(
-                        GroupMemberLoader.CONTACT_PHOTO_URI_COLUMN_INDEX);
+                long contactId = data.getLong(GroupEditorQuery.CONTACT_ID);
+                long rawContactId = data.getLong(GroupEditorQuery.RAW_CONTACT_ID);
+                String lookupKey = data.getString(GroupEditorQuery.CONTACT_LOOKUP_KEY);
+                String displayName = data.getString(GroupEditorQuery.CONTACT_DISPLAY_NAME_PRIMARY);
+                String photoUri = data.getString(GroupEditorQuery.CONTACT_PHOTO_URI);
                 listExistingMembers.add(new Member(rawContactId, lookupKey, contactId,
                         displayName, photoUri));
             }
diff --git a/src/com/android/contacts/interactions/PhoneNumberInteraction.java b/src/com/android/contacts/interactions/PhoneNumberInteraction.java
index d10ec06..4c75896 100644
--- a/src/com/android/contacts/interactions/PhoneNumberInteraction.java
+++ b/src/com/android/contacts/interactions/PhoneNumberInteraction.java
@@ -15,13 +15,13 @@
  */
 package com.android.contacts.interactions;
 
-
 import com.android.contacts.Collapser;
 import com.android.contacts.Collapser.Collapsible;
 import com.android.contacts.ContactSaveService;
 import com.android.contacts.ContactsUtils;
 import com.android.contacts.R;
 import com.android.contacts.activities.DialtactsActivity;
+import com.android.contacts.activities.TransactionSafeActivity;
 import com.android.contacts.model.AccountType;
 import com.android.contacts.model.AccountType.StringInflater;
 import com.android.contacts.model.AccountTypeManager;
@@ -63,7 +63,8 @@
 
 /**
  * Initiates phone calls or a text message. If there are multiple candidates, this class shows a
- * dialog to pick one.
+ * dialog to pick one. Creating one of these interactions should be done through the static
+ * factory methods.
  */
 public class PhoneNumberInteraction implements OnLoadCompleteListener<Cursor> {
     private static final String TAG = PhoneNumberInteraction.class.getSimpleName();
@@ -183,9 +184,10 @@
      * one will be chosen to make a call or initiate an sms message.
      *
      * It is recommended to use
-     * {@link PhoneNumberInteraction#startInteractionForPhoneCall(Activity, Uri)} or
-     * {@link PhoneNumberInteraction#startInteractionForTextMessage(Activity, Uri)} instead of
-     * directly using this class, as those methods handle one or multiple data cases appropriately.
+     * {@link PhoneNumberInteraction#startInteractionForPhoneCall(TransactionSafeActivity, Uri)} or
+     * {@link PhoneNumberInteraction#startInteractionForTextMessage(TransactionSafeActivity, Uri)}
+     * instead of directly using this class, as those methods handle one or multiple data cases
+     * appropriately.
      */
     /* Made public to let the system reach this class */
     public static class PhoneDisambiguationDialogFragment extends DialogFragment
@@ -272,6 +274,12 @@
 
     private CursorLoader mLoader;
 
+    /**
+     * Constructs a new {@link PhoneNumberInteraction}. The constructor takes in a {@link Context}
+     * instead of a {@link TransactionSafeActivity} for testing purposes to verify the functionality
+     * of this class. However, all factory methods for creating {@link PhoneNumberInteraction}s
+     * require a {@link TransactionSafeActivity} (i.e. see {@link #startInteractionForPhoneCall}).
+     */
     @VisibleForTesting
     /* package */ PhoneNumberInteraction(Context context, InteractionType interactionType,
             DialogInterface.OnDismissListener dismissListener) {
@@ -347,7 +355,7 @@
 
     @Override
     public void onLoadComplete(Loader<Cursor> loader, Cursor cursor) {
-        if (cursor == null) {
+        if (cursor == null || !isSafeToCommitTransactions()) {
             onDismiss();
             return;
         }
@@ -396,6 +404,11 @@
         }
     }
 
+    private boolean isSafeToCommitTransactions() {
+        return mContext instanceof TransactionSafeActivity ?
+                ((TransactionSafeActivity) mContext).isSafeToCommitTransactions() : true;
+    }
+
     private void onDismiss() {
         if (mDismissListener != null) {
             mDismissListener.onDismiss(null);
@@ -406,21 +419,27 @@
      * Start call action using given contact Uri. If there are multiple candidates for the phone
      * call, dialog is automatically shown and the user is asked to choose one.
      *
+     * @param activity that is calling this interaction. This must be of type
+     * {@link TransactionSafeActivity} because we need to check on the activity state after the
+     * phone numbers have been queried for.
      * @param uri contact Uri (built from {@link Contacts#CONTENT_URI}) or data Uri
      * (built from {@link Data#CONTENT_URI}). Contact Uri may show the disambiguation dialog while
      * data Uri won't.
      */
-    public static void startInteractionForPhoneCall(Activity activity, Uri uri) {
+    public static void startInteractionForPhoneCall(TransactionSafeActivity activity, Uri uri) {
         (new PhoneNumberInteraction(activity, InteractionType.PHONE_CALL, null))
                 .startInteraction(uri);
     }
 
     /**
+     * @param activity that is calling this interaction. This must be of type
+     * {@link TransactionSafeActivity} because we need to check on the activity state after the
+     * phone numbers have been queried for.
      * @param callOrigin If non null, {@link DialtactsActivity#EXTRA_CALL_ORIGIN} will be
      * appended to the Intent initiating phone call. See comments in Phone package (PhoneApp)
      * for more detail.
      */
-    public static void startInteractionForPhoneCall(Activity activity, Uri uri,
+    public static void startInteractionForPhoneCall(TransactionSafeActivity activity, Uri uri,
             String callOrigin) {
         (new PhoneNumberInteraction(activity, InteractionType.PHONE_CALL, null, callOrigin))
                 .startInteraction(uri);
@@ -431,11 +450,14 @@
      * candidates for the phone call, dialog is automatically shown and the user is asked to choose
      * one.
      *
+     * @param activity that is calling this interaction. This must be of type
+     * {@link TransactionSafeActivity} because we need to check on the activity state after the
+     * phone numbers have been queried for.
      * @param uri contact Uri (built from {@link Contacts#CONTENT_URI}) or data Uri
      * (built from {@link Data#CONTENT_URI}). Contact Uri may show the disambiguation dialog while
      * data Uri won't.
      */
-    public static void startInteractionForTextMessage(Activity activity, Uri uri) {
+    public static void startInteractionForTextMessage(TransactionSafeActivity activity, Uri uri) {
         (new PhoneNumberInteraction(activity, InteractionType.SMS, null)).startInteraction(uri);
     }
 
diff --git a/src/com/android/contacts/list/ContactTileAdapter.java b/src/com/android/contacts/list/ContactTileAdapter.java
index 3eb7232..b7e2586 100644
--- a/src/com/android/contacts/list/ContactTileAdapter.java
+++ b/src/com/android/contacts/list/ContactTileAdapter.java
@@ -21,7 +21,9 @@
 import com.android.contacts.ContactTileLoaderFactory;
 import com.android.contacts.ContactsUtils;
 import com.android.contacts.GroupMemberLoader;
+import com.android.contacts.GroupMemberLoader.GroupDetailQuery;
 import com.android.contacts.R;
+import com.android.contacts.list.ContactTileAdapter.DisplayType;
 
 import android.content.ContentUris;
 import android.content.Context;
@@ -36,7 +38,6 @@
 import android.view.ViewGroup;
 import android.widget.BaseAdapter;
 import android.widget.FrameLayout;
-import android.widget.TextView;
 
 import java.util.ArrayList;
 
@@ -156,13 +157,12 @@
          * the correct {@link Cursor}s will be given.
          */
         if (mDisplayType == DisplayType.GROUP_MEMBERS) {
-            mIdIndex = GroupMemberLoader.CONTACT_PHOTO_ID_COLUMN_INDEX;
-            mLookupIndex = GroupMemberLoader.CONTACT_LOOKUP_KEY_COLUMN_INDEX;
-            mPhotoUriIndex = GroupMemberLoader.CONTACT_PHOTO_URI_COLUMN_INDEX;
-            mNameIndex = GroupMemberLoader.CONTACT_DISPLAY_NAME_PRIMARY_COLUMN_INDEX;
-            mStarredIndex = GroupMemberLoader.CONTACT_STARRED_COLUMN_INDEX;
-            mPresenceIndex = GroupMemberLoader.CONTACT_PRESENCE_STATUS_COLUMN_INDEX;
-            mStatusIndex = GroupMemberLoader.CONTACT_STATUS_COLUMN_INDEX;
+            mIdIndex = GroupDetailQuery.CONTACT_PHOTO_ID;
+            mLookupIndex = GroupDetailQuery.CONTACT_LOOKUP_KEY;
+            mPhotoUriIndex = GroupDetailQuery.CONTACT_PHOTO_URI;
+            mNameIndex = GroupDetailQuery.CONTACT_DISPLAY_NAME_PRIMARY;
+            mPresenceIndex = GroupDetailQuery.CONTACT_PRESENCE_STATUS;
+            mStatusIndex = GroupDetailQuery.CONTACT_STATUS;
         } else {
             mIdIndex = ContactTileLoaderFactory.CONTACT_ID;
             mLookupIndex = ContactTileLoaderFactory.LOOKUP_KEY;