Browse Source

latest sdl

dm 7 years ago
parent
commit
6fe455a941

+ 28 - 3
oxygine/SDL/android/lib/src/org/libsdl/app/HIDDeviceManager.java

@@ -1,5 +1,7 @@
 package org.libsdl.app;
 
+import android.app.Activity;
+import android.app.AlertDialog;
 import android.app.PendingIntent;
 import android.bluetooth.BluetoothAdapter;
 import android.bluetooth.BluetoothDevice;
@@ -8,6 +10,7 @@ import android.bluetooth.BluetoothProfile;
 import android.util.Log;
 import android.content.BroadcastReceiver;
 import android.content.Context;
+import android.content.DialogInterface;
 import android.content.Intent;
 import android.content.IntentFilter;
 import android.content.SharedPreferences;
@@ -98,17 +101,39 @@ public class HIDDeviceManager {
         }
     };
 
-    private HIDDeviceManager(Context context) {
+    private HIDDeviceManager(final Context context) {
         mContext = context;
 
         // Make sure we have the HIDAPI library loaded with the native functions
         try {
             SDL.loadLibrary("hidapi");
-        } catch (Exception e) {
+        } catch (Throwable e) {
             Log.w(TAG, "Couldn't load hidapi: " + e.toString());
+
+            AlertDialog.Builder builder = new AlertDialog.Builder(context);
+            builder.setCancelable(false);
+            builder.setTitle("SDL HIDAPI Error");
+            builder.setMessage("Please report the following error to the SDL maintainers: " + e.getMessage());
+            builder.setNegativeButton("Quit", new DialogInterface.OnClickListener() {
+                @Override
+                public void onClick(DialogInterface dialog, int which) {
+                    try {
+                        // If our context is an activity, exit rather than crashing when we can't
+                        // call our native functions.
+                        Activity activity = (Activity)context;
+        
+                        activity.finish();
+                    }
+                    catch (ClassCastException cce) {
+                        // Context wasn't an activity, there's nothing we can do.  Give up and return.
+                    }
+                }
+            });
+            builder.show();
+
             return;
         }
-
+        
         HIDDeviceRegisterCallback();
 
         mSharedPreferences = mContext.getSharedPreferences("hidapi", Context.MODE_PRIVATE);

+ 1 - 1
oxygine/SDL/android/lib/src/org/libsdl/app/SDL.java

@@ -66,7 +66,7 @@ public class SDL {
             Method loadMethod = relinkInstanceClass.getDeclaredMethod("loadLibrary", contextClass, stringClass, stringClass, relinkListenerClass);
             loadMethod.invoke(relinkInstance, mContext, libraryName, null, null);
         }
-        catch (final Exception e) {
+        catch (final Throwable e) {
             // Fall back
             try {
                 System.loadLibrary(libraryName);

+ 48 - 8
oxygine/SDL/android/lib/src/org/libsdl/app/SDLActivity.java

@@ -645,15 +645,54 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
         msg.obj = data;
         boolean result = commandHandler.sendMessage(msg);
 
-        // Ensure we don't return until the resize has actually happened,
-        // or 250ms have passed.
-        if (command == COMMAND_CHANGE_WINDOW_STYLE) {
-            synchronized(SDLActivity.getContext()) {
-                try {
-                    SDLActivity.getContext().wait(250);
+        if ((Build.VERSION.SDK_INT >= 19) && (command == COMMAND_CHANGE_WINDOW_STYLE)) {
+            // Ensure we don't return until the resize has actually happened,
+            // or 500ms have passed.
+
+            boolean bShouldWait = false;
+            
+            if (data instanceof Integer) {
+                // Let's figure out if we're already laid out fullscreen or not.
+                Display display = ((WindowManager)getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
+                android.util.DisplayMetrics realMetrics = new android.util.DisplayMetrics();
+                display.getRealMetrics( realMetrics );
+        
+                boolean bFullscreenLayout = ((realMetrics.widthPixels == mSurface.getWidth()) && 
+                                             (realMetrics.heightPixels == mSurface.getHeight()));
+
+                if (((Integer)data).intValue() == 1) {
+                    // If we aren't laid out fullscreen or actively in fullscreen mode already, we're going
+                    // to change size and should wait for surfaceChanged() before we return, so the size
+                    // is right back in native code.  If we're already laid out fullscreen, though, we're
+                    // not going to change size even if we change decor modes, so we shouldn't wait for
+                    // surfaceChanged() -- which may not even happen -- and should return immediately.
+                    bShouldWait = !bFullscreenLayout;
+                }
+                else {
+                    // If we're laid out fullscreen (even if the status bar and nav bar are present),
+                    // or are actively in fullscreen, we're going to change size and should wait for
+                    // surfaceChanged before we return, so the size is right back in native code.
+                    bShouldWait = bFullscreenLayout;
                 }
-                catch (InterruptedException ie) {
-                    ie.printStackTrace();
+            }
+
+            if (bShouldWait) {
+                // We'll wait for the surfaceChanged() method, which will notify us
+                // when called.  That way, we know our current size is really the
+                // size we need, instead of grabbing a size that's still got
+                // the navigation and/or status bars before they're hidden.
+                //
+                // We'll wait for up to half a second, because some devices 
+                // take a surprisingly long time for the surface resize, but
+                // then we'll just give up and return.
+                //
+                synchronized(SDLActivity.getContext()) {
+                    try {
+                        SDLActivity.getContext().wait(500);
+                    }
+                    catch (InterruptedException ie) {
+                        ie.printStackTrace();
+                    }
                 }
             }
         }
@@ -1595,6 +1634,7 @@ class SDLSurface extends SurfaceView implements SurfaceHolder.Callback,
         catch ( java.lang.Throwable throwable ) {}
 
         synchronized(SDLActivity.getContext()) {
+            // In case we're waiting on a size change after going fullscreen, send a notification.
             SDLActivity.getContext().notifyAll();
         }
 

+ 17 - 20
oxygine/SDL/android/lib/src/org/libsdl/app/SDLControllerManager.java

@@ -36,27 +36,24 @@ public class SDLControllerManager
     private static final String TAG = "SDLControllerManager";
 
     public static void initialize() {
-        mJoystickHandler = null;
-        mHapticHandler = null;
-
-        SDLControllerManager.setup();
-    }
-
-    public static void setup() {
-        if (Build.VERSION.SDK_INT >= 19) {
-            mJoystickHandler = new SDLJoystickHandler_API19();
-        } else if (Build.VERSION.SDK_INT >= 16) {
-            mJoystickHandler = new SDLJoystickHandler_API16();
-        } else if (Build.VERSION.SDK_INT >= 12) {
-            mJoystickHandler = new SDLJoystickHandler_API12();
-        } else {
-            mJoystickHandler = new SDLJoystickHandler();
+        if (mJoystickHandler == null) {
+            if (Build.VERSION.SDK_INT >= 19) {
+                mJoystickHandler = new SDLJoystickHandler_API19();
+            } else if (Build.VERSION.SDK_INT >= 16) {
+                mJoystickHandler = new SDLJoystickHandler_API16();
+            } else if (Build.VERSION.SDK_INT >= 12) {
+                mJoystickHandler = new SDLJoystickHandler_API12();
+            } else {
+                mJoystickHandler = new SDLJoystickHandler();
+            }
         }
 
-        if (Build.VERSION.SDK_INT >= 26) {
-            mHapticHandler = new SDLHapticHandler_API26();
-        } else {
-            mHapticHandler = new SDLHapticHandler();
+        if (mHapticHandler == null) {
+            if (Build.VERSION.SDK_INT >= 26) {
+                mHapticHandler = new SDLHapticHandler_API26();
+            } else {
+                mHapticHandler = new SDLHapticHandler();
+            }
         }
     }
 
@@ -846,4 +843,4 @@ class SDLGenericMotionListener_API26 extends SDLGenericMotionListener_API24 {
         // Relative mouse in capture mode will only have relative for X/Y
         return event.getY(0);
     }
-}
+}