4package org.qtproject.qt.android;
6import android.app.Activity;
7import android.content.Context;
8import android.content.ContextWrapper;
9import android.content.pm.PackageManager.NameNotFoundException;
10import android.content.res.Resources;
11import android.os.Handler;
12import android.os.Looper;
13import android.view.View;
14import android.view.ViewGroup;
16import java.security.InvalidParameterException;
17import java.util.ArrayList;
21abstract class QtView
extends ViewGroup {
22 private final static String TAG =
"QtView";
30 protected QtWindow m_window;
31 protected long m_windowReference;
32 protected long m_parentWindowReference;
39 abstract protected void createWindow(
long parentWindowRef);
41 static native
void createRootWindow(View rootView,
int x,
int y,
int width,
int height);
42 static native
void deleteWindow(
long windowReference);
43 private static native
void setWindowVisible(
long windowReference,
boolean visible);
44 private static native
void resizeWindow(
long windowReference,
55 public QtView(Context
context, String appLibName)
throws InvalidParameterException {
57 if (appLibName ==
null || appLibName.isEmpty()) {
58 throw new InvalidParameterException(
"QtView: argument 'appLibName' may not be empty "+
62 QtEmbeddedLoader loader =
new QtEmbeddedLoader(
context);
63 m_viewInterface = QtEmbeddedDelegateFactory.create((Activity)
context);
64 loader.setMainLibraryName(appLibName);
65 addOnLayoutChangeListener(
new View.OnLayoutChangeListener() {
67 public void onLayoutChange(View v, int left, int top, int right, int bottom,
68 int oldLeft, int oldTop, int oldRight, int oldBottom) {
69 if (m_windowReference != 0L) {
70 final int oldWidth = oldRight - oldLeft;
71 final int oldHeight = oldBottom - oldTop;
72 final int newWidth = right - left;
73 final int newHeight = bottom - top;
74 if (oldWidth != newWidth || oldHeight != newHeight || left != oldLeft ||
76 resizeWindow(m_windowReference, left, top, newWidth, newHeight);
81 loader.loadQtLibraries();
84 loader.getMainLibraryPath());
88 protected void onAttachedToWindow() {
89 super.onAttachedToWindow();
95 protected void onDetachedFromWindow() {
96 super.onDetachedFromWindow();
102 public void onLayout(
boolean changed,
int l,
int t,
int r,
int b) {
103 if (m_window !=
null)
104 m_window.layout(0 , 0 ,
r - l ,
b -
t );
108 protected void onMeasure(
int widthMeasureSpec,
int heightMeasureSpec)
110 measureChildren(widthMeasureSpec, heightMeasureSpec);
112 final int count = getChildCount();
118 measureChildren(widthMeasureSpec, heightMeasureSpec);
123 if (
child.getVisibility() != GONE) {
124 maxWidth = Math.max(maxWidth,
child.getMeasuredWidth());
125 maxHeight = Math.max(maxHeight,
child.getMeasuredHeight());
130 maxHeight = Math.max(maxHeight, getSuggestedMinimumHeight());
131 maxWidth = Math.max(maxWidth, getSuggestedMinimumWidth());
133 setMeasuredDimension(resolveSize(maxWidth, widthMeasureSpec),
134 resolveSize(maxHeight, heightMeasureSpec));
138 public void setQtWindowListener(QtWindowListener listener) {
139 m_windowListener = listener;
142 void setWindowReference(
long windowReference) {
143 m_windowReference = windowReference;
146 long windowReference() {
147 return m_windowReference;
153 if (m_windowReference != 0L)
160 void addQtWindow(QtWindow
window,
long viewReference,
long parentWindowRef) {
161 setWindowReference(viewReference);
162 m_parentWindowReference = parentWindowRef;
163 final Handler handler =
new Handler(Looper.getMainLooper());
164 handler.post(
new Runnable() {
168 m_window.setLayoutParams(
new ViewGroup.LayoutParams(
169 ViewGroup.LayoutParams.MATCH_PARENT,
170 ViewGroup.LayoutParams.MATCH_PARENT));
171 addView(m_window, 0);
174 if (m_windowListener !=
null)
181 void destroyWindow() {
182 if (m_parentWindowReference != 0L)
184 m_parentWindowReference = 0L;
187 QtWindow getQtWindow() {
void setView(QtView view)
void startQtApplication(String appParams, String mainLib)
void setWindowVisible(JNIEnv *, jclass, jlong windowRef, jboolean visible)
void deleteWindow(JNIEnv *, jclass, jlong windowRef)
QTCONCURRENT_RUN_NODISCARD auto run(QThreadPool *pool, Function &&f, Args &&...args)
GLboolean GLboolean GLboolean b
GLint GLint GLint GLint GLint x
[0]
GLint GLsizei GLsizei height
GLenum GLenum GLsizei count