diff options
Diffstat (limited to 'src/android/jar/src/org/qtproject/qt/android/QtView.java')
-rw-r--r-- | src/android/jar/src/org/qtproject/qt/android/QtView.java | 71 |
1 files changed, 43 insertions, 28 deletions
diff --git a/src/android/jar/src/org/qtproject/qt/android/QtView.java b/src/android/jar/src/org/qtproject/qt/android/QtView.java index 6836171187..b4fa0382ed 100644 --- a/src/android/jar/src/org/qtproject/qt/android/QtView.java +++ b/src/android/jar/src/org/qtproject/qt/android/QtView.java @@ -29,36 +29,30 @@ abstract class QtView extends ViewGroup { protected QtWindow m_window; protected long m_windowReference; + protected long m_parentWindowReference; protected QtWindowListener m_windowListener; - protected QtEmbeddedDelegate m_delegate; + protected QtEmbeddedViewInterface m_viewInterface; // Implement in subclass to handle the creation of the QWindow and its parent container. // TODO could we take care of the parent window creation and parenting outside of the // window creation method to simplify things if user would extend this? Preferably without // too much JNI back and forth. Related to parent window creation, so handle with QTBUG-121511. abstract protected void createWindow(long parentWindowRef); + static native void createRootWindow(View rootView, int x, int y, int width, int height); + static native void deleteWindow(long windowReference); private static native void setWindowVisible(long windowReference, boolean visible); private static native void resizeWindow(long windowReference, int x, int y, int width, int height); - /** - * Create QtView for embedding a QWindow. Instantiating a QtView will load the Qt libraries - * if they have not already been loaded, including the app library specified by appName, and - * starting the said Qt app. - * @param context the hosting Context - * @param appLibName the name of the Qt app library to load and start. This corresponds to the - target name set in Qt app's CMakeLists.txt - **/ - public QtView(Context context, String appLibName) throws InvalidParameterException { + /** + * Create a QtView for embedding a QWindow without loading the Qt libraries or starting + * the Qt app. + * @param context the hosting Context + **/ + public QtView(Context context) { super(context); - if (appLibName == null || appLibName.isEmpty()) { - throw new InvalidParameterException("QtView: argument 'appLibName' may not be empty "+ - "or null"); - } - QtEmbeddedLoader loader = new QtEmbeddedLoader(context); - m_delegate = QtEmbeddedDelegateFactory.create((Activity)context); - loader.setMainLibraryName(appLibName); + m_viewInterface = QtEmbeddedViewInterfaceFactory.create(context); addOnLayoutChangeListener(new View.OnLayoutChangeListener() { @Override public void onLayoutChange(View v, int left, int top, int right, int bottom, @@ -75,24 +69,36 @@ abstract class QtView extends ViewGroup { } } }); - loader.loadQtLibraries(); - // Start Native Qt application - m_delegate.startNativeApplication(loader.getApplicationParameters(), - loader.getMainLibraryPath()); + } + /** + * Create a QtView for embedding a QWindow, and load the Qt libraries if they have not already + * been loaded, including the app library specified by appName, and starting the said Qt app. + * @param context the hosting Context + * @param appLibName the name of the Qt app library to load and start. This corresponds to the + target name set in Qt app's CMakeLists.txt + **/ + public QtView(Context context, String appLibName) throws InvalidParameterException { + this(context); + if (appLibName == null || appLibName.isEmpty()) { + throw new InvalidParameterException("QtView: argument 'appLibName' may not be empty "+ + "or null"); + } + + loadQtLibraries(appLibName); } @Override protected void onAttachedToWindow() { super.onAttachedToWindow(); - m_delegate.setView(this); - m_delegate.queueLoadWindow(); + m_viewInterface.setView(this); + m_viewInterface.queueLoadWindow(); } @Override protected void onDetachedFromWindow() { super.onDetachedFromWindow(); destroyWindow(); - m_delegate.setView(null); + m_viewInterface.setView(null); } @Override @@ -136,6 +142,15 @@ abstract class QtView extends ViewGroup { m_windowListener = listener; } + void loadQtLibraries(String appLibName) { + QtEmbeddedLoader loader = new QtEmbeddedLoader(getContext()); + loader.setMainLibraryName(appLibName); + loader.loadQtLibraries(); + // Start Native Qt application + m_viewInterface.startQtApplication(loader.getApplicationParameters(), + loader.getMainLibraryPath()); + } + void setWindowReference(long windowReference) { m_windowReference = windowReference; } @@ -156,7 +171,7 @@ abstract class QtView extends ViewGroup { // viewReference - the reference to the created QQuickView void addQtWindow(QtWindow window, long viewReference, long parentWindowRef) { setWindowReference(viewReference); - m_delegate.setRootWindowRef(parentWindowRef); + m_parentWindowReference = parentWindowRef; final Handler handler = new Handler(Looper.getMainLooper()); handler.post(new Runnable() { @Override @@ -176,9 +191,9 @@ abstract class QtView extends ViewGroup { // Destroy the underlying QWindow void destroyWindow() { - if (m_windowReference != 0L) - QtEmbeddedDelegate.deleteWindow(m_windowReference); - m_windowReference = 0L; + if (m_parentWindowReference != 0L) + deleteWindow(m_parentWindowReference); + m_parentWindowReference = 0L; } QtWindow getQtWindow() { |