diff --git a/android/app-android.cpp b/android/app-android.cpp index 258fa7340d..63266f6f95 100644 --- a/android/app-android.cpp +++ b/android/app-android.cpp @@ -44,8 +44,6 @@ std::queue frameCommands; std::string systemName; std::string langRegion; -const bool extraLog = true; - static float left_joystick_x_async; static float left_joystick_y_async; static float right_joystick_x_async; @@ -134,13 +132,9 @@ extern "C" jboolean Java_com_henrikrydgard_libnative_NativeApp_isLandscape(JNIEn return landscape; } -// For the Back button to work right. +// Allow the app to intercept the back button. extern "C" jboolean Java_com_henrikrydgard_libnative_NativeApp_isAtTopLevel(JNIEnv *env, jclass) { - bool isAtTop = NativeIsAtTopLevel(); - if (extraLog) { - ILOG("isAtTopLevel %i", (int)isAtTop); - } - return isAtTop; + return NativeIsAtTopLevel(); } extern "C" void Java_com_henrikrydgard_libnative_NativeApp_audioConfig diff --git a/android/native-audio-so.cpp b/android/native-audio-so.cpp index 53fa40273c..998080d8f1 100644 --- a/android/native-audio-so.cpp +++ b/android/native-audio-so.cpp @@ -1,8 +1,6 @@ // Minimal audio streaming using OpenSL. // // Loosely based on the Android NDK sample code. -// Hardcoded to 44.1kHz stereo 16-bit audio, because as far as I'm concerned, -// that's the only format that makes any sense. #include #include diff --git a/android/src/com/henrikrydgard/libnative/Installation.java b/android/src/com/henrikrydgard/libnative/Installation.java new file mode 100644 index 0000000000..dffa7cc441 --- /dev/null +++ b/android/src/com/henrikrydgard/libnative/Installation.java @@ -0,0 +1,46 @@ +package com.henrikrydgard.libnative; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.RandomAccessFile; +import java.util.UUID; + +import android.content.Context; + + +public class Installation { + private static String sID = null; + private static final String INSTALLATION = "INSTALLATION"; + + public synchronized static String id(Context context) { + if (sID == null) { + File installation = new File(context.getFilesDir(), INSTALLATION); + try { + if (!installation.exists()) + writeInstallationFile(installation); + sID = readInstallationFile(installation); + } catch (Exception e) { + // We can't even open a file for writing? Then we can't get a unique-ish installation id. + return "BROKENAPPUSERFILESYSTEM"; + } + } + return sID; + } + + private static String readInstallationFile(File installation) throws IOException { + RandomAccessFile f = new RandomAccessFile(installation, "r"); + byte[] bytes = new byte[(int) f.length()]; + f.readFully(bytes); + f.close(); + return new String(bytes); + } + + private static void writeInstallationFile(File installation) throws IOException { + FileOutputStream out = new FileOutputStream(installation); + String id = UUID.randomUUID().toString(); + out.write(id.getBytes()); + out.close(); + } +} + \ No newline at end of file diff --git a/android/src/com/henrikrydgard/libnative/NativeActivity.java b/android/src/com/henrikrydgard/libnative/NativeActivity.java index 1489b15a46..b08ac3d726 100644 --- a/android/src/com/henrikrydgard/libnative/NativeActivity.java +++ b/android/src/com/henrikrydgard/libnative/NativeActivity.java @@ -51,41 +51,6 @@ import android.widget.EditText; import android.widget.FrameLayout; import android.widget.Toast; -class Installation { - private static String sID = null; - private static final String INSTALLATION = "INSTALLATION"; - - public synchronized static String id(Context context) { - if (sID == null) { - File installation = new File(context.getFilesDir(), INSTALLATION); - try { - if (!installation.exists()) - writeInstallationFile(installation); - sID = readInstallationFile(installation); - } catch (Exception e) { - // We can't even open a file for writing? Then we can't get a unique-ish installation id. - return "BROKENAPPUSERFILESYSTEM"; - } - } - return sID; - } - - private static String readInstallationFile(File installation) throws IOException { - RandomAccessFile f = new RandomAccessFile(installation, "r"); - byte[] bytes = new byte[(int) f.length()]; - f.readFully(bytes); - f.close(); - return new String(bytes); - } - - private static void writeInstallationFile(File installation) throws IOException { - FileOutputStream out = new FileOutputStream(installation); - String id = UUID.randomUUID().toString(); - out.write(id.getBytes()); - out.close(); - } -} - public class NativeActivity extends Activity { // Remember to loadLibrary your JNI .so in a static {} block @@ -135,6 +100,10 @@ public class NativeActivity extends Activity { private void detectOptimalAudioSettings() { try { optimalFramesPerBuffer = Integer.parseInt(this.audioManager.getProperty(AudioManager.PROPERTY_OUTPUT_FRAMES_PER_BUFFER)); + } catch (NumberFormatException e) { + // Ignore, if we can't parse it it's bogus and zero is a fine value (means we couldn't detect it). + } + try { optimalSampleRate = Integer.parseInt(this.audioManager.getProperty(AudioManager.PROPERTY_OUTPUT_SAMPLE_RATE)); } catch (NumberFormatException e) { // Ignore, if we can't parse it it's bogus and zero is a fine value (means we couldn't detect it). @@ -159,7 +128,7 @@ public class NativeActivity extends Activity { return libdir; } - @TargetApi(13) + @TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2) void GetScreenSizeHC(Point size) { WindowManager w = getWindowManager(); w.getDefaultDisplay().getSize(size); diff --git a/android/src/com/henrikrydgard/libnative/NativeRenderer.java b/android/src/com/henrikrydgard/libnative/NativeRenderer.java index 4856fdd09c..85e857f53e 100644 --- a/android/src/com/henrikrydgard/libnative/NativeRenderer.java +++ b/android/src/com/henrikrydgard/libnative/NativeRenderer.java @@ -21,8 +21,10 @@ public class NativeRenderer implements GLSurfaceView.Renderer { isDark = d; } + @Override public void onDrawFrame(GL10 unused /*use GLES20*/) { if (isDark) { + GLES20.glDisable(GLES20.GL_SCISSOR_TEST); GLES20.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT | GLES20.GL_STENCIL_BUFFER_BIT); } else { @@ -30,17 +32,20 @@ public class NativeRenderer implements GLSurfaceView.Renderer { } } + @Override public void onSurfaceCreated(GL10 unused, EGLConfig config) { // Log.i(TAG, "onSurfaceCreated - EGL context is new or was lost"); // Actually, it seems that it is here we should recreate lost GL objects. displayInit(); } + @Override public void onSurfaceChanged(GL10 unused, int width, int height) { Log.i(TAG, "onSurfaceChanged"); displayResize(width, height); } - + + // Not override, it's custom. public void onDestroyed() { displayShutdown(); }