110 lines
4.5 KiB
Java
110 lines
4.5 KiB
Java
package code.name.monkey.retromusic.misc;
|
|
|
|
import android.content.Context;
|
|
import android.os.Handler;
|
|
import android.support.annotation.NonNull;
|
|
import android.support.design.widget.CoordinatorLayout;
|
|
import android.support.design.widget.FloatingActionButton;
|
|
import android.support.v4.view.ViewCompat;
|
|
import android.util.AttributeSet;
|
|
import android.util.Log;
|
|
import android.view.View;
|
|
import android.view.animation.LinearInterpolator;
|
|
|
|
/*Don't delete even if its not showing not using*/
|
|
public class ScrollAwareFABBehavior extends CoordinatorLayout.Behavior<FloatingActionButton> {
|
|
private static final String TAG = "ScrollingFABBehavior";
|
|
Handler mHandler;
|
|
|
|
public ScrollAwareFABBehavior(Context context, AttributeSet attrs) {
|
|
super();
|
|
}
|
|
|
|
@Override
|
|
public void onStopNestedScroll(@NonNull CoordinatorLayout coordinatorLayout,
|
|
@NonNull FloatingActionButton child,
|
|
@NonNull View target) {
|
|
super.onStopNestedScroll(coordinatorLayout, child, target);
|
|
|
|
if (mHandler == null)
|
|
mHandler = new Handler();
|
|
|
|
|
|
mHandler.postDelayed(() -> {
|
|
child.animate().translationY(0).setInterpolator(new LinearInterpolator()).start();
|
|
Log.d("FabAnim", "startHandler()");
|
|
}, 1000);
|
|
|
|
}
|
|
|
|
@Override
|
|
public void onNestedScroll(@NonNull CoordinatorLayout coordinatorLayout,
|
|
@NonNull FloatingActionButton child,
|
|
@NonNull View target,
|
|
int dxConsumed,
|
|
int dyConsumed,
|
|
int dxUnconsumed,
|
|
int dyUnconsumed) {
|
|
super.onNestedScroll(coordinatorLayout, child, target, dxConsumed, dyConsumed, dxUnconsumed, dyUnconsumed);
|
|
|
|
//child -> Floating Action Button
|
|
if (dyConsumed > 0) {
|
|
Log.d("Scrolling", "Up");
|
|
CoordinatorLayout.LayoutParams layoutParams = (CoordinatorLayout.LayoutParams) child.getLayoutParams();
|
|
int fab_bottomMargin = layoutParams.bottomMargin;
|
|
child.animate().translationY(child.getHeight() + fab_bottomMargin).setInterpolator(new LinearInterpolator()).start();
|
|
} else if (dyConsumed < 0) {
|
|
Log.d("Scrolling", "down");
|
|
child.animate().translationY(0).setInterpolator(new LinearInterpolator()).start();
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public boolean onStartNestedScroll(@NonNull CoordinatorLayout coordinatorLayout,
|
|
@NonNull FloatingActionButton child,
|
|
@NonNull View directTargetChild,
|
|
@NonNull View target,
|
|
int nestedScrollAxes) {
|
|
if (mHandler != null) {
|
|
mHandler.removeMessages(0);
|
|
Log.d("Scrolling", "stopHandler()");
|
|
}
|
|
return nestedScrollAxes == ViewCompat.SCROLL_AXIS_VERTICAL;
|
|
}
|
|
}
|
|
/*extends FloatingActionButton.Behavior {
|
|
|
|
public ScrollAwareFABBehavior(Context context, AttributeSet attrs) {
|
|
super();
|
|
}
|
|
|
|
|
|
@Override
|
|
public boolean onStartNestedScroll(@NonNull final CoordinatorLayout coordinatorLayout,
|
|
@NonNull final FloatingActionButton child,
|
|
@NonNull final View directTargetChild,
|
|
@NonNull final View target,
|
|
final int nestedScrollAxes) {
|
|
// Ensure we react to vertical scrolling
|
|
return nestedScrollAxes == ViewCompat.SCROLL_AXIS_VERTICAL
|
|
|| super.onStartNestedScroll(coordinatorLayout, child, directTargetChild, target, nestedScrollAxes);
|
|
}
|
|
|
|
@Override
|
|
public void onNestedScroll(@NonNull CoordinatorLayout coordinatorLayout,
|
|
@NonNull FloatingActionButton child,
|
|
@NonNull View target,
|
|
int dxConsumed,
|
|
int dyConsumed,
|
|
int dxUnconsumed,
|
|
int dyUnconsumed) {
|
|
super.onNestedScroll(coordinatorLayout, child, target, dxConsumed, dyConsumed, dxUnconsumed,
|
|
dyUnconsumed);
|
|
|
|
if (dyConsumed > 0 && child.getVisibility() == View.VISIBLE) {
|
|
child.hide();
|
|
} else if (dyConsumed < 0 && child.getVisibility() != View.VISIBLE) {
|
|
child.show();
|
|
}
|
|
}
|
|
}*/ |