Bug 2739 - [Android] No support for SDL_DisableScreenSaver by Martin Gerhardy

This commit is contained in:
Gabriel Jacobo 2014-10-20 10:10:39 -03:00
parent ec4dfdfc58
commit 79035b393a
4 changed files with 28 additions and 1 deletions

View File

@ -187,6 +187,13 @@ public class SDLActivity extends Activity {
return super.dispatchKeyEvent(event); return super.dispatchKeyEvent(event);
} }
public static void suspendScreenSaver(boolean suspend) {
if (suspend)
mSingleton.getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
else
mSingleton.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
}
/** Called by onPause or surfaceDestroyed. Even if surfaceDestroyed /** Called by onPause or surfaceDestroyed. Even if surfaceDestroyed
* is the first to be called, mIsSurfaceReady should still be set * is the first to be called, mIsSurfaceReady should still be set
* to 'true' during the call to onPause (in a usual scenario). * to 'true' during the call to onPause (in a usual scenario).

View File

@ -77,6 +77,7 @@ static jmethodID midAudioWriteShortBuffer;
static jmethodID midAudioWriteByteBuffer; static jmethodID midAudioWriteByteBuffer;
static jmethodID midAudioQuit; static jmethodID midAudioQuit;
static jmethodID midPollInputDevices; static jmethodID midPollInputDevices;
static jmethodID midSuspendScreenSaver;
/* Accelerometer data storage */ /* Accelerometer data storage */
static float fLastAccelerometer[3]; static float fLastAccelerometer[3];
@ -131,6 +132,8 @@ JNIEXPORT void JNICALL SDL_Android_Init(JNIEnv* mEnv, jclass cls)
"audioQuit", "()V"); "audioQuit", "()V");
midPollInputDevices = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass, midPollInputDevices = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass,
"pollInputDevices", "()V"); "pollInputDevices", "()V");
midSuspendScreenSaver = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass,
"suspendScreenSaver", "(Z)V");
bHasNewData = false; bHasNewData = false;
@ -444,7 +447,13 @@ static void LocalReferenceHolder_Cleanup(struct LocalReferenceHolder *refholder)
static SDL_bool LocalReferenceHolder_IsActive() static SDL_bool LocalReferenceHolder_IsActive()
{ {
return s_active > 0; return s_active > 0;
}
void Android_JNI_SuspendScreenSaver(SDL_bool suspend)
{
JNIEnv *env = Android_JNI_GetEnv();
(*env)->CallStaticObjectMethod(env, mActivityClass, midSuspendScreenSaver, suspend);
} }
ANativeWindow* Android_JNI_GetNativeWindow(void) ANativeWindow* Android_JNI_GetNativeWindow(void)

View File

@ -68,6 +68,8 @@ int Android_JNI_GetPowerInfo(int* plugged, int* charged, int* battery, int* seco
/* Joystick support */ /* Joystick support */
void Android_JNI_PollInputDevices(); void Android_JNI_PollInputDevices();
/* Video */
void Android_JNI_SuspendScreenSaver(SDL_bool suspend);
/* Touch support */ /* Touch support */
int Android_JNI_GetTouchDeviceIds(int **ids); int Android_JNI_GetTouchDeviceIds(int **ids);

View File

@ -75,6 +75,12 @@ Android_Available(void)
return 1; return 1;
} }
static void
Android_SuspendScreenSaver(_THIS)
{
Android_JNI_SuspendScreenSaver(_this->suspend_screensaver);
}
static void static void
Android_DeleteDevice(SDL_VideoDevice * device) Android_DeleteDevice(SDL_VideoDevice * device)
{ {
@ -126,6 +132,9 @@ Android_CreateDevice(int devindex)
device->GL_SwapWindow = Android_GLES_SwapWindow; device->GL_SwapWindow = Android_GLES_SwapWindow;
device->GL_DeleteContext = Android_GLES_DeleteContext; device->GL_DeleteContext = Android_GLES_DeleteContext;
/* Screensaver */
device->SuspendScreenSaver = Android_SuspendScreenSaver;
/* Text input */ /* Text input */
device->StartTextInput = Android_StartTextInput; device->StartTextInput = Android_StartTextInput;
device->StopTextInput = Android_StopTextInput; device->StopTextInput = Android_StopTextInput;