Gesture Movement in Android-Part 1

int SWIPE_MIN_VELOCITY = 100;
int SWIPE_MIN_DISTANCE = 100;
private GestureDetector gesturedetector = null;
View.OnTouchListener gestureListener;
//-----------------------------------------------------------------------

gesturedetector = new GestureDetector(this, this);
gesturedetector = new GestureDetector(new MyGestureDetector());
gestureListener = new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
if (gesturedetector.onTouchEvent(event)) {
return true;
}
return false;
}
};
//-------------------------------------------------------

class MyGestureDetector extends SimpleOnGestureListener {
@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2,
float distanceX, float distanceY) {
// bottomAnimation();
return false;
}
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
float velocityY) {
try {
String flag = null;
float ev1X = e1.getX();
float ev2X = e2.getX();
final float xdistance = Math.abs(ev1X - ev2X);
// Get veclocity of cusor
final float xvelocity = Math.abs(velocityX);
if ((xvelocity > SWIPE_MIN_VELOCITY)
&& (xdistance > SWIPE_MIN_DISTANCE)) {
if (ev1X > ev2X)// Switch Left
{
if (i > 0) {
i = i - 1;
previousView(i);
}
System.out.println("left swipe");
} else {
System.out.println("Righjt swipe");
if (i < 25) {
i = i + 1;
nextView(i);
}
}
return false;
}
} catch (Exception e) {
// nothing
}
return false;
}
}