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