diff --git a/src/Joystick/JoystickAndroid.cc b/src/Joystick/JoystickAndroid.cc index 19fc106..7f77b79 100644 --- a/src/Joystick/JoystickAndroid.cc +++ b/src/Joystick/JoystickAndroid.cc @@ -211,9 +211,7 @@ static JoystickManager *_manager = nullptr; //helper method bool JoystickAndroid::init(JoystickManager *manager) { - if (_manager == nullptr) { - setNativeMethods(manager); - } + _manager = manager; //this gets list of all possible buttons - this is needed to check how many buttons our gamepad supports //instead of the whole logic below we could have just a simple array of hardcoded int values as these 'should' not change @@ -267,12 +265,10 @@ static void jniUpdateAvailableJoysticks(JNIEnv *envA, jobject thizA) } } -void JoystickAndroid::setNativeMethods(JoystickManager *manager) +void JoystickAndroid::setNativeMethods() { qCDebug(JoystickLog) << "Registering Native Functions"; - _manager = manager; - // REGISTER THE C++ FUNCTION WITH JNI JNINativeMethod javaMethods[] { {"nativeUpdateAvailableJoysticks", "()V", reinterpret_cast(jniUpdateAvailableJoysticks)} diff --git a/src/Joystick/JoystickAndroid.h b/src/Joystick/JoystickAndroid.h index 329194e..1a0afbd 100644 --- a/src/Joystick/JoystickAndroid.h +++ b/src/Joystick/JoystickAndroid.h @@ -21,14 +21,14 @@ public: static bool init(JoystickManager *manager); + static void setNativeMethods(); + static QMap discover(MultiVehicleManager* _multiVehicleManager); private: bool handleKeyEvent(jobject event); bool handleGenericMotionEvent(jobject event); - static void setNativeMethods(JoystickManager *manager); - virtual bool _open(); virtual void _close(); virtual bool _update(); diff --git a/src/main.cc b/src/main.cc index 26afa36..c65c971 100644 --- a/src/main.cc +++ b/src/main.cc @@ -78,9 +78,12 @@ int WindowsCrtReportHook(int reportType, char* message, int* returnValue) #endif -#if defined(__android__) && !defined(NO_SERIAL_LINK) +#if defined(__android__) #include +#include "JoystickAndroid.h" +#if !defined(NO_SERIAL_LINK) #include "qserialport.h" +#endif jint JNI_OnLoad(JavaVM* vm, void* reserved) { @@ -90,8 +93,10 @@ jint JNI_OnLoad(JavaVM* vm, void* reserved) if (vm->GetEnv(reinterpret_cast(&env), JNI_VERSION_1_6) != JNI_OK) { return -1; } - + #if !defined(NO_SERIAL_LINK) QSerialPort::setNativeMethods(); + #endif + JoystickAndroid::setNativeMethods(); return JNI_VERSION_1_6; }