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

Updates #2

Merged
merged 33 commits into from
Jun 7, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
77f94f0
Fix typo
ened May 27, 2016
24c1ac6
Merge pull request #256 from ened/patch-1
roughike May 27, 2016
d3c5b40
update README with more badge configurations
westlinkin May 30, 2016
f7fb656
add feature: remove badge at tabPosition
westlinkin May 31, 2016
b8742e8
Add null check for mListener to setOnTabClickListener. Listener can n…
dptsolutions Jun 2, 2016
76ce3a1
Fix the @Nullable derp
dptsolutions Jun 2, 2016
aeaa9e1
Split setting of items from a Menu resource and setting of the onMenu…
dptsolutions Jun 2, 2016
77fe7d2
Update javadoc to match format for changes in other branch.
dptsolutions Jun 2, 2016
0b00985
Update readme
dptsolutions Jun 2, 2016
e3f2e9e
Fix selection/unselection when using badges
henhal Jun 2, 2016
590c00b
Merge branch 'master' of git://github.com/westlinkin/BottomBar into w…
roughike Jun 5, 2016
a1544cc
Removed a the remove badge method for now, as it crashes.
roughike Jun 5, 2016
492137b
Merge branch 'westlinkin-master'
roughike Jun 5, 2016
fd9287e
Merge branch 'unregister-listeners' of git://github.com/dptsolutions/…
roughike Jun 5, 2016
c3b27b8
Derp.
roughike Jun 5, 2016
327abce
Merge branch 'dptsolutions-unregister-listeners'
roughike Jun 5, 2016
8b29953
Merge branch 'break-up-menu-set-and-listener' of git://github.com/dpt…
roughike Jun 5, 2016
7dbedfa
Merge branch 'dptsolutions-break-up-menu-set-and-listener'
roughike Jun 5, 2016
b3e0765
Merge branch 'fix-selection-with-badges' of git://github.com/henhal/B…
roughike Jun 5, 2016
539e761
Merge branch 'henhal-fix-selection-with-badges'
roughike Jun 5, 2016
fbfc56a
Updated changelog and readme.
roughike Jun 5, 2016
33fe72c
Bumped library version.
roughike Jun 5, 2016
1c2fb14
Fixed issue with the transparent navbar on some devices.
roughike Jun 6, 2016
72ac83c
Fixed issue with the transparent navbar on some devices.
roughike Jun 6, 2016
5fd7457
Pressed the enter key once for some advanced next-level functionality.
roughike Jun 6, 2016
f6d1964
Flattened View hierarchy.
roughike Jun 6, 2016
daeff47
Now throwing an exception when calling noResizeGoodness() improperly.
roughike Jun 6, 2016
58fbcb4
Updated Changelog.
roughike Jun 6, 2016
e0b58c3
Bumped up library version.
roughike Jun 6, 2016
f32f99f
Update .gitignore
roughike Jun 6, 2016
0e38fd5
Add files via upload
roughike Jun 6, 2016
79659b1
Update README.md
roughike Jun 6, 2016
2a9cc12
Update README.md
roughike Jun 6, 2016
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,4 @@ tablet.png
screenshot_tablet.png
scrolling_demo.gif
demo_shifting.gif
icons-howto.png
16 changes: 14 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
## Changelog

(or: why are you updating this all the time?)
(or: y u no add shiny new things?!)

### Newest version: 1.3.4
### Newest version: 1.3.6

* Fixed a bug that would cause the navigation bar to not be transparent.
* Flattened View hierarchy.
* Throwing a nice little Exception if someone tries to call ```noResizeGoodness()``` improperly, instead of just failing silently.

### 1.3.5

* [Merged](https://github.com/roughike/BottomBar/pull/260) [some](https://github.com/roughike/BottomBar/pull/268) [pull](https://github.com/roughike/BottomBar/pull/269) [requests.](https://github.com/roughike/BottomBar/pull/271)
* Thanks to @henhal, now the unselection bug when using badges is fixed.
* Deprecated the ```setItemsFromMenu(@MenuRes int resId, OnMenuTabClickListener listener)``` method in favor of two separate methods: ```mBottomBar.setItems(@MenuRes int resId)``` and ```mBottomBar.setOnMenuTabClickListener(OnMenuTabClickListener listener)```. Not only because deprecating stuff is so fun (it is), but because this actually makes more sense than the old approach. The old approach still works.

### 1.3.4

* Now the BottomBar is 56dp tall, as it should be! Make sure your icons are 24dp and **trimmed**, meaning that the whole png size musn't be more than 24dp. So **don't use padding** around the icon.
* Fixed a minor bug when programmatically selecting a tab.
Expand Down
16 changes: 13 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ Your uncle Bob's Galaxy S Mini will probably be supported in the future though.
## Gimme that Gradle sweetness, pls?

```groovy
compile 'com.roughike:bottom-bar:1.3.4'
compile 'com.roughike:bottom-bar:1.3.5'
```

**Maven:**
```xml
<dependency>
<groupId>com.roughike</groupId>
<artifactId>bottom-bar</artifactId>
<version>1.3.4</version>
<version>1.3.5</version>
<type>pom</type>
</dependency>
```
Expand All @@ -37,6 +37,12 @@ compile 'com.roughike:bottom-bar:1.3.4'

You can add items by specifying an array of items or **by xml menu resources**.

#### Creating the icons

The icons must be fully opaque, solid color, 24dp and **with no padding**. For example, [with Android Asset Studio Generic Icon generator](https://romannurik.github.io/AndroidAssetStudio/icons-generic.html), select "TRIM" and make sure the padding is 0dp. Here's what your icons should look like:

![Sample icons](https://raw.githubusercontent.com/roughike/BottomBar/master/icons-howto.png)

#### Adding items from menu resource

**res/menu/bottombar_menu.xml:**
Expand All @@ -63,7 +69,8 @@ public class MainActivity extends AppCompatActivity {
setContentView(R.layout.activity_main);

mBottomBar = BottomBar.attach(this, savedInstanceState);
mBottomBar.setItemsFromMenu(R.menu.bottombar_menu, new OnMenuTabClickListener() {
mBottomBar.setItems(R.menu.bottombar_menu);
mBottomBar.setOnMenuTabClickListener(new OnMenuTabClickListener() {
@Override
public void onMenuTabSelected(@IdRes int menuItemId) {
if (menuItemId == R.id.bottomBarItemOne) {
Expand Down Expand Up @@ -119,6 +126,9 @@ unreadMessages.setAnimationDuration(200);

// If you want the badge be shown always after unselecting the tab that contains it.
unreadMessages.setAutoShowAfterUnSelection(true);

// If you don't want this badge to be hidden after selecting the tab contains it.
unreadMessages.setAutoShowAfterUnSelection(false);
```

## Customization
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ protected void onCreate(Bundle savedInstanceState) {
mMessageView = (TextView) findViewById(R.id.messageView);

mBottomBar = BottomBar.attach(this, savedInstanceState);
mBottomBar.setItemsFromMenu(R.menu.bottombar_menu, new OnMenuTabClickListener() {
mBottomBar.setItems(R.menu.bottombar_menu);
mBottomBar.setOnMenuTabClickListener(new OnMenuTabClickListener() {
@Override
public void onMenuTabSelected(@IdRes int menuItemId) {
mMessageView.setText(getMessage(menuItemId, false));
Expand Down Expand Up @@ -79,4 +80,11 @@ protected void onSaveInstanceState(Bundle outState) {
// lose the current tab on orientation change.
mBottomBar.onSaveInstanceState(outState);
}

@Override
protected void onDestroy() {
mBottomBar.setOnMenuTabClickListener(null);
super.onDestroy();

}
}
22 changes: 11 additions & 11 deletions bottom-bar/bottom-bar.iml
Original file line number Diff line number Diff line change
@@ -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.3.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.3.6" type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="android-gradle" name="Android-Gradle">
<configuration>
Expand Down Expand Up @@ -65,14 +65,6 @@
<sourceFolder url="file://$MODULE_DIR$/src/main/jni" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/rs" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/shaders" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/aidl" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/shaders" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/assets" type="java-test-resource" />
Expand All @@ -81,6 +73,14 @@
<sourceFolder url="file://$MODULE_DIR$/src/test/jni" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/shaders" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/aidl" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/shaders" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/build/docs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/annotations" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" />
Expand All @@ -107,10 +107,10 @@
<orderEntry type="library" exported="" name="design-23.3.0" level="project" />
<orderEntry type="library" exported="" name="support-vector-drawable-23.3.0" level="project" />
<orderEntry type="library" exported="" name="animated-vector-drawable-23.3.0" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="hamcrest-core-1.3" level="project" />
<orderEntry type="library" exported="" name="support-v4-23.3.0" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="junit-4.12" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="hamcrest-core-1.3" level="project" />
<orderEntry type="library" exported="" name="appcompat-v7-23.3.0" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="junit-4.12" level="project" />
<orderEntry type="library" exported="" name="support-annotations-23.3.0" level="project" />
<orderEntry type="library" exported="" name="recyclerview-v7-23.3.0" level="project" />
</component>
Expand Down
2 changes: 1 addition & 1 deletion bottom-bar/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ ext {
siteUrl = 'https://github.com/roughike/BottomBar'
gitUrl = 'https://github.com/roughike/BottomBar.git'

libraryVersion = '1.3.4'
libraryVersion = '1.3.6'

developerId = 'roughike'
developerName = 'Iiro Krankka'
Expand Down
82 changes: 64 additions & 18 deletions bottom-bar/src/main/java/com/roughike/bottombar/BottomBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import android.os.Bundle;
import android.support.annotation.IdRes;
import android.support.annotation.MenuRes;
import android.support.annotation.Nullable;
import android.support.annotation.StyleRes;
import android.support.design.widget.CoordinatorLayout;
import android.support.v4.content.ContextCompat;
Expand All @@ -29,6 +30,7 @@
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

Expand All @@ -52,7 +54,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
public class BottomBar extends FrameLayout implements View.OnClickListener, View.OnLongClickListener {
public class BottomBar extends RelativeLayout implements View.OnClickListener, View.OnLongClickListener {
private static final long ANIMATION_DURATION = 150;

private static final String STATE_CURRENT_SELECTED_TAB = "STATE_CURRENT_SELECTED_TAB";
Expand Down Expand Up @@ -132,7 +134,7 @@ public class BottomBar extends FrameLayout implements View.OnClickListener, View
/**
* Bind the BottomBar to your Activity, and inflate your layout here.
* <p/>
* Remember to also call {@link #onRestoreInstanceState(Bundle)} inside
* Remember to also call {@link #onSaveInstanceState(Bundle)} inside
* of your {@link Activity#onSaveInstanceState(Bundle)} to restore the state.
*
* @param activity an Activity to attach to.
Expand Down Expand Up @@ -299,9 +301,10 @@ public void setFragmentItems(android.support.v4.app.FragmentManager fragmentMana
}

/**
* Set tabs for this BottomBar. When setting more than 3 items,
* only the icons will show by default, but the selected item
* will have the text visible.
* Set items for this BottomBar.
*
* When setting more than 3 items, only the icons will show by
* default, but the selected item will have the text visible.
*
* @param bottomBarTabs an array of {@link BottomBarTab} objects.
*/
Expand All @@ -310,9 +313,23 @@ public void setItems(BottomBarTab... bottomBarTabs) {
mItems = bottomBarTabs;
updateItems(mItems);
}
/**
* Set items for this BottomBar from an XML menu resource file.
*
* When setting more than 3 items, only the icons will show by
* default, but the selected item will have the text visible.
*
* @param menuRes the menu resource to inflate items from.
*/
public void setItems(@MenuRes int menuRes) {
clearItems();
mItems = MiscUtils.inflateMenuFromResource((Activity) getContext(), menuRes);
updateItems(mItems);
}

/**
* Deprecated. Use {@link #setItemsFromMenu(int, OnMenuTabClickListener)} instead.
* Deprecated. Use {@link #setItems(int)} and
* {@link #setOnMenuTabClickListener(OnMenuTabClickListener)}instead.
*/
@Deprecated
public void setItemsFromMenu(@MenuRes int menuRes, OnMenuTabSelectedListener listener) {
Expand All @@ -323,11 +340,10 @@ public void setItemsFromMenu(@MenuRes int menuRes, OnMenuTabSelectedListener lis
}

/**
* Set items from an XML menu resource file.
*
* @param menuRes the menu resource to inflate items from.
* @param listener listener for tab change events.
* Deprecated. Use {@link #setItems(int)} and
* {@link #setOnMenuTabClickListener(OnMenuTabClickListener)}instead.
*/
@Deprecated
public void setItemsFromMenu(@MenuRes int menuRes, OnMenuTabClickListener listener) {
clearItems();
mItems = MiscUtils.inflateMenuFromResource((Activity) getContext(), menuRes);
Expand All @@ -351,16 +367,37 @@ public void setOnItemSelectedListener(OnTabSelectedListener listener) {
/**
* Set a listener that gets fired when the selected tab changes.
*
* Note: If listener is set after items are added to the BottomBar, onTabSelected
* will be immediately called for the currently selected tab
*
* @param listener a listener for monitoring changes in tab selection.
*/
public void setOnTabClickListener(OnTabClickListener listener) {
public void setOnTabClickListener(@Nullable OnTabClickListener listener) {
mListener = listener;

if (mItems != null && mItems.length > 0) {
if (mListener != null && mItems != null && mItems.length > 0) {
listener.onTabSelected(mCurrentTabPosition);
}
}

/**
* Set a listener that gets fired when the selected tab changes, when the
* tabs are created from an XML menu resource file.
*
* Note: If listener is set after items are added to the BottomBar, onMenuTabSelected
* will be immediately called for the currently selected tab
*
* @param listener a listener for monitoring changes in tab selection.
*/
public void setOnMenuTabClickListener(@Nullable OnMenuTabClickListener listener) {
mMenuListener = listener;

if (mMenuListener != null && mItems != null && mItems.length > 0
&& mItems instanceof BottomBarTab[]) {
listener.onMenuTabSelected(((BottomBarTab) mItems[mCurrentTabPosition]).id);
}
}

/**
* Select a tab at the specified position.
*
Expand Down Expand Up @@ -776,6 +813,12 @@ public void noTabletGoodness() {
* is ignored.
*/
public void noResizeGoodness() {
if (mItems != null) {
throw new UnsupportedOperationException("This BottomBar already has items! " +
"You must call noResizeGoodness() before setting the items, preferably " +
"right after attaching it to your layout.");
}

mIgnoreShiftingResize = true;
}

Expand Down Expand Up @@ -888,9 +931,9 @@ private void initializeViews() {
mIsTabletMode = !mIgnoreTabletLayout &&
mContext.getResources().getBoolean(R.bool.bb_bottom_bar_is_tablet_mode);
ViewCompat.setElevation(this, MiscUtils.dpToPixel(mContext, 8));
View rootView = View.inflate(mContext, mIsTabletMode ?
View rootView = inflate(mContext, mIsTabletMode ?
R.layout.bb_bottom_bar_item_container_tablet : R.layout.bb_bottom_bar_item_container,
null);
this);
mTabletRightBorder = rootView.findViewById(R.id.bb_tablet_right_border);

mUserContentContainer = (ViewGroup) rootView.findViewById(R.id.bb_user_content_container);
Expand Down Expand Up @@ -942,8 +985,6 @@ public void onGlobalLayout() {
}
});
}

addView(rootView);
}

/**
Expand Down Expand Up @@ -1557,6 +1598,7 @@ private void clearItems() {

private static void navBarMagic(Activity activity, final BottomBar bottomBar) {
Resources res = activity.getResources();

int softMenuIdentifier = res
.getIdentifier("config_showNavigationBar", "bool", "android");
int navBarIdentifier = res.getIdentifier("navigation_bar_height",
Expand All @@ -1568,8 +1610,7 @@ private static void navBarMagic(Activity activity, final BottomBar bottomBar) {
}

if (!bottomBar.drawBehindNavBar()
|| navBarHeight == 0
|| (!(softMenuIdentifier > 0 && res.getBoolean(softMenuIdentifier)))) {
|| navBarHeight == 0) {
return;
}

Expand All @@ -1578,6 +1619,11 @@ private static void navBarMagic(Activity activity, final BottomBar bottomBar) {
return;
}

if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1 &&
(!(softMenuIdentifier > 0 && res.getBoolean(softMenuIdentifier)))) {
return;
}

/**
* Copy-paste coding made possible by:
* http://stackoverflow.com/a/14871974/940036
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ protected BottomBarBadge(Context context, int position, final View tabToAddTo, /
parent.removeView(tabToAddTo);

container.setTag(tabToAddTo.getTag());
tabToAddTo.setTag(null);
container.addView(tabToAddTo);
container.addView(this);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
<?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="wrap_content"
android:layout_gravity="bottom">
<merge xmlns:android="http://schemas.android.com/apk/res/android">

<FrameLayout
android:id="@+id/bb_user_content_container"
Expand Down Expand Up @@ -51,4 +48,4 @@

</FrameLayout>

</RelativeLayout>
</merge>
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
<?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">
<merge xmlns:android="http://schemas.android.com/apk/res/android">

<FrameLayout
android:id="@+id/bb_user_content_container"
Expand Down Expand Up @@ -38,4 +35,4 @@

</FrameLayout>

</RelativeLayout>
</merge>
Binary file added icons-howto.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.