import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.GestureDetector; import android.view.GestureDetector.OnDoubleTapListener; import android.view.Menu; import android.view.MotionEvent; import android.widget.Toast; public class MainActivity extends Activity implements GestureDetector.OnGestureListener{ private GestureDetector detector; protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); detector = new GestureDetector(this, this); detector.setOnDoubleTapListener(new OnDoubleTapListener() { public boolean onSingleTapConfirmed(MotionEvent e) { System.out.println("onSingleTapConfirmed"); return false; } public boolean onDoubleTapEvent(MotionEvent e) { System.out.println("onDoubleTapEvent"); return false; } public boolean onDoubleTap(MotionEvent e) { System.out.println("onDoubleTap"); return false; } }); } public boolean onTouchEvent(MotionEvent event){ System.out.println("onDoubleTap"); return detector.onTouchEvent(event); } public boolean onDown(MotionEvent e) { // Intent intent=new Intent(); // intent.setClass(MainActivity.this, StartActivity.class); // startActivity(intent); // finish(); // System.out.println("onDown"); return false; } public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,float velocityY) { if (e1.getX() - e2.getX() > 200&& Math.abs(velocityX) > 20) {// Fling left System.out.println("Fling Left"); Toast.makeText(this, "Fling Left", Toast.LENGTH_SHORT).show(); } else if (e2.getX() - e1.getX() > 200&& Math.abs(velocityX) > 20) { // Fling right System.out.println("Fling Right"); Toast.makeText(this, "Fling Right", Toast.LENGTH_SHORT).show(); } else if (e2.getY() - e1.getY() > 200&& Math.abs(velocityY) > 20) { //Fling down System.out.println("Fling down"); Toast.makeText(this, "Fling down", Toast.LENGTH_SHORT).show(); } else if (e1.getY() - e2.getY() > 200&& Math.abs(velocityY) > 20) { //Fling up System.out.println("Fling up"); Toast.makeText(this, "Fling up", Toast.LENGTH_SHORT).show(); } return false; } public void onLongPress(MotionEvent e) { System.out.println("onLongPress"); } public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX,float distanceY) { if (e1.getX() - e2.getX() > 200&& Math.abs(distanceX) > 20) {// Scroll left System.out.println("Scroll Left"); Toast.makeText(this, "Scroll Left", Toast.LENGTH_SHORT).show(); } else if (e2.getX() - e1.getX() > 200&& Math.abs(distanceX) > 20) { // Scroll right System.out.println("Scroll Right"); Toast.makeText(this, "Scroll Right", Toast.LENGTH_SHORT).show(); } else if (e2.getY() - e1.getY() > 200&& Math.abs(distanceY) > 20) { //Scroll down System.out.println("Scroll down"); Toast.makeText(this, "Scroll down", Toast.LENGTH_SHORT).show(); } else if (e1.getY() - e2.getY() > 200&& Math.abs(distanceY) > 20) { //Scroll up System.out.println("Scroll up"); Toast.makeText(this, "Scroll up", Toast.LENGTH_SHORT).show(); } System.out.println("onScroll"); return false; } public void onShowPress(MotionEvent e) { System.out.println("onShowPress"); } public boolean onSingleTapUp(MotionEvent e) { System.out.println("onSingleTapUp"); return false; } public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.main, menu); return true; } }