diff options
author | BogDan Vatra <bogdan@kde.org> | 2015-10-15 08:41:09 +0300 |
---|---|---|
committer | BogDan Vatra <bogdan@kdab.com> | 2015-10-15 13:57:28 +0000 |
commit | 3674718e3d7a030a774d53630888e424139df79b (patch) | |
tree | 08e7f84c9527e768df791d2da7ed4db5ab1e8ba5 /src/android | |
parent | 4f7e0bdc4c18b8d0a1e317ddae2d2caa80b59c8e (diff) |
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 <eskil.abrahamsen-blomfeldt@theqtcompany.com>
Diffstat (limited to 'src/android')
-rw-r--r-- | src/android/jar/src/org/qtproject/qt5/android/QtActivityDelegate.java | 25 | ||||
-rw-r--r-- | src/android/jar/src/org/qtproject/qt5/android/QtNative.java | 6 |
2 files changed, 31 insertions, 0 deletions
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 |