Merge "Add a dummy loader to calllog to defer other fragments." into ics-mr1
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/PeopleActivity.java b/src/com/android/contacts/activities/PeopleActivity.java
index 031f0c8..5afcbbd 100644
--- a/src/com/android/contacts/activities/PeopleActivity.java
+++ b/src/com/android/contacts/activities/PeopleActivity.java
@@ -472,12 +472,15 @@
 
     @Override
     protected void onDestroy() {
-        // mActionBarAdapter will be null here when redirecting to another activity in
-        // configureContentView().
+        // Some of variables will be null if this Activity redirects Intent.
+        // See also onCreate() or other methods called during the Activity's initialization.
         if (mActionBarAdapter != null) {
             mActionBarAdapter.setListener(null);
         }
-        mContactListFilterController.removeListener(this);
+        if (mContactListFilterController != null) {
+            mContactListFilterController.removeListener(this);
+        }
+
         super.onDestroy();
     }
 
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/detail/ContactDetailFragment.java b/src/com/android/contacts/detail/ContactDetailFragment.java
index 5d7ab93..e63ee28 100644
--- a/src/com/android/contacts/detail/ContactDetailFragment.java
+++ b/src/com/android/contacts/detail/ContactDetailFragment.java
@@ -387,6 +387,16 @@
     }
 
     /**
+     * Reset the list adapter in this {@link Fragment} to get rid of any saved scroll position
+     * from a previous contact.
+     */
+    public void resetAdapter() {
+        if (mListView != null) {
+            mListView.setAdapter(mAdapter);
+        }
+    }
+
+    /**
      * Returns the top coordinate of the first item in the {@link ListView}. If the first item
      * in the {@link ListView} is not visible or there are no children in the list, then return
      * Integer.MIN_VALUE. Note that the returned value will be <= 0 because the first item in the
diff --git a/src/com/android/contacts/detail/ContactDetailLayoutController.java b/src/com/android/contacts/detail/ContactDetailLayoutController.java
index 2bcd1a0..74811e4 100644
--- a/src/com/android/contacts/detail/ContactDetailLayoutController.java
+++ b/src/com/android/contacts/detail/ContactDetailLayoutController.java
@@ -20,6 +20,7 @@
 import com.android.contacts.NfcHandler;
 import com.android.contacts.R;
 import com.android.contacts.activities.ContactDetailActivity.FragmentKeyListener;
+import com.android.contacts.util.UriUtils;
 
 import android.animation.Animator;
 import android.animation.Animator.AnimatorListener;
@@ -28,6 +29,7 @@
 import android.app.FragmentManager;
 import android.app.FragmentTransaction;
 import android.content.Context;
+import android.net.Uri;
 import android.os.Bundle;
 import android.support.v4.view.ViewPager;
 import android.support.v4.view.ViewPager.OnPageChangeListener;
@@ -42,6 +44,7 @@
  */
 public class ContactDetailLayoutController {
 
+    private static final String KEY_CONTACT_URI = "contactUri";
     private static final String KEY_CONTACT_HAS_UPDATES = "contactHasUpdates";
     private static final String KEY_CURRENT_PAGE_INDEX = "currentPageIndex";
 
@@ -78,6 +81,7 @@
     private ContactDetailFragment.Listener mContactDetailFragmentListener;
 
     private ContactLoader.Result mContactData;
+    private Uri mContactUri;
 
     private boolean mTabCarouselIsAnimating;
     private boolean mContactHasUpdates;
@@ -144,6 +148,7 @@
         // Read from savedState if possible
         int currentPageIndex = 0;
         if (savedState != null) {
+            mContactUri = savedState.getParcelable(KEY_CONTACT_URI);
             mContactHasUpdates = savedState.getBoolean(KEY_CONTACT_HAS_UPDATES);
             currentPageIndex = savedState.getInt(KEY_CURRENT_PAGE_INDEX, 0);
         }
@@ -269,13 +274,18 @@
     }
 
     /**
-     * Setup the layout for the contact with updates. Pass in the index of the current page to
-     * select or null if the current selection should be left as is.
+     * Setup the layout for the contact with updates.
+     * TODO: Clean up this method so it's easier to understand.
      */
     private void showContactWithUpdates() {
         if (mContactData == null) {
             return;
         }
+
+        Uri previousContactUri = mContactUri;
+        mContactUri = mContactData.getLookupUri();
+        boolean isDifferentContact = !UriUtils.areEqual(previousContactUri, mContactUri);
+
         switch (mLayoutMode) {
             case TWO_COLUMN: {
                 // Set the contact data (hide the static photo because the photo will already be in
@@ -292,6 +302,11 @@
                 mTabCarousel.setVisibility(View.VISIBLE);
                 // Update ViewPager to allow swipe between all the fragments (to see updates)
                 mViewPagerAdapter.enableSwipe(true);
+                // If this is a different contact than before, then reset some views.
+                if (isDifferentContact) {
+                    resetViewPager();
+                    resetTabCarousel();
+                }
                 break;
             }
             case FRAGMENT_CAROUSEL: {
@@ -303,14 +318,27 @@
                 throw new IllegalStateException("Invalid LayoutMode " + mLayoutMode);
         }
 
-        mDetailFragment.setData(mContactData.getLookupUri(), mContactData);
-        mUpdatesFragment.setData(mContactData.getLookupUri(), mContactData);
+        if (isDifferentContact) {
+            resetFragments();
+        }
+
+        mDetailFragment.setData(mContactUri, mContactData);
+        mUpdatesFragment.setData(mContactUri, mContactData);
     }
 
+    /**
+     * Setup the layout for the contact without updates.
+     * TODO: Clean up this method so it's easier to understand.
+     */
     private void showContactWithoutUpdates() {
         if (mContactData == null) {
             return;
         }
+
+        Uri previousContactUri = mContactUri;
+        mContactUri = mContactData.getLookupUri();
+        boolean isDifferentContact = !UriUtils.areEqual(previousContactUri, mContactUri);
+
         switch (mLayoutMode) {
             case TWO_COLUMN:
                 // Show the static photo which is next to the list of scrolling contact details
@@ -336,7 +364,24 @@
                 throw new IllegalStateException("Invalid LayoutMode " + mLayoutMode);
         }
 
-        mDetailFragment.setData(mContactData.getLookupUri(), mContactData);
+        if (isDifferentContact) {
+            resetFragments();
+        }
+
+        mDetailFragment.setData(mContactUri, mContactData);
+    }
+
+    private void resetTabCarousel() {
+        mTabCarousel.reset();
+    }
+
+    private void resetViewPager() {
+        mViewPager.setCurrentItem(0, false /* smooth transition */);
+    }
+
+    private void resetFragments() {
+        mDetailFragment.resetAdapter();
+        mUpdatesFragment.resetAdapter();
     }
 
     public FragmentKeyListener getCurrentPage() {
@@ -365,6 +410,7 @@
     }
 
     public void onSaveInstanceState(Bundle outState) {
+        outState.putParcelable(KEY_CONTACT_URI, mContactUri);
         outState.putBoolean(KEY_CONTACT_HAS_UPDATES, mContactHasUpdates);
         outState.putInt(KEY_CURRENT_PAGE_INDEX, getCurrentPageIndex());
     }
diff --git a/src/com/android/contacts/detail/ContactDetailTabCarousel.java b/src/com/android/contacts/detail/ContactDetailTabCarousel.java
index 4700078..045e900 100644
--- a/src/com/android/contacts/detail/ContactDetailTabCarousel.java
+++ b/src/com/android/contacts/detail/ContactDetailTabCarousel.java
@@ -180,6 +180,16 @@
     }
 
     /**
+     * Reset the carousel to the start position (i.e. because new data will be loaded in for a
+     * different contact).
+     */
+    public void reset() {
+        scrollTo(0, 0);
+        setCurrentTab(0);
+        moveToYCoordinate(0, 0);
+    }
+
+    /**
      * Set the current tab that should be restored when the view is first laid out.
      */
     public void restoreCurrentTab(int position) {
diff --git a/src/com/android/contacts/detail/ContactDetailUpdatesFragment.java b/src/com/android/contacts/detail/ContactDetailUpdatesFragment.java
index afe159b..fd59674 100644
--- a/src/com/android/contacts/detail/ContactDetailUpdatesFragment.java
+++ b/src/com/android/contacts/detail/ContactDetailUpdatesFragment.java
@@ -158,6 +158,14 @@
         }
     }
 
+    /**
+     * Reset the list adapter in this {@link Fragment} to get rid of any saved scroll position
+     * from a previous contact.
+     */
+    public void resetAdapter() {
+        setListAdapter(mStreamItemAdapter);
+    }
+
     @Override
     public void setAlphaLayerValue(float alpha) {
         // If the alpha layer is not ready yet, store it for later when the view is initialized
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;