diff --git a/project/AndroidManifestTemplate.xml b/project/AndroidManifestTemplate.xml
index 830f508c5..cb6e16cd4 100644
--- a/project/AndroidManifestTemplate.xml
+++ b/project/AndroidManifestTemplate.xml
@@ -14,21 +14,22 @@
android:label="@string/app_name"
android:alwaysRetainTaskState="true"
android:launchMode="singleTask"
- android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|fontScale|uiMode|screenSize|smallestScreenSize"
+ android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|screenLayout|fontScale|uiMode|orientation|screenSize|smallestScreenSize|layoutDirection"
android:windowSoftInputMode="stateUnspecified"
>
@@ -1199,6 +1202,7 @@ public class GLSurfaceView_SDL extends SurfaceView implements SurfaceHolder.Call
mWidth = w;
mHeight = h;
mSizeChanged = true;
+ mRenderer.onWindowResize(w, h);
notify();
}
}
diff --git a/project/java/Globals.java b/project/java/Globals.java
index 02c893049..976aa2536 100644
--- a/project/java/Globals.java
+++ b/project/java/Globals.java
@@ -79,6 +79,7 @@ class Globals
// Phone-specific config, modified by user in "Change phone config" startup dialog
public static int VideoDepthBpp = 16;
public static boolean HorizontalOrientation = true;
+ public static boolean AutoDetectOrientation = false;
public static boolean ImmersiveMode = true;
public static boolean DownloadToSdcard = true;
public static boolean PhoneHasArrowKeys = false;
diff --git a/project/java/MainActivity.java b/project/java/MainActivity.java
index 5570739d6..b799121be 100644
--- a/project/java/MainActivity.java
+++ b/project/java/MainActivity.java
@@ -94,8 +94,6 @@ public class MainActivity extends Activity
{
super.onCreate(savedInstanceState);
- setScreenOrientation();
-
instance = this;
// fullscreen mode
requestWindowFeature(Window.FEATURE_NO_TITLE);
@@ -191,6 +189,7 @@ public class MainActivity extends Activity
public void run()
{
Settings.Load(Parent);
+ setScreenOrientation();
loaded.release();
loadedLibraries.release();
if( _btn != null )
@@ -282,10 +281,12 @@ public class MainActivity extends Activity
{
public void run()
{
+ if( Globals.AutoDetectOrientation )
+ Globals.HorizontalOrientation = isCurrentOrientationHorizontal();
while( isCurrentOrientationHorizontal() != Globals.HorizontalOrientation ||
((KeyguardManager)getSystemService(Context.KEYGUARD_SERVICE)).inKeyguardRestrictedInputMode() )
{
- Log.i("SDL", "libSDL: Waiting for screen orientation to change, and for disabling lockscreen mode");
+ Log.d("SDL", "libSDL: Waiting for screen orientation to change to " + (Globals.HorizontalOrientation ? "landscape" : "portrait") + ", and for disabling lockscreen mode");
try {
Thread.sleep(500);
} catch( Exception e ) {}
@@ -885,12 +886,24 @@ public class MainActivity extends Activity
return true;
}
+ //private Configuration oldConfig = null;
@Override
public void onConfigurationChanged(Configuration newConfig)
{
- // This function is actually never called
super.onConfigurationChanged(newConfig);
updateScreenOrientation();
+ /*
+ if (oldConfig != null)
+ {
+ int diff = newConfig.diff(oldConfig);
+ Log.i("SDL", "onConfigurationChanged(): " + " diff " + diff +
+ ((diff & ActivityInfo.CONFIG_ORIENTATION) == ActivityInfo.CONFIG_ORIENTATION ? " orientation" : "") +
+ ((diff & ActivityInfo.CONFIG_SCREEN_SIZE) == ActivityInfo.CONFIG_SCREEN_SIZE ? " screen size" : "") +
+ ((diff & ActivityInfo.CONFIG_SMALLEST_SCREEN_SIZE) == ActivityInfo.CONFIG_SMALLEST_SCREEN_SIZE ? " smallest screen size" : "") +
+ " " + newConfig.toString());
+ }
+ oldConfig = new Configuration(newConfig);
+ */
}
public void updateScreenOrientation()
@@ -942,6 +955,14 @@ public class MainActivity extends Activity
NotificationManager NotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
NotificationManager.cancel(NOTIFY_ID);
}
+
+ @Override
+ public void onNewIntent(Intent i)
+ {
+ Log.i("SDL", "onNewIntent(): " + i.toString());
+ super.onNewIntent(i);
+ setIntent(i);
+ }
public void LoadLibraries()
{
@@ -1239,12 +1260,27 @@ public class MainActivity extends Activity
public boolean isCurrentOrientationHorizontal()
{
+ if (Globals.AutoDetectOrientation)
+ {
+ // Less reliable way to detect orientation, but works with multiwindow
+ View topView = getWindow().peekDecorView();
+ if (topView != null)
+ {
+ //Log.d("SDL", "isCurrentOrientationHorizontal(): decorview: " + topView.getWidth() + "x" + topView.getHeight());
+ return topView.getWidth() >= topView.getHeight();
+ }
+ }
Display getOrient = getWindowManager().getDefaultDisplay();
return getOrient.getWidth() >= getOrient.getHeight();
}
void setScreenOrientation()
{
+ if( Globals.AutoDetectOrientation )
+ {
+ setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LOCKED);
+ return;
+ }
if( android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.GINGERBREAD )
setRequestedOrientation(Globals.HorizontalOrientation ? ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE : ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT);
else
diff --git a/project/java/Settings.java b/project/java/Settings.java
index 475b4c7a2..bd45db53f 100644
--- a/project/java/Settings.java
+++ b/project/java/Settings.java
@@ -182,6 +182,7 @@ class Settings
out.writeInt(Globals.VideoDepthBpp);
out.writeBoolean(Globals.HorizontalOrientation);
out.writeBoolean(Globals.ImmersiveMode);
+ out.writeBoolean(Globals.AutoDetectOrientation);
out.close();
settingsLoaded = true;
@@ -374,6 +375,7 @@ class Settings
Globals.VideoDepthBpp = settingsFile.readInt();
Globals.HorizontalOrientation = settingsFile.readBoolean();
Globals.ImmersiveMode = settingsFile.readBoolean();
+ Globals.AutoDetectOrientation = settingsFile.readBoolean();
settingsLoaded = true;
@@ -439,6 +441,7 @@ class Settings
}
Log.i("SDL", "libSDL: Settings.Load(): loading settings failed, running config dialog");
+ p.setScreenOrientation();
p.setUpStatusLabel();
if( checkRamSize(p) )
SettingsMenu.showConfig(p, true);
diff --git a/project/java/SettingsMenuMisc.java b/project/java/SettingsMenuMisc.java
index 6425c0006..abbe27f09 100644
--- a/project/java/SettingsMenuMisc.java
+++ b/project/java/SettingsMenuMisc.java
@@ -347,6 +347,7 @@ class SettingsMenuMisc extends SettingsMenu
p.getResources().getString(R.string.mouse_keepaspectratio),
p.getResources().getString(R.string.video_smooth),
p.getResources().getString(R.string.video_immersive),
+ p.getResources().getString(R.string.video_orientation_autodetect),
p.getResources().getString(R.string.video_orientation_vertical),
p.getResources().getString(R.string.video_bpp_24),
};
@@ -354,6 +355,7 @@ class SettingsMenuMisc extends SettingsMenu
Globals.KeepAspectRatio,
Globals.VideoLinearFilter,
Globals.ImmersiveMode,
+ Globals.AutoDetectOrientation,
!Globals.HorizontalOrientation,
Globals.VideoDepthBpp == 24,
};
@@ -364,6 +366,7 @@ class SettingsMenuMisc extends SettingsMenu
p.getResources().getString(R.string.mouse_keepaspectratio),
p.getResources().getString(R.string.video_smooth),
p.getResources().getString(R.string.video_immersive),
+ p.getResources().getString(R.string.video_orientation_autodetect),
p.getResources().getString(R.string.video_orientation_vertical),
p.getResources().getString(R.string.video_bpp_24),
p.getResources().getString(R.string.video_separatethread),
@@ -372,6 +375,7 @@ class SettingsMenuMisc extends SettingsMenu
Globals.KeepAspectRatio,
Globals.VideoLinearFilter,
Globals.ImmersiveMode,
+ Globals.AutoDetectOrientation,
!Globals.HorizontalOrientation,
Globals.VideoDepthBpp == 24,
Globals.MultiThreadedVideo,
@@ -405,10 +409,12 @@ class SettingsMenuMisc extends SettingsMenu
if( item == 2 )
Globals.ImmersiveMode = isChecked;
if( item == 3 )
- Globals.HorizontalOrientation = !isChecked;
+ Globals.AutoDetectOrientation = isChecked;
if( item == 4 )
- Globals.VideoDepthBpp = (isChecked ? 24 : 16);
+ Globals.HorizontalOrientation = !isChecked;
if( item == 5 )
+ Globals.VideoDepthBpp = (isChecked ? 24 : 16);
+ if( item == 6 )
Globals.MultiThreadedVideo = isChecked;
}
});
diff --git a/project/java/Video.java b/project/java/Video.java
index aa7dea466..8c83692a7 100644
--- a/project/java/Video.java
+++ b/project/java/Video.java
@@ -59,6 +59,10 @@ import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.content.ClipboardManager;
import android.content.ClipboardManager.OnPrimaryClipChangedListener;
+import android.app.PendingIntent;
+import android.app.AlarmManager;
+import android.content.Intent;
+import android.view.View;
class Mouse
@@ -581,7 +585,8 @@ class DemoRenderer extends GLSurfaceView_SDL.Renderer
});
}
- public void onSurfaceCreated(GL10 gl, EGLConfig config) {
+ public void onSurfaceCreated(GL10 gl, EGLConfig config)
+ {
Log.i("SDL", "libSDL: DemoRenderer.onSurfaceCreated(): paused " + mPaused + " mFirstTimeStart " + mFirstTimeStart );
mGlSurfaceCreated = true;
mGl = gl;
@@ -590,7 +595,8 @@ class DemoRenderer extends GLSurfaceView_SDL.Renderer
mFirstTimeStart = false;
}
- public void onSurfaceChanged(GL10 gl, int w, int h) {
+ public void onSurfaceChanged(GL10 gl, int w, int h)
+ {
Log.i("SDL", "libSDL: DemoRenderer.onSurfaceChanged(): paused " + mPaused + " mFirstTimeStart " + mFirstTimeStart + " w " + w + " h " + h);
if( w < h && Globals.HorizontalOrientation )
{
@@ -599,21 +605,53 @@ class DemoRenderer extends GLSurfaceView_SDL.Renderer
w = h;
h = x;
}
- mWidth = w;
- mHeight = h;
+ mWidth = w - w % 2;
+ mHeight = h - h % 2;
mGl = gl;
- nativeResize(w, h, Globals.KeepAspectRatio ? 1 : 0);
+ nativeResize(mWidth, mHeight, Globals.KeepAspectRatio ? 1 : 0);
}
-
- public void onSurfaceDestroyed() {
+
+ public void onWindowResize(final int w, final int h)
+ {
+ Log.d("SDL", "libSDL: DemoRenderer.onWindowResize(): " + w + "x" + h);
+ new Thread(new Runnable()
+ {
+ public void run()
+ {
+ // Samsung multiwindow will swap screen dimensionswhen unlocking the lockscreen, sleep a while so we won't use these temporary values
+ try{
+ Thread.sleep(3000);
+ } catch (InterruptedException e) {}
+ int ww = w;
+ int hh = h;
+ View topView = context.getWindow().peekDecorView();
+ if (topView != null)
+ {
+ ww = topView.getWidth() - topView.getWidth() % 2;
+ hh = topView.getHeight() - topView.getHeight() % 2;
+ }
+ if(mWidth != 0 && mHeight != 0 && (mWidth != ww || mHeight != hh))
+ {
+ Log.w("SDL", "libSDL: DemoRenderer.onWindowResize(): screen size changed from " + mWidth + "x" + mHeight + " to " + ww + "x" + hh + " - restarting application");
+ PendingIntent intent = PendingIntent.getActivity(context, 0, new Intent(context.getIntent()), context.getIntent().getFlags());
+ AlarmManager mgr = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
+ mgr.set(AlarmManager.RTC, System.currentTimeMillis() + 1000, intent);
+ System.exit(0);
+ }
+ }
+ }).start();
+ }
+
+ public void onSurfaceDestroyed()
+ {
Log.i("SDL", "libSDL: DemoRenderer.onSurfaceDestroyed(): paused " + mPaused + " mFirstTimeStart " + mFirstTimeStart );
mGlSurfaceCreated = false;
mGlContextLost = true;
nativeGlContextLost();
};
- public void onDrawFrame(GL10 gl) {
-
+ public void onDrawFrame(GL10 gl)
+ {
mGl = gl;
DrawLogo(mGl);
SwapBuffers();
diff --git a/project/java/translations/values/strings.xml b/project/java/translations/values/strings.xml
index 1d81b5ccc..642b30edf 100644
--- a/project/java/translations/values/strings.xml
+++ b/project/java/translations/values/strings.xml
@@ -154,6 +154,7 @@