@@ -40,6 +40,7 @@ import be.scri.helpers.PERIOD_ON_DOUBLE_TAP
40
40
import be.scri.helpers.PreferencesHelper
41
41
import be.scri.helpers.PreferencesHelper.getIsDarkModeOrNot
42
42
import be.scri.helpers.PreferencesHelper.getIsEmojiSuggestionsEnabled
43
+ import be.scri.helpers.PreferencesHelper.getPreferredTranslationLanguage
43
44
import be.scri.helpers.SHIFT_OFF
44
45
import be.scri.helpers.SHIFT_ON_ONE_CHAR
45
46
import be.scri.helpers.SHIFT_ON_PERMANENT
@@ -460,7 +461,7 @@ abstract class GeneralKeyboardIME(
460
461
private fun updateCommandBarHintAndPrompt (isUserDarkMode : Boolean? = null) {
461
462
val commandBarButton = keyboardBinding.commandBar
462
463
val hintMessage = HintUtils .getCommandBarHint(currentState, language)
463
- val promptText = HintUtils .getPromptText(currentState, language)
464
+ val promptText = HintUtils .getPromptText(currentState, language, context = this )
464
465
val promptTextView = keyboardBinding.promptText
465
466
promptTextView.text = promptText
466
467
commandBarButton.hint = hintMessage
@@ -519,6 +520,8 @@ abstract class GeneralKeyboardIME(
519
520
setupIdleView()
520
521
handleTextSizeForSuggestion(binding)
521
522
initializeEmojiButtons()
523
+ keyboard = KeyboardBase (this , getKeyboardLayoutXML(), enterKeyType)
524
+ keyboardView!! .setKeyboard(keyboard!! )
522
525
updateButtonVisibility(emojiAutoSuggestionEnabled)
523
526
updateButtonText(emojiAutoSuggestionEnabled, autoSuggestEmojis)
524
527
}
@@ -537,37 +540,64 @@ abstract class GeneralKeyboardIME(
537
540
* to have toolbar interface, allowing the user to interact with the toolbar.
538
541
*/
539
542
private fun switchToToolBar () {
540
- this . keyboardBinding = initializeKeyboardBinding()
543
+ keyboardBinding = initializeKeyboardBinding()
541
544
val keyboardHolder = keyboardBinding.root
545
+
542
546
setupToolBarTheme(keyboardBinding)
543
547
handleTextSizeForSuggestion(binding)
544
- var isUserDarkMode = getIsDarkModeOrNot(applicationContext)
545
548
binding.translateBtn.textSize = SUGGESTION_SIZE
546
- when (isUserDarkMode) {
547
- true -> {
548
- keyboardBinding.topKeyboardDivider.setBackgroundColor(getColor(R .color.special_key_dark))
549
- val color = ContextCompat .getColorStateList(this , R .color.light_key_color)
550
- keyboardBinding.scribeKey.foregroundTintList = color
549
+
550
+ val isDarkMode = getIsDarkModeOrNot(applicationContext)
551
+ updateToolBarTheme(isDarkMode)
552
+
553
+ handleModeChange(keyboardSymbols, keyboardView, this )
554
+
555
+ val keyboardXmlId =
556
+ if (currentState == ScribeState .TRANSLATE ) {
557
+ val language = getPreferredTranslationLanguage(this , language)
558
+ baseKeyboardOfAnyLanguage(language)
559
+ } else {
560
+ getKeyboardLayoutXML()
551
561
}
552
562
553
- false -> {
554
- keyboardBinding.topKeyboardDivider.setBackgroundColor(getColor(R .color.special_key_light))
555
- val colorLight = ContextCompat .getColorStateList(this , R .color.light_key_text_color)
556
- keyboardBinding.scribeKey.foregroundTintList = colorLight
563
+ keyboard = KeyboardBase (this , keyboardXmlId, enterKeyType)
564
+ keyboardView =
565
+ keyboardBinding.keyboardView.apply {
566
+ setKeyboard(keyboard!! )
567
+ mOnKeyboardActionListener = this @GeneralKeyboardIME
557
568
}
558
- }
559
- handleModeChange(keyboardSymbols, keyboardView, this )
560
- keyboardView = keyboardBinding.keyboardView
561
- keyboardView!! .setKeyboard(keyboard!! )
562
- keyboardView!! .mOnKeyboardActionListener = this
569
+
563
570
keyboardBinding.scribeKey.setOnClickListener {
564
571
currentState = ScribeState .IDLE
565
572
switchToCommandToolBar()
566
573
handleTextSizeForSuggestion(binding)
567
574
updateUI()
568
575
}
576
+
569
577
setInputView(keyboardHolder)
570
- updateCommandBarHintAndPrompt(isUserDarkMode)
578
+ updateCommandBarHintAndPrompt(isDarkMode)
579
+ }
580
+
581
+ /* *
582
+ * Updates the toolbar theme based on the current system theme (dark or light).
583
+ *
584
+ * This function adjusts the toolbar's visual elements such as the top divider color
585
+ * and the tint of the custom scribe key, depending on whether dark mode is enabled.
586
+ *
587
+ * @param isDarkMode A boolean indicating if the system is in dark mode.
588
+ */
589
+ private fun updateToolBarTheme (isDarkMode : Boolean ) {
590
+ val dividerColor = if (isDarkMode) R .color.special_key_dark else R .color.special_key_light
591
+ keyboardBinding.topKeyboardDivider.setBackgroundColor(getColor(dividerColor))
592
+
593
+ val tintColor =
594
+ if (isDarkMode) {
595
+ ContextCompat .getColorStateList(this , R .color.light_key_color)
596
+ } else {
597
+ ContextCompat .getColorStateList(this , R .color.light_key_text_color)
598
+ }
599
+
600
+ keyboardBinding.scribeKey.foregroundTintList = tintColor
571
601
}
572
602
573
603
/* *
@@ -1642,6 +1672,32 @@ abstract class GeneralKeyboardIME(
1642
1672
}
1643
1673
}
1644
1674
1675
+ /* *
1676
+ * Returns the XML layout resource ID for the base keyboard of the specified language.
1677
+ *
1678
+ * This function maps a given language name to its corresponding keyboard layout XML file.
1679
+ * If the provided language is `null` or doesn't match any of the predefined options,
1680
+ * the function defaults to returning the English keyboard layout.
1681
+ *
1682
+ * @param language The name of the language for which the base keyboard layout is requested.
1683
+ * Expected values are: "English", "French", "German", "Italian",
1684
+ * "Portuguese", "Russian", "Spanish", and "Swedish".
1685
+ *
1686
+ * @return The resource ID of the XML layout file for the corresponding keyboard.
1687
+ */
1688
+ private fun baseKeyboardOfAnyLanguage (language : String? ): Int =
1689
+ when (language) {
1690
+ " English" -> R .xml.keys_letters_english
1691
+ " French" -> R .xml.keys_letters_french
1692
+ " German" -> R .xml.keys_letters_german
1693
+ " Italian" -> R .xml.keys_letters_italian
1694
+ " Portuguese" -> R .xml.keys_letters_portuguese
1695
+ " Russian" -> R .xml.keys_letters_russian
1696
+ " Spanish" -> R .xml.keys_letters_spanish
1697
+ " Swedish" -> R .xml.keys_letters_swedish
1698
+ else -> R .xml.keys_letters_english
1699
+ }
1700
+
1645
1701
internal companion object {
1646
1702
const val DEFAULT_SHIFT_PERM_TOGGLE_SPEED = 500
1647
1703
const val TEXT_LENGTH = 20
0 commit comments