SDL: Conclusively fixed black bar on top when restoring the app from background

This commit is contained in:
Sergii Pylypenko
2015-02-23 19:00:11 +02:00
parent e058734273
commit f3e0e142b0
2 changed files with 30 additions and 12 deletions

View File

@@ -382,8 +382,8 @@ public class MainActivity extends Activity
_videoLayout.getWindowVisibleDisplayFrame(r);
int heightDiff = _videoLayout.getRootView().getHeight() - _videoLayout.getHeight(); // Take system bar into consideration
int widthDiff = _videoLayout.getRootView().getWidth() - _videoLayout.getWidth(); // Nexus 5 has system bar at the right side
mGLView.nativeScreenVisibleRect(r.left + widthDiff, r.top + heightDiff, r.width(), r.height());
Log.v("SDL", "Main window visible region changed: " + r.left + ":" + r.top + ":" + r.width() + ":" + r.height() );
mGLView.nativeScreenVisibleRect(r.left + widthDiff, r.top + heightDiff, r.width(), r.height());
}
});
}
@@ -410,9 +410,9 @@ public class MainActivity extends Activity
super.onResume();
if( mGLView != null )
{
mGLView.onResume();
DimSystemStatusBar.get().dim(_videoLayout);
DimSystemStatusBar.get().dim(mGLView);
mGLView.onResume();
}
else
if( downloader != null )
@@ -439,14 +439,6 @@ public class MainActivity extends Activity
onPause();
else
onResume();
/*
if (hasFocus == false) {
synchronized(textInput) {
// Send 'SDLK_PAUSE' (to enter pause mode) to native code:
DemoRenderer.nativeTextInput( 19, 19 );
}
}
*/
}
public boolean isPaused()
@@ -1315,7 +1307,7 @@ public class MainActivity extends Activity
static int NOTIFY_ID = 12367098; // Random ID
private static DemoGLSurfaceView mGLView = null;
DemoGLSurfaceView mGLView = null;
private static AudioThread mAudioThread = null;
private static DataDownloader downloader = null;

View File

@@ -608,9 +608,12 @@ class DemoRenderer extends GLSurfaceView_SDL.Renderer
nativeResize(mWidth, mHeight, Globals.KeepAspectRatio ? 1 : 0);
}
int mLastPendingResize = 0;
public void onWindowResize(final int w, final int h)
{
Log.d("SDL", "libSDL: DemoRenderer.onWindowResize(): " + w + "x" + h);
mLastPendingResize ++;
final int resizeThreadIndex = mLastPendingResize;
new Thread(new Runnable()
{
public void run()
@@ -619,6 +622,8 @@ class DemoRenderer extends GLSurfaceView_SDL.Renderer
try{
Thread.sleep(2000);
} catch (InterruptedException e) {}
if (resizeThreadIndex != mLastPendingResize)
return; // Avoid running this function multiple times in a row
int ww = w - w % 2;
int hh = h - h % 2;
View topView = context.getWindow().peekDecorView();
@@ -632,7 +637,7 @@ class DemoRenderer extends GLSurfaceView_SDL.Renderer
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);
Log.i("SDL", "libSDL: DemoRenderer.onWindowResize(): screen size changed from " + mWidth + "x" + mHeight + " to " + ww + "x" + hh);
if (Globals.SwVideoMode &&
(Math.abs(display.getWidth() - ww) > display.getWidth() / 10 ||
Math.abs(display.getHeight() - hh) > display.getHeight() / 10))
@@ -643,6 +648,27 @@ class DemoRenderer extends GLSurfaceView_SDL.Renderer
DemoRenderer.super.ResetVideoSurface();
DemoRenderer.super.onWindowResize(ww, hh);
}
else if (mWidth < ww && mHeight <= hh || mWidth <= ww && mHeight < hh)
{
Log.i("SDL", "System button bar hidden - re-init video to avoid black bar at the top");
context.runOnUiThread(new Runnable()
{
public void run()
{
if (!context.mGLView.isPaused())
{
context.onPause();
context.mGLView.postDelayed(new Runnable()
{
public void run()
{
context.onResume();
}
}, 1000);
}
}
});
}
}
if (mWidth == 0 && mHeight == 0)
{