Android: Ensure that Layout params are applied on editText

Make sure that the Layout parameters are applied to the editText
before opening the Popup (in openContextMenu method).
Without them, it may cause incorrect behavior.

Especially in the case of the error:
  "E BufferLayer: dimension too large 212x9957
   E SurfaceFlinger: createBufferLayer() failed (Invalid argument)
   E SurfaceComposerClinet: SurfaceComposerClien::createSurface error
       Invalid argument"

It may cause crash.

Fixes: QTBUG-129770
Change-Id: Ib9ef4b5b77fb1faf196e56431976c2a0e6e4a1e2
Reviewed-by: Petri Virkkunen <petri.virkkunen@qt.io>
Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
(cherry picked from commit 0d4778497ee13f93ecaff9036ee7f5f6d24bb2a3)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Bartlomiej Moskal 2024-10-02 21:21:55 +02:00 committed by Qt Cherry-pick Bot
parent 6f56cc73ce
commit 4cbef8822a

View File

@ -310,13 +310,21 @@ class QtActivityDelegate extends QtActivityDelegateBase
return;
}
m_layout.setLayoutParams(focusedEditText, new QtLayout.LayoutParams(w, h, x, y), false);
PopupMenu popup = new PopupMenu(m_activity, focusedEditText);
QtActivityDelegate.this.onCreatePopupMenu(popup.getMenu());
popup.setOnMenuItemClickListener(menuItem ->
m_activity.onContextItemSelected(menuItem));
popup.setOnDismissListener(popupMenu ->
m_activity.onContextMenuClosed(popupMenu.getMenu()));
popup.show();
focusedEditText.requestLayout();
focusedEditText.getViewTreeObserver().addOnGlobalLayoutListener(
new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
focusedEditText.getViewTreeObserver().removeOnGlobalLayoutListener(this);
PopupMenu popup = new PopupMenu(m_activity, focusedEditText);
QtActivityDelegate.this.onCreatePopupMenu(popup.getMenu());
popup.setOnMenuItemClickListener(menuItem ->
m_activity.onContextItemSelected(menuItem));
popup.setOnDismissListener(popupMenu ->
m_activity.onContextMenuClosed(popupMenu.getMenu()));
popup.show();
}
});
}, 100);
}
// QtMenuInterface implementation end