mirror of
https://github.com/mihonapp/mihon.git
synced 2025-06-25 18:47:51 +02:00
FAB animation update
This commit is contained in:
@ -19,10 +19,19 @@ import android.content.Context;
|
||||
import android.support.design.widget.CoordinatorLayout;
|
||||
import android.support.design.widget.FloatingActionButton;
|
||||
import android.support.v4.view.ViewCompat;
|
||||
import android.support.v4.view.animation.FastOutSlowInInterpolator;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
import android.view.animation.Animation;
|
||||
import android.view.animation.AnimationUtils;
|
||||
import android.view.animation.Interpolator;
|
||||
|
||||
import eu.kanade.tachiyomi.R;
|
||||
|
||||
public class ScrollAwareFABBehavior extends FloatingActionButton.Behavior {
|
||||
private static final Interpolator INTERPOLATOR = new FastOutSlowInInterpolator();
|
||||
private boolean mIsAnimatingOut = false;
|
||||
|
||||
public ScrollAwareFABBehavior(Context context, AttributeSet attrs) {
|
||||
super();
|
||||
}
|
||||
@ -40,12 +49,43 @@ public class ScrollAwareFABBehavior extends FloatingActionButton.Behavior {
|
||||
final View target, final int dxConsumed, final int dyConsumed,
|
||||
final int dxUnconsumed, final int dyUnconsumed) {
|
||||
super.onNestedScroll(coordinatorLayout, child, target, dxConsumed, dyConsumed, dxUnconsumed, dyUnconsumed);
|
||||
if (dyConsumed > 0 && child.getVisibility() == View.VISIBLE) {
|
||||
if (dyConsumed > 0 && !this.mIsAnimatingOut && child.getVisibility() == View.VISIBLE) {
|
||||
// User scrolled down and the FAB is currently visible -> hide the FAB
|
||||
child.hide();
|
||||
animateOut(child);
|
||||
} else if (dyConsumed < 0 && child.getVisibility() != View.VISIBLE) {
|
||||
// User scrolled up and the FAB is currently not visible -> show the FAB
|
||||
child.show();
|
||||
animateIn(child);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Same animation that FloatingActionButton.Behavior uses to hide the FAB when the AppBarLayout exits
|
||||
private void animateOut(final FloatingActionButton button) {
|
||||
Animation anim = AnimationUtils.loadAnimation(button.getContext(), R.anim.fab_hide_to_bottom);
|
||||
anim.setInterpolator(INTERPOLATOR);
|
||||
anim.setDuration(200L);
|
||||
anim.setAnimationListener(new Animation.AnimationListener() {
|
||||
public void onAnimationStart(Animation animation) {
|
||||
ScrollAwareFABBehavior.this.mIsAnimatingOut = true;
|
||||
}
|
||||
|
||||
public void onAnimationEnd(Animation animation) {
|
||||
ScrollAwareFABBehavior.this.mIsAnimatingOut = false;
|
||||
button.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationRepeat(final Animation animation) {
|
||||
}
|
||||
});
|
||||
button.startAnimation(anim);
|
||||
}
|
||||
|
||||
// Same animation that FloatingActionButton.Behavior uses to show the FAB when the AppBarLayout enters
|
||||
private void animateIn(FloatingActionButton button) {
|
||||
button.setVisibility(View.VISIBLE);
|
||||
Animation anim = AnimationUtils.loadAnimation(button.getContext(), R.anim.fab_show_from_bottom);
|
||||
anim.setDuration(200L);
|
||||
anim.setInterpolator(INTERPOLATOR);
|
||||
button.startAnimation(anim);
|
||||
}
|
||||
}
|
@ -65,15 +65,6 @@ public class MangaInfoFragment extends BaseRxFragment<MangaInfoPresenter> {
|
||||
View view = inflater.inflate(R.layout.fragment_manga_info, container, false);
|
||||
ButterKnife.bind(this, view);
|
||||
|
||||
//Create edit drawable with size 24dp (google guidelines)
|
||||
IconicsDrawable edit = new IconicsDrawable(this.getContext())
|
||||
.icon(GoogleMaterial.Icon.gmd_edit)
|
||||
.color(ContextCompat.getColor(this.getContext(), R.color.white))
|
||||
.sizeDp(24);
|
||||
|
||||
// Update image of fab button
|
||||
fabEdit.setImageDrawable(edit);
|
||||
|
||||
// Set listener.
|
||||
fabEdit.setOnClickListener(v -> selectImage());
|
||||
|
||||
|
Reference in New Issue
Block a user