aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Murphy <tomnom@google.com>2022-12-05 13:36:36 +0000
committerTom Murphy <tomnom@google.com>2022-12-06 11:06:44 +0000
commit5e01ff2420dd6ead0d648103be19cf8f46019491 (patch)
tree47056b2a1672b58d2483dbd6825bce99106d5691
parent33ba3a8452ebb1a28903b2f1a81eecbb3f8e864a (diff)
downloadgamesdk-5e01ff2420dd6ead0d648103be19cf8f46019491.tar.gz
Revert "Revert "update contentRect in GameActivity""
This reverts commit 59114d8ea5ccfd735bf5f89de899d969ef03fc0a. Reason for revert: We can now remerge this now that the release is out. Change-Id: I0f22891f10bf2a30151afe8ce14233d79559c042
-rw-r--r--game-activity/prefab-src/modules/game-activity/include/game-activity/GameActivity.cpp19
-rw-r--r--game-activity/prefab-src/modules/game-activity/include/game-activity/GameActivity.h6
-rw-r--r--game-activity/prefab-src/modules/game-activity/include/game-activity/native_app_glue/android_native_app_glue.c15
-rw-r--r--game-activity/src/main/java/com/google/androidgamesdk/GameActivity.java37
4 files changed, 76 insertions, 1 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 dee363cb..de1affb2 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
@@ -1209,6 +1209,23 @@ static void setInputConnection_native(JNIEnv *env, jobject activity,
GameTextInput_setInputConnection(code->gameTextInput, inputConnection);
}
+static void onContentRectChangedNative_native(JNIEnv *env, jobject activity,
+ jlong handle, jint x, jint y,
+ jint w, jint h) {
+ if (handle != 0) {
+ NativeCode *code = (NativeCode *)handle;
+
+ if (code->callbacks.onContentRectChanged != nullptr) {
+ ARect rect;
+ rect.left = x;
+ rect.top = y;
+ rect.right = x+w;
+ rect.bottom = y+h;
+ code->callbacks.onContentRectChanged(code, &rect);
+ }
+ }
+}
+
static const JNINativeMethod g_methods[] = {
{"initializeNativeCode",
"(Ljava/lang/String;Ljava/lang/String;"
@@ -1246,6 +1263,8 @@ static const JNINativeMethod g_methods[] = {
{"setInputConnectionNative",
"(JLcom/google/androidgamesdk/gametextinput/InputConnection;)V",
(void *)setInputConnection_native},
+ {"onContentRectChangedNative", "(JIIII)V",
+ (void *)onContentRectChangedNative_native},
};
static const char *const kGameActivityPathName =
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 31fd7ca0..05830893 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
@@ -530,6 +530,12 @@ typedef struct GameActivityCallbacks {
* Call GameActivity_getWindowInsets to retrieve the insets themselves.
*/
void (*onWindowInsetsChanged)(GameActivity* activity);
+
+ /**
+ * Callback called when the rectangle in the window where the content
+ * should be placed has changed.
+ */
+ void (*onContentRectChanged)(GameActivity *activity, const ARect *rect);
} GameActivityCallbacks;
/** \brief Handle the freeing of the GameActivityMotionEvent struct. */
diff --git a/game-activity/prefab-src/modules/game-activity/include/game-activity/native_app_glue/android_native_app_glue.c b/game-activity/prefab-src/modules/game-activity/include/game-activity/native_app_glue/android_native_app_glue.c
index f4fff5f5..ebc265e4 100644
--- a/game-activity/prefab-src/modules/game-activity/include/game-activity/native_app_glue/android_native_app_glue.c
+++ b/game-activity/prefab-src/modules/game-activity/include/game-activity/native_app_glue/android_native_app_glue.c
@@ -593,6 +593,20 @@ static void onWindowInsetsChanged(GameActivity* activity) {
android_app_write_cmd(ToApp(activity), APP_CMD_WINDOW_INSETS_CHANGED);
}
+static void onContentRectChanged(GameActivity* activity, const ARect *rect) {
+ LOGV("ContentRectChanged: %p -- (%d %d) (%d %d)", activity, rect->left, rect->top,
+ rect->right, rect->bottom);
+
+ struct android_app* android_app = ToApp(activity);
+
+ pthread_mutex_lock(&android_app->mutex);
+ android_app->contentRect = *rect;
+
+ android_app_write_cmd(android_app, APP_CMD_CONTENT_RECT_CHANGED);
+ pthread_mutex_unlock(&android_app->mutex);
+}
+
+
JNIEXPORT
void GameActivity_onCreate(GameActivity* activity, void* savedState,
size_t savedStateSize) {
@@ -616,6 +630,7 @@ void GameActivity_onCreate(GameActivity* activity, void* savedState,
onNativeWindowRedrawNeeded;
activity->callbacks->onNativeWindowResized = onNativeWindowResized;
activity->callbacks->onWindowInsetsChanged = onWindowInsetsChanged;
+ activity->callbacks->onContentRectChanged = onContentRectChanged;
LOGV("Callbacks set: %p", activity->callbacks);
activity->instance =
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 fa436118..df19ed32 100644
--- a/game-activity/src/main/java/com/google/androidgamesdk/GameActivity.java
+++ b/game-activity/src/main/java/com/google/androidgamesdk/GameActivity.java
@@ -24,6 +24,7 @@ import android.content.pm.ActivityInfo;
import android.content.pm.PackageManager;
import android.content.res.AssetManager;
import android.content.res.Configuration;
+import android.content.Context;
import android.graphics.PixelFormat;
import android.os.Build;
import android.os.Bundle;
@@ -58,7 +59,8 @@ import java.io.File;
public class GameActivity
extends AppCompatActivity
- implements SurfaceHolder.Callback2, Listener, OnApplyWindowInsetsListener {
+ implements SurfaceHolder.Callback2, Listener, OnApplyWindowInsetsListener,
+ OnGlobalLayoutListener {
private static final String LOG_TAG = "GameActivity";
private static final String DEFAULT_NATIVE_LIB_NAME = "main";
@@ -110,6 +112,27 @@ public class GameActivity
onTextInputEventNative(mNativeHandle, newState);
}
+ @Override
+ public void onGlobalLayout() {
+ mSurfaceView.getLocationInWindow(mLocation);
+ int w = mSurfaceView.getWidth();
+ int h = mSurfaceView.getHeight();
+
+ if (mLocation[0] != mLastContentX || mLocation[1] != mLastContentY
+ || w != mLastContentWidth || h != mLastContentHeight)
+ {
+ mLastContentX = mLocation[0];
+ mLastContentY = mLocation[1];
+ mLastContentWidth = w;
+ mLastContentHeight = h;
+
+ if (!mDestroyed) {
+ onContentRectChangedNative(mNativeHandle, mLastContentX, mLastContentY,
+ mLastContentWidth, mLastContentHeight);
+ }
+ }
+ }
+
// Called when we want to set the input state, e.g. before first showing the IME
public void setTextInputState(State s) {
if (mSurfaceView == null) return;
@@ -125,6 +148,11 @@ public class GameActivity
private SurfaceHolder mCurSurfaceHolder;
protected final int[] mLocation = new int[2];
+ protected int mLastContentX;
+ protected int mLastContentY;
+ protected int mLastContentWidth;
+ protected int mLastContentHeight;
+
protected boolean mDestroyed;
@@ -172,6 +200,8 @@ public class GameActivity
protected native void onWindowInsetsChangedNative(long handle);
+ protected native void onContentRectChangedNative(long handle, int x, int y, int w, int h);
+
/**
* Get the pointer to the C `GameActivity` struct associated to this activity.
* @return the pointer to the C `GameActivity` struct associated to this activity.
@@ -226,6 +256,11 @@ public class GameActivity
@Override
protected void onCreate(Bundle savedInstanceState) {
onCreateSurfaceView();
+
+ if (mSurfaceView != null) {
+ mSurfaceView.getViewTreeObserver().addOnGlobalLayoutListener(this);
+ }
+
onSetUpWindow();
String libname = new String(DEFAULT_NATIVE_LIB_NAME);