Fixed bug #5221 - Add SDL_AndroidSendMessage()
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
diff --git a/include/SDL_system.h b/include/SDL_system.h
index e2fa7b5..2257643 100644
--- a/include/SDL_system.h
+++ b/include/SDL_system.h
@@ -425,6 +425,15 @@ extern DECLSPEC SDL_bool SDLCALL SDL_AndroidRequestPermission(const char *permis
*/
extern DECLSPEC int SDLCALL SDL_AndroidShowToast(const char* message, int duration, int gravity, int xoffset, int yoffset);
+/**
+ * Send a user command to SDLActivity
+ * override "boolean onUnhandledMessage(Message msg)" to handle the message
+ *
+ * \param command user command that must be greater or equal to 0x8000
+ * \param param user parameter
+ */
+extern DECLSPEC int SDLCALL SDL_AndroidSendMessage(Uint32 command, int param);
+
#endif /* __ANDROID__ */
/* Platform specific functions for WinRT */
diff --git a/src/core/android/SDL_android.c b/src/core/android/SDL_android.c
index 4236835..c3815d1 100644
--- a/src/core/android/SDL_android.c
+++ b/src/core/android/SDL_android.c
@@ -2126,6 +2126,15 @@ void Android_JNI_HapticStop(int device_id)
/* See SDLActivity.java for constants. */
#define COMMAND_SET_KEEP_SCREEN_ON 5
+
+int SDL_AndroidSendMessage(Uint32 command, int param)
+{
+ if (command >= 0x8000) {
+ return Android_JNI_SendMessage(command, param);
+ }
+ return -1;
+}
+
/* sends message to be handled on the UI event dispatch thread */
int Android_JNI_SendMessage(int command, int param)
{
diff --git a/src/dynapi/SDL_dynapi_overrides.h b/src/dynapi/SDL_dynapi_overrides.h
index 53bb4d4..2eec056 100644
--- a/src/dynapi/SDL_dynapi_overrides.h
+++ b/src/dynapi/SDL_dynapi_overrides.h
@@ -855,3 +855,4 @@
#define SDL_GameControllerHasRumbleTriggers SDL_GameControllerHasRumbleTriggers_REAL
#define SDL_hid_ble_scan SDL_hid_ble_scan_REAL
#define SDL_PremultiplyAlpha SDL_PremultiplyAlpha_REAL
+#define SDL_AndroidSendMessage SDL_AndroidSendMessage_REAL
diff --git a/src/dynapi/SDL_dynapi_procs.h b/src/dynapi/SDL_dynapi_procs.h
index 000cde8..2d870ec 100644
--- a/src/dynapi/SDL_dynapi_procs.h
+++ b/src/dynapi/SDL_dynapi_procs.h
@@ -924,3 +924,4 @@ SDL_DYNAPI_PROC(SDL_bool,SDL_GameControllerHasRumble,(SDL_GameController *a),(a)
SDL_DYNAPI_PROC(SDL_bool,SDL_GameControllerHasRumbleTriggers,(SDL_GameController *a),(a),return)
SDL_DYNAPI_PROC(void,SDL_hid_ble_scan,(SDL_bool a),(a),)
SDL_DYNAPI_PROC(int,SDL_PremultiplyAlpha,(int a, int b, Uint32 c, const void *d, int e, Uint32 f, void *g, int h),(a,b,c,d,e,f,g,h),return)
+SDL_DYNAPI_PROC(int,SDL_AndroidSendMessage,(Uint32 a, int b),(a,b),return)