2-pane: Make sure to hide "edit contact" on non "all" tabs

(also other options such as "delete conact" and "share copntact")

These menu items are actually owned by ContactLoaderFragment, so we need to
show/hide the fragment as well even though it's invisible.

Bug 5028965

Change-Id: I302ee49a2a549c0397bee6a657e04c291c3e8b3c
diff --git a/res/layout/contact_detail_loader_fragment.xml b/res/layout/contact_detail_loader_fragment.xml
index 3c4bbef..62edb3d 100644
--- a/res/layout/contact_detail_loader_fragment.xml
+++ b/res/layout/contact_detail_loader_fragment.xml
@@ -14,7 +14,13 @@
      limitations under the License.
 -->
 
-<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
-    android:layout_width="wrap_content"
-    android:layout_height="wrap_content"
-    android:visibility="gone"/>
\ No newline at end of file
+<!--
+    Invisible view.
+    Note we show/hide the fragment at runtime with FragmentTransaction.show()/hide() in order to
+    change the visibility of the options menu.  This means the visibility of the view will be
+    changed at runtime, so we use width/height to make it invisible, rather than using
+    visibility.
+-->
+<View xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="0dip"
+    android:layout_height="0dip"/>
\ No newline at end of file
diff --git a/src/com/android/contacts/activities/PeopleActivity.java b/src/com/android/contacts/activities/PeopleActivity.java
index b0844e9..06b3f9d 100644
--- a/src/com/android/contacts/activities/PeopleActivity.java
+++ b/src/com/android/contacts/activities/PeopleActivity.java
@@ -543,11 +543,14 @@
         FragmentManager fragmentManager = getFragmentManager();
         FragmentTransaction ft = fragmentManager.beginTransaction();
 
+        // Note mContactDetailLoaderFragment is an invisible fragment, but we still have to show/
+        // hide it so its options menu will be shown/hidden.
         switch (tab) {
             case FAVORITES:
                 showFragment(ft, mFavoritesFragment);
                 showFragment(ft, mFrequentFragment);
                 hideFragment(ft, mAllFragment);
+                hideFragment(ft, mContactDetailLoaderFragment);
                 hideFragment(ft, mContactDetailFragment);
                 hideFragment(ft, mGroupsFragment);
                 hideFragment(ft, mGroupDetailFragment);
@@ -556,6 +559,7 @@
                 hideFragment(ft, mFavoritesFragment);
                 hideFragment(ft, mFrequentFragment);
                 showFragment(ft, mAllFragment);
+                showFragment(ft, mContactDetailLoaderFragment);
                 showFragment(ft, mContactDetailFragment);
                 hideFragment(ft, mGroupsFragment);
                 hideFragment(ft, mGroupDetailFragment);
@@ -564,6 +568,7 @@
                 hideFragment(ft, mFavoritesFragment);
                 hideFragment(ft, mFrequentFragment);
                 hideFragment(ft, mAllFragment);
+                hideFragment(ft, mContactDetailLoaderFragment);
                 hideFragment(ft, mContactDetailFragment);
                 showFragment(ft, mGroupsFragment);
                 showFragment(ft, mGroupDetailFragment);
diff --git a/src/com/android/contacts/detail/ContactLoaderFragment.java b/src/com/android/contacts/detail/ContactLoaderFragment.java
index b7cb2b7..0dc83ef 100644
--- a/src/com/android/contacts/detail/ContactLoaderFragment.java
+++ b/src/com/android/contacts/detail/ContactLoaderFragment.java
@@ -28,15 +28,12 @@
 import android.app.LoaderManager;
 import android.app.LoaderManager.LoaderCallbacks;
 import android.content.ActivityNotFoundException;
-import android.content.ContentValues;
 import android.content.Context;
-import android.content.Entity;
 import android.content.Intent;
 import android.content.Loader;
 import android.net.Uri;
 import android.os.Bundle;
 import android.provider.ContactsContract.Contacts;
-import android.provider.ContactsContract.RawContacts;
 import android.util.Log;
 import android.view.KeyEvent;
 import android.view.LayoutInflater;
@@ -124,7 +121,9 @@
     @Override
     public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedState) {
         setHasOptionsMenu(true);
-        // This is an empty view that is set to visibility gone.
+        // This is an invisible view.  This fragment is declared in a layout, so it can't be
+        // "viewless".  (i.e. can't return null here.)
+        // See also the comment in the layout file.
         return inflater.inflate(R.layout.contact_detail_loader_fragment, container, false);
     }