diff --git a/hashtag-view/src/main/java/com/greenfrvr/hashtagview/HashtagView.java b/hashtag-view/src/main/java/com/greenfrvr/hashtagview/HashtagView.java index edfde82..84d3058 100644 --- a/hashtag-view/src/main/java/com/greenfrvr/hashtagview/HashtagView.java +++ b/hashtag-view/src/main/java/com/greenfrvr/hashtagview/HashtagView.java @@ -116,6 +116,7 @@ public class HashtagView extends LinearLayout { private SortState sortState = SortState.initState(); private ColorStateList itemTextColorStateList; + private ColorStateList itemSelectedTextColorStateList; private int itemMargin; private int itemPaddingLeft; private int itemPaddingRight; @@ -135,6 +136,7 @@ public class HashtagView extends LinearLayout { private int rowCount; private int composeMode; private int backgroundDrawable; + private int selectedBackgroundDrawable; private int foregroundDrawable; private int leftDrawable; private int leftSelectedDrawable; @@ -401,7 +403,7 @@ public void setSelectionLimit(int selectionLimit) { if (viewMap != null) { for (ItemData item : viewMap.values()) { item.isSelected = false; - item.displaySelection(leftDrawable, leftSelectedDrawable, rightDrawable, rightSelectedDrawable); + item.displaySelection(leftDrawable, leftSelectedDrawable, rightDrawable, rightSelectedDrawable, backgroundDrawable, selectedBackgroundDrawable, itemTextColorStateList, itemSelectedTextColorStateList); item.decorateText(transformer); } } @@ -449,6 +451,10 @@ public void setItemTextColor(int textColor) { this.itemTextColorStateList = ColorStateList.valueOf(textColor); } + public void setItemSelectedTextColor(int textColor) { + this.itemSelectedTextColorStateList = ColorStateList.valueOf(textColor); + } + public void setItemTextColorRes(@ColorRes int textColor) { int colorValue = ContextCompat.getColor(getContext(), textColor); this.itemTextColorStateList = ColorStateList.valueOf(colorValue); @@ -507,6 +513,10 @@ public void setBackgroundDrawable(@DrawableRes int backgroundDrawable) { this.backgroundDrawable = backgroundDrawable; } + public void setSelectedBackgroundDrawable(@DrawableRes int selectedBackgroundDrawable) { + this.selectedBackgroundDrawable = selectedBackgroundDrawable; + } + public void setBackgroundColor(@ColorRes int backgroundDrawable) { this.backgroundDrawable = backgroundDrawable; } @@ -570,6 +580,8 @@ private void extractAttributes(AttributeSet attrs) { composeMode = a.getInt(R.styleable.HashtagView_composeMode, COMPOSE_ORIGIN); backgroundDrawable = a.getResourceId(R.styleable.HashtagView_tagBackground, 0); + selectedBackgroundDrawable = a.getResourceId(R.styleable.HashtagView_tagSelectedBackground, 0); + if (selectedBackgroundDrawable == 0) selectedBackgroundDrawable = backgroundDrawable; foregroundDrawable = a.getResourceId(R.styleable.HashtagView_tagForeground, 0); leftDrawable = a.getResourceId(R.styleable.HashtagView_tagDrawableLeft, 0); leftSelectedDrawable = a.getResourceId(R.styleable.HashtagView_tagSelectedDrawableLeft, 0); @@ -577,9 +589,13 @@ private void extractAttributes(AttributeSet attrs) { rightSelectedDrawable = a.getResourceId(R.styleable.HashtagView_tagSelectedDrawableRight, 0); itemTextColorStateList = a.getColorStateList(R.styleable.HashtagView_tagTextColor); + itemSelectedTextColorStateList = a.getColorStateList(R.styleable.HashtagView_tagSelectedTextColor); if (itemTextColorStateList == null) { itemTextColorStateList = ColorStateList.valueOf(Color.BLACK); } + if (itemSelectedTextColorStateList == null) { + itemSelectedTextColorStateList = itemTextColorStateList; + } isInSelectMode = a.getBoolean(R.styleable.HashtagView_selectionMode, false); isDynamic = a.getBoolean(R.styleable.HashtagView_dynamicMode, false); @@ -667,7 +683,7 @@ private void setItemPreselected(ItemData item) { item.isSelected = selection; item.decorateText(transformer); - item.displaySelection(leftDrawable, leftSelectedDrawable, rightDrawable, rightSelectedDrawable); + item.displaySelection(leftDrawable, leftSelectedDrawable, rightDrawable, rightSelectedDrawable, backgroundDrawable, selectedBackgroundDrawable, itemTextColorStateList, itemSelectedTextColorStateList); } } @@ -823,7 +839,7 @@ private void handleSelection(ItemData item) { } } - item.select(leftDrawable, leftSelectedDrawable, rightDrawable, rightSelectedDrawable); + item.select(leftDrawable, leftSelectedDrawable, rightDrawable, rightSelectedDrawable, backgroundDrawable, selectedBackgroundDrawable, itemTextColorStateList, itemSelectedTextColorStateList); item.decorateText(transformer); if (selectListeners != null) { diff --git a/hashtag-view/src/main/java/com/greenfrvr/hashtagview/ItemData.java b/hashtag-view/src/main/java/com/greenfrvr/hashtagview/ItemData.java index f117e38..cbd147e 100644 --- a/hashtag-view/src/main/java/com/greenfrvr/hashtagview/ItemData.java +++ b/hashtag-view/src/main/java/com/greenfrvr/hashtagview/ItemData.java @@ -1,5 +1,6 @@ package com.greenfrvr.hashtagview; +import android.content.res.ColorStateList; import android.support.annotation.NonNull; import android.view.View; import android.widget.TextView; @@ -25,15 +26,18 @@ void setText(CharSequence charSequence) { ((TextView) view.findViewById(R.id.text)).setText(charSequence); } - void displaySelection(int left, int leftSelected, int right, int rightSelected) { - ((TextView) view.findViewById(R.id.text)).setCompoundDrawablesWithIntrinsicBounds(isSelected ? leftSelected : left, 0, isSelected ? rightSelected : right, 0); + void displaySelection(int left, int leftSelected, int right, int rightSelected, int background, int selectedBackground, ColorStateList textColor, ColorStateList selectedTextColor) { + view.setBackgroundResource(isSelected ? selectedBackground : background); + TextView textView = (TextView) view.findViewById(R.id.text); + textView.setCompoundDrawablesWithIntrinsicBounds(isSelected ? leftSelected : left, 0, isSelected ? rightSelected : right, 0); + textView.setTextColor(isSelected ? selectedTextColor : textColor); view.setSelected(isSelected); view.invalidate(); } - void select(int left, int leftSelected, int right, int rightSelected) { + void select(int left, int leftSelected, int right, int rightSelected, int background, int selectedBackground, ColorStateList textColor, ColorStateList selectedTextColor) { isSelected = !isSelected; - displaySelection(left, leftSelected, right, rightSelected); + displaySelection(left, leftSelected, right, rightSelected, background, selectedBackground, textColor, selectedTextColor); } void decorateText(HashtagView.DataTransform transformer) { diff --git a/hashtag-view/src/main/res/layout/layout_item.xml b/hashtag-view/src/main/res/layout/layout_item.xml index c0d4a21..954d819 100644 --- a/hashtag-view/src/main/res/layout/layout_item.xml +++ b/hashtag-view/src/main/res/layout/layout_item.xml @@ -9,5 +9,5 @@ android:id="@+id/text" android:layout_width="match_parent" android:layout_height="wrap_content" - android:singleLine="true"/> + android:maxLines="1"/> diff --git a/hashtag-view/src/main/res/values/attrs.xml b/hashtag-view/src/main/res/values/attrs.xml index 9654f5e..1288f25 100644 --- a/hashtag-view/src/main/res/values/attrs.xml +++ b/hashtag-view/src/main/res/values/attrs.xml @@ -3,6 +3,7 @@ + @@ -16,6 +17,7 @@ +