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
15 changes: 13 additions & 2 deletions library/src/main/java/com/adroitandroid/chipcloud/Chip.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class Chip extends android.support.v7.widget.AppCompatTextView implements
private boolean selected = false;
private ChipListener listener = null;
private int selectedFontColor = -1;
private int backgroundDrawable = -1;
private int unselectedFontColor = -1;
private TransitionDrawable crossfader;
private int selectTransitionMS = 750;
Expand Down Expand Up @@ -46,12 +47,13 @@ public Chip(Context context, AttributeSet attrs, int defStyleAttr) {

public void initChip(Context context, int index, String label, Typeface typeface, int textSizePx,
boolean allCaps, int selectedColor, int selectedFontColor, int unselectedColor,
int unselectedFontColor, ChipCloud.Mode mode) {
int unselectedFontColor, ChipCloud.Mode mode,int backgroundDrawable) {

this.index = index;
this.selectedFontColor = selectedFontColor;
this.unselectedFontColor = unselectedFontColor;
this.mode = mode;
this.backgroundDrawable=backgroundDrawable;

Drawable selectedDrawable = ContextCompat.getDrawable(context, R.drawable.chip_selected);

Expand Down Expand Up @@ -168,6 +170,8 @@ private void setBackgroundCompat(Drawable background) {
} else {
setBackground(background);
}
if (backgroundDrawable != -1)
setBackgroundResource(backgroundDrawable);
}

public void deselect() {
Expand All @@ -191,6 +195,7 @@ public static class ChipBuilder {

private ChipListener chipListener;
private ChipCloud.Mode mode;
private int backgroundDrawable;

public ChipBuilder index(int index) {
this.index = index;
Expand Down Expand Up @@ -265,12 +270,18 @@ public ChipBuilder deselectTransitionMS(int deselectTransitionMS) {
public Chip build(Context context) {
Chip chip = (Chip) LayoutInflater.from(context).inflate(R.layout.chip, null);
chip.initChip(context, index, label, typeface, textSizePx, allCaps, selectedColor,
selectedFontColor, unselectedColor, unselectedFontColor, mode);
selectedFontColor, unselectedColor, unselectedFontColor, mode,backgroundDrawable);
chip.setSelectTransitionMS(selectTransitionMS);
chip.setDeselectTransitionMS(deselectTransitionMS);
chip.setChipListener(chipListener);
chip.setHeight(chipHeight);
return chip;
}

public ChipBuilder backgroundDrawable(int backgroundDrawable) {
this.backgroundDrawable = backgroundDrawable;
return this;

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public enum Mode {
private int selectedFontColor = -1;
private int unselectedColor = -1;
private int unselectedFontColor = -1;
private int backgroundDrawable = -1;
private int selectTransitionMS = 750;
private int deselectTransitionMS = 500;
private Mode mode = Mode.SINGLE;
Expand Down Expand Up @@ -48,6 +49,7 @@ public ChipCloud(Context context, AttributeSet attrs) {
unselectedFontColor = a.getColor(R.styleable.ChipCloud_deselectedFontColor, -1);
selectTransitionMS = a.getInt(R.styleable.ChipCloud_selectTransitionMS, 750);
deselectTransitionMS = a.getInt(R.styleable.ChipCloud_deselectTransitionMS, 500);
backgroundDrawable = a.getResourceId(R.styleable.ChipCloud_backgroundDrawable, -1);
String typefaceString = a.getString(R.styleable.ChipCloud_typeface);
if (typefaceString != null) {
typeface = Typeface.createFromAsset(getContext().getAssets(), typefaceString);
Expand Down Expand Up @@ -202,6 +204,7 @@ public void addChip(String label) {
.allCaps(allCaps)
.selectedColor(selectedColor)
.selectedFontColor(selectedFontColor)
.backgroundDrawable(backgroundDrawable)
.unselectedColor(unselectedColor)
.unselectedFontColor(unselectedFontColor)
.selectTransitionMS(selectTransitionMS)
Expand Down Expand Up @@ -273,6 +276,7 @@ public boolean isSelected(int index) {
public static class Configure {
private ChipCloud chipCloud;
private int selectedColor = -1;
private int backgroundDrawable = -1;
private int selectedFontColor = -1;
private int deselectedColor = -1;
private int deselectedFontColor = -1;
Expand Down Expand Up @@ -386,6 +390,7 @@ public void build() {
if (deselectTransitionMS != -1) chipCloud.setDeselectTransitionMS(deselectTransitionMS);
if (minHorizontalSpacing != -1) chipCloud.setMinimumHorizontalSpacing(minHorizontalSpacing);
if (verticalSpacing != -1) chipCloud.setVerticalSpacing(verticalSpacing);
if (backgroundDrawable != -1) chipCloud.setBackgroundDrawable(backgroundDrawable);
chipCloud.setChipListener(chipListener);
chipCloud.addChips(labels);
}
Expand All @@ -401,4 +406,8 @@ public void update() {
chipCloud.requestLayout();
}
}

private void setBackgroundDrawable(int backgroundDrawable) {
this.backgroundDrawable=backgroundDrawable;
}
}
1 change: 1 addition & 0 deletions library/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<attr name="selectedFontColor" format="color" />
<attr name="selectTransitionMS" format="integer" />
<attr name="deselectTransitionMS" format="integer" />
<attr name="backgroundDrawable" format="integer" />
<attr name="selectMode">
<enum name="single" value="0" />
<enum name="multi" value="1" />
Expand Down