Android: Do not request focus on window touch
Remove focusing QtEditText on window touch so that hardware keyboard events can still be sent to the application after touching the screen. Move QtEditText focus request back to showSoftwareKeyboard in QtInputDelegate, so that we can still show virtual keyboard on QtEditText when needed. So that QtInputDelegate still has a valid QtEditText instance to show a virtual keyboard with, add a new QtInputConnectionListener interface function that gives the currently "active" QtEditText to listeners. Call the new QtInputConnectionListener interface function when QtWindow is touched. Pick-to: 6.7 Task-number: QTBUG-126187 Change-Id: Iff90b96351d5285249d5bcd19f3caa648628cf14 Reviewed-by: Tinja Paavoseppä <tinja.paavoseppa@qt.io> (cherry picked from commit 25852624e1a306ab35acb7192ab29dc80b416556) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
07dc649747
commit
bdca63dba3
@ -116,7 +116,6 @@ abstract class QtActivityDelegateBase
|
||||
if (newFocus instanceof QtEditText) {
|
||||
final QtWindow newWindow = (QtWindow) newFocus.getParent();
|
||||
QtWindow.windowFocusChanged(true, newWindow.getId());
|
||||
m_inputDelegate.setFocusedView((QtEditText) newFocus);
|
||||
} else {
|
||||
int id = -1;
|
||||
if (oldFocus instanceof QtEditText) {
|
||||
@ -124,7 +123,6 @@ abstract class QtActivityDelegateBase
|
||||
id = oldWindow.getId();
|
||||
}
|
||||
QtWindow.windowFocusChanged(false, id);
|
||||
m_inputDelegate.setFocusedView(null);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -104,6 +104,7 @@ class QtInputConnection extends BaseInputConnection
|
||||
void onSetClosing(boolean closing);
|
||||
void onHideKeyboardRunnableDone(boolean visibility, long hideTimeStamp);
|
||||
void onSendKeyEventDefaultCase();
|
||||
void onEditTextChanged(QtEditText editText);
|
||||
}
|
||||
|
||||
private final QtEditText m_view;
|
||||
|
@ -117,6 +117,7 @@ class QtInputDelegate implements QtInputConnection.QtInputConnectionListener, Qt
|
||||
return;
|
||||
|
||||
m_currentEditText.setEditTextOptions(enterKeyType, inputHints);
|
||||
m_currentEditText.requestFocus();
|
||||
|
||||
m_currentEditText.postDelayed(() -> {
|
||||
m_imm.showSoftInput(m_currentEditText, 0, new ResultReceiver(new Handler()) {
|
||||
@ -241,6 +242,11 @@ class QtInputDelegate implements QtInputConnection.QtInputConnectionListener, Qt
|
||||
public void onSendKeyEventDefaultCase() {
|
||||
hideSoftwareKeyboard();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEditTextChanged(QtEditText editText) {
|
||||
setFocusedView(editText);
|
||||
}
|
||||
// QtInputConnectionListener methods
|
||||
|
||||
boolean isKeyboardVisible()
|
||||
@ -283,7 +289,6 @@ class QtInputDelegate implements QtInputConnection.QtInputConnectionListener, Qt
|
||||
// Hiding the keyboard clears the immersive mode, so we need to set it again.
|
||||
if (!visibility)
|
||||
m_keyboardVisibilityListener.onKeyboardVisibilityChange();
|
||||
|
||||
}
|
||||
|
||||
void setFocusedView(QtEditText currentEditText)
|
||||
|
@ -19,6 +19,7 @@ class QtWindow extends QtLayout implements QtSurfaceInterface {
|
||||
private QtWindow m_parentWindow;
|
||||
private GestureDetector m_gestureDetector;
|
||||
private final QtEditText m_editText;
|
||||
private final QtInputConnection.QtInputConnectionListener m_inputConnectionListener;
|
||||
|
||||
private static native void setSurface(int windowId, Surface surface);
|
||||
static native void windowFocusChanged(boolean hasFocus, int id);
|
||||
@ -29,6 +30,7 @@ class QtWindow extends QtLayout implements QtSurfaceInterface {
|
||||
super(context);
|
||||
setId(View.generateViewId());
|
||||
m_editText = new QtEditText(context, listener);
|
||||
m_inputConnectionListener = listener;
|
||||
setParent(parentWindow);
|
||||
setFocusableInTouchMode(true);
|
||||
addView(m_editText, new QtLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
|
||||
@ -65,7 +67,9 @@ class QtWindow extends QtLayout implements QtSurfaceInterface {
|
||||
@Override
|
||||
public boolean onTouchEvent(MotionEvent event)
|
||||
{
|
||||
m_editText.requestFocus();
|
||||
if (m_editText != null && m_inputConnectionListener != null)
|
||||
m_inputConnectionListener.onEditTextChanged(m_editText);
|
||||
|
||||
event.setLocation(event.getX() + getX(), event.getY() + getY());
|
||||
QtInputDelegate.sendTouchEvent(event, getId());
|
||||
m_gestureDetector.onTouchEvent(event);
|
||||
|
Loading…
x
Reference in New Issue
Block a user