Hide keyboard when next key is pressed

Also move some shared utility methods to DialerUtils

Bug: 16542561
Change-Id: Ibc574c24919bdcd11b0786fb9d22d29ff9c21bf1
diff --git a/src/com/android/dialer/DialtactsActivity.java b/src/com/android/dialer/DialtactsActivity.java
index 249e0c1..3d06a8e 100644
--- a/src/com/android/dialer/DialtactsActivity.java
+++ b/src/com/android/dialer/DialtactsActivity.java
@@ -731,14 +731,6 @@
         }
     }
 
-    private void hideInputMethod(View view) {
-        final InputMethodManager imm = (InputMethodManager) getSystemService(
-                Context.INPUT_METHOD_SERVICE);
-        if (imm != null && view != null) {
-            imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
-        }
-    }
-
     private void prepareVoiceSearchButton() {
         final Intent voiceIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
         if (canIntentBeHandled(voiceIntent)) {
@@ -940,7 +932,7 @@
             hideDialpadFragment(true, false);
         } else if (isInSearchUi()) {
             exitSearchUi();
-            hideInputMethod(parentLayout);
+            DialerUtils.hideInputMethod(parentLayout);
         } else {
             super.onBackPressed();
         }
@@ -952,7 +944,7 @@
     private boolean maybeExitSearchUi() {
         if (isInSearchUi() && TextUtils.isEmpty(mSearchQuery)) {
             exitSearchUi();
-            hideInputMethod(parentLayout);
+            DialerUtils.hideInputMethod(parentLayout);
             return true;
         }
         return false;
@@ -989,7 +981,7 @@
     public void onListFragmentScrollStateChange(int scrollState) {
         if (scrollState == OnScrollListener.SCROLL_STATE_TOUCH_SCROLL) {
             hideDialpadFragment(true, false);
-            hideInputMethod(getCurrentFocus());
+            DialerUtils.hideInputMethod(getCurrentFocus());
         }
     }
 
diff --git a/src/com/android/dialer/util/DialerUtils.java b/src/com/android/dialer/util/DialerUtils.java
index 07a330e..bd18133 100644
--- a/src/com/android/dialer/util/DialerUtils.java
+++ b/src/com/android/dialer/util/DialerUtils.java
@@ -26,6 +26,7 @@
 import android.provider.Telephony;
 import android.text.TextUtils;
 import android.view.View;
+import android.view.inputmethod.InputMethodManager;
 import android.widget.ImageView;
 import android.widget.TextView;
 import android.widget.Toast;
@@ -147,4 +148,20 @@
         return TextUtils.getLayoutDirectionFromLocale(Locale.getDefault()) ==
             View.LAYOUT_DIRECTION_RTL;
     }
+
+    public static void showInputMethod(View view) {
+        final InputMethodManager imm = (InputMethodManager) view.getContext().getSystemService(
+                Context.INPUT_METHOD_SERVICE);
+        if (imm != null) {
+            imm.showSoftInput(view, 0);
+        }
+    }
+
+    public static void hideInputMethod(View view) {
+        final InputMethodManager imm = (InputMethodManager) view.getContext().getSystemService(
+                Context.INPUT_METHOD_SERVICE);
+        if (imm != null) {
+            imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
+        }
+    }
 }
diff --git a/src/com/android/dialer/widget/SearchEditTextLayout.java b/src/com/android/dialer/widget/SearchEditTextLayout.java
index 36e5789..919f65c 100644
--- a/src/com/android/dialer/widget/SearchEditTextLayout.java
+++ b/src/com/android/dialer/widget/SearchEditTextLayout.java
@@ -19,15 +19,14 @@
 import android.animation.ValueAnimator;
 import android.animation.ValueAnimator.AnimatorUpdateListener;
 import android.content.Context;
-import android.graphics.Color;
 import android.util.AttributeSet;
 import android.view.KeyEvent;
 import android.view.View;
-import android.view.inputmethod.InputMethodManager;
 import android.widget.EditText;
 import android.widget.FrameLayout;
 
 import com.android.dialer.R;
+import com.android.dialer.util.DialerUtils;
 import com.android.phone.common.animation.AnimUtils;
 
 public class SearchEditTextLayout extends FrameLayout {
@@ -106,7 +105,9 @@
             @Override
             public void onFocusChange(View v, boolean hasFocus) {
                 if (hasFocus) {
-                    showInputMethod(v);
+                    DialerUtils.showInputMethod(v);
+                } else {
+                    DialerUtils.hideInputMethod(v);
                 }
             }
         });
@@ -261,14 +262,6 @@
         return mIsFadedOut;
     }
 
-    private void showInputMethod(View view) {
-        final InputMethodManager imm = (InputMethodManager) getContext().getSystemService(
-                Context.INPUT_METHOD_SERVICE);
-        if (imm != null) {
-            imm.showSoftInput(view, 0);
-        }
-    }
-
     /**
      * Assigns margins to the search box as a fraction of its maximum margin size
      *