am cb11fced: Adding customized chip color support
* commit 'cb11fced23f3a08ad68ea61719d7f0fdeb0f7279':
Adding customized chip color support
diff --git a/res/values/attrs.xml b/res/values/attrs.xml
index d3500aa..be838bf 100644
--- a/res/values/attrs.xml
+++ b/res/values/attrs.xml
@@ -31,5 +31,9 @@
<enum name="bottom" value = "0"/>
<enum name="baseline" value = "1"/>
</attr>
+ <attr name="unselectedChipBackgroundColor" format="color" />
+ <attr name="selectedChipBackgroundColor" format="color" />
+ <attr name="unselectedChipTextColor" format="color" />
+ <attr name="selectedChipTextColor" format="color" />
</declare-styleable>
</resources>
\ No newline at end of file
diff --git a/src/com/android/ex/chips/RecipientEditTextView.java b/src/com/android/ex/chips/RecipientEditTextView.java
index c6bf29b..bcb7736 100644
--- a/src/com/android/ex/chips/RecipientEditTextView.java
+++ b/src/com/android/ex/chips/RecipientEditTextView.java
@@ -139,7 +139,10 @@
private static final int MAX_CHIPS_PARSED = 50;
- private static int sSelectedTextColor = -1;
+ private int mSelectedChipTextColor;
+ private int mUnselectedChipTextColor;
+ private int mSelectedChipBackgroundColor;
+ private int mUnselectedChipBackgroundColor;
// Work variables to avoid re-allocation on every typed character.
private final Rect mRect = new Rect();
@@ -263,9 +266,6 @@
super(context, attrs);
setChipDimensions(context, attrs);
mTextHeight = calculateTextHeight();
- if (sSelectedTextColor == -1) {
- sSelectedTextColor = context.getResources().getColor(android.R.color.white);
- }
mAlternatesPopup = new ListPopupWindow(context);
setupPopupWindow(mAlternatesPopup);
mAddressPopup = new ListPopupWindow(context);
@@ -666,9 +666,9 @@
* @param paint The paint to use to draw the bitmap.
*/
private Bitmap createSelectedChip(RecipientEntry contact, TextPaint paint) {
- paint.setColor(sSelectedTextColor);
+ paint.setColor(mSelectedChipTextColor);
final ChipBitmapContainer bitmapContainer = createChipBitmap(contact, paint,
- mChipBackgroundPressed, getResources().getColor(R.color.chip_background_selected));
+ mChipBackgroundPressed, mSelectedChipBackgroundColor);
if (bitmapContainer.loadIcon) {
loadAvatarIcon(contact, bitmapContainer);
@@ -684,7 +684,7 @@
* @param paint The paint to use to draw the bitmap.
*/
private Bitmap createUnselectedChip(RecipientEntry contact, TextPaint paint) {
- paint.setColor(getContext().getResources().getColor(android.R.color.black));
+ paint.setColor(getDefaultChipTextColor(contact));
ChipBitmapContainer bitmapContainer = createChipBitmap(contact, paint,
getChipBackground(contact), getDefaultChipBackgroundColor(contact));
@@ -860,9 +860,14 @@
return contact.isValid() ? mChipBackground : mInvalidChipBackground;
}
+ private int getDefaultChipTextColor(RecipientEntry contact) {
+ return contact.isValid() ? mUnselectedChipTextColor :
+ getResources().getColor(android.R.color.black);
+ }
+
private int getDefaultChipBackgroundColor(RecipientEntry contact) {
- return getResources().getColor(contact.isValid() ? R.color.chip_background :
- R.color.chip_background_invalid);
+ return contact.isValid() ? mUnselectedChipBackgroundColor :
+ getResources().getColor(R.color.chip_background_invalid);
}
/**
@@ -1013,6 +1018,21 @@
mMaxLines = r.getInteger(R.integer.chips_max_lines);
mLineSpacingExtra = r.getDimensionPixelOffset(R.dimen.line_spacing_extra);
+ mUnselectedChipTextColor = a.getColor(
+ R.styleable.RecipientEditTextView_unselectedChipTextColor,
+ r.getColor(android.R.color.black));
+
+ mSelectedChipTextColor = a.getColor(
+ R.styleable.RecipientEditTextView_selectedChipTextColor,
+ r.getColor(android.R.color.white));
+
+ mUnselectedChipBackgroundColor = a.getColor(
+ R.styleable.RecipientEditTextView_unselectedChipBackgroundColor,
+ r.getColor(R.color.chip_background));
+
+ mSelectedChipBackgroundColor = a.getColor(
+ R.styleable.RecipientEditTextView_selectedChipBackgroundColor,
+ r.getColor(R.color.chip_background_selected));
a.recycle();
}