Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
QtServiceEmbeddedDelegate.java
Go to the documentation of this file.
1// Copyright (C) 2024 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4package org.qtproject.qt.android;
5
6import static org.qtproject.qt.android.QtNative.ApplicationState.ApplicationSuspended;
7
8import android.app.Service;
9import android.content.res.Resources;
10import android.util.DisplayMetrics;
11
12import java.util.HashSet;
13
18class QtServiceEmbeddedDelegate implements QtEmbeddedViewInterface, QtNative.AppStateDetailsListener
19{
20 private final Service m_service;
21 private final HashSet<QtView> m_views = new HashSet<>();
22
23 QtServiceEmbeddedDelegate(Service service)
24 {
25 m_service = service;
26 QtNative.registerAppStateListener(this);
27 QtNative.setService(service);
28 // QTBUG-122920 TODO Implement accessibility for service UIs
29 // QTBUG-122552 TODO Implement text input
30 }
31
32 @Override
33 public void onNativePluginIntegrationReadyChanged(boolean ready)
34 {
35 synchronized (this) {
36 if (ready) {
37 QtNative.runAction(() -> {
38 final DisplayMetrics metrics = Resources.getSystem().getDisplayMetrics();
39
40 final int maxWidth = metrics.widthPixels;
41 final int maxHeight = metrics.heightPixels;
42
43 QtDisplayManager.handleLayoutSizeChanged(maxWidth, maxHeight);
44
45 QtDisplayManager.updateRefreshRate(m_service);
46 QtDisplayManager.handleScreenDensityChanged(metrics.density);
47 });
48 }
49 }
50 }
51
52 // QtEmbeddedViewInterface implementation begin
53 @Override
54 public void startQtApplication(String appParams, String mainLib)
55 {
56 QtNative.startApplication(appParams, mainLib);
57 }
58
59 @Override
60 public void addView(QtView view)
61 {
62 if (m_views.add(view)) {
63 QtNative.runAction(() -> createRootWindow(view));
64 }
65 }
66
67 @Override
68 public void removeView(QtView view)
69 {
70 m_views.remove(view);
71 if (m_views.isEmpty())
72 cleanup();
73 }
74 // QtEmbeddedViewInterface implementation end
75
76 private void createRootWindow(QtView view)
77 {
78 if (m_views.contains(view)) {
79 QtView.createRootWindow(view, view.getLeft(), view.getTop(), view.getWidth(),
80 view.getHeight());
81 }
82 }
83
84 private void cleanup()
85 {
86 QtNative.setApplicationState(ApplicationSuspended);
87 QtNative.unregisterAppStateListener(QtServiceEmbeddedDelegate.this);
88 QtEmbeddedViewInterfaceFactory.remove(m_service);
89
90 QtNative.terminateQtNativeApplication();
91 QtNative.setService(null);
92 }
93}
Q_CORE_EXPORT QtJniTypes::Service service()
GLsizei GLenum const void GLuint GLsizei GLfloat * metrics
void cleanup()
QQuickView * view
[0]