28 private final static String TAG =
"QtQuickView";
31 private String[] m_qmlImportPaths =
null;
34 private boolean m_hasQueuedStatus =
false;
35 private WeakReference<QtQuickViewContent> m_loadedComponent;
36 private QtSignalQueue m_signalQueue =
new QtSignalQueue();
38 native
void createQuickView(
String qmlUri,
int width,
int height,
long parentWindowReference,
39 long viewReference,
String[] qmlImportPaths);
40 native
void setRootObjectProperty(
long windowReference,
String propertyName,
Object value);
41 native
Object getRootObjectProperty(
long windowReference,
String propertyName);
42 native
boolean addRootObjectSignalListener(
long windowReference,
String signalName,
44 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 (getWindowReference() == 0) {
145 loadQtLibraries(libName);
147 createQuickView(m_qmlUri, getWidth(), getHeight(), 0, getWindowReference(),
153 void setWindowReference(
long windowReference) {
154 super.setWindowReference(windowReference);
155 m_signalQueue.connectQueuedSignalListeners(
this);
158 private boolean hasUnderlyingView() {
159 return getWindowReference() != 0L;
170 public <T extends QtQuickViewContent>
void loadContent(T qmlContent)
171 throws InvalidParameterException
173 loadContent(qmlContent,
null);
178 createQuickView(m_qmlUri, getWidth(), getHeight(), parentWindowReference, getWindowReference(),
199 setRootObjectProperty(getWindowReference(), propertyName,
value);
219 @SuppressWarnings(
"unchecked")
220 public <T> T getProperty(
String propertyName)
222 return (T)getRootObjectProperty(getWindowReference(), propertyName);
239 QtSignalListener<T> listener)
259 connectSignalListener(
signalName, argTypes, listener,
id);
277 if (hasUnderlyingView())
278 addRootObjectSignalListener(getWindowReference(),
signalName, argTypes, listener,
id);
280 m_signalQueue.add(
signalName, argTypes, listener,
id);
295 if (hasUnderlyingView())
296 return removeRootObjectSignalListener(getWindowReference(), signalListenerId);
298 return m_signalQueue.remove(signalListenerId);
328 m_statusChangeListener = listener;
330 if (m_hasQueuedStatus) {
331 sendStatusChanged(m_lastStatus);
332 m_hasQueuedStatus =
false;
371 private void handleStatusChange(
int status)
375 }
catch (IllegalArgumentException e) {
376 m_lastStatus = QtQmlStatus.
NULL;
380 if (m_statusChangeListener ==
null)
381 m_hasQueuedStatus =
true;
383 sendStatusChanged(m_lastStatus);
386 private void sendStatusChanged(QtQmlStatus status)
388 if (m_statusChangeListener !=
null) {
389 QtQuickViewContent content = m_loadedComponent !=
null ? m_loadedComponent.get() :
null;