Skip to content

Commit a7f1947

Browse files
committed
Added email input types as an exception to capitalization
Fixed comments in code
1 parent aef91d8 commit a7f1947

File tree

2 files changed

+21
-12
lines changed

2 files changed

+21
-12
lines changed

app/src/main/kotlin/com/simplemobiletools/keyboard/helpers/Constants.kt

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ enum class ShiftState {
1111
ON_PERMANENT;
1212

1313
companion object {
14-
private val MIN_TEXT_LENGTH = 2
14+
private const val MIN_TEXT_LENGTH = 2
1515
private val endOfSentenceChars: List<Char> = listOf('.', '?', '!')
1616

1717
fun getDefaultShiftState(context: Context, inputTypeClassVariation: Int): ShiftState {
18-
if (isInputTypePassword(inputTypeClassVariation)) {
18+
if (isInputTypePasswordOrEmail(inputTypeClassVariation)) {
1919
return OFF
2020
}
2121
return when (context.config.enableSentencesCapitalization) {
@@ -25,7 +25,7 @@ enum class ShiftState {
2525
}
2626

2727
fun getShiftStateForText(context: Context, inputTypeClassVariation: Int, text: String?): ShiftState {
28-
if (isInputTypePassword(inputTypeClassVariation)) {
28+
if (isInputTypePasswordOrEmail(inputTypeClassVariation)) {
2929
return OFF
3030
}
3131
return when {
@@ -38,8 +38,13 @@ enum class ShiftState {
3838
}
3939
}
4040

41+
/**
42+
* The function is checking whether there is a need in capitalizing based on the given text
43+
* @param context Used for checking current sentences capitalization setting
44+
* @param text Last text from the input
45+
*/
4146
fun shouldCapitalize(context: Context, text: String?): Boolean {
42-
//To capitalize first letter in textField
47+
// check whether it is the first letter in textField
4348
if (text.isNullOrEmpty()) {
4449
return true
4550
}
@@ -57,11 +62,13 @@ enum class ShiftState {
5762
return endOfSentenceChars.contains(twoLastSymbols.first()) && twoLastSymbols.last().code == KEYCODE_SPACE
5863
}
5964

60-
fun isInputTypePassword(inputTypeVariation: Int): Boolean {
65+
fun isInputTypePasswordOrEmail(inputTypeVariation: Int): Boolean {
6166
return inputTypeVariation == InputType.TYPE_TEXT_VARIATION_PASSWORD
6267
|| inputTypeVariation == InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD
6368
|| inputTypeVariation == InputType.TYPE_TEXT_VARIATION_WEB_PASSWORD
6469
|| inputTypeVariation == InputType.TYPE_NUMBER_VARIATION_PASSWORD
70+
|| inputTypeVariation == InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS
71+
|| inputTypeVariation == InputType.TYPE_TEXT_VARIATION_WEB_EMAIL_ADDRESS
6572
}
6673
}
6774
}

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,22 +76,22 @@ class SimpleKeyboardIME : InputMethodService(), MyKeyboardView.OnKeyboardActionL
7676
return
7777
}
7878

79-
if (keyboardMode != KEYBOARD_LETTERS || ShiftState.isInputTypePassword(inputTypeClassVariation)) {
79+
if (keyboardMode != KEYBOARD_LETTERS || ShiftState.isInputTypePasswordOrEmail(inputTypeClassVariation)) {
8080
return
8181
}
8282

8383
val text = currentInputConnection.getTextBeforeCursor(2, 0) ?: return
84-
//Capitalize first letter on startup or if text is empty
84+
// capitalize first letter on startup or if text is empty
8585
if (code == null || text.isEmpty()) {
8686
keyboard!!.setShifted(ShiftState.ON_ONE_CHAR)
8787
keyboardView?.invalidateAllKeys()
8888
return
8989
}
9090

91-
//Capitalize sentences if needed
91+
// capitalize sentences if needed
9292
if (config.enableSentencesCapitalization) {
9393

94-
//Capitalize on Enter click
94+
// capitalize on Enter click
9595
if (code == MyKeyboard.KEYCODE_ENTER) {
9696
keyboard!!.setShifted(ShiftState.ON_ONE_CHAR)
9797
keyboardView?.invalidateAllKeys()
@@ -104,10 +104,10 @@ class SimpleKeyboardIME : InputMethodService(), MyKeyboardView.OnKeyboardActionL
104104
keyboardView?.invalidateAllKeys()
105105
return
106106
} else {
107-
//Try capitalizing based on the editor info like google keep or google messenger apps
107+
// try capitalizing based on the editor info like google keep or google messenger apps
108108
val editorInfo = currentInputEditorInfo
109109

110-
if (editorInfo != null && editorInfo.inputType != InputType.TYPE_NULL && keyboard?.mShiftState != ShiftState.ON_PERMANENT) {
110+
if (editorInfo != null && editorInfo.inputType != InputType.TYPE_NULL) {
111111
if (currentInputConnection.getCursorCapsMode(editorInfo.inputType) != 0) {
112112
keyboard?.setShifted(ShiftState.ON_ONE_CHAR)
113113
keyboardView?.invalidateAllKeys()
@@ -117,7 +117,7 @@ class SimpleKeyboardIME : InputMethodService(), MyKeyboardView.OnKeyboardActionL
117117
}
118118
}
119119

120-
//Else just reset shift to OFF
120+
// In other cases reset shift to OFF
121121
keyboard?.setShifted(ShiftState.OFF)
122122
keyboardView?.invalidateAllKeys()
123123
}
@@ -128,6 +128,8 @@ class SimpleKeyboardIME : InputMethodService(), MyKeyboardView.OnKeyboardActionL
128128
return
129129
}
130130

131+
// this.keyboardView.setEditorInfo(EditorInfo)
132+
131133
if (code != MyKeyboard.KEYCODE_SHIFT) {
132134
lastShiftPressTS = 0
133135
}

0 commit comments

Comments
 (0)