mirror of
				https://github.com/SimpleMobileTools/Simple-Keyboard.git
				synced 2025-06-05 21:49:26 +02:00 
			
		
		
		
	switch to letters keyboard if Space is pressed with symbols keyboard
This commit is contained in:
		| @@ -7,6 +7,7 @@ import android.view.KeyEvent | ||||
| import android.view.View | ||||
| import android.view.inputmethod.EditorInfo | ||||
| import android.view.inputmethod.EditorInfo.IME_ACTION_NONE | ||||
| import android.view.inputmethod.ExtractedTextRequest | ||||
| import com.simplemobiletools.commons.extensions.performHapticFeedback | ||||
| import com.simplemobiletools.keyboard.R | ||||
| import com.simplemobiletools.keyboard.helpers.MyKeyboard | ||||
| @@ -28,6 +29,7 @@ class SimpleKeyboardIME : InputMethodService(), MyKeyboardView.OnKeyboardActionL | ||||
|     private var keyboardMode = KEYBOARD_LETTERS | ||||
|     private var inputTypeClass = InputType.TYPE_CLASS_TEXT | ||||
|     private var enterKeyType = IME_ACTION_NONE | ||||
|     private var switchToLetters = false | ||||
|  | ||||
|     override fun onInitializeInterface() { | ||||
|         super.onInitializeInterface() | ||||
| @@ -144,11 +146,16 @@ class SimpleKeyboardIME : InputMethodService(), MyKeyboardView.OnKeyboardActionL | ||||
|                     code = Character.toUpperCase(code) | ||||
|                 } | ||||
|  | ||||
|                 // If the keyboard is set to symbols and the user presses space, we usually should switch back to the letters keyboard. | ||||
|                 // However, avoid doing that in cases when the EditText for example requires numbers as the input. | ||||
|                 // We can detect that by the text not changing on pressing Space. | ||||
|                 if (keyboardMode != KEYBOARD_LETTERS && primaryCode == MyKeyboard.KEYCODE_SPACE) { | ||||
|                     val originalText = inputConnection.getExtractedText(ExtractedTextRequest(), 0).text | ||||
|                     inputConnection.commitText(code.toString(), 1) | ||||
|                     val newText = inputConnection.getExtractedText(ExtractedTextRequest(), 0).text | ||||
|                     switchToLetters = originalText != newText | ||||
|                 } else { | ||||
|                     inputConnection.commitText(code.toString(), 1) | ||||
|                 if (primaryCode == MyKeyboard.KEYCODE_SPACE && keyboardMode != KEYBOARD_LETTERS) { | ||||
|                     keyboardMode = KEYBOARD_LETTERS | ||||
|                     keyboard = MyKeyboard(this, R.xml.keys_letters, enterKeyType) | ||||
|                     keyboardView!!.setKeyboard(keyboard!!) | ||||
|                 } | ||||
|  | ||||
|                 if (keyboard!!.shiftState == SHIFT_ON_ONE_CHAR && keyboardMode == KEYBOARD_LETTERS) { | ||||
| @@ -163,6 +170,23 @@ class SimpleKeyboardIME : InputMethodService(), MyKeyboardView.OnKeyboardActionL | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     override fun onActionUp() { | ||||
|         if (switchToLetters) { | ||||
|             keyboardMode = KEYBOARD_LETTERS | ||||
|             keyboard = MyKeyboard(this, R.xml.keys_letters, enterKeyType) | ||||
|  | ||||
|             val editorInfo = currentInputEditorInfo | ||||
|             if (editorInfo != null && editorInfo.inputType != InputType.TYPE_NULL && keyboard?.shiftState != SHIFT_ON_PERMANENT) { | ||||
|                 if (currentInputConnection.getCursorCapsMode(editorInfo.inputType) != 0) { | ||||
|                     keyboard?.setShifted(SHIFT_ON_ONE_CHAR) | ||||
|                 } | ||||
|             } | ||||
|  | ||||
|             keyboardView!!.setKeyboard(keyboard!!) | ||||
|             switchToLetters = false | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     override fun onText(text: CharSequence?) {} | ||||
|  | ||||
|     override fun swipeLeft() {} | ||||
|   | ||||
| @@ -98,6 +98,11 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut | ||||
|          * Called when the user quickly moves the finger from down to up. | ||||
|          */ | ||||
|         fun swipeUp() | ||||
|  | ||||
|         /** | ||||
|          * Called when the finger has been lifted after pressing a key | ||||
|          */ | ||||
|         fun onActionUp() | ||||
|     } | ||||
|  | ||||
|     private var mKeyboard: MyKeyboard? = null | ||||
| @@ -1060,6 +1065,10 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut | ||||
|                     override fun onRelease(primaryCode: Int) { | ||||
|                         onKeyboardActionListener!!.onRelease(primaryCode) | ||||
|                     } | ||||
|  | ||||
|                     override fun onActionUp() { | ||||
|                         onKeyboardActionListener!!.onActionUp() | ||||
|                     } | ||||
|                 } | ||||
|  | ||||
|                 //mInputView.setSuggest(mSuggest); | ||||
| @@ -1369,6 +1378,7 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut | ||||
|                 } | ||||
|                 invalidateKey(keyIndex) | ||||
|                 mRepeatKeyIndex = NOT_A_KEY | ||||
|                 onKeyboardActionListener!!.onActionUp() | ||||
|             } | ||||
|             MotionEvent.ACTION_CANCEL -> { | ||||
|                 removeMessages() | ||||
|   | ||||
		Reference in New Issue
	
	Block a user