I have to GestureDetectors in my program. One works beautifully, the other doesn't. As far as I can tell they're both implemented the same way.
Here's the code for implementing the one that isn't working:
myExcuseGestureDetector = new GestureDetector(new excuseGestureDetector());
excuseView.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
if(myExcuseGestureDetector.onTouchEvent(event)){
Log.d("Excuse Gesture Return","true");
return true;
}
Log.d("Excuse Gesture Return","false");
return false;
}
});
Then I have this block later which defines excuseGestureDetector
private class excuseGestureDetector extends SimpleOnGestureListener{
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
Log.d("MotionEvent","onFling");
try {
if (Math.abs(e1.getY() - e2.getY()) > SWIPE_MAX_OFF_PATH)
return false;
// right to left swipe
if(e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
if(currExcuseNumber<currExcuseSet.size()){
currExcuseNumber++;
loadNextExcuse(currExcuseNumber,1);
excuseView.setInAnimation(slideLeftExcuseIn);
excuseView.setOutAnimation(slideLeftExcuseOut);
excuseView.showNext();
return true;
}
} else if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
if(currExcuseNumber > 1){
loadNextExcuse(currExcuseNumber,0);
excuseView.setInAnimation(slideRightExcuseIn);
excuseView.setOutAnimation(slideRightExcuseOut);
excuseView.showPrevious();
return true;
}
}
} catch (Exception e) {
// nothing
}
return false;
}
}
For whatever reason, it doesn't register the fling at all. Regardless of whether the animation happens or not, the program should print out the Log.d("MotionEvent","onFling") that I'm trying to trace and it doesn't. All I know is that it does register that a touchevent of some sort has occured because it does trace out "Excuse Gesture Return" "false" from the first block I showed. Any thoughts on why it won't register the fling?