From adb47d8c64c38c3e41811e4ad2b3727c4fa76d88 Mon Sep 17 00:00:00 2001
From: Iiro <iiro.krankka@gmail.com>
Date: Mon, 21 Mar 2016 05:11:06 +0200
Subject: [PATCH 1/4] Added ability to disable the left menu on tablets.

---
 .../java/com/roughike/bottombar/BottomBar.java     | 72 +++++++++++++++-------
 .../bb_bottom_bar_item_container.xml               | 41 ------------
 .../layout-sw600dp/bb_bottom_bar_item_fixed.xml    | 14 -----
 .../layout/bb_bottom_bar_item_container_tablet.xml | 41 ++++++++++++
 .../res/layout/bb_bottom_bar_item_fixed_tablet.xml | 14 +++++
 5 files changed, 106 insertions(+), 76 deletions(-)
 delete mode 100644 bottom-bar/src/main/res/layout-sw600dp/bb_bottom_bar_item_container.xml
 delete mode 100644 bottom-bar/src/main/res/layout-sw600dp/bb_bottom_bar_item_fixed.xml
 create mode 100644 bottom-bar/src/main/res/layout/bb_bottom_bar_item_container_tablet.xml
 create mode 100644 bottom-bar/src/main/res/layout/bb_bottom_bar_item_fixed_tablet.xml

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 47aeda8..0ff24d9 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 @@
     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 mUseExtraOffset;
@@ -73,6 +74,7 @@
     private View mBackgroundOverlay;
     private View mShadowView;
     private View mTabletRightBorder;
+    private View mPendingUserContentView;
 
     private int mPrimaryColor;
     private int mInActiveColor;
@@ -130,13 +132,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 +164,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;
@@ -517,6 +515,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 +585,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 +605,17 @@ 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);
+        }
+
         addView(rootView);
     }
 
@@ -667,6 +690,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 +717,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 +994,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));
+                }
             }
         }
 
diff --git a/bottom-bar/src/main/res/layout-sw600dp/bb_bottom_bar_item_container.xml b/bottom-bar/src/main/res/layout-sw600dp/bb_bottom_bar_item_container.xml
deleted file mode 100644
index 9b2993a..0000000
--- a/bottom-bar/src/main/res/layout-sw600dp/bb_bottom_bar_item_container.xml
+++ /dev/null
@@ -1,41 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
-    android:layout_width="match_parent"
-    android:layout_height="match_parent"
-    android:layout_gravity="bottom">
-
-    <FrameLayout
-        android:id="@+id/bb_user_content_container"
-        android:layout_width="match_parent"
-        android:layout_height="match_parent"
-        android:layout_toRightOf="@+id/bb_bottom_bar_outer_container"
-        android:layout_toEndOf="@+id/bb_bottom_bar_outer_container"/>
-
-    <FrameLayout
-        android:id="@+id/bb_bottom_bar_outer_container"
-        android:layout_width="wrap_content"
-        android:layout_height="match_parent"
-        android:layout_alignParentLeft="true"
-        android:layout_alignParentStart="true">
-
-        <View
-            android:id="@+id/bb_tablet_right_border"
-            android:layout_width="1dp"
-            android:layout_height="match_parent"
-            android:layout_gravity="right|end"
-            android:background="#EAEAEA"/>
-
-        <LinearLayout
-            android:id="@+id/bb_bottom_bar_item_container"
-            android:layout_width="wrap_content"
-            android:layout_height="match_parent"
-            android:layout_marginRight="1dp"
-            android:layout_marginEnd="1dp"
-            android:paddingTop="8dp"
-            android:paddingBottom="8dp"
-            android:background="#FFFFFF"
-            android:orientation="vertical" />
-
-    </FrameLayout>
-
-</RelativeLayout>
\ No newline at end of file
diff --git a/bottom-bar/src/main/res/layout-sw600dp/bb_bottom_bar_item_fixed.xml b/bottom-bar/src/main/res/layout-sw600dp/bb_bottom_bar_item_fixed.xml
deleted file mode 100644
index 9d03bd2..0000000
--- a/bottom-bar/src/main/res/layout-sw600dp/bb_bottom_bar_item_fixed.xml
+++ /dev/null
@@ -1,14 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
-    android:layout_width="wrap_content"
-    android:layout_height="wrap_content"
-    android:paddingLeft="20dp"
-    android:paddingRight="20dp"
-    android:paddingTop="16dp"
-    android:paddingBottom="16dp">
-
-    <ImageView
-        android:id="@+id/bb_bottom_bar_icon"
-        style="@style/BB_BottomBarItem_Tablet" />
-
-</FrameLayout>
\ No newline at end of file
diff --git a/bottom-bar/src/main/res/layout/bb_bottom_bar_item_container_tablet.xml b/bottom-bar/src/main/res/layout/bb_bottom_bar_item_container_tablet.xml
new file mode 100644
index 0000000..9b2993a
--- /dev/null
+++ b/bottom-bar/src/main/res/layout/bb_bottom_bar_item_container_tablet.xml
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="utf-8"?>
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    android:layout_gravity="bottom">
+
+    <FrameLayout
+        android:id="@+id/bb_user_content_container"
+        android:layout_width="match_parent"
+        android:layout_height="match_parent"
+        android:layout_toRightOf="@+id/bb_bottom_bar_outer_container"
+        android:layout_toEndOf="@+id/bb_bottom_bar_outer_container"/>
+
+    <FrameLayout
+        android:id="@+id/bb_bottom_bar_outer_container"
+        android:layout_width="wrap_content"
+        android:layout_height="match_parent"
+        android:layout_alignParentLeft="true"
+        android:layout_alignParentStart="true">
+
+        <View
+            android:id="@+id/bb_tablet_right_border"
+            android:layout_width="1dp"
+            android:layout_height="match_parent"
+            android:layout_gravity="right|end"
+            android:background="#EAEAEA"/>
+
+        <LinearLayout
+            android:id="@+id/bb_bottom_bar_item_container"
+            android:layout_width="wrap_content"
+            android:layout_height="match_parent"
+            android:layout_marginRight="1dp"
+            android:layout_marginEnd="1dp"
+            android:paddingTop="8dp"
+            android:paddingBottom="8dp"
+            android:background="#FFFFFF"
+            android:orientation="vertical" />
+
+    </FrameLayout>
+
+</RelativeLayout>
\ No newline at end of file
diff --git a/bottom-bar/src/main/res/layout/bb_bottom_bar_item_fixed_tablet.xml b/bottom-bar/src/main/res/layout/bb_bottom_bar_item_fixed_tablet.xml
new file mode 100644
index 0000000..9d03bd2
--- /dev/null
+++ b/bottom-bar/src/main/res/layout/bb_bottom_bar_item_fixed_tablet.xml
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="utf-8"?>
+<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="wrap_content"
+    android:layout_height="wrap_content"
+    android:paddingLeft="20dp"
+    android:paddingRight="20dp"
+    android:paddingTop="16dp"
+    android:paddingBottom="16dp">
+
+    <ImageView
+        android:id="@+id/bb_bottom_bar_icon"
+        style="@style/BB_BottomBarItem_Tablet" />
+
+</FrameLayout>
\ No newline at end of file

From 0cd927486914106041a5fdd4ce80242479ffb3e8 Mon Sep 17 00:00:00 2001
From: Iiro <iiro.krankka@gmail.com>
Date: Mon, 21 Mar 2016 05:27:41 +0200
Subject: [PATCH 2/4] Fixed shadow.

---
 bottom-bar/src/main/res/layout/bb_bottom_bar_item_container.xml | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/bottom-bar/src/main/res/layout/bb_bottom_bar_item_container.xml b/bottom-bar/src/main/res/layout/bb_bottom_bar_item_container.xml
index c08d6a3..02dcb8e 100644
--- a/bottom-bar/src/main/res/layout/bb_bottom_bar_item_container.xml
+++ b/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"

From 68535e173e6b25d9154fb78468bb061764ecd508 Mon Sep 17 00:00:00 2001
From: Iiro <iiro.krankka@gmail.com>
Date: Mon, 21 Mar 2016 05:28:48 +0200
Subject: [PATCH 3/4] Navbar height calculation improvements.

---
 .../java/com/roughike/bottombar/BottomBar.java     | 52 +++++++++++++---------
 1 file changed, 31 insertions(+), 21 deletions(-)

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 0ff24d9..e051566 100644
--- a/bottom-bar/src/main/java/com/roughike/bottombar/BottomBar.java
+++ b/bottom-bar/src/main/java/com/roughike/bottombar/BottomBar.java
@@ -64,6 +64,7 @@
     private boolean mIgnoreTabletLayout;
     private boolean mIsTabletMode;
     private boolean mIsShy;
+    private boolean mShyHeightAlreadyCalculated;
     private boolean mUseExtraOffset;
 
     private ViewGroup mUserContentContainer;
@@ -189,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;
     }
@@ -591,7 +574,7 @@ private void initializeViews() {
         mIsTabletMode = !mIgnoreTabletLayout &&
                 mContext.getResources().getBoolean(R.bool.bb_bottom_bar_is_tablet_mode);
 
-        View rootView = View.inflate(mContext, mIsTabletMode?
+        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);
@@ -616,6 +599,27 @@ private void initializeViews() {
             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);
     }
 
@@ -631,6 +635,10 @@ protected boolean isShy() {
         return mIsShy;
     }
 
+    protected void shyHeightAlreadyCalculated() {
+        mShyHeightAlreadyCalculated = true;
+    }
+
     protected boolean useExtraOffset() {
         return mUseExtraOffset;
     }
@@ -717,7 +725,7 @@ private void updateItems(BottomBarItemBase[] bottomBarItems) {
             if (mIsShiftingMode && !mIsTabletMode) {
                 layoutResource = R.layout.bb_bottom_bar_item_shifting;
             } else {
-                layoutResource = mIsTabletMode?
+                layoutResource = mIsTabletMode ?
                         R.layout.bb_bottom_bar_item_fixed_tablet : R.layout.bb_bottom_bar_item_fixed;
             }
 
@@ -1100,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));

From b307c0393be10c70cdb0743283a19398296ce81c Mon Sep 17 00:00:00 2001
From: Iiro <iiro.krankka@gmail.com>
Date: Mon, 21 Mar 2016 05:29:29 +0200
Subject: [PATCH 4/4] Updated library version.

---
 bottom-bar/bottom-bar.iml | 2 +-
 bottom-bar/build.gradle   | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/bottom-bar/bottom-bar.iml b/bottom-bar/bottom-bar.iml
index ee4617e..d9fb75b 100644
--- a/bottom-bar/bottom-bar.iml
+++ b/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>
diff --git a/bottom-bar/build.gradle b/bottom-bar/build.gradle
index df1695e..a0f5a6f 100644
--- a/bottom-bar/build.gradle
+++ b/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'
