summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSunny Goyal <sunnygoyal@google.com>2016-07-21 10:42:30 -0700
committerSunny Goyal <sunnygoyal@google.com>2016-07-22 13:17:30 -0700
commitce3fffb5fb446e031e52ee0c5f2a4a5cf86a8c81 (patch)
tree7f95627d9e96e445b5dc9f03d6ed2a02eca408f3
parent58368b15152052fb479891f0d3aba30ab3794fba (diff)
downloadandroid_packages_apps_Trebuchet-ce3fffb5fb446e031e52ee0c5f2a4a5cf86a8c81.tar.gz
android_packages_apps_Trebuchet-ce3fffb5fb446e031e52ee0c5f2a4a5cf86a8c81.tar.bz2
android_packages_apps_Trebuchet-ce3fffb5fb446e031e52ee0c5f2a4a5cf86a8c81.zip
Updating the search hint to contain the icon as a span object.
This makes the icon part of the hint text, and removes any need for custom focus event handling. Also the icon will now appear at the start of the text based on the direction of the text and not the direction of the layout Change-Id: I06c5cf99492d75b1005c69ec7c521cde0fdab010
-rw-r--r--res/layout/all_apps.xml14
-rw-r--r--src/com/android/launcher3/allapps/AllAppsContainerView.java14
-rw-r--r--src/com/android/launcher3/allapps/AllAppsSearchBarController.java27
-rw-r--r--src/com/android/launcher3/graphics/TintedDrawableSpan.java62
4 files changed, 77 insertions, 40 deletions
diff --git a/res/layout/all_apps.xml b/res/layout/all_apps.xml
index 822c8b687..5c2c4b869 100644
--- a/res/layout/all_apps.xml
+++ b/res/layout/all_apps.xml
@@ -65,18 +65,6 @@
android:orientation="horizontal"
android:saveEnabled="false">
- <TextView
- android:layout_width="wrap_content"
- android:layout_height="match_parent"
- android:gravity="center_vertical"
- android:id="@+id/search_hint"
- android:layout_gravity="center_horizontal"
- android:drawablePadding="@dimen/all_apps_search_bar_icon_margin_right"
- android:drawableStart="@drawable/ic_allapps_search"
- android:text="@string/all_apps_search_bar_hint"
- android:textColor="@drawable/all_apps_search_hint"
- android:textSize="16sp" />
-
<com.android.launcher3.ExtendedEditText
android:id="@+id/search_box_input"
android:layout_width="match_parent"
@@ -90,7 +78,7 @@
android:scrollHorizontally="true"
android:singleLine="true"
android:textColor="#4c4c4c"
- android:contentDescription="@string/all_apps_search_bar_hint"
+ android:hint="@string/all_apps_search_bar_hint"
android:textColorHint="@drawable/all_apps_search_hint"
android:textSize="16sp" />
</FrameLayout>
diff --git a/src/com/android/launcher3/allapps/AllAppsContainerView.java b/src/com/android/launcher3/allapps/AllAppsContainerView.java
index 3ef510c3f..8b1f95087 100644
--- a/src/com/android/launcher3/allapps/AllAppsContainerView.java
+++ b/src/com/android/launcher3/allapps/AllAppsContainerView.java
@@ -22,6 +22,8 @@ import android.graphics.Point;
import android.graphics.Rect;
import android.support.v7.widget.RecyclerView;
import android.text.Selection;
+import android.text.Spannable;
+import android.text.SpannableString;
import android.text.SpannableStringBuilder;
import android.text.method.TextKeyListener;
import android.util.AttributeSet;
@@ -47,6 +49,7 @@ import com.android.launcher3.Utilities;
import com.android.launcher3.Workspace;
import com.android.launcher3.config.FeatureFlags;
import com.android.launcher3.folder.Folder;
+import com.android.launcher3.graphics.TintedDrawableSpan;
import com.android.launcher3.keyboard.FocusedItemDecorator;
import com.android.launcher3.util.ComponentKey;
@@ -240,7 +243,6 @@ 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);
}
@@ -308,6 +310,16 @@ public class AllAppsContainerView extends BaseContainerView implements DragSourc
mSearchContainer = findViewById(R.id.search_container);
mSearchInput = (ExtendedEditText) findViewById(R.id.search_box_input);
+
+ // Update the hint to contain the icon.
+ // Prefix the original hint with two spaces. The first space gets replaced by the icon
+ // using span. The second space is used for a singe space character between the hint
+ // and the icon.
+ SpannableString spanned = new SpannableString(" " + mSearchInput.getHint());
+ spanned.setSpan(new TintedDrawableSpan(getContext(), R.drawable.ic_allapps_search),
+ 0, 1, Spannable.SPAN_EXCLUSIVE_INCLUSIVE);
+ mSearchInput.setHint(spanned);
+
mSearchContainerOffsetTop = getResources().getDimensionPixelSize(
R.dimen.all_apps_search_bar_margin_top);
diff --git a/src/com/android/launcher3/allapps/AllAppsSearchBarController.java b/src/com/android/launcher3/allapps/AllAppsSearchBarController.java
index b4a71caf8..ac3593238 100644
--- a/src/com/android/launcher3/allapps/AllAppsSearchBarController.java
+++ b/src/com/android/launcher3/allapps/AllAppsSearchBarController.java
@@ -39,8 +39,7 @@ import java.util.ArrayList;
* An interface to a search box that AllApps can command.
*/
public abstract class AllAppsSearchBarController
- implements TextWatcher, OnEditorActionListener, ExtendedEditText.OnBackKeyListener,
- View.OnFocusChangeListener {
+ implements TextWatcher, OnEditorActionListener, ExtendedEditText.OnBackKeyListener {
protected Launcher mLauncher;
protected AlphabeticalAppsList mApps;
@@ -50,8 +49,6 @@ public abstract class AllAppsSearchBarController
protected DefaultAppSearchAlgorithm mSearchAlgorithm;
protected InputMethodManager mInputMethodManager;
- protected View mHintView;
-
public void setVisibility(int visibility) {
mInput.setVisibility(visibility);
}
@@ -69,7 +66,6 @@ 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);
@@ -130,27 +126,6 @@ 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.
*/
diff --git a/src/com/android/launcher3/graphics/TintedDrawableSpan.java b/src/com/android/launcher3/graphics/TintedDrawableSpan.java
new file mode 100644
index 000000000..f72ce03f4
--- /dev/null
+++ b/src/com/android/launcher3/graphics/TintedDrawableSpan.java
@@ -0,0 +1,62 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.launcher3.graphics;
+
+import android.content.Context;
+import android.graphics.Canvas;
+import android.graphics.Paint;
+import android.graphics.Paint.FontMetricsInt;
+import android.graphics.drawable.Drawable;
+import android.text.style.DynamicDrawableSpan;
+
+/**
+ * {@link DynamicDrawableSpan} which draws a drawable tinted with the current paint color.
+ */
+public class TintedDrawableSpan extends DynamicDrawableSpan {
+
+ private final Drawable mDrawable;
+ private int mOldTint;
+
+ public TintedDrawableSpan(Context context, int resourceId) {
+ super(ALIGN_BOTTOM);
+ mDrawable = context.getDrawable(resourceId);
+ mOldTint = 0;
+ }
+
+ @Override
+ public int getSize(Paint paint, CharSequence text, int start, int end, FontMetricsInt fm) {
+ fm = fm == null ? paint.getFontMetricsInt() : fm;
+ int iconSize = fm.bottom - fm.top;
+ mDrawable.setBounds(0, 0, iconSize, iconSize);
+ return super.getSize(paint, text, start, end, fm);
+ }
+
+ @Override
+ public void draw(Canvas canvas, CharSequence text,
+ int start, int end, float x, int top, int y, int bottom, Paint paint) {
+ int color = paint.getColor();
+ if (mOldTint != color) {
+ mOldTint = color;
+ mDrawable.setTint(mOldTint);
+ }
+ super.draw(canvas, text, start, end, x, top, y, bottom, paint);
+ }
+
+ @Override
+ public Drawable getDrawable() {
+ return mDrawable;
+ }
+}