Eliminating selection delay when query comes from intent.

We want to delay automatic selection of the first
result when the user is typing in order to prevent
flashing UI.  However when the query string is sent
to Contacts as part of an intent, such delay is unnecessary.

Change-Id: I55afd4b435e46fbd701eb6a514bcf0f85b963409
diff --git a/src/com/android/contacts/activities/ContactBrowserActivity.java b/src/com/android/contacts/activities/ContactBrowserActivity.java
index f934e6a..4c2411c 100644
--- a/src/com/android/contacts/activities/ContactBrowserActivity.java
+++ b/src/com/android/contacts/activities/ContactBrowserActivity.java
@@ -349,7 +349,7 @@
     @Override
     public void onAction() {
         configureFragments(false /* from request */);
-        mListFragment.setQueryString(mActionBarAdapter.getQueryString());
+        mListFragment.setQueryString(mActionBarAdapter.getQueryString(), true);
     }
 
     private void configureListFragmentForRequest() {
@@ -359,7 +359,7 @@
         }
 
         mListFragment.setSearchMode(mRequest.isSearchMode());
-        mListFragment.setQueryString(mRequest.getQueryString());
+        mListFragment.setQueryString(mRequest.getQueryString(), false);
 
         if (mRequest.isDirectorySearchEnabled()) {
             mListFragment.setDirectorySearchMode(DirectoryListLoader.SEARCH_MODE_DEFAULT);
diff --git a/src/com/android/contacts/activities/ContactSelectionActivity.java b/src/com/android/contacts/activities/ContactSelectionActivity.java
index 2ed258f..278ec63 100644
--- a/src/com/android/contacts/activities/ContactSelectionActivity.java
+++ b/src/com/android/contacts/activities/ContactSelectionActivity.java
@@ -216,7 +216,7 @@
             case ContactsRequest.ACTION_CREATE_SHORTCUT_CONTACT: {
                 ContactPickerFragment fragment = new ContactPickerFragment();
                 fragment.setSearchMode(mRequest.isSearchMode());
-                fragment.setQueryString(mRequest.getQueryString());
+                fragment.setQueryString(mRequest.getQueryString(), false);
                 fragment.setShortcutRequested(true);
                 mListFragment = fragment;
                 break;
@@ -258,7 +258,7 @@
         mListFragment.setLegacyCompatibilityMode(mRequest.isLegacyCompatibilityMode());
         mListFragment.setContactsRequest(mRequest);
         mListFragment.setSearchMode(mRequest.isSearchMode());
-        mListFragment.setQueryString(mRequest.getQueryString());
+        mListFragment.setQueryString(mRequest.getQueryString(), false);
         mListFragment.setDirectoryResultLimit(DEFAULT_DIRECTORY_RESULT_LIMIT);
 
         getFragmentManager().beginTransaction()
@@ -350,7 +350,7 @@
 
     @Override
     public boolean onQueryTextChanged(String newText) {
-        mListFragment.setQueryString(newText);
+        mListFragment.setQueryString(newText, true);
         mListFragment.setSearchMode(!TextUtils.isEmpty(newText));
         return false;
     }
diff --git a/src/com/android/contacts/list/ContactBrowseListFragment.java b/src/com/android/contacts/list/ContactBrowseListFragment.java
index 1d92cab..9b99639 100644
--- a/src/com/android/contacts/list/ContactBrowseListFragment.java
+++ b/src/com/android/contacts/list/ContactBrowseListFragment.java
@@ -137,6 +137,8 @@
 
     private ContactUriQueryHandler mQueryHandler;
 
+    private boolean mDelaySelection;
+
     private Handler getHandler() {
         if (mHandler == null) {
             mHandler = new Handler() {
@@ -288,6 +290,12 @@
         setSelectedContactUri(uri, true, true, true, false);
     }
 
+    @Override
+    public void setQueryString(String queryString, boolean delaySelection) {
+        mDelaySelection = delaySelection;
+        super.setQueryString(queryString, delaySelection);
+    }
+
     /**
      * Sets the new contact selection.
      *
@@ -436,14 +444,14 @@
             mLastSelectedPosition = selectedPosition;
         } else {
             if (isSearchMode()) {
-                selectFirstFoundContactAfterDelay();
-                if (mListener != null) {
-                    mListener.onSelectionChange();
+                if (mDelaySelection) {
+                    selectFirstFoundContactAfterDelay();
+                    if (mListener != null) {
+                        mListener.onSelectionChange();
+                    }
+                    return;
                 }
-                return;
-            }
-
-            if (mSelectionRequired) {
+            } else if (mSelectionRequired) {
                 // A specific contact was requested, but it's not in the loaded list.
 
                 // Try reconfiguring and reloading the list that will hopefully contain
@@ -460,12 +468,10 @@
                     notifyInvalidSelection();
                 }
                 return;
-            }
-
-            // If we were trying to load a specific contact, but that contact no longer
-            // exists, call the listener, which will adjust the filter.
-            if (mFilter != null
+            } else if (mFilter != null
                     && mFilter.filterType == ContactListFilter.FILTER_TYPE_SINGLE_CONTACT) {
+                // If we were trying to load a specific contact, but that contact no longer
+                // exists, call the listener, which will adjust the filter.
                 notifyInvalidSelection();
                 return;
             }
diff --git a/src/com/android/contacts/list/ContactEntryListFragment.java b/src/com/android/contacts/list/ContactEntryListFragment.java
index 903127b..e61232a 100644
--- a/src/com/android/contacts/list/ContactEntryListFragment.java
+++ b/src/com/android/contacts/list/ContactEntryListFragment.java
@@ -615,7 +615,7 @@
         return mQueryString;
     }
 
-    public void setQueryString(String queryString) {
+    public void setQueryString(String queryString, boolean delaySelection) {
         if (!TextUtils.equals(mQueryString, queryString)) {
             mQueryString = queryString;
             if (mAdapter != null) {