summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTinja Paavoseppä <[email protected]>2024-02-23 14:41:30 +0200
committerTinja Paavoseppä <[email protected]>2024-03-13 15:50:14 +0000
commit7942f7eedf4a8d7fac82737ea490f3c443e82149 (patch)
tree1606580e783377ff5026be12687f096f9649ae2d
parentd899cdb3a4dc9eb1ad489f7541244110e7e80f61 (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 Pick-to: 6.7 Change-Id: I7bfbca149f927718d1e28cdabfa8759afbd06039 Reviewed-by: Assam Boudjelthia <[email protected]>
-rw-r--r--src/android/jar/src/org/qtproject/qt/android/QtView.java15
-rw-r--r--src/plugins/platforms/android/androidwindowembedding.cpp10
-rw-r--r--src/plugins/platforms/android/androidwindowembedding.h2
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 9a43b8aa743..d7c2ad5bcf1 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 7d82ac6d87e..e72bb326ccc 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 f9d92d4afc1..4f3261a30bd 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