summaryrefslogtreecommitdiffstats
path: root/src/android/java/src/org/qtproject/qt/android/bindings/QtApplication.java
diff options
context:
space:
mode:
authorAssam Boudjelthia <assam.boudjelthia@qt.io>2023-09-15 17:58:02 +0300
committerAssam Boudjelthia <assam.boudjelthia@qt.io>2023-10-12 19:16:47 +0300
commit3b6d288e3bf7a778f3ea8ccf51f59780a6de0dcc (patch)
treee4db31b0e83636aaee316cbff92cd2c40909c8d1 /src/android/java/src/org/qtproject/qt/android/bindings/QtApplication.java
parentbeac5a6d727cb177549ff8e4eb98edef05de6956 (diff)
Android: Simplify Qt for Android hierarchy, less Java reflection!
This changes takes Qt for Android Java code away from the Delegate classes that uses heavily Java reflection to invoke Activity/Service calls and overrides. So instead of that, now, we have a QtActivityBase and a QtServiceBase classes which handle the override logic needed for Qt directly without reflection. These Base classes extend Android's Activity and Service directly, and are inside the internal Qt android package (under Qt6Android.jar). For example, to handle onConfigurationChanged, instead of the current way where we need this in QtActivityDelegate: public void onConfigurationChanged(Configuration configuration) { try { m_super_onConfigurationChanged.invoke(m_activity, configuration); } catch (Exception e) { e.printStackTrace(); } handleUiModeChange(configuration.uiMode & Configuration.UI_MODE_NIGHT_MASK); } And then this in QtActivity: @Override public void onConfigurationChanged(Configuration newConfig) { if (!QtLoader.invokeDelegate(newConfig).invoked) super.onConfigurationChanged(newConfig); } public void super_onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); } And having to keep it's Method handles around and then use Java reflection to call the override behavior done by Qt and the superclass methods. instead of that, we can do it now in QtActivityBase like: @Override public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); handleUiModeChange(newConfig.uiMode & Configuration.UI_MODE_NIGHT_MASK); } Then, we would still have our user facing QtActivity class which extends QtActivityBase and benefit from the same implementation of Qt logic done in the base class. An additional benefit to this approach is that now QtActivity will be very lightweight and doesn't need to have all the boilerplate code as before. [ChangeLog][Android] Simplify Qt for Android public bindings (QActivity, QtService and QtApplication) by implementing base classes which use the delegate implementions directly and avoid reflection. Task-number: QTBUG-115014 Task-number: QTBUG-114593 Change-Id: Ie1eca74f989627be4468786a27e30b16209fc521 Reviewed-by: Tinja Paavoseppä <tinja.paavoseppa@qt.io>
Diffstat (limited to 'src/android/java/src/org/qtproject/qt/android/bindings/QtApplication.java')
-rw-r--r--src/android/java/src/org/qtproject/qt/android/bindings/QtApplication.java22
1 files changed, 2 insertions, 20 deletions
diff --git a/src/android/java/src/org/qtproject/qt/android/bindings/QtApplication.java b/src/android/java/src/org/qtproject/qt/android/bindings/QtApplication.java
index b89946b9a5..d1330565c1 100644
--- a/src/android/java/src/org/qtproject/qt/android/bindings/QtApplication.java
+++ b/src/android/java/src/org/qtproject/qt/android/bindings/QtApplication.java
@@ -4,30 +4,12 @@
package org.qtproject.qt.android.bindings;
-import android.app.Application;
-import org.qtproject.qt.android.QtLoader;
+import org.qtproject.qt.android.QtApplicationBase;
-public class QtApplication extends Application
+public class QtApplication extends QtApplicationBase
{
- public final static String QtTAG = "Qt";
-
@Override
public void onTerminate() {
- if (QtLoader.m_delegateObject != null && QtLoader.m_delegateMethods.containsKey("onTerminate"))
- QtLoader.invokeDelegateMethod(QtLoader.m_delegateMethods.get("onTerminate").get(0));
super.onTerminate();
}
-
- // TODO: only keep around for avoid build errors, will be removed.
- public static class InvokeResult
- {
- public boolean invoked = false;
- public Object methodReturns = null;
- }
-
- public static InvokeResult invokeDelegate(Object... args)
- {
- InvokeResult result = new InvokeResult();
- return result;
- }
}