aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArtyom Palvelev <artyompp@google.com>2023-10-18 16:39:02 +0100
committerArtyom Palvelev <artyompp@google.com>2023-10-19 16:23:59 +0100
commitdfca49441b074e6384ce321f46f34d42505f981e (patch)
treed593802747d07b3e10b51c5bacfd404e3f50ceca
parente7cc630a269be37ff70185e013845ebd93bced9f (diff)
downloadgamesdk-dfca49441b074e6384ce321f46f34d42505f981e.tar.gz
refactor GameActivity and GameTextInput interfaces
These changes are made to address the feedback by NDK Council review. This CL does not change behavior of these libraries. Mostly these changes are cosmetic. Since we changed API earlier (GameActivityMotionEvent structure), we bump major versions of GameActivity and GameTextInput. Since we're making a major release, we fix a few other interfaces: * onEditorAction changes its return type from boolean to void * setImeEditorInfo now expects enum parameters, not integers * some code has been moved from GameActivityMotionEvent_fromJava into onTouchEvent_native * internal functions of GameActivityEvents are moved into GameActivityEvents_internal.h. Fix: 301147938 Test: run AGDKSample or any other sample Change-Id: I97d0479bd3bfaf137505258abb681528491abae0
-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 76f3a718..33e95ca3 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
@@ -587,9 +587,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