fab: use auto calculated fling threshold
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
parent
f315654d40
commit
8e3586328c
@ -8,21 +8,26 @@ package com.wireguard.android.widget;
|
|||||||
|
|
||||||
import android.support.v7.widget.RecyclerView;
|
import android.support.v7.widget.RecyclerView;
|
||||||
|
|
||||||
|
import com.wireguard.android.R;
|
||||||
|
|
||||||
public abstract class CustomRecyclerViewScrollListener extends RecyclerView.OnScrollListener {
|
public abstract class CustomRecyclerViewScrollListener extends RecyclerView.OnScrollListener {
|
||||||
|
|
||||||
private int scrollDist;
|
private int scrollDist;
|
||||||
private boolean isVisible = true;
|
private boolean isVisible = true;
|
||||||
private static final float FLING_THRESHOLD = 25;
|
private static int flingThreshold;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onScrolled(final RecyclerView recyclerView, final int dx, final int dy) {
|
public void onScrolled(final RecyclerView recyclerView, final int dx, final int dy) {
|
||||||
super.onScrolled(recyclerView, dx, dy);
|
super.onScrolled(recyclerView, dx, dy);
|
||||||
|
|
||||||
if (isVisible && scrollDist > FLING_THRESHOLD) {
|
if (flingThreshold == 0)
|
||||||
|
flingThreshold = recyclerView.getResources().getDimensionPixelSize(R.dimen.design_fab_size_normal) / 2;
|
||||||
|
|
||||||
|
if (isVisible && scrollDist >= flingThreshold) {
|
||||||
hide();
|
hide();
|
||||||
scrollDist = 0;
|
scrollDist = 0;
|
||||||
isVisible = false;
|
isVisible = false;
|
||||||
} else if (!isVisible && scrollDist < -FLING_THRESHOLD) {
|
} else if (!isVisible && scrollDist <= -flingThreshold) {
|
||||||
show();
|
show();
|
||||||
scrollDist = 0;
|
scrollDist = 0;
|
||||||
isVisible = true;
|
isVisible = true;
|
||||||
|
Loading…
Reference in New Issue
Block a user