I debugged the code into the android source code, GestureDetector class. And this explains why SimpleOnGestureListener
was not called:
- The ACTION_DOWN is received and generates an internal TAP message to the GestureDetector message Handler.
- The Handler calls the listener
onSingleTapConfirmed()
only if the event is not still down (!mStillDown
) - The event is still down, because the ACTION_UP event was never received.
So you see, the two questions are related, when I find out why ACTION_UP is not issued I will solve the problem!
Edit
This completes the answer, now it is working.
- The call to
super.onTouchEvent()
in GameView returnsfalse
, because thesuper
class of SurfaceView is View, and it returnsfalse
. That's why ACTION_UP is never called - The call to
super.onTouchEvent()
in GameActivity returnstrue
, that's why ACTION_UP is issued on GameActivity.
Note: If I set GameView.setclickable(true)
then super.onTouchEvent()
returns true
. It is also an acceptable solution
Now my GameView code is:
@Override
public boolean onTouchEvent(MotionEvent event) {
Log.d(TAG, "+ onTouchEvent(event:" + event + ")");
gestureDetector.onTouchEvent(event);
Log.d(TAG, "- onTouchEvent()");
return true;
}
The current LogCat logs are:
03-11 16:32:06.629: D/GameView(5316): + onTouchEvent(event:MotionEvent { action=ACTION_DOWN, id[0]=0, x[0]=977.0, y[0]=414.0, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=35158623, downTime=35158623, deviceId=0, source=0x1002 })
03-11 16:32:06.629: D/GameView(5316): - onTouchEvent()
03-11 16:32:06.641: D/GameView(5316): + onTouchEvent(event:MotionEvent { action=ACTION_MOVE, id[0]=0, x[0]=978.0, y[0]=414.0, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=35158623, downTime=35158623, deviceId=0, source=0x1002 })
03-11 16:32:06.641: D/GameView(5316): - onTouchEvent()
03-11 16:32:06.772: D/GameView(5316): + onTouchEvent(event:MotionEvent { action=ACTION_UP, id[0]=0, x[0]=978.0, y[0]=414.0, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=35158772, downTime=35158623, deviceId=0, source=0x1002 })
03-11 16:32:06.772: D/GameView(5316): - onTouchEvent()
03-11 16:32:06.931: D/GestureListener(5316): + onSingleTapConfirmed(event:MotionEvent { action=ACTION_DOWN, id[0]=0, x[0]=977.0, y[0]=414.0, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=35158623, downTime=35158623, deviceId=0, source=0x1002 })
03-11 16:32:06.931: D/GestureListener(5316): - onSingleTapConfirmed()