Android: handle ImEnterKeyType flag

Replace KEYCODE_ENTER to KEYCODE_TAB if IME_ACTION_NEXT or
IME_ACTION_PREVIOUS flag is set.

Before this change any of imKeyEntryType [1] was handled as default
return key. After the fix, event is changed to Tab or Backtab (if any of
mentioned flag is set)

[1] https://doc.qt.io/qt-5/qt.html#EnterKeyType-enum

Fixes: QTBUG-61652
Pick-to: 5.15
Change-Id: Ia27aa308fdae75bc17d1e892d17048c5afa3e2cb
Reviewed-by: Rami Potinkara <rami.potinkara@qt.io>
Reviewed-by: Ville Voutilainen <ville.voutilainen@qt.io>
This commit is contained in:
Bartlomiej Moskal 2021-02-18 13:34:34 +01:00
parent 33ac3cf766
commit e5686b35f0
2 changed files with 31 additions and 1 deletions

View File

@ -375,8 +375,12 @@ public class QtActivityDelegate
inputType |= android.text.InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS; inputType |= android.text.InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS;
} }
if ((inputHints & ImhMultiLine) != 0) if ((inputHints & ImhMultiLine) != 0) {
inputType |= android.text.InputType.TYPE_TEXT_FLAG_MULTI_LINE; inputType |= android.text.InputType.TYPE_TEXT_FLAG_MULTI_LINE;
// Clear imeOptions for Multi-Line Type
// User should be able to insert new line in such case
imeOptions = android.view.inputmethod.EditorInfo.IME_ACTION_DONE;
}
if ((inputHints & (ImhNoPredictiveText | ImhSensitiveData | ImhHiddenText)) != 0) if ((inputHints & (ImhNoPredictiveText | ImhSensitiveData | ImhHiddenText)) != 0)
inputType |= android.text.InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS; inputType |= android.text.InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS;

View File

@ -257,6 +257,32 @@ public class QtInputConnection extends BaseInputConnection
// If the sendKeyEvent was invoked, it means that the button not related with composingText was used // If the sendKeyEvent was invoked, it means that the button not related with composingText was used
// In such case composing text (if it exists) should be finished immediately // In such case composing text (if it exists) should be finished immediately
finishComposingText(); finishComposingText();
if (event.getKeyCode() == KeyEvent.KEYCODE_ENTER && m_view != null) {
KeyEvent fakeEvent;
switch (m_view.m_imeOptions) {
case android.view.inputmethod.EditorInfo.IME_ACTION_NEXT:
fakeEvent = new KeyEvent(event.getDownTime(),
event.getEventTime(),
event.getAction(),
KeyEvent.KEYCODE_TAB,
event.getRepeatCount(),
event.getMetaState());
return super.sendKeyEvent(fakeEvent);
case android.view.inputmethod.EditorInfo.IME_ACTION_PREVIOUS:
fakeEvent = new KeyEvent(event.getDownTime(),
event.getEventTime(),
event.getAction(),
KeyEvent.KEYCODE_TAB,
event.getRepeatCount(),
KeyEvent.META_SHIFT_ON);
return super.sendKeyEvent(fakeEvent);
default:
break;
}
}
return super.sendKeyEvent(event); return super.sendKeyEvent(event);
} }