diff --git a/pythonforandroid/bootstraps/sdl2/build/src/main/java/org/kivy/android/PythonActivity.java b/pythonforandroid/bootstraps/sdl2/build/src/main/java/org/kivy/android/PythonActivity.java index 956c5f5b59..33d0855ef3 100644 --- a/pythonforandroid/bootstraps/sdl2/build/src/main/java/org/kivy/android/PythonActivity.java +++ b/pythonforandroid/bootstraps/sdl2/build/src/main/java/org/kivy/android/PythonActivity.java @@ -193,7 +193,7 @@ protected void onPostExecute(String result) { mActivity.getPackageName(), PackageManager.GET_META_DATA).metaData; PowerManager pm = (PowerManager) mActivity.getSystemService(Context.POWER_SERVICE); - if (mActivity.mMetaData.getInt("wakelock") == 1) { + if ( mActivity.mMetaData.getInt("wakelock") == 1 ) { mActivity.mWakeLock = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, "Screen On"); mActivity.mWakeLock.acquire(); } @@ -450,32 +450,35 @@ public void appConfirmedActive() { public void considerLoadingScreenRemoval() { if (loadingScreenRemovalTimer != null) return; - if (PythonActivity.mSingleton != null && - mAppConfirmedActive && - loadingScreenRemovalTimer == null) { - Log.v(TAG, "loading screen timer Runnable() launched."); - // Remove loading screen but with a delay. - // (app can use p4a's android.loadingscreen module to - // do it quicker if it wants to) - TimerTask removalTask = new TimerTask() { - @Override - public void run() { - // post a runnable to the handler - runOnUiThread(new Runnable() { + runOnUiThread(new Runnable() { + public void run() { + if (((PythonActivity)PythonActivity.mSingleton).mAppConfirmedActive && + loadingScreenRemovalTimer == null) { + // Remove loading screen but with a delay. + // (app can use p4a's android.loadingscreen module to + // do it quicker if it wants to) + // get a handler (call from main thread) + // this will run when timer elapses + TimerTask removalTask = new TimerTask() { @Override public void run() { - Log.v(TAG, "loading screen timer Runnable() finished."); - PythonActivity activity = - ((PythonActivity)PythonActivity.mSingleton); - if (activity != null) - activity.removeLoadingScreen(); + // post a runnable to the handler + runOnUiThread(new Runnable() { + @Override + public void run() { + PythonActivity activity = + ((PythonActivity)PythonActivity.mSingleton); + if (activity != null) + activity.removeLoadingScreen(); + } + }); } - }); + }; + loadingScreenRemovalTimer = new Timer(); + loadingScreenRemovalTimer.schedule(removalTask, 5000); } - }; - loadingScreenRemovalTimer = new Timer(); - loadingScreenRemovalTimer.schedule(removalTask, 5000); - } + } + }); } public void removeLoadingScreen() { @@ -586,30 +589,14 @@ protected void onResume() { if (this.mWakeLock != null) { this.mWakeLock.acquire(); } - Log.v(TAG, "onResume(), mSDLThread exists yet: " + (mSDLThread != null)); + Log.v(TAG, "onResume()"); try { super.onResume(); - if (mSDLThread == null && !mIsResumedCalled) { - // Ok so SDL2's onStart() usually launches the native code. - // However, this may fail if native libs aren't loaded yet at that point - // (due ot our loading screen) so we may need to manually trigger this, - // otherwise code would only launch by leaving & re-entering the app: - Log.v(TAG, "Loading screen workaround: triggering native resume"); - if (mSDLThread == null && mCurrentNativeState == NativeState.RESUMED) { - // Force a state change so SDL2 doesn't just ignore the resume: - mCurrentNativeState = NativeState.PAUSED; - } - resumeNativeThread(); // native resume to call native code - } } catch (UnsatisfiedLinkError e) { // Catch resume while still in loading screen failing to // call native function (since it's not yet loaded) - Log.v(TAG, "failed to call native onResume() because libs " + - "aren't loaded yet. this is expected to happen"); } considerLoadingScreenRemoval(); - Log.v(TAG, "onResume() done in PythonActivity, " + - "mSDLThread exists yet: " + (mSDLThread != null)); } @Override @@ -619,7 +606,6 @@ public void onWindowFocusChanged(boolean hasFocus) { } catch (UnsatisfiedLinkError e) { // Catch window focus while still in loading screen failing to // call native function (since it's not yet loaded) - return; // no point in barging further } considerLoadingScreenRemoval(); } diff --git a/pythonforandroid/bootstraps/sdl2/build/src/patches/SDLActivity.java.patch b/pythonforandroid/bootstraps/sdl2/build/src/patches/SDLActivity.java.patch index 90daa10eea..27b97a7fbb 100644 --- a/pythonforandroid/bootstraps/sdl2/build/src/patches/SDLActivity.java.patch +++ b/pythonforandroid/bootstraps/sdl2/build/src/patches/SDLActivity.java.patch @@ -1,13 +1,12 @@ --- a/src/main/java/org/libsdl/app/SDLActivity.java +++ b/src/main/java/org/libsdl/app/SDLActivity.java -@@ -196,6 +196,16 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh +@@ -196,6 +196,15 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh Log.v(TAG, "onCreate()"); super.onCreate(savedInstanceState); ++ SDLActivity.initialize(); + // So we can call stuff from static callbacks + mSingleton = this; -+ -+ SDLActivity.initialize(); + } + + // We don't do this in onCreate because we unpack and load the app data on a thread @@ -17,16 +16,6 @@ // Load shared libraries String errorMsgBrokenLib = ""; try { -@@ -508,7 +508,8 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh - } - - // Try a transition to resumed state -- if (mNextNativeState == NativeState.RESUMED) { -+ // python-for-android: we delay finishLoad() -> mSurface can be null! -+ if (mNextNativeState == NativeState.RESUMED && mSurface != null) { - if (mSurface.mIsSurfaceReady && mHasFocus && mIsResumedCalled) { - if (mSDLThread == null) { - // This is the entry point to the C app. @@ -639,7 +648,7 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh Handler commandHandler = new SDLCommandHandler(); @@ -58,11 +47,28 @@ // APK expansion files support /** com.android.vending.expansion.zipfile.ZipResourceFile object or null. */ -@@ -1475,5 +1475,7 @@ class SDLMain implements Runnable { +@@ -1341,14 +1366,13 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh + }; + + public void onSystemUiVisibilityChange(int visibility) { +- if (SDLActivity.mFullscreenModeActive && (visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0 || (visibility & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0) { +- ++ // SDL2 BUGFIX (see sdl bug #4424 ) - REMOVE WHEN FIXED IN UPSTREAM !! ++ if (SDLActivity.mFullscreenModeActive && ((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0 || (visibility & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0)) { + Handler handler = getWindow().getDecorView().getHandler(); + if (handler != null) { + handler.removeCallbacks(rehideSystemUi); // Prevent a hide loop. + handler.postDelayed(rehideSystemUi, 2000); + } +- + } + } + +@@ -1475,6 +1499,7 @@ class SDLMain implements Runnable { + String[] arguments = SDLActivity.mSingleton.getArguments(); + Log.v("SDL", "Running main function " + function + " from library " + library); - + SDLActivity.mSingleton.appConfirmedActive(); -+ Log.v("SDL", "(python-for-android: appConfirmedActive() was called)"); SDLActivity.nativeRunMain(library, function, arguments); Log.v("SDL", "Finished main function"); diff --git a/pythonforandroid/recipes/sdl2/__init__.py b/pythonforandroid/recipes/sdl2/__init__.py index ddf373c27b..830e9dde44 100644 --- a/pythonforandroid/recipes/sdl2/__init__.py +++ b/pythonforandroid/recipes/sdl2/__init__.py @@ -4,9 +4,9 @@ class LibSDL2Recipe(BootstrapNDKRecipe): - version = "2.0.10" - url = "https://www.libsdl.org/release/SDL2-{version}.zip" - md5sum = "6b2e9a4a2faba4ff277062cf669724f4" + version = "2.0.9" + url = "https://www.libsdl.org/release/SDL2-{version}.tar.gz" + md5sum = 'f2ecfba915c54f7200f504d8b48a5dfe' dir_name = 'SDL'