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 9173c677ab1148c5
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
     1.1 --- a/android-project/src/org/libsdl/app/SDLActivity.java	Fri Oct 17 23:36:45 2014 +0200
     1.2 +++ b/android-project/src/org/libsdl/app/SDLActivity.java	Mon Oct 20 10:10:39 2014 -0300
     1.3 @@ -187,6 +187,13 @@
     1.4          return super.dispatchKeyEvent(event);
     1.5      }
     1.6  
     1.7 +    public static void suspendScreenSaver(boolean suspend) {
     1.8 +        if (suspend)
     1.9 +            mSingleton.getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    1.10 +        else
    1.11 +            mSingleton.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    1.12 +    }
    1.13 +
    1.14      /** Called by onPause or surfaceDestroyed. Even if surfaceDestroyed
    1.15       *  is the first to be called, mIsSurfaceReady should still be set
    1.16       *  to 'true' during the call to onPause (in a usual scenario).
     2.1 --- a/src/core/android/SDL_android.c	Fri Oct 17 23:36:45 2014 +0200
     2.2 +++ b/src/core/android/SDL_android.c	Mon Oct 20 10:10:39 2014 -0300
     2.3 @@ -77,6 +77,7 @@
     2.4  static jmethodID midAudioWriteByteBuffer;
     2.5  static jmethodID midAudioQuit;
     2.6  static jmethodID midPollInputDevices;
     2.7 +static jmethodID midSuspendScreenSaver;
     2.8  
     2.9  /* Accelerometer data storage */
    2.10  static float fLastAccelerometer[3];
    2.11 @@ -131,6 +132,8 @@
    2.12                                  "audioQuit", "()V");
    2.13      midPollInputDevices = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass,
    2.14                                  "pollInputDevices", "()V");
    2.15 +    midSuspendScreenSaver = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass,
    2.16 +                                "suspendScreenSaver", "(Z)V");
    2.17  
    2.18      bHasNewData = false;
    2.19  
    2.20 @@ -444,7 +447,13 @@
    2.21  
    2.22  static SDL_bool LocalReferenceHolder_IsActive()
    2.23  {
    2.24 -    return s_active > 0;    
    2.25 +    return s_active > 0;
    2.26 +}
    2.27 +
    2.28 +void Android_JNI_SuspendScreenSaver(SDL_bool suspend)
    2.29 +{
    2.30 +    JNIEnv *env = Android_JNI_GetEnv();
    2.31 +    (*env)->CallStaticObjectMethod(env, mActivityClass, midSuspendScreenSaver, suspend);
    2.32  }
    2.33  
    2.34  ANativeWindow* Android_JNI_GetNativeWindow(void)
     3.1 --- a/src/core/android/SDL_android.h	Fri Oct 17 23:36:45 2014 +0200
     3.2 +++ b/src/core/android/SDL_android.h	Mon Oct 20 10:10:39 2014 -0300
     3.3 @@ -68,6 +68,8 @@
     3.4  /* Joystick support */
     3.5  void Android_JNI_PollInputDevices();
     3.6  
     3.7 +/* Video */
     3.8 +void Android_JNI_SuspendScreenSaver(SDL_bool suspend);
     3.9  
    3.10  /* Touch support */
    3.11  int Android_JNI_GetTouchDeviceIds(int **ids);
     4.1 --- a/src/video/android/SDL_androidvideo.c	Fri Oct 17 23:36:45 2014 +0200
     4.2 +++ b/src/video/android/SDL_androidvideo.c	Mon Oct 20 10:10:39 2014 -0300
     4.3 @@ -76,6 +76,12 @@
     4.4  }
     4.5  
     4.6  static void
     4.7 +Android_SuspendScreenSaver(_THIS)
     4.8 +{
     4.9 +    Android_JNI_SuspendScreenSaver(_this->suspend_screensaver);
    4.10 +}
    4.11 +
    4.12 +static void
    4.13  Android_DeleteDevice(SDL_VideoDevice * device)
    4.14  {
    4.15      SDL_free(device);
    4.16 @@ -126,6 +132,9 @@
    4.17      device->GL_SwapWindow = Android_GLES_SwapWindow;
    4.18      device->GL_DeleteContext = Android_GLES_DeleteContext;
    4.19  
    4.20 +    /* Screensaver */
    4.21 +    device->SuspendScreenSaver = Android_SuspendScreenSaver;
    4.22 +
    4.23      /* Text input */
    4.24      device->StartTextInput = Android_StartTextInput;
    4.25      device->StopTextInput = Android_StopTextInput;