aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArtyom Palvelev <artyompp@google.com>2023-10-20 12:32:39 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2023-10-20 12:32:39 +0000
commit12ea55fbfdbc9c76d3e2e654e3da2a80a0de9c23 (patch)
treea054b96dfd9dff450c62fd8b7bb02ea7e3ce8542
parent3c0102a4f42afc46ea5398daad3f8bd2c6100e57 (diff)
parentdfca49441b074e6384ce321f46f34d42505f981e (diff)
downloadgamesdk-12ea55fbfdbc9c76d3e2e654e3da2a80a0de9c23.tar.gz
Merge "refactor GameActivity and GameTextInput interfaces" into main
-rw-r--r--game-activity/prefab-src/modules/game-activity/include/game-activity/GameActivity.cpp40
-rw-r--r--game-activity/prefab-src/modules/game-activity/include/game-activity/GameActivity.h10
-rw-r--r--game-activity/prefab-src/modules/game-activity/include/game-activity/GameActivityEvents.cpp24
-rw-r--r--game-activity/prefab-src/modules/game-activity/include/game-activity/GameActivityEvents.h37
-rw-r--r--game-activity/prefab-src/modules/game-activity/include/game-activity/GameActivityEvents_internal.h75
-rw-r--r--game-activity/src/main/java/com/google/androidgamesdk/GameActivity.java6
-rw-r--r--game-text-input/prefab-src/modules/game-text-input/include/game-text-input/gametextinput.h12
-rw-r--r--game-text-input/src/main/java/com/google/androidgamesdk/gametextinput/InputConnection.java5
-rw-r--r--game-text-input/src/main/java/com/google/androidgamesdk/gametextinput/Listener.java2
-rw-r--r--samples/game_text_input/game_text_input_testbed/app/src/main/java/com/gameinput/testbed/InputEnabledTextView.java3
10 files changed, 123 insertions, 91 deletions
diff --git a/game-activity/prefab-src/modules/game-activity/include/game-activity/GameActivity.cpp b/game-activity/prefab-src/modules/game-activity/include/game-activity/GameActivity.cpp
index bf013db6..3be59a12 100644
--- a/game-activity/prefab-src/modules/game-activity/include/game-activity/GameActivity.cpp
+++ b/game-activity/prefab-src/modules/game-activity/include/game-activity/GameActivity.cpp
@@ -15,6 +15,7 @@
*/
#include "GameActivity.h"
+#include "GameActivityEvents_internal.h"
#include <android/api-level.h>
#include <android/asset_manager.h>
@@ -786,9 +787,11 @@ static void onSurfaceDestroyed_native(JNIEnv *env, jobject javaGameActivity,
}
}
-extern "C" void GameActivity_setImeEditorInfo(GameActivity *activity,
- int inputType, int actionId,
- int imeOptions) {
+extern "C" void GameActivity_setImeEditorInfo(
+ GameActivity *activity,
+ GameTextInputType inputType,
+ GameTextInputActionType actionId,
+ GameTextInputImeOptions imeOptions) {
NativeCode *code = static_cast<NativeCode *>(activity);
write_work(code->mainWorkWrite, CMD_SET_IME_EDITOR_INFO, inputType,
actionId, imeOptions);
@@ -879,10 +882,27 @@ static bool onTouchEvent_native(JNIEnv *env, jobject javaGameActivity,
if (code->callbacks.onTouchEvent == nullptr) return false;
static GameActivityMotionEvent c_event;
+
+ c_event.deviceId = deviceId;
+ c_event.source = source;
+ c_event.action = action;
+
+ c_event.eventTime = eventTime;
+ c_event.downTime = downTime;
+
+ c_event.flags = flags;
+ c_event.metaState = metaState;
+
+ c_event.actionButton = actionButton;
+ c_event.buttonState = buttonState;
+ c_event.classification = classification;
+ c_event.edgeFlags = edgeFlags;
+
+ c_event.precisionX = precisionX;
+ c_event.precisionY = precisionY;
+
GameActivityMotionEvent_fromJava(
- env, motionEvent, &c_event, pointerCount, historySize, deviceId, source,
- action, eventTime, downTime, flags, metaState, actionButton,
- buttonState, classification, edgeFlags, precisionX, precisionY);
+ env, motionEvent, &c_event, pointerCount, historySize);
return code->callbacks.onTouchEvent(code, &c_event);
}
@@ -990,7 +1010,7 @@ static void onSoftwareKeyboardVisibilityChangedNative_native(JNIEnv *env,
}
}
-static bool onEditorActionNative_native(JNIEnv *env,
+static void onEditorActionNative_native(JNIEnv *env,
jobject activity,
jlong handle,
int action) {
@@ -998,11 +1018,9 @@ static bool onEditorActionNative_native(JNIEnv *env,
NativeCode *code = (NativeCode *)handle;
if (code->callbacks.onEditorAction != nullptr) {
- return code->callbacks.onEditorAction(code, action);
+ code->callbacks.onEditorAction(code, action);
}
}
-
- return true;
}
static const JNINativeMethod g_methods[] = {
@@ -1047,7 +1065,7 @@ static const JNINativeMethod g_methods[] = {
(void *)onContentRectChangedNative_native},
{"onSoftwareKeyboardVisibilityChangedNative", "(JZ)V",
(void *)onSoftwareKeyboardVisibilityChangedNative_native},
- {"onEditorActionNative", "(JI)Z",
+ {"onEditorActionNative", "(JI)V",
(void *)onEditorActionNative_native},
};
diff --git a/game-activity/prefab-src/modules/game-activity/include/game-activity/GameActivity.h b/game-activity/prefab-src/modules/game-activity/include/game-activity/GameActivity.h
index 6ff744bf..29e3b1ff 100644
--- a/game-activity/prefab-src/modules/game-activity/include/game-activity/GameActivity.h
+++ b/game-activity/prefab-src/modules/game-activity/include/game-activity/GameActivity.h
@@ -619,13 +619,11 @@ bool GameActivity_isSoftwareKeyboardVisible(GameActivity* activity);
* for the meaning of inputType, actionId and imeOptions.
*
* <b>Note:</b> currently only TYPE_NULL AND TYPE_CLASS_NUMBER are supported.
- *
- * Note that this function will attach the current thread to the JVM if it is
- * not already attached, so the caller must detach the thread from the JVM
- * before the thread is destroyed using DetachCurrentThread.
*/
-void GameActivity_setImeEditorInfo(GameActivity* activity, int inputType,
- int actionId, int imeOptions);
+void GameActivity_setImeEditorInfo(GameActivity* activity,
+ enum GameTextInputType inputType,
+ enum GameTextInputActionType actionId,
+ enum GameTextInputImeOptions imeOptions);
/**
* These are getters for Configuration class members. They may be called from
diff --git a/game-activity/prefab-src/modules/game-activity/include/game-activity/GameActivityEvents.cpp b/game-activity/prefab-src/modules/game-activity/include/game-activity/GameActivityEvents.cpp
index df810638..31e143d6 100644
--- a/game-activity/prefab-src/modules/game-activity/include/game-activity/GameActivityEvents.cpp
+++ b/game-activity/prefab-src/modules/game-activity/include/game-activity/GameActivityEvents.cpp
@@ -15,6 +15,7 @@
*/
#include "GameActivityEvents.h"
+#include "GameActivityEvents_internal.h"
#include <sys/system_properties.h>
@@ -190,10 +191,7 @@ static void initMotionEvents(JNIEnv *env) {
extern "C" void GameActivityMotionEvent_fromJava(
JNIEnv *env, jobject motionEvent, GameActivityMotionEvent *out_event,
- int pointerCount, int historySize, int deviceId, int source, int action,
- int64_t eventTime, int64_t downTime, int flags, int metaState,
- int actionButton, int buttonState, int classification, int edgeFlags,
- float precisionX, float precisionY) {
+ int pointerCount, int historySize) {
pointerCount =
std::min(pointerCount, GAMEACTIVITY_MAX_NUM_POINTERS_IN_MOTION_EVENT);
out_event->pointerCount = pointerCount;
@@ -259,24 +257,6 @@ extern "C" void GameActivityMotionEvent_fromJava(
}
}
}
-
- out_event->deviceId = deviceId;
- out_event->source = source;
- out_event->action = action;
-
- out_event->eventTime = eventTime;
- out_event->downTime = downTime;
-
- out_event->flags = flags;
- out_event->metaState = metaState;
-
- out_event->actionButton = actionButton;
- out_event->buttonState = buttonState;
- out_event->classification = classification;
- out_event->edgeFlags = edgeFlags;
-
- out_event->precisionX = precisionX;
- out_event->precisionY = precisionY;
}
static struct {
diff --git a/game-activity/prefab-src/modules/game-activity/include/game-activity/GameActivityEvents.h b/game-activity/prefab-src/modules/game-activity/include/game-activity/GameActivityEvents.h
index 607ae760..0d6707d7 100644
--- a/game-activity/prefab-src/modules/game-activity/include/game-activity/GameActivityEvents.h
+++ b/game-activity/prefab-src/modules/game-activity/include/game-activity/GameActivityEvents.h
@@ -274,35 +274,10 @@ inline float GameActivityMotionEvent_getHistoricalOrientation(
event, AMOTION_EVENT_AXIS_ORIENTATION, pointerIndex, historyPos);
}
-/** \brief Performs necessary initialization steps for GameActivityEvents.a
- *
- * User must call this function before calling any other functions of this unit.
- * If you use GameActivity it will call this function for you.
- */
-void GameActivityEventsInit(JNIEnv* env);
-
/** \brief Handle the freeing of the GameActivityMotionEvent struct. */
void GameActivityMotionEvent_destroy(GameActivityMotionEvent* c_event);
/**
- * \brief Convert a Java `MotionEvent` to a `GameActivityMotionEvent`.
- *
- * This is done automatically by the GameActivity: see `onTouchEvent` to set
- * a callback to consume the received events.
- * This function can be used if you re-implement events handling in your own
- * activity.
- * Ownership of out_event is maintained by the caller.
- * Note that we pass as much information from Java Activity as possible
- * to avoid extra JNI calls.
- */
-void GameActivityMotionEvent_fromJava(
- JNIEnv* env, jobject motionEvent, GameActivityMotionEvent* out_event,
- int pointerCount, int historySize, int deviceId, int source, int action,
- int64_t eventTime, int64_t downTime, int flags, int metaState,
- int actionButton, int buttonState, int classification, int edgeFlags,
- float precisionX, float precisionY);
-
-/**
* \brief Describe a key event that happened on the GameActivity SurfaceView.
*
* This is 1:1 mapping to the information contained in a Java `KeyEvent`
@@ -328,18 +303,6 @@ typedef struct GameActivityKeyEvent {
int32_t unicodeChar;
} GameActivityKeyEvent;
-/**
- * \brief Convert a Java `KeyEvent` to a `GameActivityKeyEvent`.
- *
- * This is done automatically by the GameActivity: see `onKeyUp` and `onKeyDown`
- * to set a callback to consume the received events.
- * This function can be used if you re-implement events handling in your own
- * activity.
- * Ownership of out_event is maintained by the caller.
- */
-void GameActivityKeyEvent_fromJava(JNIEnv* env, jobject motionEvent,
- GameActivityKeyEvent* out_event);
-
#ifdef __cplusplus
}
#endif
diff --git a/game-activity/prefab-src/modules/game-activity/include/game-activity/GameActivityEvents_internal.h b/game-activity/prefab-src/modules/game-activity/include/game-activity/GameActivityEvents_internal.h
new file mode 100644
index 00000000..248e9a2d
--- /dev/null
+++ b/game-activity/prefab-src/modules/game-activity/include/game-activity/GameActivityEvents_internal.h
@@ -0,0 +1,75 @@
+/*
+ * Copyright (C) 2022 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * @addtogroup GameActivity Game Activity Events
+ * The interface to use Game Activity Events.
+ * @{
+ */
+
+/**
+ * @file GameActivityEvents.h
+ */
+#ifndef ANDROID_GAME_SDK_GAME_ACTIVITY_EVENTS_INTERNAL_H
+#define ANDROID_GAME_SDK_GAME_ACTIVITY_EVENTS_INTERNAL_H
+
+#include <jni.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/** \brief Performs necessary initialization steps for GameActivityEvents.
+ *
+ * User must call this function before calling any other functions of this unit.
+ * If you use GameActivity it will call this function for you.
+ */
+void GameActivityEventsInit(JNIEnv* env);
+
+/**
+ * \brief Convert a Java `MotionEvent` to a `GameActivityMotionEvent`.
+ *
+ * This is done automatically by the GameActivity: see `onTouchEvent` to set
+ * a callback to consume the received events.
+ * This function can be used if you re-implement events handling in your own
+ * activity.
+ * Ownership of out_event is maintained by the caller.
+ * Note that we pass as much information from Java Activity as possible
+ * to avoid extra JNI calls.
+ */
+void GameActivityMotionEvent_fromJava(
+ JNIEnv* env, jobject motionEvent, GameActivityMotionEvent* out_event,
+ int pointerCount, int historySize);
+
+/**
+ * \brief Convert a Java `KeyEvent` to a `GameActivityKeyEvent`.
+ *
+ * This is done automatically by the GameActivity: see `onKeyUp` and `onKeyDown`
+ * to set a callback to consume the received events.
+ * This function can be used if you re-implement events handling in your own
+ * activity.
+ * Ownership of out_event is maintained by the caller.
+ */
+void GameActivityKeyEvent_fromJava(JNIEnv* env, jobject motionEvent,
+ GameActivityKeyEvent* out_event);
+
+#ifdef __cplusplus
+}
+#endif
+
+/** @} */
+
+#endif // ANDROID_GAME_SDK_GAME_ACTIVITY_EVENTS_INTERNAL_H
diff --git a/game-activity/src/main/java/com/google/androidgamesdk/GameActivity.java b/game-activity/src/main/java/com/google/androidgamesdk/GameActivity.java
index 8e48c154..a5e6cc77 100644
--- a/game-activity/src/main/java/com/google/androidgamesdk/GameActivity.java
+++ b/game-activity/src/main/java/com/google/androidgamesdk/GameActivity.java
@@ -232,7 +232,7 @@ public class GameActivity
protected native void onSoftwareKeyboardVisibilityChangedNative(long handle, boolean visible);
- protected native boolean onEditorActionNative(long handle, int action);
+ protected native void onEditorActionNative(long handle, int action);
/**
* Get the pointer to the C `GameActivity` struct associated to this activity.
@@ -527,8 +527,8 @@ public class GameActivity
// From the text input Listener.
// Called when editor action is performed.
@Override
- public boolean onEditorAction(int action) {
- return onEditorActionNative(mNativeHandle, action);
+ public void onEditorAction(int action) {
+ onEditorActionNative(mNativeHandle, action);
}
/**
diff --git a/game-text-input/prefab-src/modules/game-text-input/include/game-text-input/gametextinput.h b/game-text-input/prefab-src/modules/game-text-input/include/game-text-input/gametextinput.h
index 1c79ae7f..8a30b936 100644
--- a/game-text-input/prefab-src/modules/game-text-input/include/game-text-input/gametextinput.h
+++ b/game-text-input/prefab-src/modules/game-text-input/include/game-text-input/gametextinput.h
@@ -302,10 +302,6 @@ void GameTextInputState_fromJava(const GameTextInput *input, jobject state,
void *context);
-/*
- * Below there are definitions for arguments of GameActivity_setImeEditorInfo().
- */
-
/**
* Definitions for inputType argument of GameActivity_setImeEditorInfo()
*
@@ -355,7 +351,7 @@ void GameTextInputState_fromJava(const GameTextInput *input, jobject state,
* |-------|-------|-------|-------|</pre>
*/
-enum {
+enum GameTextInputType : unsigned int {
/**
* Mask of bits that determine the overall class
* of text being given. Currently supported classes are:
@@ -701,7 +697,7 @@ enum {
};
/**
- * Masks for imeOptions argument of GameActivity_setImeEditorInfo().
+ * actionId and imeOptions argument of GameActivity_setImeEditorInfo().
*
* <pre>
* |-------|-------|-------|-------|
@@ -726,7 +722,7 @@ enum {
* |-------|-------|-------|-------|</pre>
*/
-enum {
+enum GameTextInputActionType : unsigned int {
/**
* Set of bits in {@link #imeOptions} that provide alternative actions
* associated with the "enter" key. This both helps the IME provide
@@ -788,7 +784,9 @@ enum {
* can be returned to the app if it sets {@link #IME_FLAG_NAVIGATE_PREVIOUS}.
*/
IME_ACTION_PREVIOUS = 0x00000007,
+};
+enum GameTextInputImeOptions : unsigned int {
/**
* Flag of {@link #imeOptions}: used to request that the IME should not update any personalized
* data such as typing history and personalized language model based on what the user typed on
diff --git a/game-text-input/src/main/java/com/google/androidgamesdk/gametextinput/InputConnection.java b/game-text-input/src/main/java/com/google/androidgamesdk/gametextinput/InputConnection.java
index ecdfab8f..39582569 100644
--- a/game-text-input/src/main/java/com/google/androidgamesdk/gametextinput/InputConnection.java
+++ b/game-text-input/src/main/java/com/google/androidgamesdk/gametextinput/InputConnection.java
@@ -595,9 +595,10 @@ public class InputConnection
@Override
public boolean performEditorAction(int action) {
if (listener != null) {
- return listener.onEditorAction(action);
- } else {
+ listener.onEditorAction(action);
return true;
+ } else {
+ return false;
}
}
}
diff --git a/game-text-input/src/main/java/com/google/androidgamesdk/gametextinput/Listener.java b/game-text-input/src/main/java/com/google/androidgamesdk/gametextinput/Listener.java
index 2c71f2a2..ff2b4fba 100644
--- a/game-text-input/src/main/java/com/google/androidgamesdk/gametextinput/Listener.java
+++ b/game-text-input/src/main/java/com/google/androidgamesdk/gametextinput/Listener.java
@@ -52,6 +52,6 @@ public interface Listener {
*
* @param action Code of the action. A default action is IME_ACTION_DONE.
*/
- boolean onEditorAction(int action);
+ void onEditorAction(int action);
}
diff --git a/samples/game_text_input/game_text_input_testbed/app/src/main/java/com/gameinput/testbed/InputEnabledTextView.java b/samples/game_text_input/game_text_input_testbed/app/src/main/java/com/gameinput/testbed/InputEnabledTextView.java
index 0a452243..2a7e0108 100644
--- a/samples/game_text_input/game_text_input_testbed/app/src/main/java/com/gameinput/testbed/InputEnabledTextView.java
+++ b/samples/game_text_input/game_text_input_testbed/app/src/main/java/com/gameinput/testbed/InputEnabledTextView.java
@@ -74,9 +74,8 @@ public class InputEnabledTextView extends View implements Listener {
}
@Override
- public boolean onEditorAction(int action) {
+ public void onEditorAction(int action) {
System.out.println("onEditorAction: " + action);
- return true;
}
@Override