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
Change-Id: I77024ab9619e68ab98357518ad07535a2ff9614c
Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
(cherry picked from commit c4a98a729898b7bf2244675f8ba91933f9ae8b93)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Tinja Paavoseppä 2024-03-27 11:03:41 +02:00 committed by Qt Cherry-pick Bot
parent 46c639d81f
commit 7da0c6f83e
2 changed files with 46 additions and 5 deletions

View File

@ -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()

View File

@ -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;
}
}