Either disable double tap or detect second tap location
I have a GLSurfaceView with a GestureDetector and an extended SimpleOnGestureListener. I need to be able to select multiple items on the surface view by tapping them quickly. I overrode onSingleTapUp to detect the touches quickly since onSingleTapConfirmed was too slow. The problem now is that if two items on the surface view are close to one another and the user taps one and then the other quickly, then the onSingleTapUp method is called for the first item, but not for the second. The second one calls the onDoubleTap method whether it's overridden or not.
To resolve this I tried to simply not override the onDoubleTap method and I also tried to do nothing in the overridden onDoubleTap and return false. Neither solves the problem. The onSingleTapUp method will still not get called for the second tap.
I decided to try detecting the second tap in the onDoubleTap method and select the item from there. The problem with that is the motion event returned from onDoubleTap contains "The down motion event of the first tap of the double-tap." - http://developer.android.com/reference/android/view/GestureDetector.OnDoubleTapListener.html
Is there any way to either disable double taps, change the double tap time so it will never fire, change the double tap radius to something very small, or get the first tap location in the onDoubleTap method?
Here's my SimpleOnGestureListener:
public class ViewGestureListener extends
GestureDetector.SimpleOnGestureListener {
private ViewRenderer renderer;
private GLSurfaceView surfaceView;
public ViewGestureListener(GLSurfaceView surfaceView,
ViewRenderer renderer) {
this.renderer = renderer;
this.surfaceView = surfaceView;
}
// Pan
@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX,
float distanceY) {
renderer.pan(distanceX, distanceY);
surfaceView.requestRender();
return true;
}
// Double touch and release
@Override
public boolean onDoubleTap(MotionEvent e) {
// Note: e.getX() doesn't return the second tap's location!
renderer.singleTouch(e.getX(), e.getY());
surfaceView.requestRender();
return true;
}
@Override
public boolean onSingleTapUp(MotionEvent e) {
renderer.singleTouch(e.getX(), e.getY());
surfaceView.requestRender();
return true;
}
}
Thanks, Matt
I might come too late to help the author of this post but I just faced the same problem, so here is the answer for other people who is wondering about it.
ANSWER:
You need to override the following method, it will provide you the down, move, and up events of the second tap:
onDoubleTapEvent(MotionEvent e)
If you want the UP motion of the second tap then:
onDoubleTapEvent(MotionEvent e) {
if(e.getAction() != MotionEvent.ACTION_UP) {
return false; // Don't do anything for other actions
}
// YOUR CODE HERE
return true;
}
Good Luck! /Carlos
It's not well documented but in order to ignore double tap, and detect it as two separate taps, it's enough to set null
as double tap listener.
GestureDetector gd = new GestureDetector(context, gestureListener);
gd.setOnDoubleTapListener(null);
Works for both GestureDetector
and GestureDetectorCompat
.
下一篇: 禁用双击或检测第二个水龙头位置