I was playing with GestureDetector and notice that the onFling method is never called when running in the emulator on OSX.
I could make it work under windows, but not on osx.
I used the excellent code from this post: Fling gesture detection on grid layout
This is the code:
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
gestureDetector = new GestureDetector(new MyGestureDetector());
}
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
gestureDetector.onTouchEvent(event);
return false;
}
protected void addFlingSupportToView(int view) {
// TODO Auto-generated method stub
View v = (View) findViewById(view);
v.setOnTouchListener(this);
}
class MyGestureDetector extends SimpleOnGestureListener {
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
float velocityY) {
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) {
} else if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE
&& Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
// Log.i("vampidroid", CryptDetails.this.toString());
finish();
}
} catch (Exception e) {
// nothing
}
return false;
}
}
The problem is that although the OnTouch is called, the OnFling event is never called!
I was playing with this code on windows and it was working ok. When I changed to osx and give it a try it didn't work.
On device the code works as expected.
Do you have any idea of what could this be? Is it related only to osx?
I didn't find anything here on in the Net, so I think maybe this is only with me or nobody checked that.
Thanks in advance.