aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAurelien Hubert <aurel.hubert@gmail.com>2016-04-26 11:00:35 +0200
committerAurelien Hubert <aurel.hubert@gmail.com>2016-04-26 11:00:35 +0200
commitc3a0a08d98a7ad026512be95ab048fe7a04f823e (patch)
tree587fb256a43fe65995ac45f4f70f38ce66b31c70
parent375aad8ea34cc05c5837114f5981d4424be5c30f (diff)
downloadandroid_external_ahbottomnavigation-c3a0a08d98a7ad026512be95ab048fe7a04f823e.tar.gz
android_external_ahbottomnavigation-c3a0a08d98a7ad026512be95ab048fe7a04f823e.tar.bz2
android_external_ahbottomnavigation-c3a0a08d98a7ad026512be95ab048fe7a04f823e.zip
Added hideBottomNavigation(boolean withAnimation)
Added restoreBottomNavigation(boolean withAnimation) Improved Demo Added new gif Updated Readme & Changelog
-rw-r--r--CHANGELOG.md7
-rw-r--r--README.md8
-rw-r--r--ahbottomnavigation/build.gradle6
-rw-r--r--ahbottomnavigation/src/main/java/com/aurelhubert/ahbottomnavigation/AHBottomNavigation.java65
-rw-r--r--ahbottomnavigation/src/main/java/com/aurelhubert/ahbottomnavigation/AHBottomNavigationBehavior.java27
-rw-r--r--demo/src/main/java/com/aurelhubert/ahbottomnavigation/demo/DemoActivity.java11
-rw-r--r--demo/src/main/java/com/aurelhubert/ahbottomnavigation/demo/DemoFragment.java7
-rw-r--r--demo/src/main/res/layout/fragment_demo_settings.xml21
-rw-r--r--demo1.gifbin206957 -> 648051 bytes
9 files changed, 109 insertions, 43 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 9d08c89..4d31cca 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,6 +1,11 @@
## Changelog
-### Newest version: 1.1.7
+### Newest version: 1.1.8
+
+* Added `hideBottomNavigation(boolean withAnimation)`
+* Added `restoreBottomNavigation(boolean withAnimation)`
+
+### 1.1.7
* Added `public AHBottomNavigationItem getItem(int position)` to get a specific item
* Added `public void refresh()` to force a UI refresh
diff --git a/README.md b/README.md
index 39a0169..779392b 100644
--- a/README.md
+++ b/README.md
@@ -5,10 +5,10 @@ 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.7) - [Changelog](https://github.com/aurelhubert/ahbottomnavigation/blob/master/CHANGELOG.md)
+## What's new (1.1.8) - [Changelog](https://github.com/aurelhubert/ahbottomnavigation/blob/master/CHANGELOG.md)
-* Added `public AHBottomNavigationItem getItem(int position)` to get a specific item
-* Added `public void refresh()` to force a UI refresh
+* Added `hideBottomNavigation(boolean withAnimation)`
+* Added `restoreBottomNavigation(boolean withAnimation)`
## Features
* Follow the bottom navigation guidelines (https://www.google.com/design/spec/components/bottom-navigation.html)
@@ -23,7 +23,7 @@ Library to implement the Bottom Navigation component from Material Design guidel
### Gradle
```groovy
dependencies {
- compile 'com.aurelhubert:ahbottomnavigation:1.1.7'
+ compile 'com.aurelhubert:ahbottomnavigation:1.1.8'
}
```
### XML
diff --git a/ahbottomnavigation/build.gradle b/ahbottomnavigation/build.gradle
index 00463a1..5abf149 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.7'
+ libraryVersion = '1.1.8'
developerId = 'aurelhubert'
developerName = 'Aurelien Hubert'
@@ -31,8 +31,8 @@ android {
defaultConfig {
minSdkVersion 14
targetSdkVersion 23
- versionCode 24
- versionName "1.1.7"
+ versionCode 25
+ versionName "1.1.8"
}
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 02b735f..80021e6 100644
--- a/ahbottomnavigation/src/main/java/com/aurelhubert/ahbottomnavigation/AHBottomNavigation.java
+++ b/ahbottomnavigation/src/main/java/com/aurelhubert/ahbottomnavigation/AHBottomNavigation.java
@@ -76,6 +76,7 @@ public class AHBottomNavigation extends FrameLayout {
private boolean forceTint = false;
private boolean forceTitlesDisplay = false;
private boolean needHideBottomNavigation = false;
+ private boolean hideBottomNavigationWithAnimation = false;
// Notifications
private
@@ -239,9 +240,11 @@ public class AHBottomNavigation extends FrameLayout {
itemWidth = maxWidth;
}
+ @ColorInt int colorActiveSmall = ContextCompat.getColor(context, R.color.colorActiveSmall);
+ @ColorInt int colorInactiveSmall = ContextCompat.getColor(context, R.color.colorInactiveSmall);
+
float activeSize = resources.getDimension(R.dimen.bottom_navigation_text_size_active);
float inactiveSize = resources.getDimension(R.dimen.bottom_navigation_text_size_inactive);
-
int activePaddingTop = (int) resources.getDimension(R.dimen.bottom_navigation_margin_top_active);
int notificationActiveMarginLeft = (int) resources.getDimension(R.dimen.bottom_navigation_notification_margin_left_active);
@@ -294,11 +297,8 @@ public class AHBottomNavigation extends FrameLayout {
}
icon.setImageDrawable(AHHelper.getTintDrawable(items.get(i).getDrawable(context),
- currentItem == i ? ContextCompat.getColor(context, R.color.colorActiveSmall) :
- ContextCompat.getColor(context, R.color.colorInactiveSmall), forceTint));
- title.setTextColor(currentItem == i ?
- ContextCompat.getColor(context, R.color.colorActiveSmall) :
- ContextCompat.getColor(context, R.color.colorInactiveSmall));
+ currentItem == i ? colorActiveSmall : colorInactiveSmall, forceTint));
+ title.setTextColor(currentItem == i ? colorActiveSmall :colorInactiveSmall);
} else {
setBackgroundColor(defaultBackgroundColor);
@@ -349,6 +349,10 @@ public class AHBottomNavigation extends FrameLayout {
itemWidth = maxWidth;
}
+
+ @ColorInt int colorActiveSmall = ContextCompat.getColor(context, R.color.colorActiveSmall);
+ @ColorInt int colorInactiveSmall = ContextCompat.getColor(context, R.color.colorInactiveSmall);
+
int activeMarginTop = (int) resources.getDimension(R.dimen.bottom_navigation_small_margin_top_active);
int notificationActiveMarginLeft = (int) resources.getDimension(R.dimen.bottom_navigation_notification_margin_left_active);
float difference = resources.getDimension(R.dimen.bottom_navigation_small_selected_width_difference);
@@ -395,11 +399,8 @@ public class AHBottomNavigation extends FrameLayout {
}
icon.setImageDrawable(AHHelper.getTintDrawable(items.get(i).getDrawable(context),
- currentItem == i ? ContextCompat.getColor(context, R.color.colorActiveSmall) :
- ContextCompat.getColor(context, R.color.colorInactiveSmall), forceTint));
- title.setTextColor(currentItem == i ?
- ContextCompat.getColor(context, R.color.colorActiveSmall) :
- ContextCompat.getColor(context, R.color.colorInactiveSmall));
+ currentItem == i ? colorActiveSmall : colorInactiveSmall, forceTint));
+ title.setTextColor(currentItem == i ? colorActiveSmall : colorInactiveSmall);
} else {
setBackgroundColor(defaultBackgroundColor);
icon.setImageDrawable(AHHelper.getTintDrawable(items.get(i).getDrawable(context),
@@ -451,9 +452,9 @@ public class AHBottomNavigation extends FrameLayout {
inactiveSize = resources.getDimension(R.dimen.bottom_navigation_text_size_forced_inactive);
}
- int itemActiveColor = colored ? ContextCompat.getColor(context, R.color.colorActiveSmall) :
+ @ColorInt int itemActiveColor = colored ? ContextCompat.getColor(context, R.color.colorActiveSmall) :
accentColor;
- int itemInactiveColor = colored ? ContextCompat.getColor(context, R.color.colorInactiveSmall) :
+ @ColorInt int itemInactiveColor = colored ? ContextCompat.getColor(context, R.color.colorInactiveSmall) :
inactiveColor;
for (int i = 0; i < views.size(); i++) {
@@ -555,9 +556,9 @@ public class AHBottomNavigation extends FrameLayout {
int inactiveMargin = (int) resources.getDimension(R.dimen.bottom_navigation_small_margin_top);
int notificationActiveMarginLeft = (int) resources.getDimension(R.dimen.bottom_navigation_notification_margin_left_active);
int notificationInactiveMarginLeft = (int) resources.getDimension(R.dimen.bottom_navigation_notification_margin_left);
- int itemActiveColor = colored ? ContextCompat.getColor(context, R.color.colorActiveSmall) :
+ @ColorInt int itemActiveColor = colored ? ContextCompat.getColor(context, R.color.colorActiveSmall) :
accentColor;
- int itemInactiveColor = colored ? ContextCompat.getColor(context, R.color.colorInactiveSmall) :
+ @ColorInt int itemInactiveColor = colored ? ContextCompat.getColor(context, R.color.colorInactiveSmall) :
inactiveColor;
for (int i = 0; i < views.size(); i++) {
@@ -938,41 +939,61 @@ public class AHBottomNavigation extends FrameLayout {
((CoordinatorLayout.LayoutParams) params).setBehavior(bottomNavigationBehavior);
if (needHideBottomNavigation) {
needHideBottomNavigation = false;
- bottomNavigationBehavior.hideView(this, bottomNavigationHeight);
+ bottomNavigationBehavior.hideView(this, bottomNavigationHeight, hideBottomNavigationWithAnimation);
}
}
}
/**
- * Hide Bottom Navigation
+ * Hide Bottom Navigation with animation
*/
public void hideBottomNavigation() {
+ hideBottomNavigation(true);
+ }
+
+ /**
+ * Hide Bottom Navigation with or without animation
+ *
+ * @param withAnimation Boolean
+ */
+ public void hideBottomNavigation(boolean withAnimation) {
if (bottomNavigationBehavior != null) {
- bottomNavigationBehavior.hideView(this, bottomNavigationHeight);
+ bottomNavigationBehavior.hideView(this, bottomNavigationHeight, withAnimation);
} else if (getParent() instanceof CoordinatorLayout) {
+ //TODO
needHideBottomNavigation = true;
+ hideBottomNavigationWithAnimation = withAnimation;
} else {
// Hide bottom navigation
ViewCompat.animate(this)
.translationY(bottomNavigationHeight)
.setInterpolator(new LinearOutSlowInInterpolator())
- .setDuration(300)
+ .setDuration(withAnimation ? 300 : 0)
.start();
}
}
/**
- * Restore Bottom Navigation
+ * Restore Bottom Navigation with animation
*/
public void restoreBottomNavigation() {
+ restoreBottomNavigation(true);
+ }
+
+ /**
+ * Restore Bottom Navigation with or without animation
+ *
+ * @param withAnimation Boolean
+ */
+ public void restoreBottomNavigation(boolean withAnimation) {
if (bottomNavigationBehavior != null) {
- bottomNavigationBehavior.resetOffset(this);
+ bottomNavigationBehavior.resetOffset(this, withAnimation);
} else {
// Show bottom navigation
ViewCompat.animate(this)
.translationY(0)
.setInterpolator(new LinearOutSlowInInterpolator())
- .setDuration(300)
+ .setDuration(withAnimation ? 300 : 0)
.start();
}
}
diff --git a/ahbottomnavigation/src/main/java/com/aurelhubert/ahbottomnavigation/AHBottomNavigationBehavior.java b/ahbottomnavigation/src/main/java/com/aurelhubert/ahbottomnavigation/AHBottomNavigationBehavior.java
index 94c7f6f..1d869ad 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, false);
+ animateOffset(child, 0, false, true);
} else if (scrollDirection == ScrollDirection.SCROLL_DIRECTION_UP && !hidden) {
hidden = true;
- animateOffset(child, child.getHeight(), false);
+ animateOffset(child, child.getHeight(), false, true);
}
}
@@ -117,16 +117,16 @@ public class AHBottomNavigationBehavior<V extends View> extends VerticalScrollin
* @param child
* @param offset
*/
- private void animateOffset(final V child, final int offset, boolean forceAnimation) {
+ private void animateOffset(final V child, final int offset, boolean forceAnimation, boolean withAnimation) {
if (!behaviorTranslationEnabled && !forceAnimation) {
return;
}
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
- ensureOrCancelObjectAnimation(child, offset);
+ ensureOrCancelObjectAnimation(child, offset, withAnimation);
translationObjectAnimator.start();
} else {
- ensureOrCancelAnimator(child);
+ ensureOrCancelAnimator(child, withAnimation);
translationAnimator.translationY(offset).start();
}
}
@@ -136,10 +136,10 @@ public class AHBottomNavigationBehavior<V extends View> extends VerticalScrollin
*
* @param child
*/
- private void ensureOrCancelAnimator(V child) {
+ private void ensureOrCancelAnimator(V child, boolean withAnimation) {
if (translationAnimator == null) {
translationAnimator = ViewCompat.animate(child);
- translationAnimator.setDuration(ANIM_DURATION);
+ translationAnimator.setDuration(withAnimation ? ANIM_DURATION : 0);
translationAnimator.setUpdateListener(new ViewPropertyAnimatorUpdateListener() {
@Override
public void onAnimationUpdate(View view) {
@@ -161,6 +161,7 @@ public class AHBottomNavigationBehavior<V extends View> extends VerticalScrollin
});
translationAnimator.setInterpolator(INTERPOLATOR);
} else {
+ translationAnimator.setDuration(withAnimation ? ANIM_DURATION : 0);
translationAnimator.cancel();
}
}
@@ -170,14 +171,14 @@ public class AHBottomNavigationBehavior<V extends View> extends VerticalScrollin
*
* @param child
*/
- private void ensureOrCancelObjectAnimation(final V child, final int offset) {
+ private void ensureOrCancelObjectAnimation(final V child, final int offset, boolean withAnimation) {
if (translationObjectAnimator != null) {
translationObjectAnimator.cancel();
}
translationObjectAnimator = ObjectAnimator.ofFloat(child, View.TRANSLATION_Y, offset);
- translationObjectAnimator.setDuration(ANIM_DURATION);
+ translationObjectAnimator.setDuration(withAnimation ? ANIM_DURATION : 0);
translationObjectAnimator.setInterpolator(INTERPOLATOR);
translationObjectAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
@@ -223,16 +224,16 @@ public class AHBottomNavigationBehavior<V extends View> extends VerticalScrollin
* @param view
* @param offset
*/
- public void hideView(V view, int offset) {
- animateOffset(view, offset, true);
+ public void hideView(V view, int offset, boolean withAnimation) {
+ animateOffset(view, offset, true, withAnimation);
}
/**
* Reset AHBottomNavigation position with animation
* @param view
*/
- public void resetOffset(V view) {
- animateOffset(view, 0, true);
+ public void resetOffset(V view, boolean withAnimation) {
+ animateOffset(view, 0, true, withAnimation);
}
/**
diff --git a/demo/src/main/java/com/aurelhubert/ahbottomnavigation/demo/DemoActivity.java b/demo/src/main/java/com/aurelhubert/ahbottomnavigation/demo/DemoActivity.java
index b277466..1f7004f 100644
--- a/demo/src/main/java/com/aurelhubert/ahbottomnavigation/demo/DemoActivity.java
+++ b/demo/src/main/java/com/aurelhubert/ahbottomnavigation/demo/DemoActivity.java
@@ -195,6 +195,17 @@ public class DemoActivity extends AppCompatActivity {
}
/**
+ * Show or hide the bottom navigation with animation
+ */
+ public void showOrHideBottomNavigation(boolean show) {
+ if (show) {
+ bottomNavigation.restoreBottomNavigation(true);
+ } else {
+ bottomNavigation.hideBottomNavigation(true);
+ }
+ }
+
+ /**
* Return the number of items in the bottom navigation
*/
public int getBottomNavigationNbItems() {
diff --git a/demo/src/main/java/com/aurelhubert/ahbottomnavigation/demo/DemoFragment.java b/demo/src/main/java/com/aurelhubert/ahbottomnavigation/demo/DemoFragment.java
index 7002f16..46265e5 100644
--- a/demo/src/main/java/com/aurelhubert/ahbottomnavigation/demo/DemoFragment.java
+++ b/demo/src/main/java/com/aurelhubert/ahbottomnavigation/demo/DemoFragment.java
@@ -53,6 +53,7 @@ public class DemoFragment extends Fragment {
final DemoActivity demoActivity = (DemoActivity) getActivity();
final SwitchCompat switchColored = (SwitchCompat) view.findViewById(R.id.fragment_demo_switch_colored);
final SwitchCompat switchFiveItems = (SwitchCompat) view.findViewById(R.id.fragment_demo_switch_five_items);
+ final SwitchCompat showHideBottomNavigation = (SwitchCompat) view.findViewById(R.id.fragment_demo_show_hide);
switchColored.setChecked(demoActivity.isBottomNavigationColored());
switchFiveItems.setChecked(demoActivity.getBottomNavigationNbItems() == 5);
@@ -69,6 +70,12 @@ public class DemoFragment extends Fragment {
demoActivity.updateBottomNavigationItems(isChecked);
}
});
+ showHideBottomNavigation.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
+ @Override
+ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
+ demoActivity.showOrHideBottomNavigation(isChecked);
+ }
+ });
}
/**
diff --git a/demo/src/main/res/layout/fragment_demo_settings.xml b/demo/src/main/res/layout/fragment_demo_settings.xml
index 13191e2..ce70530 100644
--- a/demo/src/main/res/layout/fragment_demo_settings.xml
+++ b/demo/src/main/res/layout/fragment_demo_settings.xml
@@ -45,4 +45,25 @@
</LinearLayout>
+ <LinearLayout
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_marginTop="24dp"
+ android:orientation="horizontal">
+
+ <TextView
+ android:layout_width="0dp"
+ android:layout_height="wrap_content"
+ android:layout_weight="1"
+ android:text="Show bottom navigation"
+ android:textSize="18sp"/>
+
+ <android.support.v7.widget.SwitchCompat
+ android:id="@+id/fragment_demo_show_hide"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:checked="true"/>
+
+ </LinearLayout>
+
</LinearLayout> \ No newline at end of file
diff --git a/demo1.gif b/demo1.gif
index ab13c58..dbf12b2 100644
--- a/demo1.gif
+++ b/demo1.gif
Binary files differ