package com.example.commongestures;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.GestureDetector;
import android.widget.TextView;
import android.view.MotionEvent;
import android.support.v4.view.GestureDetectorCompat;

public class CommonGesturesActivity extends Activity
    implements GestureDetector.OnGestureListener, 
    GestureDetector.OnDoubleTapListener {

	private TextView gestureText;
	private GestureDetectorCompat gDetector;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_common_gestures);
		gestureText = (TextView)findViewById(R.id.gestureStatusText);
		this.gDetector = new GestureDetectorCompat(this,this);
		gDetector.setOnDoubleTapListener(this);

	}

	@Override 
	public boolean onTouchEvent(MotionEvent event) { 
		 this.gDetector.onTouchEvent(event);
		 // Be sure to call the superclass implementation
		 return super.onTouchEvent(event);
	}

	
    @Override
    public boolean onDown(MotionEvent event) { 
        gestureText.setText ("onDown"); 
        return true;
    }

    @Override
    public boolean onFling(MotionEvent event1, MotionEvent event2, 
            float velocityX, float velocityY) {
        gestureText.setText("onFling");
        return true;
    }

    @Override
    public void onLongPress(MotionEvent event) {
        gestureText.setText("onLongPress"); 
    }

    @Override
    public boolean onScroll(MotionEvent e1, MotionEvent e2, 
              float distanceX, float distanceY) {
        gestureText.setText("onScroll");
        return true;
    }
  
    @Override
    public void onShowPress(MotionEvent event) {
        gestureText.setText("onShowPress");
    }

    @Override
    public boolean onSingleTapUp(MotionEvent event) {
        gestureText.setText("onSingleTapUp");
        return true;
    }
  
    @Override
    public boolean onDoubleTap(MotionEvent event) {
  	  gestureText.setText("onDoubleTap");
        return true;
    }
  
    @Override
    public boolean onDoubleTapEvent(MotionEvent event) {
  	  gestureText.setText("onDoubleTapEvent");
        return true;
    }
  
    @Override
    public boolean onSingleTapConfirmed(MotionEvent event) {
  	  gestureText.setText("onSingleTapConfirmed");
        return true;
    }	

	
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.common_gestures, menu);
		return true;
	}

}
