Android: Add support for EnterKey
QAndroidInputContext now sends along the EnterKey type provided by the EnterKey input method query enabling the QtActivityDelegate to set the imeOptions for the TextView accordingly. Change-Id: Ic96077ab4b11cf6dec52283ecf66b2cabe7af665 Reviewed-by: BogDan Vatra <bogdan@kde.org>
This commit is contained in:
parent
b8c57e5fb1
commit
fc410c1398
@ -203,6 +203,16 @@ public class QtActivityDelegate
|
|||||||
private final int ImhUrlCharactersOnly = 0x400000;
|
private final int ImhUrlCharactersOnly = 0x400000;
|
||||||
private final int ImhLatinOnly = 0x800000;
|
private final int ImhLatinOnly = 0x800000;
|
||||||
|
|
||||||
|
// enter key type - must be kept in sync with QTDIR/src/corelib/global/qnamespace.h
|
||||||
|
private final int EnterKeyDefault = 0;
|
||||||
|
private final int EnterKeyReturn = 1;
|
||||||
|
private final int EnterKeyDone = 2;
|
||||||
|
private final int EnterKeyGo = 3;
|
||||||
|
private final int EnterKeySend = 4;
|
||||||
|
private final int EnterKeySearch = 5;
|
||||||
|
private final int EnterKeyNext = 6;
|
||||||
|
private final int EnterKeyPrevious = 7;
|
||||||
|
|
||||||
// application state
|
// application state
|
||||||
private final int ApplicationSuspended = 0x0;
|
private final int ApplicationSuspended = 0x0;
|
||||||
private final int ApplicationHidden = 0x1;
|
private final int ApplicationHidden = 0x1;
|
||||||
@ -239,7 +249,7 @@ public class QtActivityDelegate
|
|||||||
}, 5);
|
}, 5);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void showSoftwareKeyboard(int x, int y, int width, int height, int inputHints)
|
public void showSoftwareKeyboard(int x, int y, int width, int height, int inputHints, int enterKeyType)
|
||||||
{
|
{
|
||||||
if (m_imm == null)
|
if (m_imm == null)
|
||||||
return;
|
return;
|
||||||
@ -252,7 +262,31 @@ public class QtActivityDelegate
|
|||||||
m_activity.getWindow().setSoftInputMode(m_softInputMode);
|
m_activity.getWindow().setSoftInputMode(m_softInputMode);
|
||||||
|
|
||||||
int initialCapsMode = 0;
|
int initialCapsMode = 0;
|
||||||
|
|
||||||
int imeOptions = android.view.inputmethod.EditorInfo.IME_ACTION_DONE;
|
int imeOptions = android.view.inputmethod.EditorInfo.IME_ACTION_DONE;
|
||||||
|
|
||||||
|
switch (enterKeyType) {
|
||||||
|
case EnterKeyReturn:
|
||||||
|
imeOptions = android.view.inputmethod.EditorInfo.IME_FLAG_NO_ENTER_ACTION;
|
||||||
|
break;
|
||||||
|
case EnterKeyGo:
|
||||||
|
imeOptions = android.view.inputmethod.EditorInfo.IME_ACTION_GO;
|
||||||
|
break;
|
||||||
|
case EnterKeySend:
|
||||||
|
imeOptions = android.view.inputmethod.EditorInfo.IME_ACTION_SEND;
|
||||||
|
break;
|
||||||
|
case EnterKeySearch:
|
||||||
|
imeOptions = android.view.inputmethod.EditorInfo.IME_ACTION_SEARCH;
|
||||||
|
break;
|
||||||
|
case EnterKeyNext:
|
||||||
|
imeOptions = android.view.inputmethod.EditorInfo.IME_ACTION_NEXT;
|
||||||
|
break;
|
||||||
|
case EnterKeyPrevious:
|
||||||
|
if (Build.VERSION.SDK_INT > 10)
|
||||||
|
imeOptions = android.view.inputmethod.EditorInfo.IME_ACTION_PREVIOUS;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
int inputType = android.text.InputType.TYPE_CLASS_TEXT;
|
int inputType = android.text.InputType.TYPE_CLASS_TEXT;
|
||||||
|
|
||||||
if ((inputHints & (ImhPreferNumbers | ImhDigitsOnly | ImhFormattedNumbersOnly)) != 0) {
|
if ((inputHints & (ImhPreferNumbers | ImhDigitsOnly | ImhFormattedNumbersOnly)) != 0) {
|
||||||
@ -278,6 +312,8 @@ public class QtActivityDelegate
|
|||||||
if ((inputHints & (ImhEmailCharactersOnly | ImhUrlCharactersOnly)) != 0) {
|
if ((inputHints & (ImhEmailCharactersOnly | ImhUrlCharactersOnly)) != 0) {
|
||||||
if ((inputHints & ImhUrlCharactersOnly) != 0) {
|
if ((inputHints & ImhUrlCharactersOnly) != 0) {
|
||||||
inputType |= android.text.InputType.TYPE_TEXT_VARIATION_URI;
|
inputType |= android.text.InputType.TYPE_TEXT_VARIATION_URI;
|
||||||
|
|
||||||
|
if (enterKeyType == 0) // not explicitly overridden
|
||||||
imeOptions = android.view.inputmethod.EditorInfo.IME_ACTION_GO;
|
imeOptions = android.view.inputmethod.EditorInfo.IME_ACTION_GO;
|
||||||
} else if ((inputHints & ImhEmailCharactersOnly) != 0) {
|
} else if ((inputHints & ImhEmailCharactersOnly) != 0) {
|
||||||
inputType |= android.text.InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS;
|
inputType |= android.text.InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS;
|
||||||
@ -305,7 +341,7 @@ public class QtActivityDelegate
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((inputHints & ImhMultiLine) != 0)
|
if (enterKeyType == 0 && (inputHints & ImhMultiLine) != 0)
|
||||||
imeOptions = android.view.inputmethod.EditorInfo.IME_FLAG_NO_ENTER_ACTION;
|
imeOptions = android.view.inputmethod.EditorInfo.IME_FLAG_NO_ENTER_ACTION;
|
||||||
|
|
||||||
m_editText.setInitialCapsMode(initialCapsMode);
|
m_editText.setInitialCapsMode(initialCapsMode);
|
||||||
|
@ -389,12 +389,13 @@ public class QtNative
|
|||||||
final int y,
|
final int y,
|
||||||
final int width,
|
final int width,
|
||||||
final int height,
|
final int height,
|
||||||
final int inputHints )
|
final int inputHints,
|
||||||
|
final int enterKeyType)
|
||||||
{
|
{
|
||||||
runAction(new Runnable() {
|
runAction(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
m_activityDelegate.showSoftwareKeyboard(x, y, width, height, inputHints);
|
m_activityDelegate.showSoftwareKeyboard(x, y, width, height, inputHints, enterKeyType);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -70,18 +70,20 @@ namespace QtAndroidInput
|
|||||||
candidatesEnd);
|
candidatesEnd);
|
||||||
}
|
}
|
||||||
|
|
||||||
void showSoftwareKeyboard(int left, int top, int width, int height, int inputHints)
|
void showSoftwareKeyboard(int left, int top, int width, int height, int inputHints, int enterKeyType)
|
||||||
{
|
{
|
||||||
QJNIObjectPrivate::callStaticMethod<void>(applicationClass(),
|
QJNIObjectPrivate::callStaticMethod<void>(applicationClass(),
|
||||||
"showSoftwareKeyboard",
|
"showSoftwareKeyboard",
|
||||||
"(IIIII)V",
|
"(IIIIII)V",
|
||||||
left,
|
left,
|
||||||
top,
|
top,
|
||||||
width,
|
width,
|
||||||
height,
|
height,
|
||||||
inputHints);
|
inputHints,
|
||||||
|
enterKeyType
|
||||||
|
);
|
||||||
#ifdef QT_DEBUG_ANDROID_IM_PROTOCOL
|
#ifdef QT_DEBUG_ANDROID_IM_PROTOCOL
|
||||||
qDebug() << "@@@ SHOWSOFTWAREKEYBOARD" << left << top << width << height << inputHints;
|
qDebug() << "@@@ SHOWSOFTWAREKEYBOARD" << left << top << width << height << inputHints << enterKeyType;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,7 +41,7 @@ QT_BEGIN_NAMESPACE
|
|||||||
namespace QtAndroidInput
|
namespace QtAndroidInput
|
||||||
{
|
{
|
||||||
// Software keyboard support
|
// Software keyboard support
|
||||||
void showSoftwareKeyboard(int top, int left, int width, int height, int inputHints);
|
void showSoftwareKeyboard(int top, int left, int width, int height, int inputHints, int enterKeyType);
|
||||||
void resetSoftwareKeyboard();
|
void resetSoftwareKeyboard();
|
||||||
void hideSoftwareKeyboard();
|
void hideSoftwareKeyboard();
|
||||||
bool isSoftwareKeyboardVisible();
|
bool isSoftwareKeyboardVisible();
|
||||||
|
@ -545,7 +545,9 @@ void QAndroidInputContext::showInputPanel()
|
|||||||
rect.top(),
|
rect.top(),
|
||||||
rect.width(),
|
rect.width(),
|
||||||
rect.height(),
|
rect.height(),
|
||||||
query->value(Qt::ImHints).toUInt());
|
query->value(Qt::ImHints).toUInt(),
|
||||||
|
query->value(Qt::ImEnterKeyType).toUInt()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void QAndroidInputContext::showInputPanelLater(Qt::ApplicationState state)
|
void QAndroidInputContext::showInputPanelLater(Qt::ApplicationState state)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user