Adding a "no contact selected" fragment

Change-Id: Ib3bc474e84315854ac0f800ce2566606654d0ff2
diff --git a/res/drawable/contact_none.png b/res/drawable/contact_none.png
new file mode 100644
index 0000000..dd2a301
--- /dev/null
+++ b/res/drawable/contact_none.png
Binary files differ
diff --git a/res/layout/contact_none_fragment.xml b/res/layout/contact_none_fragment.xml
new file mode 100644
index 0000000..15dfba5
--- /dev/null
+++ b/res/layout/contact_none_fragment.xml
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2007 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.
+-->
+
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+>
+
+  <ImageView
+    android:layout_width="wrap_content"
+    android:layout_height="wrap_content"
+    android:src="@drawable/contact_none"
+    android:layout_centerInParent="true"/>
+    
+</RelativeLayout>
diff --git a/src/com/android/contacts/activities/ContactListActivity.java b/src/com/android/contacts/activities/ContactListActivity.java
index 37e4c97..5e7abb4 100644
--- a/src/com/android/contacts/activities/ContactListActivity.java
+++ b/src/com/android/contacts/activities/ContactListActivity.java
@@ -30,6 +30,7 @@
 import com.android.contacts.list.StrequentContactListFragment;
 import com.android.contacts.ui.ContactsPreferencesActivity;
 import com.android.contacts.views.detail.ContactDetailFragment;
+import com.android.contacts.views.detail.ContactNoneFragment;
 import com.android.contacts.views.editor.ContactEditorFragment;
 import com.android.contacts.widget.ContextMenuAdapter;
 import com.android.contacts.widget.SearchEditText;
@@ -77,6 +78,8 @@
     private ContactDeletionInteraction mContactDeletionInteraction;
     private ImportExportInteraction mImportExportInteraction;
 
+    private ContactNoneFragment mEmptyFragment;
+
     private ContactDetailFragment mDetailFragment;
     private DetailFragmentListener mDetailFragmentListener = new DetailFragmentListener();
 
@@ -92,6 +95,8 @@
     private NavigationBar mNavigationBar;
     private int mMode = -1;
 
+    public Uri mSelectedContactLookupUri;
+
     public ContactListActivity() {
         mIntentResolver = new ContactsIntentResolver(this);
     }
@@ -229,29 +234,39 @@
 
     private void setupContactDetailFragment() {
         // No editor here
-        if (mEditorFragment != null) {
-            mEditorFragment.setListener(null);
-            mEditorFragment = null;
+        closeEditorFragment();
+
+        if (mSelectedContactLookupUri != null) {
+            // Already showing? Nothing to do
+            if (mDetailFragment != null) {
+                mDetailFragment.loadUri(mSelectedContactLookupUri);
+                return;
+            }
+
+            closeEmptyFragment();
+
+            mDetailFragment = new ContactDetailFragment();
+            mDetailFragment.setListener(mDetailFragmentListener);
+            mDetailFragment.loadUri(mSelectedContactLookupUri);
+
+            // Nothing showing yet? Create (this happens during Activity-Startup)
+            openFragmentTransaction()
+                    .replace(R.id.two_pane_right_view, mDetailFragment)
+                    .commit();
+        } else {
+            closeDetailFragment();
+
+            mEmptyFragment = new ContactNoneFragment();
+            openFragmentTransaction()
+                    .replace(R.id.two_pane_right_view, mEmptyFragment)
+                    .commit();
         }
-
-        // Already showing? Nothing to do
-        if (mDetailFragment != null) return;
-
-        mDetailFragment = new ContactDetailFragment();
-        mDetailFragment.setListener(mDetailFragmentListener);
-
-        // Nothing showing yet? Create (this happens during Activity-Startup)
-        openFragmentTransaction()
-                .replace(R.id.two_pane_right_view, mDetailFragment)
-                .commit();
     }
 
     private void setupContactEditorFragment() {
         // No detail view here
-        if (mDetailFragment != null) {
-            mDetailFragment.setListener(null);
-            mDetailFragment = null;
-        }
+        closeDetailFragment();
+        closeEmptyFragment();
 
         // Already showing? Nothing to do
         if (mEditorFragment != null) return;
@@ -265,6 +280,24 @@
                 .commit();
     }
 
+    private void closeDetailFragment() {
+        if (mDetailFragment != null) {
+            mDetailFragment.setListener(null);
+            mDetailFragment = null;
+        }
+    }
+
+    private void closeEditorFragment() {
+        if (mEditorFragment != null) {
+            mEditorFragment.setListener(null);
+            mEditorFragment = null;
+        }
+    }
+
+    private void closeEmptyFragment() {
+        mEmptyFragment = null;
+    }
+
     @Override
     protected void onResume() {
         super.onResume();
@@ -345,8 +378,8 @@
     private final class ContactBrowserActionListener implements OnContactBrowserActionListener {
         public void onViewContactAction(Uri contactLookupUri) {
             if (mTwoPaneLayout) {
+                mSelectedContactLookupUri = contactLookupUri;
                 setupContactDetailFragment();
-                mDetailFragment.loadUri(contactLookupUri);
             } else {
                 startActivity(new Intent(Intent.ACTION_VIEW, contactLookupUri));
             }
diff --git a/src/com/android/contacts/views/detail/ContactNoneFragment.java b/src/com/android/contacts/views/detail/ContactNoneFragment.java
new file mode 100644
index 0000000..45d3fe1
--- /dev/null
+++ b/src/com/android/contacts/views/detail/ContactNoneFragment.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright (C) 2010 Google Inc.
+ *
+ * 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.views.detail;
+
+import com.android.contacts.R;
+
+import android.app.Fragment;
+import android.os.Bundle;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+
+public class ContactNoneFragment extends Fragment {
+
+    @Override
+    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedState) {
+        return inflater.inflate(R.layout.contact_none_fragment, container, false);
+    }
+}