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 e18d0953c39..cbf715ab19f 100644 --- a/src/android/jar/src/org/qtproject/qt/android/QtEmbeddedDelegate.java +++ b/src/android/jar/src/org/qtproject/qt/android/QtEmbeddedDelegate.java @@ -128,7 +128,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 d7c2ad5bcf1..afd30308046 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; + } }