Merge "Centered typing in search field" into ub-launcher3-calgary
This commit is contained in:
committed by
Android (Google) Code Review
commit
5b3ace8e56
@@ -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"
|
||||
|
||||
@@ -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.MotionEvent;
|
||||
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 @@ public class AllAppsContainerView extends BaseContainerView implements DragSourc
|
||||
}
|
||||
mSearchBarController = searchController;
|
||||
mSearchBarController.initialize(mApps, mSearchInput, mLauncher, this);
|
||||
mSearchBarController.setHintView(findViewById(R.id.search_hint));
|
||||
mAdapter.setSearchController(mSearchBarController);
|
||||
}
|
||||
|
||||
@@ -312,36 +311,6 @@ public class AllAppsContainerView extends BaseContainerView implements DragSourc
|
||||
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);
|
||||
|
||||
@@ -39,7 +39,8 @@ import java.util.ArrayList;
|
||||
* 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 @@ public abstract class AllAppsSearchBarController
|
||||
protected DefaultAppSearchAlgorithm mSearchAlgorithm;
|
||||
protected InputMethodManager mInputMethodManager;
|
||||
|
||||
protected View mHintView;
|
||||
|
||||
public void setVisibility(int visibility) {
|
||||
mInput.setVisibility(visibility);
|
||||
}
|
||||
@@ -66,6 +69,7 @@ public abstract class AllAppsSearchBarController
|
||||
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 @@ public abstract class AllAppsSearchBarController
|
||||
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.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user