Android: fix wrong position of cursor handle and editpopup menu in split screen

Use activity location in the Window to handling a cursor handle and editpopup menu
in Multi-Window mode. No effect when using full screen.

Fixes: QTBUG-58503
Pick-to: 5.15 6.2 6.3 6.4
Change-Id: I17f3119be4c3dda2fca50156bf62c1260c2ea1f6
Reviewed-by: Samuel Mira <samuel.mira@qt.io>
Reviewed-by: Rami Potinkara <rami.potinkara@qt.io>
Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
This commit is contained in:
Pekka Gehör 2022-06-14 13:43:37 +03:00
parent 526d62ee90
commit c27cca5c34
2 changed files with 16 additions and 6 deletions

View File

@ -126,12 +126,14 @@ public class CursorHandle implements ViewTreeObserver.OnPreDrawListener
final int[] layoutLocation = new int[2];
m_layout.getLocationOnScreen(layoutLocation);
// This value is used for handling split screen case
// These values are used for handling split screen case
final int[] activityLocation = new int[2];
final int[] activityLocationInWindow = new int[2];
m_activity.getWindow().getDecorView().getLocationOnScreen(activityLocation);
m_activity.getWindow().getDecorView().getLocationInWindow(activityLocationInWindow);
int x2 = x + layoutLocation[0] - activityLocation[0];
int y2 = y + layoutLocation[1] + m_yShift - activityLocation[1];
int y2 = y + layoutLocation[1] + m_yShift + (activityLocationInWindow[1] - activityLocation[1]);
if (m_id == QtNative.IdCursorHandle) {
x2 -= m_popup.getWidth() / 2 ;

View File

@ -29,6 +29,7 @@ public class EditPopupMenu implements ViewTreeObserver.OnPreDrawListener, View.O
private View m_layout = null;
private EditContextView m_view = null;
private PopupWindow m_popup = null;
private Activity m_activity;
private int m_posX;
private int m_posY;
private int m_buttons;
@ -38,6 +39,7 @@ public class EditPopupMenu implements ViewTreeObserver.OnPreDrawListener, View.O
public EditPopupMenu(Activity activity, View layout)
{
m_activity = activity;
m_view = new EditContextView(activity, this);
m_view.addOnLayoutChangeListener(this);
@ -67,11 +69,17 @@ public class EditPopupMenu implements ViewTreeObserver.OnPreDrawListener, View.O
initOverlay();
m_view.updateButtons(buttons);
final int[] location = new int[2];
m_layout.getLocationOnScreen(location);
final int[] layoutLocation = new int[2];
m_layout.getLocationOnScreen(layoutLocation);
int x2 = x + location[0];
int y2 = y + location[1];
// These values are used for handling split screen case
final int[] activityLocation = new int[2];
final int[] activityLocationInWindow = new int[2];
m_activity.getWindow().getDecorView().getLocationOnScreen(activityLocation);
m_activity.getWindow().getDecorView().getLocationInWindow(activityLocationInWindow);
int x2 = x + layoutLocation[0] - activityLocation[0];
int y2 = y + layoutLocation[1] + (activityLocationInWindow[1] - activityLocation[1]);
x2 -= m_view.getWidth() / 2 ;