Skip to content

Commit

Permalink
Made it possible to have individual titleless tabs.
Browse files Browse the repository at this point in the history
  • Loading branch information
roughike committed Apr 2, 2017
1 parent 9fe6776 commit 4c32407
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,15 @@ public void correctBadgeHidingPolicies() {
assertTrue(tabs.get(4).getBadgeHidesWhenActive());
}

@Test
public void titlelessTabsAsExpected() {
assertFalse(tabs.get(0).isTitleless());
assertFalse(tabs.get(1).isTitleless());
assertTrue(tabs.get(2).isTitleless());
assertFalse(tabs.get(3).isTitleless());
assertTrue(tabs.get(4).isTitleless());
}

private Drawable getDrawableByResource(int iconResId) {
return ContextCompat.getDrawable(context, iconResId);
}
Expand Down
4 changes: 2 additions & 2 deletions bottom-bar/src/androidTest/res/xml/dummy_tabs_five.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<tabs>
<tab inActiveColor="#00FF00" activeColor="#FF0000" id="@+id/tab_recents" title="Recents" icon="@drawable/empty_icon" barColorWhenSelected="#FF0000" badgeBackgroundColor="#FF0000" badgeHidesWhenActive="false" />
<tab inActiveColor="#0000FF" activeColor="@color/test_random_color" id="@+id/tab_favorites" title="@string/favorites" icon="@drawable/empty_icon" barColorWhenSelected="#00FF00" badgeBackgroundColor="#00FF00" />
<tab inActiveColor="#FF0000" activeColor="#0000FF" id="@+id/tab_nearby" title="Nearby" icon="@drawable/empty_icon" barColorWhenSelected="#F00000" badgeBackgroundColor="#F00000" badgeHidesWhenActive="false" />
<tab inActiveColor="#FF0000" activeColor="#0000FF" id="@+id/tab_nearby" title="Nearby" icon="@drawable/empty_icon" barColorWhenSelected="#F00000" badgeBackgroundColor="#F00000" badgeHidesWhenActive="false" iconOnly="true" />
<tab inActiveColor="#F0F000" activeColor="@color/test_random_color_two" id="@+id/tab_friends" title="@string/friends" icon="@drawable/empty_icon" barColorWhenSelected="#00F000" badgeBackgroundColor="#00F000" badgeHidesWhenActive="true" />
<tab inActiveColor="#F00F00" activeColor="#F00F00" id="@+id/tab_food" title="Food" icon="@drawable/empty_icon" barColorWhenSelected="#00F0F0" badgeBackgroundColor="#00F0F0" />
<tab inActiveColor="#F00F00" activeColor="#F00F00" id="@+id/tab_food" title="Food" icon="@drawable/empty_icon" barColorWhenSelected="#00F0F0" badgeBackgroundColor="#00F0F0" iconOnly="true" />
</tabs>
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,10 @@ void setType(Type type) {
this.type = type;
}

boolean isTitleless() {
return isTitleless;
}

void setIsTitleless(boolean isTitleless) {
if (isTitleless && getIconResId() == 0) {
throw new IllegalStateException("This tab is supposed to be " +
Expand Down
18 changes: 17 additions & 1 deletion bottom-bar/src/main/java/com/roughike/bottombar/TabParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import static com.roughike.bottombar.TabParser.TabAttribute.ICON;
import static com.roughike.bottombar.TabParser.TabAttribute.ID;
import static com.roughike.bottombar.TabParser.TabAttribute.INACTIVE_COLOR;
import static com.roughike.bottombar.TabParser.TabAttribute.IS_TITLELESS;
import static com.roughike.bottombar.TabParser.TabAttribute.TITLE;

/**
Expand Down Expand Up @@ -137,6 +138,10 @@ private BottomBarTab parseNewTab(@NonNull XmlResourceParser parser, @IntRange(fr
boolean badgeHidesWhenActive = parser.getAttributeBooleanValue(i, true);
workingTab.setBadgeHidesWhenActive(badgeHidesWhenActive);
break;
case IS_TITLELESS:
boolean isTitleless = parser.getAttributeBooleanValue(i, false);
workingTab.setIsTitleless(isTitleless);
break;
}
}

Expand Down Expand Up @@ -175,7 +180,17 @@ private int getColorValue(@NonNull XmlResourceParser parser, @IntRange(from = 0)
}

@Retention(RetentionPolicy.SOURCE)
@StringDef({ID, ICON, TITLE, INACTIVE_COLOR, ACTIVE_COLOR, BAR_COLOR_WHEN_SELECTED, BADGE_BACKGROUND_COLOR, BADGE_HIDES_WHEN_ACTIVE})
@StringDef({
ID,
ICON,
TITLE,
INACTIVE_COLOR,
ACTIVE_COLOR,
BAR_COLOR_WHEN_SELECTED,
BADGE_BACKGROUND_COLOR,
BADGE_HIDES_WHEN_ACTIVE,
IS_TITLELESS
})
@interface TabAttribute {
String ID = "id";
String ICON = "icon";
Expand All @@ -185,6 +200,7 @@ private int getColorValue(@NonNull XmlResourceParser parser, @IntRange(from = 0)
String BAR_COLOR_WHEN_SELECTED = "barColorWhenSelected";
String BADGE_BACKGROUND_COLOR = "badgeBackgroundColor";
String BADGE_HIDES_WHEN_ACTIVE = "badgeHidesWhenActive";
String IS_TITLELESS = "iconOnly";
}

@SuppressWarnings("WeakerAccess")
Expand Down

0 comments on commit 4c32407

Please sign in to comment.