Android: Add interface to handle interactions between delegate and QtView
Classes implementing QtEmbeddedViewConnector should support embedded usecases for both Service and regular Activity embedding. Any features that QtView requires from a delegate should be accessible via this interface. Task-number: QTBUG-118874 Change-Id: I238c6ef0451b1d08514c65f57e2875d31c5f4da9 Reviewed-by: Tinja Paavoseppä <tinja.paavoseppa@qt.io>
This commit is contained in:
parent
9ef4435fbf
commit
f1fa33aeb3
@ -38,6 +38,7 @@ set(java_sources
|
||||
src/org/qtproject/qt/android/QtEmbeddedDelegateFactory.java
|
||||
src/org/qtproject/qt/android/QtEmbeddedLoader.java
|
||||
src/org/qtproject/qt/android/QtView.java
|
||||
src/org/qtproject/qt/android/QtEmbeddedViewInterface.java
|
||||
)
|
||||
|
||||
qt_internal_add_jar(Qt${QtBase_VERSION_MAJOR}Android
|
||||
|
@ -21,7 +21,9 @@ import android.view.ViewGroup;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
class QtEmbeddedDelegate extends QtActivityDelegateBase implements QtNative.AppStateDetailsListener {
|
||||
class QtEmbeddedDelegate extends QtActivityDelegateBase
|
||||
implements QtNative.AppStateDetailsListener, QtEmbeddedViewInterface
|
||||
{
|
||||
// TODO simplistic implementation with one QtView, expand to support multiple views QTBUG-117649
|
||||
private QtView m_view;
|
||||
private QtNative.ApplicationStateDetails m_stateDetails;
|
||||
@ -126,6 +128,14 @@ class QtEmbeddedDelegate extends QtActivityDelegateBase implements QtNative.AppS
|
||||
return m_view.getQtWindow();
|
||||
}
|
||||
|
||||
// QtEmbeddedViewInterface implementation begin
|
||||
@Override
|
||||
public void startQtApplication(String appParams, String mainLib)
|
||||
{
|
||||
super.startNativeApplication(appParams, mainLib);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void queueLoadWindow()
|
||||
{
|
||||
synchronized (this) {
|
||||
@ -134,12 +144,15 @@ class QtEmbeddedDelegate extends QtActivityDelegateBase implements QtNative.AppS
|
||||
}
|
||||
}
|
||||
|
||||
void setView(QtView view) {
|
||||
@Override
|
||||
public void setView(QtView view)
|
||||
{
|
||||
m_view = view;
|
||||
updateInputDelegate();
|
||||
if (m_view != null)
|
||||
registerGlobalFocusChangeListener(m_view);
|
||||
}
|
||||
// QtEmbeddedViewInterface implementation end
|
||||
|
||||
private void updateInputDelegate() {
|
||||
if (m_view == null) {
|
||||
|
@ -0,0 +1,15 @@
|
||||
// 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;
|
||||
|
||||
/**
|
||||
* QtEmbeddedViewInterface is intended to encapsulate the needs of QtView, so that the Activity and
|
||||
* Service implementations of these functions may be split clearly, and the interface can be stored
|
||||
* and used conveniently in QtView.
|
||||
**/
|
||||
interface QtEmbeddedViewInterface {
|
||||
void startQtApplication(String appParams, String mainLib);
|
||||
void setView(QtView view);
|
||||
void queueLoadWindow();
|
||||
};
|
@ -31,7 +31,7 @@ abstract class QtView extends ViewGroup {
|
||||
protected long m_windowReference;
|
||||
protected long m_parentWindowReference;
|
||||
protected QtWindowListener m_windowListener;
|
||||
protected QtEmbeddedDelegate m_delegate;
|
||||
protected QtEmbeddedViewInterface m_viewInterface;
|
||||
// Implement in subclass to handle the creation of the QWindow and its parent container.
|
||||
// TODO could we take care of the parent window creation and parenting outside of the
|
||||
// window creation method to simplify things if user would extend this? Preferably without
|
||||
@ -60,7 +60,7 @@ abstract class QtView extends ViewGroup {
|
||||
}
|
||||
|
||||
QtEmbeddedLoader loader = new QtEmbeddedLoader(context);
|
||||
m_delegate = QtEmbeddedDelegateFactory.create((Activity)context);
|
||||
m_viewInterface = QtEmbeddedDelegateFactory.create((Activity)context);
|
||||
loader.setMainLibraryName(appLibName);
|
||||
addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
|
||||
@Override
|
||||
@ -80,22 +80,22 @@ abstract class QtView extends ViewGroup {
|
||||
});
|
||||
loader.loadQtLibraries();
|
||||
// Start Native Qt application
|
||||
m_delegate.startNativeApplication(loader.getApplicationParameters(),
|
||||
loader.getMainLibraryPath());
|
||||
m_viewInterface.startQtApplication(loader.getApplicationParameters(),
|
||||
loader.getMainLibraryPath());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onAttachedToWindow() {
|
||||
super.onAttachedToWindow();
|
||||
m_delegate.setView(this);
|
||||
m_delegate.queueLoadWindow();
|
||||
m_viewInterface.setView(this);
|
||||
m_viewInterface.queueLoadWindow();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDetachedFromWindow() {
|
||||
super.onDetachedFromWindow();
|
||||
destroyWindow();
|
||||
m_delegate.setView(null);
|
||||
m_viewInterface.setView(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
x
Reference in New Issue
Block a user