On Android show the system UI when an SDL window is windowed, hide the system UI when it's fullscreen, like we do on iOS. We're increasing the Android SDK minimum version to API 19, this doesn't increase the minimum target API, which is API 14.
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 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277
diff --git a/android-project/app/build.gradle b/android-project/app/build.gradle
index 3fe5540..2475c17 100644
--- a/android-project/app/build.gradle
+++ b/android-project/app/build.gradle
@@ -8,14 +8,14 @@ else {
}
android {
- compileSdkVersion 16
+ compileSdkVersion 19
buildToolsVersion "26.0.1"
defaultConfig {
if (buildAsApplication) {
applicationId "org.libsdl.app"
}
minSdkVersion 14
- targetSdkVersion 16
+ targetSdkVersion 19
versionCode 1
versionName "1.0"
externalNativeBuild {
@@ -65,4 +65,4 @@ dependencies {
exclude group: 'com.android.support', module: 'support-annotations'
})
testCompile 'junit:junit:4.12'
-}
\ No newline at end of file
+}
diff --git a/android-project/app/jni/Application.mk b/android-project/app/jni/Application.mk
index e84be02..246136d 100644
--- a/android-project/app/jni/Application.mk
+++ b/android-project/app/jni/Application.mk
@@ -5,5 +5,5 @@
APP_ABI := armeabi-v7a arm64-v8a x86 x86_64
-# Min SDK level
+# Min runtime API level
APP_PLATFORM=android-14
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 3768310..750db69 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
@@ -213,19 +213,7 @@ public class SDLActivity extends Activity {
setContentView(mLayout);
- /*
- * Per SDL_androidwindow.c, Android will only ever have one window, and that window
- * is always flagged SDL_WINDOW_FULLSCREEN. Let's treat it as an immersive fullscreen
- * window for Android UI purposes, as a result.
- */
- int iFlags =
- //View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY | // Only available since API 19
- View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
- View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION |
- View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
- View.SYSTEM_UI_FLAG_FULLSCREEN;
-
- getWindow().getDecorView().setSystemUiVisibility(iFlags);
+ setWindowStyle(false);
// Get filename from "Open with" of another application
Intent intent = getIntent();
@@ -408,7 +396,7 @@ public class SDLActivity extends Activity {
// Messages from the SDLMain thread
static final int COMMAND_CHANGE_TITLE = 1;
- static final int COMMAND_UNUSED = 2;
+ static final int COMMAND_CHANGE_WINDOW_STYLE = 2;
static final int COMMAND_TEXTEDIT_HIDE = 3;
static final int COMMAND_SET_KEEP_SCREEN_ON = 5;
@@ -447,6 +435,29 @@ public class SDLActivity extends Activity {
Log.e(TAG, "error handling message, getContext() returned no Activity");
}
break;
+ case COMMAND_CHANGE_WINDOW_STYLE:
+ if (context instanceof Activity) {
+ Window window = ((Activity) context).getWindow();
+ if (window != null) {
+ if ((msg.obj instanceof Integer) && (((Integer) msg.obj).intValue() != 0)) {
+ int flags = View.SYSTEM_UI_FLAG_LAYOUT_STABLE |
+ View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION |
+ View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
+ View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
+ View.SYSTEM_UI_FLAG_FULLSCREEN |
+ View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
+ window.getDecorView().setSystemUiVisibility(flags);
+ window.addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
+ } else {
+ int flags = View.SYSTEM_UI_FLAG_LAYOUT_STABLE;
+ window.getDecorView().setSystemUiVisibility(flags);
+ window.clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
+ }
+ }
+ } else {
+ Log.e(TAG, "error handling message, getContext() returned no Activity");
+ }
+ break;
case COMMAND_TEXTEDIT_HIDE:
if (mTextEdit != null) {
// Note: On some devices setting view to GONE creates a flicker in landscape.
@@ -526,6 +537,14 @@ public class SDLActivity extends Activity {
/**
* This method is called by SDL using JNI.
+ */
+ public static void setWindowStyle(boolean fullscreen) {
+ // Called from SDLMain() thread and can't directly affect the view
+ mSingleton.sendCommand(COMMAND_CHANGE_WINDOW_STYLE, fullscreen ? 1 : 0);
+ }
+
+ /**
+ * This method is called by SDL using JNI.
* This is a static method for JNI convenience, it calls a non-static method
* so that is can be overridden
*/
@@ -637,7 +656,7 @@ public class SDLActivity extends Activity {
if (bundle == null) {
return false;
}
- String prefix = "SDL_ENV.";
+ String prefix = "SDL_ENV.";
final int trimLength = prefix.length();
for (String key : bundle.keySet()) {
if (key.startsWith(prefix)) {
diff --git a/docs/README-android.md b/docs/README-android.md
index 1e9e8ef..2d20534 100644
--- a/docs/README-android.md
+++ b/docs/README-android.md
@@ -14,7 +14,7 @@ supported, but you can use the "android-project-ant" directory as a template.
Requirements
================================================================================
-Android SDK (version 16 or later)
+Android SDK (version 19 or later)
https://developer.android.com/sdk/index.html
Android NDK r10e or later
diff --git a/src/core/android/SDL_android.c b/src/core/android/SDL_android.c
index f09f918..c40c676 100644
--- a/src/core/android/SDL_android.c
+++ b/src/core/android/SDL_android.c
@@ -209,6 +209,7 @@ static jclass mActivityClass;
/* method signatures */
static jmethodID midGetNativeSurface;
static jmethodID midSetActivityTitle;
+static jmethodID midSetWindowStyle;
static jmethodID midSetOrientation;
static jmethodID midGetContext;
static jmethodID midIsAndroidTV;
@@ -302,6 +303,8 @@ JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeSetupJNI)(JNIEnv* mEnv, jclass c
"getNativeSurface","()Landroid/view/Surface;");
midSetActivityTitle = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass,
"setActivityTitle","(Ljava/lang/String;)Z");
+ midSetWindowStyle = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass,
+ "setWindowStyle","(Z)V");
midSetOrientation = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass,
"setOrientation","(IIZLjava/lang/String;)V");
midGetContext = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass,
@@ -332,7 +335,7 @@ JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeSetupJNI)(JNIEnv* mEnv, jclass c
midGetDisplayDPI = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass, "getDisplayDPI", "()Landroid/util/DisplayMetrics;");
if (!midGetNativeSurface ||
- !midSetActivityTitle || !midSetOrientation || !midGetContext || !midIsAndroidTV || !midInputGetInputDeviceIds ||
+ !midSetActivityTitle || !midSetWindowStyle || !midSetOrientation || !midGetContext || !midIsAndroidTV || !midInputGetInputDeviceIds ||
!midSendMessage || !midShowTextInput || !midIsScreenKeyboardShown ||
!midClipboardSetText || !midClipboardGetText || !midClipboardHasText ||
!midOpenAPKExpansionInputStream || !midGetManifestEnvironmentVariables|| !midGetDisplayDPI) {
@@ -907,6 +910,12 @@ void Android_JNI_SetActivityTitle(const char *title)
(*mEnv)->DeleteLocalRef(mEnv, jtitle);
}
+void Android_JNI_SetWindowStyle(SDL_bool fullscreen)
+{
+ JNIEnv *mEnv = Android_JNI_GetEnv();
+ (*mEnv)->CallStaticVoidMethod(mEnv, mActivityClass, midSetWindowStyle, fullscreen ? 1 : 0);
+}
+
void Android_JNI_SetOrientation(int w, int h, int resizable, const char *hint)
{
JNIEnv *mEnv = Android_JNI_GetEnv();
diff --git a/src/core/android/SDL_android.h b/src/core/android/SDL_android.h
index e26804c..c800dc6 100644
--- a/src/core/android/SDL_android.h
+++ b/src/core/android/SDL_android.h
@@ -34,6 +34,7 @@ extern "C" {
/* Interface from the SDL library into the Android Java activity */
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 SDL_bool Android_JNI_GetAccelerometerValues(float values[3]);
diff --git a/src/video/android/SDL_androidvideo.c b/src/video/android/SDL_androidvideo.c
index c291c54..357f5cf 100644
--- a/src/video/android/SDL_androidvideo.c
+++ b/src/video/android/SDL_androidvideo.c
@@ -120,6 +120,7 @@ Android_CreateDevice(int devindex)
device->CreateSDLWindow = Android_CreateWindow;
device->SetWindowTitle = Android_SetWindowTitle;
+ device->SetWindowFullscreen = Android_SetWindowFullscreen;
device->DestroyWindow = Android_DestroyWindow;
device->GetWindowWMInfo = Android_GetWindowWMInfo;
@@ -220,7 +221,7 @@ Android_SetScreenResolution(int width, int height, Uint32 format, float rate)
/*
Update the resolution of the desktop mode, so that the window
can be properly resized. The screen resolution change can for
- example happen when the Activity enters or exists immersive mode,
+ example happen when the Activity enters or exits immersive mode,
which can happen after VideoInit().
*/
device = SDL_GetVideoDevice();
@@ -234,16 +235,17 @@ Android_SetScreenResolution(int width, int height, Uint32 format, float rate)
}
if (Android_Window) {
- SDL_SendWindowEvent(Android_Window, SDL_WINDOWEVENT_RESIZED, width, height);
-
/* Force the current mode to match the resize otherwise the SDL_WINDOWEVENT_RESTORED event
* will fall back to the old mode */
display = SDL_GetDisplayForWindow(Android_Window);
- display->current_mode.format = format;
- display->current_mode.w = width;
- display->current_mode.h = height;
- display->current_mode.refresh_rate = rate;
+ display->display_modes[0].format = format;
+ display->display_modes[0].w = width;
+ display->display_modes[0].h = height;
+ display->display_modes[0].refresh_rate = rate;
+ display->current_mode = display->display_modes[0];
+
+ SDL_SendWindowEvent(Android_Window, SDL_WINDOWEVENT_RESIZED, width, height);
}
}
diff --git a/src/video/android/SDL_androidwindow.c b/src/video/android/SDL_androidwindow.c
index b38d130..f1cbf58 100644
--- a/src/video/android/SDL_androidwindow.c
+++ b/src/video/android/SDL_androidwindow.c
@@ -53,7 +53,6 @@ Android_CreateWindow(_THIS, SDL_Window * window)
window->h = Android_ScreenHeight;
window->flags &= ~SDL_WINDOW_RESIZABLE; /* window is NEVER resizeable */
- window->flags |= SDL_WINDOW_FULLSCREEN; /* window is always fullscreen */
window->flags &= ~SDL_WINDOW_HIDDEN;
window->flags |= SDL_WINDOW_SHOWN; /* only one window on Android */
window->flags |= SDL_WINDOW_INPUT_FOCUS; /* always has input focus */
@@ -99,6 +98,12 @@ Android_SetWindowTitle(_THIS, SDL_Window * window)
}
void
+Android_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen)
+{
+ Android_JNI_SetWindowStyle(fullscreen);
+}
+
+void
Android_DestroyWindow(_THIS, SDL_Window * window)
{
SDL_WindowData *data;
diff --git a/src/video/android/SDL_androidwindow.h b/src/video/android/SDL_androidwindow.h
index 32d92e4..df99567 100644
--- a/src/video/android/SDL_androidwindow.h
+++ b/src/video/android/SDL_androidwindow.h
@@ -28,6 +28,7 @@
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_DestroyWindow(_THIS, SDL_Window * window);
extern SDL_bool Android_GetWindowWMInfo(_THIS, SDL_Window * window, struct SDL_SysWMinfo * info);