Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -570,16 +580,22 @@ 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);
rightDrawable = a.getResourceId(R.styleable.HashtagView_tagDrawableRight, 0);
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);
Expand Down Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<T> transformer) {
Expand Down
2 changes: 1 addition & 1 deletion hashtag-view/src/main/res/layout/layout_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
android:id="@+id/text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="true"/>
android:maxLines="1"/>
</FrameLayout>
2 changes: 2 additions & 0 deletions hashtag-view/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

<declare-styleable name="HashtagView">
<attr name="tagTextColor" format="color|reference"/>
<attr name="tagSelectedTextColor" format="color|reference"/>
<attr name="tagTextSize" format="dimension"/>
<attr name="tagTextGravity" format="enum">
<enum name="left" value="3"/>
Expand All @@ -16,6 +17,7 @@
<enum name="marquee" value="3"/>
</attr>
<attr name="tagBackground" format="color|reference"/>
<attr name="tagSelectedBackground" format="color|reference"/>
<attr name="tagForeground" format="color|reference"/>
<attr name="tagDrawableLeft" format="reference"/>
<attr name="tagSelectedDrawableLeft" format="reference"/>
Expand Down