From a42c717bf4dc27ff89a0207f1f87334731d4123e Mon Sep 17 00:00:00 2001 From: Bhanu Nagpure <130910873+bhanu-dev82@users.noreply.github.com> Date: Thu, 26 Nov 2026 12:18:19 +0530 Subject: [PATCH 01/15] Point keyboard hex colors at the shared Scribe colors (#783) --- CHANGELOG.md | 1 + .../be/scri/helpers/ui/KeyboardUIManager.kt | 30 +++++++++------ .../be/scri/services/GeneralKeyboardIME.kt | 2 - app/src/main/java/be/scri/ui/theme/Colors.kt | 10 +---- .../be/scri/ui/theme/ScribeColorResolver.kt | 30 +++++++++++++++ .../scri/ui/theme/ScribeColorResolverTest.kt | 38 +++++++++++++++++++ 6 files changed, 88 insertions(+), 23 deletions(-) create mode 100644 app/src/main/java/be/scri/ui/theme/ScribeColorResolver.kt create mode 100644 app/src/test/kotlin/be/scri/ui/theme/ScribeColorResolverTest.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index 1a0fc758..c9de3e98 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ Emojis for the following are chosen based on [gitmoji](https://gitmoji.dev/). ### 🎨 Design - Compose theme colors now come from the shared `scribe_*` resources. Dark mode button text stays orange on orange. The dark caption uses the named token `#CAC4D0`, the same grey this slot already used ([#782](https://github.com/scribe-org/Scribe-Android/issues/782)). +- The keyboard's conjugation labels and dark command info bar read the shared `scribe_*` colors instead of hex literals. No color changes ([#783](https://github.com/scribe-org/Scribe-Android/issues/783)). ### 🔒 Security diff --git a/app/src/keyboards/java/be/scri/helpers/ui/KeyboardUIManager.kt b/app/src/keyboards/java/be/scri/helpers/ui/KeyboardUIManager.kt index 8d615557..e82036a0 100644 --- a/app/src/keyboards/java/be/scri/helpers/ui/KeyboardUIManager.kt +++ b/app/src/keyboards/java/be/scri/helpers/ui/KeyboardUIManager.kt @@ -52,11 +52,14 @@ import be.scri.helpers.parseRawEmojiSpecsFile import be.scri.models.ScribeLanguage import be.scri.models.ScribeState import be.scri.services.GeneralKeyboardIME +import be.scri.ui.theme.scribeColorInt import be.scri.views.KeyboardView private const val SUB_SELECTION_LABEL_TEXT_SIZE_RATIO = 0.8f -private const val CONJUGATION_LABEL_COLOR_LIGHT = "#E558564B" -private const val CONJUGATION_LABEL_COLOR_DARK = "#CAC4D0" + +// Light background of the invalid and already-plural command bars. It is one step off +// scribe_keyboard_background (#D3D6DD), so it stays as is until we decide which one wins. +private const val LIGHT_COMMAND_INFO_BAR_COLOR = "#D2D4DA" private const val MAX_FORM_COUNT_2X1 = 2 private const val FORM_COUNT_3X1 = 3 private const val MAX_FORM_COUNT_2X2 = 4 @@ -370,10 +373,6 @@ class KeyboardUIManager( binding.pluralBtn.foreground = null } - val separatorColor = (if (isUserDarkMode) GeneralKeyboardIME.DARK_THEME else GeneralKeyboardIME.LIGHT_THEME).toColorInt() - binding.separator2.setBackgroundColor(separatorColor) - binding.separator3.setBackgroundColor(separatorColor) - val spaceInDp = 4 val spaceInPx = (spaceInDp * context.resources.displayMetrics.density).toInt() listOf(binding.separator2, binding.separator3).forEach { separator -> @@ -530,8 +529,7 @@ class KeyboardUIManager( label.length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE, ) - val labelColor = - (if (isDarkMode) CONJUGATION_LABEL_COLOR_DARK else CONJUGATION_LABEL_COLOR_LIGHT).toColorInt() + val labelColor = context.scribeColorInt(R.color.scribe_caption, isDarkMode) spannable.setSpan( ForegroundColorSpan(labelColor), 0, @@ -748,9 +746,7 @@ class KeyboardUIManager( val isDarkMode = getIsDarkModeOrNot(context) // Restore original logic: Set background on toolbarBar, not invalidInfoBar. - binding.toolbarBar.setBackgroundColor( - if (isDarkMode) "#1E1E1E".toColorInt() else "#d2d4da".toColorInt(), - ) + binding.toolbarBar.setBackgroundColor(commandInfoBarColor(isDarkMode)) val isWikidata = invalidCommandSource != ScribeState.TRANSLATE val invalidMsg = @@ -772,6 +768,16 @@ class KeyboardUIManager( binding.scribeKeyToolbar.foreground = AppCompatResources.getDrawable(context, R.drawable.ic_scribe_icon_vector) } + /** + * Background of the command bar while it shows the invalid or already-plural message. + */ + private fun commandInfoBarColor(isDarkMode: Boolean): Int = + if (isDarkMode) { + context.scribeColorInt(R.color.scribe_keyboard_background, dark = true) + } else { + LIGHT_COMMAND_INFO_BAR_COLOR.toColorInt() + } + /** * Configures the UI for the `ALREADY_PLURAL` state, which is shown when the user * attempts to pluralize a word that is already plural. @@ -781,7 +787,7 @@ class KeyboardUIManager( binding.commandOptionsBar.visibility = View.GONE binding.toolbarBar.visibility = View.VISIBLE val isDarkMode = getIsDarkModeOrNot(context) - binding.toolbarBar.setBackgroundColor(if (isDarkMode) "#1E1E1E".toColorInt() else "#d2d4da".toColorInt()) + binding.toolbarBar.setBackgroundColor(commandInfoBarColor(isDarkMode)) binding.ivInfo.visibility = View.VISIBLE binding.promptText.text = "$ALREADY_PLURAL_MSG: " binding.commandBar.hint = "" diff --git a/app/src/keyboards/java/be/scri/services/GeneralKeyboardIME.kt b/app/src/keyboards/java/be/scri/services/GeneralKeyboardIME.kt index f849cc7c..ced220d7 100644 --- a/app/src/keyboards/java/be/scri/services/GeneralKeyboardIME.kt +++ b/app/src/keyboards/java/be/scri/services/GeneralKeyboardIME.kt @@ -266,8 +266,6 @@ abstract class GeneralKeyboardIME( const val SMALLEST_SCREEN_WIDTH_TABLET = 600 const val TEXT_LENGTH = 20 const val SUGGESTION_SIZE = 15f - const val DARK_THEME = "#aeb3be" - const val LIGHT_THEME = "#4b4b4b" internal const val MAX_TEXT_LENGTH = 1000 const val COMMIT_TEXT_CURSOR_POSITION = 1 internal const val CUSTOM_CURSOR = "│" // special tall cursor character diff --git a/app/src/main/java/be/scri/ui/theme/Colors.kt b/app/src/main/java/be/scri/ui/theme/Colors.kt index 5624a6f0..c7bc4855 100644 --- a/app/src/main/java/be/scri/ui/theme/Colors.kt +++ b/app/src/main/java/be/scri/ui/theme/Colors.kt @@ -3,7 +3,6 @@ package be.scri.ui.theme import android.content.Context -import android.content.res.Configuration import androidx.compose.material3.ColorScheme import androidx.compose.material3.darkColorScheme import androidx.compose.material3.lightColorScheme @@ -16,7 +15,7 @@ import be.scri.R * [dark] follows the app theme argument, not the device night mode. */ fun Context.scribeColorScheme(dark: Boolean): ColorScheme { - val themed = configurationContext(dark) + val themed = scribeNightContext(dark) val button = themed.scribeColor(R.color.scribe_button) val onButton = themed.scribeColor(R.color.scribe_on_button) val background = themed.scribeColor(R.color.scribe_background) @@ -67,11 +66,4 @@ fun Context.scribeColorScheme(dark: Boolean): ColorScheme { } } -private fun Context.configurationContext(dark: Boolean): Context { - val nightMode = if (dark) Configuration.UI_MODE_NIGHT_YES else Configuration.UI_MODE_NIGHT_NO - val config = Configuration(resources.configuration) - config.uiMode = (config.uiMode and Configuration.UI_MODE_NIGHT_MASK.inv()) or nightMode - return createConfigurationContext(config) -} - private fun Context.scribeColor(id: Int): Color = Color(color = ContextCompat.getColor(this, id)) diff --git a/app/src/main/java/be/scri/ui/theme/ScribeColorResolver.kt b/app/src/main/java/be/scri/ui/theme/ScribeColorResolver.kt new file mode 100644 index 00000000..a10644af --- /dev/null +++ b/app/src/main/java/be/scri/ui/theme/ScribeColorResolver.kt @@ -0,0 +1,30 @@ +// SPDX-License-Identifier: GPL-3.0-or-later + +package be.scri.ui.theme + +import android.content.Context +import android.content.res.Configuration +import androidx.annotation.ColorInt +import androidx.annotation.ColorRes +import androidx.core.content.ContextCompat + +/** + * Reads a shared `scribe_*` color for light or dark. + * [dark] follows the Scribe dark mode setting, not the device night mode, + * so the keyboard and the Compose theme pick the same value. + */ +@ColorInt +fun Context.scribeColorInt( + @ColorRes id: Int, + dark: Boolean, +): Int = ContextCompat.getColor(scribeNightContext(dark), id) + +/** + * A context whose resources resolve as day or night according to [dark]. + */ +internal fun Context.scribeNightContext(dark: Boolean): Context { + val nightMode = if (dark) Configuration.UI_MODE_NIGHT_YES else Configuration.UI_MODE_NIGHT_NO + val config = Configuration(resources.configuration) + config.uiMode = (config.uiMode and Configuration.UI_MODE_NIGHT_MASK.inv()) or nightMode + return createConfigurationContext(config) +} diff --git a/app/src/test/kotlin/be/scri/ui/theme/ScribeColorResolverTest.kt b/app/src/test/kotlin/be/scri/ui/theme/ScribeColorResolverTest.kt new file mode 100644 index 00000000..0eb83203 --- /dev/null +++ b/app/src/test/kotlin/be/scri/ui/theme/ScribeColorResolverTest.kt @@ -0,0 +1,38 @@ +// SPDX-License-Identifier: GPL-3.0-or-later + +package be.scri.ui.theme + +import android.content.Context +import androidx.test.core.app.ApplicationProvider +import be.scri.R +import org.junit.Assert.assertEquals +import org.junit.Test +import org.junit.runner.RunWith +import org.robolectric.RobolectricTestRunner +import org.robolectric.annotation.Config + +/** + * The keyboard colors moved off hex literals in #783 must keep the exact values they had. + */ +@RunWith(RobolectricTestRunner::class) +@Config(sdk = [34]) +class ScribeColorResolverTest { + @Test + fun keyboardColorsMatchTheOldHexOnADayDevice() { + assertKeyboardColors(ApplicationProvider.getApplicationContext()) + } + + @Test + @Config(qualifiers = "night") + fun keyboardColorsMatchTheOldHexOnANightDevice() { + assertKeyboardColors(ApplicationProvider.getApplicationContext()) + } + + private fun assertKeyboardColors(context: Context) { + // Conjugation sub-labels, was "#E558564B" / "#CAC4D0". + assertEquals(0xE558564B.toInt(), context.scribeColorInt(R.color.scribe_caption, dark = false)) + assertEquals(0xFFCAC4D0.toInt(), context.scribeColorInt(R.color.scribe_caption, dark = true)) + // Dark invalid and already-plural command bar, was "#1E1E1E". + assertEquals(0xFF1E1E1E.toInt(), context.scribeColorInt(R.color.scribe_keyboard_background, dark = true)) + } +} From 8559f648c42dd7eadf1303500531de88b9cfaf27 Mon Sep 17 00:00:00 2001 From: Bhanu Nagpure <130910873+bhanu-dev82@users.noreply.github.com> Date: Thu, 26 Nov 2026 12:33:01 +0530 Subject: [PATCH 02/15] Test keyboard shared colors at their call sites (#783) --- .../scri/ui/theme/ScribeColorResolverTest.kt | 23 +++ .../helpers/ui/KeyboardSharedColorsTest.kt | 165 ++++++++++++++++++ 2 files changed, 188 insertions(+) create mode 100644 app/src/testKeyboards/kotlin/be/scri/helpers/ui/KeyboardSharedColorsTest.kt diff --git a/app/src/test/kotlin/be/scri/ui/theme/ScribeColorResolverTest.kt b/app/src/test/kotlin/be/scri/ui/theme/ScribeColorResolverTest.kt index 0eb83203..45fc8940 100644 --- a/app/src/test/kotlin/be/scri/ui/theme/ScribeColorResolverTest.kt +++ b/app/src/test/kotlin/be/scri/ui/theme/ScribeColorResolverTest.kt @@ -9,6 +9,7 @@ import org.junit.Assert.assertEquals import org.junit.Test import org.junit.runner.RunWith import org.robolectric.RobolectricTestRunner +import org.robolectric.RuntimeEnvironment import org.robolectric.annotation.Config /** @@ -28,6 +29,28 @@ class ScribeColorResolverTest { assertKeyboardColors(ApplicationProvider.getApplicationContext()) } + @Test + fun everyScribeColorIgnoresTheDeviceNightMode() { + val ids = + R.color::class.java.fields + .filter { it.name.startsWith("scribe_") } + .associate { it.name to it.getInt(null) } + // Guards against the list silently shrinking if the R class shape changes. + assertEquals(true, ids.size >= 26) + + val onDayDevice = ids.mapValues { (_, id) -> context().bothModes(id) } + RuntimeEnvironment.setQualifiers("+night") + val onNightDevice = ids.mapValues { (_, id) -> context().bothModes(id) } + + assertEquals(onDayDevice, onNightDevice) + // The light and dark halves really come from different files. + assertEquals(0xFF5EB5E8.toInt() to 0xFF235270.toInt(), onDayDevice.getValue("scribe_background")) + } + + private fun context(): Context = ApplicationProvider.getApplicationContext() + + private fun Context.bothModes(id: Int): Pair = scribeColorInt(id, dark = false) to scribeColorInt(id, dark = true) + private fun assertKeyboardColors(context: Context) { // Conjugation sub-labels, was "#E558564B" / "#CAC4D0". assertEquals(0xE558564B.toInt(), context.scribeColorInt(R.color.scribe_caption, dark = false)) diff --git a/app/src/testKeyboards/kotlin/be/scri/helpers/ui/KeyboardSharedColorsTest.kt b/app/src/testKeyboards/kotlin/be/scri/helpers/ui/KeyboardSharedColorsTest.kt new file mode 100644 index 00000000..f2618558 --- /dev/null +++ b/app/src/testKeyboards/kotlin/be/scri/helpers/ui/KeyboardSharedColorsTest.kt @@ -0,0 +1,165 @@ +// SPDX-License-Identifier: GPL-3.0-or-later + +package be.scri.helpers.ui + +import android.content.Context +import android.graphics.drawable.ColorDrawable +import android.text.Spanned +import android.text.style.ForegroundColorSpan +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.Button +import androidx.test.core.app.ApplicationProvider +import be.scri.R +import be.scri.databinding.InputMethodViewBinding +import be.scri.helpers.PreferencesHelper +import be.scri.models.ScribeState +import io.mockk.every +import io.mockk.mockk +import org.junit.Assert.assertEquals +import org.junit.Assert.assertNotNull +import org.junit.Test +import org.junit.runner.RunWith +import org.robolectric.RobolectricTestRunner +import org.robolectric.annotation.Config + +/** + * The keyboard colors moved to shared `scribe_*` names in #783 keep their old hex, and follow the + * Scribe dark mode setting even when the device night mode says the opposite. + */ +@RunWith(RobolectricTestRunner::class) +@Config(sdk = [34]) +class KeyboardSharedColorsTest { + @Test + fun invalidBarIsDarkWhenScribeIsDarkOnADayDevice() { + val binding = showState(ScribeState.INVALID, scribeDark = true, deviceNight = false) + assertEquals(0xFF1E1E1E.toInt(), binding.toolbarBar.backgroundColor()) + } + + @Test + @Config(qualifiers = "night") + fun invalidBarIsLightWhenScribeIsLightOnANightDevice() { + val binding = showState(ScribeState.INVALID, scribeDark = false, deviceNight = true) + assertEquals(0xFFD2D4DA.toInt(), binding.toolbarBar.backgroundColor()) + } + + @Test + fun alreadyPluralBarIsDarkWhenScribeIsDarkOnADayDevice() { + val binding = showState(ScribeState.ALREADY_PLURAL, scribeDark = true, deviceNight = false) + assertEquals(0xFF1E1E1E.toInt(), binding.toolbarBar.backgroundColor()) + } + + @Test + @Config(qualifiers = "night") + fun alreadyPluralBarIsLightWhenScribeIsLightOnANightDevice() { + val binding = showState(ScribeState.ALREADY_PLURAL, scribeDark = false, deviceNight = true) + assertEquals(0xFFD2D4DA.toInt(), binding.toolbarBar.backgroundColor()) + } + + @Test + fun conjugationLabelUsesTheDarkCaptionWhenScribeIsDarkOnADayDevice() { + val binding = showConjugationGrid(scribeDark = true, deviceNight = false) + assertEquals(0xFFCAC4D0.toInt(), binding.root.labelColor("1ps")) + } + + @Test + @Config(qualifiers = "night") + fun conjugationLabelUsesTheLightCaptionWhenScribeIsLightOnANightDevice() { + val binding = showConjugationGrid(scribeDark = false, deviceNight = true) + assertEquals(0xE558564B.toInt(), binding.root.labelColor("1ps")) + } + + @Test + fun commandSeparatorsStayTransparentInBothModes() { + listOf(true, false).forEach { dark -> + val binding = showState(ScribeState.SELECT_COMMAND, scribeDark = dark, deviceNight = false) + assertEquals(0, binding.separator2.backgroundColor()) + assertEquals(0, binding.separator3.backgroundColor()) + } + } + + private fun showState( + state: ScribeState, + scribeDark: Boolean, + deviceNight: Boolean, + conjugateOutput: Map>>>? = null, + conjugateLabels: Set? = null, + verb: String? = null, + ): InputMethodViewBinding { + val context = ApplicationProvider.getApplicationContext() + context + .getSharedPreferences(PreferencesHelper.SCRIBE_PREFS, Context.MODE_PRIVATE) + .edit() + .putBoolean("dark_mode", scribeDark) + .putBoolean("last_system_dark_mode", deviceNight) + .commit() + assertEquals(scribeDark, PreferencesHelper.getIsDarkModeOrNot(context)) + + val binding = InputMethodViewBinding.inflate(LayoutInflater.from(context)) + val listener = mockk(relaxed = true) + every { listener.getKeyboardLayoutXML() } returns R.xml.keys_letters_english + every { listener.getCurrentKeyboardLayoutXML() } returns R.xml.keys_letters_english + every { listener.onKeyboardActionListener() } returns mockk() + every { listener.isNumericKeyboardActive() } returns false + + KeyboardUIManager(binding, context, listener).updateUI( + currentState = state, + language = "English", + emojiAutoSuggestionEnabled = false, + autoSuggestEmojis = null, + conjugateOutput = conjugateOutput, + conjugateLabels = conjugateLabels, + selectedConjugationSubCategory = null, + currentVerbForConjugation = verb, + ) + return binding + } + + private fun showConjugationGrid( + scribeDark: Boolean, + deviceNight: Boolean, + ): InputMethodViewBinding { + val context = ApplicationProvider.getApplicationContext() + context + .getSharedPreferences("keyboard_preferences", Context.MODE_PRIVATE) + .edit() + .putInt("conjugate_index", 0) + .commit() + return showState( + ScribeState.SELECT_VERB_CONJUNCTION, + scribeDark = scribeDark, + deviceNight = deviceNight, + conjugateOutput = + mapOf( + "Present" to + mapOf( + "1ps" to listOf("1ps" to "I am"), + "2ps" to listOf("2ps" to "You are"), + ), + ), + conjugateLabels = setOf("1ps", "2ps"), + verb = "be", + ) + } + + private fun View.backgroundColor(): Int = (background as ColorDrawable).color + + private fun View.labelColor(label: String): Int { + val button = findButtonStartingWith(label) + assertNotNull("No conjugation button starts with $label", button) + val text = button!!.text as Spanned + val span = text.getSpans(0, label.length, ForegroundColorSpan::class.java).single() + return span.foregroundColor + } + + private fun View.findButtonStartingWith(label: String): Button? { + if (this is Button && text is Spanned && text.startsWith(label)) return this + if (this is ViewGroup) { + for (i in 0 until childCount) { + getChildAt(i).findButtonStartingWith(label)?.let { return it } + } + } + return null + } +} From bc3d49afb67eee5e5d04c099d62124e4e7bd6c01 Mon Sep 17 00:00:00 2001 From: Bhanu Nagpure <130910873+bhanu-dev82@users.noreply.github.com> Date: Thu, 26 Nov 2026 12:36:51 +0530 Subject: [PATCH 03/15] Resolve the conjugation label color once per grid (#783) --- .../be/scri/helpers/ui/KeyboardUIManager.kt | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/app/src/keyboards/java/be/scri/helpers/ui/KeyboardUIManager.kt b/app/src/keyboards/java/be/scri/helpers/ui/KeyboardUIManager.kt index e82036a0..4fa6d4b9 100644 --- a/app/src/keyboards/java/be/scri/helpers/ui/KeyboardUIManager.kt +++ b/app/src/keyboards/java/be/scri/helpers/ui/KeyboardUIManager.kt @@ -24,6 +24,7 @@ import android.view.View import android.widget.Button import android.widget.LinearLayout import android.widget.TextView +import androidx.annotation.ColorInt import androidx.appcompat.content.res.AppCompatResources import androidx.core.content.ContextCompat import androidx.core.content.edit @@ -515,10 +516,16 @@ class KeyboardUIManager( R.id.conjugate_btn_6, ) + /** + * Color of the small label above a conjugation form, resolved once per grid. + */ + @ColorInt + private fun conjugationLabelColor(isDarkMode: Boolean): Int = context.scribeColorInt(R.color.scribe_caption, dark = isDarkMode) + private fun formatButtonText( label: String, form: String, - isDarkMode: Boolean, + @ColorInt labelColor: Int, ): CharSequence { if (label.isEmpty() || label == "all") return form val spannable = SpannableStringBuilder() @@ -529,7 +536,6 @@ class KeyboardUIManager( label.length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE, ) - val labelColor = context.scribeColorInt(R.color.scribe_caption, isDarkMode) spannable.setSpan( ForegroundColorSpan(labelColor), 0, @@ -584,6 +590,7 @@ class KeyboardUIManager( subPairs: List>, isDarkMode: Boolean, ) { + val labelColor = conjugationLabelColor(isDarkMode) buttonIds.forEachIndexed { i, btnId -> val btn = gridContent.findViewById(btnId) ?: return@forEachIndexed if (i < subPairs.size) { @@ -597,7 +604,7 @@ class KeyboardUIManager( btn.setTextColor(if (isDarkMode) Color.WHITE else Color.BLACK) val hasLabel = label.isNotEmpty() && label != "all" applyButtonLayout(btn, hasLabel) - btn.text = formatButtonText(label, form, isDarkMode) + btn.text = formatButtonText(label, form, labelColor) btn.setOnClickListener { listener.commitText("$form ") listener.processLinguisticSuggestions(form) @@ -614,6 +621,7 @@ class KeyboardUIManager( categoryEntries: List>>>, isDarkMode: Boolean, ) { + val labelColor = conjugationLabelColor(isDarkMode) buttonIds.forEachIndexed { i, btnId -> val btn = gridContent.findViewById(btnId) ?: return@forEachIndexed if (i < categoryEntries.size) { @@ -627,7 +635,7 @@ class KeyboardUIManager( btn.setTextColor(if (isDarkMode) Color.WHITE else Color.BLACK) val formsPreview = pairs.map { it.second.trim() }.filter { it.isNotBlank() }.joinToString(" / ") applyButtonLayout(btn, categoryTitle.isNotEmpty()) - btn.text = formatButtonText(categoryTitle, formsPreview, isDarkMode) + btn.text = formatButtonText(categoryTitle, formsPreview, labelColor) if (pairs.size == 1) { val (_, form) = pairs.first() btn.setOnClickListener { @@ -651,6 +659,7 @@ class KeyboardUIManager( directPairs: List>, isDarkMode: Boolean, ) { + val labelColor = conjugationLabelColor(isDarkMode) buttonIds.forEachIndexed { i, btnId -> val btn = gridContent.findViewById(btnId) ?: return@forEachIndexed if (i < directPairs.size) { @@ -664,7 +673,7 @@ class KeyboardUIManager( btn.setTextColor(if (isDarkMode) Color.WHITE else Color.BLACK) val hasLabel = label.isNotEmpty() && label != "all" applyButtonLayout(btn, hasLabel) - btn.text = formatButtonText(label, form, isDarkMode) + btn.text = formatButtonText(label, form, labelColor) btn.setOnClickListener { listener.commitText("$form ") listener.processLinguisticSuggestions(form) From 9fac2e2ff0d6633f678d37b84d8e2b0370962041 Mon Sep 17 00:00:00 2001 From: Bhanu Nagpure <130910873+bhanu-dev82@users.noreply.github.com> Date: Thu, 26 Nov 2026 12:44:05 +0530 Subject: [PATCH 04/15] Use scribe_keyboard_background for the light command info bar (#783) --- .../java/be/scri/helpers/ui/KeyboardUIManager.kt | 11 +---------- .../be/scri/helpers/ui/KeyboardSharedColorsTest.kt | 4 ++-- 2 files changed, 3 insertions(+), 12 deletions(-) diff --git a/app/src/keyboards/java/be/scri/helpers/ui/KeyboardUIManager.kt b/app/src/keyboards/java/be/scri/helpers/ui/KeyboardUIManager.kt index 4fa6d4b9..012f42ba 100644 --- a/app/src/keyboards/java/be/scri/helpers/ui/KeyboardUIManager.kt +++ b/app/src/keyboards/java/be/scri/helpers/ui/KeyboardUIManager.kt @@ -57,10 +57,6 @@ import be.scri.ui.theme.scribeColorInt import be.scri.views.KeyboardView private const val SUB_SELECTION_LABEL_TEXT_SIZE_RATIO = 0.8f - -// Light background of the invalid and already-plural command bars. It is one step off -// scribe_keyboard_background (#D3D6DD), so it stays as is until we decide which one wins. -private const val LIGHT_COMMAND_INFO_BAR_COLOR = "#D2D4DA" private const val MAX_FORM_COUNT_2X1 = 2 private const val FORM_COUNT_3X1 = 3 private const val MAX_FORM_COUNT_2X2 = 4 @@ -780,12 +776,7 @@ class KeyboardUIManager( /** * Background of the command bar while it shows the invalid or already-plural message. */ - private fun commandInfoBarColor(isDarkMode: Boolean): Int = - if (isDarkMode) { - context.scribeColorInt(R.color.scribe_keyboard_background, dark = true) - } else { - LIGHT_COMMAND_INFO_BAR_COLOR.toColorInt() - } + private fun commandInfoBarColor(isDarkMode: Boolean): Int = context.scribeColorInt(R.color.scribe_keyboard_background, dark = isDarkMode) /** * Configures the UI for the `ALREADY_PLURAL` state, which is shown when the user diff --git a/app/src/testKeyboards/kotlin/be/scri/helpers/ui/KeyboardSharedColorsTest.kt b/app/src/testKeyboards/kotlin/be/scri/helpers/ui/KeyboardSharedColorsTest.kt index f2618558..8cde879e 100644 --- a/app/src/testKeyboards/kotlin/be/scri/helpers/ui/KeyboardSharedColorsTest.kt +++ b/app/src/testKeyboards/kotlin/be/scri/helpers/ui/KeyboardSharedColorsTest.kt @@ -41,7 +41,7 @@ class KeyboardSharedColorsTest { @Config(qualifiers = "night") fun invalidBarIsLightWhenScribeIsLightOnANightDevice() { val binding = showState(ScribeState.INVALID, scribeDark = false, deviceNight = true) - assertEquals(0xFFD2D4DA.toInt(), binding.toolbarBar.backgroundColor()) + assertEquals(0xFFD3D6DD.toInt(), binding.toolbarBar.backgroundColor()) } @Test @@ -54,7 +54,7 @@ class KeyboardSharedColorsTest { @Config(qualifiers = "night") fun alreadyPluralBarIsLightWhenScribeIsLightOnANightDevice() { val binding = showState(ScribeState.ALREADY_PLURAL, scribeDark = false, deviceNight = true) - assertEquals(0xFFD2D4DA.toInt(), binding.toolbarBar.backgroundColor()) + assertEquals(0xFFD3D6DD.toInt(), binding.toolbarBar.backgroundColor()) } @Test From 7e44f22723e801c413ba1e91a5f2a5f278002dc8 Mon Sep 17 00:00:00 2001 From: Bhanu Nagpure <130910873+bhanu-dev82@users.noreply.github.com> Date: Thu, 26 Nov 2026 12:45:25 +0530 Subject: [PATCH 05/15] Use scribe_key and scribe_text for the letter keys (#783) --- .../main/java/be/scri/views/KeyboardView.kt | 46 +++++++++++-------- .../helpers/ui/KeyboardSharedColorsTest.kt | 19 ++++++++ 2 files changed, 47 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/be/scri/views/KeyboardView.kt b/app/src/main/java/be/scri/views/KeyboardView.kt index 6ceb257b..3699e14e 100644 --- a/app/src/main/java/be/scri/views/KeyboardView.kt +++ b/app/src/main/java/be/scri/views/KeyboardView.kt @@ -31,6 +31,8 @@ import android.view.accessibility.AccessibilityManager import android.view.inputmethod.EditorInfo import android.widget.PopupWindow import android.widget.TextView +import androidx.annotation.ColorInt +import androidx.annotation.VisibleForTesting import androidx.core.content.edit import androidx.core.graphics.createBitmap import androidx.core.graphics.withSave @@ -66,6 +68,7 @@ import be.scri.helpers.SHIFT_OFF import be.scri.helpers.SHIFT_ON_ONE_CHAR import be.scri.helpers.SHIFT_ON_PERMANENT import be.scri.models.ScribeState +import be.scri.ui.theme.scribeColorInt import java.util.Arrays import java.util.Locale import kotlin.ranges.coerceIn @@ -275,6 +278,27 @@ class KeyboardView private var mKeyboardBackgroundColor = 0 + /** + * Shared `scribe_*` colors for the keys in one mode. + */ + internal data class KeyColors( + @ColorInt val key: Int, + @ColorInt val label: Int, + ) + + private var cachedKeyColors: Pair? = null + + /** + * Key colors for the Scribe dark mode setting, read once per mode instead of on every draw. + */ + @VisibleForTesting + internal fun keyColorsFor(dark: Boolean): KeyColors = + cachedKeyColors?.takeIf { it.first == dark }?.second + ?: KeyColors( + key = context.scribeColorInt(R.color.scribe_key, dark = dark), + label = context.scribeColorInt(R.color.scribe_text, dark = dark), + ).also { cachedKeyColors = dark to it } + private val alpha = FULL_ALPHA private val redDark = (DARK_COLOR_FACTOR * FULL_ALPHA).toInt() private val greenDark = (DARK_COLOR_FACTOR * FULL_ALPHA).toInt() @@ -858,24 +882,10 @@ class KeyboardView val isUserDarkMode = be.scri.helpers.PreferencesHelper .getIsDarkModeOrNot(context) - val keyBackgroundColor = - if (isUserDarkMode) { - Color.DKGRAY - } else { - Color.WHITE - } - mBackgroundColor = - if (isUserDarkMode) { - Color.DKGRAY - } else { - Color.WHITE - } - mTextColor = - if (keyBackgroundColor == Color.WHITE) { - Color.BLACK - } else { - Color.WHITE - } + val keyColors = keyColorsFor(isUserDarkMode) + val keyBackgroundColor = keyColors.key + mBackgroundColor = keyColors.key + mTextColor = keyColors.label val pressedColorResId = if (isUserDarkMode) { R.color.dark_key_press_color diff --git a/app/src/testKeyboards/kotlin/be/scri/helpers/ui/KeyboardSharedColorsTest.kt b/app/src/testKeyboards/kotlin/be/scri/helpers/ui/KeyboardSharedColorsTest.kt index 8cde879e..584ed3d3 100644 --- a/app/src/testKeyboards/kotlin/be/scri/helpers/ui/KeyboardSharedColorsTest.kt +++ b/app/src/testKeyboards/kotlin/be/scri/helpers/ui/KeyboardSharedColorsTest.kt @@ -79,6 +79,25 @@ class KeyboardSharedColorsTest { } } + @Test + @Config(qualifiers = "night") + fun letterKeysUseScribeKeyAndTextOnANightDevice() { + val binding = showState(ScribeState.IDLE, scribeDark = false, deviceNight = true) + val light = binding.keyboardView.keyColorsFor(dark = false) + val dark = binding.keyboardView.keyColorsFor(dark = true) + assertEquals(0xFFFFFFFF.toInt(), light.key) + assertEquals(0xFF000000.toInt(), light.label) + assertEquals(0xFF434343.toInt(), dark.key) + assertEquals(0xFFFFFFFF.toInt(), dark.label) + } + + @Test + fun letterKeysUseScribeKeyAndTextOnADayDevice() { + val binding = showState(ScribeState.IDLE, scribeDark = true, deviceNight = false) + assertEquals(0xFF434343.toInt(), binding.keyboardView.keyColorsFor(dark = true).key) + assertEquals(0xFFFFFFFF.toInt(), binding.keyboardView.keyColorsFor(dark = false).key) + } + private fun showState( state: ScribeState, scribeDark: Boolean, From 67831497fb90916a669743fcc55a9cff56dc3869 Mon Sep 17 00:00:00 2001 From: Bhanu Nagpure <130910873+bhanu-dev82@users.noreply.github.com> Date: Thu, 26 Nov 2026 12:46:41 +0530 Subject: [PATCH 06/15] Color suggestions like the key labels (#783) --- .../be/scri/helpers/ui/KeyboardThemeManager.kt | 5 +++-- .../be/scri/helpers/ui/KeyboardUIManager.kt | 4 ++-- .../scri/helpers/ui/KeyboardSharedColorsTest.kt | 17 +++++++++++++++++ 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/app/src/keyboards/java/be/scri/helpers/ui/KeyboardThemeManager.kt b/app/src/keyboards/java/be/scri/helpers/ui/KeyboardThemeManager.kt index 788ef0f9..404645d5 100644 --- a/app/src/keyboards/java/be/scri/helpers/ui/KeyboardThemeManager.kt +++ b/app/src/keyboards/java/be/scri/helpers/ui/KeyboardThemeManager.kt @@ -16,13 +16,13 @@ import android.widget.Button import android.widget.TextView import androidx.core.content.ContextCompat import androidx.core.graphics.ColorUtils -import androidx.core.graphics.toColorInt import androidx.core.view.ViewCompat import androidx.core.view.WindowCompat import androidx.core.view.WindowInsetsCompat import androidx.core.view.WindowInsetsControllerCompat import be.scri.R import be.scri.helpers.PreferencesHelper.getIsDarkModeOrNot +import be.scri.ui.theme.scribeColorInt /** * Manages UI theme color resolutions, gradient/ripple drawables creation, @@ -232,6 +232,7 @@ class KeyboardThemeManager { */ fun getSuggestionTextColor(context: Context): Int { val isDarkMode = getIsDarkModeOrNot(context) - return if (isDarkMode) Color.WHITE else "#1E1E1E".toColorInt() + // Same color as the characters on the keys. + return context.scribeColorInt(R.color.scribe_text, dark = isDarkMode) } } diff --git a/app/src/keyboards/java/be/scri/helpers/ui/KeyboardUIManager.kt b/app/src/keyboards/java/be/scri/helpers/ui/KeyboardUIManager.kt index 012f42ba..e90744d8 100644 --- a/app/src/keyboards/java/be/scri/helpers/ui/KeyboardUIManager.kt +++ b/app/src/keyboards/java/be/scri/helpers/ui/KeyboardUIManager.kt @@ -28,7 +28,6 @@ import androidx.annotation.ColorInt import androidx.appcompat.content.res.AppCompatResources import androidx.core.content.ContextCompat import androidx.core.content.edit -import androidx.core.graphics.toColorInt import androidx.core.view.updateLayoutParams import androidx.recyclerview.widget.GridLayoutManager import be.scri.R @@ -269,7 +268,8 @@ class KeyboardUIManager( ), ) - val textColor = if (isUserDarkMode) Color.WHITE else "#1E1E1E".toColorInt() + // Same color as the characters on the keys. + val textColor = context.scribeColorInt(R.color.scribe_text, dark = isUserDarkMode) listOf(binding.translateBtn, binding.conjugateBtn, binding.pluralBtn).forEachIndexed { index, button -> button.visibility = View.VISIBLE diff --git a/app/src/testKeyboards/kotlin/be/scri/helpers/ui/KeyboardSharedColorsTest.kt b/app/src/testKeyboards/kotlin/be/scri/helpers/ui/KeyboardSharedColorsTest.kt index 584ed3d3..d4dde2f3 100644 --- a/app/src/testKeyboards/kotlin/be/scri/helpers/ui/KeyboardSharedColorsTest.kt +++ b/app/src/testKeyboards/kotlin/be/scri/helpers/ui/KeyboardSharedColorsTest.kt @@ -98,6 +98,23 @@ class KeyboardSharedColorsTest { assertEquals(0xFFFFFFFF.toInt(), binding.keyboardView.keyColorsFor(dark = false).key) } + @Test + @Config(qualifiers = "night") + fun suggestionsMatchTheKeyLabelsWhenScribeIsLightOnANightDevice() { + val binding = showState(ScribeState.IDLE, scribeDark = false, deviceNight = true) + val context = ApplicationProvider.getApplicationContext() + assertEquals(0xFF000000.toInt(), KeyboardThemeManager().getSuggestionTextColor(context)) + assertEquals(0xFF000000.toInt(), binding.translateBtn.currentTextColor) + } + + @Test + fun suggestionsMatchTheKeyLabelsWhenScribeIsDarkOnADayDevice() { + val binding = showState(ScribeState.IDLE, scribeDark = true, deviceNight = false) + val context = ApplicationProvider.getApplicationContext() + assertEquals(0xFFFFFFFF.toInt(), KeyboardThemeManager().getSuggestionTextColor(context)) + assertEquals(0xFFFFFFFF.toInt(), binding.translateBtn.currentTextColor) + } + private fun showState( state: ScribeState, scribeDark: Boolean, From 1929678f7e8cc5ea7efcc28aefc512254dcc7d9a Mon Sep 17 00:00:00 2001 From: Bhanu Nagpure <130910873+bhanu-dev82@users.noreply.github.com> Date: Thu, 26 Nov 2026 12:48:02 +0530 Subject: [PATCH 07/15] Use Figma's special-key colors for Enter, delete, shift and mode keys (#783) --- .../main/java/be/scri/views/KeyboardView.kt | 31 ++++--------------- app/src/main/res/values-night/colors.xml | 2 +- app/src/main/res/values/colors.xml | 2 +- .../helpers/ui/KeyboardSharedColorsTest.kt | 5 +++ 4 files changed, 13 insertions(+), 27 deletions(-) diff --git a/app/src/main/java/be/scri/views/KeyboardView.kt b/app/src/main/java/be/scri/views/KeyboardView.kt index 3699e14e..2074fc2f 100644 --- a/app/src/main/java/be/scri/views/KeyboardView.kt +++ b/app/src/main/java/be/scri/views/KeyboardView.kt @@ -279,11 +279,12 @@ class KeyboardView private var mKeyboardBackgroundColor = 0 /** - * Shared `scribe_*` colors for the keys in one mode. + * Shared `scribe_*` colors for the keys in one mode. [special] paints Enter, delete, shift and the mode key. */ internal data class KeyColors( @ColorInt val key: Int, @ColorInt val label: Int, + @ColorInt val special: Int, ) private var cachedKeyColors: Pair? = null @@ -297,19 +298,9 @@ class KeyboardView ?: KeyColors( key = context.scribeColorInt(R.color.scribe_key, dark = dark), label = context.scribeColorInt(R.color.scribe_text, dark = dark), + special = context.scribeColorInt(R.color.scribe_key_special, dark = dark), ).also { cachedKeyColors = dark to it } - private val alpha = FULL_ALPHA - private val redDark = (DARK_COLOR_FACTOR * FULL_ALPHA).toInt() - private val greenDark = (DARK_COLOR_FACTOR * FULL_ALPHA).toInt() - private val blueDark = (DARK_COLOR_FACTOR * FULL_ALPHA).toInt() - private val darkSpecialKey = Color.argb(FULL_ALPHA, redDark, greenDark, blueDark) - - private val red = (LIGHT_COLOR_RED_FACTOR * FULL_ALPHA).toInt() - private val green = (LIGHT_COLOR_GREEN_FACTOR * FULL_ALPHA).toInt() - private val blue = (LIGHT_COLOR_BLUE_FACTOR * FULL_ALPHA).toInt() - private val lightSpecialKey = Color.argb(alpha, red, green, blue) - /** * Contains constants and configuration values used across KeyboardView. */ @@ -327,10 +318,6 @@ class KeyboardView private const val DOUBLE_TAP_DELAY = 300L private const val NUMBER_OF_KEYS = 12 private const val FULL_ALPHA = 255 - private const val DARK_COLOR_FACTOR = 0.180 - private const val LIGHT_COLOR_RED_FACTOR = 0.682 - private const val LIGHT_COLOR_GREEN_FACTOR = 0.702 - private const val LIGHT_COLOR_BLUE_FACTOR = 0.745 private const val DEFAULT_KEY_TEXT_SIZE = 18 private const val MARGIN_ADJUSTMENT = 10 private const val PROXIMITY_SCALING_FACTOR = 1.4f @@ -374,12 +361,12 @@ class KeyboardView } else { when (isDarkMode) { true -> { - mEnterKeyColor = darkSpecialKey + mEnterKeyColor = keyColorsFor(dark = true).special invalidateAllKeys() } else -> { - mEnterKeyColor = lightSpecialKey + mEnterKeyColor = keyColorsFor(dark = false).special invalidateAllKeys() } } @@ -893,13 +880,7 @@ class KeyboardView R.color.light_key_press_color } val pressedColor = resources.getColor(pressedColorResId, context.theme) - val specialKeyColorResource = - if (isUserDarkMode) { - R.color.special_key_dark - } else { - R.color.special_key_light - } - val specialKeyColorValue = resources.getColor(specialKeyColorResource, context.theme) + val specialKeyColorValue = keyColors.special val focusedColorResId = if (isUserDarkMode) { R.color.theme_scribe_blue diff --git a/app/src/main/res/values-night/colors.xml b/app/src/main/res/values-night/colors.xml index 0587b35c..b6422cca 100644 --- a/app/src/main/res/values-night/colors.xml +++ b/app/src/main/res/values-night/colors.xml @@ -67,7 +67,7 @@ #FF434343 #95FFFFFF #FF363636 - #FF202020 + #FF2D2D2D #FF4CADE6 #FFFB5F6C #FF339EEB diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index fa8f0c45..1f0fb01a 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -839,7 +839,7 @@ #95000000 #FFE9E9E9 #FFAEB3BE + name="scribe_key_special">#FFADB3BD #FF75CEFA #FF9F1722 diff --git a/app/src/testKeyboards/kotlin/be/scri/helpers/ui/KeyboardSharedColorsTest.kt b/app/src/testKeyboards/kotlin/be/scri/helpers/ui/KeyboardSharedColorsTest.kt index d4dde2f3..4b33b756 100644 --- a/app/src/testKeyboards/kotlin/be/scri/helpers/ui/KeyboardSharedColorsTest.kt +++ b/app/src/testKeyboards/kotlin/be/scri/helpers/ui/KeyboardSharedColorsTest.kt @@ -89,6 +89,9 @@ class KeyboardSharedColorsTest { assertEquals(0xFF000000.toInt(), light.label) assertEquals(0xFF434343.toInt(), dark.key) assertEquals(0xFFFFFFFF.toInt(), dark.label) + // Enter, delete, shift and the mode key use the Figma special-key values. + assertEquals(0xFFADB3BD.toInt(), light.special) + assertEquals(0xFF2D2D2D.toInt(), dark.special) } @Test @@ -96,6 +99,8 @@ class KeyboardSharedColorsTest { val binding = showState(ScribeState.IDLE, scribeDark = true, deviceNight = false) assertEquals(0xFF434343.toInt(), binding.keyboardView.keyColorsFor(dark = true).key) assertEquals(0xFFFFFFFF.toInt(), binding.keyboardView.keyColorsFor(dark = false).key) + assertEquals(0xFF2D2D2D.toInt(), binding.keyboardView.keyColorsFor(dark = true).special) + assertEquals(0xFFADB3BD.toInt(), binding.keyboardView.keyColorsFor(dark = false).special) } @Test From 26cdf2497b7a7fe4a05e540ff032dad4eb67101b Mon Sep 17 00:00:00 2001 From: Bhanu Nagpure <130910873+bhanu-dev82@users.noreply.github.com> Date: Thu, 26 Nov 2026 12:49:26 +0530 Subject: [PATCH 08/15] Name the floating keyboard border scribe_keyboard_border (#783) --- .../keyboards/java/be/scri/helpers/FloatingKeyboardHandler.kt | 3 ++- app/src/main/res/drawable/floating_keyboard_background.xml | 2 +- app/src/main/res/values-night/colors.xml | 1 + app/src/main/res/values/colors.xml | 1 + .../test/kotlin/be/scri/ui/theme/ScribeColorResolverTest.kt | 3 +++ 5 files changed, 8 insertions(+), 2 deletions(-) diff --git a/app/src/keyboards/java/be/scri/helpers/FloatingKeyboardHandler.kt b/app/src/keyboards/java/be/scri/helpers/FloatingKeyboardHandler.kt index 884b839f..406bcd59 100644 --- a/app/src/keyboards/java/be/scri/helpers/FloatingKeyboardHandler.kt +++ b/app/src/keyboards/java/be/scri/helpers/FloatingKeyboardHandler.kt @@ -17,6 +17,7 @@ import android.view.WindowManager import androidx.core.content.ContextCompat import be.scri.R import be.scri.helpers.PreferencesHelper.getIsDarkModeOrNot +import be.scri.ui.theme.scribeColorInt /** * Manages floating keyboard state, resize handles, touch listeners, and layout transitions @@ -160,7 +161,7 @@ class FloatingKeyboardHandler( shape = GradientDrawable.RECTANGLE cornerRadius = 16f * density setColor(kbBgColor) - setStroke((1f * density).toInt(), 0x40888888.toInt()) + setStroke((1f * density).toInt(), ime.imeContext.scribeColorInt(R.color.scribe_keyboard_border, dark = isDarkMode)) } card.background = floatingBg card.elevation = 8f * density diff --git a/app/src/main/res/drawable/floating_keyboard_background.xml b/app/src/main/res/drawable/floating_keyboard_background.xml index 4b34336d..97cf6ad3 100644 --- a/app/src/main/res/drawable/floating_keyboard_background.xml +++ b/app/src/main/res/drawable/floating_keyboard_background.xml @@ -5,5 +5,5 @@ + android:color="@color/scribe_keyboard_border" /> diff --git a/app/src/main/res/values-night/colors.xml b/app/src/main/res/values-night/colors.xml index b6422cca..cde540a5 100644 --- a/app/src/main/res/values-night/colors.xml +++ b/app/src/main/res/values-night/colors.xml @@ -76,4 +76,5 @@ #FFFD9F5D #FF808080 #FFFFFFFF + #40888888 diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index 1f0fb01a..3f75fb04 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -852,5 +852,6 @@ #FF808080 #FF000000 + #40888888 diff --git a/app/src/test/kotlin/be/scri/ui/theme/ScribeColorResolverTest.kt b/app/src/test/kotlin/be/scri/ui/theme/ScribeColorResolverTest.kt index 45fc8940..1ef74a3e 100644 --- a/app/src/test/kotlin/be/scri/ui/theme/ScribeColorResolverTest.kt +++ b/app/src/test/kotlin/be/scri/ui/theme/ScribeColorResolverTest.kt @@ -57,5 +57,8 @@ class ScribeColorResolverTest { assertEquals(0xFFCAC4D0.toInt(), context.scribeColorInt(R.color.scribe_caption, dark = true)) // Dark invalid and already-plural command bar, was "#1E1E1E". assertEquals(0xFF1E1E1E.toInt(), context.scribeColorInt(R.color.scribe_keyboard_background, dark = true)) + // Floating keyboard border, was 0x40888888 in both modes. + assertEquals(0x40888888, context.scribeColorInt(R.color.scribe_keyboard_border, dark = false)) + assertEquals(0x40888888, context.scribeColorInt(R.color.scribe_keyboard_border, dark = true)) } } From 95e2fb8c34e2f2637005ce141e704105d079693d Mon Sep 17 00:00:00 2001 From: Bhanu Nagpure <130910873+bhanu-dev82@users.noreply.github.com> Date: Thu, 26 Nov 2026 12:51:22 +0530 Subject: [PATCH 09/15] Add scribe_delete for the clipboard clear-all icon (#783) --- .../be/scri/helpers/ui/KeyboardUIManager.kt | 2 ++ app/src/main/res/layout/input_method_view.xml | 2 +- app/src/main/res/values-night/colors.xml | 1 + app/src/main/res/values/colors.xml | 1 + .../scri/ui/theme/ScribeColorResolverTest.kt | 3 ++ .../helpers/ui/KeyboardSharedColorsTest.kt | 32 +++++++++++++++---- 6 files changed, 33 insertions(+), 8 deletions(-) diff --git a/app/src/keyboards/java/be/scri/helpers/ui/KeyboardUIManager.kt b/app/src/keyboards/java/be/scri/helpers/ui/KeyboardUIManager.kt index e90744d8..cca5065e 100644 --- a/app/src/keyboards/java/be/scri/helpers/ui/KeyboardUIManager.kt +++ b/app/src/keyboards/java/be/scri/helpers/ui/KeyboardUIManager.kt @@ -1509,6 +1509,8 @@ class KeyboardUIManager( binding.clipboardPanelClose.setColorFilter(textColor) binding.clipboardPanelLabel.setTextColor(textColor) binding.clipboardEmptyText.setTextColor(textColor) + binding.clipboardClearAll.imageTintList = + ColorStateList.valueOf(context.scribeColorInt(R.color.scribe_delete, dark = isDarkMode)) } fun hideClipboardPanel() { diff --git a/app/src/main/res/layout/input_method_view.xml b/app/src/main/res/layout/input_method_view.xml index d9317366..e5597583 100644 --- a/app/src/main/res/layout/input_method_view.xml +++ b/app/src/main/res/layout/input_method_view.xml @@ -838,7 +838,7 @@ GeneralKeyboardIME.kt android:contentDescription="@string/i18n.app._global.clear_all" android:padding="@dimen/small_margin" android:src="@drawable/ic_delete_vector" - android:tint="#E53935" /> + android:tint="@color/scribe_delete" /> diff --git a/app/src/main/res/values-night/colors.xml b/app/src/main/res/values-night/colors.xml index cde540a5..db2b3299 100644 --- a/app/src/main/res/values-night/colors.xml +++ b/app/src/main/res/values-night/colors.xml @@ -77,4 +77,5 @@ #FF808080 #FFFFFFFF #40888888 + #FFD11149 diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index 3f75fb04..71d31133 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -853,5 +853,6 @@ name="scribe_nav_unselected">#FF808080 #FF000000 #40888888 + #FFE4572E diff --git a/app/src/test/kotlin/be/scri/ui/theme/ScribeColorResolverTest.kt b/app/src/test/kotlin/be/scri/ui/theme/ScribeColorResolverTest.kt index 1ef74a3e..e50f015b 100644 --- a/app/src/test/kotlin/be/scri/ui/theme/ScribeColorResolverTest.kt +++ b/app/src/test/kotlin/be/scri/ui/theme/ScribeColorResolverTest.kt @@ -60,5 +60,8 @@ class ScribeColorResolverTest { // Floating keyboard border, was 0x40888888 in both modes. assertEquals(0x40888888, context.scribeColorInt(R.color.scribe_keyboard_border, dark = false)) assertEquals(0x40888888, context.scribeColorInt(R.color.scribe_keyboard_border, dark = true)) + // Clipboard clear-all, the delete red from #772 (was #E53935 in both modes). + assertEquals(0xFFE4572E.toInt(), context.scribeColorInt(R.color.scribe_delete, dark = false)) + assertEquals(0xFFD11149.toInt(), context.scribeColorInt(R.color.scribe_delete, dark = true)) } } diff --git a/app/src/testKeyboards/kotlin/be/scri/helpers/ui/KeyboardSharedColorsTest.kt b/app/src/testKeyboards/kotlin/be/scri/helpers/ui/KeyboardSharedColorsTest.kt index 4b33b756..aac26ad7 100644 --- a/app/src/testKeyboards/kotlin/be/scri/helpers/ui/KeyboardSharedColorsTest.kt +++ b/app/src/testKeyboards/kotlin/be/scri/helpers/ui/KeyboardSharedColorsTest.kt @@ -120,6 +120,21 @@ class KeyboardSharedColorsTest { assertEquals(0xFFFFFFFF.toInt(), binding.translateBtn.currentTextColor) } + @Test + @Config(qualifiers = "night") + fun clipboardClearAllUsesTheLightDeleteRedWhenScribeIsLightOnANightDevice() { + val binding = showState(ScribeState.IDLE, scribeDark = false, deviceNight = true) + KeyboardUIManager(binding, ApplicationProvider.getApplicationContext(), relaxedListener()).applyClipboardPanelTheme() + assertEquals(0xFFE4572E.toInt(), binding.clipboardClearAll.imageTintList!!.defaultColor) + } + + @Test + fun clipboardClearAllUsesTheDarkDeleteRedWhenScribeIsDarkOnADayDevice() { + val binding = showState(ScribeState.IDLE, scribeDark = true, deviceNight = false) + KeyboardUIManager(binding, ApplicationProvider.getApplicationContext(), relaxedListener()).applyClipboardPanelTheme() + assertEquals(0xFFD11149.toInt(), binding.clipboardClearAll.imageTintList!!.defaultColor) + } + private fun showState( state: ScribeState, scribeDark: Boolean, @@ -138,13 +153,7 @@ class KeyboardSharedColorsTest { assertEquals(scribeDark, PreferencesHelper.getIsDarkModeOrNot(context)) val binding = InputMethodViewBinding.inflate(LayoutInflater.from(context)) - val listener = mockk(relaxed = true) - every { listener.getKeyboardLayoutXML() } returns R.xml.keys_letters_english - every { listener.getCurrentKeyboardLayoutXML() } returns R.xml.keys_letters_english - every { listener.onKeyboardActionListener() } returns mockk() - every { listener.isNumericKeyboardActive() } returns false - - KeyboardUIManager(binding, context, listener).updateUI( + KeyboardUIManager(binding, context, relaxedListener()).updateUI( currentState = state, language = "English", emojiAutoSuggestionEnabled = false, @@ -157,6 +166,15 @@ class KeyboardSharedColorsTest { return binding } + private fun relaxedListener(): KeyboardUIManager.KeyboardUIListener { + val listener = mockk(relaxed = true) + every { listener.getKeyboardLayoutXML() } returns R.xml.keys_letters_english + every { listener.getCurrentKeyboardLayoutXML() } returns R.xml.keys_letters_english + every { listener.onKeyboardActionListener() } returns mockk() + every { listener.isNumericKeyboardActive() } returns false + return listener + } + private fun showConjugationGrid( scribeDark: Boolean, deviceNight: Boolean, From 0de9882ee945d562c0315b6a359aaa06ad7833c7 Mon Sep 17 00:00:00 2001 From: Bhanu Nagpure <130910873+bhanu-dev82@users.noreply.github.com> Date: Thu, 26 Nov 2026 12:56:35 +0530 Subject: [PATCH 10/15] Cache shared color lookups so suggestions don't allocate per keystroke (#783) --- .../be/scri/ui/theme/ScribeColorResolver.kt | 18 +++++++++++++++++- .../scri/ui/theme/ScribeColorResolverTest.kt | 6 ++++++ .../helpers/ui/KeyboardSharedColorsTest.kt | 5 +++++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/be/scri/ui/theme/ScribeColorResolver.kt b/app/src/main/java/be/scri/ui/theme/ScribeColorResolver.kt index a10644af..5bd4937f 100644 --- a/app/src/main/java/be/scri/ui/theme/ScribeColorResolver.kt +++ b/app/src/main/java/be/scri/ui/theme/ScribeColorResolver.kt @@ -6,7 +6,14 @@ import android.content.Context import android.content.res.Configuration import androidx.annotation.ColorInt import androidx.annotation.ColorRes +import androidx.annotation.VisibleForTesting import androidx.core.content.ContextCompat +import java.util.concurrent.ConcurrentHashMap + +// Colors are only split by night mode (values and values-night), so a color id and the +// dark flag fully decide the value. Caching avoids a new configuration context per lookup, +// as suggestions are colored on every keystroke. +private val scribeColorCache = ConcurrentHashMap() /** * Reads a shared `scribe_*` color for light or dark. @@ -17,7 +24,16 @@ import androidx.core.content.ContextCompat fun Context.scribeColorInt( @ColorRes id: Int, dark: Boolean, -): Int = ContextCompat.getColor(scribeNightContext(dark), id) +): Int { + val key = (id.toLong() shl 1) or (if (dark) 1L else 0L) + return scribeColorCache.getOrPut(key) { ContextCompat.getColor(scribeNightContext(dark), id) } +} + +/** + * Empties the color cache so tests can resolve again under a different device configuration. + */ +@VisibleForTesting +internal fun clearScribeColorCache() = scribeColorCache.clear() /** * A context whose resources resolve as day or night according to [dark]. diff --git a/app/src/test/kotlin/be/scri/ui/theme/ScribeColorResolverTest.kt b/app/src/test/kotlin/be/scri/ui/theme/ScribeColorResolverTest.kt index e50f015b..6b637a93 100644 --- a/app/src/test/kotlin/be/scri/ui/theme/ScribeColorResolverTest.kt +++ b/app/src/test/kotlin/be/scri/ui/theme/ScribeColorResolverTest.kt @@ -6,6 +6,7 @@ import android.content.Context import androidx.test.core.app.ApplicationProvider import be.scri.R import org.junit.Assert.assertEquals +import org.junit.Before import org.junit.Test import org.junit.runner.RunWith import org.robolectric.RobolectricTestRunner @@ -18,6 +19,9 @@ import org.robolectric.annotation.Config @RunWith(RobolectricTestRunner::class) @Config(sdk = [34]) class ScribeColorResolverTest { + @Before + fun resetColorCache() = clearScribeColorCache() + @Test fun keyboardColorsMatchTheOldHexOnADayDevice() { assertKeyboardColors(ApplicationProvider.getApplicationContext()) @@ -38,7 +42,9 @@ class ScribeColorResolverTest { // Guards against the list silently shrinking if the R class shape changes. assertEquals(true, ids.size >= 26) + clearScribeColorCache() val onDayDevice = ids.mapValues { (_, id) -> context().bothModes(id) } + clearScribeColorCache() RuntimeEnvironment.setQualifiers("+night") val onNightDevice = ids.mapValues { (_, id) -> context().bothModes(id) } diff --git a/app/src/testKeyboards/kotlin/be/scri/helpers/ui/KeyboardSharedColorsTest.kt b/app/src/testKeyboards/kotlin/be/scri/helpers/ui/KeyboardSharedColorsTest.kt index aac26ad7..1f2e8d35 100644 --- a/app/src/testKeyboards/kotlin/be/scri/helpers/ui/KeyboardSharedColorsTest.kt +++ b/app/src/testKeyboards/kotlin/be/scri/helpers/ui/KeyboardSharedColorsTest.kt @@ -15,10 +15,12 @@ import be.scri.R import be.scri.databinding.InputMethodViewBinding import be.scri.helpers.PreferencesHelper import be.scri.models.ScribeState +import be.scri.ui.theme.clearScribeColorCache import io.mockk.every import io.mockk.mockk import org.junit.Assert.assertEquals import org.junit.Assert.assertNotNull +import org.junit.Before import org.junit.Test import org.junit.runner.RunWith import org.robolectric.RobolectricTestRunner @@ -31,6 +33,9 @@ import org.robolectric.annotation.Config @RunWith(RobolectricTestRunner::class) @Config(sdk = [34]) class KeyboardSharedColorsTest { + @Before + fun resetColorCache() = clearScribeColorCache() + @Test fun invalidBarIsDarkWhenScribeIsDarkOnADayDevice() { val binding = showState(ScribeState.INVALID, scribeDark = true, deviceNight = false) From 1c64659e06e66cb19f879af2d30ad058657e6bc1 Mon Sep 17 00:00:00 2001 From: Bhanu Nagpure <130910873+bhanu-dev82@users.noreply.github.com> Date: Thu, 26 Nov 2026 12:56:35 +0530 Subject: [PATCH 11/15] Update the changelog for the #783 color changes --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c9de3e98..238b1cb2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,7 +18,7 @@ Emojis for the following are chosen based on [gitmoji](https://gitmoji.dev/). ### 🎨 Design - Compose theme colors now come from the shared `scribe_*` resources. Dark mode button text stays orange on orange. The dark caption uses the named token `#CAC4D0`, the same grey this slot already used ([#782](https://github.com/scribe-org/Scribe-Android/issues/782)). -- The keyboard's conjugation labels and dark command info bar read the shared `scribe_*` colors instead of hex literals. No color changes ([#783](https://github.com/scribe-org/Scribe-Android/issues/783)). +- The keyboard reads the shared `scribe_*` colors instead of hex literals. Small intentional changes: the light invalid and already-plural bar matches the keyboard background, dark letter keys use `scribe_key`, suggestions match the key labels, Enter, delete, shift and the mode key use the Figma special-key colors, and the clipboard clear-all icon uses the new `scribe_delete` red ([#783](https://github.com/scribe-org/Scribe-Android/issues/783)). ### 🔒 Security From dea6c636efeebaf08ba54791d9bb65f42e98326d Mon Sep 17 00:00:00 2001 From: Bhanu Nagpure <130910873+bhanu-dev82@users.noreply.github.com> Date: Thu, 26 Nov 2026 17:13:32 +0530 Subject: [PATCH 12/15] Use a SparseIntArray per mode for color lookups and drop the XML clear-all tint (#783) --- .../be/scri/ui/theme/ScribeColorResolver.kt | 36 ++++++++++++++----- .../drawable/floating_keyboard_background.xml | 9 ----- app/src/main/res/layout/input_method_view.xml | 3 +- .../scri/ui/theme/ScribeColorResolverTest.kt | 29 +++++++++++++++ 4 files changed, 58 insertions(+), 19 deletions(-) delete mode 100644 app/src/main/res/drawable/floating_keyboard_background.xml diff --git a/app/src/main/java/be/scri/ui/theme/ScribeColorResolver.kt b/app/src/main/java/be/scri/ui/theme/ScribeColorResolver.kt index 5bd4937f..d77d0557 100644 --- a/app/src/main/java/be/scri/ui/theme/ScribeColorResolver.kt +++ b/app/src/main/java/be/scri/ui/theme/ScribeColorResolver.kt @@ -4,36 +4,56 @@ package be.scri.ui.theme import android.content.Context import android.content.res.Configuration +import android.util.SparseIntArray import androidx.annotation.ColorInt import androidx.annotation.ColorRes +import androidx.annotation.MainThread import androidx.annotation.VisibleForTesting import androidx.core.content.ContextCompat -import java.util.concurrent.ConcurrentHashMap +import androidx.core.util.size // Colors are only split by night mode (values and values-night), so a color id and the -// dark flag fully decide the value. Caching avoids a new configuration context per lookup, -// as suggestions are colored on every keystroke. -private val scribeColorCache = ConcurrentHashMap() +// dark flag fully decide the value. One SparseIntArray per mode keeps lookups free of boxing, +// as suggestions are colored on every keystroke. Every caller sets a view or paint color, +// so lookups happen on the main thread and the caches are not synchronized. +private val lightColorCache = SparseIntArray() +private val darkColorCache = SparseIntArray() /** * Reads a shared `scribe_*` color for light or dark. * [dark] follows the Scribe dark mode setting, not the device night mode, * so the keyboard and the Compose theme pick the same value. */ +@MainThread @ColorInt fun Context.scribeColorInt( @ColorRes id: Int, dark: Boolean, ): Int { - val key = (id.toLong() shl 1) or (if (dark) 1L else 0L) - return scribeColorCache.getOrPut(key) { ContextCompat.getColor(scribeNightContext(dark), id) } + val cache = if (dark) darkColorCache else lightColorCache + // indexOfKey rather than get(id, default): any int, including 0 (transparent), is a valid color. + val index = cache.indexOfKey(id) + if (index >= 0) return cache.valueAt(index) + val color = ContextCompat.getColor(scribeNightContext(dark), id) + cache.put(id, color) + return color } /** - * Empties the color cache so tests can resolve again under a different device configuration. + * Empties the color caches so tests can resolve again under a different device configuration. */ @VisibleForTesting -internal fun clearScribeColorCache() = scribeColorCache.clear() +@MainThread +internal fun clearScribeColorCache() { + lightColorCache.clear() + darkColorCache.clear() +} + +/** + * Number of cached colors in both modes, for tests. + */ +@VisibleForTesting +internal fun scribeColorCacheSize(): Int = lightColorCache.size + darkColorCache.size /** * A context whose resources resolve as day or night according to [dark]. diff --git a/app/src/main/res/drawable/floating_keyboard_background.xml b/app/src/main/res/drawable/floating_keyboard_background.xml deleted file mode 100644 index 97cf6ad3..00000000 --- a/app/src/main/res/drawable/floating_keyboard_background.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - diff --git a/app/src/main/res/layout/input_method_view.xml b/app/src/main/res/layout/input_method_view.xml index e5597583..974e4215 100644 --- a/app/src/main/res/layout/input_method_view.xml +++ b/app/src/main/res/layout/input_method_view.xml @@ -837,8 +837,7 @@ GeneralKeyboardIME.kt android:background="?android:attr/selectableItemBackgroundBorderless" android:contentDescription="@string/i18n.app._global.clear_all" android:padding="@dimen/small_margin" - android:src="@drawable/ic_delete_vector" - android:tint="@color/scribe_delete" /> + android:src="@drawable/ic_delete_vector" /> diff --git a/app/src/test/kotlin/be/scri/ui/theme/ScribeColorResolverTest.kt b/app/src/test/kotlin/be/scri/ui/theme/ScribeColorResolverTest.kt index 6b637a93..2061cf95 100644 --- a/app/src/test/kotlin/be/scri/ui/theme/ScribeColorResolverTest.kt +++ b/app/src/test/kotlin/be/scri/ui/theme/ScribeColorResolverTest.kt @@ -53,6 +53,35 @@ class ScribeColorResolverTest { assertEquals(0xFF5EB5E8.toInt() to 0xFF235270.toInt(), onDayDevice.getValue("scribe_background")) } + @Test + fun cachedLookupsReturnTheSameValuesInBothModes() { + val context = context() + val first = context.bothModes(R.color.scribe_key) + assertEquals(2, scribeColorCacheSize()) + // Second read comes from the cache and must keep light and dark apart. + assertEquals(first, context.bothModes(R.color.scribe_key)) + assertEquals(0xFFFFFFFF.toInt() to 0xFF434343.toInt(), first) + assertEquals(2, scribeColorCacheSize()) + } + + @Test + fun aCachedTransparentColorIsNotMistakenForAMiss() { + val context = context() + assertEquals(0, context.scribeColorInt(R.color.transparent, dark = false)) + assertEquals(1, scribeColorCacheSize()) + assertEquals(0, context.scribeColorInt(R.color.transparent, dark = false)) + assertEquals(1, scribeColorCacheSize()) + } + + @Test + fun clearingTheCacheEmptiesBothModes() { + context().bothModes(R.color.scribe_text) + assertEquals(2, scribeColorCacheSize()) + clearScribeColorCache() + assertEquals(0, scribeColorCacheSize()) + assertEquals(0xFF000000.toInt() to 0xFFFFFFFF.toInt(), context().bothModes(R.color.scribe_text)) + } + private fun context(): Context = ApplicationProvider.getApplicationContext() private fun Context.bothModes(id: Int): Pair = scribeColorInt(id, dark = false) to scribeColorInt(id, dark = true) From 32d4207de80cbaba9fafa95e43c0b4f10bf6ddc9 Mon Sep 17 00:00:00 2001 From: Bhanu Nagpure <130910873+bhanu-dev82@users.noreply.github.com> Date: Thu, 26 Nov 2026 17:13:32 +0530 Subject: [PATCH 13/15] Remove resources this PR left unused and test every changed color path (#783) --- .../main/java/be/scri/views/KeyboardView.kt | 4 ++ app/src/main/res/values/colors.xml | 1 - .../helpers/FloatingKeyboardBorderTest.kt | 68 ++++++++++++++++++ .../helpers/ui/KeyboardSharedColorsTest.kt | 72 ++++++++++++++++--- 4 files changed, 135 insertions(+), 10 deletions(-) create mode 100644 app/src/testKeyboards/kotlin/be/scri/helpers/FloatingKeyboardBorderTest.kt diff --git a/app/src/main/java/be/scri/views/KeyboardView.kt b/app/src/main/java/be/scri/views/KeyboardView.kt index 2074fc2f..a50bb98b 100644 --- a/app/src/main/java/be/scri/views/KeyboardView.kt +++ b/app/src/main/java/be/scri/views/KeyboardView.kt @@ -247,6 +247,10 @@ class KeyboardView private var mEnterKeyColor: Int = 0 + /** Current Enter key background, for tests. */ + @get:VisibleForTesting + internal val enterKeyColor: Int get() = mEnterKeyColor + private var mKeyBackground: Drawable? = null private var mToolbarHolder: View? = null diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index 71d31133..e79c6c4b 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -25,7 +25,6 @@ @android:color/transparent #aeb3be - #202020 #2E2E2E #3F3F46 diff --git a/app/src/testKeyboards/kotlin/be/scri/helpers/FloatingKeyboardBorderTest.kt b/app/src/testKeyboards/kotlin/be/scri/helpers/FloatingKeyboardBorderTest.kt new file mode 100644 index 00000000..5b93a3c1 --- /dev/null +++ b/app/src/testKeyboards/kotlin/be/scri/helpers/FloatingKeyboardBorderTest.kt @@ -0,0 +1,68 @@ +// SPDX-License-Identifier: GPL-3.0-or-later + +package be.scri.helpers + +import android.content.Context +import android.graphics.drawable.GradientDrawable +import android.view.LayoutInflater +import androidx.test.core.app.ApplicationProvider +import be.scri.databinding.InputMethodViewBinding +import be.scri.ui.theme.clearScribeColorCache +import io.mockk.every +import io.mockk.mockk +import org.junit.Assert.assertEquals +import org.junit.Before +import org.junit.Test +import org.junit.runner.RunWith +import org.robolectric.RobolectricTestRunner +import org.robolectric.Shadows.shadowOf +import org.robolectric.annotation.Config + +/** + * The floating keyboard border reads `scribe_keyboard_border` (#40888888) in both modes. + */ +@RunWith(RobolectricTestRunner::class) +@Config(sdk = [34]) +class FloatingKeyboardBorderTest { + @Before + fun resetColorCache() = clearScribeColorCache() + + @Test + fun floatingBorderUsesScribeKeyboardBorderInLightMode() { + assertEquals(0x40888888, floatingBorderColor(scribeDark = false)) + } + + @Test + @Config(qualifiers = "night") + fun floatingBorderUsesScribeKeyboardBorderInDarkMode() { + assertEquals(0x40888888, floatingBorderColor(scribeDark = true)) + } + + private fun floatingBorderColor(scribeDark: Boolean): Int { + val context = ApplicationProvider.getApplicationContext() + val deviceNight = context.resources.configuration.isNightModeActive + context + .getSharedPreferences(PreferencesHelper.SCRIBE_PREFS, Context.MODE_PRIVATE) + .edit() + .putBoolean("dark_mode", scribeDark) + .putBoolean("last_system_dark_mode", deviceNight) + .commit() + PreferencesHelper.setIsFloatingModeEnabled(context, LANGUAGE, true) + + val binding = InputMethodViewBinding.inflate(LayoutInflater.from(context)) + val ime = mockk(relaxed = true) + every { ime.imeContext } returns context + every { ime.language } returns LANGUAGE + every { ime.binding } returns binding + every { ime.isUiManagerInitialized } returns true + every { ime.getImeResources() } returns context.resources + every { ime.getImeWindow() } returns null + + FloatingKeyboardHandler(ime).initFloatingMode() + return shadowOf(binding.keyboardCard.background as GradientDrawable).strokeColor + } + + private companion object { + const val LANGUAGE = "English" + } +} diff --git a/app/src/testKeyboards/kotlin/be/scri/helpers/ui/KeyboardSharedColorsTest.kt b/app/src/testKeyboards/kotlin/be/scri/helpers/ui/KeyboardSharedColorsTest.kt index 1f2e8d35..41404b5a 100644 --- a/app/src/testKeyboards/kotlin/be/scri/helpers/ui/KeyboardSharedColorsTest.kt +++ b/app/src/testKeyboards/kotlin/be/scri/helpers/ui/KeyboardSharedColorsTest.kt @@ -20,6 +20,7 @@ import io.mockk.every import io.mockk.mockk import org.junit.Assert.assertEquals import org.junit.Assert.assertNotNull +import org.junit.Assert.assertNull import org.junit.Before import org.junit.Test import org.junit.runner.RunWith @@ -140,6 +141,43 @@ class KeyboardSharedColorsTest { assertEquals(0xFFD11149.toInt(), binding.clipboardClearAll.imageTintList!!.defaultColor) } + @Test + @Config(qualifiers = "night") + fun directConjugationLabelsFollowTheScribeSetting() { + val light = showConjugationGrid(scribeDark = false, deviceNight = true, output = DIRECT_OUTPUT) + assertEquals(0xE558564B.toInt(), light.root.labelColor("1ps")) + val dark = showConjugationGrid(scribeDark = true, deviceNight = true, output = DIRECT_OUTPUT) + assertEquals(0xFFCAC4D0.toInt(), dark.root.labelColor("1ps")) + } + + @Test + fun subSelectionConjugationLabelsFollowTheScribeSetting() { + val dark = showConjugationGrid(scribeDark = true, deviceNight = false, output = SUB_OUTPUT, subCategory = "1ps") + assertEquals(0xFFCAC4D0.toInt(), dark.root.labelColor("sg")) + val light = showConjugationGrid(scribeDark = false, deviceNight = false, output = SUB_OUTPUT, subCategory = "1ps") + assertEquals(0xE558564B.toInt(), light.root.labelColor("sg")) + } + + @Test + fun enterKeyUsesTheSpecialKeyColorForTheScribeSetting() { + val binding = showState(ScribeState.IDLE, scribeDark = false, deviceNight = false) + binding.keyboardView.setEnterKeyColor(null, isDarkMode = true) + assertEquals(0xFF2D2D2D.toInt(), binding.keyboardView.enterKeyColor) + binding.keyboardView.setEnterKeyColor(null, isDarkMode = false) + assertEquals(0xFFADB3BD.toInt(), binding.keyboardView.enterKeyColor) + } + + @Test + fun clearAllHasNoXmlTintAndShowingTheClipboardTintsIt() { + val binding = showState(ScribeState.IDLE, scribeDark = true, deviceNight = false) + // The XML tint followed the device night mode, so the color now only comes from code. + val inflated = InputMethodViewBinding.inflate(LayoutInflater.from(ApplicationProvider.getApplicationContext())) + assertNull(inflated.clipboardClearAll.imageTintList) + + KeyboardUIManager(binding, ApplicationProvider.getApplicationContext(), relaxedListener()).showClipboardPanel() + assertEquals(0xFFD11149.toInt(), binding.clipboardClearAll.imageTintList!!.defaultColor) + } + private fun showState( state: ScribeState, scribeDark: Boolean, @@ -147,6 +185,7 @@ class KeyboardSharedColorsTest { conjugateOutput: Map>>>? = null, conjugateLabels: Set? = null, verb: String? = null, + subCategory: String? = null, ): InputMethodViewBinding { val context = ApplicationProvider.getApplicationContext() context @@ -165,7 +204,7 @@ class KeyboardSharedColorsTest { autoSuggestEmojis = null, conjugateOutput = conjugateOutput, conjugateLabels = conjugateLabels, - selectedConjugationSubCategory = null, + selectedConjugationSubCategory = subCategory, currentVerbForConjugation = verb, ) return binding @@ -183,6 +222,8 @@ class KeyboardSharedColorsTest { private fun showConjugationGrid( scribeDark: Boolean, deviceNight: Boolean, + output: Map>>> = CATEGORY_OUTPUT, + subCategory: String? = null, ): InputMethodViewBinding { val context = ApplicationProvider.getApplicationContext() context @@ -194,19 +235,32 @@ class KeyboardSharedColorsTest { ScribeState.SELECT_VERB_CONJUNCTION, scribeDark = scribeDark, deviceNight = deviceNight, - conjugateOutput = - mapOf( - "Present" to - mapOf( - "1ps" to listOf("1ps" to "I am"), - "2ps" to listOf("2ps" to "You are"), - ), - ), + conjugateOutput = output, conjugateLabels = setOf("1ps", "2ps"), verb = "be", + subCategory = subCategory, ) } + private companion object { + val CATEGORY_OUTPUT = + mapOf( + "Present" to + mapOf( + "1ps" to listOf("1ps" to "I am"), + "2ps" to listOf("2ps" to "You are"), + ), + ) + val DIRECT_OUTPUT = + mapOf( + "Present" to mapOf("Present" to listOf("1ps" to "I am", "2ps" to "You are")), + ) + val SUB_OUTPUT = + mapOf( + "Present" to mapOf("1ps" to listOf("sg" to "I am", "pl" to "we are")), + ) + } + private fun View.backgroundColor(): Int = (background as ColorDrawable).color private fun View.labelColor(label: String): Int { From 3ad5993604c2383a257ae12d65490553cfead5d6 Mon Sep 17 00:00:00 2001 From: Bhanu Nagpure <130910873+bhanu-dev82@users.noreply.github.com> Date: Thu, 26 Nov 2026 17:29:22 +0530 Subject: [PATCH 14/15] Re-run CI (Maven Central 429 in Keyboards instrumentation job) From 47a21e8e753b9f063c54942ded14143f42431b76 Mon Sep 17 00:00:00 2001 From: Bhanu Nagpure <130910873+bhanu-dev82@users.noreply.github.com> Date: Sat, 28 Nov 2026 13:18:01 +0530 Subject: [PATCH 15/15] Color Wikidata info-panel page dots with scribe_text and scribe_caption (#783) --- CHANGELOG.md | 2 +- .../be/scri/helpers/ui/KeyboardUIManager.kt | 13 ++----- app/src/main/res/drawable/dot_active.xml | 2 +- app/src/main/res/drawable/dot_inactive.xml | 5 --- app/src/main/res/layout/input_method_view.xml | 4 +- .../helpers/ui/KeyboardSharedColorsTest.kt | 39 +++++++++++++++++++ 6 files changed, 47 insertions(+), 18 deletions(-) delete mode 100644 app/src/main/res/drawable/dot_inactive.xml diff --git a/CHANGELOG.md b/CHANGELOG.md index 238b1cb2..d3b2c451 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,7 +18,7 @@ Emojis for the following are chosen based on [gitmoji](https://gitmoji.dev/). ### 🎨 Design - Compose theme colors now come from the shared `scribe_*` resources. Dark mode button text stays orange on orange. The dark caption uses the named token `#CAC4D0`, the same grey this slot already used ([#782](https://github.com/scribe-org/Scribe-Android/issues/782)). -- The keyboard reads the shared `scribe_*` colors instead of hex literals. Small intentional changes: the light invalid and already-plural bar matches the keyboard background, dark letter keys use `scribe_key`, suggestions match the key labels, Enter, delete, shift and the mode key use the Figma special-key colors, and the clipboard clear-all icon uses the new `scribe_delete` red ([#783](https://github.com/scribe-org/Scribe-Android/issues/783)). +- The keyboard reads the shared `scribe_*` colors instead of hex literals. Small intentional changes: the light invalid and already-plural bar matches the keyboard background, dark letter keys use `scribe_key`, suggestions match the key labels, Enter, delete, shift and the mode key use the Figma special-key colors, and the clipboard clear-all icon uses the new `scribe_delete` red, and the Wikidata info-panel page dots use the key text color when active and `scribe_caption` when not ([#783](https://github.com/scribe-org/Scribe-Android/issues/783)). ### 🔒 Security diff --git a/app/src/keyboards/java/be/scri/helpers/ui/KeyboardUIManager.kt b/app/src/keyboards/java/be/scri/helpers/ui/KeyboardUIManager.kt index cca5065e..c5a17611 100644 --- a/app/src/keyboards/java/be/scri/helpers/ui/KeyboardUIManager.kt +++ b/app/src/keyboards/java/be/scri/helpers/ui/KeyboardUIManager.kt @@ -1435,16 +1435,11 @@ class KeyboardUIManager( private fun updateDotIndicators() { val pageIndicators = binding.pageIndicators val isDarkMode = getIsDarkModeOrNot(context) + val activeColor = context.scribeColorInt(R.color.scribe_text, dark = isDarkMode) + val inactiveColor = context.scribeColorInt(R.color.scribe_caption, dark = isDarkMode) for (i in 0 until pageIndicators.childCount) { - val dot = pageIndicators.getChildAt(i) - val drawableRes = if (i == currentPage) R.drawable.dot_active else R.drawable.dot_inactive - val drawable = ContextCompat.getDrawable(context, drawableRes)?.mutate() - if (isDarkMode) { - drawable?.setTint(if (i == currentPage) Color.WHITE else 0x66FFFFFF.toInt()) - } else { - drawable?.setTint(if (i == currentPage) Color.BLACK else 0xFFCCCCCC.toInt()) - } - dot.background = drawable + val color = if (i == currentPage) activeColor else inactiveColor + pageIndicators.getChildAt(i).backgroundTintList = ColorStateList.valueOf(color) } } diff --git a/app/src/main/res/drawable/dot_active.xml b/app/src/main/res/drawable/dot_active.xml index 87bf83ef..3cd90b3b 100644 --- a/app/src/main/res/drawable/dot_active.xml +++ b/app/src/main/res/drawable/dot_active.xml @@ -1,5 +1,5 @@ - + diff --git a/app/src/main/res/drawable/dot_inactive.xml b/app/src/main/res/drawable/dot_inactive.xml deleted file mode 100644 index 169edfd7..00000000 --- a/app/src/main/res/drawable/dot_inactive.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - diff --git a/app/src/main/res/layout/input_method_view.xml b/app/src/main/res/layout/input_method_view.xml index 974e4215..c9f3254c 100644 --- a/app/src/main/res/layout/input_method_view.xml +++ b/app/src/main/res/layout/input_method_view.xml @@ -671,13 +671,13 @@ GeneralKeyboardIME.kt android:layout_width="6dp" android:layout_height="6dp" android:layout_margin="4dp" - android:background="@drawable/dot_inactive" /> + android:background="@drawable/dot_active" /> + android:background="@drawable/dot_active" /> diff --git a/app/src/testKeyboards/kotlin/be/scri/helpers/ui/KeyboardSharedColorsTest.kt b/app/src/testKeyboards/kotlin/be/scri/helpers/ui/KeyboardSharedColorsTest.kt index 41404b5a..0fe6f53e 100644 --- a/app/src/testKeyboards/kotlin/be/scri/helpers/ui/KeyboardSharedColorsTest.kt +++ b/app/src/testKeyboards/kotlin/be/scri/helpers/ui/KeyboardSharedColorsTest.kt @@ -178,6 +178,45 @@ class KeyboardSharedColorsTest { assertEquals(0xFFD11149.toInt(), binding.clipboardClearAll.imageTintList!!.defaultColor) } + @Test + @Config(qualifiers = "night") + fun pageDotsUseTextAndCaptionWhenScribeIsLightOnANightDevice() { + val binding = showInvalidInfoPanel(scribeDark = false, deviceNight = true) + binding.assertDotColors(active = 0xFF000000.toInt(), inactive = 0xE558564B.toInt(), currentPage = 0) + binding.buttonRight.performClick() + binding.assertDotColors(active = 0xFF000000.toInt(), inactive = 0xE558564B.toInt(), currentPage = 1) + } + + @Test + fun pageDotsUseTextAndCaptionWhenScribeIsDarkOnADayDevice() { + val binding = showInvalidInfoPanel(scribeDark = true, deviceNight = false) + binding.assertDotColors(active = 0xFFFFFFFF.toInt(), inactive = 0xFFCAC4D0.toInt(), currentPage = 0) + binding.buttonRight.performClick() + binding.assertDotColors(active = 0xFFFFFFFF.toInt(), inactive = 0xFFCAC4D0.toInt(), currentPage = 1) + } + + private fun showInvalidInfoPanel( + scribeDark: Boolean, + deviceNight: Boolean, + ): InputMethodViewBinding { + val binding = showState(ScribeState.INVALID, scribeDark = scribeDark, deviceNight = deviceNight) + binding.ivInfo.performClick() + return binding + } + + private fun InputMethodViewBinding.assertDotColors( + active: Int, + inactive: Int, + currentPage: Int, + ) { + assertEquals(3, pageIndicators.childCount) + for (i in 0 until pageIndicators.childCount) { + val expected = if (i == currentPage) active else inactive + val actual = pageIndicators.getChildAt(i).backgroundTintList!!.defaultColor + assertEquals("dot $i on page $currentPage", expected, actual) + } + } + private fun showState( state: ScribeState, scribeDark: Boolean,