Commit a7381c4e authored by Matej Frančeškin's avatar Matej Frančeškin

Make Android Joystick init behave in the same was as for SDL

parent 98643b5f
...@@ -76,8 +76,6 @@ QMap<QString, Joystick*> JoystickAndroid::discover(MultiVehicleManager* _multiVe ...@@ -76,8 +76,6 @@ QMap<QString, Joystick*> JoystickAndroid::discover(MultiVehicleManager* _multiVe
bool joystickFound = false; bool joystickFound = false;
static QMap<QString, Joystick*> ret; static QMap<QString, Joystick*> ret;
_initStatic(); //it's enough to run it once, should be in a static constructor
QMutexLocker lock(&m_mutex); QMutexLocker lock(&m_mutex);
QAndroidJniEnvironment env; QAndroidJniEnvironment env;
...@@ -194,7 +192,7 @@ uint8_t JoystickAndroid::_getHat(int hat,int i) { ...@@ -194,7 +192,7 @@ uint8_t JoystickAndroid::_getHat(int hat,int i) {
} }
//helper method //helper method
void JoystickAndroid::_initStatic() { bool JoystickAndroid::init() {
//this gets list of all possible buttons - this is needed to check how many buttons our gamepad supports //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 //instead of the whole logic below we could have just a simple array of hardcoded int values as these 'should' not change
...@@ -229,5 +227,7 @@ void JoystickAndroid::_initStatic() { ...@@ -229,5 +227,7 @@ void JoystickAndroid::_initStatic() {
ACTION_DOWN = QAndroidJniObject::getStaticField<jint>("android/view/KeyEvent", "ACTION_DOWN"); ACTION_DOWN = QAndroidJniObject::getStaticField<jint>("android/view/KeyEvent", "ACTION_DOWN");
ACTION_UP = QAndroidJniObject::getStaticField<jint>("android/view/KeyEvent", "ACTION_UP"); ACTION_UP = QAndroidJniObject::getStaticField<jint>("android/view/KeyEvent", "ACTION_UP");
return true;
} }
...@@ -16,9 +16,12 @@ class JoystickAndroid : public Joystick, public QtAndroidPrivate::GenericMotionE ...@@ -16,9 +16,12 @@ class JoystickAndroid : public Joystick, public QtAndroidPrivate::GenericMotionE
{ {
public: public:
JoystickAndroid(const QString& name, int axisCount, int buttonCount, int id, MultiVehicleManager* multiVehicleManager); JoystickAndroid(const QString& name, int axisCount, int buttonCount, int id, MultiVehicleManager* multiVehicleManager);
~JoystickAndroid(); ~JoystickAndroid();
static QMap<QString, Joystick*> discover(MultiVehicleManager* _multiVehicleManager); static bool init();
static QMap<QString, Joystick*> discover(MultiVehicleManager* _multiVehicleManager);
private: private:
bool handleKeyEvent(jobject event); bool handleKeyEvent(jobject event);
...@@ -37,7 +40,6 @@ private: ...@@ -37,7 +40,6 @@ private:
bool *btnValue; bool *btnValue;
int *axisValue; int *axisValue;
static void _initStatic();
static int * _androidBtnList; //list of all possible android buttons static int * _androidBtnList; //list of all possible android buttons
static int _androidBtnListCount; static int _androidBtnListCount;
......
...@@ -60,8 +60,11 @@ void JoystickManager::init() { ...@@ -60,8 +60,11 @@ void JoystickManager::init() {
_joystickCheckTimer.start(250); _joystickCheckTimer.start(250);
} }
#elif defined(__android__) #elif defined(__android__)
_setActiveJoystickFromSettings(); if (JoystickAndroid::init()) {
//TODO: Investigate Android events for Joystick hot plugging & run _joystickCheckTimer if possible _setActiveJoystickFromSettings();
connect(&_joystickCheckTimer, &QTimer::timeout, this, &JoystickManager::_updateAvailableJoysticks);
_joystickCheckTimer.start(250);
}
#endif #endif
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment