summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcretin45 <cretin45@gmail.com>2014-07-25 11:36:19 -0700
committerSteve Kondik <shade@chemlab.org>2014-12-04 17:03:46 +0000
commitffb6b0d7d1fe9e569bf570bc238eef99ad224a7a (patch)
tree9d2843c277a25e24005f83f0c8b05485b15d79a5
parent58511371fc0b12de39255ddbf742686d4e18b079 (diff)
downloadandroid_packages_apps_ContactsCommon-ffb6b0d7d1fe9e569bf570bc238eef99ad224a7a.tar.gz
android_packages_apps_ContactsCommon-ffb6b0d7d1fe9e569bf570bc238eef99ad224a7a.tar.bz2
android_packages_apps_ContactsCommon-ffb6b0d7d1fe9e569bf570bc238eef99ad224a7a.zip
ContactsCommon: Add optional text highlight color
Change-Id: Ia2b7786ea32fc9cda029d90df7ba3f3ac4782fe4
-rw-r--r--res/values/colors.xml2
-rw-r--r--src/com/android/contacts/common/format/TextHighlighter.java24
-rwxr-xr-xsrc/com/android/contacts/common/list/ContactListItemView.java8
3 files changed, 29 insertions, 5 deletions
diff --git a/res/values/colors.xml b/res/values/colors.xml
index 1da07fb8..c9698166 100644
--- a/res/values/colors.xml
+++ b/res/values/colors.xml
@@ -115,6 +115,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 0f523d66..146a4a29 100755
--- a/src/com/android/contacts/common/list/ContactListItemView.java
+++ b/src/com/android/contacts/common/list/ContactListItemView.java
@@ -242,7 +242,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>();
}
@@ -304,7 +306,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();