summaryrefslogtreecommitdiffstats
path: root/src/android/jar
diff options
context:
space:
mode:
authorTinja Paavoseppä <tinja.paavoseppa@qt.io>2024-03-27 11:03:41 +0200
committerTinja Paavoseppä <tinja.paavoseppa@qt.io>2024-04-04 15:46:44 +0200
commitc4a98a729898b7bf2244675f8ba91933f9ae8b93 (patch)
treea8be7a61a4d6a4a197af4b139d6adbd20ab300d7 /src/android/jar
parentb3685743f31daef71021d9948deaf20ce34ce57a (diff)
Android: Make QtView extend ViewGroup instead of QtLayout
QtView should only have one child, the QtWindow, and that should always match the QtView's size, so the handling for absolute layout is unnecessary. Task-number: QTBUG-121516 Task-number: QTBUG-123306 Pick-to: 6.7 Change-Id: I77024ab9619e68ab98357518ad07535a2ff9614c Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
Diffstat (limited to 'src/android/jar')
-rw-r--r--src/android/jar/src/org/qtproject/qt/android/QtEmbeddedDelegate.java4
-rw-r--r--src/android/jar/src/org/qtproject/qt/android/QtView.java47
2 files changed, 46 insertions, 5 deletions
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 74617706f9..8bf44bb16a 100644
--- a/src/android/jar/src/org/qtproject/qt/android/QtEmbeddedDelegate.java
+++ b/src/android/jar/src/org/qtproject/qt/android/QtEmbeddedDelegate.java
@@ -126,7 +126,9 @@ class QtEmbeddedDelegate extends QtActivityDelegateBase implements QtNative.AppS
// TODO verify if returning m_view here works, this is used by the androidjniinput
// when e.g. showing a keyboard, so depends on getting the keyboard focus working
// QTBUG-118873
- return m_view;
+ if (m_view == null)
+ return null;
+ return m_view.getQtWindow();
}
public void queueLoadWindow()
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 d7c2ad5bcf..afd3030804 100644
--- a/src/android/jar/src/org/qtproject/qt/android/QtView.java
+++ b/src/android/jar/src/org/qtproject/qt/android/QtView.java
@@ -16,11 +16,9 @@ import android.view.ViewGroup;
import java.security.InvalidParameterException;
import java.util.ArrayList;
-// TODO this should not need to extend QtLayout, a simple FrameLayout/ViewGroup should do
-// QTBUG-121516
// Base class for embedding QWindow into native Android view hierarchy. Extend to implement
// the creation of appropriate window to embed.
-abstract class QtView extends QtLayout {
+abstract class QtView extends ViewGroup {
private final static String TAG = "QtView";
public interface QtWindowListener {
@@ -94,6 +92,43 @@ abstract class QtView extends QtLayout {
m_delegate.setView(null);
}
+ @Override
+ public void onLayout(boolean changed, int l, int t, int r, int b) {
+ if (m_window != null)
+ m_window.layout(0 /* left */, 0 /* top */, r - l /* right */, b - t /* bottom */);
+ }
+
+ @Override
+ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
+ {
+ measureChildren(widthMeasureSpec, heightMeasureSpec);
+
+ final int count = getChildCount();
+
+ int maxHeight = 0;
+ int maxWidth = 0;
+
+ // Find out how big everyone wants to be
+ measureChildren(widthMeasureSpec, heightMeasureSpec);
+
+ // Find rightmost and bottom-most child
+ for (int i = 0; i < count; i++) {
+ View child = getChildAt(i);
+ if (child.getVisibility() != GONE) {
+ maxWidth = Math.max(maxWidth, child.getMeasuredWidth());
+ maxHeight = Math.max(maxHeight, child.getMeasuredHeight());
+ }
+ }
+
+ // Check against minimum height and width
+ maxHeight = Math.max(maxHeight, getSuggestedMinimumHeight());
+ maxWidth = Math.max(maxWidth, getSuggestedMinimumWidth());
+
+ setMeasuredDimension(resolveSize(maxWidth, widthMeasureSpec),
+ resolveSize(maxHeight, heightMeasureSpec));
+ }
+
+
public void setQtWindowListener(QtWindowListener listener) {
m_windowListener = listener;
}
@@ -124,7 +159,7 @@ abstract class QtView extends QtLayout {
@Override
public void run() {
m_window = window;
- m_window.setLayoutParams(new QtLayout.LayoutParams(
+ m_window.setLayoutParams(new ViewGroup.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT));
addView(m_window, 0);
@@ -142,4 +177,8 @@ abstract class QtView extends QtLayout {
QtEmbeddedDelegate.deleteWindow(m_windowReference);
m_windowReference = 0L;
}
+
+ QtWindow getQtWindow() {
+ return m_window;
+ }
}