Skip to content

Commit 00cd9b4

Browse files
committed
fix #16, improve Enter handling in some cases
1 parent b6467f1 commit 00cd9b4

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ android {
6464
}
6565

6666
dependencies {
67-
implementation 'com.github.SimpleMobileTools:Simple-Commons:3abc10fcdb'
67+
implementation 'com.github.SimpleMobileTools:Simple-Commons:b3416c828f'
6868

6969
kapt 'androidx.room:room-compiler:2.3.0'
7070
implementation 'androidx.room:room-runtime:2.3.0'

app/src/main/kotlin/com/simplemobiletools/keyboard/services/SimpleKeyboardIME.kt

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,17 @@ package com.simplemobiletools.keyboard.services
22

33
import android.inputmethodservice.InputMethodService
44
import 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
59
import android.text.TextUtils
610
import android.view.KeyEvent
711
import android.view.View
812
import android.view.inputmethod.EditorInfo
913
import 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
1016
import android.view.inputmethod.ExtractedTextRequest
1117
import com.simplemobiletools.keyboard.R
1218
import 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

Comments
 (0)