Browse Source

Merge branch 'sdl2_2.0.9_fix' into 0.11.x

Martin Felis 7 years ago
parent
commit
696fae730c

+ 67 - 48
love/src/jni/SDL2-2.0.9/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java

@@ -233,50 +233,9 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
            return;
            return;
         }
         }
 
 
-        // Set up JNI
-        SDL.setupJNI();
-
-        // Initialize state
-        SDL.initialize();
-
-        // So we can call stuff from static callbacks
-        mSingleton = this;
-        SDL.setContext(this);
-
-        if (Build.VERSION.SDK_INT >= 11) {
-            mClipboardHandler = new SDLClipboardHandler_API11();
-        } else {
-            /* Before API 11, no clipboard notification (eg no SDL_CLIPBOARDUPDATE) */
-            mClipboardHandler = new SDLClipboardHandler_Old();
-        }
-
-        mHIDDeviceManager = HIDDeviceManager.acquire(this);
-
-        // Set up the surface
-        mSurface = new SDLSurface(getApplication());
-
-        mLayout = new RelativeLayout(this);
-        mLayout.addView(mSurface);
-
-        // Get our current screen orientation and pass it down.
-        mCurrentOrientation = SDLActivity.getCurrentOrientation();
-        SDLActivity.onNativeOrientationChanged(mCurrentOrientation);
-
-        setContentView(mLayout);
-
-        setWindowStyle(false);
-
-        getWindow().getDecorView().setOnSystemUiVisibilityChangeListener(this);
-
-        // Get filename from "Open with" of another application
-        Intent intent = getIntent();
-        if (intent != null && intent.getData() != null) {
-            String filename = intent.getData().getPath();
-            if (filename != null) {
-                Log.v(TAG, "Got filename: " + filename);
-                SDLActivity.onNativeDropFile(filename);
-            }
-        }
+        // love2d-mod-start: allow restarting of the native thread
+        startNative();
+        // love2d-mod-end: allow restarting of the native thread
     }
     }
 
 
     // Events
     // Events
@@ -394,6 +353,17 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
         mNextNativeState = NativeState.PAUSED;
         mNextNativeState = NativeState.PAUSED;
         SDLActivity.handleNativeState();
         SDLActivity.handleNativeState();
 
 
+        // love2d-mod-start: allow restarting of the native thread
+        resetNative();
+        // love2d-mod-end: allow restarting of the native thread
+
+        super.onDestroy();
+    }
+
+    // love2d-mod-start: allow restarting of the native thread
+    public void resetNative() {
+        Log.v("SDL", "resetNative()");
+
         // Send a quit message to the application
         // Send a quit message to the application
         SDLActivity.mExitCalledFromJava = true;
         SDLActivity.mExitCalledFromJava = true;
         SDLActivity.nativeQuit();
         SDLActivity.nativeQuit();
@@ -403,18 +373,67 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
             try {
             try {
                 SDLActivity.mSDLThread.join();
                 SDLActivity.mSDLThread.join();
             } catch(Exception e) {
             } catch(Exception e) {
-                Log.v(TAG, "Problem stopping thread: " + e);
+                Log.v("SDL", "Problem stopping thread: " + e);
             }
             }
             SDLActivity.mSDLThread = null;
             SDLActivity.mSDLThread = null;
 
 
-            //Log.v(TAG, "Finished waiting for SDL thread");
+            //Log.v("SDL", "Finished waiting for SDL thread");
         }
         }
 
 
-        super.onDestroy();
+        SDLActivity.initialize();
+    }
+
+    public void startNative() {
+        Log.v("SDL", "startNative()");
 
 
-        // Reset everything in case the user re opens the app
         SDLActivity.initialize();
         SDLActivity.initialize();
+
+        // Set up JNI
+        SDL.setupJNI();
+
+        // Initialize state
+        SDL.initialize();
+
+        // So we can call stuff from static callbacks
+        mSingleton = this;
+        SDL.setContext(this);
+
+        if (Build.VERSION.SDK_INT >= 11) {
+            mClipboardHandler = new SDLClipboardHandler_API11();
+        } else {
+            /* Before API 11, no clipboard notification (eg no SDL_CLIPBOARDUPDATE) */
+            mClipboardHandler = new SDLClipboardHandler_Old();
+        }
+
+        mHIDDeviceManager = HIDDeviceManager.acquire(this);
+
+        // Set up the surface
+        mSurface = new SDLSurface(getApplication());
+
+        mLayout = new RelativeLayout(this);
+        mLayout.addView(mSurface);
+
+        // Get our current screen orientation and pass it down.
+        mCurrentOrientation = SDLActivity.getCurrentOrientation();
+        SDLActivity.onNativeOrientationChanged(mCurrentOrientation);
+
+        setContentView(mLayout);
+
+        setWindowStyle(false);
+
+        getWindow().getDecorView().setOnSystemUiVisibilityChangeListener(this);
+
+        // Get filename from "Open with" of another application
+        Intent intent = getIntent();
+        if (intent != null && intent.getData() != null) {
+            String filename = intent.getData().getPath();
+            if (filename != null) {
+                Log.v(TAG, "Got filename: " + filename);
+                SDLActivity.onNativeDropFile(filename);
+            }
+        }
     }
     }
+    // love2d-mod-end: allow restarting of the native thread
 
 
     @Override
     @Override
     public void onBackPressed() {
     public void onBackPressed() {