diff --git a/library/src/main/java/com/github/sealstudios/fab/FloatingActionMenu.java b/library/src/main/java/com/github/sealstudios/fab/FloatingActionMenu.java
index e3ec5ef..c44fa65 100755
--- a/library/src/main/java/com/github/sealstudios/fab/FloatingActionMenu.java
+++ b/library/src/main/java/com/github/sealstudios/fab/FloatingActionMenu.java
@@ -31,6 +31,9 @@
public class FloatingActionMenu extends ViewGroup {
+ private Animation mShowAnimation;
+ private Animation mHideAnimation;
+
private static final int ANIMATION_DURATION = 300;
private static final float CLOSED_PLUS_ROTATION = 0f;
private static final float OPENED_PLUS_ROTATION_LEFT = -90f - 45f;
@@ -211,6 +214,8 @@ private void init(Context context, AttributeSet attrs) {
createMenuButton();
initMenuButtonAnimations(attr);
+ initShowAnimation(attr);
+ initHideAnimation(attr);
attr.recycle();
}
@@ -1258,4 +1263,72 @@ public void setOnMenuButtonClickListener(OnClickListener clickListener) {
public void setOnMenuButtonLongClickListener(OnLongClickListener longClickListener) {
mMenuButton.setOnLongClickListener(longClickListener);
}
+
+
+
+
+
+
+
+
+ public boolean isHidden() {
+ return getVisibility() == INVISIBLE;
+ }
+
+ public void show(boolean animate) {
+ if (isHidden()) {
+ if (animate) {
+ playShowAnimation();
+ }
+ super.setVisibility(VISIBLE);
+ }
+ }
+
+ public void hide(boolean animate) {
+ if (!isHidden()) {
+ if (animate) {
+ playHideAnimation();
+ }
+ super.setVisibility(INVISIBLE);
+ }
+ }
+
+ private void initShowAnimation(TypedArray attr) {
+ int resourceId = attr.getResourceId(R.styleable.FloatingActionButton_fab_showAnimation, R.anim.fab_scale_up);
+ mShowAnimation = AnimationUtils.loadAnimation(getContext(), resourceId);
+ }
+
+ private void initHideAnimation(TypedArray attr) {
+ int resourceId = attr.getResourceId(R.styleable.FloatingActionButton_fab_hideAnimation, R.anim.fab_scale_down);
+ mHideAnimation = AnimationUtils.loadAnimation(getContext(), resourceId);
+ }
+
+ public void setShowAnimation(Animation showAnimation) {
+ mShowAnimation = showAnimation;
+ }
+
+ public void setHideAnimation(Animation hideAnimation) {
+ mHideAnimation = hideAnimation;
+ }
+
+
+ Animation getShowAnimation() {
+ return mShowAnimation;
+ }
+
+ Animation getHideAnimation() {
+ return mHideAnimation;
+ }
+
+ void playShowAnimation() {
+ mHideAnimation.cancel();
+ startAnimation(mShowAnimation);
+ }
+
+ void playHideAnimation() {
+ mShowAnimation.cancel();
+ startAnimation(mHideAnimation);
+ }
+
+
}
diff --git a/library/src/main/res/values/attrs.xml b/library/src/main/res/values/attrs.xml
index e1d8333..237a64d 100755
--- a/library/src/main/res/values/attrs.xml
+++ b/library/src/main/res/values/attrs.xml
@@ -85,6 +85,8 @@
+
+
\ No newline at end of file
diff --git a/sample/src/main/java/com/github/sealstudios/fab/sample/MenusFragment.java b/sample/src/main/java/com/github/sealstudios/fab/sample/MenusFragment.java
index 95e5049..fd74c8b 100644
--- a/sample/src/main/java/com/github/sealstudios/fab/sample/MenusFragment.java
+++ b/sample/src/main/java/com/github/sealstudios/fab/sample/MenusFragment.java
@@ -37,6 +37,7 @@ public class MenusFragment extends Fragment {
private FloatingActionButton fab3;
private FloatingActionButton fabEdit;
+ private boolean isHidden = false;
private List menus = new ArrayList<>();
private Handler mUiHandler = new Handler();
@@ -95,6 +96,17 @@ public void onClick(View v) {
menuLabelsRight.hideMenuButton(false);
fabEdit = (FloatingActionButton) view.findViewById(R.id.fab_edit);
+ fabEdit.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ isHidden = !isHidden;
+ if (isHidden){
+ menuRed.show(true);
+ } else {
+ menuRed.hide(true);
+ }
+ }
+ });
fabEdit.setShowAnimation(AnimationUtils.loadAnimation(getActivity(), R.anim.scale_up));
fabEdit.setHideAnimation(AnimationUtils.loadAnimation(getActivity(), R.anim.scale_down));
}
diff --git a/sample/src/main/res/layout/menus_fragment.xml b/sample/src/main/res/layout/menus_fragment.xml
index 8863e61..62a1bec 100644
--- a/sample/src/main/res/layout/menus_fragment.xml
+++ b/sample/src/main/res/layout/menus_fragment.xml
@@ -85,7 +85,6 @@
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
- fab:menu_icon="@drawable/ic_star"
fab:menu_animationDelayPerItem="0"
fab:menu_colorNormal="#43A047"
fab:menu_colorPressed="#2E7D32"
@@ -222,6 +221,8 @@
android:paddingLeft="10dp"
fab:menu_labels_ellipsize="end"
fab:menu_labels_singleLine="true"
+ fab:fab_showAnimation="@anim/show_from_bottom"
+ fab:fab_hideAnimation="@anim/hide_to_bottom"
fab:menu_fab_label="Menu label">