Skip to content
Permalink
Browse files

Android: add MinimizeWindow function (Bug 4580, 4657)

shouldMinimizeOnFocusLoss is un-activated (return false)
  • Loading branch information
1bsyl committed Jun 10, 2019
1 parent 3f4e189 commit f9a9193e2c65edd84f204455d13ee7bd204b61ef
@@ -846,6 +846,45 @@ public void setOrientationBis(int w, int h, boolean resizable, String hint)
}
}

/**
* 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.
*/
@@ -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;
@@ -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);
@@ -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);
}

@@ -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;

@@ -160,6 +160,12 @@ Android_SetWindowFullscreen(_THIS, SDL_Window *window, SDL_VideoDisplay *display
SDL_UnlockMutex(Android_ActivityMutex);
}

void
Android_MinimizeWindow(_THIS, SDL_Window *window)
{
Android_JNI_MinizeWindow();
}

void
Android_DestroyWindow(_THIS, SDL_Window *window)
{
@@ -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;

0 comments on commit f9a9193

Please sign in to comment.