diff options
author | Tinja Paavoseppä <tinja.paavoseppa@qt.io> | 2024-02-23 14:41:30 +0200 |
---|---|---|
committer | Tinja Paavoseppä <tinja.paavoseppa@qt.io> | 2024-03-07 12:39:37 +0000 |
commit | 1e96139cf273d144e6d90b4b925f7b8670a5f788 (patch) | |
tree | 9110e03da0b469f397afd4a26d0665c0e3fd83a3 | |
parent | 0533f7c075863b7c1541a5caa8340158923a8569 (diff) |
Android: Resize QWindow when its QtView is resized
If the Android View is resized, the QWindow instantiated by it
should be resized accordingly.
Task-number: QTBUG-122626
Change-Id: I7bfbca149f927718d1e28cdabfa8759afbd06039
Reviewed-by: Tinja Paavoseppä <tinja.paavoseppa@qt.io>
3 files changed, 26 insertions, 1 deletions
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 9a43b8aa74..d7c2ad5bcf 100644 --- a/src/android/jar/src/org/qtproject/qt/android/QtView.java +++ b/src/android/jar/src/org/qtproject/qt/android/QtView.java @@ -40,6 +40,7 @@ abstract class QtView extends QtLayout { abstract protected void createWindow(long parentWindowRef); private static native void setWindowVisible(long windowReference, boolean visible); + private static native void resizeWindow(long windowReference, int width, int height); /** * Create QtView for embedding a QWindow. Instantiating a QtView will load the Qt libraries @@ -59,6 +60,20 @@ abstract class QtView extends QtLayout { QtEmbeddedLoader loader = new QtEmbeddedLoader(context); m_delegate = QtEmbeddedDelegateFactory.create((Activity)context); loader.setMainLibraryName(appLibName); + addOnLayoutChangeListener(new View.OnLayoutChangeListener() { + @Override + public void onLayoutChange(View v, int left, int top, int right, int bottom, + int oldLeft, int oldTop, int oldRight, int oldBottom) { + if (m_windowReference != 0L) { + final int oldWidth = oldRight - oldLeft; + final int oldHeight = oldBottom - oldTop; + final int newWidth = right - left; + final int newHeight = bottom - top; + if (oldWidth != newWidth || oldHeight != newHeight) + resizeWindow(m_windowReference, right - left, bottom - top); + } + } + }); loader.loadQtLibraries(); // Start Native Qt application m_delegate.startNativeApplication(loader.getApplicationParameters(), diff --git a/src/plugins/platforms/android/androidwindowembedding.cpp b/src/plugins/platforms/android/androidwindowembedding.cpp index 7d82ac6d87..e72bb326cc 100644 --- a/src/plugins/platforms/android/androidwindowembedding.cpp +++ b/src/plugins/platforms/android/androidwindowembedding.cpp @@ -45,6 +45,13 @@ namespace QtAndroidWindowEmbedding { }); } + void resizeWindow(JNIEnv *, jclass, jlong windowRef, jint width, jint height) + { + QWindow *window = reinterpret_cast<QWindow*>(windowRef); + window->setWidth(width); + window->setHeight(height); + } + bool registerNatives(QJniEnvironment& env) { using namespace QtJniTypes; bool success = env.registerNativeMethods(Traits<QtEmbeddedDelegate>::className(), @@ -52,7 +59,8 @@ namespace QtAndroidWindowEmbedding { Q_JNI_NATIVE_SCOPED_METHOD(deleteWindow, QtAndroidWindowEmbedding)}); success &= env.registerNativeMethods(Traits<QtView>::className(), - {Q_JNI_NATIVE_SCOPED_METHOD(setWindowVisible, QtAndroidWindowEmbedding)}); + {Q_JNI_NATIVE_SCOPED_METHOD(setWindowVisible, QtAndroidWindowEmbedding), + Q_JNI_NATIVE_SCOPED_METHOD(resizeWindow, QtAndroidWindowEmbedding)}); return success; } diff --git a/src/plugins/platforms/android/androidwindowembedding.h b/src/plugins/platforms/android/androidwindowembedding.h index f9d92d4afc..4f3261a30b 100644 --- a/src/plugins/platforms/android/androidwindowembedding.h +++ b/src/plugins/platforms/android/androidwindowembedding.h @@ -31,6 +31,8 @@ namespace QtAndroidWindowEmbedding Q_DECLARE_JNI_NATIVE_METHOD_IN_CURRENT_SCOPE(deleteWindow) void setWindowVisible(JNIEnv *, jclass, jlong window, jboolean visible); Q_DECLARE_JNI_NATIVE_METHOD_IN_CURRENT_SCOPE(setWindowVisible) + void resizeWindow(JNIEnv *, jclass, jlong windowRef, jint width, jint height); + Q_DECLARE_JNI_NATIVE_METHOD_IN_CURRENT_SCOPE(resizeWindow) }; QT_END_NAMESPACE |