@@ -2,11 +2,17 @@ package com.simplemobiletools.keyboard.services
22
33import android.inputmethodservice.InputMethodService
44import android.text.InputType
5+ import android.text.InputType.TYPE_CLASS_DATETIME
6+ import android.text.InputType.TYPE_CLASS_NUMBER
7+ import android.text.InputType.TYPE_CLASS_PHONE
8+ import android.text.InputType.TYPE_MASK_CLASS
59import android.text.TextUtils
610import android.view.KeyEvent
711import android.view.View
812import android.view.inputmethod.EditorInfo
913import android.view.inputmethod.EditorInfo.IME_ACTION_NONE
14+ import android.view.inputmethod.EditorInfo.IME_FLAG_NO_ENTER_ACTION
15+ import android.view.inputmethod.EditorInfo.IME_MASK_ACTION
1016import android.view.inputmethod.ExtractedTextRequest
1117import com.simplemobiletools.keyboard.R
1218import com.simplemobiletools.keyboard.extensions.config
@@ -51,11 +57,11 @@ class SimpleKeyboardIME : InputMethodService(), MyKeyboardView.OnKeyboardActionL
5157
5258 override fun onStartInput (attribute : EditorInfo ? , restarting : Boolean ) {
5359 super .onStartInput(attribute, restarting)
54- inputTypeClass = attribute!! .inputType and InputType . TYPE_MASK_CLASS
55- enterKeyType = attribute.imeOptions and (EditorInfo . IME_MASK_ACTION or EditorInfo . IME_FLAG_NO_ENTER_ACTION )
60+ inputTypeClass = attribute!! .inputType and TYPE_MASK_CLASS
61+ enterKeyType = attribute.imeOptions and (IME_MASK_ACTION or IME_FLAG_NO_ENTER_ACTION )
5662
5763 val keyboardXml = when (inputTypeClass) {
58- InputType . TYPE_CLASS_NUMBER , InputType . TYPE_CLASS_DATETIME , InputType . TYPE_CLASS_PHONE -> {
64+ TYPE_CLASS_NUMBER , TYPE_CLASS_DATETIME , TYPE_CLASS_PHONE -> {
5965 keyboardMode = KEYBOARD_SYMBOLS
6066 R .xml.keys_symbols
6167 }
@@ -130,8 +136,13 @@ class SimpleKeyboardIME : InputMethodService(), MyKeyboardView.OnKeyboardActionL
130136 keyboardView!! .invalidateAllKeys()
131137 }
132138 MyKeyboard .KEYCODE_ENTER -> {
133- inputConnection.sendKeyEvent(KeyEvent (KeyEvent .ACTION_DOWN , KeyEvent .KEYCODE_ENTER ))
134- inputConnection.sendKeyEvent(KeyEvent (KeyEvent .ACTION_UP , KeyEvent .KEYCODE_ENTER ))
139+ val imeOptionsActionId = getImeOptionsActionId()
140+ if (imeOptionsActionId != IME_ACTION_NONE ) {
141+ inputConnection.performEditorAction(imeOptionsActionId)
142+ } else {
143+ inputConnection.sendKeyEvent(KeyEvent (KeyEvent .ACTION_DOWN , KeyEvent .KEYCODE_ENTER ))
144+ inputConnection.sendKeyEvent(KeyEvent (KeyEvent .ACTION_UP , KeyEvent .KEYCODE_ENTER ))
145+ }
135146 }
136147 MyKeyboard .KEYCODE_MODE_CHANGE -> {
137148 val keyboardXml = if (keyboardMode == KEYBOARD_LETTERS ) {
@@ -222,6 +233,14 @@ class SimpleKeyboardIME : InputMethodService(), MyKeyboardView.OnKeyboardActionL
222233 currentInputConnection?.setSelection(newCursorPosition, newCursorPosition)
223234 }
224235
236+ private fun getImeOptionsActionId (): Int {
237+ return if (currentInputEditorInfo.imeOptions and IME_FLAG_NO_ENTER_ACTION != 0 ) {
238+ IME_ACTION_NONE
239+ } else {
240+ currentInputEditorInfo.imeOptions and IME_MASK_ACTION
241+ }
242+ }
243+
225244 private fun getKeyboardLayoutXML (): Int {
226245 return when (baseContext.config.keyboardLanguage) {
227246 LANGUAGE_FRENCH -> R .xml.keys_letters_french
0 commit comments