diff --git a/android/app-android.cpp b/android/app-android.cpp index 38f0e5c55d..7064a246cf 100644 --- a/android/app-android.cpp +++ b/android/app-android.cpp @@ -43,6 +43,7 @@ std::queue frameCommands; std::string systemName; std::string langRegion; +std::string mogaVersion; static float left_joystick_x_async; static float left_joystick_y_async; @@ -103,6 +104,8 @@ std::string System_GetProperty(SystemProperty prop) { return systemName; case SYSPROP_LANGREGION: // "en_US" return langRegion; + case SYSPROP_MOGA_VERSION: + return mogaVersion; default: return ""; } @@ -519,5 +522,9 @@ extern "C" jboolean JNICALL Java_com_henrikrydgard_libnative_NativeApp_accelerom extern "C" void Java_com_henrikrydgard_libnative_NativeApp_sendMessage(JNIEnv *env, jclass, jstring message, jstring param) { std::string msg = GetJavaString(env, message); std::string prm = GetJavaString(env, param); + + if (msg == "moga") { + mogaVersion = prm; + } NativeMessageReceived(msg.c_str(), prm.c_str()); } diff --git a/android/src/com/henrikrydgard/libnative/NativeGLView.java b/android/src/com/henrikrydgard/libnative/NativeGLView.java index ec2cd9dd49..cca8e0fbab 100644 --- a/android/src/com/henrikrydgard/libnative/NativeGLView.java +++ b/android/src/com/henrikrydgard/libnative/NativeGLView.java @@ -32,7 +32,7 @@ public class NativeGLView extends GLSurfaceView implements SensorEventListener, super(activity); mActivity = activity; - /* + /*// TODO: This would be nice. if (Build.VERSION.SDK_INT >= 11) { try { Method method_setPreserveEGLContextOnPause = GLSurfaceView.class.getMethod( @@ -57,12 +57,8 @@ public class NativeGLView extends GLSurfaceView implements SensorEventListener, if (mController.init()) { Log.i(TAG, "MOGA initialized"); mController.setListener(this, new Handler()); - if (mController.getState(Controller.STATE_CURRENT_PRODUCT_VERSION) != Controller.ACTION_VERSION_MOGA) { - Log.i(TAG, "MOGA pro detected"); - isMogaPro = true; - } } else { - Log.i(TAG, "MOGA failed to initialize"); + Log.i(TAG, "MOGA failed to initialize. No moga detected?"); } } @@ -202,12 +198,20 @@ public class NativeGLView extends GLSurfaceView implements SensorEventListener, switch (state.getAction()) { case StateEvent.ACTION_CONNECTED: Log.i(TAG, "Moga Connected"); + if (mController.getState(Controller.STATE_CURRENT_PRODUCT_VERSION) == Controller.ACTION_VERSION_MOGA) { + NativeApp.sendMessage("moga", "Moga"); + } else { + Log.i(TAG, "MOGA Pro detected"); + isMogaPro = true; + NativeApp.sendMessage("moga", "MogaPro"); + } break; case StateEvent.ACTION_CONNECTING: Log.i(TAG, "Moga Connecting..."); break; case StateEvent.ACTION_DISCONNECTED: Log.i(TAG, "Moga Disconnected (or simply Not connected)"); + NativeApp.sendMessage("moga", ""); break; } break; diff --git a/base/NativeApp.h b/base/NativeApp.h index 16b69cc93c..7c14c0e562 100644 --- a/base/NativeApp.h +++ b/base/NativeApp.h @@ -130,6 +130,7 @@ enum SystemProperty { SYSPROP_SYSTEMVERSION, SYSPROP_DISPLAY_XRES, SYSPROP_DISPLAY_YRES, + SYSPROP_MOGA_VERSION }; std::string System_GetProperty(SystemProperty prop);