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 ++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'src/android/jar/src/org/qtproject/qt5/android/QtActivityDelegate.java') 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; + } } -- cgit v1.2.3 From c63f4c5d015e265f7e7c0cd410787470e66f00e4 Mon Sep 17 00:00:00 2001 From: BogDan Vatra Date: Thu, 28 May 2015 10:55:12 +0300 Subject: Android: Set "immersive" mode on earlier android versions. Most of "immersive" flags are available on earlier Android versions. Change-Id: Ic4f03a3c9491570bc5f8c5afbb61669644b20d8e Reviewed-by: Christian Stromme --- .../qtproject/qt5/android/QtActivityDelegate.java | 39 ++++++++++------------ 1 file changed, 17 insertions(+), 22 deletions(-) (limited to 'src/android/jar/src/org/qtproject/qt5/android/QtActivityDelegate.java') 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 871f9ae2c2..064b538e1f 100644 --- a/src/android/jar/src/org/qtproject/qt5/android/QtActivityDelegate.java +++ b/src/android/jar/src/org/qtproject/qt5/android/QtActivityDelegate.java @@ -133,37 +133,32 @@ public class QtActivityDelegate if (m_fullScreen = enterFullScreen) { m_activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); m_activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN); - if (Build.VERSION.SDK_INT >= 19) { - try { - int ui_flag_immersive_sticky = View.class.getDeclaredField("SYSTEM_UI_FLAG_IMMERSIVE_STICKY").getInt(null); - int ui_flag_layout_stable = View.class.getDeclaredField("SYSTEM_UI_FLAG_LAYOUT_STABLE").getInt(null); - int ui_flag_layout_hide_navigation = View.class.getDeclaredField("SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION").getInt(null); - int ui_flag_layout_fullscreen = View.class.getDeclaredField("SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN").getInt(null); - int ui_flag_hide_navigation = View.class.getDeclaredField("SYSTEM_UI_FLAG_HIDE_NAVIGATION").getInt(null); - int ui_flag_fullscreen = View.class.getDeclaredField("SYSTEM_UI_FLAG_FULLSCREEN").getInt(null); - + try { + if (Build.VERSION.SDK_INT >= 14) { + int flags = View.class.getDeclaredField("SYSTEM_UI_FLAG_HIDE_NAVIGATION").getInt(null); + if (Build.VERSION.SDK_INT >= 16) { + flags |= View.class.getDeclaredField("SYSTEM_UI_FLAG_LAYOUT_STABLE").getInt(null); + flags |= View.class.getDeclaredField("SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION").getInt(null); + flags |= View.class.getDeclaredField("SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN").getInt(null); + flags |= View.class.getDeclaredField("SYSTEM_UI_FLAG_FULLSCREEN").getInt(null); + + if (Build.VERSION.SDK_INT >= 19) + flags |= View.class.getDeclaredField("SYSTEM_UI_FLAG_IMMERSIVE_STICKY").getInt(null); + } Method m = View.class.getMethod("setSystemUiVisibility", int.class); - m.invoke(m_activity.getWindow().getDecorView(), - ui_flag_layout_stable - | ui_flag_layout_hide_navigation - | ui_flag_layout_fullscreen - | ui_flag_hide_navigation - | ui_flag_fullscreen - | ui_flag_immersive_sticky - | View.INVISIBLE); - } catch (Exception e) { - e.printStackTrace(); + m.invoke(m_activity.getWindow().getDecorView(), flags | View.INVISIBLE); } + } catch (Exception e) { + e.printStackTrace(); } } else { m_activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN); m_activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); - if (Build.VERSION.SDK_INT >= 19) { + if (Build.VERSION.SDK_INT >= 14) { try { int ui_flag_visible = View.class.getDeclaredField("SYSTEM_UI_FLAG_VISIBLE").getInt(null); Method m = View.class.getMethod("setSystemUiVisibility", int.class); - m.invoke(m_activity.getWindow().getDecorView(), - ui_flag_visible); + m.invoke(m_activity.getWindow().getDecorView(), ui_flag_visible); } catch (Exception e) { e.printStackTrace(); } -- cgit v1.2.3 From f35797991ea450478f4703399a551ca85bde053d Mon Sep 17 00:00:00 2001 From: BogDan Vatra Date: Fri, 16 Oct 2015 17:22:14 +0300 Subject: Android: Make sure we deliver all queued actions when we resume. When the activity is paused, all runOnUi actions are dropped :(, this patch ensures that no action is lost no matter what. Task-number: QTBUG-45526 Change-Id: I61db4f73b0d2da47bf71a1324dc40b90dab01e81 Reviewed-by: Christian Stromme --- .../qtproject/qt5/android/QtActivityDelegate.java | 30 ++++++++-------------- 1 file changed, 10 insertions(+), 20 deletions(-) (limited to 'src/android/jar/src/org/qtproject/qt5/android/QtActivityDelegate.java') 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 064b538e1f..a6067b1a10 100644 --- a/src/android/jar/src/org/qtproject/qt5/android/QtActivityDelegate.java +++ b/src/android/jar/src/org/qtproject/qt5/android/QtActivityDelegate.java @@ -77,7 +77,6 @@ import java.lang.reflect.Constructor; import java.lang.reflect.Method; import java.util.ArrayList; import java.util.HashMap; -import java.util.Iterator; public class QtActivityDelegate { @@ -211,10 +210,10 @@ public class QtActivityDelegate private final int EnterKeyPrevious = 7; // application state - private final int ApplicationSuspended = 0x0; - private final int ApplicationHidden = 0x1; - private final int ApplicationInactive = 0x2; - private final int ApplicationActive = 0x4; + public static final int ApplicationSuspended = 0x0; + public static final int ApplicationHidden = 0x1; + public static final int ApplicationInactive = 0x2; + public static final int ApplicationActive = 0x4; public boolean setKeyboardVisibility(boolean visibility, long timeStamp) @@ -902,24 +901,15 @@ public class QtActivityDelegate public void onPause() { - QtNative.updateApplicationState(ApplicationInactive); + QtNative.setApplicationState(ApplicationInactive); } public void onResume() { - // fire all lostActions - synchronized (QtNative.m_mainActivityMutex) - { - Iterator itr = QtNative.getLostActions().iterator(); - while (itr.hasNext()) - m_activity.runOnUiThread(itr.next()); - - QtNative.updateApplicationState(ApplicationActive); - if (m_started) { - QtNative.clearLostActions(); - QtNative.updateWindow(); - updateFullScreen(); // Suspending the app clears the immersive mode, so we need to set it again. - } + QtNative.setApplicationState(ApplicationActive); + if (m_started) { + QtNative.updateWindow(); + updateFullScreen(); // Suspending the app clears the immersive mode, so we need to set it again. } } @@ -942,7 +932,7 @@ public class QtActivityDelegate public void onStop() { - QtNative.updateApplicationState(ApplicationSuspended); + QtNative.setApplicationState(ApplicationSuspended); } public Object onRetainNonConfigurationInstance() -- cgit v1.2.3