diff options
Diffstat (limited to 'src/com/android/contacts/common/format/TextHighlighter.java')
-rw-r--r-- | src/com/android/contacts/common/format/TextHighlighter.java | 25 |
1 files changed, 14 insertions, 11 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; |