Question

While hacking with the NDK and NativeActivity, I've been unable to get useful information for touch input - I just get obfuscated information for the flags.

This is a snippet of the relevant code (edited from plasma.c from the sample):

static int32_t engine_handle_input(struct android_app* app, AInputEvent* event) {
    struct engine* engine = (struct engine*)app->userData;
    LOGI("Event: action=%d\nkeyCode=%d\nmetaState=0x%x\nAction=0x%x\nx=%d\ny=%d"
        "\nflags=0x%x\nxprec=%d\nyprec=%d\nxoff=%d\nyoff=%d\nguessX=%d\n\n",
                AKeyEvent_getAction(event),
                AKeyEvent_getKeyCode(event),
                AKeyEvent_getMetaState(event),
                AMotionEvent_getAction(event),
                AMotionEvent_getX(event,0),
                AMotionEvent_getY(event,0),
                AMotionEvent_getFlags(event),
                AMotionEvent_getXPrecision(event),
                AMotionEvent_getYPrecision(event),
                AMotionEvent_getXOffset(event),
                AMotionEvent_getYOffset(event))

    return 0;
}

This is the sort of log output I get while touching the screen:

I/libplasma(24786): Event: action=1
I/libplasma(24786): keyCode=0
I/libplasma(24786): metaState=0x0
I/libplasma(24786): Action=0x1
I/libplasma(24786): x=1074838969
I/libplasma(24786): y=1073741824
I/libplasma(24786): flags=0x408cf365
I/libplasma(24786): xprec=-2147483648
I/libplasma(24786): yprec=1081822550
I/libplasma(24786): xoff=0
I/libplasma(24786): yoff=1074839057
I/libplasma(24786):

I'm not sure how I'm supposed to extract useful information out of this junk, and I can't find a single tutorial on NDK NativeActivity input. Any NDK gurus here?

Était-ce utile?

La solution

Silly me. They all return floats.

AMotionEvent_getX(event,0)
AMotionEvent_getY(event,0)
AMotionEvent_getFlags(event)
AMotionEvent_getXPrecision(event)
AMotionEvent_getYPrecision(event)
AMotionEvent_getXOffset(event)
AMotionEvent_getYOffset(event)

If I use them as floats with %f, this is my output:

I/libplasma(29039): Event: action=1
I/libplasma(29039): keyCode=0
I/libplasma(29039): metaState=0x0
I/libplasma(29039): Action=0x1
I/libplasma(29039): x=1513.833618
I/libplasma(29039): y=697.899841
I/libplasma(29039): flags=0x0
I/libplasma(29039): xprec=1.533854
I/libplasma(29039): yprec=1.547500
I/libplasma(29039): xoff=0.000000
I/libplasma(29039): yoff=0.000000

If someone in the future runs into this issue, please make sure to open up the source file android/input.h for information on each function. By default, this will be located at <NDK-Install-Path>/platforms/<ndk-platform>/arch-arm/usr/include/android/input.h.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top