From c27cca5c3421b08253535cfcfb9dd414986c7653 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pekka=20Geh=C3=B6r?= Date: Tue, 14 Jun 2022 13:43:37 +0300 Subject: [PATCH] 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 Reviewed-by: Rami Potinkara Reviewed-by: Assam Boudjelthia --- .../org/qtproject/qt/android/CursorHandle.java | 6 ++++-- .../org/qtproject/qt/android/EditPopupMenu.java | 16 ++++++++++++---- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/android/jar/src/org/qtproject/qt/android/CursorHandle.java b/src/android/jar/src/org/qtproject/qt/android/CursorHandle.java index 0b64f81335..b6d054d600 100644 --- a/src/android/jar/src/org/qtproject/qt/android/CursorHandle.java +++ b/src/android/jar/src/org/qtproject/qt/android/CursorHandle.java @@ -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 ; diff --git a/src/android/jar/src/org/qtproject/qt/android/EditPopupMenu.java b/src/android/jar/src/org/qtproject/qt/android/EditPopupMenu.java index 41dca5f9df..00cbb97561 100644 --- a/src/android/jar/src/org/qtproject/qt/android/EditPopupMenu.java +++ b/src/android/jar/src/org/qtproject/qt/android/EditPopupMenu.java @@ -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 ;