mirror of https://github.com/encounter/SDL.git
Fixed bug 3753 - Android : load methodID during initialization
Sylvain Small patch to load some java methodID at start-up (and avoid a potential crash at run-time).
This commit is contained in:
parent
1da2c1bb36
commit
e9d4e31044
|
@ -84,7 +84,7 @@ JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeHat)(
|
||||||
|
|
||||||
JNIEXPORT jint JNICALL SDL_JAVA_INTERFACE(nativeAddJoystick)(
|
JNIEXPORT jint JNICALL SDL_JAVA_INTERFACE(nativeAddJoystick)(
|
||||||
JNIEnv* env, jclass jcls,
|
JNIEnv* env, jclass jcls,
|
||||||
jint device_id, jstring device_name, jint is_accelerometer,
|
jint device_id, jstring device_name, jint is_accelerometer,
|
||||||
jint nbuttons, jint naxes, jint nhats, jint nballs);
|
jint nbuttons, jint naxes, jint nhats, jint nballs);
|
||||||
|
|
||||||
JNIEXPORT jint JNICALL SDL_JAVA_INTERFACE(nativeRemoveJoystick)(
|
JNIEXPORT jint JNICALL SDL_JAVA_INTERFACE(nativeRemoveJoystick)(
|
||||||
|
@ -180,6 +180,14 @@ static jmethodID midCaptureClose;
|
||||||
static jmethodID midPollInputDevices;
|
static jmethodID midPollInputDevices;
|
||||||
static jmethodID midPollHapticDevices;
|
static jmethodID midPollHapticDevices;
|
||||||
static jmethodID midHapticRun;
|
static jmethodID midHapticRun;
|
||||||
|
static jmethodID midSetActivityTitle;
|
||||||
|
static jmethodID midSetOrientation;
|
||||||
|
static jmethodID midGetContext;
|
||||||
|
static jmethodID midInputGetInputDeviceIds;
|
||||||
|
static jmethodID midSendMessage;
|
||||||
|
static jmethodID midShowTextInput;
|
||||||
|
static jmethodID midIsScreenKeyboardShown;
|
||||||
|
static jmethodID midGetSystemServiceFromUiThread;
|
||||||
|
|
||||||
/* static fields */
|
/* static fields */
|
||||||
static jfieldID fidSeparateMouseAndTouch;
|
static jfieldID fidSeparateMouseAndTouch;
|
||||||
|
@ -247,18 +255,36 @@ JNIEXPORT void JNICALL SDL_Android_Init(JNIEnv* mEnv, jclass cls)
|
||||||
"pollHapticDevices", "()V");
|
"pollHapticDevices", "()V");
|
||||||
midHapticRun = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass,
|
midHapticRun = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass,
|
||||||
"hapticRun", "(II)V");
|
"hapticRun", "(II)V");
|
||||||
|
midSetActivityTitle = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass,
|
||||||
|
"setActivityTitle","(Ljava/lang/String;)Z");
|
||||||
|
midSetOrientation = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass,
|
||||||
|
"setOrientation","(IIZLjava/lang/String;)V");
|
||||||
|
midGetContext = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass,
|
||||||
|
"getContext","()Landroid/content/Context;");
|
||||||
|
midInputGetInputDeviceIds = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass,
|
||||||
|
"inputGetInputDeviceIds", "(I)[I");
|
||||||
|
midSendMessage = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass,
|
||||||
|
"sendMessage", "(II)Z");
|
||||||
|
midShowTextInput = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass,
|
||||||
|
"showTextInput", "(IIII)Z");
|
||||||
|
midIsScreenKeyboardShown = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass,
|
||||||
|
"isScreenKeyboardShown","()Z");
|
||||||
|
midGetSystemServiceFromUiThread = (*mEnv)->GetMethodID(mEnv, mActivityClass,
|
||||||
|
"getSystemServiceFromUiThread", "(Ljava/lang/String;)Ljava/lang/Object;");
|
||||||
|
|
||||||
bHasNewData = SDL_FALSE;
|
bHasNewData = SDL_FALSE;
|
||||||
|
|
||||||
if (!midGetNativeSurface ||
|
if (!midGetNativeSurface ||
|
||||||
!midAudioOpen || !midAudioWriteShortBuffer || !midAudioWriteByteBuffer || !midAudioClose ||
|
!midAudioOpen || !midAudioWriteShortBuffer || !midAudioWriteByteBuffer || !midAudioClose ||
|
||||||
!midCaptureOpen || !midCaptureReadShortBuffer || !midCaptureReadByteBuffer || !midCaptureClose ||
|
!midCaptureOpen || !midCaptureReadShortBuffer || !midCaptureReadByteBuffer || !midCaptureClose ||
|
||||||
!midPollInputDevices || !midPollHapticDevices || !midHapticRun) {
|
!midPollInputDevices || !midPollHapticDevices || !midHapticRun ||
|
||||||
|
!midSetActivityTitle || !midSetOrientation || !midGetContext || !midInputGetInputDeviceIds ||
|
||||||
|
!midSendMessage || !midShowTextInput || !midIsScreenKeyboardShown || !midGetSystemServiceFromUiThread) {
|
||||||
__android_log_print(ANDROID_LOG_WARN, "SDL", "SDL: Couldn't locate Java callbacks, check that they're named and typed correctly");
|
__android_log_print(ANDROID_LOG_WARN, "SDL", "SDL: Couldn't locate Java callbacks, check that they're named and typed correctly");
|
||||||
}
|
}
|
||||||
|
|
||||||
fidSeparateMouseAndTouch = (*mEnv)->GetStaticFieldID(mEnv, mActivityClass, "mSeparateMouseAndTouch", "Z");
|
fidSeparateMouseAndTouch = (*mEnv)->GetStaticFieldID(mEnv, mActivityClass, "mSeparateMouseAndTouch", "Z");
|
||||||
|
|
||||||
if (!fidSeparateMouseAndTouch) {
|
if (!fidSeparateMouseAndTouch) {
|
||||||
__android_log_print(ANDROID_LOG_WARN, "SDL", "SDL: Couldn't locate Java static fields, check that they're named and typed correctly");
|
__android_log_print(ANDROID_LOG_WARN, "SDL", "SDL: Couldn't locate Java static fields, check that they're named and typed correctly");
|
||||||
}
|
}
|
||||||
|
@ -320,7 +346,7 @@ JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeHat)(
|
||||||
|
|
||||||
JNIEXPORT jint JNICALL SDL_JAVA_INTERFACE(nativeAddJoystick)(
|
JNIEXPORT jint JNICALL SDL_JAVA_INTERFACE(nativeAddJoystick)(
|
||||||
JNIEnv* env, jclass jcls,
|
JNIEnv* env, jclass jcls,
|
||||||
jint device_id, jstring device_name, jint is_accelerometer,
|
jint device_id, jstring device_name, jint is_accelerometer,
|
||||||
jint nbuttons, jint naxes, jint nhats, jint nballs)
|
jint nbuttons, jint naxes, jint nhats, jint nballs)
|
||||||
{
|
{
|
||||||
int retval;
|
int retval;
|
||||||
|
@ -329,7 +355,7 @@ JNIEXPORT jint JNICALL SDL_JAVA_INTERFACE(nativeAddJoystick)(
|
||||||
retval = Android_AddJoystick(device_id, name, (SDL_bool) is_accelerometer, nbuttons, naxes, nhats, nballs);
|
retval = Android_AddJoystick(device_id, name, (SDL_bool) is_accelerometer, nbuttons, naxes, nhats, nballs);
|
||||||
|
|
||||||
(*env)->ReleaseStringUTFChars(env, device_name, name);
|
(*env)->ReleaseStringUTFChars(env, device_name, name);
|
||||||
|
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -369,10 +395,10 @@ JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeSurfaceChanged)(JNIEnv* env, j
|
||||||
if (Android_Window == NULL || Android_Window->driverdata == NULL ) {
|
if (Android_Window == NULL || Android_Window->driverdata == NULL ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
_this = SDL_GetVideoDevice();
|
_this = SDL_GetVideoDevice();
|
||||||
data = (SDL_WindowData *) Android_Window->driverdata;
|
data = (SDL_WindowData *) Android_Window->driverdata;
|
||||||
|
|
||||||
/* If the surface has been previously destroyed by onNativeSurfaceDestroyed, recreate it here */
|
/* If the surface has been previously destroyed by onNativeSurfaceDestroyed, recreate it here */
|
||||||
if (data->egl_surface == EGL_NO_SURFACE) {
|
if (data->egl_surface == EGL_NO_SURFACE) {
|
||||||
if(data->native_window) {
|
if(data->native_window) {
|
||||||
|
@ -381,9 +407,9 @@ JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeSurfaceChanged)(JNIEnv* env, j
|
||||||
data->native_window = Android_JNI_GetNativeWindow();
|
data->native_window = Android_JNI_GetNativeWindow();
|
||||||
data->egl_surface = SDL_EGL_CreateSurface(_this, (NativeWindowType) data->native_window);
|
data->egl_surface = SDL_EGL_CreateSurface(_this, (NativeWindowType) data->native_window);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* GL Context handling is done in the event loop because this function is run from the Java thread */
|
/* GL Context handling is done in the event loop because this function is run from the Java thread */
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Surface Destroyed */
|
/* Surface Destroyed */
|
||||||
|
@ -395,20 +421,20 @@ JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeSurfaceDestroyed)(JNIEnv* env,
|
||||||
*/
|
*/
|
||||||
SDL_WindowData *data;
|
SDL_WindowData *data;
|
||||||
SDL_VideoDevice *_this;
|
SDL_VideoDevice *_this;
|
||||||
|
|
||||||
if (Android_Window == NULL || Android_Window->driverdata == NULL ) {
|
if (Android_Window == NULL || Android_Window->driverdata == NULL ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
_this = SDL_GetVideoDevice();
|
_this = SDL_GetVideoDevice();
|
||||||
data = (SDL_WindowData *) Android_Window->driverdata;
|
data = (SDL_WindowData *) Android_Window->driverdata;
|
||||||
|
|
||||||
if (data->egl_surface != EGL_NO_SURFACE) {
|
if (data->egl_surface != EGL_NO_SURFACE) {
|
||||||
SDL_EGL_MakeCurrent(_this, NULL, NULL);
|
SDL_EGL_MakeCurrent(_this, NULL, NULL);
|
||||||
SDL_EGL_DestroySurface(_this, data->egl_surface);
|
SDL_EGL_DestroySurface(_this, data->egl_surface);
|
||||||
data->egl_surface = EGL_NO_SURFACE;
|
data->egl_surface = EGL_NO_SURFACE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* GL Context handling is done in the event loop because this function is run from the Java thread */
|
/* GL Context handling is done in the event loop because this function is run from the Java thread */
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -499,8 +525,8 @@ JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativePause)(
|
||||||
SDL_SendWindowEvent(Android_Window, SDL_WINDOWEVENT_MINIMIZED, 0, 0);
|
SDL_SendWindowEvent(Android_Window, SDL_WINDOWEVENT_MINIMIZED, 0, 0);
|
||||||
SDL_SendAppEvent(SDL_APP_WILLENTERBACKGROUND);
|
SDL_SendAppEvent(SDL_APP_WILLENTERBACKGROUND);
|
||||||
SDL_SendAppEvent(SDL_APP_DIDENTERBACKGROUND);
|
SDL_SendAppEvent(SDL_APP_DIDENTERBACKGROUND);
|
||||||
|
|
||||||
/* *After* sending the relevant events, signal the pause semaphore
|
/* *After* sending the relevant events, signal the pause semaphore
|
||||||
* so the event loop knows to pause and (optionally) block itself */
|
* so the event loop knows to pause and (optionally) block itself */
|
||||||
if (!SDL_SemValue(Android_PauseSem)) SDL_SemPost(Android_PauseSem);
|
if (!SDL_SemValue(Android_PauseSem)) SDL_SemPost(Android_PauseSem);
|
||||||
}
|
}
|
||||||
|
@ -620,32 +646,26 @@ ANativeWindow* Android_JNI_GetNativeWindow(void)
|
||||||
s = (*env)->CallStaticObjectMethod(env, mActivityClass, midGetNativeSurface);
|
s = (*env)->CallStaticObjectMethod(env, mActivityClass, midGetNativeSurface);
|
||||||
anw = ANativeWindow_fromSurface(env, s);
|
anw = ANativeWindow_fromSurface(env, s);
|
||||||
(*env)->DeleteLocalRef(env, s);
|
(*env)->DeleteLocalRef(env, s);
|
||||||
|
|
||||||
return anw;
|
return anw;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Android_JNI_SetActivityTitle(const char *title)
|
void Android_JNI_SetActivityTitle(const char *title)
|
||||||
{
|
{
|
||||||
jmethodID mid;
|
|
||||||
JNIEnv *mEnv = Android_JNI_GetEnv();
|
JNIEnv *mEnv = Android_JNI_GetEnv();
|
||||||
mid = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass,"setActivityTitle","(Ljava/lang/String;)Z");
|
|
||||||
if (mid) {
|
jstring jtitle = (jstring)((*mEnv)->NewStringUTF(mEnv, title));
|
||||||
jstring jtitle = (jstring)((*mEnv)->NewStringUTF(mEnv, title));
|
(*mEnv)->CallStaticBooleanMethod(mEnv, mActivityClass, midSetActivityTitle, jtitle);
|
||||||
(*mEnv)->CallStaticBooleanMethod(mEnv, mActivityClass, mid, jtitle);
|
(*mEnv)->DeleteLocalRef(mEnv, jtitle);
|
||||||
(*mEnv)->DeleteLocalRef(mEnv, jtitle);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Android_JNI_SetOrientation(int w, int h, int resizable, const char *hint)
|
void Android_JNI_SetOrientation(int w, int h, int resizable, const char *hint)
|
||||||
{
|
{
|
||||||
jmethodID mid;
|
|
||||||
JNIEnv *mEnv = Android_JNI_GetEnv();
|
JNIEnv *mEnv = Android_JNI_GetEnv();
|
||||||
mid = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass,"setOrientation","(IIZLjava/lang/String;)V");
|
|
||||||
if (mid) {
|
jstring jhint = (jstring)((*mEnv)->NewStringUTF(mEnv, (hint ? hint : "")));
|
||||||
jstring jhint = (jstring)((*mEnv)->NewStringUTF(mEnv, (hint ? hint : "")));
|
(*mEnv)->CallStaticVoidMethod(mEnv, mActivityClass, midSetOrientation, w, h, (resizable? 1 : 0), jhint);
|
||||||
(*mEnv)->CallStaticVoidMethod(mEnv, mActivityClass, mid, w, h, (resizable? 1 : 0), jhint);
|
(*mEnv)->DeleteLocalRef(mEnv, jhint);
|
||||||
(*mEnv)->DeleteLocalRef(mEnv, jhint);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_bool Android_JNI_GetAccelerometerValues(float values[3])
|
SDL_bool Android_JNI_GetAccelerometerValues(float values[3])
|
||||||
|
@ -859,7 +879,7 @@ int Android_JNI_CaptureAudioBuffer(void *buffer, int buflen)
|
||||||
void Android_JNI_FlushCapturedAudio(void)
|
void Android_JNI_FlushCapturedAudio(void)
|
||||||
{
|
{
|
||||||
JNIEnv *env = Android_JNI_GetEnv();
|
JNIEnv *env = Android_JNI_GetEnv();
|
||||||
#if 0 /* !!! FIXME: this needs API 23, or it'll do blocking reads and never end. */
|
#if 0 /* !!! FIXME: this needs API 23, or it'll do blocking reads and never end. */
|
||||||
if (captureBuffer16Bit) {
|
if (captureBuffer16Bit) {
|
||||||
const jint len = (*env)->GetArrayLength(env, (jshortArray)captureBuffer);
|
const jint len = (*env)->GetArrayLength(env, (jshortArray)captureBuffer);
|
||||||
while ((*env)->CallStaticIntMethod(env, mActivityClass, midCaptureReadShortBuffer, (jshortArray)captureBuffer, JNI_FALSE) == len) { /* spin */ }
|
while ((*env)->CallStaticIntMethod(env, mActivityClass, midCaptureReadShortBuffer, (jshortArray)captureBuffer, JNI_FALSE) == len) { /* spin */ }
|
||||||
|
@ -867,13 +887,13 @@ void Android_JNI_FlushCapturedAudio(void)
|
||||||
const jint len = (*env)->GetArrayLength(env, (jbyteArray)captureBuffer);
|
const jint len = (*env)->GetArrayLength(env, (jbyteArray)captureBuffer);
|
||||||
while ((*env)->CallStaticIntMethod(env, mActivityClass, midCaptureReadByteBuffer, (jbyteArray)captureBuffer, JNI_FALSE) == len) { /* spin */ }
|
while ((*env)->CallStaticIntMethod(env, mActivityClass, midCaptureReadByteBuffer, (jbyteArray)captureBuffer, JNI_FALSE) == len) { /* spin */ }
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
if (captureBuffer16Bit) {
|
if (captureBuffer16Bit) {
|
||||||
(*env)->CallStaticIntMethod(env, mActivityClass, midCaptureReadShortBuffer, (jshortArray)captureBuffer, JNI_FALSE);
|
(*env)->CallStaticIntMethod(env, mActivityClass, midCaptureReadShortBuffer, (jshortArray)captureBuffer, JNI_FALSE);
|
||||||
} else {
|
} else {
|
||||||
(*env)->CallStaticIntMethod(env, mActivityClass, midCaptureReadByteBuffer, (jbyteArray)captureBuffer, JNI_FALSE);
|
(*env)->CallStaticIntMethod(env, mActivityClass, midCaptureReadByteBuffer, (jbyteArray)captureBuffer, JNI_FALSE);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void Android_JNI_CloseAudioDevice(const int iscapture)
|
void Android_JNI_CloseAudioDevice(const int iscapture)
|
||||||
|
@ -969,10 +989,7 @@ static int Internal_Android_JNI_FileOpen(SDL_RWops* ctx)
|
||||||
ctx->hidden.androidio.position = 0;
|
ctx->hidden.androidio.position = 0;
|
||||||
|
|
||||||
/* context = SDLActivity.getContext(); */
|
/* context = SDLActivity.getContext(); */
|
||||||
mid = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass,
|
context = (*mEnv)->CallStaticObjectMethod(mEnv, mActivityClass, midGetContext);
|
||||||
"getContext","()Landroid/content/Context;");
|
|
||||||
context = (*mEnv)->CallStaticObjectMethod(mEnv, mActivityClass, mid);
|
|
||||||
|
|
||||||
|
|
||||||
/* assetManager = context.getAssets(); */
|
/* assetManager = context.getAssets(); */
|
||||||
mid = (*mEnv)->GetMethodID(mEnv, (*mEnv)->GetObjectClass(mEnv, context),
|
mid = (*mEnv)->GetMethodID(mEnv, (*mEnv)->GetObjectClass(mEnv, context),
|
||||||
|
@ -1048,7 +1065,7 @@ fallback:
|
||||||
* android/apis/content/ReadAsset.java imply that Android's
|
* android/apis/content/ReadAsset.java imply that Android's
|
||||||
* AssetInputStream.available() /will/ always return the total file size
|
* AssetInputStream.available() /will/ always return the total file size
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* size = inputStream.available(); */
|
/* size = inputStream.available(); */
|
||||||
mid = (*mEnv)->GetMethodID(mEnv, (*mEnv)->GetObjectClass(mEnv, inputStream),
|
mid = (*mEnv)->GetMethodID(mEnv, (*mEnv)->GetObjectClass(mEnv, inputStream),
|
||||||
"available", "()I");
|
"available", "()I");
|
||||||
|
@ -1096,7 +1113,7 @@ failure:
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
LocalReferenceHolder_Cleanup(&refs);
|
LocalReferenceHolder_Cleanup(&refs);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -1110,7 +1127,7 @@ int Android_JNI_FileOpen(SDL_RWops* ctx,
|
||||||
jstring fileNameJString;
|
jstring fileNameJString;
|
||||||
|
|
||||||
if (!LocalReferenceHolder_Init(&refs, mEnv)) {
|
if (!LocalReferenceHolder_Init(&refs, mEnv)) {
|
||||||
LocalReferenceHolder_Cleanup(&refs);
|
LocalReferenceHolder_Cleanup(&refs);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1164,7 +1181,7 @@ size_t Android_JNI_FileRead(SDL_RWops* ctx, void* buffer,
|
||||||
|
|
||||||
mEnv = Android_JNI_GetEnv();
|
mEnv = Android_JNI_GetEnv();
|
||||||
if (!LocalReferenceHolder_Init(&refs, mEnv)) {
|
if (!LocalReferenceHolder_Init(&refs, mEnv)) {
|
||||||
LocalReferenceHolder_Cleanup(&refs);
|
LocalReferenceHolder_Cleanup(&refs);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1177,7 +1194,7 @@ size_t Android_JNI_FileRead(SDL_RWops* ctx, void* buffer,
|
||||||
int result = (*mEnv)->CallIntMethod(mEnv, readableByteChannel, readMethod, byteBuffer);
|
int result = (*mEnv)->CallIntMethod(mEnv, readableByteChannel, readMethod, byteBuffer);
|
||||||
|
|
||||||
if (Android_JNI_ExceptionOccurred(SDL_FALSE)) {
|
if (Android_JNI_ExceptionOccurred(SDL_FALSE)) {
|
||||||
LocalReferenceHolder_Cleanup(&refs);
|
LocalReferenceHolder_Cleanup(&refs);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1189,7 +1206,7 @@ size_t Android_JNI_FileRead(SDL_RWops* ctx, void* buffer,
|
||||||
bytesRead += result;
|
bytesRead += result;
|
||||||
ctx->hidden.androidio.position += result;
|
ctx->hidden.androidio.position += result;
|
||||||
}
|
}
|
||||||
LocalReferenceHolder_Cleanup(&refs);
|
LocalReferenceHolder_Cleanup(&refs);
|
||||||
return bytesRead / size;
|
return bytesRead / size;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1353,7 +1370,6 @@ static jobject Android_JNI_GetSystemServiceObject(const char* name)
|
||||||
JNIEnv* env = Android_JNI_GetEnv();
|
JNIEnv* env = Android_JNI_GetEnv();
|
||||||
jobject retval = NULL;
|
jobject retval = NULL;
|
||||||
jstring service;
|
jstring service;
|
||||||
jmethodID mid;
|
|
||||||
jobject context;
|
jobject context;
|
||||||
jobject manager;
|
jobject manager;
|
||||||
|
|
||||||
|
@ -1364,11 +1380,10 @@ static jobject Android_JNI_GetSystemServiceObject(const char* name)
|
||||||
|
|
||||||
service = (*env)->NewStringUTF(env, name);
|
service = (*env)->NewStringUTF(env, name);
|
||||||
|
|
||||||
mid = (*env)->GetStaticMethodID(env, mActivityClass, "getContext", "()Landroid/content/Context;");
|
/* context = SDLActivity.getContext(); */
|
||||||
context = (*env)->CallStaticObjectMethod(env, mActivityClass, mid);
|
context = (*env)->CallStaticObjectMethod(env, mActivityClass, midGetContext);
|
||||||
|
|
||||||
mid = (*env)->GetMethodID(env, mActivityClass, "getSystemServiceFromUiThread", "(Ljava/lang/String;)Ljava/lang/Object;");
|
manager = (*env)->CallObjectMethod(env, context, midGetSystemServiceFromUiThread, service);
|
||||||
manager = (*env)->CallObjectMethod(env, context, mid, service);
|
|
||||||
|
|
||||||
(*env)->DeleteLocalRef(env, service);
|
(*env)->DeleteLocalRef(env, service);
|
||||||
|
|
||||||
|
@ -1438,7 +1453,7 @@ char* Android_JNI_GetClipboardText(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
CLEANUP_CLIPBOARD();
|
CLEANUP_CLIPBOARD();
|
||||||
|
|
||||||
return SDL_strdup("");
|
return SDL_strdup("");
|
||||||
}
|
}
|
||||||
|
@ -1455,7 +1470,7 @@ SDL_bool Android_JNI_HasClipboardText(void)
|
||||||
(*env)->DeleteGlobalRef(env, clipboard);
|
(*env)->DeleteGlobalRef(env, clipboard);
|
||||||
|
|
||||||
CLEANUP_CLIPBOARD();
|
CLEANUP_CLIPBOARD();
|
||||||
|
|
||||||
return has ? SDL_TRUE : SDL_FALSE;
|
return has ? SDL_TRUE : SDL_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1484,8 +1499,8 @@ int Android_JNI_GetPowerInfo(int* plugged, int* charged, int* battery, int* seco
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
mid = (*env)->GetStaticMethodID(env, mActivityClass, "getContext", "()Landroid/content/Context;");
|
/* context = SDLActivity.getContext(); */
|
||||||
context = (*env)->CallStaticObjectMethod(env, mActivityClass, mid);
|
context = (*env)->CallStaticObjectMethod(env, mActivityClass, midGetContext);
|
||||||
|
|
||||||
action = (*env)->NewStringUTF(env, "android.intent.action.BATTERY_CHANGED");
|
action = (*env)->NewStringUTF(env, "android.intent.action.BATTERY_CHANGED");
|
||||||
|
|
||||||
|
@ -1556,7 +1571,7 @@ int Android_JNI_GetPowerInfo(int* plugged, int* charged, int* battery, int* seco
|
||||||
if (percent) {
|
if (percent) {
|
||||||
int level;
|
int level;
|
||||||
int scale;
|
int scale;
|
||||||
|
|
||||||
/* Watch out for C89 scoping rules because of the macro */
|
/* Watch out for C89 scoping rules because of the macro */
|
||||||
{
|
{
|
||||||
GET_INT_EXTRA(level_temp, "level") /* == BatteryManager.EXTRA_LEVEL (API 5) */
|
GET_INT_EXTRA(level_temp, "level") /* == BatteryManager.EXTRA_LEVEL (API 5) */
|
||||||
|
@ -1567,7 +1582,7 @@ int Android_JNI_GetPowerInfo(int* plugged, int* charged, int* battery, int* seco
|
||||||
GET_INT_EXTRA(scale_temp, "scale") /* == BatteryManager.EXTRA_SCALE (API 5) */
|
GET_INT_EXTRA(scale_temp, "scale") /* == BatteryManager.EXTRA_SCALE (API 5) */
|
||||||
scale = scale_temp;
|
scale = scale_temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((level == -1) || (scale == -1)) {
|
if ((level == -1) || (scale == -1)) {
|
||||||
LocalReferenceHolder_Cleanup(&refs);
|
LocalReferenceHolder_Cleanup(&refs);
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -1585,8 +1600,7 @@ int Android_JNI_GetPowerInfo(int* plugged, int* charged, int* battery, int* seco
|
||||||
int Android_JNI_GetTouchDeviceIds(int **ids) {
|
int Android_JNI_GetTouchDeviceIds(int **ids) {
|
||||||
JNIEnv *env = Android_JNI_GetEnv();
|
JNIEnv *env = Android_JNI_GetEnv();
|
||||||
jint sources = 4098; /* == InputDevice.SOURCE_TOUCHSCREEN */
|
jint sources = 4098; /* == InputDevice.SOURCE_TOUCHSCREEN */
|
||||||
jmethodID mid = (*env)->GetStaticMethodID(env, mActivityClass, "inputGetInputDeviceIds", "(I)[I");
|
jintArray array = (jintArray) (*env)->CallStaticObjectMethod(env, mActivityClass, midInputGetInputDeviceIds, sources);
|
||||||
jintArray array = (jintArray) (*env)->CallStaticObjectMethod(env, mActivityClass, mid, sources);
|
|
||||||
int number = 0;
|
int number = 0;
|
||||||
*ids = NULL;
|
*ids = NULL;
|
||||||
if (array) {
|
if (array) {
|
||||||
|
@ -1617,7 +1631,7 @@ void Android_JNI_SetSeparateMouseAndTouch(SDL_bool new_value)
|
||||||
void Android_JNI_PollInputDevices(void)
|
void Android_JNI_PollInputDevices(void)
|
||||||
{
|
{
|
||||||
JNIEnv *env = Android_JNI_GetEnv();
|
JNIEnv *env = Android_JNI_GetEnv();
|
||||||
(*env)->CallStaticVoidMethod(env, mActivityClass, midPollInputDevices);
|
(*env)->CallStaticVoidMethod(env, mActivityClass, midPollInputDevices);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Android_JNI_PollHapticDevices(void)
|
void Android_JNI_PollHapticDevices(void)
|
||||||
|
@ -1625,7 +1639,7 @@ void Android_JNI_PollHapticDevices(void)
|
||||||
JNIEnv *env = Android_JNI_GetEnv();
|
JNIEnv *env = Android_JNI_GetEnv();
|
||||||
(*env)->CallStaticVoidMethod(env, mActivityClass, midPollHapticDevices);
|
(*env)->CallStaticVoidMethod(env, mActivityClass, midPollHapticDevices);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Android_JNI_HapticRun(int device_id, int length)
|
void Android_JNI_HapticRun(int device_id, int length)
|
||||||
{
|
{
|
||||||
JNIEnv *env = Android_JNI_GetEnv();
|
JNIEnv *env = Android_JNI_GetEnv();
|
||||||
|
@ -1640,16 +1654,8 @@ void Android_JNI_HapticRun(int device_id, int length)
|
||||||
int Android_JNI_SendMessage(int command, int param)
|
int Android_JNI_SendMessage(int command, int param)
|
||||||
{
|
{
|
||||||
JNIEnv *env = Android_JNI_GetEnv();
|
JNIEnv *env = Android_JNI_GetEnv();
|
||||||
jmethodID mid;
|
|
||||||
jboolean success;
|
jboolean success;
|
||||||
if (!env) {
|
success = (*env)->CallStaticBooleanMethod(env, mActivityClass, midSendMessage, command, param);
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
mid = (*env)->GetStaticMethodID(env, mActivityClass, "sendMessage", "(II)Z");
|
|
||||||
if (!mid) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
success = (*env)->CallStaticBooleanMethod(env, mActivityClass, mid, command, param);
|
|
||||||
return success ? 0 : -1;
|
return success ? 0 : -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1661,16 +1667,7 @@ void Android_JNI_SuspendScreenSaver(SDL_bool suspend)
|
||||||
void Android_JNI_ShowTextInput(SDL_Rect *inputRect)
|
void Android_JNI_ShowTextInput(SDL_Rect *inputRect)
|
||||||
{
|
{
|
||||||
JNIEnv *env = Android_JNI_GetEnv();
|
JNIEnv *env = Android_JNI_GetEnv();
|
||||||
jmethodID mid;
|
(*env)->CallStaticBooleanMethod(env, mActivityClass, midShowTextInput,
|
||||||
if (!env) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
mid = (*env)->GetStaticMethodID(env, mActivityClass, "showTextInput", "(IIII)Z");
|
|
||||||
if (!mid) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
(*env)->CallStaticBooleanMethod(env, mActivityClass, mid,
|
|
||||||
inputRect->x,
|
inputRect->x,
|
||||||
inputRect->y,
|
inputRect->y,
|
||||||
inputRect->w,
|
inputRect->w,
|
||||||
|
@ -1686,14 +1683,9 @@ void Android_JNI_HideTextInput(void)
|
||||||
|
|
||||||
SDL_bool Android_JNI_IsScreenKeyboardShown()
|
SDL_bool Android_JNI_IsScreenKeyboardShown()
|
||||||
{
|
{
|
||||||
jmethodID mid;
|
|
||||||
jboolean is_shown = 0;
|
|
||||||
JNIEnv *mEnv = Android_JNI_GetEnv();
|
JNIEnv *mEnv = Android_JNI_GetEnv();
|
||||||
mid = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass,"isScreenKeyboardShown","()Z");
|
jboolean is_shown = 0;
|
||||||
if (mid) {
|
is_shown = (*mEnv)->CallStaticBooleanMethod(mEnv, mActivityClass, midIsScreenKeyboardShown);
|
||||||
is_shown = (*mEnv)->CallStaticBooleanMethod(mEnv, mActivityClass, mid);
|
|
||||||
}
|
|
||||||
|
|
||||||
return is_shown;
|
return is_shown;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1752,11 +1744,8 @@ int Android_JNI_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *bu
|
||||||
|
|
||||||
(*env)->DeleteLocalRef(env, clazz);
|
(*env)->DeleteLocalRef(env, clazz);
|
||||||
|
|
||||||
/* call function */
|
/* context = SDLActivity.getContext(); */
|
||||||
|
context = (*env)->CallStaticObjectMethod(env, mActivityClass, midGetContext);
|
||||||
mid = (*env)->GetStaticMethodID(env, mActivityClass, "getContext","()Landroid/content/Context;");
|
|
||||||
|
|
||||||
context = (*env)->CallStaticObjectMethod(env, mActivityClass, mid);
|
|
||||||
|
|
||||||
clazz = (*env)->GetObjectClass(env, context);
|
clazz = (*env)->GetObjectClass(env, context);
|
||||||
|
|
||||||
|
@ -1802,17 +1791,13 @@ void *SDL_AndroidGetActivity(void)
|
||||||
{
|
{
|
||||||
/* See SDL_system.h for caveats on using this function. */
|
/* See SDL_system.h for caveats on using this function. */
|
||||||
|
|
||||||
jmethodID mid;
|
|
||||||
|
|
||||||
JNIEnv *env = Android_JNI_GetEnv();
|
JNIEnv *env = Android_JNI_GetEnv();
|
||||||
if (!env) {
|
if (!env) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* return SDLActivity.getContext(); */
|
/* return SDLActivity.getContext(); */
|
||||||
mid = (*env)->GetStaticMethodID(env, mActivityClass,
|
return (*env)->CallStaticObjectMethod(env, mActivityClass, midGetContext);
|
||||||
"getContext","()Landroid/content/Context;");
|
|
||||||
return (*env)->CallStaticObjectMethod(env, mActivityClass, mid);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const char * SDL_AndroidGetInternalStoragePath(void)
|
const char * SDL_AndroidGetInternalStoragePath(void)
|
||||||
|
@ -1834,9 +1819,7 @@ const char * SDL_AndroidGetInternalStoragePath(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* context = SDLActivity.getContext(); */
|
/* context = SDLActivity.getContext(); */
|
||||||
mid = (*env)->GetStaticMethodID(env, mActivityClass,
|
context = (*env)->CallStaticObjectMethod(env, mActivityClass, midGetContext);
|
||||||
"getContext","()Landroid/content/Context;");
|
|
||||||
context = (*env)->CallStaticObjectMethod(env, mActivityClass, mid);
|
|
||||||
|
|
||||||
/* fileObj = context.getFilesDir(); */
|
/* fileObj = context.getFilesDir(); */
|
||||||
mid = (*env)->GetMethodID(env, (*env)->GetObjectClass(env, context),
|
mid = (*env)->GetMethodID(env, (*env)->GetObjectClass(env, context),
|
||||||
|
@ -1920,9 +1903,7 @@ const char * SDL_AndroidGetExternalStoragePath(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* context = SDLActivity.getContext(); */
|
/* context = SDLActivity.getContext(); */
|
||||||
mid = (*env)->GetStaticMethodID(env, mActivityClass,
|
context = (*env)->CallStaticObjectMethod(env, mActivityClass, midGetContext);
|
||||||
"getContext","()Landroid/content/Context;");
|
|
||||||
context = (*env)->CallStaticObjectMethod(env, mActivityClass, mid);
|
|
||||||
|
|
||||||
/* fileObj = context.getExternalFilesDir(); */
|
/* fileObj = context.getExternalFilesDir(); */
|
||||||
mid = (*env)->GetMethodID(env, (*env)->GetObjectClass(env, context),
|
mid = (*env)->GetMethodID(env, (*env)->GetObjectClass(env, context),
|
||||||
|
|
Loading…
Reference in New Issue