I am taking time
125 based on PRESSED_STATE_DURATION
Try this
//Declare as instance variables
int oldX,oldY,newX,newY;
//State the minimum distance of swipe that you forgive the user for ;)
int distance = 10;
int time = 125;
boolean cancel = false;
case MotionEvent.ACTION_DOWN:
cancel = false;
//Get x and y of touch
oldX = ev.getX();
oldY = ev.getY();
startActionTimer();
case MotionEvent.ACTION_MOVE:
//Get x and y of touch
newX = ev.getX();
newY = ev.getY();
case MotionEvent.ACTION_UP:
cancel = true;
private void startActionTimer(){
//time is pressed state duration
new CountDownTimer(time, time) {
public void onTick(long millisUntilFinished) {}
public void onFinish() {
//Time to do our action!!!
// please consider
if((Math.abs(newX - oldX )< distance) && (Math.abs(newY - oldY ) <distance)){
if(cancel == false){
// Now its a touch so do your action
}
}
}
}.start();
}
NOTE: Please use all the variables as class variables(instance variables) to avoid problems. Because sometimes i get weird situations where values are not updated properly
OR
Why don't you try the gesture detection
and override the onSingleTapUp
method