Permalink
...
Comparing changes
Open a pull request
- 5 commits
- 6 files changed
- 0 commit comments
- 1 contributor
Unified
Split
Showing
with
84 additions
and 43 deletions.
- +1 −1 bottom-bar/bottom-bar.iml
- +1 −1 bottom-bar/build.gradle
- +80 −40 bottom-bar/src/main/java/com/roughike/bottombar/BottomBar.java
- +2 −1 bottom-bar/src/main/res/layout/bb_bottom_bar_item_container.xml
- 0 ...layout-sw600dp/bb_bottom_bar_item_container.xml → layout/bb_bottom_bar_item_container_tablet.xml}
- 0 ...in/res/{layout-sw600dp/bb_bottom_bar_item_fixed.xml → layout/bb_bottom_bar_item_fixed_tablet.xml}
View
2
bottom-bar/bottom-bar.iml
| @@ -1,5 +1,5 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| -<module external.linked.project.id=":bottom-bar" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="com.roughike" external.system.module.version="1.1.4" type="JAVA_MODULE" version="4"> | ||
| +<module external.linked.project.id=":bottom-bar" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="com.roughike" external.system.module.version="1.1.5" type="JAVA_MODULE" version="4"> | ||
| <component name="FacetManager"> | ||
| <facet type="android-gradle" name="Android-Gradle"> | ||
| <configuration> | ||
View
2
bottom-bar/build.gradle
| @@ -13,7 +13,7 @@ ext { | ||
| siteUrl = 'https://github.com/roughike/BottomBar' | ||
| gitUrl = 'https://github.com/roughike/BottomBar.git' | ||
| - libraryVersion = '1.1.4' | ||
| + libraryVersion = '1.1.5' | ||
| developerId = 'roughike' | ||
| developerName = 'Iiro Krankka' | ||
View
120
bottom-bar/src/main/java/com/roughike/bottombar/BottomBar.java
| @@ -61,8 +61,10 @@ | ||
| private static final String TAG_BOTTOM_BAR_VIEW_ACTIVE = "BOTTOM_BAR_VIEW_ACTIVE"; | ||
| private Context mContext; | ||
| + private boolean mIgnoreTabletLayout; | ||
| private boolean mIsTabletMode; | ||
| private boolean mIsShy; | ||
| + private boolean mShyHeightAlreadyCalculated; | ||
| private boolean mUseExtraOffset; | ||
| private ViewGroup mUserContentContainer; | ||
| @@ -73,6 +75,7 @@ | ||
| private View mBackgroundOverlay; | ||
| private View mShadowView; | ||
| private View mTabletRightBorder; | ||
| + private View mPendingUserContentView; | ||
| private int mPrimaryColor; | ||
| private int mInActiveColor; | ||
| @@ -130,13 +133,16 @@ public static BottomBar attach(Activity activity, Bundle savedInstanceState) { | ||
| View oldLayout = contentView.getChildAt(0); | ||
| contentView.removeView(oldLayout); | ||
| - bottomBar.getUserContainer() | ||
| - .addView(oldLayout, 0, oldLayout.getLayoutParams()); | ||
| + bottomBar.setPendingUserContentView(oldLayout); | ||
| contentView.addView(bottomBar, 0); | ||
| return bottomBar; | ||
| } | ||
| + private void setPendingUserContentView(View oldLayout) { | ||
| + mPendingUserContentView = oldLayout; | ||
| + } | ||
| + | ||
| /** | ||
| * Bind the BottomBar to the specified View's parent, and inflate | ||
| * your layout there. Useful when the BottomBar overlaps some content | ||
| @@ -159,17 +165,10 @@ public static BottomBar attach(View view, Bundle savedInstanceState) { | ||
| View oldLayout = contentView.getChildAt(0); | ||
| contentView.removeView(oldLayout); | ||
| - bottomBar.getUserContainer() | ||
| - .addView(oldLayout, oldLayout.getLayoutParams()); | ||
| + bottomBar.setPendingUserContentView(oldLayout); | ||
| contentView.addView(bottomBar, 0); | ||
| } else { | ||
| - if (view.getLayoutParams() == null) { | ||
| - bottomBar.getUserContainer() | ||
| - .addView(view, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); | ||
| - } else { | ||
| - bottomBar.getUserContainer() | ||
| - .addView(view, view.getLayoutParams()); | ||
| - } | ||
| + bottomBar.setPendingUserContentView(view); | ||
| } | ||
| return bottomBar; | ||
| @@ -191,24 +190,6 @@ public static BottomBar attachShy(CoordinatorLayout coordinatorLayout, Bundle sa | ||
| bottomBar.toughChildHood(ViewCompat.getFitsSystemWindows(coordinatorLayout)); | ||
| bottomBar.onRestoreInstanceState(savedInstanceState); | ||
| - if (!coordinatorLayout.getContext().getResources().getBoolean(R.bool.bb_bottom_bar_is_tablet_mode)) { | ||
| - bottomBar.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { | ||
| - @SuppressWarnings("deprecation") | ||
| - @Override | ||
| - public void onGlobalLayout() { | ||
| - ((CoordinatorLayout.LayoutParams) bottomBar.getLayoutParams()) | ||
| - .setBehavior(new BottomNavigationBehavior(bottomBar.getOuterContainer().getHeight(), 0)); | ||
| - ViewTreeObserver obs = bottomBar.getViewTreeObserver(); | ||
| - | ||
| - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { | ||
| - obs.removeOnGlobalLayoutListener(this); | ||
| - } else { | ||
| - obs.removeGlobalOnLayoutListener(this); | ||
| - } | ||
| - } | ||
| - }); | ||
| - } | ||
| - | ||
| coordinatorLayout.addView(bottomBar); | ||
| return bottomBar; | ||
| } | ||
| @@ -517,6 +498,20 @@ public void noNavBarGoodness() { | ||
| } | ||
| /** | ||
| + * Force the BottomBar to behave exactly same on tablets and phones, | ||
| + * instead of showing a left menu on tablets. | ||
| + */ | ||
| + public void noTabletGoodness() { | ||
| + if (mItems != null) { | ||
| + throw new UnsupportedOperationException("This BottomBar already has items! " + | ||
| + "You must call noTabletGoodness() before setting the items, preferably " + | ||
| + "right after attaching it to your layout."); | ||
| + } | ||
| + | ||
| + mIgnoreTabletLayout = true; | ||
| + } | ||
| + | ||
| + /** | ||
| * Super ugly hacks | ||
| * ----------------------------/ | ||
| */ | ||
| @@ -573,16 +568,16 @@ private void init(Context context, AttributeSet attrs, int defStyleAttr, int def | ||
| mTwoDp = MiscUtils.dpToPixel(mContext, 2); | ||
| mTenDp = MiscUtils.dpToPixel(mContext, 10); | ||
| mMaxFixedItemWidth = MiscUtils.dpToPixel(mContext, 168); | ||
| - | ||
| - initializeViews(); | ||
| } | ||
| - | ||
| private void initializeViews() { | ||
| - View rootView = View.inflate(mContext, R.layout.bb_bottom_bar_item_container, null); | ||
| + mIsTabletMode = !mIgnoreTabletLayout && | ||
| + mContext.getResources().getBoolean(R.bool.bb_bottom_bar_is_tablet_mode); | ||
| + View rootView = View.inflate(mContext, mIsTabletMode ? | ||
| + R.layout.bb_bottom_bar_item_container_tablet : R.layout.bb_bottom_bar_item_container, | ||
| + null); | ||
| mTabletRightBorder = rootView.findViewById(R.id.bb_tablet_right_border); | ||
| - mIsTabletMode = mTabletRightBorder != null; | ||
| mUserContentContainer = (ViewGroup) rootView.findViewById(R.id.bb_user_content_container); | ||
| mShadowView = rootView.findViewById(R.id.bb_bottom_bar_shadow); | ||
| @@ -593,6 +588,38 @@ private void initializeViews() { | ||
| mBackgroundView = rootView.findViewById(R.id.bb_bottom_bar_background_view); | ||
| mBackgroundOverlay = rootView.findViewById(R.id.bb_bottom_bar_background_overlay); | ||
| + if (mPendingUserContentView != null) { | ||
| + ViewGroup.LayoutParams params = mPendingUserContentView.getLayoutParams(); | ||
| + | ||
| + if (params == null) { | ||
| + params = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, | ||
| + ViewGroup.LayoutParams.MATCH_PARENT); | ||
| + } | ||
| + | ||
| + mUserContentContainer.addView(mPendingUserContentView, 0, params); | ||
| + } | ||
| + | ||
| + if (mIsShy && !mIsTabletMode) { | ||
| + getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { | ||
| + @SuppressWarnings("deprecation") | ||
| + @Override | ||
| + public void onGlobalLayout() { | ||
| + if (!mShyHeightAlreadyCalculated) { | ||
| + ((CoordinatorLayout.LayoutParams) getLayoutParams()) | ||
| + .setBehavior(new BottomNavigationBehavior(getOuterContainer().getHeight(), 0)); | ||
| + } | ||
| + | ||
| + ViewTreeObserver obs = getViewTreeObserver(); | ||
| + | ||
| + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { | ||
| + obs.removeOnGlobalLayoutListener(this); | ||
| + } else { | ||
| + obs.removeGlobalOnLayoutListener(this); | ||
| + } | ||
| + } | ||
| + }); | ||
| + } | ||
| + | ||
| addView(rootView); | ||
| } | ||
| @@ -608,6 +635,10 @@ protected boolean isShy() { | ||
| return mIsShy; | ||
| } | ||
| + protected void shyHeightAlreadyCalculated() { | ||
| + mShyHeightAlreadyCalculated = true; | ||
| + } | ||
| + | ||
| protected boolean useExtraOffset() { | ||
| return mUseExtraOffset; | ||
| } | ||
| @@ -667,6 +698,10 @@ public boolean onLongClick(View v) { | ||
| } | ||
| private void updateItems(BottomBarItemBase[] bottomBarItems) { | ||
| + if (mItemContainer == null) { | ||
| + initializeViews(); | ||
| + } | ||
| + | ||
| int index = 0; | ||
| int biggestWidth = 0; | ||
| mIsShiftingMode = MAX_FIXED_TAB_COUNT < bottomBarItems.length; | ||
| @@ -690,7 +725,8 @@ private void updateItems(BottomBarItemBase[] bottomBarItems) { | ||
| if (mIsShiftingMode && !mIsTabletMode) { | ||
| layoutResource = R.layout.bb_bottom_bar_item_shifting; | ||
| } else { | ||
| - layoutResource = R.layout.bb_bottom_bar_item_fixed; | ||
| + layoutResource = mIsTabletMode ? | ||
| + R.layout.bb_bottom_bar_item_fixed_tablet : R.layout.bb_bottom_bar_item_fixed; | ||
| } | ||
| View bottomBarTab = View.inflate(mContext, layoutResource, null); | ||
| @@ -966,11 +1002,13 @@ private void updateCurrentFragment() { | ||
| } | ||
| private void clearItems() { | ||
| - int childCount = mItemContainer.getChildCount(); | ||
| + if (mItemContainer != null) { | ||
| + int childCount = mItemContainer.getChildCount(); | ||
| - if (childCount > 0) { | ||
| - for (int i = 0; i < childCount; i++) { | ||
| - mItemContainer.removeView(mItemContainer.getChildAt(i)); | ||
| + if (childCount > 0) { | ||
| + for (int i = 0; i < childCount; i++) { | ||
| + mItemContainer.removeView(mItemContainer.getChildAt(i)); | ||
| + } | ||
| } | ||
| } | ||
| @@ -1070,11 +1108,13 @@ private static void navBarMagic(Activity activity, final BottomBar bottomBar) { | ||
| @SuppressWarnings("deprecation") | ||
| @Override | ||
| public void onGlobalLayout() { | ||
| + bottomBar.shyHeightAlreadyCalculated(); | ||
| + | ||
| int newHeight = outerContainer.getHeight() + navBarHeightCopy; | ||
| outerContainer.getLayoutParams().height = newHeight; | ||
| if (bottomBar.isShy()) { | ||
| - int defaultOffset = bottomBar.useExtraOffset()? navBarHeightCopy : 0; | ||
| + int defaultOffset = bottomBar.useExtraOffset() ? navBarHeightCopy : 0; | ||
| bottomBar.setTranslationY(defaultOffset); | ||
| ((CoordinatorLayout.LayoutParams) bottomBar.getLayoutParams()) | ||
| .setBehavior(new BottomNavigationBehavior(newHeight, defaultOffset)); | ||
View
3
bottom-bar/src/main/res/layout/bb_bottom_bar_item_container.xml
| @@ -7,7 +7,8 @@ | ||
| <FrameLayout | ||
| android:id="@+id/bb_user_content_container" | ||
| android:layout_width="match_parent" | ||
| - android:layout_height="match_parent"> | ||
| + android:layout_height="match_parent" | ||
| + android:layout_above="@+id/bb_bottom_bar_outer_container"> | ||
| <ImageView | ||
| android:id="@+id/bb_bottom_bar_shadow" | ||
View
0
...-sw600dp/bb_bottom_bar_item_container.xml → ...t/bb_bottom_bar_item_container_tablet.xml
File renamed without changes.
View
0
...yout-sw600dp/bb_bottom_bar_item_fixed.xml → ...ayout/bb_bottom_bar_item_fixed_tablet.xml
File renamed without changes.