diff --git a/project/lib/sdl b/project/lib/sdl index 19e50f499..50975d342 160000 --- a/project/lib/sdl +++ b/project/lib/sdl @@ -1 +1 @@ -Subproject commit 19e50f499de933ea39f57c1a4326ab71f36383d3 +Subproject commit 50975d34256bef2f4d3d4c86db4a30e0f5f5abd8 diff --git a/templates/android/template/src/org/libsdl/app/SDLActivity.java b/templates/android/template/src/org/libsdl/app/SDLActivity.java index 72ceca790..5fee28713 100644 --- a/templates/android/template/src/org/libsdl/app/SDLActivity.java +++ b/templates/android/template/src/org/libsdl/app/SDLActivity.java @@ -305,7 +305,7 @@ public class SDLActivity extends Activity { if (!SDLActivity.mIsPaused && SDLActivity.mIsSurfaceReady) { SDLActivity.mIsPaused = true; SDLActivity.nativePause(); - mSurface.enableSensor(Sensor.TYPE_ACCELEROMETER, false); + mSurface.handlePause(); } } @@ -432,20 +432,12 @@ public class SDLActivity extends Activity { public static native void onNativeAccel(float x, float y, float z); public static native void onNativeSurfaceChanged(); public static native void onNativeSurfaceDestroyed(); - public static native void nativeFlipBuffers(); public static native int nativeAddJoystick(int device_id, String name, int is_accelerometer, int nbuttons, int naxes, int nhats, int nballs); public static native int nativeRemoveJoystick(int device_id); public static native String nativeGetHint(String name); - /** - * This method is called by SDL using JNI. - */ - public static void flipBuffers() { - SDLActivity.nativeFlipBuffers(); - } - /** * This method is called by SDL using JNI. */ @@ -693,12 +685,30 @@ public class SDLActivity extends Activity { /** * This method is called by SDL using JNI. + * @return an InputStream on success or null if no expansion file was used. + * @throws IOException on errors. Message is set for the SDL error message. */ public InputStream openAPKExpansionInputStream(String fileName) throws IOException { // Get a ZipResourceFile representing a merger of both the main and patch files if (expansionFile == null) { - Integer mainVersion = Integer.valueOf(nativeGetHint("SDL_ANDROID_APK_EXPANSION_MAIN_FILE_VERSION")); - Integer patchVersion = Integer.valueOf(nativeGetHint("SDL_ANDROID_APK_EXPANSION_PATCH_FILE_VERSION")); + String mainHint = nativeGetHint("SDL_ANDROID_APK_EXPANSION_MAIN_FILE_VERSION"); + if (mainHint == null) { + return null; // no expansion use if no main version was set + } + String patchHint = nativeGetHint("SDL_ANDROID_APK_EXPANSION_PATCH_FILE_VERSION"); + if (patchHint == null) { + return null; // no expansion use if no patch version was set + } + + Integer mainVersion; + Integer patchVersion; + try { + mainVersion = Integer.valueOf(mainHint); + patchVersion = Integer.valueOf(patchHint); + } catch (NumberFormatException ex) { + ex.printStackTrace(); + throw new IOException("No valid file versions set for APK expansion files", ex); + } try { // To avoid direct dependency on Google APK expansion library that is @@ -713,6 +723,7 @@ public class SDLActivity extends Activity { ex.printStackTrace(); expansionFile = null; expansionFileMethod = null; + throw new IOException("Could not access APK expansion support library", ex); } } @@ -721,12 +732,14 @@ public class SDLActivity extends Activity { try { fileStream = (InputStream)expansionFileMethod.invoke(expansionFile, fileName); } catch (Exception ex) { + // calling "getInputStream" failed ex.printStackTrace(); - fileStream = null; + throw new IOException("Could not open stream from APK expansion file", ex); } if (fileStream == null) { - throw new IOException(); + // calling "getInputStream" was successful but null was returned + throw new IOException("Could not find path in APK expansion file"); } return fileStream; @@ -992,6 +1005,10 @@ class SDLSurface extends SurfaceView implements SurfaceHolder.Callback, mHeight = 1.0f; } + public void handlePause() { + enableSensor(Sensor.TYPE_ACCELEROMETER, false); + } + public void handleResume() { setFocusable(true); setFocusableInTouchMode(true); @@ -1651,4 +1668,4 @@ class SDLGenericMotionListener_API12 implements View.OnGenericMotionListener { // Event was not managed return false; } -} \ No newline at end of file +}