SDL_android.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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_VIDEO_DISABLED
  28. #include <EGL/eglplatform.h>
  29. #include <android/native_window_jni.h>
  30. #endif
  31. #ifndef SDL_AUDIO_DISABLED
  32. #include "../../audio/SDL_sysaudio.h"
  33. // this appears to be broken right now (on Android, not SDL, I think...?).
  34. #define ALLOW_MULTIPLE_ANDROID_AUDIO_DEVICES 0
  35. #endif
  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. // Interface from the SDL library into the Android Java activity
  53. extern void Android_JNI_SetActivityTitle(const char *title);
  54. extern void Android_JNI_SetWindowStyle(bool fullscreen);
  55. extern void Android_JNI_SetOrientation(int w, int h, int resizable, const char *hint);
  56. extern void Android_JNI_MinimizeWindow(void);
  57. extern bool Android_JNI_ShouldMinimizeOnFocusLoss(void);
  58. extern void Android_JNI_ShowScreenKeyboard(int input_type, SDL_Rect *inputRect);
  59. extern void Android_JNI_HideScreenKeyboard(void);
  60. extern ANativeWindow *Android_JNI_GetNativeWindow(void);
  61. #endif // !SDL_VIDEO_DISABLED
  62. // Kept outside the video guard for the camera driver; stays SDL_ORIENTATION_UNKNOWN when video is disabled (only the video Java layer updates it).
  63. extern SDL_DisplayOrientation Android_JNI_GetDisplayNaturalOrientation(void);
  64. extern SDL_DisplayOrientation Android_JNI_GetDisplayCurrentOrientation(void);
  65. #ifndef SDL_AUDIO_DISABLED
  66. // Audio support
  67. void Android_StartAudioHotplug(SDL_AudioDevice **default_playback, SDL_AudioDevice **default_recording);
  68. void Android_StopAudioHotplug(void);
  69. extern void Android_AudioThreadInit(SDL_AudioDevice *device);
  70. #endif // !SDL_AUDIO_DISABLED
  71. // Detecting device type
  72. extern bool Android_IsDeXMode(void);
  73. extern bool Android_IsChromebook(void);
  74. bool Android_JNI_FileOpen(void **puserdata, const char *fileName, const char *mode);
  75. Sint64 Android_JNI_FileSize(void *userdata);
  76. Sint64 Android_JNI_FileSeek(void *userdata, Sint64 offset, SDL_IOWhence whence);
  77. size_t Android_JNI_FileRead(void *userdata, void *buffer, size_t size, SDL_IOStatus *status);
  78. size_t Android_JNI_FileWrite(void *userdata, const void *buffer, size_t size, SDL_IOStatus *status);
  79. bool Android_JNI_FileClose(void *userdata);
  80. bool Android_JNI_EnumerateAssetDirectory(const char *path, SDL_EnumerateDirectoryCallback cb, void *userdata);
  81. bool Android_JNI_GetAssetPathInfo(const char *path, SDL_PathInfo *info);
  82. // Environment support
  83. void Android_JNI_GetManifestEnvironmentVariables(void);
  84. int Android_JNI_OpenFileDescriptor(const char *uri, const char *mode);
  85. #ifndef SDL_VIDEO_DISABLED
  86. // Clipboard support
  87. bool Android_JNI_SetClipboardText(const char *text);
  88. char *Android_JNI_GetClipboardText(void);
  89. bool Android_JNI_HasClipboardText(void);
  90. #endif // !SDL_VIDEO_DISABLED
  91. // Power support
  92. int Android_JNI_GetPowerInfo(int *plugged, int *charged, int *battery, int *seconds, int *percent);
  93. // Joystick support
  94. void Android_JNI_DetectDevices(void);
  95. void Android_JNI_JoystickSetLED(int device_id, int red, int green, int blue);
  96. void Android_JNI_JoystickSetSensorsEnabled(int device_id, bool enabled);
  97. // Haptic support
  98. void Android_JNI_DetectHapticDevices(void);
  99. void Android_JNI_HapticRun(int device_id, float intensity, int length);
  100. void Android_JNI_HapticRumble(int device_id, float low_frequency_intensity, float high_frequency_intensity, int length);
  101. void Android_JNI_HapticStop(int device_id);
  102. // Video
  103. bool Android_JNI_SuspendScreenSaver(bool suspend);
  104. #ifndef SDL_VIDEO_DISABLED
  105. // Touch support
  106. void Android_JNI_InitTouch(void);
  107. #endif // !SDL_VIDEO_DISABLED
  108. // Threads
  109. #include <jni.h>
  110. JNIEnv *Android_JNI_GetEnv(void);
  111. bool Android_JNI_SetupThread(void);
  112. // Locale
  113. bool Android_JNI_GetLocale(char *buf, size_t buflen);
  114. // Generic messages
  115. bool Android_JNI_SendMessage(int command, int param);
  116. // MessageBox
  117. bool Android_JNI_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonID);
  118. #ifndef SDL_VIDEO_DISABLED
  119. // Cursor support
  120. int Android_JNI_CreateCustomCursor(SDL_Surface *surface, int hot_x, int hot_y);
  121. void Android_JNI_DestroyCustomCursor(int cursorID);
  122. bool Android_JNI_SetCustomCursor(int cursorID);
  123. bool Android_JNI_SetSystemCursor(int cursorID);
  124. // Relative mouse support
  125. bool Android_JNI_SupportsRelativeMouse(void);
  126. bool Android_JNI_SetRelativeMouseEnabled(bool enabled);
  127. #endif // !SDL_VIDEO_DISABLED
  128. // Show toast notification
  129. bool Android_JNI_ShowToast(const char *message, int duration, int gravity, int xOffset, int yOffset);
  130. bool Android_JNI_OpenURL(const char *url);
  131. int SDL_GetAndroidSDKVersion(void);
  132. bool SDL_IsAndroidTablet(void);
  133. bool SDL_IsAndroidTV(void);
  134. SDL_FormFactor SDL_GetAndroidDeviceFormFactor(void);
  135. char *SDL_GetAndroidPackageName(void); // this is a SDL_malloc'd string the caller will own.
  136. // File Dialogs
  137. bool Android_JNI_ShowFileDialog(SDL_DialogFileCallback callback, void *userdata,
  138. const SDL_DialogFileFilter *filters, int nfilters, SDL_FileDialogType type,
  139. bool multiple, const char *initialPath);
  140. // Ends C function definitions when using C++
  141. #ifdef __cplusplus
  142. /* *INDENT-OFF* */
  143. }
  144. /* *INDENT-ON* */
  145. #endif
  146. #endif // SDL_android_h