Fixed bug 3128 - Removing all the static variables from android SDLActivity and accompanying JNI calls.
authorSam Lantinga <slouken@libsdl.org>
Sat, 12 Aug 2017 12:24:59 -0700
changeset 11239856e5e3c1e86
parent 11238 c728c661cec7
child 11240 1f6105d09344
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.
src/core/android/SDL_android.c
src/core/android/SDL_android.h
src/video/android/SDL_androidtouch.c
     1.1 --- a/src/core/android/SDL_android.c	Sat Aug 12 08:15:09 2017 -0700
     1.2 +++ b/src/core/android/SDL_android.c	Sat Aug 12 12:24:59 2017 -0700
     1.3 @@ -181,6 +181,9 @@
     1.4  static jmethodID midPollHapticDevices;
     1.5  static jmethodID midHapticRun;
     1.6  
     1.7 +/* static fields */
     1.8 +static jfieldID fidSeparateMouseAndTouch;
     1.9 +
    1.10  /* Accelerometer data storage */
    1.11  static float fLastAccelerometer[3];
    1.12  static SDL_bool bHasNewData;
    1.13 @@ -253,6 +256,13 @@
    1.14         !midPollInputDevices || !midPollHapticDevices || !midHapticRun) {
    1.15          __android_log_print(ANDROID_LOG_WARN, "SDL", "SDL: Couldn't locate Java callbacks, check that they're named and typed correctly");
    1.16      }
    1.17 +
    1.18 +    fidSeparateMouseAndTouch = (*mEnv)->GetStaticFieldID(mEnv, mActivityClass, "mSeparateMouseAndTouch", "Z");
    1.19 +    
    1.20 +    if (!fidSeparateMouseAndTouch) {
    1.21 +        __android_log_print(ANDROID_LOG_WARN, "SDL", "SDL: Couldn't locate Java static fields, check that they're named and typed correctly");
    1.22 +    }
    1.23 +
    1.24      __android_log_print(ANDROID_LOG_INFO, "SDL", "SDL_Android_Init() finished!");
    1.25  }
    1.26  
    1.27 @@ -693,11 +703,6 @@
    1.28      return 1;
    1.29  }
    1.30  
    1.31 -jclass Android_JNI_GetActivityClass(void)
    1.32 -{
    1.33 -    return mActivityClass;
    1.34 -}
    1.35 -
    1.36  /*
    1.37   * Audio support
    1.38   */
    1.39 @@ -1590,6 +1595,13 @@
    1.40      return number;
    1.41  }
    1.42  
    1.43 +/* sets the mSeparateMouseAndTouch field */
    1.44 +void Android_JNI_SetSeparateMouseAndTouch(SDL_bool new_value)
    1.45 +{
    1.46 +    JNIEnv *env = Android_JNI_GetEnv();
    1.47 +    (*env)->SetStaticBooleanField(env, mActivityClass, fidSeparateMouseAndTouch, new_value ? JNI_TRUE : JNI_FALSE);
    1.48 +}
    1.49 +
    1.50  void Android_JNI_PollInputDevices(void)
    1.51  {
    1.52      JNIEnv *env = Android_JNI_GetEnv();
     2.1 --- a/src/core/android/SDL_android.h	Sat Aug 12 08:15:09 2017 -0700
     2.2 +++ b/src/core/android/SDL_android.h	Sat Aug 12 12:24:59 2017 -0700
     2.3 @@ -76,12 +76,12 @@
     2.4  
     2.5  /* Touch support */
     2.6  int Android_JNI_GetTouchDeviceIds(int **ids);
     2.7 +void Android_JNI_SetSeparateMouseAndTouch(SDL_bool new_value);
     2.8  
     2.9  /* Threads */
    2.10  #include <jni.h>
    2.11  JNIEnv *Android_JNI_GetEnv(void);
    2.12  int Android_JNI_SetupThread(void);
    2.13 -jclass Android_JNI_GetActivityClass(void);
    2.14  
    2.15  /* Generic messages */
    2.16  int Android_JNI_SendMessage(int command, int param);
     3.1 --- a/src/video/android/SDL_androidtouch.c	Sat Aug 12 08:15:09 2017 -0700
     3.2 +++ b/src/video/android/SDL_androidtouch.c	Sat Aug 12 12:24:59 2017 -0700
     3.3 @@ -56,12 +56,9 @@
     3.4  SeparateEventsHintWatcher(void *userdata, const char *name,
     3.5                            const char *oldValue, const char *newValue)
     3.6  {
     3.7 -    jclass mActivityClass = Android_JNI_GetActivityClass();
     3.8 -    JNIEnv *env = Android_JNI_GetEnv();
     3.9 -    jfieldID fid = (*env)->GetStaticFieldID(env, mActivityClass, "mSeparateMouseAndTouch", "Z");
    3.10 +    separate_mouse_and_touch = (newValue && (SDL_strcmp(newValue, "1") == 0));
    3.11  
    3.12 -    separate_mouse_and_touch = (newValue && (SDL_strcmp(newValue, "1") == 0));
    3.13 -    (*env)->SetStaticBooleanField(env, mActivityClass, fid, separate_mouse_and_touch ? JNI_TRUE : JNI_FALSE);
    3.14 +    Android_JNI_SetSeparateMouseAndTouch(separate_mouse_and_touch);
    3.15  }
    3.16  
    3.17  void Android_InitTouch(void)