summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorYorke Lee <yorkelee@google.com>2013-09-12 12:38:41 -0700
committerYorke Lee <yorkelee@google.com>2013-09-12 12:38:41 -0700
commit42210256d3d584783ac2fb2742088ce57d9da766 (patch)
treedb9e42eec2b3c8407efc068eaef3a6e3870d2fc1 /src
parent675f39d654c1b905a26299baf8594d4c12177b88 (diff)
downloadpackages_apps_ContactsCommon-42210256d3d584783ac2fb2742088ce57d9da766.tar.gz
packages_apps_ContactsCommon-42210256d3d584783ac2fb2742088ce57d9da766.tar.bz2
packages_apps_ContactsCommon-42210256d3d584783ac2fb2742088ce57d9da766.zip
Fix search highlighting
Bug: 10713067 Change-Id: I6fd3e6018619d61f7c69bbcaf2ad7475b20499a6
Diffstat (limited to 'src')
-rw-r--r--src/com/android/contacts/common/format/TextHighlighter.java25
-rw-r--r--src/com/android/contacts/common/list/ContactListItemView.java7
2 files changed, 17 insertions, 15 deletions
diff --git a/src/com/android/contacts/common/format/TextHighlighter.java b/src/com/android/contacts/common/format/TextHighlighter.java
index 648b1d56..496dcdae 100644
--- a/src/com/android/contacts/common/format/TextHighlighter.java
+++ b/src/com/android/contacts/common/format/TextHighlighter.java
@@ -16,9 +16,11 @@
package com.android.contacts.common.format;
+import android.graphics.Typeface;
import android.text.SpannableString;
+import android.text.style.CharacterStyle;
import android.text.style.ForegroundColorSpan;
-import android.util.Log;
+import android.text.style.StyleSpan;
import android.widget.TextView;
import com.google.common.base.Preconditions;
@@ -30,12 +32,13 @@ public class TextHighlighter {
private final String TAG = TextHighlighter.class.getSimpleName();
private final static boolean DEBUG = false;
- private final int mTextHighlightColor;
+ private int mTextStyle;
- private ForegroundColorSpan mTextColorSpan;
+ private CharacterStyle mTextStyleSpan;
- public TextHighlighter(int textHighlightColor) {
- mTextHighlightColor = textHighlightColor;
+ public TextHighlighter(int textStyle) {
+ mTextStyle = textStyle;
+ mTextStyleSpan = getStyleSpan();
}
/**
@@ -49,6 +52,10 @@ public class TextHighlighter {
view.setText(applyPrefixHighlight(text, prefix));
}
+ private CharacterStyle getStyleSpan() {
+ return new StyleSpan(mTextStyle);
+ }
+
/**
* Applies highlight span to the text.
* @param text Text sequence to be highlighted.
@@ -57,7 +64,7 @@ public class TextHighlighter {
*/
public void applyMaskingHighlight(SpannableString text, int start, int end) {
/** Sets text color of the masked locations to be highlighted. */
- text.setSpan(new ForegroundColorSpan(mTextHighlightColor), start, end, 0);
+ text.setSpan(getStyleSpan(), start, end, 0);
}
/**
@@ -81,12 +88,8 @@ public class TextHighlighter {
int index = FormatUtils.indexOfWordPrefix(text, trimmedPrefix);
if (index != -1) {
- if (mTextColorSpan == null) {
- mTextColorSpan = new ForegroundColorSpan(mTextHighlightColor);
- }
-
final SpannableString result = new SpannableString(text);
- result.setSpan(mTextColorSpan, index, index + trimmedPrefix.length(), 0 /* flags */);
+ result.setSpan(mTextStyleSpan, index, index + trimmedPrefix.length(), 0 /* flags */);
return result;
} else {
return text;
diff --git a/src/com/android/contacts/common/list/ContactListItemView.java b/src/com/android/contacts/common/list/ContactListItemView.java
index f6da9903..ecb41109 100644
--- a/src/com/android/contacts/common/list/ContactListItemView.java
+++ b/src/com/android/contacts/common/list/ContactListItemView.java
@@ -235,7 +235,7 @@ public class ContactListItemView extends ViewGroup
super(context);
mContext = context;
- mTextHighlighter = new TextHighlighter(Color.GREEN);
+ mTextHighlighter = new TextHighlighter(Typeface.BOLD);
}
public ContactListItemView(Context context, AttributeSet attrs) {
@@ -302,9 +302,8 @@ public class ContactListItemView extends ViewGroup
a.getDimensionPixelOffset(
R.styleable.ContactListItemView_list_item_padding_bottom, 0));
- final int prefixHighlightColor = a.getColor(
- R.styleable.ContactListItemView_list_item_prefix_highlight_color, Color.GREEN);
- mTextHighlighter = new TextHighlighter(prefixHighlightColor);
+ mTextHighlighter = new TextHighlighter(Typeface.BOLD);
+
a.recycle();
a = getContext().obtainStyledAttributes(android.R.styleable.Theme);