onFling not being called on OSX Emulator?
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", CryptDetail开发者_运维技巧s.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.
I recently came across exactly the same issue. Unfortunately and fortunately, I did not receive any help from this post but resolved the issue sometime later with some luck. The answer is simple: DON'T USE YOUR TRACKPAD TO DO FLING in your emulator because it ain't gonna work. Simply plug in an external mouse and it should work just fine.
p.s. In my case I was testing with a macbookpro.
EDIT: it turns out it had nothing to do with internal or external.. sorry about the confusion. the real culprit here, at least for me, is because i've enabled "tab to click" in system preferences and tried to tab twice to drag along. The default "press to click" works perfectly without any issue.
精彩评论