As it doesn't seem to be possible to intercept MotionEvents on the Java side before
they are passed to the C side, I've now tried it the other way round: Whenever I
get an AINPUT_EVENT_TYPE_MOTION on the C side, I'm feeding this to the GestureDetector
on the Java side through JNI like this:
(*env)->CallVoidMethod(env, g_android->activity->clazz, (*env)->GetMethodID(env, globalMyNativeActivityClass, "runGestureDetector", "(JJIIFFFFIFFII)V"), AMotionEvent_getDownTime(event), AMotionEvent_getEventTime(event), AMotionEvent_getAction(event), AMotionEvent_getPointerCount(event), AMotionEvent_getRawX(event, 0), AMotionEvent_getRawY(event, 0), AMotionEvent_getPressure(event, 0), AMotionEvent_getSize(event, 0), AMotionEvent_getMetaState(event), AMotionEvent_getXPrecision(event), AMotionEvent_getYPrecision(event), AInputEvent_getDeviceId(event), AMotionEvent_getEdgeFlags(event));
The Java method runGestureDetector() simply does this then:
public void runGestureDetector(long downTime, long eventTime, int action, int pointerCount, float x, float y, float pressure, float size, int metaState, float xPrecision, float yPrecision, int deviceId, int edgeFlags) {
mGestureDetector.onTouchEvent(MotionEvent.obtain(downTime, eventTime, action, pointerCount, x, y, pressure, size, metaState, xPrecision, yPrecision, deviceId, edgeFlags));
}
By doing it this way I'm able to detect some gestures. onDown(), onSingleTap() and onScroll()
come in just fine. What is not working, however, is onFling(). But onFling() is the most
important one for me.
My suspection is that onFling() does not work because it might rely on the historical values
that can be stored in a MotionEvent (every MotionEvent has a historical size with historical
parameters, see android/input.h). However, the obtain() constructor of MotionEvent class does
not allow me to construct a MotionEvent object with historical values.
So is there any way to feed the real MotionEvent that I get on the C side to onTouchEvent() on
the Java side? I can get the historical values through the NDK API but AFAICS it is not possible
to construct a MotionEvent with historical information on the Java side :-(
Any ideas?
Tks,
Andreas
--
Best regards,
Andreas Falkenhahn mailto:
and...@falkenhahn.com