Fixed bug 4246 - Android: orientation between portrait<->landscape doesn't work Improve handling of landscape/portrait orientation. Promote to SCREEN_ORIENTATION_SENSOR_* when needed. Android window can be somehow resizable. If SDL_WINDOW_RESIZABLE is set, window size change is allowed, for instance when orientation changes (provided the hint allows it).
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
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 b91a96a..615f84c 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
@@ -817,39 +817,62 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
*/
public void setOrientationBis(int w, int h, boolean resizable, String hint)
{
- int orientation = -1;
+ int orientation_landscape = -1;
+ int orientation_portrait = -1;
+ /* If set, hint "explicitly controls which UI orientations are allowed". */
if (hint.contains("LandscapeRight") && hint.contains("LandscapeLeft")) {
- orientation = ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE;
+ orientation_landscape = ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE;
} else if (hint.contains("LandscapeRight")) {
- orientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
+ orientation_landscape = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
} else if (hint.contains("LandscapeLeft")) {
- orientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE;
- } else if (hint.contains("Portrait") && hint.contains("PortraitUpsideDown")) {
- orientation = ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT;
+ orientation_landscape = ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE;
+ }
+
+ if (hint.contains("Portrait") && hint.contains("PortraitUpsideDown")) {
+ orientation_portrait = ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT;
} else if (hint.contains("Portrait")) {
- orientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
+ orientation_portrait = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
} else if (hint.contains("PortraitUpsideDown")) {
- orientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT;
+ orientation_portrait = ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT;
}
- /* no valid hint */
- if (orientation == -1) {
+ boolean is_landscape_allowed = (orientation_landscape == -1 ? false : true);
+ boolean is_portrait_allowed = (orientation_portrait == -1 ? false : true);
+ int req = -1; /* Requested orientation */
+
+ /* No valid hint, nothing is explicitly allowed */
+ if (!is_portrait_allowed && !is_landscape_allowed) {
+ if (resizable) {
+ /* All orientations are allowed */
+ req = ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR;
+ } else {
+ /* Fixed window and nothing specified. Get orientation from w/h of created window */
+ req = (w > h ? ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE : ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT);
+ }
+ } else {
+ /* At least one orientation is allowed */
if (resizable) {
- /* no fixed orientation */
+ if (is_portrait_allowed && is_landscape_allowed) {
+ /* hint allows both landscape and portrait, promote to full sensor */
+ req = ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR;
+ } else {
+ /* Use the only one allowed "orientation" */
+ req = (is_landscape_allowed ? orientation_landscape : orientation_portrait);
+ }
} else {
- if (w > h) {
- orientation = ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE;
+ /* Fixed window and both orientations are allowed. Choose one. */
+ if (is_portrait_allowed && is_landscape_allowed) {
+ req = (w > h ? orientation_landscape : orientation_portrait);
} else {
- orientation = ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT;
+ /* Use the only one allowed "orientation" */
+ req = (is_landscape_allowed ? orientation_landscape : orientation_portrait);
}
}
}
- Log.v("SDL", "setOrientation() orientation=" + orientation + " width=" + w +" height="+ h +" resizable=" + resizable + " hint=" + hint);
- if (orientation != -1) {
- mSingleton.setRequestedOrientation(orientation);
- }
+ Log.v("SDL", "setOrientation() requestedOrientation=" + req + " width=" + w +" height="+ h +" resizable=" + resizable + " hint=" + hint);
+ mSingleton.setRequestedOrientation(req);
}
/**
diff --git a/src/video/android/SDL_androidwindow.c b/src/video/android/SDL_androidwindow.c
index 9a96fa0..bf4bc91 100644
--- a/src/video/android/SDL_androidwindow.c
+++ b/src/video/android/SDL_androidwindow.c
@@ -58,7 +58,6 @@ Android_CreateWindow(_THIS, SDL_Window * window)
window->w = Android_SurfaceWidth;
window->h = Android_SurfaceHeight;
- window->flags &= ~SDL_WINDOW_RESIZABLE; /* window is NEVER resizeable */
window->flags &= ~SDL_WINDOW_HIDDEN;
window->flags |= SDL_WINDOW_SHOWN; /* only one window on Android */