public class MainActivity extends AppCompatActivity {
private GestureDetector mDetector;
@
Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
View myView = findViewById(R.id.my_view);
mDetector = new GestureDetector(this, new MyGestureListener());
myView.setOnTouchListener(touchListener);
}
View.OnTouchListener touchListener = new View.OnTouchListener() {
@
Override
public boolean onTouch(View v, MotionEvent event) {
return mDetector.onTouchEvent(event);
}
};
class MyGestureListener extends GestureDetector.SimpleOnGestureListener {
@
Override
public boolean onDown(MotionEvent event) {
Log.d("TAG","onDown: ");
return true;
}
@
Override
public boolean onSingleTapConfirmed(MotionEvent e) {
Log.i("TAG", "onSingleTapConfirmed: ");
return true;
}
@
Override
public void onLongPress(MotionEvent e) {
Log.i("TAG", "onLongPress: ");
}
@
Override
public boolean onDoubleTap(MotionEvent e) {
Log.i("TAG", "onDoubleTap: ");
return true;
}
@
Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
Log.i("TAG", "onScroll: ");
return true;
}
@
Override
public boolean onFling(MotionEvent event1, MotionEvent event2, float velocityX, float velocityY) {
Log.d("TAG", "onFling: ");
return true;
}
}
}