Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
QtQuickView.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 android.content.Context;
7import android.view.View;
8import android.view.ViewGroup;
9import android.util.Log;
10
11import java.security.InvalidParameterException;
12
32public class QtQuickView extends QtView {
33 private final static String TAG = "QtQuickView";
34
38 @FunctionalInterface
39 public interface SignalListener<T>
40 {
46 void onSignalEmitted(String signalName, T value);
47 }
48
52 public interface StatusChangeListener
53 {
59 void onStatusChanged(int status);
60 }
61
65 public static final int STATUS_NULL = 0;
73 public static final int STATUS_READY = 1;
77 public static final int STATUS_LOADING = 2;
81 public static final int STATUS_ERROR = 3;
82
83 private String m_qmlUri;
84 private String[] m_qmlImportPaths = null;
85 private StatusChangeListener m_statusChangeListener = null;
86 private int m_lastStatus = STATUS_NULL;
87 private boolean m_hasQueuedStatus = false;
88
89 native void createQuickView(String qmlUri, int width, int height, long parentWindowReference,
90 String[] qmlImportPaths);
91 native void setRootObjectProperty(long windowReference, String propertyName, Object value);
92 native Object getRootObjectProperty(long windowReference, String propertyName);
93 native int addRootObjectSignalListener(long windowReference, String signalName, Class argType,
94 Object listener);
95 native boolean removeRootObjectSignalListener(long windowReference, int signalListenerId);
96
109 public QtQuickView(Context context, String qmlUri, String appName)
110 throws InvalidParameterException {
111 this(context, qmlUri, appName, null);
112 }
113
129 public QtQuickView(Context context, String qmlUri, String appName, String[] qmlImportPaths)
130 throws InvalidParameterException
131 {
132 super(context, appName);
133 if (qmlUri == null || qmlUri.isEmpty()) {
134 throw new InvalidParameterException(
135 "QtQuickView: argument 'qmlUri' may not be empty or null");
136 }
137 m_qmlUri = qmlUri;
138 m_qmlImportPaths = qmlImportPaths;
139 }
140
141 @Override
142 protected void createWindow(long parentWindowReference) {
143 createQuickView(m_qmlUri, getWidth(), getHeight(), parentWindowReference, m_qmlImportPaths);
144 }
145
160 public void setProperty(String propertyName, Object value)
161 {
162 setRootObjectProperty(windowReference(), propertyName, value);
163 }
164
180 // getRootObjectProperty always returns a primitive type or an Object
181 // so it is safe to suppress the unchecked warning
182 @SuppressWarnings("unchecked")
183 public <T> T getProperty(String propertyName)
184 {
185 return (T)getRootObjectProperty(windowReference(), propertyName);
186 }
187
198 public <T> int connectSignalListener(String signalName, Class<T> argType,
199 SignalListener<T> listener)
200 {
201 int signalListenerId =
202 addRootObjectSignalListener(windowReference(), signalName, argType, listener);
203 if (signalListenerId < 0) {
204 Log.w(TAG, "The signal " + signalName + " does not exist in the root object "
205 + "or the arguments do not match with the listener.");
206 }
207 return signalListenerId;
208 }
209
219 public boolean disconnectSignalListener(int signalListenerId)
220 {
221 return removeRootObjectSignalListener(windowReference(), signalListenerId);
222 }
223
235 public int getStatus()
236 {
237 return m_lastStatus;
238 }
239
246 {
247 m_statusChangeListener = listener;
248
249 if (m_hasQueuedStatus) {
250 QtNative.runAction(() -> { m_statusChangeListener.onStatusChanged(m_lastStatus); });
251 m_hasQueuedStatus = false;
252 }
253 }
254
255 private void handleStatusChange(int status)
256 {
257 m_lastStatus = status;
258
259 if (m_statusChangeListener != null)
260 QtNative.runAction(() -> { m_statusChangeListener.onStatusChanged(status); });
261 else
262 m_hasQueuedStatus = true;
263 }
264}
Definition main.cpp:8
void setProperty(String propertyName, Object value)
QtQuickView(Context context, String qmlUri, String appName)
QtQuickView(Context context, String qmlUri, String appName, String[] qmlImportPaths)
void createWindow(long parentWindowReference)
void setStatusChangeListener(StatusChangeListener listener)
boolean disconnectSignalListener(int signalListenerId)
void onSignalEmitted(String signalName, T value)
static void * context
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
GLint GLsizei GLsizei height
GLint GLsizei width