5package org.qtproject.qt.android;
7import android.content.Context;
8import android.os.Handler;
9import android.os.Looper;
10import android.util.Log;
11import android.view.View;
12import android.view.ViewGroup;
14import java.security.InvalidParameterException;
15import java.util.Objects;
19abstract class QtView
extends ViewGroup implements
QtNative.AppStateDetailsListener {
20 private final static String TAG =
"QtView";
28 private QtWindow m_window;
29 private long m_windowReference;
30 private long m_parentWindowReference;
37 abstract protected void createWindow(
long parentWindowRef);
39 static native
void createRootWindow(
View rootView,
int x,
int y,
int width,
int height);
40 static native
void deleteWindow(
long windowReference);
41 private static native
void setWindowVisible(
long windowReference,
boolean visible);
42 private static native
void resizeWindow(
long windowReference,
52 QtNative.registerAppStateListener(
this);
53 m_viewInterface = QtEmbeddedViewInterfaceFactory.create(
context);
54 addOnLayoutChangeListener(
56 if (m_windowReference != 0L) {
57 final int oldWidth = oldRight - oldLeft;
58 final int oldHeight = oldBottom - oldTop;
61 if (oldWidth != newWidth || oldHeight != newHeight ||
left != oldLeft ||
63 resizeWindow(m_windowReference,
left,
top, newWidth, newHeight);
68 setId(
View.generateViewId());
79 if (appLibName ==
null || appLibName.isEmpty()) {
80 throw new InvalidParameterException(
"QtView: argument 'appLibName' may not be empty "+
83 loadQtLibraries(appLibName);
87 protected void onAttachedToWindow() {
88 super.onAttachedToWindow();
89 m_viewInterface.addView(
this);
93 protected void onDetachedFromWindow() {
94 super.onDetachedFromWindow();
96 m_viewInterface.removeView(
this);
100 public void onLayout(
boolean changed,
int l,
int t,
int r,
int b) {
101 if (m_window !=
null)
102 m_window.layout(0 , 0 ,
r - l ,
b -
t );
106 protected void onMeasure(
int widthMeasureSpec,
int heightMeasureSpec)
108 measureChildren(widthMeasureSpec, heightMeasureSpec);
110 final int count = getChildCount();
116 measureChildren(widthMeasureSpec, heightMeasureSpec);
119 for (
int i = 0;
i <
count;
i++) {
120 View
child = getChildAt(i);
121 if (
child.getVisibility() != GONE) {
122 maxWidth = Math.max(maxWidth,
child.getMeasuredWidth());
123 maxHeight = Math.max(maxHeight,
child.getMeasuredHeight());
128 maxHeight = Math.max(maxHeight, getSuggestedMinimumHeight());
129 maxWidth = Math.max(maxWidth, getSuggestedMinimumWidth());
131 setMeasuredDimension(resolveSize(maxWidth, widthMeasureSpec),
132 resolveSize(maxHeight, heightMeasureSpec));
137 m_windowListener = listener;
140 void loadQtLibraries(
String appLibName) {
141 QtEmbeddedLoader loader;
143 loader = QtEmbeddedLoader.getEmbeddedLoader(getContext());
144 }
catch (IllegalArgumentException e) {
145 Log.e(TAG, Objects.requireNonNull(e.getMessage()));
146 QtEmbeddedViewInterfaceFactory.remove(getContext());
150 loader.setMainLibraryName(appLibName);
151 QtLoader.LoadingResult
result = loader.loadQtLibraries();
152 if (
result == QtLoader.LoadingResult.Failed) {
155 QtEmbeddedViewInterfaceFactory.remove(getContext());
158 m_viewInterface.startQtApplication(loader.getApplicationParameters(),
159 loader.getMainLibraryPath());
163 void setWindowReference(
long windowReference) {
164 m_windowReference = windowReference;
167 long getWindowReference() {
168 return m_windowReference;
171 void setQtWindow(QtWindow qtWindow) {
175 QtWindow getQtWindow() {
179 long getParentWindowReference()
181 return m_parentWindowReference;
184 void setParentWindowReference(
long reference)
191 return m_windowListener;
196 m_windowListener = listner;
199 QtEmbeddedViewInterface getViewInterface()
201 return m_viewInterface;
206 void setWindowVisible(
boolean visible) {
207 if (m_windowReference != 0L)
208 setWindowVisible(m_windowReference,
true);
214 void addQtWindow(QtWindow
window,
long viewReference,
long parentWindowRef) {
215 setWindowReference(viewReference);
216 m_parentWindowReference = parentWindowRef;
220 m_window.setLayoutParams(
new LayoutParams(
221 LayoutParams.MATCH_PARENT,
222 LayoutParams.MATCH_PARENT));
223 addView(m_window, 0);
225 setWindowVisible(
true);
226 if (m_windowListener !=
null)
227 m_windowListener.onQtWindowLoaded();
232 void destroyWindow() {
233 if (m_parentWindowReference != 0L)
234 deleteWindow(m_parentWindowReference);
235 m_parentWindowReference = 0L;
236 setWindowReference(0L);
240 public void onAppStateDetailsChanged(QtNative.ApplicationStateDetails details) {
241 if (!details.isStarted) {
242 ViewGroup parent = (ViewGroup)getParent();
244 parent.removeView(
this);
static const QString context()
Catch::Generators::GeneratorWrapper< T > handler(Catch::Generators::GeneratorWrapper< T > &&generator)
Returns a generator wrapping generator that ensures that changes its semantics so that the first call...
GLboolean GLboolean GLboolean b
GLint GLint GLint GLint GLint x
GLenum GLenum GLsizei count
GLdouble GLdouble GLdouble GLdouble top
GLsizei const GLfloat * v