From 3674718e3d7a030a774d53630888e424139df79b Mon Sep 17 00:00:00 2001 From: BogDan Vatra Date: Thu, 15 Oct 2015 08:41:09 +0300 Subject: Dispatch all key and all generic motion events java objects to QtCore These events are needed to enable the usage of all input methods available on Android e.g. gamepads, stylus, etc. In orer to get GenericMotionEvents your application min API version must be at least 12, otherwise the application will receive only key events. Change-Id: I7564fccaf5423aa318ba4f62317eaf101ba6e97e Reviewed-by: Eskil Abrahamsen Blomfeldt --- .../qtproject/qt5/android/QtActivityDelegate.java | 25 ++++++++++++++++++++++ .../src/org/qtproject/qt5/android/QtNative.java | 6 ++++++ 2 files changed, 31 insertions(+) (limited to 'src/android') diff --git a/src/android/jar/src/org/qtproject/qt5/android/QtActivityDelegate.java b/src/android/jar/src/org/qtproject/qt5/android/QtActivityDelegate.java index ee196f1aef..871f9ae2c2 100644 --- a/src/android/jar/src/org/qtproject/qt5/android/QtActivityDelegate.java +++ b/src/android/jar/src/org/qtproject/qt5/android/QtActivityDelegate.java @@ -59,6 +59,7 @@ import android.view.KeyCharacterMap; import android.view.KeyEvent; import android.view.Menu; import android.view.MenuItem; +import android.view.MotionEvent; import android.view.Surface; import android.view.View; import android.view.ViewConfiguration; @@ -89,6 +90,7 @@ public class QtActivityDelegate private Method m_super_onKeyUp = null; private Method m_super_onConfigurationChanged = null; private Method m_super_onActivityResult = null; + private Method m_super_dispatchGenericMotionEvent = null; private static final String NATIVE_LIBRARIES_KEY = "native.libraries"; private static final String BUNDLED_LIBRARIES_KEY = "bundled.libraries"; @@ -475,6 +477,13 @@ public class QtActivityDelegate m_super_onKeyUp = m_activity.getClass().getMethod("super_onKeyUp", Integer.TYPE, KeyEvent.class); m_super_onConfigurationChanged = m_activity.getClass().getMethod("super_onConfigurationChanged", Configuration.class); m_super_onActivityResult = m_activity.getClass().getMethod("super_onActivityResult", Integer.TYPE, Integer.TYPE, Intent.class); + if (Build.VERSION.SDK_INT >= 12) { + try { + m_super_dispatchGenericMotionEvent = m_activity.getClass().getMethod("super_dispatchGenericMotionEvent", MotionEvent.class); + } catch (Exception e) { + } + } + } catch (Exception e) { e.printStackTrace(); return false; @@ -1043,6 +1052,9 @@ public class QtActivityDelegate QtNative.keyUp(0, event.getCharacters().charAt(0), event.getMetaState(), event.getRepeatCount() > 0); } + if (QtNative.dispatchKeyEvent(event)) + return true; + try { return (Boolean) m_super_dispatchKeyEvent.invoke(m_activity, event); } catch (Exception e) { @@ -1311,4 +1323,17 @@ public class QtActivityDelegate m_layout.moveChild(view, index); } } + + public boolean dispatchGenericMotionEvent (MotionEvent ev) + { + if (m_started && QtNative.dispatchGenericMotionEvent(ev)) + return true; + + try { + return (Boolean) m_super_dispatchGenericMotionEvent.invoke(m_activity, ev); + } catch (Exception e) { + e.printStackTrace(); + } + return false; + } } diff --git a/src/android/jar/src/org/qtproject/qt5/android/QtNative.java b/src/android/jar/src/org/qtproject/qt5/android/QtNative.java index 0c01e67637..94e0e4e92b 100644 --- a/src/android/jar/src/org/qtproject/qt5/android/QtNative.java +++ b/src/android/jar/src/org/qtproject/qt5/android/QtNative.java @@ -48,6 +48,7 @@ import android.text.ClipboardManager; import android.os.Build; import android.util.Log; import android.view.ContextMenu; +import android.view.KeyEvent; import android.view.Menu; import android.view.MotionEvent; import android.view.View; @@ -633,6 +634,11 @@ public class QtNative public static native void keyboardVisibilityChanged(boolean visibility); // keyboard methods + // dispatch events methods + public static native boolean dispatchGenericMotionEvent(MotionEvent ev); + public static native boolean dispatchKeyEvent(KeyEvent event); + // dispatch events methods + // surface methods public static native void setSurface(int id, Object surface, int w, int h); // surface methods -- cgit v1.2.3