Android: add MinimizeWindow function (Bug 4580, 4657) shouldMinimizeOnFocusLoss is un-activated (return false)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177
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 1c36f86..2dbdef7 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
@@ -849,6 +849,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.
+ */
public static boolean isScreenKeyboardShown()
{
if (mTextEdit == null) {
diff --git a/src/core/android/SDL_android.c b/src/core/android/SDL_android.c
index c960a54..a4a2e1c 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 7469de9..837c3a4 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 fd67442..c63f746 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 3057ee9..91e6e99 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 c99ca70..96a94e1 100644
--- a/src/video/android/SDL_androidwindow.c
+++ b/src/video/android/SDL_androidwindow.c
@@ -161,6 +161,12 @@ endfunction:
}
void
+Android_MinimizeWindow(_THIS, SDL_Window *window)
+{
+ Android_JNI_MinizeWindow();
+}
+
+void
Android_DestroyWindow(_THIS, SDL_Window *window)
{
SDL_LockMutex(Android_ActivityMutex);
diff --git a/src/video/android/SDL_androidwindow.h b/src/video/android/SDL_androidwindow.h
index 02cefd9..f9b813b 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;