diff options
3 files changed, 19 insertions, 16 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); diff --git a/tests/src/com/android/contacts/common/format/TextHighlighterTest.java b/tests/src/com/android/contacts/common/format/TextHighlighterTest.java index f6962f8d..b97542d4 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 @@ public class TextHighlighterTest extends TestCase { @Override protected void setUp() throws Exception { super.setUp(); - mTextHighlighter = new TextHighlighter(TEST_PREFIX_HIGHLIGHT_COLOR); + mTextHighlighter = new TextHighlighter(Typeface.BOLD); } public void testApply_EmptyPrefix() { |