@@ -123,8 +123,8 @@ abstract class GeneralKeyboardIME(
123123 private val shiftPermToggleSpeed: Int = DEFAULT_SHIFT_PERM_TOGGLE_SPEED
124124
125125 private lateinit var dbManagers: DatabaseManagers
126- private lateinit var suggestionHandler: SuggestionHandler
127- private lateinit var autocompletionHandler: AutocompletionHandler
126+ internal lateinit var suggestionHandler: SuggestionHandler
127+ internal lateinit var autocompletionHandler: AutocompletionHandler
128128 private lateinit var autocompletionManager: AutocompletionDataManager
129129 private var dataContract: DataContract ? = null
130130
@@ -146,6 +146,7 @@ abstract class GeneralKeyboardIME(
146146 var wordSuggestions: List <String >? = null
147147 var checkIfPluralWord: Boolean = false
148148 private var currentEnterKeyType: Int? = null
149+ private var isNumericKeyboardActive: Boolean = false
149150
150151 internal var currentState: ScribeState = ScribeState .IDLE
151152 internal var invalidCommandSource: ScribeState = ScribeState .IDLE
@@ -178,6 +179,22 @@ abstract class GeneralKeyboardIME(
178179 internal const val MAX_TEXT_LENGTH = 1000
179180 const val COMMIT_TEXT_CURSOR_POSITION = 1
180181 internal const val CUSTOM_CURSOR = " │" // special tall cursor character
182+
183+ internal fun shouldUseNumericKeyboard (inputType : Int ): Boolean =
184+ when (inputType and TYPE_MASK_CLASS ) {
185+ TYPE_CLASS_NUMBER , TYPE_CLASS_DATETIME , TYPE_CLASS_PHONE -> true
186+ else -> false
187+ }
188+
189+ internal fun getKeyboardLayoutXMLForInputType (
190+ inputType : Int ,
191+ letterKeyboardLayoutXML : Int ,
192+ ): Int =
193+ if (shouldUseNumericKeyboard(inputType)) {
194+ R .xml.keys_numeric
195+ } else {
196+ letterKeyboardLayoutXML
197+ }
181198 }
182199
183200 // MARK: Lifecycle Methods
@@ -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