Scroll instead of fling

pull/172/head
M66B 5 years ago
parent 383cafdd20
commit 3c324e3de9

@ -76,6 +76,7 @@ import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.SeekBar;
import android.widget.Spinner;
import android.widget.TextView;
@ -192,6 +193,8 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
private FixedRecyclerView rvMessage;
private View vwAnchor;
private SeekBar sbThread;
private ImageView ivLeft;
private ImageView ivRight;
private ImageButton ibDown;
private ImageButton ibUp;
private ImageButton ibSeen;
@ -381,6 +384,8 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
rvMessage = view.findViewById(R.id.rvMessage);
vwAnchor = view.findViewById(R.id.vwAnchor);
sbThread = view.findViewById(R.id.sbThread);
ivLeft = view.findViewById(R.id.ivLeft);
ivRight = view.findViewById(R.id.ivRight);
ibDown = view.findViewById(R.id.ibDown);
ibUp = view.findViewById(R.id.ibUp);
ibSeen = view.findViewById(R.id.ibSeen);
@ -982,6 +987,8 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
tvNoEmail.setVisibility(View.GONE);
tvNoEmailHint.setVisibility(View.GONE);
sbThread.setVisibility(View.GONE);
ivLeft.setVisibility(View.GONE);
ivRight.setVisibility(View.GONE);
ibDown.setVisibility(View.GONE);
ibUp.setVisibility(View.GONE);
ibSeen.setVisibility(View.GONE);
@ -1052,7 +1059,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
final SwipeListener swipeListener = new SwipeListener(getContext(), new SwipeListener.ISwipeListener() {
@Override
public boolean onSwipeRight() {
public boolean onSwipedRight() {
if (prev == null) {
Animation bounce = AnimationUtils.loadAnimation(getContext(), R.anim.bounce_right);
view.startAnimation(bounce);
@ -1063,7 +1070,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
}
@Override
public boolean onSwipeLeft() {
public boolean onSwipedLeft() {
if (next == null) {
Animation bounce = AnimationUtils.loadAnimation(getContext(), R.anim.bounce_left);
view.startAnimation(bounce);
@ -1072,6 +1079,24 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
return (next != null);
}
@Override
public void onSwipingLeft() {
ivLeft.setVisibility(View.VISIBLE);
ivRight.setVisibility(View.GONE);
}
@Override
public void onSwipingRight() {
ivLeft.setVisibility(View.GONE);
ivRight.setVisibility(View.VISIBLE);
}
@Override
public void onCancel() {
ivLeft.setVisibility(View.GONE);
ivRight.setVisibility(View.GONE);
}
});
rvMessage.addOnItemTouchListener(new RecyclerView.OnItemTouchListener() {

@ -31,12 +31,12 @@ public class SwipeListener implements View.OnTouchListener {
SwipeListener(final Context context, final ISwipeListener listener) {
final int width = context.getResources().getDisplayMetrics().widthPixels;
final int MOVE_THRESHOLD = width / 3;
final int SPEED_THRESHOLD = width / 2;
final int MOVE_THRESHOLD = width / 10;
final int SWIPE_THRESHOLD = width / 3;
gestureDetector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() {
@Override
public boolean onFling(MotionEvent me1, MotionEvent me2, float vx, float vy) {
public boolean onScroll(MotionEvent me1, MotionEvent me2, float distanceX, float distanceY) {
if (me1 == null || me2 == null)
return false;
if (me1.getPointerCount() > 1 || me2.getPointerCount() > 1)
@ -45,21 +45,39 @@ public class SwipeListener implements View.OnTouchListener {
boolean consumed = false;
int dx = Math.round(me2.getX() - me1.getX());
int dy = Math.round(me2.getY() - me1.getY());
if (Math.abs(dx) > Math.abs(dy)) {
Log.i("Swipe dx=" + dx + "/" + MOVE_THRESHOLD + " vx=" + vx + "/" + SPEED_THRESHOLD);
if (Math.abs(dx) > MOVE_THRESHOLD && Math.abs(vx) > SPEED_THRESHOLD)
try {
Log.i("Swipe dx=" + dx + "/" + SWIPE_THRESHOLD);
try {
if (Math.abs(dx) > SWIPE_THRESHOLD) {
if (dx > 0)
consumed = listener.onSwipedRight();
else
consumed = listener.onSwipedLeft();
} else if (Math.abs(dx) > MOVE_THRESHOLD) {
if (dx > 0)
consumed = listener.onSwipeRight();
listener.onSwipingRight();
else
consumed = listener.onSwipeLeft();
} catch (Throwable ex) {
Log.e(ex);
listener.onSwipingLeft();
}
} catch (Throwable ex) {
Log.e(ex);
}
}
return consumed;
}
});
}) {
@Override
public boolean onTouchEvent(MotionEvent ev) {
if (ev.getAction() == MotionEvent.ACTION_UP)
try {
listener.onCancel();
} catch (Throwable ex) {
Log.e(ex);
}
return super.onTouchEvent(ev);
}
};
}
public boolean onTouch(@NonNull View view, @NonNull MotionEvent event) {
@ -67,8 +85,14 @@ public class SwipeListener implements View.OnTouchListener {
}
interface ISwipeListener {
boolean onSwipeRight();
boolean onSwipedRight();
boolean onSwipedLeft();
void onSwipingLeft();
void onSwipingRight();
boolean onSwipeLeft();
void onCancel();
}
}

@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M15.41,16.59L10.83,12l4.58,-4.59L14,6l-6,6 6,6 1.41,-1.41z"/>
</vector>

@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M8.59,16.59L13.17,12 8.59,7.41 10,6l6,6 -6,6 -1.41,-1.41z"/>
</vector>

@ -200,6 +200,30 @@
app:layout_constraintEnd_toEndOf="parent"
app:srcCompat="@drawable/baseline_reply_24" />
<ImageView
android:id="@+id/ivLeft"
android:layout_width="60dp"
android:layout_height="60dp"
android:padding="12dp"
android:tint="?attr/colorSeparator"
app:layout_constraintBottom_toTopOf="@+id/sbThread"
app:layout_constraintHorizontal_chainStyle="packed"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/baseline_keyboard_arrow_left_24" />
<ImageView
android:id="@+id/ivRight"
android:layout_width="60dp"
android:layout_height="60dp"
android:padding="12dp"
android:tint="?attr/colorSeparator"
app:layout_constraintBottom_toTopOf="@+id/sbThread"
app:layout_constraintHorizontal_chainStyle="packed"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/baseline_keyboard_arrow_right_24" />
<ImageButton
android:id="@+id/ibDown"
android:layout_width="wrap_content"

Loading…
Cancel
Save