Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/optional long press toasts #714

Merged
merged 6 commits into from
Apr 2, 2017
Merged
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
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