diff options
author | cretin45 <cretin45@gmail.com> | 2014-07-25 11:36:19 -0700 |
---|---|---|
committer | Gerrit Code Review <gerrit@cyanogenmod.org> | 2015-11-17 14:54:54 -0800 |
commit | 5cd4157867399d6a3d2f4d1f8dceebb65665f44f (patch) | |
tree | 8dfd26719b299554d39058cd4e620e718408d4a3 | |
parent | 373e7e425b1f803024ccb254836bd1944db04ebc (diff) | |
download | android_packages_apps_ContactsCommon-5cd4157867399d6a3d2f4d1f8dceebb65665f44f.tar.gz android_packages_apps_ContactsCommon-5cd4157867399d6a3d2f4d1f8dceebb65665f44f.tar.bz2 android_packages_apps_ContactsCommon-5cd4157867399d6a3d2f4d1f8dceebb65665f44f.zip |
ContactsCommon: Add optional text highlight color
Change-Id: Ia2b7786ea32fc9cda029d90df7ba3f3ac4782fe4
-rw-r--r-- | res/values/colors.xml | 2 | ||||
-rw-r--r-- | src/com/android/contacts/common/format/TextHighlighter.java | 24 | ||||
-rw-r--r-- | src/com/android/contacts/common/list/ContactListItemView.java | 8 |
3 files changed, 29 insertions, 5 deletions
diff --git a/res/values/colors.xml b/res/values/colors.xml index bbf4d980..abc17977 100644 --- a/res/values/colors.xml +++ b/res/values/colors.xml @@ -118,6 +118,8 @@ <color name="letter_tile_font_color">#ffffff</color> + <color name="text_highlight_color">#3B77E7</color> + <!-- Background color of action bars. Ensure this stays in sync with packages/Telephony actionbar_background_color. --> <color name="actionbar_background_color">#0fc6dc</color> diff --git a/src/com/android/contacts/common/format/TextHighlighter.java b/src/com/android/contacts/common/format/TextHighlighter.java index 496dcdae..47b36e39 100644 --- a/src/com/android/contacts/common/format/TextHighlighter.java +++ b/src/com/android/contacts/common/format/TextHighlighter.java @@ -16,15 +16,12 @@ 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.text.style.StyleSpan; import android.widget.TextView; -import com.google.common.base.Preconditions; - /** * Highlights the text in a text field. */ @@ -33,12 +30,20 @@ public class TextHighlighter { private final static boolean DEBUG = false; private int mTextStyle; + private int mHighlightColor; private CharacterStyle mTextStyleSpan; + private CharacterStyle mTextColorStyleSpan; public TextHighlighter(int textStyle) { + this(textStyle, -1); + } + + public TextHighlighter(int textStyle, int highlightColor) { mTextStyle = textStyle; + mHighlightColor = highlightColor; mTextStyleSpan = getStyleSpan(); + mTextColorStyleSpan = getColorStyleSpan(); } /** @@ -56,6 +61,13 @@ public class TextHighlighter { return new StyleSpan(mTextStyle); } + private CharacterStyle getColorStyleSpan() { + if (mHighlightColor != -1) { + return new ForegroundColorSpan(mHighlightColor); + } + return null; + } + /** * Applies highlight span to the text. * @param text Text sequence to be highlighted. @@ -65,6 +77,9 @@ public class TextHighlighter { public void applyMaskingHighlight(SpannableString text, int start, int end) { /** Sets text color of the masked locations to be highlighted. */ text.setSpan(getStyleSpan(), start, end, 0); + if (mTextColorStyleSpan != null) { + text.setSpan(getColorStyleSpan(), start, end, 0); + } } /** @@ -90,6 +105,9 @@ public class TextHighlighter { if (index != -1) { final SpannableString result = new SpannableString(text); result.setSpan(mTextStyleSpan, index, index + trimmedPrefix.length(), 0 /* flags */); + if (mTextColorStyleSpan != null) { + result.setSpan(mTextColorStyleSpan, 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 d70aeb5b..8466e32c 100644 --- a/src/com/android/contacts/common/list/ContactListItemView.java +++ b/src/com/android/contacts/common/list/ContactListItemView.java @@ -231,7 +231,9 @@ public class ContactListItemView extends ViewGroup public ContactListItemView(Context context) { super(context); - mTextHighlighter = new TextHighlighter(Typeface.BOLD); + mTextHighlighter = new TextHighlighter(Typeface.BOLD, + context.getResources().getColor(R.color.text_highlight_color)); + mNameHighlightSequence = new ArrayList<HighlightSequence>(); mNumberHighlightSequence = new ArrayList<HighlightSequence>(); } @@ -284,7 +286,9 @@ public class ContactListItemView extends ViewGroup a.getDimensionPixelOffset( R.styleable.ContactListItemView_list_item_padding_bottom, 0)); - mTextHighlighter = new TextHighlighter(Typeface.BOLD); + mTextHighlighter = new TextHighlighter(Typeface.BOLD, + context.getResources().getColor(R.color.text_highlight_color)); + a.recycle(); |