How do I track all gestures on an entire application screen. I was struggling with adding a gesture detector to the entire screen of my application. I am using gesturedetector compat to get gestures from the layout however when I tap or double tap the button and edit text gesturedetector does not detect the gesture on the view. Is it possible to have all tap,swipes,gestures on the ENTIRE screen as opposed to only the layout. If there is a better solution to tracking all touches,swipes,taps please let me know I have struggling with this for weeks.
MainActivity.java
public class MainActivity extends AppCompatActivity {
private GestureDetectorCompat mGestureDetector;
private TextView touchCheckText;
private TextView singleTapText;
private TextView doubleTapText;
private static final String TAG = "Gesture ";
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
if (event.getAction()!=KeyEvent.ACTION_DOWN)
Log.i("key pressed", String.valueOf(event.getKeyCode()));
return super.dispatchKeyEvent(event);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mGestureDetector = new GestureDetectorCompat(this,new GestureListener());
touchCheckText = (TextView) findViewById(R.id.touchCheckTextView);
scrollText = (TextView) findViewById(R.id.scrollTextView);
singleTapText = (TextView) findViewById(R.id.singleTapTextView);
doubleTapText = (TextView) findViewById(R.id.doubleTapTextView);
}
private class GestureListener extends GestureDetector.SimpleOnGestureListener{
@Override
public boolean onDoubleTap(MotionEvent e) {
int x = (int) e.getX();
int y = (int) e.getY();
Long tsLong = System.currentTimeMillis()/1000;
String ts = tsLong.toString();
Log.e(TAG, "in on onDoubleTap Event");
doubleTapText.setBackgroundColor(Color.GREEN);
return super.onDoubleTap(e);
}
@Override
public boolean onDown(MotionEvent e) {
touchCheckText.setText("TOUCHING!");
return super.onDown(e);
}
@Override
public boolean onSingleTapConfirmed(MotionEvent e) {
int x = (int) e.getX();
int y = (int) e.getY();
Long tsLong = System.currentTimeMillis()/1000;
String ts = tsLong.toString();
singleTapText.setBackgroundColor(Color.GREEN);
Log.e(TAG, "Single Tap "+ts+" x:"+x+" y:"+y);
singleTapText.postDelayed(new Runnable() {
@Override
public void run() {
// change color in here
singleTapText.setBackgroundColor(Color.TRANSPARENT);
}
}, 100);
return super.onSingleTapConfirmed(e);
}
}
@Override
public boolean onTouchEvent(MotionEvent event) {
mGestureDetector.onTouchEvent(event);
switch ( event.getAction() ) {
case MotionEvent.ACTION_UP:
Log.e("onTouch","Released");
doubleTapText.setBackgroundColor(Color.TRANSPARENT);
touchCheckText.setText("No Longer Touching");
break;
}
return super.onTouchEvent(event);
}
}