summaryrefslogtreecommitdiffstats
path: root/src/android/jar/src/org/qtproject/qt/android/QtInputDelegate.java
diff options
context:
space:
mode:
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.java325
1 files changed, 168 insertions, 157 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 cfa273e410..3a879776c2 100644
--- a/src/android/jar/src/org/qtproject/qt/android/QtInputDelegate.java
+++ b/src/android/jar/src/org/qtproject/qt/android/QtInputDelegate.java
@@ -21,22 +21,23 @@ 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);
- public static native void keyUp(int key, int unicode, int modifier, boolean autoRepeat);
- public static native void keyboardVisibilityChanged(boolean visibility);
- public static native void keyboardGeometryChanged(int x, int y, int width, int height);
+ static native void keyDown(int key, int unicode, int modifier, boolean autoRepeat);
+ static native void keyUp(int key, int unicode, int modifier, boolean autoRepeat);
+ static native void keyboardVisibilityChanged(boolean visibility);
+ static native void keyboardGeometryChanged(int x, int y, int width, int height);
// keyboard methods
// dispatch events methods
- public static native boolean dispatchGenericMotionEvent(MotionEvent event);
- public static native boolean dispatchKeyEvent(KeyEvent event);
+ static native boolean dispatchGenericMotionEvent(MotionEvent event);
+ static native boolean dispatchKeyEvent(KeyEvent event);
// dispatch events methods
// handle methods
- public static native void handleLocationChanged(int id, int x, int y);
+ static native void handleLocationChanged(int id, int x, int y);
// handle methods
private QtEditText m_currentEditText = null;
@@ -62,9 +63,9 @@ class QtInputDelegate implements QtInputConnection.QtInputConnectionListener {
private static final int CursorHandleShowEdit = 0x100;
// Handle IDs
- public static final int IdCursorHandle = 1;
- public static final int IdLeftHandle = 2;
- public static final int IdRightHandle = 3;
+ static final int IdCursorHandle = 1;
+ static final int IdLeftHandle = 2;
+ static final int IdRightHandle = 3;
private static Boolean m_tabletEventSupported = null;
@@ -78,7 +79,7 @@ class QtInputDelegate implements QtInputConnection.QtInputConnectionListener {
// Note: because of the circular call to updateFullScreen() from the delegate, we need
// a listener to be able to do that call from the delegate, because that's where that
// logic lives
- public interface KeyboardVisibilityListener {
+ interface KeyboardVisibilityListener {
void onKeyboardVisibilityChange();
}
@@ -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) {
@@ -108,18 +243,11 @@ class QtInputDelegate implements QtInputConnection.QtInputConnectionListener {
}
// QtInputConnectionListener methods
- public boolean isKeyboardVisible()
+ boolean isKeyboardVisible()
{
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;
@@ -141,7 +269,7 @@ class QtInputDelegate implements QtInputConnection.QtInputConnectionListener {
QtInputDelegate.keyboardVisibilityChanged(visibility);
}
- public void setKeyboardVisibility(boolean visibility, long timeStamp)
+ void setKeyboardVisibility(boolean visibility, long timeStamp)
{
if (m_showHideTimeStamp > timeStamp)
return;
@@ -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)
@@ -416,7 +427,7 @@ class QtInputDelegate implements QtInputConnection.QtInputConnectionListener {
}
}
- public boolean onKeyDown(int keyCode, KeyEvent event)
+ boolean onKeyDown(int keyCode, KeyEvent event)
{
m_metaState = MetaKeyKeyListener.handleKeyDown(m_metaState, keyCode, event);
int metaState = MetaKeyKeyListener.getMetaState(m_metaState) | event.getMetaState();
@@ -448,7 +459,7 @@ class QtInputDelegate implements QtInputConnection.QtInputConnectionListener {
return true;
}
- public boolean onKeyUp(int keyCode, KeyEvent event)
+ boolean onKeyUp(int keyCode, KeyEvent event)
{
if ((keyCode == KeyEvent.KEYCODE_VOLUME_UP
|| keyCode == KeyEvent.KEYCODE_VOLUME_DOWN
@@ -470,7 +481,7 @@ class QtInputDelegate implements QtInputConnection.QtInputConnectionListener {
return true;
}
- public boolean handleDispatchKeyEvent(KeyEvent event)
+ boolean handleDispatchKeyEvent(KeyEvent event)
{
if (event.getAction() == KeyEvent.ACTION_MULTIPLE
&& event.getCharacters() != null
@@ -485,7 +496,7 @@ class QtInputDelegate implements QtInputConnection.QtInputConnectionListener {
return dispatchKeyEvent(event);
}
- public boolean handleDispatchGenericMotionEvent(MotionEvent event)
+ boolean handleDispatchGenericMotionEvent(MotionEvent event)
{
return dispatchGenericMotionEvent(event);
}
@@ -495,24 +506,24 @@ class QtInputDelegate implements QtInputConnection.QtInputConnectionListener {
//////////////////////////////
// tablet methods
- public static native boolean isTabletEventSupported();
- public static native void tabletEvent(int winId, int deviceId, long time, int action,
+ static native boolean isTabletEventSupported();
+ static native void tabletEvent(int winId, int deviceId, long time, int action,
int pointerType, int buttonState, float x, float y,
float pressure);
// tablet methods
// pointer methods
- 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);
- public static native void touchAdd(int winId, int pointerId, int action, boolean primary,
+ static native void mouseDown(int winId, int x, int y, int mouseButtonState);
+ static native void mouseUp(int winId, int x, int y, int mouseButtonState);
+ static native void mouseMove(int winId, int x, int y);
+ static native void mouseWheel(int winId, int x, int y, float hDelta, float vDelta);
+ static native void touchBegin(int winId);
+ static native void touchAdd(int winId, int pointerId, int action, boolean primary,
int x, int y, float major, float minor, float rotation,
float pressure);
- public static native void touchEnd(int winId, int action);
- public static native void touchCancel(int winId);
- public static native void longPress(int winId, int x, int y);
+ static native void touchEnd(int winId, int action);
+ static native void touchCancel(int winId);
+ static native void longPress(int winId, int x, int y);
// pointer methods
static private int getAction(int index, MotionEvent event)
@@ -542,7 +553,7 @@ class QtInputDelegate implements QtInputConnection.QtInputConnectionListener {
return 2;
}
- static public void sendTouchEvent(MotionEvent event, int id)
+ static void sendTouchEvent(MotionEvent event, int id)
{
int pointerType = 0;
@@ -598,12 +609,12 @@ class QtInputDelegate implements QtInputConnection.QtInputConnectionListener {
}
}
- static public void sendTrackballEvent(MotionEvent event, int id)
+ static void sendTrackballEvent(MotionEvent event, int id)
{
sendMouseEvent(event,id);
}
- static public boolean sendGenericMotionEvent(MotionEvent event, int id)
+ static boolean sendGenericMotionEvent(MotionEvent event, int id)
{
int scrollOrHoverMove = MotionEvent.ACTION_SCROLL | MotionEvent.ACTION_HOVER_MOVE;
int pointerDeviceModifier = (event.getSource() & InputDevice.SOURCE_CLASS_POINTER);
@@ -615,7 +626,7 @@ class QtInputDelegate implements QtInputConnection.QtInputConnectionListener {
return sendMouseEvent(event, id);
}
- static public boolean sendMouseEvent(MotionEvent event, int id)
+ static boolean sendMouseEvent(MotionEvent event, int id)
{
switch (event.getActionMasked()) {
case MotionEvent.ACTION_UP: