Fit-and-finish.  Redoing the title for contact search results.

Bug: 2534618

Change-Id: If00dd28dfcdc5596e6b6cb8a5690f5c0382200de
diff --git a/src/com/android/contacts/ContactsListActivity.java b/src/com/android/contacts/ContactsListActivity.java
index ad6589e..122e97b 100644
--- a/src/com/android/contacts/ContactsListActivity.java
+++ b/src/com/android/contacts/ContactsListActivity.java
@@ -88,6 +88,7 @@
 import android.provider.ContactsContract.Intents.UI;
 import android.telephony.TelephonyManager;
 import android.text.Editable;
+import android.text.Html;
 import android.text.TextUtils;
 import android.text.TextWatcher;
 import android.util.Log;
@@ -447,6 +448,7 @@
     private int mProviderStatus = ProviderStatus.STATUS_NORMAL;
 
     private boolean mSearchMode;
+    private boolean mSearchResultsMode;
     private boolean mShowNumberOfContacts;
 
     private boolean mShowSearchSnippets;
@@ -713,6 +715,7 @@
                 mShowSearchSnippets = true;
                 mInitialFilter = getIntent().getStringExtra(SearchManager.QUERY);
             }
+            mSearchResultsMode = true;
         } else if (ACTION_SEARCH_INTERNAL.equals(action)) {
             String originalAction = null;
             Bundle extras = intent.getExtras();
@@ -735,6 +738,7 @@
                 mShowSearchSnippets = true;
                 mInitialFilter = getIntent().getStringExtra(SearchManager.QUERY);
             }
+            mSearchResultsMode = true;
         // Since this is the filter activity it receives all intents
         // dispatched from the SearchManager for security reasons
         // so we need to re-dispatch from here to the intended target.
@@ -797,7 +801,8 @@
             mMode = MODE_DEFAULT;
         }
 
-        if ((mMode & MODE_MASK_SHOW_NUMBER_OF_CONTACTS) != 0 || mSearchMode) {
+        if (((mMode & MODE_MASK_SHOW_NUMBER_OF_CONTACTS) != 0 || mSearchMode)
+                && !mSearchResultsMode) {
             mShowNumberOfContacts = true;
         }
 
@@ -811,6 +816,11 @@
             mJoinModeShowAllContacts = true;
         } else if (mSearchMode) {
             setContentView(R.layout.contacts_search_content);
+        } else if (mSearchResultsMode) {
+            setContentView(R.layout.contacts_list_search_results);
+            TextView titleText = (TextView)findViewById(R.id.search_results_for);
+            titleText.setText(Html.fromHtml(getString(R.string.search_results_for,
+                    "<b>" + mInitialFilter + "</b>")));
         } else {
             setContentView(R.layout.contacts_list_content);
         }
@@ -1297,7 +1307,7 @@
             return;
         }
 
-        Intent intent = new Intent(this, ContactsListActivity.class);
+        Intent intent = new Intent(this, SearchResultsActivity.class);
         Intent originalIntent = getIntent();
         Bundle originalExtras = originalIntent.getExtras();
         if (originalExtras != null) {
@@ -2349,6 +2359,11 @@
         // Set the proper empty string
         setEmptyText();
 
+        if (mSearchResultsMode) {
+            TextView foundContactsText = (TextView)findViewById(R.id.search_results_found);
+            foundContactsText.setText(R.string.search_results_searching);
+        }
+
         mAdapter.setLoading(true);
 
         // Cancel any pending queries
@@ -2648,6 +2663,16 @@
         return null;
     }
 
+    // TODO: fix PluralRules to handle zero correctly and use Resources.getQuantityText directly
+    protected String getQuantityText(int count, int zeroResourceId, int pluralResourceId) {
+        if (count == 0) {
+            return getString(zeroResourceId);
+        } else {
+            String format = getResources().getQuantityText(pluralResourceId, count).toString();
+            return String.format(format, count);
+        }
+    }
+
     /**
      * Signal an error to the user.
      */
@@ -2956,11 +2981,7 @@
             String text;
             int count = getRealCount();
 
-            if (mMode == MODE_QUERY || mMode == MODE_QUERY_PICK || mMode == MODE_QUERY_PICK_PHONE
-                    || mMode == MODE_QUERY_PICK_TO_EDIT) {
-                text = getQuantityText(count, R.string.listFoundAllContactsZero,
-                        R.plurals.listFoundAllContacts);
-            } else if (mSearchMode && !TextUtils.isEmpty(getTextFilter())) {
+            if (mSearchMode && !TextUtils.isEmpty(getTextFilter())) {
                 text = getQuantityText(count, R.string.listFoundAllContactsZero,
                         R.plurals.searchFoundContacts);
             } else {
@@ -2976,16 +2997,6 @@
             return view;
         }
 
-        // TODO: fix PluralRules to handle zero correctly and use Resources.getQuantityText directly
-        private String getQuantityText(int count, int zeroResourceId, int pluralResourceId) {
-            if (count == 0) {
-                return getString(zeroResourceId);
-            } else {
-                String format = getResources().getQuantityText(pluralResourceId, count).toString();
-                return String.format(format, count);
-            }
-        }
-
         private boolean isShowAllContactsItemPosition(int position) {
             return mMode == MODE_JOIN_CONTACT && mJoinModeShowAllContacts
                     && mSuggestionsCursorCount != 0 && position == mSuggestionsCursorCount + 2;
@@ -3319,6 +3330,13 @@
                 }
             }
 
+            if (cursor != null && mSearchResultsMode) {
+                TextView foundContactsText = (TextView)findViewById(R.id.search_results_found);
+                String text = getQuantityText(cursor.getCount(), R.string.listFoundAllContactsZero,
+                        R.plurals.listFoundAllContacts);
+                foundContactsText.setText(text);
+            }
+
             super.changeCursor(cursor);
             // Update the indexer for the fast scroll widget
             updateIndexer(cursor);
diff --git a/src/com/android/contacts/SearchResultsActivity.java b/src/com/android/contacts/SearchResultsActivity.java
new file mode 100644
index 0000000..09f0014
--- /dev/null
+++ b/src/com/android/contacts/SearchResultsActivity.java
@@ -0,0 +1,23 @@
+/*
+ * 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.
+ */
+package com.android.contacts;
+
+/**
+ * The activity that displays the list of contact search results.  We need a separate
+ * class because it uses a different theme from {@link ContactsListActivity}.
+ */
+public class SearchResultsActivity extends ContactsListActivity {
+}