Half-assed support for Samsung MultiWindow, you neeed to enable "Autodetect screen orientation" to make it work, and launch SDL app as a second window
This commit is contained in:
@@ -573,6 +573,9 @@ public class GLSurfaceView_SDL extends SurfaceView implements SurfaceHolder.Call
|
||||
*/
|
||||
public abstract void onSurfaceChanged(GL10 gl, int width, int height);
|
||||
|
||||
/** Called when screen size changes */
|
||||
public abstract void onWindowResize(int width, int height);
|
||||
|
||||
/**
|
||||
* Called to draw the current frame.
|
||||
* <p>
|
||||
@@ -1199,6 +1202,7 @@ public class GLSurfaceView_SDL extends SurfaceView implements SurfaceHolder.Call
|
||||
mWidth = w;
|
||||
mHeight = h;
|
||||
mSizeChanged = true;
|
||||
mRenderer.onWindowResize(w, h);
|
||||
notify();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
});
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -154,6 +154,7 @@
|
||||
<string name="video_smooth">Linear video filtering</string>
|
||||
<string name="video_separatethread">Separate thread for video, it can increase FPS, it also can crash the app</string>
|
||||
<string name="video_orientation_vertical">Portrait/vertical screen orientation</string>
|
||||
<string name="video_orientation_autodetect">Auto-detect screen orientation</string>
|
||||
<string name="video_bpp_24">24 bpp screen color depth</string>
|
||||
<string name="video_immersive">Hide system navigation buttons / immersive mode</string>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user