@@ -2,7 +2,6 @@ package com.simplemobiletools.keyboard.services
22
33import android.content.SharedPreferences
44import android.inputmethodservice.InputMethodService
5- import android.text.InputType
65import android.text.InputType.*
76import android.text.TextUtils
87import android.view.KeyEvent
@@ -17,8 +16,7 @@ import com.simplemobiletools.keyboard.R
1716import com.simplemobiletools.keyboard.extensions.config
1817import com.simplemobiletools.keyboard.helpers.*
1918import com.simplemobiletools.keyboard.views.MyKeyboardView
20- import kotlinx.android.synthetic.main.keyboard_view_keyboard.view.keyboard_holder
21- import kotlinx.android.synthetic.main.keyboard_view_keyboard.view.keyboard_view
19+ import kotlinx.android.synthetic.main.keyboard_view_keyboard.view.*
2220
2321// based on https://www.androidauthority.com/lets-build-custom-keyboard-android-832362/
2422class SimpleKeyboardIME : InputMethodService (), MyKeyboardView.OnKeyboardActionListener, SharedPreferences.OnSharedPreferenceChangeListener {
@@ -33,8 +31,8 @@ class SimpleKeyboardIME : InputMethodService(), MyKeyboardView.OnKeyboardActionL
3331 private var keyboardView: MyKeyboardView ? = null
3432 private var lastShiftPressTS = 0L
3533 private var keyboardMode = KEYBOARD_LETTERS
36- private var inputTypeClass = InputType . TYPE_CLASS_TEXT
37- private var inputTypeClassVariation = InputType . TYPE_CLASS_TEXT
34+ private var inputTypeClass = TYPE_CLASS_TEXT
35+ private var inputTypeClassVariation = TYPE_CLASS_TEXT
3836 private var enterKeyType = IME_ACTION_NONE
3937 private var switchToLetters = false
4038
@@ -62,7 +60,7 @@ class SimpleKeyboardIME : InputMethodService(), MyKeyboardView.OnKeyboardActionL
6260 override fun onStartInput (attribute : EditorInfo ? , restarting : Boolean ) {
6361 super .onStartInput(attribute, restarting)
6462 inputTypeClass = attribute!! .inputType and TYPE_MASK_CLASS
65- inputTypeClassVariation = attribute!! .inputType and TYPE_MASK_VARIATION
63+ inputTypeClassVariation = attribute.inputType and TYPE_MASK_VARIATION
6664
6765 enterKeyType = attribute.imeOptions and (IME_MASK_ACTION or IME_FLAG_NO_ENTER_ACTION )
6866 keyboard = createNewKeyboard()
@@ -77,7 +75,7 @@ class SimpleKeyboardIME : InputMethodService(), MyKeyboardView.OnKeyboardActionL
7775 }
7876
7977 val editorInfo = currentInputEditorInfo
80- if (config.enableSentencesCapitalization && editorInfo != null && editorInfo.inputType != InputType . TYPE_NULL ) {
78+ if (config.enableSentencesCapitalization && editorInfo != null && editorInfo.inputType != TYPE_NULL ) {
8179 if (currentInputConnection.getCursorCapsMode(editorInfo.inputType) != 0 ) {
8280 keyboard?.setShifted(ShiftState .ON_ONE_CHAR )
8381 keyboardView?.invalidateAllKeys()
@@ -101,7 +99,6 @@ class SimpleKeyboardIME : InputMethodService(), MyKeyboardView.OnKeyboardActionL
10199
102100 when (code) {
103101 MyKeyboard .KEYCODE_DELETE -> {
104-
105102 val selectedText = inputConnection.getSelectedText(0 )
106103 if (TextUtils .isEmpty(selectedText)) {
107104 inputConnection.sendKeyEvent(KeyEvent (KeyEvent .ACTION_DOWN , KeyEvent .KEYCODE_DEL ))
@@ -110,7 +107,6 @@ class SimpleKeyboardIME : InputMethodService(), MyKeyboardView.OnKeyboardActionL
110107 inputConnection.commitText(" " , 1 )
111108 }
112109 }
113-
114110 MyKeyboard .KEYCODE_SHIFT -> {
115111 if (keyboardMode == KEYBOARD_LETTERS ) {
116112 when {
@@ -134,7 +130,6 @@ class SimpleKeyboardIME : InputMethodService(), MyKeyboardView.OnKeyboardActionL
134130 }
135131 keyboardView!! .invalidateAllKeys()
136132 }
137-
138133 MyKeyboard .KEYCODE_ENTER -> {
139134 val imeOptionsActionId = getImeOptionsActionId()
140135 if (imeOptionsActionId != IME_ACTION_NONE ) {
@@ -144,7 +139,6 @@ class SimpleKeyboardIME : InputMethodService(), MyKeyboardView.OnKeyboardActionL
144139 inputConnection.sendKeyEvent(KeyEvent (KeyEvent .ACTION_UP , KeyEvent .KEYCODE_ENTER ))
145140 }
146141 }
147-
148142 MyKeyboard .KEYCODE_MODE_CHANGE -> {
149143 val keyboardXml = if (keyboardMode == KEYBOARD_LETTERS ) {
150144 keyboardMode = KEYBOARD_SYMBOLS
@@ -156,11 +150,9 @@ class SimpleKeyboardIME : InputMethodService(), MyKeyboardView.OnKeyboardActionL
156150 keyboard = MyKeyboard (this , keyboardXml, enterKeyType)
157151 keyboardView!! .setKeyboard(keyboard!! )
158152 }
159-
160153 MyKeyboard .KEYCODE_EMOJI -> {
161154 keyboardView?.openEmojiPalette()
162155 }
163-
164156 else -> {
165157 var codeChar = code.toChar()
166158 val originalText = inputConnection.getExtractedText(ExtractedTextRequest (), 0 )?.text ? : return
@@ -172,7 +164,7 @@ class SimpleKeyboardIME : InputMethodService(), MyKeyboardView.OnKeyboardActionL
172164 // If the keyboard is set to symbols and the user presses space, we usually should switch back to the letters keyboard.
173165 // However, avoid doing that in cases when the EditText for example requires numbers as the input.
174166 // We can detect that by the text not changing on pressing Space.
175- if (keyboardMode != KEYBOARD_LETTERS && inputTypeClass == InputType . TYPE_CLASS_TEXT && code == MyKeyboard .KEYCODE_SPACE ) {
167+ if (keyboardMode != KEYBOARD_LETTERS && inputTypeClass == TYPE_CLASS_TEXT && code == MyKeyboard .KEYCODE_SPACE ) {
176168 inputConnection.commitText(codeChar.toString(), 1 )
177169 val newText = inputConnection.getExtractedText(ExtractedTextRequest (), 0 )?.text
178170 if (originalText != newText) {
@@ -197,7 +189,7 @@ class SimpleKeyboardIME : InputMethodService(), MyKeyboardView.OnKeyboardActionL
197189 keyboard = MyKeyboard (this , getKeyboardLayoutXML(), enterKeyType)
198190
199191 val editorInfo = currentInputEditorInfo
200- if (editorInfo != null && editorInfo.inputType != InputType . TYPE_NULL && keyboard?.mShiftState != ShiftState .ON_PERMANENT ) {
192+ if (editorInfo != null && editorInfo.inputType != TYPE_NULL && keyboard?.mShiftState != ShiftState .ON_PERMANENT ) {
201193 if (currentInputConnection.getCursorCapsMode(editorInfo.inputType) != 0 ) {
202194 keyboard?.setShifted(ShiftState .ON_ONE_CHAR )
203195 }
@@ -232,17 +224,14 @@ class SimpleKeyboardIME : InputMethodService(), MyKeyboardView.OnKeyboardActionL
232224 keyboardMode = KEYBOARD_NUMBERS
233225 R .xml.keys_numbers
234226 }
235-
236227 TYPE_CLASS_PHONE -> {
237228 keyboardMode = KEYBOARD_PHONE
238229 R .xml.keys_phone
239230 }
240-
241231 TYPE_CLASS_DATETIME -> {
242232 keyboardMode = KEYBOARD_SYMBOLS
243233 R .xml.keys_symbols
244234 }
245-
246235 else -> {
247236 keyboardMode = KEYBOARD_LETTERS
248237 getKeyboardLayoutXML()
0 commit comments