src/core/android/SDL_android.h
author Sam Lantinga <slouken@libsdl.org>
Mon, 28 Aug 2017 10:03:39 -0700
changeset 11393 3e57ce45a890
parent 11271 ab3f2402a777
child 11653 4130b92b6be4
permissions -rw-r--r--
Fixed bug 2361 - [Android] Joysticks do not have unique IDs

David Brady

When I attempted to make a mapping file for Android gamepads, I quickly discovered that most of the ones that I have here show up as the same device (Broadcom Bluetooth HID), meaning that it was impossible to make mappings on Android, since every device looked the same.

This patch will check for the existence of the getDescriptor function added in Jelly Bean, and use it if it's there. The Android Dashboard says that the majority of Android phones should support this function, and doing it this way will not force us to bump up our API version.
     1 /*
     2   Simple DirectMedia Layer
     3   Copyright (C) 1997-2017 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 /* Set up for C function definitions, even when using C++ */
    24 #ifdef __cplusplus
    25 /* *INDENT-OFF* */
    26 extern "C" {
    27 /* *INDENT-ON* */
    28 #endif
    29 
    30 #include <EGL/eglplatform.h>
    31 #include <android/native_window_jni.h>
    32 
    33 #include "SDL_rect.h"
    34 
    35 /* Interface from the SDL library into the Android Java activity */
    36 extern void Android_JNI_SetActivityTitle(const char *title);
    37 extern void Android_JNI_SetOrientation(int w, int h, int resizable, const char *hint);
    38 
    39 extern SDL_bool Android_JNI_GetAccelerometerValues(float values[3]);
    40 extern void Android_JNI_ShowTextInput(SDL_Rect *inputRect);
    41 extern void Android_JNI_HideTextInput(void);
    42 extern SDL_bool Android_JNI_IsScreenKeyboardShown(void);
    43 extern ANativeWindow* Android_JNI_GetNativeWindow(void);
    44 
    45 /* Audio support */
    46 extern int Android_JNI_OpenAudioDevice(int iscapture, int sampleRate, int is16Bit, int channelCount, int desiredBufferFrames);
    47 extern void* Android_JNI_GetAudioBuffer(void);
    48 extern void Android_JNI_WriteAudioBuffer(void);
    49 extern int Android_JNI_CaptureAudioBuffer(void *buffer, int buflen);
    50 extern void Android_JNI_FlushCapturedAudio(void);
    51 extern void Android_JNI_CloseAudioDevice(const int iscapture);
    52 
    53 #include "SDL_rwops.h"
    54 
    55 int Android_JNI_FileOpen(SDL_RWops* ctx, const char* fileName, const char* mode);
    56 Sint64 Android_JNI_FileSize(SDL_RWops* ctx);
    57 Sint64 Android_JNI_FileSeek(SDL_RWops* ctx, Sint64 offset, int whence);
    58 size_t Android_JNI_FileRead(SDL_RWops* ctx, void* buffer, size_t size, size_t maxnum);
    59 size_t Android_JNI_FileWrite(SDL_RWops* ctx, const void* buffer, size_t size, size_t num);
    60 int Android_JNI_FileClose(SDL_RWops* ctx);
    61 
    62 /* Clipboard support */
    63 int Android_JNI_SetClipboardText(const char* text);
    64 char* Android_JNI_GetClipboardText(void);
    65 SDL_bool Android_JNI_HasClipboardText(void);
    66 
    67 /* Power support */
    68 int Android_JNI_GetPowerInfo(int* plugged, int* charged, int* battery, int* seconds, int* percent);
    69 
    70 /* Joystick support */
    71 void Android_JNI_PollInputDevices(void);
    72 
    73 /* Haptic support */
    74 void Android_JNI_PollHapticDevices(void);
    75 void Android_JNI_HapticRun(int device_id, int length);
    76 
    77 /* Video */
    78 void Android_JNI_SuspendScreenSaver(SDL_bool suspend);
    79 
    80 /* Touch support */
    81 int Android_JNI_GetTouchDeviceIds(int **ids);
    82 void Android_JNI_SetSeparateMouseAndTouch(SDL_bool new_value);
    83 
    84 /* Threads */
    85 #include <jni.h>
    86 JNIEnv *Android_JNI_GetEnv(void);
    87 int Android_JNI_SetupThread(void);
    88 
    89 /* Generic messages */
    90 int Android_JNI_SendMessage(int command, int param);
    91 
    92 /* Init */
    93 JNIEXPORT void JNICALL SDL_Android_Init(JNIEnv* mEnv, jclass cls);
    94 
    95 /* MessageBox */
    96 #include "SDL_messagebox.h"
    97 int Android_JNI_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid);
    98 
    99 /* Ends C function definitions when using C++ */
   100 #ifdef __cplusplus
   101 /* *INDENT-OFF* */
   102 }
   103 /* *INDENT-ON* */
   104 #endif
   105 
   106 /* vi: set ts=4 sw=4 expandtab: */