diff options
Diffstat (limited to 'src/android/jar/src/org/qtproject/qt/android/QtInputDelegate.java')
-rw-r--r-- | src/android/jar/src/org/qtproject/qt/android/QtInputDelegate.java | 280 |
1 files changed, 146 insertions, 134 deletions
diff --git a/src/android/jar/src/org/qtproject/qt/android/QtInputDelegate.java b/src/android/jar/src/org/qtproject/qt/android/QtInputDelegate.java index 206b024877..bf5578285a 100644 --- a/src/android/jar/src/org/qtproject/qt/android/QtInputDelegate.java +++ b/src/android/jar/src/org/qtproject/qt/android/QtInputDelegate.java @@ -21,7 +21,8 @@ import android.view.inputmethod.InputMethodManager; import org.qtproject.qt.android.QtInputConnection.QtInputConnectionListener; /** @noinspection FieldCanBeLocal*/ -class QtInputDelegate implements QtInputConnection.QtInputConnectionListener { +class QtInputDelegate implements QtInputConnection.QtInputConnectionListener, QtInputInterface +{ // keyboard methods public static native void keyDown(int key, int unicode, int modifier, boolean autoRepeat); @@ -90,6 +91,140 @@ class QtInputDelegate implements QtInputConnection.QtInputConnectionListener { m_imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE); } + // QtInputInterface implementation begin + @Override + public void updateSelection(final int selStart, final int selEnd, + final int candidatesStart, final int candidatesEnd) + { + QtNative.runAction(() -> { + if (m_imm == null) + return; + + m_imm.updateSelection(m_currentEditText, selStart, selEnd, candidatesStart, candidatesEnd); + }); + } + + @Override + public void showSoftwareKeyboard(Activity activity, QtLayout layout, + final int x, final int y, final int width, final int height, + final int inputHints, final int enterKeyType) + { + QtNative.runAction(() -> { + if (m_imm == null || m_currentEditText == null) + return; + + if (updateSoftInputMode(activity, height)) + return; + + m_currentEditText.setEditTextOptions(enterKeyType, inputHints); + + m_currentEditText.postDelayed(() -> { + m_imm.showSoftInput(m_currentEditText, 0, new ResultReceiver(new Handler()) { + @Override + protected void onReceiveResult(int resultCode, Bundle resultData) { + switch (resultCode) { + case InputMethodManager.RESULT_SHOWN: + QtNativeInputConnection.updateCursorPosition(); + //FALLTHROUGH + case InputMethodManager.RESULT_UNCHANGED_SHOWN: + setKeyboardVisibility(true, System.nanoTime()); + if (m_softInputMode == 0) { + probeForKeyboardHeight(layout, activity, + x, y, width, height, inputHints, enterKeyType); + } + break; + case InputMethodManager.RESULT_HIDDEN: + case InputMethodManager.RESULT_UNCHANGED_HIDDEN: + setKeyboardVisibility(false, System.nanoTime()); + break; + } + } + }); + if (m_currentEditText.m_optionsChanged) { + m_imm.restartInput(m_currentEditText); + m_currentEditText.m_optionsChanged = false; + } + }, 15); + }); + } + + @Override + public int getSelectHandleWidth() + { + int width = 0; + if (m_leftSelectionHandle != null && m_rightSelectionHandle != null) { + width = Math.max(m_leftSelectionHandle.width(), m_rightSelectionHandle.width()); + } else if (m_cursorHandle != null) { + width = m_cursorHandle.width(); + } + return width; + } + + /* called from the C++ code when the position of the cursor or selection handles needs to + be adjusted. + mode is one of QAndroidInputContext::CursorHandleShowMode + */ + @Override + public void updateHandles(Activity activity, QtLayout layout, int mode, + int editX, int editY, int editButtons, + int x1, int y1, int x2, int y2, boolean rtl) + { + QtNative.runAction(() -> updateHandleImpl(activity, layout, mode, editX, editY, editButtons, + x1, y1, x2, y2, rtl)); + } + + @Override + public QtInputConnection.QtInputConnectionListener getInputConnectionListener() + { + return this; + } + + @Override + public void resetSoftwareKeyboard() + { + if (m_imm == null || m_currentEditText == null) + return; + m_currentEditText.postDelayed(() -> { + m_imm.restartInput(m_currentEditText); + m_currentEditText.m_optionsChanged = false; + }, 5); + } + + @Override + public void hideSoftwareKeyboard() + { + m_isKeyboardHidingAnimationOngoing = true; + QtNative.runAction(() -> { + if (m_imm == null || m_currentEditText == null) + return; + + m_imm.hideSoftInputFromWindow(m_currentEditText.getWindowToken(), 0, + new ResultReceiver(new Handler()) { + @Override + protected void onReceiveResult(int resultCode, Bundle resultData) { + switch (resultCode) { + case InputMethodManager.RESULT_SHOWN: + case InputMethodManager.RESULT_UNCHANGED_SHOWN: + setKeyboardVisibility(true, System.nanoTime()); + break; + case InputMethodManager.RESULT_HIDDEN: + case InputMethodManager.RESULT_UNCHANGED_HIDDEN: + setKeyboardVisibility(false, System.nanoTime()); + break; + } + } + }); + }); + } + + // Is the keyboard fully visible i.e. visible and no ongoing animation + @Override + public boolean isSoftwareKeyboardVisible() + { + return isKeyboardVisible() && !m_isKeyboardHidingAnimationOngoing; + } + // QtInputInterface implementation end + // QtInputConnectionListener methods @Override public void onSetClosing(boolean closing) { @@ -113,13 +248,6 @@ class QtInputDelegate implements QtInputConnection.QtInputConnectionListener { return m_keyboardIsVisible; } - // Is the keyboard fully visible i.e. visible and no ongoing animation - @UsedFromNativeCode - public boolean isSoftwareKeyboardVisible() - { - return isKeyboardVisible() && !m_isKeyboardHidingAnimationOngoing; - } - void setSoftInputMode(int inputMode) { m_softInputMode = inputMode; @@ -158,65 +286,11 @@ class QtInputDelegate implements QtInputConnection.QtInputConnectionListener { } - @UsedFromNativeCode - public void resetSoftwareKeyboard() - { - if (m_imm == null || m_currentEditText == null) - return; - m_currentEditText.postDelayed(() -> { - m_imm.restartInput(m_currentEditText); - m_currentEditText.m_optionsChanged = false; - }, 5); - } - void setFocusedView(QtEditText currentEditText) { m_currentEditText = currentEditText; } - public void showSoftwareKeyboard(Activity activity, QtLayout layout, - final int x, final int y, final int width, final int height, - final int inputHints, final int enterKeyType) - { - QtNative.runAction(() -> { - if (m_imm == null || m_currentEditText == null) - return; - - if (updateSoftInputMode(activity, height)) - return; - - m_currentEditText.setEditTextOptions(enterKeyType, inputHints); - - m_currentEditText.postDelayed(() -> { - m_imm.showSoftInput(m_currentEditText, 0, new ResultReceiver(new Handler()) { - @Override - protected void onReceiveResult(int resultCode, Bundle resultData) { - switch (resultCode) { - case InputMethodManager.RESULT_SHOWN: - QtNativeInputConnection.updateCursorPosition(); - //FALLTHROUGH - case InputMethodManager.RESULT_UNCHANGED_SHOWN: - setKeyboardVisibility(true, System.nanoTime()); - if (m_softInputMode == 0) { - probeForKeyboardHeight(layout, activity, - x, y, width, height, inputHints, enterKeyType); - } - break; - case InputMethodManager.RESULT_HIDDEN: - case InputMethodManager.RESULT_UNCHANGED_HIDDEN: - setKeyboardVisibility(false, System.nanoTime()); - break; - } - } - }); - if (m_currentEditText.m_optionsChanged) { - m_imm.restartInput(m_currentEditText); - m_currentEditText.m_optionsChanged = false; - } - }, 15); - }); - } - private boolean updateSoftInputMode(Activity activity, int height) { DisplayMetrics metrics = new DisplayMetrics(); @@ -284,69 +358,6 @@ class QtInputDelegate implements QtInputConnection.QtInputConnectionListener { }, m_probeKeyboardHeightDelayMs); } - public void hideSoftwareKeyboard() - { - m_isKeyboardHidingAnimationOngoing = true; - QtNative.runAction(() -> { - if (m_imm == null || m_currentEditText == null) - return; - - m_imm.hideSoftInputFromWindow(m_currentEditText.getWindowToken(), 0, - new ResultReceiver(new Handler()) { - @Override - protected void onReceiveResult(int resultCode, Bundle resultData) { - switch (resultCode) { - case InputMethodManager.RESULT_SHOWN: - case InputMethodManager.RESULT_UNCHANGED_SHOWN: - setKeyboardVisibility(true, System.nanoTime()); - break; - case InputMethodManager.RESULT_HIDDEN: - case InputMethodManager.RESULT_UNCHANGED_HIDDEN: - setKeyboardVisibility(false, System.nanoTime()); - break; - } - } - }); - }); - } - - @UsedFromNativeCode - public void updateSelection(final int selStart, final int selEnd, - final int candidatesStart, final int candidatesEnd) - { - QtNative.runAction(() -> { - if (m_imm == null) - return; - - m_imm.updateSelection(m_currentEditText, selStart, selEnd, candidatesStart, candidatesEnd); - }); - } - - @UsedFromNativeCode - public int getSelectHandleWidth() - { - int width = 0; - if (m_leftSelectionHandle != null && m_rightSelectionHandle != null) { - width = Math.max(m_leftSelectionHandle.width(), m_rightSelectionHandle.width()); - } else if (m_cursorHandle != null) { - width = m_cursorHandle.width(); - } - return width; - } - - /* called from the C++ code when the position of the cursor or selection handles needs to - be adjusted. - mode is one of QAndroidInputContext::CursorHandleShowMode - */ - @UsedFromNativeCode - public void updateHandles(Activity activity, QtLayout layout, int mode, - int editX, int editY, int editButtons, - int x1, int y1, int x2, int y2, boolean rtl) - { - QtNative.runAction(() -> updateHandleImpl(activity, layout, mode, editX, editY, editButtons, - x1, y1, x2, y2, rtl)); - } - private void updateHandleImpl(Activity activity, QtLayout layout, int mode, int editX, int editY, int editButtons, int x1, int y1, int x2, int y2, boolean rtl) @@ -406,12 +417,13 @@ class QtInputDelegate implements QtInputConnection.QtInputConnectionListener { if (!QtClipboardManager.hasClipboardText(activity)) editButtons &= ~EditContextView.PASTE_BUTTON; - if ((mode & CursorHandleShowEdit) == CursorHandleShowEdit && editButtons != 0) { - m_editPopupMenu.setPosition(editX, editY, editButtons, - m_cursorHandle, m_leftSelectionHandle, m_rightSelectionHandle); - } else { - if (m_editPopupMenu != null) + if (m_editPopupMenu != null) { + if ((mode & CursorHandleShowEdit) == CursorHandleShowEdit && editButtons != 0) { + m_editPopupMenu.setPosition(editX, editY, editButtons, + m_cursorHandle, m_leftSelectionHandle, m_rightSelectionHandle); + } else { m_editPopupMenu.hide(); + } } } @@ -501,8 +513,8 @@ class QtInputDelegate implements QtInputConnection.QtInputConnectionListener { // tablet methods // pointer methods - public static native void mouseDown(int winId, int x, int y); - public static native void mouseUp(int winId, int x, int y); + public static native void mouseDown(int winId, int x, int y, int mouseButtonState); + public static native void mouseUp(int winId, int x, int y, int mouseButtonState); public static native void mouseMove(int winId, int x, int y); public static native void mouseWheel(int winId, int x, int y, float hDelta, float vDelta); public static native void touchBegin(int winId); @@ -618,11 +630,11 @@ class QtInputDelegate implements QtInputConnection.QtInputConnectionListener { { switch (event.getActionMasked()) { case MotionEvent.ACTION_UP: - mouseUp(id, (int) event.getX(), (int) event.getY()); + mouseUp(id, (int) event.getX(), (int) event.getY(), event.getButtonState()); break; case MotionEvent.ACTION_DOWN: - mouseDown(id, (int) event.getX(), (int) event.getY()); + mouseDown(id, (int) event.getX(), (int) event.getY(), event.getButtonState()); m_oldX = (int) event.getX(); m_oldY = (int) event.getY(); break; |