SDL_android.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2026 Sam Lantinga <slouken@libsdl.org>
  4. This software is provided 'as-is', without any express or implied
  5. warranty. In no event will the authors be held liable for any damages
  6. arising from the use of this software.
  7. Permission is granted to anyone to use this software for any purpose,
  8. including commercial applications, and to alter it and redistribute it
  9. freely, subject to the following restrictions:
  10. 1. The origin of this software must not be misrepresented; you must not
  11. claim that you wrote the original software. If you use this software
  12. in a product, an acknowledgment in the product documentation would be
  13. appreciated but is not required.
  14. 2. Altered source versions must be plainly marked as such, and must not be
  15. misrepresented as being the original software.
  16. 3. This notice may not be removed or altered from any source distribution.
  17. */
  18. #include "SDL_internal.h"
  19. #ifndef SDL_android_h
  20. #define SDL_android_h
  21. // Set up for C function definitions, even when using C++
  22. #ifdef __cplusplus
  23. /* *INDENT-OFF* */
  24. extern "C" {
  25. /* *INDENT-ON* */
  26. #endif
  27. #ifndef SDL_AUDIO_DISABLED
  28. // Audio support
  29. #include "../../audio/SDL_sysaudio.h"
  30. // this appears to be broken right now (on Android, not SDL, I think...?).
  31. #define ALLOW_MULTIPLE_ANDROID_AUDIO_DEVICES 0
  32. void Android_StartAudioHotplug(SDL_AudioDevice **default_playback, SDL_AudioDevice **default_recording);
  33. void Android_StopAudioHotplug(void);
  34. extern void Android_AudioThreadInit(SDL_AudioDevice *device);
  35. #endif // !SDL_AUDIO_DISABLED
  36. // Life cycle
  37. typedef enum
  38. {
  39. SDL_ANDROID_LIFECYCLE_WAKE,
  40. SDL_ANDROID_LIFECYCLE_PAUSE,
  41. SDL_ANDROID_LIFECYCLE_RESUME,
  42. SDL_ANDROID_LIFECYCLE_LOWMEMORY,
  43. SDL_ANDROID_LIFECYCLE_DESTROY,
  44. SDL_NUM_ANDROID_LIFECYCLE_EVENTS
  45. } SDL_AndroidLifecycleEvent;
  46. void Android_SendLifecycleEvent(SDL_AndroidLifecycleEvent event);
  47. bool Android_WaitLifecycleEvent(SDL_AndroidLifecycleEvent *event, Sint64 timeoutNS);
  48. void Android_LockActivityMutex(void);
  49. void Android_UnlockActivityMutex(void);
  50. void Android_SetAllowRecreateActivity(bool enabled);
  51. #ifndef SDL_VIDEO_DISABLED
  52. #include <EGL/eglplatform.h>
  53. #include <android/native_window_jni.h>
  54. // Interface from the SDL library into the Android Java activity
  55. extern void Android_JNI_SetActivityTitle(const char *title);
  56. extern void Android_JNI_SetWindowStyle(bool fullscreen);
  57. extern void Android_JNI_SetOrientation(int w, int h, int resizable, const char *hint);
  58. extern void Android_JNI_MinimizeWindow(void);
  59. extern bool Android_JNI_ShouldMinimizeOnFocusLoss(void);
  60. extern void Android_JNI_ShowScreenKeyboard(int input_type, SDL_Rect *inputRect);
  61. extern void Android_JNI_HideScreenKeyboard(void);
  62. bool Android_JNI_SuspendScreenSaver(bool suspend);
  63. extern ANativeWindow *Android_JNI_GetNativeWindow(void);
  64. extern SDL_DisplayOrientation Android_JNI_GetDisplayNaturalOrientation(void);
  65. // Also used by the camera subsystem, which is safe because camera requires video.
  66. extern SDL_DisplayOrientation Android_JNI_GetDisplayCurrentOrientation(void);
  67. // Clipboard support
  68. bool Android_JNI_SetClipboardText(const char *text);
  69. char *Android_JNI_GetClipboardText(void);
  70. bool Android_JNI_HasClipboardText(void);
  71. // Touch support
  72. void Android_JNI_InitTouch(void);
  73. // Cursor support
  74. int Android_JNI_CreateCustomCursor(SDL_Surface *surface, int hot_x, int hot_y);
  75. void Android_JNI_DestroyCustomCursor(int cursorID);
  76. bool Android_JNI_SetCustomCursor(int cursorID);
  77. bool Android_JNI_SetSystemCursor(int cursorID);
  78. // Relative mouse support
  79. bool Android_JNI_SupportsRelativeMouse(void);
  80. bool Android_JNI_SetRelativeMouseEnabled(bool enabled);
  81. // MessageBox
  82. bool Android_JNI_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonID);
  83. #endif // !SDL_VIDEO_DISABLED
  84. bool Android_JNI_FileOpen(void **puserdata, const char *fileName, const char *mode);
  85. Sint64 Android_JNI_FileSize(void *userdata);
  86. Sint64 Android_JNI_FileSeek(void *userdata, Sint64 offset, SDL_IOWhence whence);
  87. size_t Android_JNI_FileRead(void *userdata, void *buffer, size_t size, SDL_IOStatus *status);
  88. size_t Android_JNI_FileWrite(void *userdata, const void *buffer, size_t size, SDL_IOStatus *status);
  89. bool Android_JNI_FileClose(void *userdata);
  90. bool Android_JNI_EnumerateAssetDirectory(const char *path, SDL_EnumerateDirectoryCallback cb, void *userdata);
  91. bool Android_JNI_GetAssetPathInfo(const char *path, SDL_PathInfo *info);
  92. // Environment support
  93. void Android_JNI_GetManifestEnvironmentVariables(void);
  94. int Android_JNI_OpenFileDescriptor(const char *uri, const char *mode);
  95. #ifndef SDL_POWER_DISABLED
  96. // Power support
  97. int Android_JNI_GetPowerInfo(int *plugged, int *charged, int *battery, int *seconds, int *percent);
  98. #endif // !SDL_POWER_DISABLED
  99. #ifndef SDL_JOYSTICK_DISABLED
  100. // Joystick support
  101. void Android_JNI_DetectDevices(void);
  102. void Android_JNI_JoystickSetLED(int device_id, int red, int green, int blue);
  103. void Android_JNI_JoystickSetSensorsEnabled(int device_id, bool enabled);
  104. #endif // !SDL_JOYSTICK_DISABLED
  105. #ifndef SDL_HAPTIC_DISABLED
  106. // Haptic support
  107. void Android_JNI_DetectHapticDevices(void);
  108. void Android_JNI_HapticRun(int device_id, float intensity, int length);
  109. void Android_JNI_HapticRumble(int device_id, float low_frequency_intensity, float high_frequency_intensity, int length);
  110. void Android_JNI_HapticStop(int device_id);
  111. #endif // !SDL_HAPTIC_DISABLED
  112. // Threads
  113. #include <jni.h>
  114. JNIEnv *Android_JNI_GetEnv(void);
  115. bool Android_JNI_SetupThread(void);
  116. // Locale
  117. bool Android_JNI_GetLocale(char *buf, size_t buflen);
  118. // Generic messages
  119. bool Android_JNI_SendMessage(int command, int param);
  120. // Show toast notification
  121. bool Android_JNI_ShowToast(const char *message, int duration, int gravity, int xOffset, int yOffset);
  122. bool Android_JNI_OpenURL(const char *url);
  123. int SDL_GetAndroidSDKVersion(void);
  124. bool SDL_IsAndroidTablet(void);
  125. bool SDL_IsAndroidTV(void);
  126. SDL_FormFactor SDL_GetAndroidDeviceFormFactor(void);
  127. char *SDL_GetAndroidPackageName(void); // this is a SDL_malloc'd string the caller will own.
  128. #ifndef SDL_DIALOG_DISABLED
  129. // File Dialogs
  130. bool Android_JNI_ShowFileDialog(SDL_DialogFileCallback callback, void *userdata, const SDL_DialogFileFilter *filters,
  131. int nfilters, SDL_FileDialogType type, bool multiple, const char *initialPath);
  132. #endif // !SDL_DIALOG_DISABLED
  133. // Ends C function definitions when using C++
  134. #ifdef __cplusplus
  135. /* *INDENT-OFF* */
  136. }
  137. /* *INDENT-ON* */
  138. #endif
  139. #endif // SDL_android_h