Bug 2739 - [Android] No support for SDL_DisableScreenSaver by Martin Gerhardy
authorGabriel Jacobo <gabomdq@gmail.com>
Mon, 20 Oct 2014 10:10:39 -0300
changeset 9173 c677ab1148c5
parent 9172 985481d7f3a1
child 9174 f9244b2a1511
Bug 2739 - [Android] No support for SDL_DisableScreenSaver by Martin Gerhardy
android-project/src/org/libsdl/app/SDLActivity.java
src/core/android/SDL_android.c
src/core/android/SDL_android.h
src/video/android/SDL_androidvideo.c
--- a/android-project/src/org/libsdl/app/SDLActivity.java	Fri Oct 17 23:36:45 2014 +0200
+++ b/android-project/src/org/libsdl/app/SDLActivity.java	Mon Oct 20 10:10:39 2014 -0300
@@ -187,6 +187,13 @@
         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
      *  is the first to be called, mIsSurfaceReady should still be set
      *  to 'true' during the call to onPause (in a usual scenario).
--- a/src/core/android/SDL_android.c	Fri Oct 17 23:36:45 2014 +0200
+++ b/src/core/android/SDL_android.c	Mon Oct 20 10:10:39 2014 -0300
@@ -77,6 +77,7 @@
 static jmethodID midAudioWriteByteBuffer;
 static jmethodID midAudioQuit;
 static jmethodID midPollInputDevices;
+static jmethodID midSuspendScreenSaver;
 
 /* Accelerometer data storage */
 static float fLastAccelerometer[3];
@@ -131,6 +132,8 @@
                                 "audioQuit", "()V");
     midPollInputDevices = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass,
                                 "pollInputDevices", "()V");
+    midSuspendScreenSaver = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass,
+                                "suspendScreenSaver", "(Z)V");
 
     bHasNewData = false;
 
@@ -444,7 +447,13 @@
 
 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)
--- a/src/core/android/SDL_android.h	Fri Oct 17 23:36:45 2014 +0200
+++ b/src/core/android/SDL_android.h	Mon Oct 20 10:10:39 2014 -0300
@@ -68,6 +68,8 @@
 /* Joystick support */
 void Android_JNI_PollInputDevices();
 
+/* Video */
+void Android_JNI_SuspendScreenSaver(SDL_bool suspend);
 
 /* Touch support */
 int Android_JNI_GetTouchDeviceIds(int **ids);
--- a/src/video/android/SDL_androidvideo.c	Fri Oct 17 23:36:45 2014 +0200
+++ b/src/video/android/SDL_androidvideo.c	Mon Oct 20 10:10:39 2014 -0300
@@ -76,6 +76,12 @@
 }
 
 static void
+Android_SuspendScreenSaver(_THIS)
+{
+    Android_JNI_SuspendScreenSaver(_this->suspend_screensaver);
+}
+
+static void
 Android_DeleteDevice(SDL_VideoDevice * device)
 {
     SDL_free(device);
@@ -126,6 +132,9 @@
     device->GL_SwapWindow = Android_GLES_SwapWindow;
     device->GL_DeleteContext = Android_GLES_DeleteContext;
 
+    /* Screensaver */
+    device->SuspendScreenSaver = Android_SuspendScreenSaver;
+
     /* Text input */
     device->StartTextInput = Android_StartTextInput;
     device->StopTextInput = Android_StopTextInput;