diff options
| author | Kaikai Wang <kaikai@google.com> | 2014-12-09 22:44:34 +0000 |
|---|---|---|
| committer | Android Git Automerger <android-git-automerger@android.com> | 2014-12-09 22:44:34 +0000 |
| commit | bf01ce471e52042bb4c072c4f8e5abb05f4b60f3 (patch) | |
| tree | 4463a20a77566271646c934a968539c76e369e96 | |
| parent | 2633ca91b7e5bcec29b2aaf80afa28451770aede (diff) | |
| parent | cb11fced23f3a08ad68ea61719d7f0fdeb0f7279 (diff) | |
| download | android_frameworks_opt_chips-bf01ce471e52042bb4c072c4f8e5abb05f4b60f3.tar.gz android_frameworks_opt_chips-bf01ce471e52042bb4c072c4f8e5abb05f4b60f3.tar.bz2 android_frameworks_opt_chips-bf01ce471e52042bb4c072c4f8e5abb05f4b60f3.zip | |
am cb11fced: Adding customized chip color support
* commit 'cb11fced23f3a08ad68ea61719d7f0fdeb0f7279':
Adding customized chip color support
| -rw-r--r-- | res/values/attrs.xml | 4 | ||||
| -rw-r--r-- | src/com/android/ex/chips/RecipientEditTextView.java | 38 |
2 files changed, 33 insertions, 9 deletions
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 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements 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 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements 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 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements * @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 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements * @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 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements 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 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements 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(); } |
