From 399e313f2c727083ac569d58de3761e3c6017401 Mon Sep 17 00:00:00 2001 From: rhettor Date: Mon, 21 Aug 2017 15:18:21 +0800 Subject: [PATCH] Adding motionless behavior mode --- app/src/main/res/layout/activity_three_tabs.xml | 1 + .../main/java/com/roughike/bottombar/BottomBar.java | 11 +++++++++-- .../java/com/roughike/bottombar/BottomBarTab.java | 13 +++++++++---- bottom-bar/src/main/res/values/attrs.xml | 1 + 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/app/src/main/res/layout/activity_three_tabs.xml b/app/src/main/res/layout/activity_three_tabs.xml index e1684096..e15c7273 100644 --- a/app/src/main/res/layout/activity_three_tabs.xml +++ b/app/src/main/res/layout/activity_three_tabs.xml @@ -17,6 +17,7 @@ android:layout_width="match_parent" android:layout_height="60dp" android:layout_alignParentBottom="true" + app:bb_behavior="motionless" app:bb_tabXmlResource="@xml/bottombar_tabs_three" /> \ No newline at end of file diff --git a/bottom-bar/src/main/java/com/roughike/bottombar/BottomBar.java b/bottom-bar/src/main/java/com/roughike/bottombar/BottomBar.java index 350cc316..8b207bf3 100644 --- a/bottom-bar/src/main/java/com/roughike/bottombar/BottomBar.java +++ b/bottom-bar/src/main/java/com/roughike/bottombar/BottomBar.java @@ -61,6 +61,7 @@ public class BottomBar extends LinearLayout implements View.OnClickListener, Vie private static final int BEHAVIOR_SHY = 2; private static final int BEHAVIOR_DRAW_UNDER_NAV = 4; private static final int BEHAVIOR_ICONS_ONLY = 8; + private static final int BEHAVIOR_MOTIONLESS = 16; private BatchTabPropertyApplier batchPropertyApplier; private int primaryColor; @@ -239,6 +240,10 @@ private boolean isIconsOnlyMode() { return !isTabletMode && hasBehavior(BEHAVIOR_ICONS_ONLY); } + private boolean isMotionlessMode() { + return !isTabletMode && hasBehavior(BEHAVIOR_MOTIONLESS); + } + private boolean hasBehavior(int behavior) { return (behaviors | behavior) == behaviors; } @@ -337,6 +342,8 @@ private void updateItems(final List bottomBarItems) { if (isShiftingMode()) { type = BottomBarTab.Type.SHIFTING; + } else if (isMotionlessMode()) { + type = BottomBarTab.Type.MOTIONLESS; } else if (isTabletMode) { type = BottomBarTab.Type.TABLET; } else { @@ -918,8 +925,8 @@ private void handleClick(BottomBarTab newTab) { return; } - oldTab.deselect(true); - newTab.select(true); + oldTab.deselect(!isMotionlessMode()); + newTab.select(!isMotionlessMode()); shiftingMagic(oldTab, newTab, true); handleBackgroundColorChange(newTab, true); diff --git a/bottom-bar/src/main/java/com/roughike/bottombar/BottomBarTab.java b/bottom-bar/src/main/java/com/roughike/bottombar/BottomBarTab.java index d33e1e30..bd7f944c 100644 --- a/bottom-bar/src/main/java/com/roughike/bottombar/BottomBarTab.java +++ b/bottom-bar/src/main/java/com/roughike/bottombar/BottomBarTab.java @@ -118,6 +118,7 @@ void prepareLayout() { int getLayoutResource() { int layoutResource; switch (type) { + case MOTIONLESS: case FIXED: layoutResource = R.layout.bb_bottom_bar_item_fixed; break; @@ -384,13 +385,16 @@ public Typeface getTitleTypeFace() { void select(boolean animate) { isActive = true; + boolean isMotionless = type == Type.MOTIONLESS; + int iconPaddingTop = isMotionless ? eightDps : sixDps; + if (animate) { animateIcon(activeAlpha, ACTIVE_SHIFTING_TITLELESS_ICON_SCALE); animateTitle(sixDps, ACTIVE_TITLE_SCALE, activeAlpha); animateColors(inActiveColor, activeColor); } else { setTitleScale(ACTIVE_TITLE_SCALE); - setTopPadding(sixDps); + setTopPadding(iconPaddingTop); setIconScale(ACTIVE_SHIFTING_TITLELESS_ICON_SCALE); setColors(activeColor); setAlphas(activeAlpha); @@ -407,9 +411,10 @@ void deselect(boolean animate) { isActive = false; boolean isShifting = type == Type.SHIFTING; + boolean isMotionless = type == Type.MOTIONLESS; - float titleScale = isShifting ? 0 : INACTIVE_FIXED_TITLE_SCALE; - int iconPaddingTop = isShifting ? sixteenDps : eightDps; + float titleScale = isMotionless ? ACTIVE_TITLE_SCALE: isShifting ? 0 : INACTIVE_FIXED_TITLE_SCALE; + int iconPaddingTop = isMotionless ? eightDps : isShifting ? sixteenDps : eightDps; if (animate) { animateTitle(iconPaddingTop, titleScale, inActiveAlpha); @@ -637,7 +642,7 @@ void restoreState(Bundle savedInstanceState) { } enum Type { - FIXED, SHIFTING, TABLET + MOTIONLESS, FIXED, SHIFTING, TABLET } public static class Config { diff --git a/bottom-bar/src/main/res/values/attrs.xml b/bottom-bar/src/main/res/values/attrs.xml index 8b382f4d..dbec2385 100644 --- a/bottom-bar/src/main/res/values/attrs.xml +++ b/bottom-bar/src/main/res/values/attrs.xml @@ -8,6 +8,7 @@ +