src/core/android/SDL_android.c
changeset 11238 c728c661cec7
parent 11066 f39b145db3eb
child 11239 856e5e3c1e86
     1.1 --- a/src/core/android/SDL_android.c	Sat Aug 12 08:06:16 2017 -0700
     1.2 +++ b/src/core/android/SDL_android.c	Sat Aug 12 08:15:09 2017 -0700
     1.3 @@ -37,6 +37,7 @@
     1.4  #include "../../video/android/SDL_androidvideo.h"
     1.5  #include "../../video/android/SDL_androidwindow.h"
     1.6  #include "../../joystick/android/SDL_sysjoystick_c.h"
     1.7 +#include "../../haptic/android/SDL_syshaptic_c.h"
     1.8  
     1.9  #include <android/log.h>
    1.10  #include <pthread.h>
    1.11 @@ -177,6 +178,8 @@
    1.12  static jmethodID midCaptureReadByteBuffer;
    1.13  static jmethodID midCaptureClose;
    1.14  static jmethodID midPollInputDevices;
    1.15 +static jmethodID midPollHapticDevices;
    1.16 +static jmethodID midHapticRun;
    1.17  
    1.18  /* Accelerometer data storage */
    1.19  static float fLastAccelerometer[3];
    1.20 @@ -237,13 +240,17 @@
    1.21                                  "captureClose", "()V");
    1.22      midPollInputDevices = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass,
    1.23                                  "pollInputDevices", "()V");
    1.24 +    midPollHapticDevices = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass,
    1.25 +                                "pollHapticDevices", "()V");
    1.26 +    midHapticRun = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass,
    1.27 +                                "hapticRun", "(II)V");
    1.28  
    1.29      bHasNewData = SDL_FALSE;
    1.30  
    1.31      if (!midGetNativeSurface ||
    1.32         !midAudioOpen || !midAudioWriteShortBuffer || !midAudioWriteByteBuffer || !midAudioClose ||
    1.33         !midCaptureOpen || !midCaptureReadShortBuffer || !midCaptureReadByteBuffer || !midCaptureClose ||
    1.34 -       !midPollInputDevices) {
    1.35 +       !midPollInputDevices || !midPollHapticDevices || !midHapticRun) {
    1.36          __android_log_print(ANDROID_LOG_WARN, "SDL", "SDL: Couldn't locate Java callbacks, check that they're named and typed correctly");
    1.37      }
    1.38      __android_log_print(ANDROID_LOG_INFO, "SDL", "SDL_Android_Init() finished!");
    1.39 @@ -323,6 +330,25 @@
    1.40      return Android_RemoveJoystick(device_id);
    1.41  }
    1.42  
    1.43 +JNIEXPORT jint JNICALL Java_org_libsdl_app_SDLActivity_nativeAddHaptic(
    1.44 +    JNIEnv* env, jclass jcls, jint device_id, jstring device_name)
    1.45 +{
    1.46 +    int retval;
    1.47 +    const char *name = (*env)->GetStringUTFChars(env, device_name, NULL);
    1.48 +
    1.49 +    retval = Android_AddHaptic(device_id, name);
    1.50 +
    1.51 +    (*env)->ReleaseStringUTFChars(env, device_name, name);
    1.52 +
    1.53 +    return retval;
    1.54 +}
    1.55 +
    1.56 +JNIEXPORT jint JNICALL Java_org_libsdl_app_SDLActivity_nativeRemoveHaptic(
    1.57 +    JNIEnv* env, jclass jcls, jint device_id)
    1.58 +{
    1.59 +    return Android_RemoveHaptic(device_id);
    1.60 +}
    1.61 +
    1.62  
    1.63  /* Surface Created */
    1.64  JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeSurfaceChanged)(JNIEnv* env, jclass jcls)
    1.65 @@ -1570,6 +1596,19 @@
    1.66      (*env)->CallStaticVoidMethod(env, mActivityClass, midPollInputDevices);    
    1.67  }
    1.68  
    1.69 +void Android_JNI_PollHapticDevices(void)
    1.70 +{
    1.71 +    JNIEnv *env = Android_JNI_GetEnv();
    1.72 +    (*env)->CallStaticVoidMethod(env, mActivityClass, midPollHapticDevices);
    1.73 +}
    1.74 +    
    1.75 +void Android_JNI_HapticRun(int device_id, int length)
    1.76 +{
    1.77 +    JNIEnv *env = Android_JNI_GetEnv();
    1.78 +    (*env)->CallStaticVoidMethod(env, mActivityClass, midHapticRun, device_id, length);
    1.79 +}
    1.80 +
    1.81 +
    1.82  /* See SDLActivity.java for constants. */
    1.83  #define COMMAND_SET_KEEP_SCREEN_ON    5
    1.84