Implement SDL_HapticStopEffect on Android (thanks Rachel!)
authorSam Lantinga <slouken@libsdl.org>
Fri, 24 Aug 2018 10:41:57 -0700
changeset 12152cb129c06aa86
parent 12151 5b9895d82ebe
child 12153 de4288fa5b0b
Implement SDL_HapticStopEffect on Android (thanks Rachel!)
android-project/app/src/main/java/org/libsdl/app/SDLControllerManager.java
src/core/android/SDL_android.c
src/core/android/SDL_android.h
src/haptic/android/SDL_syshaptic.c
     1.1 --- a/android-project/app/src/main/java/org/libsdl/app/SDLControllerManager.java	Fri Aug 24 09:49:48 2018 -0400
     1.2 +++ b/android-project/app/src/main/java/org/libsdl/app/SDLControllerManager.java	Fri Aug 24 10:41:57 2018 -0700
     1.3 @@ -81,6 +81,14 @@
     1.4          mHapticHandler.run(device_id, length);
     1.5      }
     1.6  
     1.7 +    /**
     1.8 +     * This method is called by SDL using JNI.
     1.9 +     */
    1.10 +    public static void hapticStop(int device_id)
    1.11 +    {
    1.12 +        mHapticHandler.stop(device_id);
    1.13 +    }
    1.14 +
    1.15      // Check if a given device is considered a possible SDL joystick
    1.16      public static boolean isDeviceSDLJoystick(int deviceId) {
    1.17          InputDevice device = InputDevice.getDevice(deviceId);
    1.18 @@ -422,6 +430,13 @@
    1.19          }
    1.20      }
    1.21  
    1.22 +    public void stop(int device_id) {
    1.23 +        SDLHaptic haptic = getHaptic(device_id);
    1.24 +        if (haptic != null) {
    1.25 +            haptic.vib.cancel();
    1.26 +        }
    1.27 +    }
    1.28 +
    1.29      public void pollHapticDevices() {
    1.30          
    1.31          final int deviceId_VIBRATOR_SERVICE = 999999;
     2.1 --- a/src/core/android/SDL_android.c	Fri Aug 24 09:49:48 2018 -0400
     2.2 +++ b/src/core/android/SDL_android.c	Fri Aug 24 10:41:57 2018 -0700
     2.3 @@ -258,6 +258,7 @@
     2.4  static jmethodID midPollInputDevices;
     2.5  static jmethodID midPollHapticDevices;
     2.6  static jmethodID midHapticRun;
     2.7 +static jmethodID midHapticStop;
     2.8  
     2.9  /* static fields */
    2.10  static jfieldID fidSeparateMouseAndTouch;
    2.11 @@ -430,8 +431,10 @@
    2.12                                  "pollHapticDevices", "()V");
    2.13      midHapticRun = (*mEnv)->GetStaticMethodID(mEnv, mControllerManagerClass,
    2.14                                  "hapticRun", "(II)V");
    2.15 +    midHapticStop = (*mEnv)->GetStaticMethodID(mEnv, mControllerManagerClass,
    2.16 +                                "hapticStop", "(I)V");
    2.17  
    2.18 -    if (!midPollInputDevices || !midPollHapticDevices || !midHapticRun) {
    2.19 +    if (!midPollInputDevices || !midPollHapticDevices || !midHapticRun || !midHapticStop) {
    2.20          __android_log_print(ANDROID_LOG_WARN, "SDL", "Missing some Java callbacks, do you have the latest version of SDLControllerManager.java?");
    2.21      }
    2.22  
    2.23 @@ -1892,6 +1895,11 @@
    2.24      (*env)->CallStaticVoidMethod(env, mControllerManagerClass, midHapticRun, device_id, length);
    2.25  }
    2.26  
    2.27 +void Android_JNI_HapticStop(int device_id)
    2.28 +{
    2.29 +    JNIEnv *env = Android_JNI_GetEnv();
    2.30 +    (*env)->CallStaticVoidMethod(env, mControllerManagerClass, midHapticStop, device_id);
    2.31 +}
    2.32  
    2.33  /* See SDLActivity.java for constants. */
    2.34  #define COMMAND_SET_KEEP_SCREEN_ON    5
     3.1 --- a/src/core/android/SDL_android.h	Fri Aug 24 09:49:48 2018 -0400
     3.2 +++ b/src/core/android/SDL_android.h	Fri Aug 24 10:41:57 2018 -0700
     3.3 @@ -79,6 +79,7 @@
     3.4  /* Haptic support */
     3.5  void Android_JNI_PollHapticDevices(void);
     3.6  void Android_JNI_HapticRun(int device_id, int length);
     3.7 +void Android_JNI_HapticStop(int device_id);
     3.8  
     3.9  /* Video */
    3.10  void Android_JNI_SuspendScreenSaver(SDL_bool suspend);
     4.1 --- a/src/haptic/android/SDL_syshaptic.c	Fri Aug 24 09:49:48 2018 -0400
     4.2 +++ b/src/haptic/android/SDL_syshaptic.c	Fri Aug 24 10:41:57 2018 -0700
     4.3 @@ -238,6 +238,7 @@
     4.4  int
     4.5  SDL_SYS_HapticStopEffect(SDL_Haptic * haptic, struct haptic_effect *effect)
     4.6  {
     4.7 +    Android_JNI_HapticStop (((SDL_hapticlist_item *)haptic->hwdata)->device_id);
     4.8      return 0;
     4.9  }
    4.10