diff --git a/android/AndroidManifest.xml b/android/AndroidManifest.xml
index cd288649c3..b28f3165ea 100644
--- a/android/AndroidManifest.xml
+++ b/android/AndroidManifest.xml
@@ -4,7 +4,7 @@
android:versionCode="1"
android:versionName="1.0" >
-
+
diff --git a/android/app-android.cpp b/android/app-android.cpp
index 58a7468311..b986cc4e53 100644
--- a/android/app-android.cpp
+++ b/android/app-android.cpp
@@ -94,6 +94,11 @@ extern "C" jboolean Java_com_turboviking_libnative_NativeApp_isLandscape(JNIEnv
return landscape;
}
+// For the Back button to work right.
+extern "C" jboolean Java_com_turboviking_libnative_NativeApp_isAtTopLevel(JNIEnv *env, jclass) {
+ return NativeIsAtTopLevel();
+}
+
extern "C" void Java_com_turboviking_libnative_NativeApp_init
(JNIEnv *env, jclass, jint xxres, jint yyres, jint dpi, jstring japkpath,
jstring jdataDir, jstring jexternalDir, jstring jlibraryDir, jstring jinstallID, jboolean juseNativeAudio) {
diff --git a/android/project.properties b/android/project.properties
index 8061f9c3fe..fec2d6168d 100644
--- a/android/project.properties
+++ b/android/project.properties
@@ -11,5 +11,5 @@
#proguard.config=${sdk.dir}\tools\proguard\proguard-android.txt:proguard-project.txt
# Project target.
-target=android-8
+target=android-15
android.library=true
diff --git a/android/src/com/turboviking/libnative/NativeActivity.java b/android/src/com/turboviking/libnative/NativeActivity.java
index 065ed5544c..6b88954992 100644
--- a/android/src/com/turboviking/libnative/NativeActivity.java
+++ b/android/src/com/turboviking/libnative/NativeActivity.java
@@ -6,9 +6,7 @@ import java.io.RandomAccessFile;
import java.lang.reflect.Field;
import java.util.UUID;
-import javax.microedition.khronos.egl.EGLConfig;
-import javax.microedition.khronos.opengles.GL10;
-
+import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.ActivityManager;
import android.content.Context;
@@ -19,13 +17,7 @@ import android.content.pm.ConfigurationInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.res.Configuration;
-import android.hardware.Sensor;
-import android.hardware.SensorEvent;
-import android.hardware.SensorEventListener;
-import android.hardware.SensorManager;
-import android.media.AudioFormat;
import android.media.AudioManager;
-import android.media.AudioTrack;
import android.net.Uri;
import android.opengl.GLSurfaceView;
import android.os.Build;
@@ -35,14 +27,11 @@ import android.util.DisplayMetrics;
import android.util.Log;
import android.view.Display;
import android.view.KeyEvent;
-import android.view.MotionEvent;
+import android.view.View;
import android.view.Window;
import android.view.WindowManager;
-import android.view.inputmethod.InputMethodManager;
import android.widget.Toast;
-
-
class Installation {
private static String sID = null;
private static final String INSTALLATION = "INSTALLATION";
@@ -113,6 +102,7 @@ public class NativeActivity extends Activity {
return libdir;
}
+
@Override
public void onCreate(Bundle savedInstanceState) {
if (Build.VERSION.SDK_INT >= 9) {
@@ -142,8 +132,10 @@ public class NativeActivity extends Activity {
File sdcard = Environment.getExternalStorageDirectory();
Display display = ((WindowManager)this.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
int scrPixelFormat = display.getPixelFormat();
+ @SuppressWarnings("deprecation")
int scrWidth = display.getWidth();
- int scrHeight = display.getHeight();
+ @SuppressWarnings("deprecation")
+ int scrHeight = display.getHeight();
float scrRefreshRate = (float)display.getRefreshRate();
String externalStorageDir = sdcard.getAbsolutePath();
String dataDir = this.getFilesDir().getAbsolutePath();
@@ -152,6 +144,7 @@ public class NativeActivity extends Activity {
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
int dpi = metrics.densityDpi;
+
// INIT!
NativeApp.init(scrWidth, scrHeight, dpi, apkFilePath, dataDir, externalStorageDir, libraryDir, installID, useOpenSL);
@@ -162,8 +155,9 @@ public class NativeActivity extends Activity {
Log.i(TAG, "W : " + scrWidth + " H: " + scrHeight + " rate: " + scrRefreshRate + " fmt: " + scrPixelFormat);
// Initialize Graphics
+
if (!detectOpenGLES20()) {
- throw new RuntimeException("Application requires OpenGL ES 2.0.");
+ Log.i(TAG, "OpenGL ES 2.0 NOT detected.");
} else {
Log.i(TAG, "OpenGL ES 2.0 detected.");
}
@@ -173,7 +167,15 @@ public class NativeActivity extends Activity {
setContentView(mGLSurfaceView);
if (!useOpenSL)
audioPlayer = new NativeAudioPlayer();
+ lightsOut();
}
+
+ @SuppressLint("NewApi")
+ public void lightsOut() {
+ if (Build.VERSION.SDK_INT >= 11) {
+ mGLSurfaceView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE);
+ }
+ }
private boolean detectOpenGLES20() {
ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
@@ -250,19 +252,24 @@ public class NativeActivity extends Activity {
// Eat these keys, to avoid accidental exits / other screwups.
// Maybe there's even more we need to eat on tablets?
if (keyCode == KeyEvent.KEYCODE_BACK) {
- NativeApp.keyUp(1);
- return true;
+ if (NativeApp.isAtTopLevel()) {
+ return false;
+ } else {
+ NativeApp.keyUp(1);
+ return true;
+ }
}
else if (keyCode == KeyEvent.KEYCODE_MENU) {
- // Menu should be ignored from android 3 forwards
+ // Menu should be ignored from SDK 11 forwards. We send it to the app.
NativeApp.keyUp(2);
return true;
}
else if (keyCode == KeyEvent.KEYCODE_SEARCH) {
- // Search probably should also be ignored.
+ // Search probably should also be ignored. We send it to the app.
NativeApp.keyUp(3);
return true;
}
+ // All other keys retain their default behaviour.
return false;
}
@@ -292,7 +299,7 @@ public class NativeActivity extends Activity {
// http://stackoverflow.com/questions/3442366/android-link-to-market-from-inside-another-app
// http://developer.android.com/guide/publishing/publishing.html#marketintent
} else if (command.equals("toast")) {
- Toast toast = Toast.makeText(this, params, 2000);
+ Toast toast = Toast.makeText(this, params, Toast.LENGTH_SHORT);
toast.show();
} else if (command.equals("showkeyboard")) {
//InputMethodManager inputMethodManager=(InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
diff --git a/android/src/com/turboviking/libnative/NativeApp.java b/android/src/com/turboviking/libnative/NativeApp.java
index e7e0c32444..420739f406 100644
--- a/android/src/com/turboviking/libnative/NativeApp.java
+++ b/android/src/com/turboviking/libnative/NativeApp.java
@@ -2,6 +2,7 @@ package com.turboviking.libnative;
public class NativeApp {
public static native boolean isLandscape();
+ public static native boolean isAtTopLevel();
public static native void init(
int xxres, int yyres, int dpi, String apkPath,
String dataDir, String externalDir, String libraryDir, String installID, boolean useOpenSL);
diff --git a/android/src/com/turboviking/libnative/NativeAudioPlayer.java b/android/src/com/turboviking/libnative/NativeAudioPlayer.java
index ede5ebc375..c15ef0a91b 100644
--- a/android/src/com/turboviking/libnative/NativeAudioPlayer.java
+++ b/android/src/com/turboviking/libnative/NativeAudioPlayer.java
@@ -63,7 +63,7 @@ public class NativeAudioPlayer {
// Get the smallest possible buffer size (which is annoyingly huge).
int buffer_size_bytes = AudioTrack.getMinBufferSize(
44100,
- AudioFormat.CHANNEL_CONFIGURATION_STEREO,
+ AudioFormat.CHANNEL_OUT_STEREO,
AudioFormat.ENCODING_PCM_16BIT);
// Round buffer_size_bytes up to an even multiple of 128 for convenience.
@@ -71,7 +71,7 @@ public class NativeAudioPlayer {
AudioTrack audioTrack = new AudioTrack(AudioManager.STREAM_MUSIC,
44100,
- AudioFormat.CHANNEL_CONFIGURATION_STEREO,
+ AudioFormat.CHANNEL_OUT_STEREO,
AudioFormat.ENCODING_PCM_16BIT,
buffer_size_bytes,
AudioTrack.MODE_STREAM);
diff --git a/base/NativeApp.h b/base/NativeApp.h
index b66667302e..efb24a460b 100644
--- a/base/NativeApp.h
+++ b/base/NativeApp.h
@@ -15,6 +15,10 @@ struct InputState;
// This might get called multiple times in some implementations, you must be able to handle that.
void NativeGetAppInfo(std::string *app_dir_name, std::string *app_nice_name, bool *landscape);
+// For the back button to work right, this should return true on your main or title screen.
+// Otherwise, just return false.
+bool NativeIsAtTopLevel();
+
// The very first function to be called after NativeGetAppInfo. Even NativeMix is not called
// before this, although it may be called at any point in time afterwards (on any thread!)
// This functions must NOT call OpenGL. Main thread.