diff --git a/project/java/MainActivity.java b/project/java/MainActivity.java index e3f7f1243..14d4a43f0 100644 --- a/project/java/MainActivity.java +++ b/project/java/MainActivity.java @@ -71,6 +71,7 @@ import android.os.Handler; import android.os.Message; import java.util.concurrent.Semaphore; import android.content.pm.ActivityInfo; +import android.view.Display; public class MainActivity extends Activity { @@ -236,10 +237,49 @@ public class MainActivity extends Activity } public void initSDL() + { + (new Thread(new Runnable() + { + public void run() + { + //int tries = 30; + while( isCurrentOrientationHorizontal() != Globals.HorizontalOrientation ) + { + System.out.println("libSDL: Waiting for screen orientation to change - the device is probably in the lockscreen mode"); + try { + Thread.sleep(500); + } catch( Exception e ) {} + /* + tries--; + if( tries <= 0 ) + { + System.out.println("libSDL: Giving up waiting for screen orientation change"); + break; + } + */ + if( _isPaused ) + { + System.out.println("libSDL: Application paused, cancelling SDL initialization until it will be brought to foreground"); + return; + } + } + runOnUiThread(new Runnable() + { + public void run() + { + initSDLInternal(); + } + }); + } + })).start(); + } + + private void initSDLInternal() { if(sdlInited) return; System.out.println("libSDL: Initializing video and SDL application"); + sdlInited = true; if(Globals.UseAccelerometerAsArrowKeys || Globals.AppUsesAccelerometer) getWindow().setFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON, @@ -304,25 +344,6 @@ public class MainActivity extends Activity if( downloader.DownloadComplete ) { initSDL(); - /* - // This code does not work - (new Thread(new Runnable() - { - public void run() - { - try { - Thread.sleep(300); // Allow some time for Os to change screen orientation - } catch(Exception e) {} - runOnUiThread(new Runnable() - { - public void run() - { - initSDL(); - } - }); - } - })).start(); - */ } } } @@ -936,6 +957,12 @@ public class MainActivity extends Activity return 0; } + public boolean isCurrentOrientationHorizontal() + { + Display getOrient = getWindowManager().getDefaultDisplay(); + return getOrient.getWidth() >= getOrient.getHeight(); + } + public FrameLayout getVideoLayout() { return _videoLayout; } static int NOTIFY_ID = 12367098; // Random ID