Fix search highlighting

Bug: 10713067
Change-Id: I6fd3e6018619d61f7c69bbcaf2ad7475b20499a6
diff --git a/src/com/android/contacts/common/format/TextHighlighter.java b/src/com/android/contacts/common/format/TextHighlighter.java
index 648b1d5..496dcda 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 @@
     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 @@
         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 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 @@
 
         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 f6da990..ecb4110 100644
--- a/src/com/android/contacts/common/list/ContactListItemView.java
+++ b/src/com/android/contacts/common/list/ContactListItemView.java
@@ -235,7 +235,7 @@
         super(context);
         mContext = context;
 
-        mTextHighlighter = new TextHighlighter(Color.GREEN);
+        mTextHighlighter = new TextHighlighter(Typeface.BOLD);
     }
 
     public ContactListItemView(Context context, AttributeSet attrs) {
@@ -302,9 +302,8 @@
                 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);
diff --git a/tests/src/com/android/contacts/common/format/TextHighlighterTest.java b/tests/src/com/android/contacts/common/format/TextHighlighterTest.java
index f6962f8..b97542d 100644
--- a/tests/src/com/android/contacts/common/format/TextHighlighterTest.java
+++ b/tests/src/com/android/contacts/common/format/TextHighlighterTest.java
@@ -16,6 +16,7 @@
 
 package com.android.contacts.common.format;
 
+import android.graphics.Typeface;
 import android.test.suitebuilder.annotation.SmallTest;
 import android.text.SpannableString;
 
@@ -36,7 +37,7 @@
     @Override
     protected void setUp() throws Exception {
         super.setUp();
-        mTextHighlighter = new TextHighlighter(TEST_PREFIX_HIGHLIGHT_COLOR);
+        mTextHighlighter = new TextHighlighter(Typeface.BOLD);
     }
 
     public void testApply_EmptyPrefix() {