From 6558140a7ca7eda2e39c75cbb587a6f25e3cda4e Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Sun, 29 Jul 2018 16:43:19 +0200 Subject: FloatingActionButtonBehavior: animate transitions Signed-off-by: Jason A. Donenfeld --- .../widget/fab/FloatingActionButtonBehavior.java | 36 +++++++++++++++++++--- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/wireguard/android/widget/fab/FloatingActionButtonBehavior.java b/app/src/main/java/com/wireguard/android/widget/fab/FloatingActionButtonBehavior.java index c41687b0..ff2adf5a 100644 --- a/app/src/main/java/com/wireguard/android/widget/fab/FloatingActionButtonBehavior.java +++ b/app/src/main/java/com/wireguard/android/widget/fab/FloatingActionButtonBehavior.java @@ -6,13 +6,19 @@ package com.wireguard.android.widget.fab; +import android.animation.Animator; +import android.animation.AnimatorListenerAdapter; +import android.animation.TimeInterpolator; +import android.animation.ValueAnimator; import android.content.Context; import android.support.design.widget.CoordinatorLayout; import android.support.design.widget.Snackbar; +import android.support.v4.view.animation.FastOutSlowInInterpolator; import android.util.AttributeSet; import android.view.View; public class FloatingActionButtonBehavior extends CoordinatorLayout.Behavior { + public FloatingActionButtonBehavior(final Context context, final AttributeSet attrs) { super(context, attrs); } @@ -23,17 +29,39 @@ public class FloatingActionButtonBehavior extends CoordinatorLayout.Behavior child.setBehaviorYTranslation((float)a.getAnimatedValue())); + animator.start(); + } + @Override public boolean onDependentViewChanged(final CoordinatorLayout parent, final FloatingActionsMenu child, final View dependency) { - child.setBehaviorYTranslation(Math.min(0, dependency.getTranslationY() - dependency.getMeasuredHeight())); + animateChange(child, Math.min(0, dependency.getTranslationY() - dependency.getMeasuredHeight()), dependency.getMeasuredHeight()); return true; } @Override - public void onDependentViewRemoved(final CoordinatorLayout parent, FloatingActionsMenu child, + public void onDependentViewRemoved(final CoordinatorLayout parent, final FloatingActionsMenu child, final View dependency) { - // TODO(msf): animate this so it isn't so dramatic when the snackbar is swiped away - child.setBehaviorYTranslation(0); + animateChange(child, 0, dependency.getMeasuredHeight()); } } -- cgit v1.2.3