Android: add MinimizeWindow function (Bug 4580, 4657)
authorSylvain Becker <sylvain.becker@gmail.com>
Mon, 10 Jun 2019 21:58:03 +0200
changeset 12823f7629f5761d8
parent 12822 559c2b342450
child 12824 2f882d435abf
Android: add MinimizeWindow function (Bug 4580, 4657)
shouldMinimizeOnFocusLoss is un-activated (return false)
android-project/app/src/main/java/org/libsdl/app/SDLActivity.java
src/core/android/SDL_android.c
src/core/android/SDL_android.h
src/video/SDL_video.c
src/video/android/SDL_androidvideo.c
src/video/android/SDL_androidwindow.c
src/video/android/SDL_androidwindow.h
     1.1 --- a/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java	Mon Jun 10 21:41:22 2019 +0200
     1.2 +++ b/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java	Mon Jun 10 21:58:03 2019 +0200
     1.3 @@ -849,6 +849,45 @@
     1.4      /**
     1.5       * This method is called by SDL using JNI.
     1.6       */
     1.7 +    public static void minimizeWindow() {
     1.8 +
     1.9 +        if (mSingleton == null) {
    1.10 +            return;
    1.11 +        }
    1.12 +
    1.13 +        Intent startMain = new Intent(Intent.ACTION_MAIN);
    1.14 +        startMain.addCategory(Intent.CATEGORY_HOME);
    1.15 +        startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    1.16 +        mSingleton.startActivity(startMain);
    1.17 +    }
    1.18 +
    1.19 +    /**
    1.20 +     * This method is called by SDL using JNI.
    1.21 +     */
    1.22 +    public static boolean shouldMinimizeOnFocusLoss() {
    1.23 +/*
    1.24 +        if (Build.VERSION.SDK_INT >= 24) {
    1.25 +            if (mSingleton == null) {
    1.26 +                return true;
    1.27 +            }
    1.28 +
    1.29 +            if (mSingleton.isInMultiWindowMode()) {
    1.30 +                return false;
    1.31 +            }
    1.32 +
    1.33 +            if (mSingleton.isInPictureInPictureMode()) {
    1.34 +                return false;
    1.35 +            }
    1.36 +        }
    1.37 +
    1.38 +        return true;
    1.39 +*/
    1.40 +        return false;
    1.41 +    }
    1.42 +
    1.43 +    /**
    1.44 +     * This method is called by SDL using JNI.
    1.45 +     */
    1.46      public static boolean isScreenKeyboardShown()
    1.47      {
    1.48          if (mTextEdit == null) {
     2.1 --- a/src/core/android/SDL_android.c	Mon Jun 10 21:41:22 2019 +0200
     2.2 +++ b/src/core/android/SDL_android.c	Mon Jun 10 21:58:03 2019 +0200
     2.3 @@ -240,6 +240,8 @@
     2.4  static jmethodID midSetActivityTitle;
     2.5  static jmethodID midSetWindowStyle;
     2.6  static jmethodID midSetOrientation;
     2.7 +static jmethodID midMinimizeWindow;
     2.8 +static jmethodID midShouldMinimizeOnFocusLoss;
     2.9  static jmethodID midGetContext;
    2.10  static jmethodID midIsTablet;
    2.11  static jmethodID midIsAndroidTV;
    2.12 @@ -490,6 +492,10 @@
    2.13                                  "setWindowStyle","(Z)V");
    2.14      midSetOrientation = (*env)->GetStaticMethodID(env, mActivityClass,
    2.15                                  "setOrientation","(IIZLjava/lang/String;)V");
    2.16 +    midMinimizeWindow = (*env)->GetStaticMethodID(env, mActivityClass,
    2.17 +                                "minimizeWindow","()V");
    2.18 +    midShouldMinimizeOnFocusLoss = (*env)->GetStaticMethodID(env, mActivityClass,
    2.19 +                                "shouldMinimizeOnFocusLoss","()Z");
    2.20      midGetContext = (*env)->GetStaticMethodID(env, mActivityClass,
    2.21                                  "getContext","()Landroid/content/Context;");
    2.22      midIsTablet = (*env)->GetStaticMethodID(env, mActivityClass,
    2.23 @@ -532,7 +538,7 @@
    2.24  
    2.25  
    2.26      if (!midGetNativeSurface || !midSetSurfaceViewFormat ||
    2.27 -       !midSetActivityTitle || !midSetWindowStyle || !midSetOrientation || !midGetContext || !midIsTablet || !midIsAndroidTV || !midInitTouch ||
    2.28 +       !midSetActivityTitle || !midSetWindowStyle || !midSetOrientation || !midMinimizeWindow || !midShouldMinimizeOnFocusLoss || !midGetContext || !midIsTablet || !midIsAndroidTV || !midInitTouch ||
    2.29         !midSendMessage || !midShowTextInput || !midIsScreenKeyboardShown ||
    2.30         !midClipboardSetText || !midClipboardGetText || !midClipboardHasText ||
    2.31         !midOpenAPKExpansionInputStream || !midGetManifestEnvironmentVariables || !midGetDisplayDPI ||
    2.32 @@ -1285,6 +1291,18 @@
    2.33      (*env)->DeleteLocalRef(env, jhint);
    2.34  }
    2.35  
    2.36 +void Android_JNI_MinizeWindow()
    2.37 +{
    2.38 +    JNIEnv *env = Android_JNI_GetEnv();
    2.39 +    (*env)->CallStaticVoidMethod(env, mActivityClass, midMinimizeWindow);
    2.40 +}
    2.41 +
    2.42 +SDL_bool Android_JNI_ShouldMinimizeOnFocusLoss()
    2.43 +{
    2.44 +    JNIEnv *env = Android_JNI_GetEnv();
    2.45 +    return (*env)->CallStaticBooleanMethod(env, mActivityClass, midShouldMinimizeOnFocusLoss);
    2.46 +}
    2.47 +
    2.48  SDL_bool Android_JNI_GetAccelerometerValues(float values[3])
    2.49  {
    2.50      int i;
     3.1 --- a/src/core/android/SDL_android.h	Mon Jun 10 21:41:22 2019 +0200
     3.2 +++ b/src/core/android/SDL_android.h	Mon Jun 10 21:58:03 2019 +0200
     3.3 @@ -39,6 +39,8 @@
     3.4  extern void Android_JNI_SetActivityTitle(const char *title);
     3.5  extern void Android_JNI_SetWindowStyle(SDL_bool fullscreen);
     3.6  extern void Android_JNI_SetOrientation(int w, int h, int resizable, const char *hint);
     3.7 +extern void Android_JNI_MinizeWindow(void);
     3.8 +extern SDL_bool Android_JNI_ShouldMinimizeOnFocusLoss(void);
     3.9  
    3.10  extern SDL_bool Android_JNI_GetAccelerometerValues(float values[3]);
    3.11  extern void Android_JNI_ShowTextInput(SDL_Rect *inputRect);
     4.1 --- a/src/video/SDL_video.c	Mon Jun 10 21:41:22 2019 +0200
     4.2 +++ b/src/video/SDL_video.c	Mon Jun 10 21:58:03 2019 +0200
     4.3 @@ -2664,6 +2664,15 @@
     4.4      }
     4.5  #endif
     4.6  
     4.7 +#ifdef __ANDROID__
     4.8 +    {
     4.9 +        extern SDL_bool Android_JNI_ShouldMinimizeOnFocusLoss(void);
    4.10 +        if (! Android_JNI_ShouldMinimizeOnFocusLoss()) {
    4.11 +            return SDL_FALSE;
    4.12 +        }
    4.13 +    }
    4.14 +#endif
    4.15 +
    4.16      return SDL_GetHintBoolean(SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS, SDL_TRUE);
    4.17  }
    4.18  
     5.1 --- a/src/video/android/SDL_androidvideo.c	Mon Jun 10 21:41:22 2019 +0200
     5.2 +++ b/src/video/android/SDL_androidvideo.c	Mon Jun 10 21:58:03 2019 +0200
     5.3 @@ -127,6 +127,7 @@
     5.4      device->CreateSDLWindow = Android_CreateWindow;
     5.5      device->SetWindowTitle = Android_SetWindowTitle;
     5.6      device->SetWindowFullscreen = Android_SetWindowFullscreen;
     5.7 +    device->MinimizeWindow = Android_MinimizeWindow;
     5.8      device->DestroyWindow = Android_DestroyWindow;
     5.9      device->GetWindowWMInfo = Android_GetWindowWMInfo;
    5.10  
     6.1 --- a/src/video/android/SDL_androidwindow.c	Mon Jun 10 21:41:22 2019 +0200
     6.2 +++ b/src/video/android/SDL_androidwindow.c	Mon Jun 10 21:58:03 2019 +0200
     6.3 @@ -161,6 +161,12 @@
     6.4  }
     6.5  
     6.6  void
     6.7 +Android_MinimizeWindow(_THIS, SDL_Window *window)
     6.8 +{
     6.9 +    Android_JNI_MinizeWindow();
    6.10 +}
    6.11 +
    6.12 +void
    6.13  Android_DestroyWindow(_THIS, SDL_Window *window)
    6.14  {
    6.15      SDL_LockMutex(Android_ActivityMutex);
     7.1 --- a/src/video/android/SDL_androidwindow.h	Mon Jun 10 21:41:22 2019 +0200
     7.2 +++ b/src/video/android/SDL_androidwindow.h	Mon Jun 10 21:58:03 2019 +0200
     7.3 @@ -29,6 +29,8 @@
     7.4  extern int Android_CreateWindow(_THIS, SDL_Window *window);
     7.5  extern void Android_SetWindowTitle(_THIS, SDL_Window *window);
     7.6  extern void Android_SetWindowFullscreen(_THIS, SDL_Window *window, SDL_VideoDisplay *display, SDL_bool fullscreen);
     7.7 +extern void Android_MinimizeWindow(_THIS, SDL_Window *window);
     7.8 +
     7.9  extern void Android_DestroyWindow(_THIS, SDL_Window *window);
    7.10  extern SDL_bool Android_GetWindowWMInfo(_THIS, SDL_Window *window, struct SDL_SysWMinfo *info);
    7.11  extern SDL_Window *Android_Window;