diff options
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.java | 77 |
1 files changed, 60 insertions, 17 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 ff694777d5..7a460ccc17 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,26 @@ 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, QtEmbeddedViewInterface + 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 QtNative.ApplicationStateDetails m_stateDetails; private boolean m_windowLoaded = false; + private boolean m_backendsRegistered = false; - public QtEmbeddedDelegate(Activity context) { + QtEmbeddedDelegate(Activity context) { super(context); m_stateDetails = QtNative.getStateDetails(); @@ -76,7 +81,7 @@ class QtEmbeddedDelegate extends QtActivityDelegateBase 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(); @@ -89,6 +94,18 @@ class QtEmbeddedDelegate extends QtActivityDelegateBase public void onAppStateDetailsChanged(QtNative.ApplicationStateDetails details) { synchronized (this) { m_stateDetails = details; + 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); + } + updateInputDelegate(); } } @@ -115,16 +132,7 @@ class QtEmbeddedDelegate extends QtActivityDelegateBase } @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 @@ -161,11 +169,14 @@ class QtEmbeddedDelegate extends QtActivityDelegateBase // QtEmbeddedViewInterface implementation end private void updateInputDelegate() { - if (m_view == null) { - m_inputDelegate.setEditPopupMenu(null); + // If the QtView has attached to the window before Qt libs have been loaded, + // the input delegate will be null + if (m_inputDelegate == null) return; - } - m_inputDelegate.setEditPopupMenu(new EditPopupMenu(m_activity, m_view)); + if (m_view == null) + m_inputDelegate.setEditPopupMenu(null); + else + m_inputDelegate.setEditPopupMenu(new EditPopupMenu(m_activity, m_view)); } private void createRootWindow() { @@ -175,4 +186,36 @@ class QtEmbeddedDelegate extends QtActivityDelegateBase 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 } |