Centered typing in search field

Change-Id: Iae46722195d0d06ff88da52df4fa48ca7b157512
diff --git a/res/layout/all_apps.xml b/res/layout/all_apps.xml
index ad1fa82..12a4029 100644
--- a/res/layout/all_apps.xml
+++ b/res/layout/all_apps.xml
@@ -87,7 +87,7 @@
                 android:layout_height="match_parent"
                 android:background="@android:color/transparent"
                 android:focusableInTouchMode="true"
-                android:gravity="start|center_vertical"
+                android:gravity="center"
                 android:imeOptions="actionSearch|flagNoExtractUi"
                 android:inputType="text|textNoSuggestions|textCapWords"
                 android:maxLines="1"
diff --git a/src/com/android/launcher3/allapps/AllAppsContainerView.java b/src/com/android/launcher3/allapps/AllAppsContainerView.java
index 195ab47..cc96934 100644
--- a/src/com/android/launcher3/allapps/AllAppsContainerView.java
+++ b/src/com/android/launcher3/allapps/AllAppsContainerView.java
@@ -15,7 +15,6 @@
  */
 package com.android.launcher3.allapps;
 
-import android.animation.ObjectAnimator;
 import android.annotation.SuppressLint;
 import android.content.Context;
 import android.content.res.Resources;
@@ -31,7 +30,6 @@
 import android.view.View;
 import android.view.ViewConfiguration;
 import android.view.ViewGroup;
-import android.view.animation.AnimationUtils;
 
 import com.android.launcher3.AppInfo;
 import com.android.launcher3.BaseContainerView;
@@ -242,6 +240,7 @@
         }
         mSearchBarController = searchController;
         mSearchBarController.initialize(mApps, mSearchInput, mLauncher, this);
+        mSearchBarController.setHintView(findViewById(R.id.search_hint));
         mAdapter.setSearchController(mSearchBarController);
     }
 
@@ -312,36 +311,6 @@
         mSearchContainerOffsetTop = getResources().getDimensionPixelSize(
                 R.dimen.all_apps_search_bar_margin_top);
 
-        final View searchHint = findViewById(R.id.search_hint);
-        final ObjectAnimator searchInputAnimator = ObjectAnimator.ofFloat(mSearchInput,
-                View.TRANSLATION_X, 0);
-        searchInputAnimator.setDuration(getContext().getResources().getInteger(
-                R.integer.config_searchHintAnimationDuration));
-        searchInputAnimator.setInterpolator(AnimationUtils.loadInterpolator(getContext(),
-                android.R.interpolator.accelerate_decelerate));
-
-        mSearchInput.setOnFocusChangeListener(new OnFocusChangeListener() {
-            @Override
-            public void onFocusChange(View view, boolean focused) {
-                if (focused) {
-                    searchHint.setVisibility(View.INVISIBLE);
-                    if (searchInputAnimator.isRunning()) {
-                        searchInputAnimator.end();
-                    }
-
-                    if (Utilities.isRtl(getContext().getResources())) {
-                        searchInputAnimator.setFloatValues(-searchHint.getLeft(), 0);
-                    } else {
-                        searchInputAnimator.setFloatValues(searchHint.getLeft(), 0);
-                    }
-                    searchInputAnimator.start();
-                } else {
-                    searchHint.setVisibility(View.VISIBLE);
-                    mSearchInput.setTranslationX(0);
-                }
-            }
-        });
-
         mElevationController = Utilities.ATLEAST_LOLLIPOP
                 ? new HeaderElevationController.ControllerVL(mSearchContainer)
                 : new HeaderElevationController.ControllerV16(mSearchContainer);
diff --git a/src/com/android/launcher3/allapps/AllAppsSearchBarController.java b/src/com/android/launcher3/allapps/AllAppsSearchBarController.java
index ac35932..b4a71ca 100644
--- a/src/com/android/launcher3/allapps/AllAppsSearchBarController.java
+++ b/src/com/android/launcher3/allapps/AllAppsSearchBarController.java
@@ -39,7 +39,8 @@
  * An interface to a search box that AllApps can command.
  */
 public abstract class AllAppsSearchBarController
-        implements TextWatcher, OnEditorActionListener, ExtendedEditText.OnBackKeyListener {
+        implements TextWatcher, OnEditorActionListener, ExtendedEditText.OnBackKeyListener,
+        View.OnFocusChangeListener {
 
     protected Launcher mLauncher;
     protected AlphabeticalAppsList mApps;
@@ -49,6 +50,8 @@
     protected DefaultAppSearchAlgorithm mSearchAlgorithm;
     protected InputMethodManager mInputMethodManager;
 
+    protected View mHintView;
+
     public void setVisibility(int visibility) {
         mInput.setVisibility(visibility);
     }
@@ -66,6 +69,7 @@
         mInput.addTextChangedListener(this);
         mInput.setOnEditorActionListener(this);
         mInput.setOnBackKeyListener(this);
+        mInput.setOnFocusChangeListener(this);
 
         mInputMethodManager = (InputMethodManager)
                 mInput.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
@@ -126,6 +130,27 @@
         return false;
     }
 
+    @Override
+    public void onFocusChange(View view, boolean focused) {
+        if (mHintView != null) {
+            mHintView.setVisibility(focused ? View.INVISIBLE : View.VISIBLE);
+        }
+    }
+
+    /**
+     * Sets a view to serve as the search field's hint.
+     */
+    public void setHintView(View hintView) {
+        mHintView = hintView;
+    }
+
+    /**
+     * Returns the search field's hint view.
+     */
+    public View getHintView() {
+        return mHintView;
+    }
+
     /**
      * Resets the search bar state.
      */