diff --git a/src/android/jar/src/org/qtproject/qt/android/QtEmbeddedDelegate.java b/src/android/jar/src/org/qtproject/qt/android/QtEmbeddedDelegate.java index 1c0fd0f7d83..5545b0a09d4 100644 --- a/src/android/jar/src/org/qtproject/qt/android/QtEmbeddedDelegate.java +++ b/src/android/jar/src/org/qtproject/qt/android/QtEmbeddedDelegate.java @@ -24,13 +24,9 @@ import java.util.HashMap; class QtEmbeddedDelegate extends QtActivityDelegateBase implements QtNative.AppStateDetailsListener { // TODO simplistic implementation with one QtView, expand to support multiple views QTBUG-117649 private QtView m_view; - private long m_rootWindowRef = 0L; private QtNative.ApplicationStateDetails m_stateDetails; private boolean m_windowLoaded = false; - private static native void createRootWindow(View rootView, int x, int y, int width, int height); - static native void deleteWindow(long windowReference); - public QtEmbeddedDelegate(Activity context) { super(context); @@ -82,7 +78,6 @@ class QtEmbeddedDelegate extends QtActivityDelegateBase implements QtNative.AppS QtNative.terminateQt(); QtNative.setActivity(null); QtNative.getQtThread().exit(); - onDestroy(); } } }); @@ -154,20 +149,10 @@ class QtEmbeddedDelegate extends QtActivityDelegateBase implements QtNative.AppS m_inputDelegate.setEditPopupMenu(new EditPopupMenu(m_activity, m_view)); } - - public void setRootWindowRef(long ref) { - m_rootWindowRef = ref; - } - - public void onDestroy() { - if (m_rootWindowRef != 0L) - deleteWindow(m_rootWindowRef); - m_rootWindowRef = 0L; - } - private void createRootWindow() { if (m_view != null && !m_windowLoaded) { - createRootWindow(m_view, m_view.getLeft(), m_view.getTop(), m_view.getWidth(), m_view.getHeight()); + QtView.createRootWindow(m_view, m_view.getLeft(), m_view.getTop(), m_view.getWidth(), + m_view.getHeight()); m_windowLoaded = true; } } diff --git a/src/android/jar/src/org/qtproject/qt/android/QtView.java b/src/android/jar/src/org/qtproject/qt/android/QtView.java index 6836171187e..b253548a5c9 100644 --- a/src/android/jar/src/org/qtproject/qt/android/QtView.java +++ b/src/android/jar/src/org/qtproject/qt/android/QtView.java @@ -29,6 +29,7 @@ abstract class QtView extends ViewGroup { protected QtWindow m_window; protected long m_windowReference; + protected long m_parentWindowReference; protected QtWindowListener m_windowListener; protected QtEmbeddedDelegate m_delegate; // Implement in subclass to handle the creation of the QWindow and its parent container. @@ -37,6 +38,8 @@ abstract class QtView extends ViewGroup { // too much JNI back and forth. Related to parent window creation, so handle with QTBUG-121511. abstract protected void createWindow(long parentWindowRef); + static native void createRootWindow(View rootView, int x, int y, int width, int height); + static native void deleteWindow(long windowReference); private static native void setWindowVisible(long windowReference, boolean visible); private static native void resizeWindow(long windowReference, int x, int y, int width, int height); @@ -156,7 +159,7 @@ abstract class QtView extends ViewGroup { // viewReference - the reference to the created QQuickView void addQtWindow(QtWindow window, long viewReference, long parentWindowRef) { setWindowReference(viewReference); - m_delegate.setRootWindowRef(parentWindowRef); + m_parentWindowReference = parentWindowRef; final Handler handler = new Handler(Looper.getMainLooper()); handler.post(new Runnable() { @Override @@ -176,9 +179,9 @@ abstract class QtView extends ViewGroup { // Destroy the underlying QWindow void destroyWindow() { - if (m_windowReference != 0L) - QtEmbeddedDelegate.deleteWindow(m_windowReference); - m_windowReference = 0L; + if (m_parentWindowReference != 0L) + deleteWindow(m_parentWindowReference); + m_parentWindowReference = 0L; } QtWindow getQtWindow() { diff --git a/src/plugins/platforms/android/androidwindowembedding.cpp b/src/plugins/platforms/android/androidwindowembedding.cpp index 230776f5713..65dabcac662 100644 --- a/src/plugins/platforms/android/androidwindowembedding.cpp +++ b/src/plugins/platforms/android/androidwindowembedding.cpp @@ -12,7 +12,6 @@ QT_BEGIN_NAMESPACE Q_DECLARE_JNI_CLASS(QtView, "org/qtproject/qt/android/QtView"); -Q_DECLARE_JNI_CLASS(QtEmbeddedDelegate, "org/qtproject/qt/android/QtEmbeddedDelegate"); namespace QtAndroidWindowEmbedding { void createRootWindow(JNIEnv *, jclass, QtJniTypes::View rootView, @@ -59,16 +58,12 @@ namespace QtAndroidWindowEmbedding { } bool registerNatives(QJniEnvironment& env) { - using namespace QtJniTypes; - bool success = env.registerNativeMethods(Traits::className(), - {Q_JNI_NATIVE_SCOPED_METHOD(createRootWindow, QtAndroidWindowEmbedding), - Q_JNI_NATIVE_SCOPED_METHOD(deleteWindow, QtAndroidWindowEmbedding)}); - - success &= env.registerNativeMethods(Traits::className(), - {Q_JNI_NATIVE_SCOPED_METHOD(setWindowVisible, QtAndroidWindowEmbedding), - Q_JNI_NATIVE_SCOPED_METHOD(resizeWindow, QtAndroidWindowEmbedding)}); - return success; - + return env.registerNativeMethods( + QtJniTypes::Traits::className(), + { Q_JNI_NATIVE_SCOPED_METHOD(createRootWindow, QtAndroidWindowEmbedding), + Q_JNI_NATIVE_SCOPED_METHOD(deleteWindow, QtAndroidWindowEmbedding), + Q_JNI_NATIVE_SCOPED_METHOD(setWindowVisible, QtAndroidWindowEmbedding), + Q_JNI_NATIVE_SCOPED_METHOD(resizeWindow, QtAndroidWindowEmbedding) }); } }