Skip to content

Commit

Permalink
Feature/optional long press toasts (#714)
Browse files Browse the repository at this point in the history
* Update CHANGELOG.md

* Update README.md

* Update README.md

* Made it possible to control whether or not the Toasts are shown when long pressing tabs.

* Updated changelog.
  • Loading branch information
roughike authored Apr 2, 2017
1 parent 4585fbd commit b602f67
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
21 changes: 20 additions & 1 deletion bottom-bar/src/main/java/com/roughike/bottombar/BottomBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ public class BottomBar extends LinearLayout implements View.OnClickListener, Vie
private int activeTabColor;
private int badgeBackgroundColor;
private boolean hideBadgeWhenActive;
private boolean longPressHintsEnabled;
private int titleTextAppearance;
private Typeface titleTypeFace;
private boolean showShadow;
Expand Down Expand Up @@ -198,6 +199,7 @@ private void populateAttributes(Context context, AttributeSet attrs, int defStyl
Color.WHITE : ContextCompat.getColor(context, R.color.bb_inActiveBottomBarItemColor);
int defaultActiveColor = isShiftingMode() ? Color.WHITE : primaryColor;

longPressHintsEnabled = ta.getBoolean(R.styleable.BottomBar_bb_longPressHintsEnabled, true);
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);
Expand Down Expand Up @@ -608,6 +610,17 @@ public BottomBarTab getTabWithId(@IdRes int tabId) {
return (BottomBarTab) tabContainer.findViewById(tabId);
}

/**
* Controls whether the long pressed tab title should be displayed in
* a helpful Toast if the title is not currently visible.
*
* @param enabled true if toasts should be shown to indicate the title
* of a long pressed tab, false otherwise.
*/
public void setLongPressHintsEnabled(boolean enabled) {
longPressHintsEnabled = enabled;
}

/**
* Set alpha value used for inactive BottomBarTabs.
*/
Expand Down Expand Up @@ -905,7 +918,13 @@ private void handleClick(BottomBarTab newTab) {
}

private boolean handleLongClick(BottomBarTab longClickedTab) {
if ((isShiftingMode() || isTabletMode) && !longClickedTab.isActive()) {
boolean areInactiveTitlesHidden = isShiftingMode() || isTabletMode;
boolean isClickedTitleHidden = !longClickedTab.isActive();
boolean shouldShowHint = areInactiveTitlesHidden
&& isClickedTitleHidden
&& longPressHintsEnabled;

if (shouldShowHint) {
Toast.makeText(getContext(), longClickedTab.getTitle(), Toast.LENGTH_SHORT).show();
}

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 @@ -9,6 +9,7 @@
<flag name="underNavbar" value="4" />
<flag name="iconsOnly" value="8" />
</attr>
<attr name="bb_longPressHintsEnabled" format="boolean" />
<attr name="bb_inActiveTabAlpha" format="float" />
<attr name="bb_activeTabAlpha" format="float" />
<attr name="bb_inActiveTabColor" format="color" />
Expand Down

0 comments on commit b602f67

Please sign in to comment.