30 private final static String TAG =
"QtQuickView";
33 private String[] m_qmlImportPaths =
null;
36 private boolean m_hasQueuedStatus =
false;
37 private WeakReference<QtQuickViewContent> m_loadedComponent;
39 native
void createQuickView(
String qmlUri,
int width,
int height,
long parentWindowReference,
40 long viewReference,
String[] qmlImportPaths);
41 native
void setRootObjectProperty(
long windowReference,
String propertyName,
Object value);
42 native
Object getRootObjectProperty(
long windowReference,
String propertyName);
43 native
int addRootObjectSignalListener(
long windowReference,
String signalName,
44 Class<?> argType,
Object listener);
45 native
boolean removeRootObjectSignalListener(
long windowReference,
int signalListenerId);
60 throws InvalidParameterException {
61 this(
context, qmlUri, appName,
null);
80 throws InvalidParameterException
83 if (qmlUri ==
null || qmlUri.isEmpty()) {
84 throw new InvalidParameterException(
85 "QtQuickView: argument 'qmlUri' may not be empty or null");
88 m_qmlImportPaths = qmlImportPaths;
115 public <T extends QtQuickViewContent>
void loadContent(T qmlContent,
String[] qmlImportPaths)
116 throws InvalidParameterException
118 String libName = qmlContent.getLibraryName();
119 String qmlUri = qmlContent.getFilePath();
121 if (libName ==
null || libName.isEmpty()) {
122 throw new InvalidParameterException(
123 "QtQuickViewContent: return value of getLibraryName() may not be empty or null");
126 if (qmlUri ==
null || qmlUri.isEmpty()) {
127 throw new InvalidParameterException(
128 "QtQuickViewContent: return value of getFilePath() may not be empty or null");
132 m_qmlImportPaths = qmlImportPaths;
134 if (m_loadedComponent !=
null)
135 m_loadedComponent.clear();
137 m_loadedComponent =
new WeakReference<>(qmlContent);
138 qmlContent.detachView();
139 qmlContent.attachView(
this);
144 if (windowReference() == 0) {
145 loadQtLibraries(libName);
147 createQuickView(m_qmlUri, getWidth(), getHeight(), 0, windowReference(),
160 public <T extends QtQuickViewContent>
void loadContent(T qmlContent)
161 throws InvalidParameterException
163 loadContent(qmlContent,
null);
168 createQuickView(m_qmlUri, getWidth(), getHeight(), parentWindowReference, windowReference(),
189 setRootObjectProperty(windowReference(), propertyName,
value);
209 @SuppressWarnings(
"unchecked")
210 public <T> T getProperty(
String propertyName)
212 return (T)getRootObjectProperty(windowReference(), propertyName);
225 public <T>
int connectSignalListener(
String signalName, Class<T> argType,
226 QtSignalListener<T> listener)
228 int signalListenerId =
229 addRootObjectSignalListener(windowReference(), signalName, argType, listener);
230 if (signalListenerId < 0) {
231 Log.w(
TAG,
"The signal " + signalName +
" does not exist in the root object "
232 +
"or the arguments do not match with the listener.");
234 return signalListenerId;
248 return removeRootObjectSignalListener(windowReference(), signalListenerId);
276 m_statusChangeListener = listener;
278 if (m_hasQueuedStatus)
279 sendStatusChanged(m_lastStatus);
280 m_hasQueuedStatus =
false;
283 private void handleStatusChange(
int status)
287 }
catch (IllegalArgumentException e) {
288 m_lastStatus = QtQmlStatus.
NULL;
292 if (m_statusChangeListener ==
null)
293 m_hasQueuedStatus =
true;
295 sendStatusChanged(m_lastStatus);
298 private void sendStatusChanged(QtQmlStatus status)
300 QtNative.runAction(() -> {
301 if (m_statusChangeListener !=
null) {
302 QtQuickViewContent content = m_loadedComponent !=
null ?
303 m_loadedComponent.get() :
null;