diff --git a/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java b/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java index 1c36f8603..2dbdef7f8 100644 --- a/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java +++ b/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java @@ -846,6 +846,45 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh } } + /** + * This method is called by SDL using JNI. + */ + public static void minimizeWindow() { + + if (mSingleton == null) { + return; + } + + Intent startMain = new Intent(Intent.ACTION_MAIN); + startMain.addCategory(Intent.CATEGORY_HOME); + startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + mSingleton.startActivity(startMain); + } + + /** + * This method is called by SDL using JNI. + */ + public static boolean shouldMinimizeOnFocusLoss() { +/* + if (Build.VERSION.SDK_INT >= 24) { + if (mSingleton == null) { + return true; + } + + if (mSingleton.isInMultiWindowMode()) { + return false; + } + + if (mSingleton.isInPictureInPictureMode()) { + return false; + } + } + + return true; +*/ + return false; + } + /** * This method is called by SDL using JNI. */ diff --git a/src/core/android/SDL_android.c b/src/core/android/SDL_android.c index c960a54be..a4a2e1ce0 100644 --- a/src/core/android/SDL_android.c +++ b/src/core/android/SDL_android.c @@ -240,6 +240,8 @@ static jmethodID midSetSurfaceViewFormat; static jmethodID midSetActivityTitle; static jmethodID midSetWindowStyle; static jmethodID midSetOrientation; +static jmethodID midMinimizeWindow; +static jmethodID midShouldMinimizeOnFocusLoss; static jmethodID midGetContext; static jmethodID midIsTablet; static jmethodID midIsAndroidTV; @@ -490,6 +492,10 @@ JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeSetupJNI)(JNIEnv *env, jclass cl "setWindowStyle","(Z)V"); midSetOrientation = (*env)->GetStaticMethodID(env, mActivityClass, "setOrientation","(IIZLjava/lang/String;)V"); + midMinimizeWindow = (*env)->GetStaticMethodID(env, mActivityClass, + "minimizeWindow","()V"); + midShouldMinimizeOnFocusLoss = (*env)->GetStaticMethodID(env, mActivityClass, + "shouldMinimizeOnFocusLoss","()Z"); midGetContext = (*env)->GetStaticMethodID(env, mActivityClass, "getContext","()Landroid/content/Context;"); midIsTablet = (*env)->GetStaticMethodID(env, mActivityClass, @@ -532,7 +538,7 @@ JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeSetupJNI)(JNIEnv *env, jclass cl if (!midGetNativeSurface || !midSetSurfaceViewFormat || - !midSetActivityTitle || !midSetWindowStyle || !midSetOrientation || !midGetContext || !midIsTablet || !midIsAndroidTV || !midInitTouch || + !midSetActivityTitle || !midSetWindowStyle || !midSetOrientation || !midMinimizeWindow || !midShouldMinimizeOnFocusLoss || !midGetContext || !midIsTablet || !midIsAndroidTV || !midInitTouch || !midSendMessage || !midShowTextInput || !midIsScreenKeyboardShown || !midClipboardSetText || !midClipboardGetText || !midClipboardHasText || !midOpenAPKExpansionInputStream || !midGetManifestEnvironmentVariables || !midGetDisplayDPI || @@ -1285,6 +1291,18 @@ void Android_JNI_SetOrientation(int w, int h, int resizable, const char *hint) (*env)->DeleteLocalRef(env, jhint); } +void Android_JNI_MinizeWindow() +{ + JNIEnv *env = Android_JNI_GetEnv(); + (*env)->CallStaticVoidMethod(env, mActivityClass, midMinimizeWindow); +} + +SDL_bool Android_JNI_ShouldMinimizeOnFocusLoss() +{ + JNIEnv *env = Android_JNI_GetEnv(); + return (*env)->CallStaticBooleanMethod(env, mActivityClass, midShouldMinimizeOnFocusLoss); +} + SDL_bool Android_JNI_GetAccelerometerValues(float values[3]) { int i; diff --git a/src/core/android/SDL_android.h b/src/core/android/SDL_android.h index 7469de93e..837c3a4a7 100644 --- a/src/core/android/SDL_android.h +++ b/src/core/android/SDL_android.h @@ -39,6 +39,8 @@ extern "C" { extern void Android_JNI_SetActivityTitle(const char *title); extern void Android_JNI_SetWindowStyle(SDL_bool fullscreen); extern void Android_JNI_SetOrientation(int w, int h, int resizable, const char *hint); +extern void Android_JNI_MinizeWindow(void); +extern SDL_bool Android_JNI_ShouldMinimizeOnFocusLoss(void); extern SDL_bool Android_JNI_GetAccelerometerValues(float values[3]); extern void Android_JNI_ShowTextInput(SDL_Rect *inputRect); diff --git a/src/video/SDL_video.c b/src/video/SDL_video.c index fd67442d6..c63f74631 100644 --- a/src/video/SDL_video.c +++ b/src/video/SDL_video.c @@ -2664,6 +2664,15 @@ ShouldMinimizeOnFocusLoss(SDL_Window * window) } #endif +#ifdef __ANDROID__ + { + extern SDL_bool Android_JNI_ShouldMinimizeOnFocusLoss(void); + if (! Android_JNI_ShouldMinimizeOnFocusLoss()) { + return SDL_FALSE; + } + } +#endif + return SDL_GetHintBoolean(SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS, SDL_TRUE); } diff --git a/src/video/android/SDL_androidvideo.c b/src/video/android/SDL_androidvideo.c index 3057ee9ac..91e6e9973 100644 --- a/src/video/android/SDL_androidvideo.c +++ b/src/video/android/SDL_androidvideo.c @@ -127,6 +127,7 @@ Android_CreateDevice(int devindex) device->CreateSDLWindow = Android_CreateWindow; device->SetWindowTitle = Android_SetWindowTitle; device->SetWindowFullscreen = Android_SetWindowFullscreen; + device->MinimizeWindow = Android_MinimizeWindow; device->DestroyWindow = Android_DestroyWindow; device->GetWindowWMInfo = Android_GetWindowWMInfo; diff --git a/src/video/android/SDL_androidwindow.c b/src/video/android/SDL_androidwindow.c index c99ca7035..96a94e178 100644 --- a/src/video/android/SDL_androidwindow.c +++ b/src/video/android/SDL_androidwindow.c @@ -160,6 +160,12 @@ endfunction: SDL_UnlockMutex(Android_ActivityMutex); } +void +Android_MinimizeWindow(_THIS, SDL_Window *window) +{ + Android_JNI_MinizeWindow(); +} + void Android_DestroyWindow(_THIS, SDL_Window *window) { diff --git a/src/video/android/SDL_androidwindow.h b/src/video/android/SDL_androidwindow.h index 02cefd9a9..f9b813b85 100644 --- a/src/video/android/SDL_androidwindow.h +++ b/src/video/android/SDL_androidwindow.h @@ -29,6 +29,8 @@ extern int Android_CreateWindow(_THIS, SDL_Window *window); extern void Android_SetWindowTitle(_THIS, SDL_Window *window); extern void Android_SetWindowFullscreen(_THIS, SDL_Window *window, SDL_VideoDisplay *display, SDL_bool fullscreen); +extern void Android_MinimizeWindow(_THIS, SDL_Window *window); + extern void Android_DestroyWindow(_THIS, SDL_Window *window); extern SDL_bool Android_GetWindowWMInfo(_THIS, SDL_Window *window, struct SDL_SysWMinfo *info); extern SDL_Window *Android_Window;