Skip to content

Commit

Permalink
Added full support for setting Badge background colors.
Browse files Browse the repository at this point in the history
  • Loading branch information
roughike committed Aug 27, 2016
1 parent cbf79aa commit 50dab15
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ public void whenInActiveColorSetProgrammatically_ColorIsUpdated() {
assertNotEquals(testColor, previousIconColor);
assertNotEquals(testColor, previousTitleColor);

bottomBar.setInActiveTabColor(Color.GREEN);
bottomBar.setInActiveTabColor(testColor);

assertEquals(testColor, inActiveTab.getInActiveColor());
assertEquals(testColor, inActiveTab.getCurrentDisplayedIconColor());
Expand All @@ -324,13 +324,29 @@ public void whenActiveColorSetProgrammatically_ColorIsUpdated() {
assertNotEquals(testColor, previousIconColor);
assertNotEquals(testColor, previousTitleColor);

bottomBar.setActiveTabColor(Color.GREEN);
bottomBar.setActiveTabColor(testColor);

assertEquals(testColor, activeTab.getActiveColor());
assertEquals(testColor, activeTab.getCurrentDisplayedIconColor());
assertEquals(testColor, activeTab.getCurrentDisplayedTitleColor());
}

@Test
@UiThreadTest
public void whenBadgeBackgroundColorSetProgrammatically_ColorIsUpdated() {
BottomBarTab inActiveTab = bottomBar.getTabAtPosition(1);
inActiveTab.setBadgeCount(3);

int previousBadgeColor = inActiveTab.getBadgeBackgroundColor();
int testColor = Color.GREEN;

assertNotEquals(testColor, previousBadgeColor);

bottomBar.setBadgeBackgroundColor(testColor);

assertEquals(testColor, inActiveTab.getBadgeBackgroundColor());
}

@Test
@UiThreadTest
public void whenTitleTextAppearanceSetProgrammatically_AppearanceUpdated() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public class BottomBar extends LinearLayout implements View.OnClickListener, Vie
private float activeTabAlpha;
private int inActiveTabColor;
private int activeTabColor;
private int badgeBackgroundColor;
private int titleTextAppearance;
private Typeface titleTypeFace;
private boolean showShadow;
Expand Down Expand Up @@ -139,6 +140,7 @@ private void populateAttributes(Context context, AttributeSet attrs) {

inActiveTabColor = ta.getColor(R.styleable.BottomBar_bb_inActiveTabColor, defaultInActiveColor);
activeTabColor = ta.getColor(R.styleable.BottomBar_bb_activeTabColor, defaultActiveColor);
badgeBackgroundColor = ta.getColor(R.styleable.BottomBar_bb_badgeBackgroundColor, Color.RED);
titleTextAppearance = ta.getResourceId(R.styleable.BottomBar_bb_titleTextAppearance, 0);
titleTypeFace = getTypeFaceFromAsset(ta.getString(R.styleable.BottomBar_bb_titleTypeFace));
showShadow = ta.getBoolean(R.styleable.BottomBar_bb_showShadow, true);
Expand Down Expand Up @@ -244,7 +246,7 @@ private BottomBarTab.Config getTabConfig() {
.inActiveTabColor(inActiveTabColor)
.activeTabColor(activeTabColor)
.barColorWhenSelected(defaultBackgroundColor)
.badgeBackgroundColor(Color.RED)
.badgeBackgroundColor(badgeBackgroundColor)
.titleTextAppearance(titleTextAppearance)
.titleTypeFace(titleTypeFace)
.build();
Expand Down Expand Up @@ -476,6 +478,11 @@ public void setActiveTabColor(@ColorInt int color) {
refreshTabs();
}

public void setBadgeBackgroundColor(@ColorInt int color) {
badgeBackgroundColor = color;
refreshTabs();
}

/**
* Set custom text apperance for all BottomBarTabs.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ void attachToTab(BottomBarTab tab, int backgroundColor) {
wrapTabAndBadgeInSameContainer(tab);
}

private void setColoredCircleBackground(int circleColor) {
void setColoredCircleBackground(int circleColor) {
int innerPadding = MiscUtils.dpToPixel(getContext(), 1);
ShapeDrawable backgroundCircle = BadgeCircle.make(innerPadding * 3, circleColor);
setPadding(innerPadding, innerPadding, innerPadding, innerPadding);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,10 @@ int getBadgeBackgroundColor() {

void setBadgeBackgroundColor(int badgeBackgroundColor) {
this.badgeBackgroundColor = badgeBackgroundColor;

if (badge != null) {
badge.setColoredCircleBackground(badgeBackgroundColor);
}
}

int getCurrentDisplayedIconColor() {
Expand Down
1 change: 1 addition & 0 deletions bottom-bar/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<attr name="bb_activeTabAlpha" format="float" />
<attr name="bb_inActiveTabColor" format="color" />
<attr name="bb_activeTabColor" format="color" />
<attr name="bb_badgeBackgroundColor" format="color" />
<attr name="bb_titleTextAppearance" format="reference" />
<attr name="bb_titleTypeFace" format="string" />
<attr name="bb_showShadow" format="boolean" />
Expand Down

0 comments on commit 50dab15

Please sign in to comment.