New search behavior for empty query

It's a very lightweight change to implment the new spec, which says:
- Don't start searching until the user types the first letter
- But if the search view is shown, make the ALL tab current, and disable swipe

With this CL,
- No changes to ActionBarAdapter.isSearchMode().  It still returns true
  if the search view is visible, even if it's empty.
- However, in order to make the all fragment show the normal list for
  empty query, only turn the fragment into the search mode if the query is
  non-empty.

Also reverts I25908651 as we no longer do a search with empty query.

Bug 5104010

Change-Id: I50038994c6d65aab71ceefdf9218f3c7ad2bc6a4
diff --git a/src/com/android/contacts/activities/ActionBarAdapter.java b/src/com/android/contacts/activities/ActionBarAdapter.java
index 5a32d74..0c0841c 100644
--- a/src/com/android/contacts/activities/ActionBarAdapter.java
+++ b/src/com/android/contacts/activities/ActionBarAdapter.java
@@ -211,6 +211,10 @@
         return mSearchMode;
     }
 
+    public boolean shouldShowSearchResult() {
+        return mSearchMode && !TextUtils.isEmpty(mQueryString);
+    }
+
     public void setSearchMode(boolean flag) {
         if (mSearchMode != flag) {
             mSearchMode = flag;
diff --git a/src/com/android/contacts/activities/PeopleActivity.java b/src/com/android/contacts/activities/PeopleActivity.java
index fc9879a..cab8afd 100644
--- a/src/com/android/contacts/activities/PeopleActivity.java
+++ b/src/com/android/contacts/activities/PeopleActivity.java
@@ -867,11 +867,11 @@
     }
 
     private void configureContactListFragment() {
-        final boolean searchMode = mActionBarAdapter.isSearchMode();
-        mAllFragment.setSearchMode(searchMode);
+        final boolean showSearchResult = mActionBarAdapter.shouldShowSearchResult();
+        mAllFragment.setSearchMode(showSearchResult);
 
         final boolean useTwoPane = PhoneCapabilityTester.isUsingTwoPanes(this);
-        mAllFragment.setVisibleScrollbarEnabled(!searchMode);
+        mAllFragment.setVisibleScrollbarEnabled(!showSearchResult);
         mAllFragment.setVerticalScrollbarPosition(
                 useTwoPane
                         ? View.SCROLLBAR_POSITION_LEFT
diff --git a/src/com/android/contacts/list/ContactEntryListAdapter.java b/src/com/android/contacts/list/ContactEntryListAdapter.java
index 4ac54dc..8bc6559 100644
--- a/src/com/android/contacts/list/ContactEntryListAdapter.java
+++ b/src/com/android/contacts/list/ContactEntryListAdapter.java
@@ -455,10 +455,6 @@
         if (!mEmptyListEnabled) {
             return false;
         } else if (isSearchMode()) {
-            // TODO Do we really need this?  DefaultContactListAdapter overrides it and always
-            // return false, as it returns all contacts if in the search mode and the query is
-            // empty.  If there's no places relying on this behavior, we can just return false
-            // here.
             return TextUtils.isEmpty(getQueryString());
         } else if (mLoading) {
             // We don't want the empty state to show when loading.
diff --git a/src/com/android/contacts/list/DefaultContactListAdapter.java b/src/com/android/contacts/list/DefaultContactListAdapter.java
index f081921..89de966 100644
--- a/src/com/android/contacts/list/DefaultContactListAdapter.java
+++ b/src/com/android/contacts/list/DefaultContactListAdapter.java
@@ -66,15 +66,11 @@
             }
             query = query.trim();
             if (TextUtils.isEmpty(query)) {
-                // Special case: if the query string is empty, show all contacts, regardless of the
-                // current filter.
-                // (We can't use the FILTER_URI for this, as the contacts provider would return
-                // an empty cursor if the query is empty.)
-                final ContactListFilter allFilter = ContactListFilter.createFilterWithType(
-                        ContactListFilter.FILTER_TYPE_ALL_ACCOUNTS);
-                configureUri(loader, directoryId, allFilter);
-                configureProjection(loader, directoryId, allFilter);
-                configureSelection(loader, directoryId, allFilter);
+                // Regardless of the directory, we don't want anything returned,
+                // so let's just send a "nothing" query to the local directory.
+                loader.setUri(Contacts.CONTENT_URI);
+                loader.setProjection(PROJECTION_CONTACT);
+                loader.setSelection("0");
             } else {
                 Builder builder = Contacts.CONTENT_FILTER_URI.buildUpon();
                 builder.appendPath(query);      // Builder will encode the query
@@ -256,16 +252,4 @@
         return prefs.getBoolean(ContactsPreferences.PREF_DISPLAY_ONLY_PHONES,
                 ContactsPreferences.PREF_DISPLAY_ONLY_PHONES_DEFAULT);
     }
-
-    @Override
-    public boolean isEmpty() {
-        // ContactEntryListAdapter.isEmpty() returns false when in the search mode && the query is
-        // empty.  Here, we want to return all contacts in this case, override it and make it
-        // always return false.  See the TODO there -- we may not need this method entirely.
-        if (isSearchMode()) {
-            return false;
-        } else {
-            return super.isEmpty();
-        }
-    }
 }