From f3e0e142b060c79d0fcd1d6d6d1024f1f4a4fae0 Mon Sep 17 00:00:00 2001 From: Sergii Pylypenko Date: Mon, 23 Feb 2015 19:00:11 +0200 Subject: [PATCH 1/5] 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) { From fe413b28cedae02d0c34efda7080c4f8e19fe202 Mon Sep 17 00:00:00 2001 From: Sergii Pylypenko Date: Mon, 23 Feb 2015 19:00:59 +0200 Subject: [PATCH 2/5] XSDL: update --- project/jni/application/hid-pc-keyboard/src | 2 +- project/jni/application/xserver/AndroidAppSettings.cfg | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/project/jni/application/hid-pc-keyboard/src b/project/jni/application/hid-pc-keyboard/src index f062b76c8..83ca8656e 160000 --- a/project/jni/application/hid-pc-keyboard/src +++ b/project/jni/application/hid-pc-keyboard/src @@ -1 +1 @@ -Subproject commit f062b76c86c8bf7d80424228e21be3b9df1311d3 +Subproject commit 83ca8656e61a66d86895b506562628c4f77eadf3 diff --git a/project/jni/application/xserver/AndroidAppSettings.cfg b/project/jni/application/xserver/AndroidAppSettings.cfg index 9e1d1e0d7..f6e25d7e9 100644 --- a/project/jni/application/xserver/AndroidAppSettings.cfg +++ b/project/jni/application/xserver/AndroidAppSettings.cfg @@ -7,10 +7,10 @@ AppName="XServer XSDL" AppFullName=x.org.server # Application version code (integer) -AppVersionCode=11124 +AppVersionCode=11125 # Application user-visible version name (string) -AppVersionName="1.11.24" +AppVersionName="1.11.25" # Specify path to download application data in zip archive in the form 'Description|URL|MirrorURL^Description2|URL2|MirrorURL2^...' # If you'll start Description with '!' symbol it will be enabled by default, other downloads should be selected by user from startup config menu From 3c3ede2283d9746c39ecbdf16e046ea24b0c94ae Mon Sep 17 00:00:00 2001 From: Sergii Pylypenko Date: Mon, 23 Feb 2015 19:03:45 +0200 Subject: [PATCH 3/5] Reverting my commit which did not help to fix the black bar bug --- project/java/MainActivity.java | 51 ++++++++++++---------------------- 1 file changed, 17 insertions(+), 34 deletions(-) diff --git a/project/java/MainActivity.java b/project/java/MainActivity.java index 49f9b8b13..d84feb068 100644 --- a/project/java/MainActivity.java +++ b/project/java/MainActivity.java @@ -297,34 +297,23 @@ public class MainActivity extends Activity } DimSystemStatusBar.get().dim(_videoLayout); } - // Hackish way to set immersive mode, it seems to need some delay before we can create surfaces - runOnUiThread(new Runnable() - { - public void run() - { - initSDLVideoLayout(); - } - }); - try { - Thread.sleep(100); - } catch( Exception ee ) {} - runOnUiThread(new Runnable() - { - public void run() - { - DimSystemStatusBar.get().dim(_videoLayout); - } - }); - if( android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT && Globals.ImmersiveMode ) - { - try { - Thread.sleep(200); - } catch( Exception eee ) {} - } runOnUiThread(new Runnable() { public void run() { + // Hide navigation buttons, and sleep a bit so OS will process the event. + // Do not check the display size in a loop - we may have several displays of different sizes, + // so app may stuck in infinite loop + DisplayMetrics dm = new DisplayMetrics(); + getWindowManager().getDefaultDisplay().getMetrics(dm); + if( android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT && Globals.ImmersiveMode && + (_videoLayout.getHeight() != dm.widthPixels || _videoLayout.getWidth() != dm.heightPixels) ) + { + DimSystemStatusBar.get().dim(_videoLayout); + try { + Thread.sleep(300); + } catch( Exception e ) {} + } initSDLInternal(); } }); @@ -332,10 +321,13 @@ public class MainActivity extends Activity })).start(); } - private void initSDLVideoLayout() + private void initSDLInternal() { if(sdlInited) return; + Log.i("SDL", "libSDL: Initializing video and SDL application"); + + sdlInited = true; DimSystemStatusBar.get().dim(_videoLayout); _videoLayout.removeView(_layout); if( _ad.getView() != null ) @@ -348,15 +340,6 @@ public class MainActivity extends Activity _videoLayout = new FrameLayout(this); SetLayerType.get().setLayerType(_videoLayout); setContentView(_videoLayout); - DimSystemStatusBar.get().dim(_videoLayout); - } - private void initSDLInternal() - { - if(sdlInited) - return; - Log.i("SDL", "libSDL: Initializing video and SDL application"); - - sdlInited = true; mGLView = new DemoGLSurfaceView(this); SetLayerType.get().setLayerType(mGLView); _videoLayout.addView(mGLView); From 59c67c45aef4fd29736f115f980db97f0ddbd6e0 Mon Sep 17 00:00:00 2001 From: Sergii Pylypenko Date: Mon, 23 Feb 2015 19:18:26 +0200 Subject: [PATCH 4/5] SDL: System bar will auto-hide after keyboard was hidden --- project/java/MainActivity.java | 63 ++++++++++++++-------------------- 1 file changed, 25 insertions(+), 38 deletions(-) diff --git a/project/java/MainActivity.java b/project/java/MainActivity.java index d84feb068..db87934e2 100644 --- a/project/java/MainActivity.java +++ b/project/java/MainActivity.java @@ -352,7 +352,7 @@ public class MainActivity extends Activity _ad.getView().setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, Gravity.TOP | Gravity.RIGHT)); } DimSystemStatusBar.get().dim(_videoLayout); - DimSystemStatusBar.get().dim(mGLView); + //DimSystemStatusBar.get().dim(mGLView); Rect r = new Rect(); _videoLayout.getWindowVisibleDisplayFrame(r); @@ -361,12 +361,27 @@ public class MainActivity extends Activity { public void onGlobalLayout() { - Rect r = new Rect(); + final Rect r = new Rect(); _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 + final int heightDiff = _videoLayout.getRootView().getHeight() - _videoLayout.getHeight(); // Take system bar into consideration + final int widthDiff = _videoLayout.getRootView().getWidth() - _videoLayout.getWidth(); // Nexus 5 has system bar at the right side 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()); + _videoLayout.postDelayed( new Runnable() + { + public void run() + { + DimSystemStatusBar.get().dim(_videoLayout); + mGLView.nativeScreenVisibleRect(r.left + widthDiff, r.top + heightDiff, r.width(), r.height()); + } + }, 300 ); + _videoLayout.postDelayed( new Runnable() + { + public void run() + { + DimSystemStatusBar.get().dim(_videoLayout); + mGLView.nativeScreenVisibleRect(r.left + widthDiff, r.top + heightDiff, r.width(), r.height()); + } + }, 600 ); } }); } @@ -394,7 +409,7 @@ public class MainActivity extends Activity if( mGLView != null ) { DimSystemStatusBar.get().dim(_videoLayout); - DimSystemStatusBar.get().dim(mGLView); + //DimSystemStatusBar.get().dim(mGLView); mGLView.onResume(); } else @@ -481,7 +496,7 @@ public class MainActivity extends Activity getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN); _inputManager.hideSoftInputFromWindow(mGLView.getWindowToken(), 0); DimSystemStatusBar.get().dim(_videoLayout); - DimSystemStatusBar.get().dim(mGLView); + //DimSystemStatusBar.get().dim(mGLView); } } @@ -626,14 +641,14 @@ public class MainActivity extends Activity mGLView.setFocusable(true); mGLView.requestFocus(); DimSystemStatusBar.get().dim(_videoLayout); - DimSystemStatusBar.get().dim(mGLView); + //DimSystemStatusBar.get().dim(mGLView); _videoLayout.postDelayed( new Runnable() { public void run() { DimSystemStatusBar.get().dim(_videoLayout); - DimSystemStatusBar.get().dim(mGLView); + //DimSystemStatusBar.get().dim(mGLView); } }, 500 ); }; @@ -748,34 +763,6 @@ public class MainActivity extends Activity } } - /* - @Override - public boolean dispatchKeyEvent(final KeyEvent event) - { - //Log.i("SDL", "dispatchKeyEvent: action " + event.getAction() + " keycode " + event.getKeyCode() + " unicode " + event.getUnicodeChar() + " getCharacters() " + ((event.getCharacters() != null) ? event.getCharacters() : "none")); - - if( event.getAction() == KeyEvent.ACTION_DOWN ) - return onKeyDown(event.getKeyCode(), event); - if( event.getAction() == KeyEvent.ACTION_UP ) - return onKeyUp(event.getKeyCode(), event); - if( event.getAction() == KeyEvent.ACTION_MULTIPLE && event.getKeyCode() == KeyEvent.KEYCODE_UNKNOWN ) - { - // International text input - if( mGLView != null && event.getCharacters() != null ) - { - for(int i = 0; i < event.getCharacters().length(); i++ ) - { - mGLView.nativeKey( event.getKeyCode(), 1, event.getCharacters().codePointAt(i) ); - mGLView.nativeKey( event.getKeyCode(), 0, event.getCharacters().codePointAt(i) ); - } - return true; - } - } - return true; - //return super.dispatchKeyEvent(event); - } - */ - @Override public boolean onKeyDown(int keyCode, final KeyEvent event) { @@ -811,7 +798,7 @@ public class MainActivity extends Activity if( keyCode == KeyEvent.KEYCODE_BACK || keyCode == KeyEvent.KEYCODE_MENU ) { DimSystemStatusBar.get().dim(_videoLayout); - DimSystemStatusBar.get().dim(mGLView); + //DimSystemStatusBar.get().dim(mGLView); } } else From 354986e743921b2f674e9a5059b98181ce66488b Mon Sep 17 00:00:00 2001 From: Sergii Pylypenko Date: Mon, 23 Feb 2015 19:59:20 +0200 Subject: [PATCH 5/5] SDL: fixed black bar at the bottom when showing Andorid keyboard --- project/java/MainActivity.java | 12 +++++------- project/java/Video.java | 28 +++++----------------------- 2 files changed, 10 insertions(+), 30 deletions(-) diff --git a/project/java/MainActivity.java b/project/java/MainActivity.java index db87934e2..2938b9001 100644 --- a/project/java/MainActivity.java +++ b/project/java/MainActivity.java @@ -641,16 +641,14 @@ public class MainActivity extends Activity mGLView.setFocusable(true); mGLView.requestFocus(); DimSystemStatusBar.get().dim(_videoLayout); - //DimSystemStatusBar.get().dim(mGLView); _videoLayout.postDelayed( new Runnable() + { + public void run() { - public void run() - { - DimSystemStatusBar.get().dim(_videoLayout); - //DimSystemStatusBar.get().dim(mGLView); - } - }, 500 ); + DimSystemStatusBar.get().dim(_videoLayout); + } + }, 500 ); }; public boolean isScreenKeyboardShown() diff --git a/project/java/Video.java b/project/java/Video.java index 56ad78aa1..3c2b49687 100644 --- a/project/java/Video.java +++ b/project/java/Video.java @@ -614,14 +614,11 @@ class DemoRenderer extends GLSurfaceView_SDL.Renderer Log.d("SDL", "libSDL: DemoRenderer.onWindowResize(): " + w + "x" + h); mLastPendingResize ++; final int resizeThreadIndex = mLastPendingResize; - new Thread(new Runnable() + context.mGLView.postDelayed(new Runnable() { public void run() { // Samsung multiwindow will swap screen dimensions when unlocking the lockscreen, sleep a while so we won't use these temporary values - 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; @@ -648,26 +645,11 @@ class DemoRenderer extends GLSurfaceView_SDL.Renderer DemoRenderer.super.ResetVideoSurface(); DemoRenderer.super.onWindowResize(ww, hh); } - else if (mWidth < ww && mHeight <= hh || mWidth <= ww && mHeight < hh) + else { 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); - } - } - }); + DemoRenderer.super.ResetVideoSurface(); + DemoRenderer.super.onWindowResize(ww, hh); } } if (mWidth == 0 && mHeight == 0) @@ -681,7 +663,7 @@ class DemoRenderer extends GLSurfaceView_SDL.Renderer if (Globals.AutoDetectOrientation && (ww > hh) != (mWidth > mHeight)) Globals.HorizontalOrientation = (ww > hh); } - }).start(); + }, 2000); } public void onSurfaceDestroyed()