@@ -72,52 +72,20 @@ class SimpleKeyboardIME : InputMethodService(), MyKeyboardView.OnKeyboardActionL
7272 }
7373
7474 private fun updateShiftKeyState (code : Int? ) {
75- if (keyboardMode != KEYBOARD_LETTERS || ShiftState .isInputTypeAllowedCapitalizing(inputTypeClassVariation) ) {
75+ if (code == MyKeyboard . KEYCODE_SHIFT ) {
7676 return
7777 }
7878
79- if (code == MyKeyboard .KEYCODE_SHIFT || code == MyKeyboard .KEYCODE_DELETE ) {
80- return
81- }
82-
83- val text = currentInputConnection.getTextBeforeCursor(2 , 0 ) ? : return
84- // capitalize first letter on startup or if text is empty
85- if (code == null || text.isEmpty()) {
86- keyboard!! .setShifted(ShiftState .ON_ONE_CHAR )
87- keyboardView?.invalidateAllKeys()
88- return
89- }
90-
91- // capitalize sentences if needed
92- if (config.enableSentencesCapitalization) {
93-
94- // capitalize on Enter click
95- if (code == MyKeyboard .KEYCODE_ENTER ) {
96- keyboard!! .setShifted(ShiftState .ON_ONE_CHAR )
79+ val editorInfo = currentInputEditorInfo
80+ if (config.enableSentencesCapitalization && editorInfo != null && editorInfo.inputType != InputType .TYPE_NULL ) {
81+ if (currentInputConnection.getCursorCapsMode(editorInfo.inputType) != 0 ) {
82+ keyboard?.setShifted(ShiftState .ON_ONE_CHAR )
9783 keyboardView?.invalidateAllKeys()
9884 return
9985 }
100-
101-
102- if (ShiftState .shouldCapitalize(this , text.toString())) {
103- keyboard!! .setShifted(ShiftState .ON_ONE_CHAR )
104- keyboardView?.invalidateAllKeys()
105- return
106- } else {
107- // try capitalizing based on the editor info like google keep or google messenger apps
108- val editorInfo = currentInputEditorInfo
109-
110- if (editorInfo != null && editorInfo.inputType != InputType .TYPE_NULL ) {
111- if (currentInputConnection.getCursorCapsMode(editorInfo.inputType) != 0 ) {
112- keyboard?.setShifted(ShiftState .ON_ONE_CHAR )
113- keyboardView?.invalidateAllKeys()
114- return
115- }
116- }
117- }
11886 }
11987
120- // In other cases reset shift to OFF
88+ // in other cases reset shift to OFF
12189 keyboard?.setShifted(ShiftState .OFF )
12290 keyboardView?.invalidateAllKeys()
12391 }
@@ -128,8 +96,6 @@ class SimpleKeyboardIME : InputMethodService(), MyKeyboardView.OnKeyboardActionL
12896 return
12997 }
13098
131- // this.keyboardView.setEditorInfo(EditorInfo)
132-
13399 if (code != MyKeyboard .KEYCODE_SHIFT ) {
134100 lastShiftPressTS = 0
135101 }
@@ -139,18 +105,10 @@ class SimpleKeyboardIME : InputMethodService(), MyKeyboardView.OnKeyboardActionL
139105
140106 val selectedText = inputConnection.getSelectedText(0 )
141107 if (TextUtils .isEmpty(selectedText)) {
142- val text = inputConnection.getTextBeforeCursor(3 , 0 )?.dropLast(1 )
143-
144- if (keyboard?.mShiftState != ShiftState .ON_PERMANENT ) {
145- keyboard?.setShifted(ShiftState .getShiftStateForText(this , inputTypeClassVariation, text?.toString()))
146- keyboardView?.invalidateAllKeys()
147- }
148-
149108 inputConnection.sendKeyEvent(KeyEvent (KeyEvent .ACTION_DOWN , KeyEvent .KEYCODE_DEL ))
150109 inputConnection.sendKeyEvent(KeyEvent (KeyEvent .ACTION_UP , KeyEvent .KEYCODE_DEL ))
151110 } else {
152111
153-
154112 inputConnection.commitText(" " , 1 )
155113 }
156114 }
@@ -216,7 +174,7 @@ class SimpleKeyboardIME : InputMethodService(), MyKeyboardView.OnKeyboardActionL
216174 // If the keyboard is set to symbols and the user presses space, we usually should switch back to the letters keyboard.
217175 // However, avoid doing that in cases when the EditText for example requires numbers as the input.
218176 // We can detect that by the text not changing on pressing Space.
219- if (keyboardMode != KEYBOARD_LETTERS && code == MyKeyboard .KEYCODE_SPACE ) {
177+ if (keyboardMode != KEYBOARD_LETTERS && inputTypeClass == InputType . TYPE_CLASS_TEXT && code == MyKeyboard .KEYCODE_SPACE ) {
220178 inputConnection.commitText(codeChar.toString(), 1 )
221179 val newText = inputConnection.getExtractedText(ExtractedTextRequest (), 0 )?.text
222180 if (originalText != newText) {
@@ -227,6 +185,7 @@ class SimpleKeyboardIME : InputMethodService(), MyKeyboardView.OnKeyboardActionL
227185 }
228186 }
229187 }
188+
230189 if (keyboard!! .mShiftState != ShiftState .ON_PERMANENT ) {
231190 updateShiftKeyState(code)
232191 }
@@ -237,11 +196,7 @@ class SimpleKeyboardIME : InputMethodService(), MyKeyboardView.OnKeyboardActionL
237196 // TODO: Change keyboardMode to enum class
238197 keyboardMode = KEYBOARD_LETTERS
239198
240- // Check if capitalization is needed after switching to letters layout
241- val text = currentInputConnection?.getTextBeforeCursor(2 , 0 )
242- val newShiftState = ShiftState .getShiftStateForText(this , inputTypeClassVariation, text?.toString())
243-
244- keyboard = MyKeyboard (this , getKeyboardLayoutXML(), enterKeyType, shiftState = newShiftState)
199+ keyboard = MyKeyboard (this , getKeyboardLayoutXML(), enterKeyType)
245200
246201 val editorInfo = currentInputEditorInfo
247202 if (editorInfo != null && editorInfo.inputType != InputType .TYPE_NULL && keyboard?.mShiftState != ShiftState .ON_PERMANENT ) {
@@ -296,7 +251,9 @@ class SimpleKeyboardIME : InputMethodService(), MyKeyboardView.OnKeyboardActionL
296251 }
297252 }
298253 return MyKeyboard (
299- context = this , xmlLayoutResId = keyboardXml, enterKeyType = enterKeyType, shiftState = ShiftState .getDefaultShiftState(this , inputTypeClassVariation)
254+ context = this ,
255+ xmlLayoutResId = keyboardXml,
256+ enterKeyType = enterKeyType,
300257 )
301258 }
302259
0 commit comments