I need to detect swipe direction. In my code I can detect the direction, but it comes like, if I swipe right top right or left-top like that coming. same for the left, my requirement is without lifting a finger if I swipe left it should come only left, likewise all the directions. Can anyone help me out. Thanks in advance!
Here is my code
@Override
public boolean onScroll(MotionEvent event1, MotionEvent event2, float distanceX, float distanceY) {
if (Math.abs(deltaX) > Math.abs(deltaY)) {
if (Math.abs(deltaX) > MIN_DISTANCE) {
if (deltaX > leftSidelastX) {
leftSidelastX = deltaX;
Log.d("", "Right to Left swipe performed");
} else {
leftSidelastX = deltaX;
Log.d("", "Left to Right swipe performed");
}
}
} else {
if (Math.abs(deltaY) > MIN_DISTANCE) {
if (deltaY > leftSidelastY) {
leftSidelastY = deltaY;
Log.d("", "Up to Down swipe performed");
} else {
leftSidelastY = deltaY;
Log.d("", "Down to Up swipe performed");
}
}
}
return true;
}