28 private final static String TAG =
"QtQuickView";
30 private String m_qmlUri;
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,
43 Class<?>[] argTypes,
Object listener,
int id);
44 native
boolean removeRootObjectSignalListener(
long windowReference,
int signalListenerId);
45 native
void invokeMethod(
long windowReference, String methodName,
Object[]
params);
60 throws InvalidParameterException {
61 this(context, qmlUri, appName,
null);
80 throws InvalidParameterException
82 super(context, appName);
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);
241 public <T>
int connectSignalListener(String signalName, Class<T> argType,
242 QtSignalListener<T> listener)
244 return connectSignalListener(signalName,
new Class<?>[] { argType }, listener);
266 return connectSignalListener(signalName, argTypes, listener,
id) ?
id : -1;
281 boolean connectSignalListener(String signalName, Class<?>[] argTypes,
Object listener,
int id)
283 if (hasUnderlyingView()) {
284 return addRootObjectSignalListener(getWindowReference(), signalName, argTypes,
287 m_signalQueue.add(signalName, argTypes, listener,
id);
303 if (hasUnderlyingView())
304 return removeRootObjectSignalListener(getWindowReference(), signalListenerId);
306 return m_signalQueue.remove(signalListenerId);
336 m_statusChangeListener = listener;
338 if (m_hasQueuedStatus) {
339 sendStatusChanged(m_lastStatus);
340 m_hasQueuedStatus =
false;
364 invokeMethod(getWindowReference(), methodName,
params);
376 invokeMethod(getWindowReference(), methodName,
new Object[] {});
379 private void handleStatusChange(
int status)
383 }
catch (IllegalArgumentException e) {
384 m_lastStatus = QtQmlStatus.
NULL;
388 if (m_statusChangeListener ==
null)
389 m_hasQueuedStatus =
true;
391 sendStatusChanged(m_lastStatus);
394 private void sendStatusChanged(QtQmlStatus status)
396 if (m_statusChangeListener !=
null) {
397 QtQuickViewContent content = m_loadedComponent !=
null ? m_loadedComponent.get() :
null;