I have a class extended from simple to 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 that it depends on certain angles, but I canβt do it, I tried with speedX and speedY, it works only if you do it for sure. But what I want is the angle of the βerrorβ: if you swipe diagonally, for example, up and to the right, I need to choose which one is good.
source share