Android: Delete parent window in QtView instead of just the child view
Since the parent window wraps the QtView, it should always be destroyed when the QtView is, and live inside QtView rather than the delegate. Destroying the parent window will always destroy the child window, so do not destroy the child window separately. Move createRootWindow and deleteWindow native functions to QtView. Fixes: QTBUG-124908 Change-Id: Ib6b3c6388a9dd3f74d16fa09a442b0a6f8ccb336 Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
This commit is contained in:
parent
6d2db42f7c
commit
9ef4435fbf
@ -24,13 +24,9 @@ import java.util.HashMap;
|
|||||||
class QtEmbeddedDelegate extends QtActivityDelegateBase implements QtNative.AppStateDetailsListener {
|
class QtEmbeddedDelegate extends QtActivityDelegateBase implements QtNative.AppStateDetailsListener {
|
||||||
// TODO simplistic implementation with one QtView, expand to support multiple views QTBUG-117649
|
// TODO simplistic implementation with one QtView, expand to support multiple views QTBUG-117649
|
||||||
private QtView m_view;
|
private QtView m_view;
|
||||||
private long m_rootWindowRef = 0L;
|
|
||||||
private QtNative.ApplicationStateDetails m_stateDetails;
|
private QtNative.ApplicationStateDetails m_stateDetails;
|
||||||
private boolean m_windowLoaded = false;
|
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) {
|
public QtEmbeddedDelegate(Activity context) {
|
||||||
super(context);
|
super(context);
|
||||||
|
|
||||||
@ -82,7 +78,6 @@ class QtEmbeddedDelegate extends QtActivityDelegateBase implements QtNative.AppS
|
|||||||
QtNative.terminateQt();
|
QtNative.terminateQt();
|
||||||
QtNative.setActivity(null);
|
QtNative.setActivity(null);
|
||||||
QtNative.getQtThread().exit();
|
QtNative.getQtThread().exit();
|
||||||
onDestroy();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -154,20 +149,10 @@ class QtEmbeddedDelegate extends QtActivityDelegateBase implements QtNative.AppS
|
|||||||
m_inputDelegate.setEditPopupMenu(new EditPopupMenu(m_activity, m_view));
|
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() {
|
private void createRootWindow() {
|
||||||
if (m_view != null && !m_windowLoaded) {
|
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;
|
m_windowLoaded = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -29,6 +29,7 @@ abstract class QtView extends ViewGroup {
|
|||||||
|
|
||||||
protected QtWindow m_window;
|
protected QtWindow m_window;
|
||||||
protected long m_windowReference;
|
protected long m_windowReference;
|
||||||
|
protected long m_parentWindowReference;
|
||||||
protected QtWindowListener m_windowListener;
|
protected QtWindowListener m_windowListener;
|
||||||
protected QtEmbeddedDelegate m_delegate;
|
protected QtEmbeddedDelegate m_delegate;
|
||||||
// Implement in subclass to handle the creation of the QWindow and its parent container.
|
// 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.
|
// too much JNI back and forth. Related to parent window creation, so handle with QTBUG-121511.
|
||||||
abstract protected void createWindow(long parentWindowRef);
|
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 setWindowVisible(long windowReference, boolean visible);
|
||||||
private static native void resizeWindow(long windowReference,
|
private static native void resizeWindow(long windowReference,
|
||||||
int x, int y, int width, int height);
|
int x, int y, int width, int height);
|
||||||
@ -156,7 +159,7 @@ abstract class QtView extends ViewGroup {
|
|||||||
// viewReference - the reference to the created QQuickView
|
// viewReference - the reference to the created QQuickView
|
||||||
void addQtWindow(QtWindow window, long viewReference, long parentWindowRef) {
|
void addQtWindow(QtWindow window, long viewReference, long parentWindowRef) {
|
||||||
setWindowReference(viewReference);
|
setWindowReference(viewReference);
|
||||||
m_delegate.setRootWindowRef(parentWindowRef);
|
m_parentWindowReference = parentWindowRef;
|
||||||
final Handler handler = new Handler(Looper.getMainLooper());
|
final Handler handler = new Handler(Looper.getMainLooper());
|
||||||
handler.post(new Runnable() {
|
handler.post(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
@ -176,9 +179,9 @@ abstract class QtView extends ViewGroup {
|
|||||||
|
|
||||||
// Destroy the underlying QWindow
|
// Destroy the underlying QWindow
|
||||||
void destroyWindow() {
|
void destroyWindow() {
|
||||||
if (m_windowReference != 0L)
|
if (m_parentWindowReference != 0L)
|
||||||
QtEmbeddedDelegate.deleteWindow(m_windowReference);
|
deleteWindow(m_parentWindowReference);
|
||||||
m_windowReference = 0L;
|
m_parentWindowReference = 0L;
|
||||||
}
|
}
|
||||||
|
|
||||||
QtWindow getQtWindow() {
|
QtWindow getQtWindow() {
|
||||||
|
@ -12,7 +12,6 @@
|
|||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
|
|
||||||
Q_DECLARE_JNI_CLASS(QtView, "org/qtproject/qt/android/QtView");
|
Q_DECLARE_JNI_CLASS(QtView, "org/qtproject/qt/android/QtView");
|
||||||
Q_DECLARE_JNI_CLASS(QtEmbeddedDelegate, "org/qtproject/qt/android/QtEmbeddedDelegate");
|
|
||||||
|
|
||||||
namespace QtAndroidWindowEmbedding {
|
namespace QtAndroidWindowEmbedding {
|
||||||
void createRootWindow(JNIEnv *, jclass, QtJniTypes::View rootView,
|
void createRootWindow(JNIEnv *, jclass, QtJniTypes::View rootView,
|
||||||
@ -59,16 +58,12 @@ namespace QtAndroidWindowEmbedding {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool registerNatives(QJniEnvironment& env) {
|
bool registerNatives(QJniEnvironment& env) {
|
||||||
using namespace QtJniTypes;
|
return env.registerNativeMethods(
|
||||||
bool success = env.registerNativeMethods(Traits<QtEmbeddedDelegate>::className(),
|
QtJniTypes::Traits<QtJniTypes::QtView>::className(),
|
||||||
{ Q_JNI_NATIVE_SCOPED_METHOD(createRootWindow, QtAndroidWindowEmbedding),
|
{ Q_JNI_NATIVE_SCOPED_METHOD(createRootWindow, QtAndroidWindowEmbedding),
|
||||||
Q_JNI_NATIVE_SCOPED_METHOD(deleteWindow, QtAndroidWindowEmbedding)});
|
Q_JNI_NATIVE_SCOPED_METHOD(deleteWindow, QtAndroidWindowEmbedding),
|
||||||
|
Q_JNI_NATIVE_SCOPED_METHOD(setWindowVisible, QtAndroidWindowEmbedding),
|
||||||
success &= env.registerNativeMethods(Traits<QtView>::className(),
|
|
||||||
{Q_JNI_NATIVE_SCOPED_METHOD(setWindowVisible, QtAndroidWindowEmbedding),
|
|
||||||
Q_JNI_NATIVE_SCOPED_METHOD(resizeWindow, QtAndroidWindowEmbedding) });
|
Q_JNI_NATIVE_SCOPED_METHOD(resizeWindow, QtAndroidWindowEmbedding) });
|
||||||
return success;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user