Fixed bug 3128 - Removing all the static variables from android SDLActivity and accompanying JNI calls. owen I removed all the static variables from SDLActivity.java Updated all the SDL_android.c jni calls as well I added a new function to SDL_android.c/ h void Android_JNI_SeparateEventsHint(const char* c); This is called by SDL_androidtouch.c so that this TU doesn't need to call any JNI functions.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
diff --git a/src/core/android/SDL_android.c b/src/core/android/SDL_android.c
index dbff407..9029254 100644
--- a/src/core/android/SDL_android.c
+++ b/src/core/android/SDL_android.c
@@ -181,6 +181,9 @@ static jmethodID midPollInputDevices;
static jmethodID midPollHapticDevices;
static jmethodID midHapticRun;
+/* static fields */
+static jfieldID fidSeparateMouseAndTouch;
+
/* Accelerometer data storage */
static float fLastAccelerometer[3];
static SDL_bool bHasNewData;
@@ -253,6 +256,13 @@ JNIEXPORT void JNICALL SDL_Android_Init(JNIEnv* mEnv, jclass cls)
!midPollInputDevices || !midPollHapticDevices || !midHapticRun) {
__android_log_print(ANDROID_LOG_WARN, "SDL", "SDL: Couldn't locate Java callbacks, check that they're named and typed correctly");
}
+
+ fidSeparateMouseAndTouch = (*mEnv)->GetStaticFieldID(mEnv, mActivityClass, "mSeparateMouseAndTouch", "Z");
+
+ if (!fidSeparateMouseAndTouch) {
+ __android_log_print(ANDROID_LOG_WARN, "SDL", "SDL: Couldn't locate Java static fields, check that they're named and typed correctly");
+ }
+
__android_log_print(ANDROID_LOG_INFO, "SDL", "SDL_Android_Init() finished!");
}
@@ -693,11 +703,6 @@ int Android_JNI_SetupThread(void)
return 1;
}
-jclass Android_JNI_GetActivityClass(void)
-{
- return mActivityClass;
-}
-
/*
* Audio support
*/
@@ -1590,6 +1595,13 @@ int Android_JNI_GetTouchDeviceIds(int **ids) {
return number;
}
+/* sets the mSeparateMouseAndTouch field */
+void Android_JNI_SetSeparateMouseAndTouch(SDL_bool new_value)
+{
+ JNIEnv *env = Android_JNI_GetEnv();
+ (*env)->SetStaticBooleanField(env, mActivityClass, fidSeparateMouseAndTouch, new_value ? JNI_TRUE : JNI_FALSE);
+}
+
void Android_JNI_PollInputDevices(void)
{
JNIEnv *env = Android_JNI_GetEnv();
diff --git a/src/core/android/SDL_android.h b/src/core/android/SDL_android.h
index 799b29a..8fe18d6 100644
--- a/src/core/android/SDL_android.h
+++ b/src/core/android/SDL_android.h
@@ -76,12 +76,12 @@ void Android_JNI_SuspendScreenSaver(SDL_bool suspend);
/* Touch support */
int Android_JNI_GetTouchDeviceIds(int **ids);
+void Android_JNI_SetSeparateMouseAndTouch(SDL_bool new_value);
/* Threads */
#include <jni.h>
JNIEnv *Android_JNI_GetEnv(void);
int Android_JNI_SetupThread(void);
-jclass Android_JNI_GetActivityClass(void);
/* Generic messages */
int Android_JNI_SendMessage(int command, int param);
diff --git a/src/video/android/SDL_androidtouch.c b/src/video/android/SDL_androidtouch.c
index cb52d4b..4aa6b4f 100644
--- a/src/video/android/SDL_androidtouch.c
+++ b/src/video/android/SDL_androidtouch.c
@@ -56,12 +56,9 @@ static void
SeparateEventsHintWatcher(void *userdata, const char *name,
const char *oldValue, const char *newValue)
{
- jclass mActivityClass = Android_JNI_GetActivityClass();
- JNIEnv *env = Android_JNI_GetEnv();
- jfieldID fid = (*env)->GetStaticFieldID(env, mActivityClass, "mSeparateMouseAndTouch", "Z");
-
separate_mouse_and_touch = (newValue && (SDL_strcmp(newValue, "1") == 0));
- (*env)->SetStaticBooleanField(env, mActivityClass, fid, separate_mouse_and_touch ? JNI_TRUE : JNI_FALSE);
+
+ Android_JNI_SetSeparateMouseAndTouch(separate_mouse_and_touch);
}
void Android_InitTouch(void)