Android: Implement QtLayout backend interface

Small interface, just for QtLayout. This is used in
QtAndroid::qtLayout(), which is called by functions handling the
virtual keyboard and the keyboard handles.

Task-number: QTBUG-118874
Change-Id: Ib9b2830136d05dfd70c9c6ca86ac29be36cc5c30
Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
This commit is contained in:
Petri Virkkunen 2024-03-31 16:32:55 +03:00
parent 9319576a59
commit ad649b583d
6 changed files with 22 additions and 8 deletions

View File

@ -44,6 +44,7 @@ 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
)
qt_internal_add_jar(Qt${QtBase_VERSION_MAJOR}Android

View File

@ -32,7 +32,7 @@ import android.widget.PopupMenu;
import java.util.HashMap;
class QtActivityDelegate extends QtActivityDelegateBase
implements QtWindowInterface, QtAccessibilityInterface, QtMenuInterface
implements QtWindowInterface, QtAccessibilityInterface, QtMenuInterface, QtLayoutInterface
{
private static final String QtTAG = "QtActivityDelegate";
@ -63,6 +63,8 @@ class QtActivityDelegate extends QtActivityDelegateBase
(QtAccessibilityInterface)QtActivityDelegate.this);
BackendRegister.registerBackend(QtMenuInterface.class,
(QtMenuInterface)QtActivityDelegate.this);
BackendRegister.registerBackend(QtLayoutInterface.class,
(QtLayoutInterface)QtActivityDelegate.this);
}
}
@ -73,12 +75,12 @@ class QtActivityDelegate extends QtActivityDelegateBase
BackendRegister.unregisterBackend(QtWindowInterface.class);
BackendRegister.unregisterBackend(QtAccessibilityInterface.class);
BackendRegister.unregisterBackend(QtMenuInterface.class);
BackendRegister.unregisterBackend(QtLayoutInterface.class);
}
}
@UsedFromNativeCode
@Override
QtLayout getQtLayout()
public QtLayout getQtLayout()
{
return m_layout;
}

View File

@ -45,7 +45,6 @@ abstract class QtActivityDelegateBase
// Subclass must implement these
abstract void startNativeApplicationImpl(String appParams, String mainLib);
abstract QtLayout getQtLayout();
// With these we are okay with default implementation doing nothing
void setUpLayout() {}

View File

@ -25,7 +25,7 @@ import java.util.HashMap;
class QtEmbeddedDelegate extends QtActivityDelegateBase
implements QtNative.AppStateDetailsListener, QtEmbeddedViewInterface, QtWindowInterface,
QtMenuInterface
QtMenuInterface, QtLayoutInterface
{
private static final String QtTAG = "QtEmbeddedDelegate";
// TODO simplistic implementation with one QtView, expand to support multiple views QTBUG-117649
@ -98,10 +98,12 @@ 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);
} else if (!details.isStarted && m_backendsRegistered) {
m_backendsRegistered = false;
BackendRegister.unregisterBackend(QtWindowInterface.class);
BackendRegister.unregisterBackend(QtMenuInterface.class);
BackendRegister.unregisterBackend(QtLayoutInterface.class);
}
}
}
@ -128,9 +130,8 @@ class QtEmbeddedDelegate extends QtActivityDelegateBase
QtNative.startApplication(appParams, mainLib);
}
@UsedFromNativeCode
@Override
QtLayout getQtLayout()
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

View File

@ -0,0 +1,8 @@
// 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

@ -24,6 +24,7 @@ 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")
namespace QtAndroidInput
{
@ -98,7 +99,9 @@ namespace QtAndroidInput
QJniObject qtLayout()
{
return qtActivityDelegate().callMethod<QtJniTypes::QtLayout>("getQtLayout");
AndroidBackendRegister *reg = QtAndroid::backendRegister();
return reg->callInterface<QtJniTypes::QtLayoutInterface, QtJniTypes::QtLayout>(
"getQtLayout");
}
void updateSelection(int selStart, int selEnd, int candidatesStart, int candidatesEnd)