summaryrefslogtreecommitdiffstats
path: root/src/android/jar/src/org/qtproject/qt/android/QtEmbeddedDelegate.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/android/jar/src/org/qtproject/qt/android/QtEmbeddedDelegate.java')
-rw-r--r--src/android/jar/src/org/qtproject/qt/android/QtEmbeddedDelegate.java109
1 files changed, 76 insertions, 33 deletions
diff --git a/src/android/jar/src/org/qtproject/qt/android/QtEmbeddedDelegate.java b/src/android/jar/src/org/qtproject/qt/android/QtEmbeddedDelegate.java
index 1c0fd0f7d8..5298ac02bd 100644
--- a/src/android/jar/src/org/qtproject/qt/android/QtEmbeddedDelegate.java
+++ b/src/android/jar/src/org/qtproject/qt/android/QtEmbeddedDelegate.java
@@ -15,21 +15,24 @@ import android.os.Handler;
import android.os.Looper;
import android.util.DisplayMetrics;
import android.util.Log;
+import android.view.Menu;
import android.view.View;
import android.view.ViewGroup;
+import android.widget.PopupMenu;
import java.util.ArrayList;
import java.util.HashMap;
-class QtEmbeddedDelegate extends QtActivityDelegateBase implements QtNative.AppStateDetailsListener {
+class QtEmbeddedDelegate extends QtActivityDelegateBase
+ implements QtNative.AppStateDetailsListener, QtEmbeddedViewInterface, QtWindowInterface,
+ QtMenuInterface, QtLayoutInterface
+{
+ private static final String QtTAG = "QtEmbeddedDelegate";
// TODO simplistic implementation with one QtView, expand to support multiple views QTBUG-117649
private QtView m_view;
- private long m_rootWindowRef = 0L;
private QtNative.ApplicationStateDetails m_stateDetails;
private boolean m_windowLoaded = false;
-
- private static native void createRootWindow(View rootView, int x, int y, int width, int height);
- static native void deleteWindow(long windowReference);
+ private boolean m_backendsRegistered = false;
public QtEmbeddedDelegate(Activity context) {
super(context);
@@ -78,11 +81,10 @@ class QtEmbeddedDelegate extends QtActivityDelegateBase implements QtNative.AppS
if (m_activity == activity && m_stateDetails.isStarted) {
m_activity.getApplication().unregisterActivityLifecycleCallbacks(this);
QtNative.unregisterAppStateListener(QtEmbeddedDelegate.this);
- QtEmbeddedDelegateFactory.remove(m_activity);
+ QtEmbeddedViewInterfaceFactory.remove(m_activity);
QtNative.terminateQt();
QtNative.setActivity(null);
QtNative.getQtThread().exit();
- onDestroy();
}
}
});
@@ -92,11 +94,28 @@ class QtEmbeddedDelegate extends QtActivityDelegateBase implements QtNative.AppS
public void onAppStateDetailsChanged(QtNative.ApplicationStateDetails details) {
synchronized (this) {
m_stateDetails = details;
- if (m_stateDetails.nativePluginIntegrationReady) {
+ if (details.isStarted && !m_backendsRegistered) {
+ m_backendsRegistered = true;
+ BackendRegister.registerBackend(QtWindowInterface.class, (QtWindowInterface)this);
+ BackendRegister.registerBackend(QtMenuInterface.class, (QtMenuInterface)this);
+ BackendRegister.registerBackend(QtLayoutInterface.class, (QtLayoutInterface)this);
+ } else if (!details.isStarted && m_backendsRegistered) {
+ m_backendsRegistered = false;
+ BackendRegister.unregisterBackend(QtWindowInterface.class);
+ BackendRegister.unregisterBackend(QtMenuInterface.class);
+ BackendRegister.unregisterBackend(QtLayoutInterface.class);
+ }
+ }
+ }
+
+ @Override
+ public void onNativePluginIntegrationReadyChanged(boolean ready)
+ {
+ synchronized (this) {
+ if (ready) {
QtNative.runAction(() -> {
DisplayMetrics metrics = Resources.getSystem().getDisplayMetrics();
- QtDisplayManager.setApplicationDisplayMetrics(m_activity,
- metrics.widthPixels,
+ QtDisplayManager.setApplicationDisplayMetrics(m_activity, metrics.widthPixels,
metrics.heightPixels);
});
@@ -112,16 +131,7 @@ class QtEmbeddedDelegate extends QtActivityDelegateBase implements QtNative.AppS
}
@Override
- QtAccessibilityDelegate createAccessibilityDelegate()
- {
- // FIXME make QtAccessibilityDelegate window based or verify current way works
- // also for child windows: QTBUG-120685
- return null;
- }
-
- @UsedFromNativeCode
- @Override
- QtLayout getQtLayout()
+ public QtLayout getQtLayout()
{
// TODO verify if returning m_view here works, this is used by the androidjniinput
// when e.g. showing a keyboard, so depends on getting the keyboard focus working
@@ -131,6 +141,14 @@ class QtEmbeddedDelegate extends QtActivityDelegateBase implements QtNative.AppS
return m_view.getQtWindow();
}
+ // QtEmbeddedViewInterface implementation begin
+ @Override
+ public void startQtApplication(String appParams, String mainLib)
+ {
+ super.startNativeApplication(appParams, mainLib);
+ }
+
+ @Override
public void queueLoadWindow()
{
synchronized (this) {
@@ -139,12 +157,15 @@ class QtEmbeddedDelegate extends QtActivityDelegateBase implements QtNative.AppS
}
}
- void setView(QtView view) {
+ @Override
+ public void setView(QtView view)
+ {
m_view = view;
updateInputDelegate();
if (m_view != null)
registerGlobalFocusChangeListener(m_view);
}
+ // QtEmbeddedViewInterface implementation end
private void updateInputDelegate() {
if (m_view == null) {
@@ -154,21 +175,43 @@ class QtEmbeddedDelegate extends QtActivityDelegateBase implements QtNative.AppS
m_inputDelegate.setEditPopupMenu(new EditPopupMenu(m_activity, m_view));
}
-
- public void setRootWindowRef(long ref) {
- m_rootWindowRef = ref;
- }
-
- public void onDestroy() {
- if (m_rootWindowRef != 0L)
- deleteWindow(m_rootWindowRef);
- m_rootWindowRef = 0L;
- }
-
private void createRootWindow() {
if (m_view != null && !m_windowLoaded) {
- createRootWindow(m_view, m_view.getLeft(), m_view.getTop(), m_view.getWidth(), m_view.getHeight());
+ QtView.createRootWindow(m_view, m_view.getLeft(), m_view.getTop(), m_view.getWidth(),
+ m_view.getHeight());
m_windowLoaded = true;
}
}
+
+ // QtMenuInterface implementation begin
+ @Override
+ public void resetOptionsMenu() { QtNative.runAction(() -> m_activity.invalidateOptionsMenu()); }
+
+ @Override
+ public void openOptionsMenu() { QtNative.runAction(() -> m_activity.openOptionsMenu()); }
+
+ @Override
+ public void closeContextMenu() { QtNative.runAction(() -> m_activity.closeContextMenu()); }
+
+ @Override
+ public void openContextMenu(final int x, final int y, final int w, final int h)
+ {
+ QtLayout layout = getQtLayout();
+ layout.postDelayed(() -> {
+ final QtEditText focusedEditText = m_inputDelegate.getCurrentQtEditText();
+ if (focusedEditText == null) {
+ Log.w(QtTAG, "No focused view when trying to open context menu");
+ return;
+ }
+ layout.setLayoutParams(focusedEditText, new QtLayout.LayoutParams(w, h, x, y), false);
+ PopupMenu popup = new PopupMenu(m_activity, focusedEditText);
+ QtNative.fillContextMenu(popup.getMenu());
+ popup.setOnMenuItemClickListener(menuItem ->
+ m_activity.onContextItemSelected(menuItem));
+ popup.setOnDismissListener(popupMenu ->
+ m_activity.onContextMenuClosed(popupMenu.getMenu()));
+ popup.show();
+ }, 100);
+ }
+ // QtMenuInterface implementation end
}