Add java-to-native converters for input events.
Add java-to-native converters for android.view.KeyEvent, android.view.MotionEvent. Bug: 116830907 Test: atest KeyEventTest, atest MotionEventTest Change-Id: Ib993afb08ef900d95e21907660f776ad2bd3d50e
This commit is contained in:
@@ -26,6 +26,8 @@
|
||||
|
||||
#include <android_runtime/android_app_NativeActivity.h>
|
||||
#include <android_runtime/android_view_InputQueue.h>
|
||||
#include <android_view_MotionEvent.h>
|
||||
#include <android_view_KeyEvent.h>
|
||||
|
||||
#include <poll.h>
|
||||
#include <errno.h>
|
||||
@@ -50,6 +52,10 @@ int32_t AInputEvent_getSource(const AInputEvent* event) {
|
||||
return static_cast<const InputEvent*>(event)->getSource();
|
||||
}
|
||||
|
||||
void AInputEvent_release(const AInputEvent* event) {
|
||||
delete event;
|
||||
}
|
||||
|
||||
int32_t AKeyEvent_getAction(const AInputEvent* key_event) {
|
||||
return static_cast<const KeyEvent*>(key_event)->getAction();
|
||||
}
|
||||
@@ -77,6 +83,14 @@ int64_t AKeyEvent_getDownTime(const AInputEvent* key_event) {
|
||||
return static_cast<const KeyEvent*>(key_event)->getDownTime();
|
||||
}
|
||||
|
||||
const AInputEvent* AKeyEvent_fromJava(JNIEnv* env, jobject keyEvent) {
|
||||
std::unique_ptr<KeyEvent> event = std::make_unique<KeyEvent>();
|
||||
android::status_t ret = android::android_view_KeyEvent_toNative(env, keyEvent, event.get());
|
||||
if (ret == android::OK) {
|
||||
return event.release();
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
int64_t AKeyEvent_getEventTime(const AInputEvent* key_event) {
|
||||
return static_cast<const KeyEvent*>(key_event)->getEventTime();
|
||||
@@ -269,6 +283,15 @@ float AMotionEvent_getHistoricalAxisValue(const AInputEvent* motion_event,
|
||||
axis, pointer_index, history_index);
|
||||
}
|
||||
|
||||
const AInputEvent* AMotionEvent_fromJava(JNIEnv* env, jobject motionEvent) {
|
||||
MotionEvent* eventSrc = android::android_view_MotionEvent_getNativePtr(env, motionEvent);
|
||||
if (eventSrc == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
MotionEvent* event = new MotionEvent();
|
||||
event->copyFrom(eventSrc, true);
|
||||
return event;
|
||||
}
|
||||
|
||||
void AInputQueue_attachLooper(AInputQueue* queue, ALooper* looper,
|
||||
int ident, ALooper_callbackFunc callback, void* data) {
|
||||
|
||||
@@ -76,6 +76,7 @@ LIBANDROID {
|
||||
AInputEvent_getDeviceId;
|
||||
AInputEvent_getSource;
|
||||
AInputEvent_getType;
|
||||
AInputEvent_release; # introduced=31
|
||||
AInputQueue_attachLooper;
|
||||
AInputQueue_detachLooper;
|
||||
AInputQueue_finishEvent;
|
||||
@@ -90,6 +91,7 @@ LIBANDROID {
|
||||
AKeyEvent_getMetaState;
|
||||
AKeyEvent_getRepeatCount;
|
||||
AKeyEvent_getScanCode;
|
||||
AKeyEvent_fromJava; # introduced=31
|
||||
ALooper_acquire;
|
||||
ALooper_addFd;
|
||||
ALooper_forThread;
|
||||
@@ -139,6 +141,7 @@ LIBANDROID {
|
||||
AMotionEvent_getY;
|
||||
AMotionEvent_getYOffset;
|
||||
AMotionEvent_getYPrecision;
|
||||
AMotionEvent_fromJava; # introduced=31
|
||||
ANativeActivity_finish;
|
||||
ANativeActivity_hideSoftInput;
|
||||
ANativeActivity_setWindowFlags;
|
||||
|
||||
Reference in New Issue
Block a user