Android: Remove getQtLayout() method

After refactoring the various keyboard input
related Java classes so that they are more contained
inside their respective windows, this method becomes
unnecessary.

Task-number: QTBUG-126180
Change-Id: I608399e98892752182039b8ece60005670da8224
Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
(cherry picked from commit 9ed29c73674939c772cc6b407881935e7fa19bcd)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Tinja Paavoseppä 2024-07-26 12:04:27 +03:00 committed by Qt Cherry-pick Bot
parent 38e8899249
commit e1b7a0d3ee
7 changed files with 17 additions and 52 deletions

View File

@ -44,7 +44,6 @@ set(java_sources
src/org/qtproject/qt/android/QtWindowInterface.java
src/org/qtproject/qt/android/QtAccessibilityInterface.java
src/org/qtproject/qt/android/QtMenuInterface.java
src/org/qtproject/qt/android/QtLayoutInterface.java
src/org/qtproject/qt/android/QtInputInterface.java
src/org/qtproject/qt/android/QtAbstractItemModel.java
src/org/qtproject/qt/android/QtAbstractItemModelProxy.java

View File

@ -31,7 +31,7 @@ import android.widget.PopupMenu;
import java.util.HashMap;
class QtActivityDelegate extends QtActivityDelegateBase
implements QtWindowInterface, QtAccessibilityInterface, QtMenuInterface, QtLayoutInterface
implements QtWindowInterface, QtAccessibilityInterface, QtMenuInterface
{
private static final String QtTAG = "QtActivityDelegate";
@ -62,8 +62,6 @@ class QtActivityDelegate extends QtActivityDelegateBase
(QtAccessibilityInterface)QtActivityDelegate.this);
BackendRegister.registerBackend(QtMenuInterface.class,
(QtMenuInterface)QtActivityDelegate.this);
BackendRegister.registerBackend(QtLayoutInterface.class,
(QtLayoutInterface)QtActivityDelegate.this);
BackendRegister.registerBackend(QtInputInterface.class,
(QtInputInterface)m_inputDelegate);
}
@ -76,17 +74,10 @@ class QtActivityDelegate extends QtActivityDelegateBase
BackendRegister.unregisterBackend(QtWindowInterface.class);
BackendRegister.unregisterBackend(QtAccessibilityInterface.class);
BackendRegister.unregisterBackend(QtMenuInterface.class);
BackendRegister.unregisterBackend(QtLayoutInterface.class);
BackendRegister.unregisterBackend(QtInputInterface.class);
}
}
@Override
public QtLayout getQtLayout()
{
return m_layout;
}
@Override
public void setSystemUiVisibility(int systemUiVisibility)
{

View File

@ -25,7 +25,7 @@ import java.util.HashMap;
class QtEmbeddedDelegate extends QtActivityDelegateBase
implements QtNative.AppStateDetailsListener, QtEmbeddedViewInterface, QtWindowInterface,
QtMenuInterface, QtLayoutInterface
QtMenuInterface
{
private static final String QtTAG = "QtEmbeddedDelegate";
// TODO simplistic implementation with one QtView, expand to support multiple views QTBUG-117649
@ -98,13 +98,11 @@ class QtEmbeddedDelegate extends QtActivityDelegateBase
m_backendsRegistered = true;
BackendRegister.registerBackend(QtWindowInterface.class, (QtWindowInterface)this);
BackendRegister.registerBackend(QtMenuInterface.class, (QtMenuInterface)this);
BackendRegister.registerBackend(QtLayoutInterface.class, (QtLayoutInterface)this);
BackendRegister.registerBackend(QtInputInterface.class, m_inputDelegate);
} else if (!details.isStarted && m_backendsRegistered) {
m_backendsRegistered = false;
BackendRegister.unregisterBackend(QtWindowInterface.class);
BackendRegister.unregisterBackend(QtMenuInterface.class);
BackendRegister.unregisterBackend(QtLayoutInterface.class);
BackendRegister.unregisterBackend(QtInputInterface.class);
}
updateInputDelegate();
@ -133,17 +131,6 @@ class QtEmbeddedDelegate extends QtActivityDelegateBase
QtNative.startApplication(appParams, mainLib);
}
@Override
public QtLayout getQtLayout()
{
// 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
if (m_view == null)
return null;
return m_view.getQtWindow();
}
// QtEmbeddedViewInterface implementation begin
@Override
public void startQtApplication(String appParams, String mainLib)
@ -200,14 +187,12 @@ class QtEmbeddedDelegate extends QtActivityDelegateBase
@Override
public void openContextMenu(final int x, final int y, final int w, final int h)
{
QtLayout layout = getQtLayout();
layout.postDelayed(() -> {
m_view.postDelayed(() -> {
final QtEditText focusedEditText = m_inputDelegate.getCurrentQtEditText();
if (focusedEditText == null) {
Log.w(QtTAG, "No focused view when trying to open context menu");
return;
}
layout.setLayoutParams(focusedEditText, new QtLayout.LayoutParams(w, h, x, y), false);
PopupMenu popup = new PopupMenu(m_activity, focusedEditText);
QtNative.fillContextMenu(popup.getMenu());
popup.setOnMenuItemClickListener(menuItem ->

View File

@ -11,6 +11,7 @@ import android.os.Handler;
import android.os.ResultReceiver;
import android.text.method.MetaKeyKeyListener;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.InputDevice;
import android.view.KeyCharacterMap;
import android.view.KeyEvent;
@ -24,6 +25,7 @@ import org.qtproject.qt.android.QtInputConnection.QtInputConnectionListener;
class QtInputDelegate implements QtInputConnection.QtInputConnectionListener, QtInputInterface
{
private static final String TAG = "QtInputDelegate";
// keyboard methods
static native void keyDown(int key, int unicode, int modifier, boolean autoRepeat);
static native void keyUp(int key, int unicode, int modifier, boolean autoRepeat);
@ -105,7 +107,7 @@ class QtInputDelegate implements QtInputConnection.QtInputConnectionListener, Qt
}
@Override
public void showSoftwareKeyboard(Activity activity, QtLayout layout,
public void showSoftwareKeyboard(Activity activity,
final int x, final int y, final int width, final int height,
final int inputHints, final int enterKeyType)
{
@ -130,7 +132,7 @@ class QtInputDelegate implements QtInputConnection.QtInputConnectionListener, Qt
case InputMethodManager.RESULT_UNCHANGED_SHOWN:
setKeyboardVisibility(true, System.nanoTime());
if (m_softInputMode == 0) {
probeForKeyboardHeight(layout, activity,
probeForKeyboardHeight(activity,
x, y, width, height, inputHints, enterKeyType);
}
break;
@ -332,10 +334,14 @@ class QtInputDelegate implements QtInputConnection.QtInputConnectionListener, Qt
return false;
}
private void probeForKeyboardHeight(QtLayout layout, Activity activity, int x, int y,
private void probeForKeyboardHeight(Activity activity, int x, int y,
int width, int height, int inputHints, int enterKeyType)
{
layout.postDelayed(() -> {
if (m_currentEditText == null) {
Log.w(TAG, "probeForKeyboardHeight: null QtEditText");
return;
}
m_currentEditText.postDelayed(() -> {
if (!m_keyboardIsVisible)
return;
DisplayMetrics metrics = new DisplayMetrics();
@ -346,13 +352,13 @@ class QtInputDelegate implements QtInputConnection.QtInputConnectionListener, Qt
if (metrics.widthPixels > metrics.heightPixels) { // landscape
if (m_landscapeKeyboardHeight != r.bottom) {
m_landscapeKeyboardHeight = r.bottom;
showSoftwareKeyboard(activity, layout, x, y, width, height,
showSoftwareKeyboard(activity, x, y, width, height,
inputHints, enterKeyType);
}
} else {
if (m_portraitKeyboardHeight != r.bottom) {
m_portraitKeyboardHeight = r.bottom;
showSoftwareKeyboard(activity, layout, x, y, width, height,
showSoftwareKeyboard(activity, x, y, width, height,
inputHints, enterKeyType);
}
}

View File

@ -8,7 +8,7 @@ import android.app.Activity;
interface QtInputInterface {
void updateSelection(final int selStart, final int selEnd, final int candidatesStart,
final int candidatesEnd);
void showSoftwareKeyboard(Activity activity, QtLayout layout, final int x, final int y,
void showSoftwareKeyboard(Activity activity, final int x, final int y,
final int width, final int height, final int inputHints,
final int enterKeyType);
void resetSoftwareKeyboard();

View File

@ -1,8 +0,0 @@
// Copyright (C) 2024 The Qt Company Ltd.
// 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;
@UsedFromNativeCode
interface QtLayoutInterface {
QtLayout getQtLayout();
}

View File

@ -23,8 +23,6 @@ Q_LOGGING_CATEGORY(lcQpaInputMethods, "qt.qpa.input.methods");
using namespace QtAndroid;
Q_DECLARE_JNI_CLASS(QtLayout, "org/qtproject/qt/android/QtLayout")
Q_DECLARE_JNI_CLASS(QtLayoutInterface, "org/qtproject/qt/android/QtLayoutInterface")
Q_DECLARE_JNI_CLASS(QtInputInterface, "org/qtproject/qt/android/QtInputInterface")
namespace QtAndroidInput
@ -38,12 +36,6 @@ namespace QtAndroidInput
static QPointer<QWindow> m_mouseGrabber;
QJniObject qtLayout()
{
AndroidBackendRegister *reg = QtAndroid::backendRegister();
return reg->callInterface<QtJniTypes::QtLayoutInterface, QtJniTypes::QtLayout>(
"getQtLayout");
}
void updateSelection(int selStart, int selEnd, int candidatesStart, int candidatesEnd)
{
@ -58,7 +50,7 @@ namespace QtAndroidInput
AndroidBackendRegister *reg = QtAndroid::backendRegister();
reg->callInterface<QtJniTypes::QtInputInterface, void>(
"showSoftwareKeyboard", QtAndroidPrivate::activity(),
qtLayout().object<QtJniTypes::QtLayout>(), left, top, width, height, inputHints,
left, top, width, height, inputHints,
enterKeyType);
qCDebug(lcQpaInputMethods) << "@@@ SHOWSOFTWAREKEYBOARD" << left << top << width << height << inputHints << enterKeyType;
}