Keyboard now closes in regular search when user scrolls list.

This change also enables search actions to be visible in regular search.
screenshot: http://screen/ULBgq2RnKnM
Bug: 68730642,67657783,68775021,66723880
Test: manual
PiperOrigin-RevId: 175892821
Change-Id: I2c71fe8ffa2ffddfbc88d777909c4837e0ea4384
diff --git a/java/com/android/dialer/app/DialtactsActivity.java b/java/com/android/dialer/app/DialtactsActivity.java
index 269e598..d9a63fa 100644
--- a/java/com/android/dialer/app/DialtactsActivity.java
+++ b/java/com/android/dialer/app/DialtactsActivity.java
@@ -96,6 +96,7 @@
 import com.android.dialer.callintent.CallSpecificAppData;
 import com.android.dialer.common.Assert;
 import com.android.dialer.common.LogUtil;
+import com.android.dialer.common.UiUtil;
 import com.android.dialer.common.concurrent.ThreadUtil;
 import com.android.dialer.configprovider.ConfigProviderBindings;
 import com.android.dialer.constants.ActivityRequestCodes;
@@ -178,6 +179,7 @@
   private static final String KEY_IN_DIALPAD_SEARCH_UI = "in_dialpad_search_ui";
   private static final String KEY_IN_NEW_SEARCH_UI = "in_new_search_ui";
   private static final String KEY_SEARCH_QUERY = "search_query";
+  private static final String KEY_DIALPAD_QUERY = "dialpad_query";
   private static final String KEY_FIRST_LAUNCH = "first_launch";
   private static final String KEY_WAS_CONFIGURATION_CHANGE = "was_configuration_change";
   private static final String KEY_IS_DIALPAD_SHOWN = "is_dialpad_shown";
@@ -439,6 +441,7 @@
           .commit();
     } else {
       mSearchQuery = savedInstanceState.getString(KEY_SEARCH_QUERY);
+      mDialpadQuery = savedInstanceState.getString(KEY_DIALPAD_QUERY);
       mInRegularSearch = savedInstanceState.getBoolean(KEY_IN_REGULAR_SEARCH_UI);
       mInDialpadSearch = savedInstanceState.getBoolean(KEY_IN_DIALPAD_SEARCH_UI);
       mInNewSearch = savedInstanceState.getBoolean(KEY_IN_NEW_SEARCH_UI);
@@ -654,6 +657,7 @@
     LogUtil.enterBlock("DialtactsActivity.onSaveInstanceState");
     super.onSaveInstanceState(outState);
     outState.putString(KEY_SEARCH_QUERY, mSearchQuery);
+    outState.putString(KEY_DIALPAD_QUERY, mDialpadQuery);
     outState.putBoolean(KEY_IN_REGULAR_SEARCH_UI, mInRegularSearch);
     outState.putBoolean(KEY_IN_DIALPAD_SEARCH_UI, mInDialpadSearch);
     outState.putBoolean(KEY_IN_NEW_SEARCH_UI, mInNewSearch);
@@ -1425,6 +1429,21 @@
   }
 
   @Override
+  public boolean onSearchListTouch(MotionEvent event) {
+    if (mIsDialpadShown) {
+      PerformanceReport.recordClick(UiAction.Type.CLOSE_DIALPAD);
+      hideDialpadFragment(true, false);
+      if (TextUtils.isEmpty(mDialpadQuery)) {
+        exitSearchUi();
+      }
+      return true;
+    } else {
+      UiUtil.hideKeyboardFrom(this, mSearchEditTextLayout);
+    }
+    return false;
+  }
+
+  @Override
   public void onListFragmentScrollStateChange(int scrollState) {
     PerformanceReport.recordScrollStateChange(scrollState);
     if (scrollState == OnScrollListener.SCROLL_STATE_TOUCH_SCROLL) {
@@ -1659,17 +1678,6 @@
   }
 
   @Override
-  public boolean onSearchListTouch(MotionEvent event) {
-    if (mIsDialpadShown) {
-      hideDialpadFragment(true, false);
-      if (TextUtils.isEmpty(mDialpadQuery)) {
-        exitSearchUi();
-      }
-    }
-    return false;
-  }
-
-  @Override
   public void onCallPlaced() {
     if (mIsDialpadShown) {
       hideDialpadFragment(false, true);
diff --git a/java/com/android/dialer/searchfragment/list/NewSearchFragment.java b/java/com/android/dialer/searchfragment/list/NewSearchFragment.java
index 8306d37..93263ce 100644
--- a/java/com/android/dialer/searchfragment/list/NewSearchFragment.java
+++ b/java/com/android/dialer/searchfragment/list/NewSearchFragment.java
@@ -32,6 +32,7 @@
 import android.support.v13.app.FragmentCompat;
 import android.support.v7.widget.LinearLayoutManager;
 import android.support.v7.widget.RecyclerView;
+import android.telephony.PhoneNumberUtils;
 import android.text.TextUtils;
 import android.view.LayoutInflater;
 import android.view.MotionEvent;
@@ -444,7 +445,9 @@
    * the list of supported actions, see {@link SearchActionViewHolder.Action}.
    */
   private List<Integer> getActions() {
-    if (TextUtils.isEmpty(query) || query.length() == 1 || isRegularSearch()) {
+    boolean nonDialableQueryInRegularSearch =
+        isRegularSearch() && !PhoneNumberUtils.isGlobalPhoneNumber(query);
+    if (TextUtils.isEmpty(query) || query.length() == 1 || nonDialableQueryInRegularSearch) {
       return Collections.emptyList();
     }