From cc7f1bfbf5368e9e8ec6fc3c94a82b22c849634a Mon Sep 17 00:00:00 2001 From: angrezichatterbox Date: Fri, 20 Sep 2024 16:52:25 +0530 Subject: [PATCH] fix:Corrected the keyboard color and keys colors based on condtions --- .../be/scri/services/EnglishKeyboardIME.kt | 63 ++++++++++++++++--- .../be/scri/services/FrenchKeyboardIME.kt | 50 ++++++++++++++- .../be/scri/services/GermanKeyboardIME.kt | 50 ++++++++++++++- .../be/scri/services/ItalianKeyboardIME.kt | 50 ++++++++++++++- .../be/scri/services/PortugueseKeyboardIME.kt | 50 ++++++++++++++- .../be/scri/services/RussianKeyboardIME.kt | 50 ++++++++++++++- .../be/scri/services/SimpleKeyboardIME.kt | 35 +++++++++-- .../be/scri/services/SpanishKeyboardIME.kt | 50 ++++++++++++++- .../be/scri/services/SwedishKeyboardIME.kt | 50 ++++++++++++++- .../main/java/be/scri/views/MyKeyboardView.kt | 45 ++++++++++--- .../layout/keyboard_view_command_options.xml | 4 +- app/src/main/res/values-night-v31/colors.xml | 9 +-- app/src/main/res/values/colors.xml | 4 ++ 13 files changed, 461 insertions(+), 49 deletions(-) diff --git a/app/src/main/java/be/scri/services/EnglishKeyboardIME.kt b/app/src/main/java/be/scri/services/EnglishKeyboardIME.kt index c28c7c33..f49059a4 100644 --- a/app/src/main/java/be/scri/services/EnglishKeyboardIME.kt +++ b/app/src/main/java/be/scri/services/EnglishKeyboardIME.kt @@ -1,14 +1,17 @@ package be.scri.services import android.content.Context +import android.graphics.Color import android.text.InputType import android.util.Log import android.view.View +import android.view.inputmethod.EditorInfo import android.view.inputmethod.EditorInfo.IME_ACTION_NONE import be.scri.R import be.scri.databinding.KeyboardViewCommandOptionsBinding import be.scri.databinding.KeyboardViewKeyboardBinding import be.scri.helpers.MyKeyboard +import be.scri.helpers.MyKeyboard.Companion.KEYCODE_ENTER import be.scri.views.MyKeyboardView class EnglishKeyboardIME : SimpleKeyboardIME() { @@ -45,16 +48,19 @@ class EnglishKeyboardIME : SimpleKeyboardIME() { private var currentState: ScribeState = ScribeState.IDLE private lateinit var keyboardBinding: KeyboardViewKeyboardBinding - override fun onInitializeInterface() { - super.onInitializeInterface() - keyboard = MyKeyboard(this, getKeyboardLayoutXML(), enterKeyType) - } - private fun shouldCommitPeriodAfterSpace(language: String): Boolean { val sharedPref = getSharedPreferences("app_preferences", Context.MODE_PRIVATE) return sharedPref.getBoolean("period_on_double_tap_$language", false) } + override fun onStartInputView( + editorInfo: EditorInfo?, + restarting: Boolean, + ) { + super.onStartInputView(editorInfo, restarting) + setupCommandBarTheme(binding) + } + override fun commitPeriodAfterSpace() { if (shouldCommitPeriodAfterSpace("English")) { val inputConnection = currentInputConnection ?: return @@ -65,10 +71,15 @@ class EnglishKeyboardIME : SimpleKeyboardIME() { override fun onCreateInputView(): View { binding = KeyboardViewCommandOptionsBinding.inflate(layoutInflater) + setupCommandBarTheme(binding) val keyboardHolder = binding.root - Log.i("MY-TAG", "From English Keyboard IME") keyboardView = binding.keyboardView keyboardView!!.setKeyboard(keyboard!!) + when (currentState) { + ScribeState.IDLE -> keyboardView!!.setEnterKeyColor(0) + else -> keyboardView!!.setEnterKeyColor(R.color.dark_scribe_blue) + } + keyboardView!!.setKeyboardHolder(binding.keyboardHolder) keyboardView?.mOnKeyboardActionListener = this updateUI() @@ -76,9 +87,22 @@ class EnglishKeyboardIME : SimpleKeyboardIME() { } private fun setupIdleView() { - binding.translateBtn.setBackgroundColor(getColor(R.color.you_keyboard_background_color)) - binding.conjugateBtn.setBackgroundColor(getColor(R.color.you_keyboard_background_color)) - binding.pluralBtn.setBackgroundColor(getColor(R.color.you_keyboard_background_color)) + val sharedPref = getSharedPreferences("app_preferences", Context.MODE_PRIVATE) + val isUserDarkMode = sharedPref.getBoolean("dark_mode", true) + when (isUserDarkMode) { + true -> { + binding.translateBtn.setBackgroundColor(getColor(R.color.transparent)) + binding.conjugateBtn.setBackgroundColor(getColor(R.color.transparent)) + binding.pluralBtn.setBackgroundColor(getColor(R.color.transparent)) + } + else -> { + binding.translateBtn.setBackgroundColor(getColor(R.color.transparent)) + binding.conjugateBtn.setBackgroundColor(getColor(R.color.transparent)) + binding.pluralBtn.setBackgroundColor(getColor(R.color.transparent)) + } + } + + setupCommandBarTheme(binding) binding.translateBtn.text = "" binding.conjugateBtn.text = "" binding.pluralBtn.text = "" @@ -97,10 +121,12 @@ class EnglishKeyboardIME : SimpleKeyboardIME() { binding.translateBtn.text = "Translate" binding.conjugateBtn.text = "Conjugate" binding.pluralBtn.text = "Plural" + super.setupCommandBarTheme(binding) binding.scribeKey.setOnClickListener { currentState = ScribeState.IDLE Log.i("MY-TAG", "IDLE STATE") binding.scribeKey.foreground = getDrawable(R.drawable.ic_scribe_icon_vector) + updateUI() } binding.translateBtn.setOnClickListener { @@ -120,6 +146,14 @@ class EnglishKeyboardIME : SimpleKeyboardIME() { } } + private fun updateEnterKeyColor() { + when (currentState) { + ScribeState.IDLE -> keyboardView?.setEnterKeyColor(Color.TRANSPARENT) + ScribeState.SELECT_COMMAND -> keyboardView?.setEnterKeyColor(Color.TRANSPARENT) + else -> keyboardView?.setEnterKeyColor(getColor(R.color.dark_scribe_blue)) + } + } + override fun onKey(code: Int) { val inputConnection = currentInputConnection if (keyboard == null || inputConnection == null) { @@ -159,6 +193,7 @@ class EnglishKeyboardIME : SimpleKeyboardIME() { val keyboardBinding = KeyboardViewKeyboardBinding.inflate(layoutInflater) this.keyboardBinding = keyboardBinding val keyboardHolder = keyboardBinding.root + super.setupToolBarTheme(keyboardBinding) keyboardView = keyboardBinding.keyboardView keyboardView!!.setKeyboard(keyboard!!) keyboardView!!.mOnKeyboardActionListener = this @@ -167,6 +202,7 @@ class EnglishKeyboardIME : SimpleKeyboardIME() { switchToCommandToolBar() updateUI() } + setInputView(keyboardHolder) } @@ -174,6 +210,7 @@ class EnglishKeyboardIME : SimpleKeyboardIME() { val binding = KeyboardViewCommandOptionsBinding.inflate(layoutInflater) this.binding = binding val keyboardHolder = binding.root + setupCommandBarTheme(binding) keyboardView = binding.keyboardView keyboardView!!.setKeyboard(keyboard!!) keyboardView!!.mOnKeyboardActionListener = this @@ -185,11 +222,19 @@ class EnglishKeyboardIME : SimpleKeyboardIME() { setInputView(keyboardHolder) } + override fun onCreate() { + super.onCreate() + keyboard = MyKeyboard(this, getKeyboardLayoutXML(), enterKeyType) + onCreateInputView() + setupCommandBarTheme(binding) + } + private fun updateUI() { when (currentState) { ScribeState.IDLE -> setupIdleView() ScribeState.SELECT_COMMAND -> setupSelectCommandView() else -> switchToToolBar() } + updateEnterKeyColor() } } diff --git a/app/src/main/java/be/scri/services/FrenchKeyboardIME.kt b/app/src/main/java/be/scri/services/FrenchKeyboardIME.kt index 256a613c..1318372e 100644 --- a/app/src/main/java/be/scri/services/FrenchKeyboardIME.kt +++ b/app/src/main/java/be/scri/services/FrenchKeyboardIME.kt @@ -1,14 +1,17 @@ package be.scri.services import android.content.Context +import android.graphics.Color import android.text.InputType import android.util.Log import android.view.View +import android.view.inputmethod.EditorInfo import android.view.inputmethod.EditorInfo.IME_ACTION_NONE import be.scri.R import be.scri.databinding.KeyboardViewCommandOptionsBinding import be.scri.databinding.KeyboardViewKeyboardBinding import be.scri.helpers.MyKeyboard +import be.scri.services.EnglishKeyboardIME.ScribeState import be.scri.views.MyKeyboardView class FrenchKeyboardIME : SimpleKeyboardIME() { @@ -61,6 +64,14 @@ class FrenchKeyboardIME : SimpleKeyboardIME() { } } + override fun onStartInputView( + editorInfo: EditorInfo?, + restarting: Boolean, + ) { + super.onStartInputView(editorInfo, restarting) + setupCommandBarTheme(binding) + } + override fun onKey(code: Int) { val inputConnection = currentInputConnection if (keyboard == null || inputConnection == null) { @@ -102,6 +113,7 @@ class FrenchKeyboardIME : SimpleKeyboardIME() { Log.i("MY-TAG", "From French Keyboard IME") keyboardView = binding.keyboardView keyboardView!!.setKeyboard(keyboard!!) + setupCommandBarTheme(binding) keyboardView!!.setKeyboardHolder(binding.keyboardHolder) keyboardView!!.mOnKeyboardActionListener = this updateUI() @@ -109,9 +121,22 @@ class FrenchKeyboardIME : SimpleKeyboardIME() { } private fun setupIdleView() { - binding.translateBtn.setBackgroundColor(getColor(R.color.you_keyboard_background_color)) - binding.conjugateBtn.setBackgroundColor(getColor(R.color.you_keyboard_background_color)) - binding.pluralBtn.setBackgroundColor(getColor(R.color.you_keyboard_background_color)) + val sharedPref = getSharedPreferences("app_preferences", Context.MODE_PRIVATE) + val isUserDarkMode = sharedPref.getBoolean("dark_mode", true) + when (isUserDarkMode) { + true -> { + binding.translateBtn.setBackgroundColor(getColor(R.color.transparent)) + binding.conjugateBtn.setBackgroundColor(getColor(R.color.transparent)) + binding.pluralBtn.setBackgroundColor(getColor(R.color.transparent)) + } + else -> { + binding.translateBtn.setBackgroundColor(getColor(R.color.transparent)) + binding.conjugateBtn.setBackgroundColor(getColor(R.color.transparent)) + binding.pluralBtn.setBackgroundColor(getColor(R.color.transparent)) + } + } + + setupCommandBarTheme(binding) binding.translateBtn.text = "" binding.conjugateBtn.text = "" binding.pluralBtn.text = "" @@ -127,6 +152,7 @@ class FrenchKeyboardIME : SimpleKeyboardIME() { binding.translateBtn.setBackgroundDrawable(getDrawable(R.drawable.button_background_rounded)) binding.conjugateBtn.setBackgroundDrawable(getDrawable(R.drawable.button_background_rounded)) binding.pluralBtn.setBackgroundDrawable(getDrawable(R.drawable.button_background_rounded)) + setupCommandBarTheme(binding) binding.translateBtn.text = "Translate" binding.conjugateBtn.text = "Conjugate" binding.pluralBtn.text = "Plural" @@ -159,6 +185,7 @@ class FrenchKeyboardIME : SimpleKeyboardIME() { val keyboardHolder = keyboardBinding.root keyboardView = keyboardBinding.keyboardView keyboardView!!.setKeyboard(keyboard!!) + super.setupToolBarTheme(keyboardBinding) keyboardView!!.mOnKeyboardActionListener = this keyboardBinding.scribeKey.setOnClickListener { currentState = ScribeState.IDLE @@ -172,6 +199,7 @@ class FrenchKeyboardIME : SimpleKeyboardIME() { val binding = KeyboardViewCommandOptionsBinding.inflate(layoutInflater) this.binding = binding val keyboardHolder = binding.root + setupCommandBarTheme(binding) keyboardView = binding.keyboardView keyboardView!!.setKeyboard(keyboard!!) keyboardView!!.mOnKeyboardActionListener = this @@ -183,11 +211,27 @@ class FrenchKeyboardIME : SimpleKeyboardIME() { setInputView(keyboardHolder) } + private fun updateEnterKeyColor() { + when (currentState) { + ScribeState.IDLE -> keyboardView?.setEnterKeyColor(Color.TRANSPARENT) + ScribeState.SELECT_COMMAND -> keyboardView?.setEnterKeyColor(Color.TRANSPARENT) + else -> keyboardView?.setEnterKeyColor(getColor(R.color.dark_scribe_blue)) + } + } + + override fun onCreate() { + super.onCreate() + keyboard = MyKeyboard(this, getKeyboardLayoutXML(), enterKeyType) + onCreateInputView() + setupCommandBarTheme(binding) + } + private fun updateUI() { when (currentState) { ScribeState.IDLE -> setupIdleView() ScribeState.SELECT_COMMAND -> setupSelectCommandView() else -> switchToToolBar() } + updateEnterKeyColor() } } diff --git a/app/src/main/java/be/scri/services/GermanKeyboardIME.kt b/app/src/main/java/be/scri/services/GermanKeyboardIME.kt index b69e3ec6..811cece7 100644 --- a/app/src/main/java/be/scri/services/GermanKeyboardIME.kt +++ b/app/src/main/java/be/scri/services/GermanKeyboardIME.kt @@ -1,14 +1,17 @@ package be.scri.services import android.content.Context +import android.graphics.Color import android.text.InputType import android.util.Log import android.view.View +import android.view.inputmethod.EditorInfo import android.view.inputmethod.EditorInfo.IME_ACTION_NONE import be.scri.R import be.scri.databinding.KeyboardViewCommandOptionsBinding import be.scri.databinding.KeyboardViewKeyboardBinding import be.scri.helpers.MyKeyboard +import be.scri.services.EnglishKeyboardIME.ScribeState import be.scri.views.MyKeyboardView class GermanKeyboardIME : SimpleKeyboardIME() { @@ -48,6 +51,14 @@ class GermanKeyboardIME : SimpleKeyboardIME() { keyboard = MyKeyboard(this, getKeyboardLayoutXML(), enterKeyType) } + override fun onStartInputView( + editorInfo: EditorInfo?, + restarting: Boolean, + ) { + super.onStartInputView(editorInfo, restarting) + setupCommandBarTheme(binding) + } + private fun shouldCommitPeriodAfterSpace(language: String): Boolean { val sharedPref = getSharedPreferences("app_preferences", Context.MODE_PRIVATE) return sharedPref.getBoolean("period_on_double_tap_$language", false) @@ -67,6 +78,7 @@ class GermanKeyboardIME : SimpleKeyboardIME() { Log.i("MY-TAG", "From German Keyboard IME") keyboardView = binding.keyboardView keyboardView!!.setKeyboard(keyboard!!) + setupCommandBarTheme(binding) keyboardView!!.setKeyboardHolder(binding.keyboardHolder) keyboardView!!.mOnKeyboardActionListener = this updateUI() @@ -74,9 +86,22 @@ class GermanKeyboardIME : SimpleKeyboardIME() { } private fun setupIdleView() { - binding.translateBtn.setBackgroundColor(getColor(R.color.you_keyboard_background_color)) - binding.conjugateBtn.setBackgroundColor(getColor(R.color.you_keyboard_background_color)) - binding.pluralBtn.setBackgroundColor(getColor(R.color.you_keyboard_background_color)) + val sharedPref = getSharedPreferences("app_preferences", Context.MODE_PRIVATE) + val isUserDarkMode = sharedPref.getBoolean("dark_mode", true) + when (isUserDarkMode) { + true -> { + binding.translateBtn.setBackgroundColor(getColor(R.color.transparent)) + binding.conjugateBtn.setBackgroundColor(getColor(R.color.transparent)) + binding.pluralBtn.setBackgroundColor(getColor(R.color.transparent)) + } + else -> { + binding.translateBtn.setBackgroundColor(getColor(R.color.transparent)) + binding.conjugateBtn.setBackgroundColor(getColor(R.color.transparent)) + binding.pluralBtn.setBackgroundColor(getColor(R.color.transparent)) + } + } + + setupCommandBarTheme(binding) binding.translateBtn.text = "" binding.conjugateBtn.text = "" binding.pluralBtn.text = "" @@ -127,6 +152,7 @@ class GermanKeyboardIME : SimpleKeyboardIME() { binding.translateBtn.setBackgroundDrawable(getDrawable(R.drawable.button_background_rounded)) binding.conjugateBtn.setBackgroundDrawable(getDrawable(R.drawable.button_background_rounded)) binding.pluralBtn.setBackgroundDrawable(getDrawable(R.drawable.button_background_rounded)) + setupCommandBarTheme(binding) binding.translateBtn.text = "Translate" binding.conjugateBtn.text = "Conjugate" binding.pluralBtn.text = "Plural" @@ -159,6 +185,7 @@ class GermanKeyboardIME : SimpleKeyboardIME() { val keyboardHolder = keyboardBinding.root keyboardView = keyboardBinding.keyboardView keyboardView!!.setKeyboard(keyboard!!) + super.setupToolBarTheme(keyboardBinding) keyboardView!!.mOnKeyboardActionListener = this keyboardBinding.scribeKey.setOnClickListener { currentState = ScribeState.IDLE @@ -172,6 +199,7 @@ class GermanKeyboardIME : SimpleKeyboardIME() { val binding = KeyboardViewCommandOptionsBinding.inflate(layoutInflater) this.binding = binding val keyboardHolder = binding.root + setupCommandBarTheme(binding) keyboardView = binding.keyboardView keyboardView!!.setKeyboard(keyboard!!) keyboardView!!.mOnKeyboardActionListener = this @@ -183,11 +211,27 @@ class GermanKeyboardIME : SimpleKeyboardIME() { setInputView(keyboardHolder) } + private fun updateEnterKeyColor() { + when (currentState) { + ScribeState.IDLE -> keyboardView?.setEnterKeyColor(Color.TRANSPARENT) + ScribeState.SELECT_COMMAND -> keyboardView?.setEnterKeyColor(Color.TRANSPARENT) + else -> keyboardView?.setEnterKeyColor(getColor(R.color.dark_scribe_blue)) + } + } + + override fun onCreate() { + super.onCreate() + keyboard = MyKeyboard(this, getKeyboardLayoutXML(), enterKeyType) + onCreateInputView() + setupCommandBarTheme(binding) + } + private fun updateUI() { when (currentState) { ScribeState.IDLE -> setupIdleView() ScribeState.SELECT_COMMAND -> setupSelectCommandView() else -> switchToToolBar() } + updateEnterKeyColor() } } diff --git a/app/src/main/java/be/scri/services/ItalianKeyboardIME.kt b/app/src/main/java/be/scri/services/ItalianKeyboardIME.kt index 2a2a2fe5..9a7df11d 100644 --- a/app/src/main/java/be/scri/services/ItalianKeyboardIME.kt +++ b/app/src/main/java/be/scri/services/ItalianKeyboardIME.kt @@ -1,14 +1,17 @@ package be.scri.services import android.content.Context +import android.graphics.Color import android.text.InputType import android.util.Log import android.view.View +import android.view.inputmethod.EditorInfo import android.view.inputmethod.EditorInfo.IME_ACTION_NONE import be.scri.R import be.scri.databinding.KeyboardViewCommandOptionsBinding import be.scri.databinding.KeyboardViewKeyboardBinding import be.scri.helpers.MyKeyboard +import be.scri.services.EnglishKeyboardIME.ScribeState import be.scri.views.MyKeyboardView class ItalianKeyboardIME : SimpleKeyboardIME() { @@ -48,6 +51,14 @@ class ItalianKeyboardIME : SimpleKeyboardIME() { keyboard = MyKeyboard(this, getKeyboardLayoutXML(), enterKeyType) } + override fun onStartInputView( + editorInfo: EditorInfo?, + restarting: Boolean, + ) { + super.onStartInputView(editorInfo, restarting) + setupCommandBarTheme(binding) + } + private fun shouldCommitPeriodAfterSpace(language: String): Boolean { val sharedPref = getSharedPreferences("app_preferences", Context.MODE_PRIVATE) return sharedPref.getBoolean("period_on_double_tap_$language", false) @@ -68,15 +79,29 @@ class ItalianKeyboardIME : SimpleKeyboardIME() { keyboardView = binding.keyboardView keyboardView!!.setKeyboard(keyboard!!) keyboardView!!.setKeyboardHolder(binding.keyboardHolder) + setupCommandBarTheme(binding) keyboardView!!.mOnKeyboardActionListener = this updateUI() return keyboardHolder } private fun setupIdleView() { - binding.translateBtn.setBackgroundColor(getColor(R.color.you_keyboard_background_color)) - binding.conjugateBtn.setBackgroundColor(getColor(R.color.you_keyboard_background_color)) - binding.pluralBtn.setBackgroundColor(getColor(R.color.you_keyboard_background_color)) + val sharedPref = getSharedPreferences("app_preferences", Context.MODE_PRIVATE) + val isUserDarkMode = sharedPref.getBoolean("dark_mode", true) + when (isUserDarkMode) { + true -> { + binding.translateBtn.setBackgroundColor(getColor(R.color.transparent)) + binding.conjugateBtn.setBackgroundColor(getColor(R.color.transparent)) + binding.pluralBtn.setBackgroundColor(getColor(R.color.transparent)) + } + else -> { + binding.translateBtn.setBackgroundColor(getColor(R.color.transparent)) + binding.conjugateBtn.setBackgroundColor(getColor(R.color.transparent)) + binding.pluralBtn.setBackgroundColor(getColor(R.color.transparent)) + } + } + + setupCommandBarTheme(binding) binding.translateBtn.text = "" binding.conjugateBtn.text = "" binding.pluralBtn.text = "" @@ -127,6 +152,7 @@ class ItalianKeyboardIME : SimpleKeyboardIME() { binding.translateBtn.setBackgroundDrawable(getDrawable(R.drawable.button_background_rounded)) binding.conjugateBtn.setBackgroundDrawable(getDrawable(R.drawable.button_background_rounded)) binding.pluralBtn.setBackgroundDrawable(getDrawable(R.drawable.button_background_rounded)) + setupCommandBarTheme(binding) binding.translateBtn.text = "Translate" binding.conjugateBtn.text = "Conjugate" binding.pluralBtn.text = "Plural" @@ -159,6 +185,7 @@ class ItalianKeyboardIME : SimpleKeyboardIME() { val keyboardHolder = keyboardBinding.root keyboardView = keyboardBinding.keyboardView keyboardView!!.setKeyboard(keyboard!!) + super.setupToolBarTheme(keyboardBinding) keyboardView!!.mOnKeyboardActionListener = this keyboardBinding.scribeKey.setOnClickListener { currentState = ScribeState.IDLE @@ -172,6 +199,7 @@ class ItalianKeyboardIME : SimpleKeyboardIME() { val binding = KeyboardViewCommandOptionsBinding.inflate(layoutInflater) this.binding = binding val keyboardHolder = binding.root + setupCommandBarTheme(binding) keyboardView = binding.keyboardView keyboardView!!.setKeyboard(keyboard!!) keyboardView!!.mOnKeyboardActionListener = this @@ -183,11 +211,27 @@ class ItalianKeyboardIME : SimpleKeyboardIME() { setInputView(keyboardHolder) } + private fun updateEnterKeyColor() { + when (currentState) { + ScribeState.IDLE -> keyboardView?.setEnterKeyColor(Color.TRANSPARENT) + ScribeState.SELECT_COMMAND -> keyboardView?.setEnterKeyColor(Color.TRANSPARENT) + else -> keyboardView?.setEnterKeyColor(getColor(R.color.dark_scribe_blue)) + } + } + + override fun onCreate() { + super.onCreate() + keyboard = MyKeyboard(this, getKeyboardLayoutXML(), enterKeyType) + onCreateInputView() + setupCommandBarTheme(binding) + } + private fun updateUI() { when (currentState) { ScribeState.IDLE -> setupIdleView() ScribeState.SELECT_COMMAND -> setupSelectCommandView() else -> switchToToolBar() } + updateEnterKeyColor() } } diff --git a/app/src/main/java/be/scri/services/PortugueseKeyboardIME.kt b/app/src/main/java/be/scri/services/PortugueseKeyboardIME.kt index 9221b551..bcebce12 100644 --- a/app/src/main/java/be/scri/services/PortugueseKeyboardIME.kt +++ b/app/src/main/java/be/scri/services/PortugueseKeyboardIME.kt @@ -1,14 +1,17 @@ package be.scri.services import android.content.Context +import android.graphics.Color import android.text.InputType import android.util.Log import android.view.View +import android.view.inputmethod.EditorInfo import android.view.inputmethod.EditorInfo.IME_ACTION_NONE import be.scri.R import be.scri.databinding.KeyboardViewCommandOptionsBinding import be.scri.databinding.KeyboardViewKeyboardBinding import be.scri.helpers.MyKeyboard +import be.scri.services.EnglishKeyboardIME.ScribeState import be.scri.views.MyKeyboardView class PortugueseKeyboardIME : SimpleKeyboardIME() { @@ -53,6 +56,14 @@ class PortugueseKeyboardIME : SimpleKeyboardIME() { return sharedPref.getBoolean("period_on_double_tap_$language", false) } + override fun onStartInputView( + editorInfo: EditorInfo?, + restarting: Boolean, + ) { + super.onStartInputView(editorInfo, restarting) + setupCommandBarTheme(binding) + } + override fun commitPeriodAfterSpace() { if (shouldCommitPeriodAfterSpace("Portuguese")) { val inputConnection = currentInputConnection ?: return @@ -67,6 +78,7 @@ class PortugueseKeyboardIME : SimpleKeyboardIME() { Log.i("MY-TAG", "From Portuguese Keyboard IME") keyboardView = binding.keyboardView keyboardView!!.setKeyboard(keyboard!!) + setupCommandBarTheme(binding) keyboardView!!.setKeyboardHolder(binding.keyboardHolder) keyboardView!!.mOnKeyboardActionListener = this updateUI() @@ -74,9 +86,22 @@ class PortugueseKeyboardIME : SimpleKeyboardIME() { } private fun setupIdleView() { - binding.translateBtn.setBackgroundColor(getColor(R.color.you_keyboard_background_color)) - binding.conjugateBtn.setBackgroundColor(getColor(R.color.you_keyboard_background_color)) - binding.pluralBtn.setBackgroundColor(getColor(R.color.you_keyboard_background_color)) + val sharedPref = getSharedPreferences("app_preferences", Context.MODE_PRIVATE) + val isUserDarkMode = sharedPref.getBoolean("dark_mode", true) + when (isUserDarkMode) { + true -> { + binding.translateBtn.setBackgroundColor(getColor(R.color.transparent)) + binding.conjugateBtn.setBackgroundColor(getColor(R.color.transparent)) + binding.pluralBtn.setBackgroundColor(getColor(R.color.transparent)) + } + else -> { + binding.translateBtn.setBackgroundColor(getColor(R.color.transparent)) + binding.conjugateBtn.setBackgroundColor(getColor(R.color.transparent)) + binding.pluralBtn.setBackgroundColor(getColor(R.color.transparent)) + } + } + + setupCommandBarTheme(binding) binding.translateBtn.text = "" binding.conjugateBtn.text = "" binding.pluralBtn.text = "" @@ -92,6 +117,7 @@ class PortugueseKeyboardIME : SimpleKeyboardIME() { binding.translateBtn.setBackgroundDrawable(getDrawable(R.drawable.button_background_rounded)) binding.conjugateBtn.setBackgroundDrawable(getDrawable(R.drawable.button_background_rounded)) binding.pluralBtn.setBackgroundDrawable(getDrawable(R.drawable.button_background_rounded)) + setupCommandBarTheme(binding) binding.translateBtn.text = "Translate" binding.conjugateBtn.text = "Conjugate" binding.pluralBtn.text = "Plural" @@ -159,6 +185,7 @@ class PortugueseKeyboardIME : SimpleKeyboardIME() { val keyboardHolder = keyboardBinding.root keyboardView = keyboardBinding.keyboardView keyboardView!!.setKeyboard(keyboard!!) + super.setupToolBarTheme(keyboardBinding) keyboardView!!.mOnKeyboardActionListener = this keyboardBinding.scribeKey.setOnClickListener { currentState = ScribeState.IDLE @@ -172,6 +199,7 @@ class PortugueseKeyboardIME : SimpleKeyboardIME() { val binding = KeyboardViewCommandOptionsBinding.inflate(layoutInflater) this.binding = binding val keyboardHolder = binding.root + setupCommandBarTheme(binding) keyboardView = binding.keyboardView keyboardView!!.setKeyboard(keyboard!!) keyboardView!!.mOnKeyboardActionListener = this @@ -183,11 +211,27 @@ class PortugueseKeyboardIME : SimpleKeyboardIME() { setInputView(keyboardHolder) } + private fun updateEnterKeyColor() { + when (currentState) { + ScribeState.IDLE -> keyboardView?.setEnterKeyColor(Color.TRANSPARENT) + ScribeState.SELECT_COMMAND -> keyboardView?.setEnterKeyColor(Color.TRANSPARENT) + else -> keyboardView?.setEnterKeyColor(getColor(R.color.dark_scribe_blue)) + } + } + + override fun onCreate() { + super.onCreate() + keyboard = MyKeyboard(this, getKeyboardLayoutXML(), enterKeyType) + onCreateInputView() + setupCommandBarTheme(binding) + } + private fun updateUI() { when (currentState) { ScribeState.IDLE -> setupIdleView() ScribeState.SELECT_COMMAND -> setupSelectCommandView() else -> switchToToolBar() } + updateEnterKeyColor() } } diff --git a/app/src/main/java/be/scri/services/RussianKeyboardIME.kt b/app/src/main/java/be/scri/services/RussianKeyboardIME.kt index dce13da1..d439f4e6 100644 --- a/app/src/main/java/be/scri/services/RussianKeyboardIME.kt +++ b/app/src/main/java/be/scri/services/RussianKeyboardIME.kt @@ -1,14 +1,17 @@ package be.scri.services import android.content.Context +import android.graphics.Color import android.text.InputType import android.util.Log import android.view.View +import android.view.inputmethod.EditorInfo import android.view.inputmethod.EditorInfo.IME_ACTION_NONE import be.scri.R import be.scri.databinding.KeyboardViewCommandOptionsBinding import be.scri.databinding.KeyboardViewKeyboardBinding import be.scri.helpers.MyKeyboard +import be.scri.services.EnglishKeyboardIME.ScribeState import be.scri.views.MyKeyboardView class RussianKeyboardIME : SimpleKeyboardIME() { @@ -48,6 +51,14 @@ class RussianKeyboardIME : SimpleKeyboardIME() { keyboard = MyKeyboard(this, getKeyboardLayoutXML(), enterKeyType) } + override fun onStartInputView( + editorInfo: EditorInfo?, + restarting: Boolean, + ) { + super.onStartInputView(editorInfo, restarting) + setupCommandBarTheme(binding) + } + private fun shouldCommitPeriodAfterSpace(language: String): Boolean { val sharedPref = getSharedPreferences("app_preferences", Context.MODE_PRIVATE) return sharedPref.getBoolean("period_on_double_tap_$language", false) @@ -67,6 +78,7 @@ class RussianKeyboardIME : SimpleKeyboardIME() { Log.i("MY-TAG", "From Russian Keyboard IME") keyboardView = binding.keyboardView keyboardView!!.setKeyboard(keyboard!!) + setupCommandBarTheme(binding) keyboardView!!.setKeyboardHolder(binding.keyboardHolder) keyboardView!!.mOnKeyboardActionListener = this updateUI() @@ -74,9 +86,22 @@ class RussianKeyboardIME : SimpleKeyboardIME() { } private fun setupIdleView() { - binding.translateBtn.setBackgroundColor(getColor(R.color.you_keyboard_background_color)) - binding.conjugateBtn.setBackgroundColor(getColor(R.color.you_keyboard_background_color)) - binding.pluralBtn.setBackgroundColor(getColor(R.color.you_keyboard_background_color)) + val sharedPref = getSharedPreferences("app_preferences", Context.MODE_PRIVATE) + val isUserDarkMode = sharedPref.getBoolean("dark_mode", true) + when (isUserDarkMode) { + true -> { + binding.translateBtn.setBackgroundColor(getColor(R.color.transparent)) + binding.conjugateBtn.setBackgroundColor(getColor(R.color.transparent)) + binding.pluralBtn.setBackgroundColor(getColor(R.color.transparent)) + } + else -> { + binding.translateBtn.setBackgroundColor(getColor(R.color.transparent)) + binding.conjugateBtn.setBackgroundColor(getColor(R.color.transparent)) + binding.pluralBtn.setBackgroundColor(getColor(R.color.transparent)) + } + } + + setupCommandBarTheme(binding) binding.translateBtn.text = "" binding.conjugateBtn.text = "" binding.pluralBtn.text = "" @@ -127,6 +152,7 @@ class RussianKeyboardIME : SimpleKeyboardIME() { binding.translateBtn.setBackgroundDrawable(getDrawable(R.drawable.button_background_rounded)) binding.conjugateBtn.setBackgroundDrawable(getDrawable(R.drawable.button_background_rounded)) binding.pluralBtn.setBackgroundDrawable(getDrawable(R.drawable.button_background_rounded)) + setupCommandBarTheme(binding) binding.translateBtn.text = "Translate" binding.conjugateBtn.text = "Conjugate" binding.pluralBtn.text = "Plural" @@ -159,6 +185,7 @@ class RussianKeyboardIME : SimpleKeyboardIME() { val keyboardHolder = keyboardBinding.root keyboardView = keyboardBinding.keyboardView keyboardView!!.setKeyboard(keyboard!!) + super.setupToolBarTheme(keyboardBinding) keyboardView!!.mOnKeyboardActionListener = this keyboardBinding.scribeKey.setOnClickListener { currentState = ScribeState.IDLE @@ -172,6 +199,7 @@ class RussianKeyboardIME : SimpleKeyboardIME() { val binding = KeyboardViewCommandOptionsBinding.inflate(layoutInflater) this.binding = binding val keyboardHolder = binding.root + setupCommandBarTheme(binding) keyboardView = binding.keyboardView keyboardView!!.setKeyboard(keyboard!!) keyboardView!!.mOnKeyboardActionListener = this @@ -183,11 +211,27 @@ class RussianKeyboardIME : SimpleKeyboardIME() { setInputView(keyboardHolder) } + private fun updateEnterKeyColor() { + when (currentState) { + ScribeState.IDLE -> keyboardView?.setEnterKeyColor(Color.TRANSPARENT) + ScribeState.SELECT_COMMAND -> keyboardView?.setEnterKeyColor(Color.TRANSPARENT) + else -> keyboardView?.setEnterKeyColor(getColor(R.color.dark_scribe_blue)) + } + } + + override fun onCreate() { + super.onCreate() + keyboard = MyKeyboard(this, getKeyboardLayoutXML(), enterKeyType) + onCreateInputView() + setupCommandBarTheme(binding) + } + private fun updateUI() { when (currentState) { ScribeState.IDLE -> setupIdleView() ScribeState.SELECT_COMMAND -> setupSelectCommandView() else -> switchToToolBar() } + updateEnterKeyColor() } } diff --git a/app/src/main/java/be/scri/services/SimpleKeyboardIME.kt b/app/src/main/java/be/scri/services/SimpleKeyboardIME.kt index f24840b3..a4270ce1 100644 --- a/app/src/main/java/be/scri/services/SimpleKeyboardIME.kt +++ b/app/src/main/java/be/scri/services/SimpleKeyboardIME.kt @@ -18,12 +18,12 @@ import android.view.inputmethod.EditorInfo.IME_MASK_ACTION import android.view.inputmethod.ExtractedTextRequest import be.scri.R import be.scri.databinding.KeyboardViewCommandOptionsBinding +import be.scri.databinding.KeyboardViewKeyboardBinding import be.scri.helpers.MyKeyboard import be.scri.helpers.SHIFT_OFF import be.scri.helpers.SHIFT_ON_ONE_CHAR import be.scri.helpers.SHIFT_ON_PERMANENT import be.scri.views.MyKeyboardView - // based on https://www.androidauthority.com/lets-build-custom-keyboard-android-832362/ abstract class SimpleKeyboardIME : @@ -75,7 +75,7 @@ abstract class SimpleKeyboardIME : keyboardView!!.setKeyboard(keyboard!!) keyboardView!!.setKeyboardHolder(binding.keyboardHolder) keyboardView!!.mOnKeyboardActionListener = this - return keyboardHolder!! + return keyboardHolder } override fun onPress(primaryCode: Int) { @@ -89,6 +89,7 @@ abstract class SimpleKeyboardIME : restarting: Boolean, ) { super.onStartInput(attribute, restarting) + inputTypeClass = attribute!!.inputType and TYPE_MASK_CLASS enterKeyType = attribute.imeOptions and (IME_MASK_ACTION or IME_FLAG_NO_ENTER_ACTION) val inputConnection = currentInputConnection @@ -108,7 +109,6 @@ abstract class SimpleKeyboardIME : keyboard = MyKeyboard(this, keyboardXml, enterKeyType) keyboardView?.setKeyboard(keyboard!!) - updateShiftKeyState() } fun updateShiftKeyState() { @@ -168,8 +168,10 @@ abstract class SimpleKeyboardIME : private fun getImeOptionsActionId(): Int = if (currentInputEditorInfo.imeOptions and IME_FLAG_NO_ENTER_ACTION != 0) { IME_ACTION_NONE + Log.i("MYT-TAG", "Hello from ime") } else { currentInputEditorInfo.imeOptions and IME_MASK_ACTION + Log.i("MYT-TAG", "Hello from ime") } fun handleKeycodeEnter() { @@ -233,7 +235,6 @@ abstract class SimpleKeyboardIME : val inputConnection = currentInputConnection if (keyboard!!.mShiftState == SHIFT_ON_ONE_CHAR) { keyboard!!.mShiftState = SHIFT_OFF - Log.i("MY-TAG", "From English Keyboard IME") } val selectedText = inputConnection.getSelectedText(0) @@ -271,4 +272,30 @@ abstract class SimpleKeyboardIME : keyboardView!!.invalidateAllKeys() } } + + fun setupToolBarTheme(binding: KeyboardViewKeyboardBinding) { + val sharedPref = getSharedPreferences("app_preferences", Context.MODE_PRIVATE) + val isUserDarkMode = sharedPref.getBoolean("dark_mode", true) + when (isUserDarkMode) { + true -> { + binding.commandField.setBackgroundColor(getColor(R.color.md_grey_black_dark)) + } + else -> { + binding.commandField.setBackgroundColor(getColor(R.color.light_cmd_bar_border_color)) + } + } + } + + fun setupCommandBarTheme(binding: KeyboardViewCommandOptionsBinding) { + val sharedPref = getSharedPreferences("app_preferences", Context.MODE_PRIVATE) + val isUserDarkMode = sharedPref.getBoolean("dark_mode", true) + when (isUserDarkMode) { + true -> { + binding.commandField.setBackgroundColor(getColor(R.color.md_grey_black_dark)) + } + else -> { + binding.commandField.setBackgroundColor(getColor(R.color.light_cmd_bar_border_color)) + } + } + } } diff --git a/app/src/main/java/be/scri/services/SpanishKeyboardIME.kt b/app/src/main/java/be/scri/services/SpanishKeyboardIME.kt index 70e2d3d9..b76aaf9a 100644 --- a/app/src/main/java/be/scri/services/SpanishKeyboardIME.kt +++ b/app/src/main/java/be/scri/services/SpanishKeyboardIME.kt @@ -1,14 +1,17 @@ package be.scri.services import android.content.Context +import android.graphics.Color import android.text.InputType import android.util.Log import android.view.View +import android.view.inputmethod.EditorInfo import android.view.inputmethod.EditorInfo.IME_ACTION_NONE import be.scri.R import be.scri.databinding.KeyboardViewCommandOptionsBinding import be.scri.databinding.KeyboardViewKeyboardBinding import be.scri.helpers.MyKeyboard +import be.scri.services.EnglishKeyboardIME.ScribeState import be.scri.views.MyKeyboardView class SpanishKeyboardIME : SimpleKeyboardIME() { @@ -53,6 +56,14 @@ class SpanishKeyboardIME : SimpleKeyboardIME() { return sharedPref.getBoolean("period_on_double_tap_$language", false) } + override fun onStartInputView( + editorInfo: EditorInfo?, + restarting: Boolean, + ) { + super.onStartInputView(editorInfo, restarting) + setupCommandBarTheme(binding) + } + override fun commitPeriodAfterSpace() { if (shouldCommitPeriodAfterSpace("Spanish")) { val inputConnection = currentInputConnection ?: return @@ -67,6 +78,7 @@ class SpanishKeyboardIME : SimpleKeyboardIME() { Log.i("MY-TAG", "From Spanish Keyboard IME") keyboardView = binding.keyboardView keyboardView!!.setKeyboard(keyboard!!) + setupCommandBarTheme(binding) keyboardView!!.setKeyboardHolder(binding.keyboardHolder) keyboardView!!.mOnKeyboardActionListener = this updateUI() @@ -74,9 +86,22 @@ class SpanishKeyboardIME : SimpleKeyboardIME() { } private fun setupIdleView() { - binding.translateBtn.setBackgroundColor(getColor(R.color.you_keyboard_background_color)) - binding.conjugateBtn.setBackgroundColor(getColor(R.color.you_keyboard_background_color)) - binding.pluralBtn.setBackgroundColor(getColor(R.color.you_keyboard_background_color)) + val sharedPref = getSharedPreferences("app_preferences", Context.MODE_PRIVATE) + val isUserDarkMode = sharedPref.getBoolean("dark_mode", true) + when (isUserDarkMode) { + true -> { + binding.translateBtn.setBackgroundColor(getColor(R.color.transparent)) + binding.conjugateBtn.setBackgroundColor(getColor(R.color.transparent)) + binding.pluralBtn.setBackgroundColor(getColor(R.color.transparent)) + } + else -> { + binding.translateBtn.setBackgroundColor(getColor(R.color.transparent)) + binding.conjugateBtn.setBackgroundColor(getColor(R.color.transparent)) + binding.pluralBtn.setBackgroundColor(getColor(R.color.transparent)) + } + } + + setupCommandBarTheme(binding) binding.translateBtn.text = "" binding.conjugateBtn.text = "" binding.pluralBtn.text = "" @@ -127,6 +152,7 @@ class SpanishKeyboardIME : SimpleKeyboardIME() { binding.translateBtn.setBackgroundDrawable(getDrawable(R.drawable.button_background_rounded)) binding.conjugateBtn.setBackgroundDrawable(getDrawable(R.drawable.button_background_rounded)) binding.pluralBtn.setBackgroundDrawable(getDrawable(R.drawable.button_background_rounded)) + setupCommandBarTheme(binding) binding.translateBtn.text = "Translate" binding.conjugateBtn.text = "Conjugate" binding.pluralBtn.text = "Plural" @@ -153,11 +179,20 @@ class SpanishKeyboardIME : SimpleKeyboardIME() { } } + private fun updateEnterKeyColor() { + when (currentState) { + ScribeState.IDLE -> keyboardView?.setEnterKeyColor(Color.TRANSPARENT) + ScribeState.SELECT_COMMAND -> keyboardView?.setEnterKeyColor(Color.TRANSPARENT) + else -> keyboardView?.setEnterKeyColor(getColor(R.color.dark_scribe_blue)) + } + } + private fun switchToToolBar() { val keyboardBinding = KeyboardViewKeyboardBinding.inflate(layoutInflater) this.keyboardBinding = keyboardBinding val keyboardHolder = keyboardBinding.root keyboardView = keyboardBinding.keyboardView + super.setupToolBarTheme(keyboardBinding) keyboardView!!.setKeyboard(keyboard!!) keyboardView!!.mOnKeyboardActionListener = this keyboardBinding.scribeKey.setOnClickListener { @@ -172,6 +207,7 @@ class SpanishKeyboardIME : SimpleKeyboardIME() { val binding = KeyboardViewCommandOptionsBinding.inflate(layoutInflater) this.binding = binding val keyboardHolder = binding.root + setupCommandBarTheme(binding) keyboardView = binding.keyboardView keyboardView!!.setKeyboard(keyboard!!) keyboardView!!.mOnKeyboardActionListener = this @@ -183,11 +219,19 @@ class SpanishKeyboardIME : SimpleKeyboardIME() { setInputView(keyboardHolder) } + override fun onCreate() { + super.onCreate() + keyboard = MyKeyboard(this, getKeyboardLayoutXML(), enterKeyType) + onCreateInputView() + setupCommandBarTheme(binding) + } + private fun updateUI() { when (currentState) { ScribeState.IDLE -> setupIdleView() ScribeState.SELECT_COMMAND -> setupSelectCommandView() else -> switchToToolBar() } + updateEnterKeyColor() } } diff --git a/app/src/main/java/be/scri/services/SwedishKeyboardIME.kt b/app/src/main/java/be/scri/services/SwedishKeyboardIME.kt index 7afd48d8..3346c4bd 100644 --- a/app/src/main/java/be/scri/services/SwedishKeyboardIME.kt +++ b/app/src/main/java/be/scri/services/SwedishKeyboardIME.kt @@ -1,14 +1,17 @@ package be.scri.services import android.content.Context +import android.graphics.Color import android.text.InputType import android.util.Log import android.view.View +import android.view.inputmethod.EditorInfo import android.view.inputmethod.EditorInfo.IME_ACTION_NONE import be.scri.R import be.scri.databinding.KeyboardViewCommandOptionsBinding import be.scri.databinding.KeyboardViewKeyboardBinding import be.scri.helpers.MyKeyboard +import be.scri.services.EnglishKeyboardIME.ScribeState import be.scri.views.MyKeyboardView class SwedishKeyboardIME : SimpleKeyboardIME() { @@ -53,6 +56,14 @@ class SwedishKeyboardIME : SimpleKeyboardIME() { return sharedPref.getBoolean("period_on_double_tap_$language", false) } + override fun onStartInputView( + editorInfo: EditorInfo?, + restarting: Boolean, + ) { + super.onStartInputView(editorInfo, restarting) + setupCommandBarTheme(binding) + } + override fun commitPeriodAfterSpace() { if (shouldCommitPeriodAfterSpace("Swedish")) { val inputConnection = currentInputConnection ?: return @@ -102,6 +113,7 @@ class SwedishKeyboardIME : SimpleKeyboardIME() { Log.i("MY-TAG", "From Swedish Keyboard IME") keyboardView = binding.keyboardView keyboardView!!.setKeyboard(keyboard!!) + setupCommandBarTheme(binding) keyboardView!!.setKeyboardHolder(binding.keyboardHolder) keyboardView!!.mOnKeyboardActionListener = this updateUI() @@ -109,9 +121,22 @@ class SwedishKeyboardIME : SimpleKeyboardIME() { } private fun setupIdleView() { - binding.translateBtn.setBackgroundColor(getColor(R.color.you_keyboard_background_color)) - binding.conjugateBtn.setBackgroundColor(getColor(R.color.you_keyboard_background_color)) - binding.pluralBtn.setBackgroundColor(getColor(R.color.you_keyboard_background_color)) + val sharedPref = getSharedPreferences("app_preferences", Context.MODE_PRIVATE) + val isUserDarkMode = sharedPref.getBoolean("dark_mode", true) + when (isUserDarkMode) { + true -> { + binding.translateBtn.setBackgroundColor(getColor(R.color.transparent)) + binding.conjugateBtn.setBackgroundColor(getColor(R.color.transparent)) + binding.pluralBtn.setBackgroundColor(getColor(R.color.transparent)) + } + else -> { + binding.translateBtn.setBackgroundColor(getColor(R.color.transparent)) + binding.conjugateBtn.setBackgroundColor(getColor(R.color.transparent)) + binding.pluralBtn.setBackgroundColor(getColor(R.color.transparent)) + } + } + + setupCommandBarTheme(binding) binding.translateBtn.text = "" binding.conjugateBtn.text = "" binding.pluralBtn.text = "" @@ -127,6 +152,7 @@ class SwedishKeyboardIME : SimpleKeyboardIME() { binding.translateBtn.setBackgroundDrawable(getDrawable(R.drawable.button_background_rounded)) binding.conjugateBtn.setBackgroundDrawable(getDrawable(R.drawable.button_background_rounded)) binding.pluralBtn.setBackgroundDrawable(getDrawable(R.drawable.button_background_rounded)) + setupCommandBarTheme(binding) binding.translateBtn.text = "Translate" binding.conjugateBtn.text = "Conjugate" binding.pluralBtn.text = "Plural" @@ -158,6 +184,7 @@ class SwedishKeyboardIME : SimpleKeyboardIME() { this.keyboardBinding = keyboardBinding val keyboardHolder = keyboardBinding.root keyboardView = keyboardBinding.keyboardView + super.setupToolBarTheme(keyboardBinding) keyboardView!!.setKeyboard(keyboard!!) keyboardView!!.mOnKeyboardActionListener = this keyboardBinding.scribeKey.setOnClickListener { @@ -168,10 +195,19 @@ class SwedishKeyboardIME : SimpleKeyboardIME() { setInputView(keyboardHolder) } + private fun updateEnterKeyColor() { + when (currentState) { + ScribeState.IDLE -> keyboardView?.setEnterKeyColor(Color.TRANSPARENT) + ScribeState.SELECT_COMMAND -> keyboardView?.setEnterKeyColor(Color.TRANSPARENT) + else -> keyboardView?.setEnterKeyColor(getColor(R.color.dark_scribe_blue)) + } + } + private fun switchToCommandToolBar() { val binding = KeyboardViewCommandOptionsBinding.inflate(layoutInflater) this.binding = binding val keyboardHolder = binding.root + setupCommandBarTheme(binding) keyboardView = binding.keyboardView keyboardView!!.setKeyboard(keyboard!!) keyboardView!!.mOnKeyboardActionListener = this @@ -183,11 +219,19 @@ class SwedishKeyboardIME : SimpleKeyboardIME() { setInputView(keyboardHolder) } + override fun onCreate() { + super.onCreate() + keyboard = MyKeyboard(this, getKeyboardLayoutXML(), enterKeyType) + onCreateInputView() + setupCommandBarTheme(binding) + } + private fun updateUI() { when (currentState) { ScribeState.IDLE -> setupIdleView() ScribeState.SELECT_COMMAND -> setupSelectCommandView() else -> switchToToolBar() } + updateEnterKeyColor() } } diff --git a/app/src/main/java/be/scri/views/MyKeyboardView.kt b/app/src/main/java/be/scri/views/MyKeyboardView.kt index a0321659..66c494da 100644 --- a/app/src/main/java/be/scri/views/MyKeyboardView.kt +++ b/app/src/main/java/be/scri/views/MyKeyboardView.kt @@ -30,6 +30,7 @@ import android.widget.PopupWindow import android.widget.TextView import be.scri.R import be.scri.databinding.KeyboardPopupKeyboardBinding +import be.scri.databinding.KeyboardViewCommandOptionsBinding import be.scri.databinding.KeyboardViewKeyboardBinding import be.scri.extensions.adjustAlpha import be.scri.extensions.applyColorFilter @@ -162,6 +163,10 @@ class MyKeyboardView private val mSpaceMoveThreshold: Int private var ignoreTouches = false + private var mEnterKeyColor: Int = 0 + + private var mSpecialKeyColor: Int? = null + private var mKeyBackground: Drawable? = null private var mToolbarHolder: View? = null @@ -207,6 +212,14 @@ class MyKeyboardView private const val DOUBLE_TAP_DELAY = 300L } + private var _keyboardCommandBinding: KeyboardViewCommandOptionsBinding? = null + val keyboardCommandBinding: KeyboardViewCommandOptionsBinding + get() { + if (_keyboardCommandBinding == null) { + _keyboardCommandBinding = KeyboardViewCommandOptionsBinding.inflate(LayoutInflater.from(context)) + } + return _keyboardCommandBinding!! + } private var _popupBinding: KeyboardPopupKeyboardBinding? = null val popupBinding: KeyboardPopupKeyboardBinding get() { @@ -216,6 +229,11 @@ class MyKeyboardView return _popupBinding!! } + fun setEnterKeyColor(color: Int) { + mEnterKeyColor = color + invalidateAllKeys() + } + private var _keyboardBinding: KeyboardViewKeyboardBinding? = null val keyboardBinding: KeyboardViewKeyboardBinding get() { @@ -314,7 +332,7 @@ class MyKeyboardView if (context.config.isUsingSystemTheme) { resources.getColor(R.color.you_keyboard_toolbar_color, context.theme) } else { - mBackgroundColor + resources.getColor(R.color.you_keyboard_toolbar_color, context.theme) } val darkerColor = @@ -331,7 +349,7 @@ class MyKeyboardView mBackgroundColor } - if (changedView == _popupBinding?.miniKeyboardView) { + if (changedView == popupBinding.miniKeyboardView) { val previewBackground = background as LayerDrawable previewBackground.findDrawableByLayerId(R.id.button_background_shape).applyColorFilter(miniKeyboardBackgroundColor) previewBackground.findDrawableByLayerId(R.id.button_background_stroke).applyColorFilter(strokeColor) @@ -342,7 +360,7 @@ class MyKeyboardView val wasDarkened = mBackgroundColor != mBackgroundColor.darkenColor() mToolbarHolder?.apply { - _keyboardBinding?.apply { + keyboardBinding?.apply { topKeyboardDivider.beGoneIf(wasDarkened) topKeyboardDivider.background = ColorDrawable(strokeColor) @@ -378,10 +396,10 @@ class MyKeyboardView /** Sets the top row above the keyboard containing Scribe command buttons **/ fun setKeyboardHolder(keyboardHolder: View) { - mToolbarHolder = _keyboardBinding?.commandField + mToolbarHolder = keyboardBinding.commandField mToolbarHolder?.let { toolbarHolder -> - _keyboardBinding?.let { binding -> + keyboardBinding.let { binding -> } } } @@ -518,13 +536,19 @@ class MyKeyboardView } else { Color.WHITE } + + mSpecialKeyColor = + if (isUserDarkMode) { + R.color.special_key_dark + } else { + R.color.special_key_light + } paint.color = mTextColor val keyBackgroundPaint = Paint().apply { color = keyBackgroundColor style = Paint.Style.FILL } - val smallLetterPaint = Paint().apply { set(paint) @@ -546,7 +570,6 @@ class MyKeyboardView } else { Color.LTGRAY } - canvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR) canvas.drawColor(mKeyboardBackgroundColor) @@ -581,7 +604,13 @@ class MyKeyboardView val label = adjustCase(key.label)?.toString() if (key.focused || code == KEYCODE_ENTER) { - keyBackgroundPaint.color = mPrimaryColor + keyBackgroundPaint.color = mEnterKeyColor + canvas.drawRoundRect(keyRect, rectRadius, rectRadius, keyBackgroundPaint) + keyBackgroundPaint.color = keyBackgroundColor + } + + if ((code == KEYCODE_DELETE || code == KEYCODE_SHIFT || code == KEYCODE_MODE_CHANGE)) { + keyBackgroundPaint.color = resources.getColor(mSpecialKeyColor!!) canvas.drawRoundRect(keyRect, rectRadius, rectRadius, keyBackgroundPaint) keyBackgroundPaint.color = keyBackgroundColor } diff --git a/app/src/main/res/layout/keyboard_view_command_options.xml b/app/src/main/res/layout/keyboard_view_command_options.xml index ac84a758..9be41212 100644 --- a/app/src/main/res/layout/keyboard_view_command_options.xml +++ b/app/src/main/res/layout/keyboard_view_command_options.xml @@ -11,8 +11,7 @@ android:layout_above="@+id/keyboard_view" app:layout_constraintBottom_toTopOf="@+id/keyboard_view" app:layout_constraintEnd_toEndOf="parent" - app:layout_constraintStart_toStartOf="parent" - android:background="@color/you_keyboard_background_color"> + app:layout_constraintStart_toStartOf="parent">