From f3e0e142b060c79d0fcd1d6d6d1024f1f4a4fae0 Mon Sep 17 00:00:00 2001 From: Sergii Pylypenko Date: Mon, 23 Feb 2015 19:00:11 +0200 Subject: [PATCH] SDL: Conclusively fixed black bar on top when restoring the app from background --- project/java/MainActivity.java | 14 +++----------- project/java/Video.java | 28 +++++++++++++++++++++++++++- 2 files changed, 30 insertions(+), 12 deletions(-) diff --git a/project/java/MainActivity.java b/project/java/MainActivity.java index 8364e22c3..49f9b8b13 100644 --- a/project/java/MainActivity.java +++ b/project/java/MainActivity.java @@ -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; diff --git a/project/java/Video.java b/project/java/Video.java index 5d374cf2c..56ad78aa1 100644 --- a/project/java/Video.java +++ b/project/java/Video.java @@ -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) {