From 2b3f293d892c5268bd2a07ed17fa9fc5adacbd76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Str=C3=B8mme?= Date: Thu, 12 Dec 2013 16:03:12 +0100 Subject: Android: Refactor the InputType mapping code. - Fix issue where input flags and classes where wrongly mixed. - Adds DATETIME class (support for Qt::ImhDate/Qt::ImhTime). - Adds TYPE_NUMBER_VARIATION_PASSWORD for API level > 10. Task-number: QTBUG-35198 Change-Id: I794159ca7c19d38b0b97521448cef0f5112ee8ba Reviewed-by: BogDan Vatra --- .../qtproject/qt5/android/QtActivityDelegate.java | 76 ++++++++++++---------- 1 file changed, 41 insertions(+), 35 deletions(-) (limited to 'src/android/jar') diff --git a/src/android/jar/src/org/qtproject/qt5/android/QtActivityDelegate.java b/src/android/jar/src/org/qtproject/qt5/android/QtActivityDelegate.java index 07b517d3d0..d8c560933f 100644 --- a/src/android/jar/src/org/qtproject/qt5/android/QtActivityDelegate.java +++ b/src/android/jar/src/org/qtproject/qt5/android/QtActivityDelegate.java @@ -242,50 +242,56 @@ public class QtActivityDelegate int imeOptions = android.view.inputmethod.EditorInfo.IME_ACTION_DONE; int inputType = android.text.InputType.TYPE_CLASS_TEXT; - if ((inputHints & ImhMultiLine) != 0) { - inputType = android.text.InputType.TYPE_CLASS_TEXT | android.text.InputType.TYPE_TEXT_FLAG_MULTI_LINE; - imeOptions = android.view.inputmethod.EditorInfo.IME_FLAG_NO_ENTER_ACTION; - } - - if (((inputHints & ImhNoAutoUppercase) != 0 || (inputHints & ImhPreferUppercase) != 0) - && (inputHints & ImhLowercaseOnly) == 0) { - initialCapsMode = android.text.TextUtils.CAP_MODE_SENTENCES; - } - - if ((inputHints & ImhUppercaseOnly) != 0) - initialCapsMode = android.text.TextUtils.CAP_MODE_CHARACTERS; - - if ((inputHints & ImhHiddenText) != 0) - inputType = android.text.InputType.TYPE_TEXT_VARIATION_PASSWORD; - - if ((inputHints & ImhPreferNumbers) != 0) + if ((inputHints & (ImhPreferNumbers | ImhDigitsOnly | ImhFormattedNumbersOnly)) != 0) { inputType = android.text.InputType.TYPE_CLASS_NUMBER; + if ((inputHints & ImhFormattedNumbersOnly) != 0) { + inputType |= (android.text.InputType.TYPE_NUMBER_FLAG_DECIMAL + | android.text.InputType.TYPE_NUMBER_FLAG_SIGNED); + } - if ((inputHints & ImhDigitsOnly) != 0) - inputType = android.text.InputType.TYPE_CLASS_NUMBER; + if (Build.VERSION.SDK_INT > 10 && (inputHints & ImhHiddenText) != 0) + inputType |= 0x10; + } else if ((inputHints & ImhDialableCharactersOnly) != 0) { + inputType = android.text.InputType.TYPE_CLASS_PHONE; + } else if ((inputHints & (ImhDate | ImhTime)) != 0) { + inputType = android.text.InputType.TYPE_CLASS_DATETIME; + if ((inputHints & ImhDate) != 0) + inputType |= android.text.InputType.TYPE_DATETIME_VARIATION_DATE; + if ((inputHints & ImhTime) != 0) + inputType |= android.text.InputType.TYPE_DATETIME_VARIATION_TIME; + } else { // CLASS_TEXT + if ((inputHints & ImhHiddenText) != 0) { + inputType |= android.text.InputType.TYPE_TEXT_VARIATION_PASSWORD; + } else if ((inputHints & (ImhNoAutoUppercase | ImhNoPredictiveText | ImhSensitiveData)) != 0) { + inputType |= android.text.InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD; + } - if ((inputHints & ImhFormattedNumbersOnly) != 0) { - inputType = android.text.InputType.TYPE_CLASS_NUMBER - | android.text.InputType.TYPE_NUMBER_FLAG_DECIMAL - | android.text.InputType.TYPE_NUMBER_FLAG_SIGNED; - } + if ((inputHints & ImhEmailCharactersOnly) != 0) + inputType |= android.text.InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS; - if ((inputHints & ImhDialableCharactersOnly) != 0) - inputType = android.text.InputType.TYPE_CLASS_PHONE; + if ((inputHints & ImhUrlCharactersOnly) != 0) { + inputType |= android.text.InputType.TYPE_TEXT_VARIATION_URI; + imeOptions = android.view.inputmethod.EditorInfo.IME_ACTION_GO; + } - if ((inputHints & ImhEmailCharactersOnly) != 0) - inputType = android.text.InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS; + if ((inputHints & ImhMultiLine) != 0) + inputType |= android.text.InputType.TYPE_TEXT_FLAG_MULTI_LINE; - if ((inputHints & ImhUrlCharactersOnly) != 0) { - inputType = android.text.InputType.TYPE_TEXT_VARIATION_URI; - imeOptions = android.view.inputmethod.EditorInfo.IME_ACTION_GO; - } + if ((inputHints & ImhUppercaseOnly) != 0) { + initialCapsMode |= android.text.TextUtils.CAP_MODE_CHARACTERS; + inputType |= android.text.InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS; + } else if ((inputHints & ImhLowercaseOnly) == 0 && (inputHints & ImhNoAutoUppercase) == 0) { + initialCapsMode |= android.text.TextUtils.CAP_MODE_SENTENCES; + inputType |= android.text.InputType.TYPE_TEXT_FLAG_CAP_SENTENCES; + } - if ((inputHints & ImhNoPredictiveText) != 0) { - //android.text.InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS | android.text.InputType.TYPE_CLASS_TEXT; - inputType = android.text.InputType.TYPE_CLASS_TEXT | android.text.InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD; + if ((inputHints & ImhNoPredictiveText) != 0 || (inputHints & ImhSensitiveData) != 0) + inputType |= android.text.InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS; } + if ((inputHints & ImhMultiLine) != 0) + imeOptions = android.view.inputmethod.EditorInfo.IME_FLAG_NO_ENTER_ACTION; + m_editText.setInitialCapsMode(initialCapsMode); m_editText.setImeOptions(imeOptions); m_editText.setInputType(inputType); -- cgit v1.2.3