summaryrefslogtreecommitdiffstats
path: root/src/android/jar/src/org/qtproject/qt/android/EditPopupMenu.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/android/jar/src/org/qtproject/qt/android/EditPopupMenu.java')
-rw-r--r--src/android/jar/src/org/qtproject/qt/android/EditPopupMenu.java107
1 files changed, 37 insertions, 70 deletions
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 131f2a103f..25be522c48 100644
--- a/src/android/jar/src/org/qtproject/qt/android/EditPopupMenu.java
+++ b/src/android/jar/src/org/qtproject/qt/android/EditPopupMenu.java
@@ -1,70 +1,25 @@
-/****************************************************************************
-**
-** Copyright (C) 2018 BogDan Vatra <bogdan@kde.org>
-** Copyright (C) 2016 Olivier Goffart <ogoffart@woboq.com>
-** Contact: http://www.qt.io/licensing/
-**
-** This file is part of the Android port of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2018 BogDan Vatra <bogdan@kde.org>
+// Copyright (C) 2016 Olivier Goffart <ogoffart@woboq.com>
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
package org.qtproject.qt.android;
+import android.app.Activity;
import android.content.Context;
-import android.os.Bundle;
-import android.util.Log;
-import android.view.LayoutInflater;
+import android.graphics.Point;
import android.view.View;
-import android.widget.LinearLayout;
-import android.widget.ImageView;
-import android.content.res.TypedArray;
-import android.graphics.drawable.Drawable;
-import android.view.MotionEvent;
-import android.widget.PopupWindow;
-import android.app.Activity;
-import android.view.ViewTreeObserver;
-import android.view.View.OnClickListener;
-import android.view.ViewGroup.LayoutParams;
import android.view.ViewGroup;
-import android.R;
+import android.view.ViewTreeObserver;
+import android.widget.PopupWindow;
// Helper class that manages a cursor or selection handle
-public class EditPopupMenu implements ViewTreeObserver.OnPreDrawListener, View.OnLayoutChangeListener,
+class EditPopupMenu implements ViewTreeObserver.OnPreDrawListener, View.OnLayoutChangeListener,
EditContextView.OnClickListener
{
- private View m_layout = null;
- private EditContextView m_view = null;
+ private final View m_layout;
+ private final EditContextView m_view;
private PopupWindow m_popup = null;
+ private final Activity m_activity;
private int m_posX;
private int m_posY;
private int m_buttons;
@@ -74,6 +29,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);
@@ -103,24 +59,35 @@ public class EditPopupMenu implements ViewTreeObserver.OnPreDrawListener, View.O
initOverlay();
m_view.updateButtons(buttons);
- final int[] location = new int[2];
- m_layout.getLocationOnScreen(location);
+ Point viewSize = m_view.getCalculatedSize();
+
+ final int[] layoutLocation = new int[2];
+ m_layout.getLocationOnScreen(layoutLocation);
+
+ // 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 + location[0];
- int y2 = y + location[1];
+ int x2 = x + layoutLocation[0] - activityLocation[0];
+ int y2 = y + layoutLocation[1] + (activityLocationInWindow[1] - activityLocation[1]);
- x2 -= m_view.getWidth() / 2 ;
+ x2 -= viewSize.x / 2 ;
- y2 -= m_view.getHeight();
+ y2 -= viewSize.y;
if (y2 < 0) {
- if (cursorHandle != null)
+ if (cursorHandle != null) {
y2 = cursorHandle.bottom();
- else if (leftSelectionHandle != null && rightSelectionHandle != null)
+ } else if (leftSelectionHandle != null && rightSelectionHandle != null) {
y2 = Math.max(leftSelectionHandle.bottom(), rightSelectionHandle.bottom());
+ if (y2 <= 0)
+ m_layout.requestLayout();
+ }
}
- if (m_layout.getWidth() < x + m_view.getWidth() / 2)
- x2 = m_layout.getWidth() - m_view.getWidth();
+ if (m_layout.getWidth() < x + viewSize.x / 2)
+ x2 = m_layout.getWidth() - viewSize.x;
if (x2 < 0)
x2 = 0;
@@ -168,16 +135,16 @@ public class EditPopupMenu implements ViewTreeObserver.OnPreDrawListener, View.O
@Override
public void contextButtonClicked(int buttonId) {
switch (buttonId) {
- case R.string.cut:
+ case android.R.string.cut:
QtNativeInputConnection.cut();
break;
- case R.string.copy:
+ case android.R.string.copy:
QtNativeInputConnection.copy();
break;
- case R.string.paste:
+ case android.R.string.paste:
QtNativeInputConnection.paste();
break;
- case R.string.selectAll:
+ case android.R.string.selectAll:
QtNativeInputConnection.selectAll();
break;
}