diff options
author | Aurelien Hubert <aurel.hubert@gmail.com> | 2016-04-25 10:53:17 +0200 |
---|---|---|
committer | Aurelien Hubert <aurel.hubert@gmail.com> | 2016-04-25 10:53:17 +0200 |
commit | 9e027e823caa29c491912048a842c442ab03da96 (patch) | |
tree | bc8586e3915ff3c8217ad22c4a9bed32e0f036f1 | |
parent | 412f23f9af933445e16aeaec47a15bebb0ade8d1 (diff) | |
download | android_external_ahbottomnavigation-9e027e823caa29c491912048a842c442ab03da96.tar.gz android_external_ahbottomnavigation-9e027e823caa29c491912048a842c442ab03da96.tar.bz2 android_external_ahbottomnavigation-9e027e823caa29c491912048a842c442ab03da96.zip |
Improved hide & restore methods
Added setTitleTypeface
Added onSaveInstanceState & onRestoreInstanceState
Updated setNotificationTypeface method name
-rw-r--r-- | CHANGELOG.md | 9 | ||||
-rw-r--r-- | README.md | 11 | ||||
-rw-r--r-- | ahbottomnavigation/build.gradle | 6 | ||||
-rw-r--r-- | ahbottomnavigation/src/main/java/com/aurelhubert/ahbottomnavigation/AHBottomNavigation.java | 73 | ||||
-rw-r--r-- | ahbottomnavigation/src/main/java/com/aurelhubert/ahbottomnavigation/AHBottomNavigationBehavior.java | 23 |
5 files changed, 97 insertions, 25 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 47ec640..a2c8d11 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,13 @@ ## Changelog -### Newest version: 1.1.5 +### Newest version: 1.1.6 + +* Improved `hideBottomNavigation()` and `restoreBottomNavigation()` +* Added `setTitleTypeface` +* Changed method name `setNotificationBackgroundColorResource` by `setNotificationTypeface` +* Started working on `onSaveInstanceState` and `onRestoreInstanceState` (currentItem & notifications for now) + +### 1.1.5 * Added hideBottomNavigation() * Added CURRENT_ITEM_NONE to unselect all items @@ -5,11 +5,12 @@ Library to implement the Bottom Navigation component from Material Design guidel ## Demo <img src="https://raw.githubusercontent.com/aurelhubert/ahbottomnavigation/master/demo1.gif" width="208" height="368" /> <img src="https://raw.githubusercontent.com/aurelhubert/ahbottomnavigation/master/demo2.gif" width="208" height="368" /> <img src="https://raw.githubusercontent.com/aurelhubert/ahbottomnavigation/master/demo3.gif" width="208" height="368" /> <img src="https://raw.githubusercontent.com/aurelhubert/ahbottomnavigation/master/demo4.gif" width="208" height="368" /> -## What's new (1.1.5) - [Changelog](https://github.com/aurelhubert/ahbottomnavigation/blob/master/CHANGELOG.md) +## What's new (1.1.6) - [Changelog](https://github.com/aurelhubert/ahbottomnavigation/blob/master/CHANGELOG.md) -* Added hideBottomNavigation() -* Unselect all items with setCurrentItem(AHBottomNavigation.CURRENT_ITEM_NONE) -* Improved Notifications (animation, position) +* Improved `hideBottomNavigation()` and `restoreBottomNavigation()` +* Added `setTitleTypeface` +* Changed method name `setNotificationBackgroundColorResource` by `setNotificationTypeface` +* Started working on `onSaveInstanceState` and `onRestoreInstanceState` (currentItem & notifications for now) ## Features * Follow the bottom navigation guidelines (https://www.google.com/design/spec/components/bottom-navigation.html) @@ -24,7 +25,7 @@ Library to implement the Bottom Navigation component from Material Design guidel ### Gradle ```groovy dependencies { - compile 'com.aurelhubert:ahbottomnavigation:1.1.5' + compile 'com.aurelhubert:ahbottomnavigation:1.1.6' } ``` ### XML diff --git a/ahbottomnavigation/build.gradle b/ahbottomnavigation/build.gradle index 22f6e76..e111ce4 100644 --- a/ahbottomnavigation/build.gradle +++ b/ahbottomnavigation/build.gradle @@ -13,7 +13,7 @@ ext { siteUrl = 'https://github.com/aurelhubert/ahbottomnavigation' gitUrl = 'https://github.com/aurelhubert/ahbottomnavigation.git' - libraryVersion = '1.1.5' + libraryVersion = '1.1.6' developerId = 'aurelhubert' developerName = 'Aurelien Hubert' @@ -31,8 +31,8 @@ android { defaultConfig { minSdkVersion 14 targetSdkVersion 23 - versionCode 22 - versionName "1.1.5" + versionCode 23 + versionName "1.1.6" } buildTypes { release { diff --git a/ahbottomnavigation/src/main/java/com/aurelhubert/ahbottomnavigation/AHBottomNavigation.java b/ahbottomnavigation/src/main/java/com/aurelhubert/ahbottomnavigation/AHBottomNavigation.java index 44ac23d..8dbde92 100644 --- a/ahbottomnavigation/src/main/java/com/aurelhubert/ahbottomnavigation/AHBottomNavigation.java +++ b/ahbottomnavigation/src/main/java/com/aurelhubert/ahbottomnavigation/AHBottomNavigation.java @@ -7,6 +7,8 @@ import android.graphics.Color; import android.graphics.Typeface; import android.graphics.drawable.Drawable; import android.os.Build; +import android.os.Bundle; +import android.os.Parcelable; import android.support.annotation.ColorInt; import android.support.annotation.ColorRes; import android.support.design.widget.CoordinatorLayout; @@ -64,6 +66,7 @@ public class AHBottomNavigation extends FrameLayout { private int defaultBackgroundColor = Color.WHITE; private int accentColor = Color.WHITE; private int inactiveColor = Color.WHITE; + private Typeface titleTypeface; private int currentItem = 0; private int currentColor = 0; @@ -118,6 +121,26 @@ public class AHBottomNavigation extends FrameLayout { } } + @Override + protected Parcelable onSaveInstanceState() { + Bundle bundle = new Bundle(); + bundle.putParcelable("superState", super.onSaveInstanceState()); + bundle.putInt("current_item", currentItem); + bundle.putIntArray("notifications", notifications); + return bundle; + } + + @Override + protected void onRestoreInstanceState(Parcelable state) { + if (state instanceof Bundle) { + Bundle bundle = (Bundle) state; + currentItem = bundle.getInt("current_item"); + notifications = bundle.getIntArray("notifications"); + state = bundle.getParcelable("superState"); + } + super.onRestoreInstanceState(state); + } + ///////////// // PRIVATE // ///////////// @@ -241,6 +264,10 @@ public class AHBottomNavigation extends FrameLayout { icon.setImageDrawable(item.getDrawable(context)); title.setText(item.getTitle(context)); + if (titleTypeface != null) { + title.setTypeface(titleTypeface); + } + if (forceTitlesDisplay && items.size() > MIN_ITEMS) { container.setPadding(0, container.getPaddingTop(), 0, container.getPaddingBottom()); } @@ -342,6 +369,10 @@ public class AHBottomNavigation extends FrameLayout { icon.setImageDrawable(item.getDrawable(context)); title.setText(item.getTitle(context)); + if (titleTypeface != null) { + title.setTypeface(titleTypeface); + } + if (i == currentItem) { // Update margins (icon & notification) if (view.getLayoutParams() instanceof ViewGroup.MarginLayoutParams) { @@ -820,6 +851,16 @@ public class AHBottomNavigation extends FrameLayout { } /** + * Set notification typeface + * + * @param typeface Typeface + */ + public void setTitleTypeface(Typeface typeface) { + this.titleTypeface = typeface; + createItems(); + } + + /** * Get the current item * * @return The current item position @@ -889,8 +930,15 @@ public class AHBottomNavigation extends FrameLayout { public void hideBottomNavigation() { if (bottomNavigationBehavior != null) { bottomNavigationBehavior.hideView(this, bottomNavigationHeight); - } else { + } else if (getParent() instanceof CoordinatorLayout) { needHideBottomNavigation = true; + } else { + // Hide bottom navigation + ViewCompat.animate(this) + .translationY(bottomNavigationHeight) + .setInterpolator(new LinearOutSlowInInterpolator()) + .setDuration(300) + .start(); } } @@ -900,6 +948,13 @@ public class AHBottomNavigation extends FrameLayout { public void restoreBottomNavigation() { if (bottomNavigationBehavior != null) { bottomNavigationBehavior.resetOffset(this); + } else { + // Show bottom navigation + ViewCompat.animate(this) + .translationY(0) + .setInterpolator(new LinearOutSlowInInterpolator()) + .setDuration(300) + .start(); } } @@ -994,7 +1049,7 @@ public class AHBottomNavigation extends FrameLayout { * @param textColor int */ public void setNotificationTextColor(@ColorInt int textColor) { - notificationTextColor = textColor; + this.notificationTextColor = textColor; updateNotifications(true, UPDATE_ALL_NOTIFICATIONS); } @@ -1004,7 +1059,7 @@ public class AHBottomNavigation extends FrameLayout { * @param textColor int */ public void setNotificationTextColorResource(@ColorRes int textColor) { - notificationTextColor = ContextCompat.getColor(context, textColor); + this.notificationTextColor = ContextCompat.getColor(context, textColor); updateNotifications(true, UPDATE_ALL_NOTIFICATIONS); } @@ -1014,7 +1069,7 @@ public class AHBottomNavigation extends FrameLayout { * @param drawable Drawable */ public void setNotificationBackground(Drawable drawable) { - notificationBackgroundDrawable = drawable; + this.notificationBackgroundDrawable = drawable; updateNotifications(true, UPDATE_ALL_NOTIFICATIONS); } @@ -1024,7 +1079,7 @@ public class AHBottomNavigation extends FrameLayout { * @param color int */ public void setNotificationBackgroundColor(@ColorInt int color) { - notificationBackgroundColor = color; + this.notificationBackgroundColor = color; updateNotifications(true, UPDATE_ALL_NOTIFICATIONS); } @@ -1034,7 +1089,7 @@ public class AHBottomNavigation extends FrameLayout { * @param color int */ public void setNotificationBackgroundColorResource(@ColorRes int color) { - notificationBackgroundColor = ContextCompat.getColor(context, color); + this.notificationBackgroundColor = ContextCompat.getColor(context, color); updateNotifications(true, UPDATE_ALL_NOTIFICATIONS); } @@ -1043,8 +1098,8 @@ public class AHBottomNavigation extends FrameLayout { * * @param typeface Typeface */ - public void setNotificationBackgroundColorResource(Typeface typeface) { - notificationTypeface = typeface; + public void setNotificationTypeface(Typeface typeface) { + this.notificationTypeface = typeface; updateNotifications(true, UPDATE_ALL_NOTIFICATIONS); } @@ -1055,7 +1110,7 @@ public class AHBottomNavigation extends FrameLayout { */ public void setUseElevation(boolean useElevation) { ViewCompat.setElevation(this, useElevation ? - resources.getDimension(R.dimen.bottom_navigation_elevation) : 0); + resources.getDimension(R.dimen.bottom_navigation_elevation) : 0); setClipToPadding(false); } diff --git a/ahbottomnavigation/src/main/java/com/aurelhubert/ahbottomnavigation/AHBottomNavigationBehavior.java b/ahbottomnavigation/src/main/java/com/aurelhubert/ahbottomnavigation/AHBottomNavigationBehavior.java index 321e373..94c7f6f 100644 --- a/ahbottomnavigation/src/main/java/com/aurelhubert/ahbottomnavigation/AHBottomNavigationBehavior.java +++ b/ahbottomnavigation/src/main/java/com/aurelhubert/ahbottomnavigation/AHBottomNavigationBehavior.java @@ -98,10 +98,10 @@ public class AHBottomNavigationBehavior<V extends View> extends VerticalScrollin private void handleDirection(V child, int scrollDirection) { if (scrollDirection == ScrollDirection.SCROLL_DIRECTION_DOWN && hidden) { hidden = false; - animateOffset(child, 0); + animateOffset(child, 0, false); } else if (scrollDirection == ScrollDirection.SCROLL_DIRECTION_UP && !hidden) { hidden = true; - animateOffset(child, child.getHeight()); + animateOffset(child, child.getHeight(), false); } } @@ -117,10 +117,11 @@ public class AHBottomNavigationBehavior<V extends View> extends VerticalScrollin * @param child * @param offset */ - private void animateOffset(final V child, final int offset) { - if (!behaviorTranslationEnabled) { + private void animateOffset(final V child, final int offset, boolean forceAnimation) { + if (!behaviorTranslationEnabled && !forceAnimation) { return; } + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) { ensureOrCancelObjectAnimation(child, offset); translationObjectAnimator.start(); @@ -217,13 +218,21 @@ public class AHBottomNavigationBehavior<V extends View> extends VerticalScrollin this.mTabLayoutId = tabId; } - + /** + * Hide AHBottomNavigation with animation + * @param view + * @param offset + */ public void hideView(V view, int offset) { - animateOffset(view, offset); + animateOffset(view, offset, true); } + /** + * Reset AHBottomNavigation position with animation + * @param view + */ public void resetOffset(V view) { - animateOffset(view, 0); + animateOffset(view, 0, true); } /** |