@@ -121,8 +121,8 @@ abstract class GeneralKeyboardIME(
121121 private val shiftPermToggleSpeed: Int = DEFAULT_SHIFT_PERM_TOGGLE_SPEED
122122
123123 private lateinit var dbManagers: DatabaseManagers
124- private lateinit var suggestionHandler: SuggestionHandler
125- private lateinit var autocompletionHandler: AutocompletionHandler
124+ internal lateinit var suggestionHandler: SuggestionHandler
125+ internal lateinit var autocompletionHandler: AutocompletionHandler
126126 private lateinit var autocompletionManager: AutocompletionDataManager
127127 private var dataContract: DataContract ? = null
128128
@@ -144,6 +144,7 @@ abstract class GeneralKeyboardIME(
144144 var wordSuggestions: List <String >? = null
145145 var checkIfPluralWord: Boolean = false
146146 private var currentEnterKeyType: Int? = null
147+ private var isNumericKeyboardActive: Boolean = false
147148
148149 internal var currentState: ScribeState = ScribeState .IDLE
149150 internal var invalidCommandSource: ScribeState = ScribeState .IDLE
@@ -176,6 +177,22 @@ abstract class GeneralKeyboardIME(
176177 internal const val MAX_TEXT_LENGTH = 1000
177178 const val COMMIT_TEXT_CURSOR_POSITION = 1
178179 internal const val CUSTOM_CURSOR = " │" // special tall cursor character
180+
181+ internal fun shouldUseNumericKeyboard (inputType : Int ): Boolean =
182+ when (inputType and TYPE_MASK_CLASS ) {
183+ TYPE_CLASS_NUMBER , TYPE_CLASS_DATETIME , TYPE_CLASS_PHONE -> true
184+ else -> false
185+ }
186+
187+ internal fun getKeyboardLayoutXMLForInputType (
188+ inputType : Int ,
189+ letterKeyboardLayoutXML : Int ,
190+ ): Int =
191+ if (shouldUseNumericKeyboard(inputType)) {
192+ R .xml.keys_numeric
193+ } else {
194+ letterKeyboardLayoutXML
195+ }
179196 }
180197
181198 enum class ScribeState { IDLE , SELECT_COMMAND , TRANSLATE , CONJUGATE , PLURAL , SELECT_VERB_CONJUNCTION , INVALID , ALREADY_PLURAL }
@@ -286,25 +303,16 @@ abstract class GeneralKeyboardIME(
286303 // This setter triggers the logic in the property override if not shadowed.
287304 hasTextBeforeCursor = currentInputConnection?.getTextBeforeCursor(1 , 0 )?.isNotEmpty() == true
288305
289- val keyboardXml =
290- when (inputTypeClass) {
291- TYPE_CLASS_NUMBER , TYPE_CLASS_DATETIME , TYPE_CLASS_PHONE -> {
292- keyboardMode = keyboardSymbols
293- R .xml.keys_symbols
294- }
295-
296- else -> {
297- keyboardMode = keyboardLetters
298- getKeyboardLayoutXML()
299- }
300- }
306+ isNumericKeyboardActive = shouldUseNumericKeyboard(attribute.inputType)
307+ keyboardMode = if (isNumericKeyboardActive) keyboardSymbols else keyboardLetters
308+ val keyboardXml = getKeyboardLayoutXMLForInputType(attribute.inputType, getKeyboardLayoutXML())
301309
302310 loadLanguageData()
303311
304312 keyboard = KeyboardBase (this , keyboardXml, enterKeyType)
305313 keyboardView?.setKeyboard(keyboard!! )
306314
307- if (keyboardXml == R .xml.keys_symbols) {
315+ if (this ::uiManager.isInitialized && keyboardXml == R .xml.keys_symbols) {
308316 uiManager.setupCurrencySymbol(language)
309317 }
310318 }
@@ -334,7 +342,7 @@ abstract class GeneralKeyboardIME(
334342 banner.visibility =
335343 if (hasData) View .GONE else View .VISIBLE
336344 binding.commandOptionsBar.visibility =
337- if (hasData) View .VISIBLE else View .GONE
345+ if (hasData && ! isNumericKeyboardActive ) View .VISIBLE else View .GONE
338346 val isDarkMode = getIsDarkModeOrNot(applicationContext)
339347 val bannerColor = if (isDarkMode) R .color.dark_tutorial_button_color else R .color.light_tutorial_button_color
340348 val bannerTextColor = if (isDarkMode) R .color.dark_button_outline_color else R .color.light_text_color
@@ -727,6 +735,22 @@ abstract class GeneralKeyboardIME(
727735
728736 override fun getCurrentEnterKeyType (): Int = enterKeyType
729737
738+ override fun isNumericKeyboardActive (): Boolean = isNumericKeyboardActive
739+
740+ override fun getCurrentKeyboardLayoutXML (): Int =
741+ when (keyboardMode) {
742+ keyboardSymbols -> getPrimarySymbolKeyboardLayoutXML()
743+ keyboardSymbolShift -> R .xml.keys_symbols_shift
744+ else -> getKeyboardLayoutXML()
745+ }
746+
747+ private fun getPrimarySymbolKeyboardLayoutXML (): Int =
748+ if (isNumericKeyboardActive) {
749+ R .xml.keys_numeric
750+ } else {
751+ R .xml.keys_symbols
752+ }
753+
730754 override fun onKeyboardActionListener (): KeyboardView .OnKeyboardActionListener = this
731755
732756 override fun processLinguisticSuggestions (word : String ) {
@@ -1171,7 +1195,7 @@ abstract class GeneralKeyboardIME(
11711195 R .xml.keys_symbols_shift
11721196 } else {
11731197 this .keyboardMode = keyboardSymbols
1174- R .xml.keys_symbols
1198+ getPrimarySymbolKeyboardLayoutXML()
11751199 }
11761200 keyboard = KeyboardBase (this , keyboardXml, enterKeyType)
11771201 keyboardView!! .setKeyboard(keyboard!! )
@@ -1196,7 +1220,7 @@ abstract class GeneralKeyboardIME(
11961220 val keyboardXml =
11971221 if (keyboardMode == keyboardLetters) {
11981222 this .keyboardMode = keyboardSymbols
1199- R .xml.keys_symbols
1223+ getPrimarySymbolKeyboardLayoutXML()
12001224 } else {
12011225 this .keyboardMode = keyboardLetters
12021226 getKeyboardLayoutXML()
0 commit comments