src/core/android/SDL_android.c
changeset 8057 801d84e26f91
parent 8055 3e2f230a6d62
child 8093 b43765095a6f
     1.1 --- a/src/core/android/SDL_android.c	Mon Dec 09 15:17:20 2013 -0500
     1.2 +++ b/src/core/android/SDL_android.c	Tue Dec 10 16:24:11 2013 -0300
     1.3 @@ -34,7 +34,7 @@
     1.4  #include "../../video/android/SDL_androidtouch.h"
     1.5  #include "../../video/android/SDL_androidvideo.h"
     1.6  #include "../../video/android/SDL_androidwindow.h"
     1.7 -#include "../../joystick/android/SDL_sysjoystick.h"
     1.8 +#include "../../joystick/android/SDL_sysjoystick_c.h"
     1.9  
    1.10  #include <android/log.h>
    1.11  #include <pthread.h>
    1.12 @@ -75,6 +75,7 @@
    1.13  static jmethodID midAudioWriteShortBuffer;
    1.14  static jmethodID midAudioWriteByteBuffer;
    1.15  static jmethodID midAudioQuit;
    1.16 +static jmethodID midPollInputDevices;
    1.17  
    1.18  /* Accelerometer data storage */
    1.19  static float fLastAccelerometer[3];
    1.20 @@ -127,11 +128,13 @@
    1.21                                  "audioWriteByteBuffer", "([B)V");
    1.22      midAudioQuit = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass,
    1.23                                  "audioQuit", "()V");
    1.24 +    midPollInputDevices = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass,
    1.25 +                                "pollInputDevices", "()V");
    1.26  
    1.27      bHasNewData = false;
    1.28  
    1.29      if(!midGetNativeSurface || !midFlipBuffers || !midAudioInit ||
    1.30 -       !midAudioWriteShortBuffer || !midAudioWriteByteBuffer || !midAudioQuit) {
    1.31 +       !midAudioWriteShortBuffer || !midAudioWriteByteBuffer || !midAudioQuit || !midPollInputDevices) {
    1.32          __android_log_print(ANDROID_LOG_WARN, "SDL", "SDL: Couldn't locate Java callbacks, check that they're named and typed correctly");
    1.33      }
    1.34      __android_log_print(ANDROID_LOG_INFO, "SDL", "SDL_Android_Init() finished!");
    1.35 @@ -148,25 +151,47 @@
    1.36  // Paddown
    1.37  int Java_org_libsdl_app_SDLActivity_onNativePadDown(
    1.38                                      JNIEnv* env, jclass jcls,
    1.39 -                                    jint padId, jint keycode)
    1.40 +                                    jint device_id, jint keycode)
    1.41  {
    1.42 -    return Android_OnPadDown(padId, keycode);
    1.43 +    return Android_OnPadDown(device_id, keycode);
    1.44  }
    1.45  
    1.46  // Padup
    1.47  int Java_org_libsdl_app_SDLActivity_onNativePadUp(
    1.48                                     JNIEnv* env, jclass jcls,
    1.49 -                                   jint padId, jint keycode)
    1.50 +                                   jint device_id, jint keycode)
    1.51  {
    1.52 -    return Android_OnPadUp(padId, keycode);
    1.53 +    return Android_OnPadUp(device_id, keycode);
    1.54  }
    1.55  
    1.56  /* Joy */
    1.57  void Java_org_libsdl_app_SDLActivity_onNativeJoy(
    1.58                                      JNIEnv* env, jclass jcls,
    1.59 -                                    jint joyId, jint axis, jfloat value)
    1.60 +                                    jint device_id, jint axis, jfloat value)
    1.61  {
    1.62 -    Android_OnJoy(joyId, axis, value);
    1.63 +    Android_OnJoy(device_id, axis, value);
    1.64 +}
    1.65 +
    1.66 +
    1.67 +int Java_org_libsdl_app_SDLActivity_nativeAddJoystick(
    1.68 +    JNIEnv* env, jclass jcls,
    1.69 +    jint device_id, jstring device_name, jint is_accelerometer, 
    1.70 +    jint nbuttons, jint naxes, jint nhats, jint nballs)
    1.71 +{
    1.72 +    int retval;
    1.73 +    const char *name = (*env)->GetStringUTFChars(env, device_name, NULL);
    1.74 +
    1.75 +    retval = Android_AddJoystick(device_id, name, (SDL_bool) is_accelerometer, nbuttons, naxes, nhats, nballs);
    1.76 +
    1.77 +    (*env)->ReleaseStringUTFChars(env, device_name, name);
    1.78 +    
    1.79 +    return retval;
    1.80 +}
    1.81 +
    1.82 +int Java_org_libsdl_app_SDLActivity_nativeRemoveJoystick(
    1.83 +    JNIEnv* env, jclass jcls, jint device_id)
    1.84 +{
    1.85 +    return Android_RemoveJoystick(device_id);
    1.86  }
    1.87  
    1.88  
    1.89 @@ -1247,62 +1272,12 @@
    1.90      return number;
    1.91  }
    1.92  
    1.93 -/* return the total number of plugged in joysticks */
    1.94 -int Android_JNI_GetNumJoysticks()
    1.95 +void Android_JNI_PollInputDevices()
    1.96  {
    1.97 -    JNIEnv* env = Android_JNI_GetEnv();
    1.98 -    if (!env) {
    1.99 -        return -1;
   1.100 -    }
   1.101 -    
   1.102 -    jmethodID mid = (*env)->GetStaticMethodID(env, mActivityClass, "getNumJoysticks", "()I");
   1.103 -    if (!mid) {
   1.104 -        return -1;
   1.105 -    }
   1.106 -    
   1.107 -    return (int)(*env)->CallStaticIntMethod(env, mActivityClass, mid);
   1.108 +    JNIEnv *env = Android_JNI_GetEnv();
   1.109 +    (*env)->CallStaticVoidMethod(env, mActivityClass, midPollInputDevices);    
   1.110  }
   1.111  
   1.112 -/* Return the name of joystick number "i" */
   1.113 -char* Android_JNI_GetJoystickName(int i)
   1.114 -{
   1.115 -    JNIEnv* env = Android_JNI_GetEnv();
   1.116 -    if (!env) {
   1.117 -        return SDL_strdup("");
   1.118 -    }
   1.119 -    
   1.120 -    jmethodID mid = (*env)->GetStaticMethodID(env, mActivityClass, "getJoystickName", "(I)Ljava/lang/String;");
   1.121 -    if (!mid) {
   1.122 -        return SDL_strdup("");
   1.123 -    }
   1.124 -    jstring string = (jstring)((*env)->CallStaticObjectMethod(env, mActivityClass, mid, i));
   1.125 -    const char* utf = (*env)->GetStringUTFChars(env, string, 0);
   1.126 -    if (!utf) {
   1.127 -        return SDL_strdup("");
   1.128 -    }
   1.129 -    
   1.130 -    char* text = SDL_strdup(utf);
   1.131 -    (*env)->ReleaseStringUTFChars(env, string, utf);
   1.132 -    return text;
   1.133 -}
   1.134 -
   1.135 -/* return the number of axes in the given joystick */
   1.136 -int Android_JNI_GetJoystickAxes(int joy)
   1.137 -{
   1.138 -    JNIEnv* env = Android_JNI_GetEnv();
   1.139 -    if (!env) {
   1.140 -        return -1;
   1.141 -    }
   1.142 -    
   1.143 -    jmethodID mid = (*env)->GetStaticMethodID(env, mActivityClass, "getJoystickAxes", "(I)I");
   1.144 -    if (!mid) {
   1.145 -        return -1;
   1.146 -    }
   1.147 -    
   1.148 -    return (int)(*env)->CallIntMethod(env, mActivityClass, mid, joy);
   1.149 -}
   1.150 -
   1.151 -
   1.152  /* sends message to be handled on the UI event dispatch thread */
   1.153  int Android_JNI_SendMessage(int command, int param)
   1.154  {