package com.example.flinggesturedemo; import android.os.Bundle; import android.view.GestureDetector; import android.view.MotionEvent; import android.widget.Toast; import androidx.appcompat.app.AppCompatActivity; /* A swipe becomes a fling based on ending velocity and whether the affected element has crossed a threshold (or point past which an action can be undone). A drag maintains contact with an element, so reversing the direction of the gesture will drag the element back across the threshold. */ public class MainActivity extends AppCompatActivity { GestureDetector gestureDetector; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); gestureDetector = new GestureDetector(this, new GestureListener()); } private class GestureListener extends GestureDetector.SimpleOnGestureListener { @Override public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { Toast.makeText(MainActivity.this, "Fling", Toast.LENGTH_SHORT).show(); return super.onFling(e1, e2, velocityX, velocityY); } } @Override public boolean onTouchEvent(MotionEvent event) { gestureDetector.onTouchEvent(event); return super.onTouchEvent(event); } }