i've got a class extended from simple on gesture and i'm working with the onfling method:
class MyGestureListener extends GestureDetector.SimpleOnGestureListener{
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
float velocityY) {
// TODO Auto-generated method stub
float e1_X = e1.getX();
float e1_Y = e1.getY();
float e2_X = e1.getX();
float e2_Y = e2.getY();
if(velocityX > 0 && velocityX > velocityY){
text.setText("Swipe left");
}else if(velocityX < 0 && velocityX < velocityY){
text.setText("Swipe right");
}else if(velocityY < 0 && velocityX > velocityY){
text.setText("Swipe down");
}else if(velocityY > 0 && velocityX < velocityY){
text.setText("Swipe up");
}
return super.onFling(e1, e2, velocityX, velocityY);
}
}
I know it depends on certain angles but i can't do it, i tried with the velocityX, and velocityY, it's working only if you do it precisely . But what i want is an angle of "mistake" : if you swipe diagonally for example up and right i need to choose which is the good way.
You should check speed and distance. Here is an example of horizontal swipe detector. You can add vertical detection in the same manner.