Added email input types as an exception to capitalization

Fixed comments in code
This commit is contained in:
merkost 2023-05-23 18:52:33 +10:00
parent aef91d8a42
commit a7f194793d
2 changed files with 21 additions and 12 deletions

View File

@ -11,11 +11,11 @@ enum class ShiftState {
ON_PERMANENT;
companion object {
private val MIN_TEXT_LENGTH = 2
private const val MIN_TEXT_LENGTH = 2
private val endOfSentenceChars: List<Char> = listOf('.', '?', '!')
fun getDefaultShiftState(context: Context, inputTypeClassVariation: Int): ShiftState {
if (isInputTypePassword(inputTypeClassVariation)) {
if (isInputTypePasswordOrEmail(inputTypeClassVariation)) {
return OFF
}
return when (context.config.enableSentencesCapitalization) {
@ -25,7 +25,7 @@ enum class ShiftState {
}
fun getShiftStateForText(context: Context, inputTypeClassVariation: Int, text: String?): ShiftState {
if (isInputTypePassword(inputTypeClassVariation)) {
if (isInputTypePasswordOrEmail(inputTypeClassVariation)) {
return OFF
}
return when {
@ -38,8 +38,13 @@ enum class ShiftState {
}
}
/**
* The function is checking whether there is a need in capitalizing based on the given text
* @param context Used for checking current sentences capitalization setting
* @param text Last text from the input
*/
fun shouldCapitalize(context: Context, text: String?): Boolean {
//To capitalize first letter in textField
// check whether it is the first letter in textField
if (text.isNullOrEmpty()) {
return true
}
@ -57,11 +62,13 @@ enum class ShiftState {
return endOfSentenceChars.contains(twoLastSymbols.first()) && twoLastSymbols.last().code == KEYCODE_SPACE
}
fun isInputTypePassword(inputTypeVariation: Int): Boolean {
fun isInputTypePasswordOrEmail(inputTypeVariation: Int): Boolean {
return inputTypeVariation == InputType.TYPE_TEXT_VARIATION_PASSWORD
|| inputTypeVariation == InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD
|| inputTypeVariation == InputType.TYPE_TEXT_VARIATION_WEB_PASSWORD
|| inputTypeVariation == InputType.TYPE_NUMBER_VARIATION_PASSWORD
|| inputTypeVariation == InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS
|| inputTypeVariation == InputType.TYPE_TEXT_VARIATION_WEB_EMAIL_ADDRESS
}
}
}

View File

@ -76,22 +76,22 @@ class SimpleKeyboardIME : InputMethodService(), MyKeyboardView.OnKeyboardActionL
return
}
if (keyboardMode != KEYBOARD_LETTERS || ShiftState.isInputTypePassword(inputTypeClassVariation)) {
if (keyboardMode != KEYBOARD_LETTERS || ShiftState.isInputTypePasswordOrEmail(inputTypeClassVariation)) {
return
}
val text = currentInputConnection.getTextBeforeCursor(2, 0) ?: return
//Capitalize first letter on startup or if text is empty
// capitalize first letter on startup or if text is empty
if (code == null || text.isEmpty()) {
keyboard!!.setShifted(ShiftState.ON_ONE_CHAR)
keyboardView?.invalidateAllKeys()
return
}
//Capitalize sentences if needed
// capitalize sentences if needed
if (config.enableSentencesCapitalization) {
//Capitalize on Enter click
// capitalize on Enter click
if (code == MyKeyboard.KEYCODE_ENTER) {
keyboard!!.setShifted(ShiftState.ON_ONE_CHAR)
keyboardView?.invalidateAllKeys()
@ -104,10 +104,10 @@ class SimpleKeyboardIME : InputMethodService(), MyKeyboardView.OnKeyboardActionL
keyboardView?.invalidateAllKeys()
return
} else {
//Try capitalizing based on the editor info like google keep or google messenger apps
// try capitalizing based on the editor info like google keep or google messenger apps
val editorInfo = currentInputEditorInfo
if (editorInfo != null && editorInfo.inputType != InputType.TYPE_NULL && keyboard?.mShiftState != ShiftState.ON_PERMANENT) {
if (editorInfo != null && editorInfo.inputType != InputType.TYPE_NULL) {
if (currentInputConnection.getCursorCapsMode(editorInfo.inputType) != 0) {
keyboard?.setShifted(ShiftState.ON_ONE_CHAR)
keyboardView?.invalidateAllKeys()
@ -117,7 +117,7 @@ class SimpleKeyboardIME : InputMethodService(), MyKeyboardView.OnKeyboardActionL
}
}
//Else just reset shift to OFF
// In other cases reset shift to OFF
keyboard?.setShifted(ShiftState.OFF)
keyboardView?.invalidateAllKeys()
}
@ -128,6 +128,8 @@ class SimpleKeyboardIME : InputMethodService(), MyKeyboardView.OnKeyboardActionL
return
}
// this.keyboardView.setEditorInfo(EditorInfo)
if (code != MyKeyboard.KEYCODE_SHIFT) {
lastShiftPressTS = 0
}