Fixed bug 3235 - Make the Android window creation similar to iOS' window creation
Sylvain Here's a patch. It tries to get the hint first. Resizable will allow any orientation. Otherwise it uses width/height window. setOrientation method is splitted in static and non-static, so that it can be overloaded in a user subclass. Some artefact observed : surfaceChanged() can be called twice at the beginning. When the phone starts in portrait and run a landscape application.
This commit is contained in:
parent
80636fb85a
commit
545c6ea1eb
4 changed files with 72 additions and 0 deletions
|
@ -513,6 +513,61 @@ public class SDLActivity extends Activity {
|
|||
return mSingleton.sendCommand(COMMAND_CHANGE_TITLE, title);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
public static void setOrientation(int w, int h, boolean resizable, String hint)
|
||||
{
|
||||
mSingleton.setOrientationBis(w, h, resizable, hint);
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* This can be overridden
|
||||
*/
|
||||
public void setOrientationBis(int w, int h, boolean resizable, String hint)
|
||||
{
|
||||
int orientation = -1;
|
||||
|
||||
if (hint != "") {
|
||||
if (hint.contains("LandscapeRight") && hint.contains("LandscapeLeft")) {
|
||||
orientation = ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE;
|
||||
} else if (hint.contains("LandscapeRight")) {
|
||||
orientation = 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;
|
||||
} else if (hint.contains("Portrait")) {
|
||||
orientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
|
||||
} else if (hint.contains("PortraitUpsideDown")) {
|
||||
orientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT;
|
||||
}
|
||||
}
|
||||
|
||||
/* no valid hint */
|
||||
if (orientation == -1) {
|
||||
if (resizable) {
|
||||
/* no fixed orientation */
|
||||
} else {
|
||||
if (w > h) {
|
||||
orientation = ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE;
|
||||
} else {
|
||||
orientation = ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Log.v("SDL", "setOrientation() orientation=" + orientation + " width=" + w +" height="+ h +" resizable=" + resizable + " hint=" + hint);
|
||||
if (orientation != -1) {
|
||||
mSingleton.setRequestedOrientation(orientation);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called by SDL using JNI.
|
||||
*/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue