diff --git a/app/src/main/java/be/scri/services/EnglishKeyboardIME.kt b/app/src/main/java/be/scri/services/EnglishKeyboardIME.kt index 82a3e74e..75099b36 100644 --- a/app/src/main/java/be/scri/services/EnglishKeyboardIME.kt +++ b/app/src/main/java/be/scri/services/EnglishKeyboardIME.kt @@ -1,21 +1,15 @@ package be.scri.services -import android.content.Context -import android.content.res.Configuration -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() { +class EnglishKeyboardIME : SimpleKeyboardIME("English") { override fun getKeyboardLayoutXML(): Int = R.xml.keys_letters_english override var shiftPermToggleSpeed = 500 @@ -33,53 +27,6 @@ class EnglishKeyboardIME : SimpleKeyboardIME() { override var hasTextBeforeCursor = false override lateinit var binding: KeyboardViewCommandOptionsBinding - enum class ScribeState { - IDLE, - SELECT_COMMAND, - TRANSLATE, - CONJUGATE, - PLURAL, - SELECT_VERB_CONJUNCTION, - SELECT_CASE_DECLENSION, - ALREADY_PLURAL, - INVALID, - DISPLAY_INFORMATION, - } - - private var currentState: ScribeState = ScribeState.IDLE - private lateinit var keyboardBinding: KeyboardViewKeyboardBinding - private var isAutoSuggestEnabled: Boolean = false - - 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, - ) { - val sharedPref = getSharedPreferences("app_preferences", Context.MODE_PRIVATE) - val currentNightMode = resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK - val isSystemDarkMode = currentNightMode == Configuration.UI_MODE_NIGHT_YES - val isUserDarkMode = sharedPref.getBoolean("dark_mode", isSystemDarkMode) - updateEnterKeyColor(isUserDarkMode) - initializeEmojiButtons() - isAutoSuggestEnabled = sharedPref.getBoolean("emoji_suggestions_English", true) - updateButtonVisibility(isAutoSuggestEnabled) - setupIdleView() - super.onStartInputView(editorInfo, restarting) - setupCommandBarTheme(binding) - } - - override fun commitPeriodAfterSpace() { - if (shouldCommitPeriodAfterSpace("English")) { - val inputConnection = currentInputConnection ?: return - inputConnection.deleteSurroundingText(1, 0) - inputConnection.commitText(". ", 1) - } - } - override fun onCreateInputView(): View { binding = KeyboardViewCommandOptionsBinding.inflate(layoutInflater) setupCommandBarTheme(binding) @@ -97,89 +44,6 @@ class EnglishKeyboardIME : SimpleKeyboardIME() { return keyboardHolder } - private fun setupIdleView() { - val sharedPref = getSharedPreferences("app_preferences", Context.MODE_PRIVATE) - val currentNightMode = resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK - val isSystemDarkMode = currentNightMode == Configuration.UI_MODE_NIGHT_YES - val isUserDarkMode = sharedPref.getBoolean("dark_mode", isSystemDarkMode) - when (isUserDarkMode) { - true -> { - binding.translateBtn.setBackgroundColor(getColor(R.color.transparent)) - binding.conjugateBtn.setBackgroundColor(getColor(R.color.transparent)) - binding.pluralBtn.setBackgroundColor(getColor(R.color.transparent)) - binding.translateBtn.setTextColor(Color.WHITE) - binding.conjugateBtn.setTextColor(Color.WHITE) - binding.pluralBtn.setTextColor(Color.WHITE) - binding.separator2.setBackgroundColor(getColor(R.color.special_key_dark)) - binding.separator3.setBackgroundColor(getColor(R.color.special_key_dark)) - } - else -> { - binding.translateBtn.setBackgroundColor(getColor(R.color.transparent)) - binding.conjugateBtn.setBackgroundColor(getColor(R.color.transparent)) - binding.pluralBtn.setBackgroundColor(getColor(R.color.transparent)) - binding.translateBtn.setTextColor(Color.BLACK) - binding.conjugateBtn.setTextColor(Color.BLACK) - binding.pluralBtn.setTextColor(Color.BLACK) - binding.separator2.setBackgroundColor(getColor(R.color.special_key_light)) - binding.separator3.setBackgroundColor(getColor(R.color.special_key_light)) - } - } - setupCommandBarTheme(binding) - binding.translateBtn.text = "Suggestion" - binding.conjugateBtn.text = "Suggestion" - binding.pluralBtn.text = "Suggestion" - binding.separator2.visibility = View.VISIBLE - binding.separator3.visibility = View.VISIBLE - binding.scribeKey.setOnClickListener { - updateButtonVisibility(false) - currentState = ScribeState.SELECT_COMMAND - Log.i("MY-TAG", "SELECT COMMAND STATE FROM English IME") - binding.scribeKey.foreground = getDrawable(R.drawable.close) - updateUI() - } - } - - private fun setupSelectCommandView() { - 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)) - binding.translateBtn.text = "Translate" - binding.conjugateBtn.text = "Conjugate" - binding.pluralBtn.text = "Plural" - binding.separator2.visibility = View.GONE - binding.separator3.visibility = View.GONE - 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 { - currentState = ScribeState.TRANSLATE - Log.i("MY-TAG", "TRANSLATE STATE") - updateUI() - } - binding.conjugateBtn.setOnClickListener { - Log.i("MY-TAG", "CONJUGATE STATE") - currentState = ScribeState.CONJUGATE - updateUI() - } - binding.pluralBtn.setOnClickListener { - Log.i("MY-TAG", "PLURAL STATE") - currentState = ScribeState.PLURAL - updateUI() - } - } - - private fun updateEnterKeyColor(isDarkMode: Boolean? = null) { - when (currentState) { - ScribeState.IDLE -> keyboardView?.setEnterKeyColor(null, isDarkMode = isDarkMode) - ScribeState.SELECT_COMMAND -> keyboardView?.setEnterKeyColor(null, isDarkMode = isDarkMode) - else -> keyboardView?.setEnterKeyColor(getColor(R.color.dark_scribe_blue)) - } - } - override fun onKey(code: Int) { val inputConnection = currentInputConnection if (keyboard == null || inputConnection == null) { @@ -230,75 +94,10 @@ class EnglishKeyboardIME : SimpleKeyboardIME() { } } - private fun switchToToolBar() { - this.keyboardBinding = initializeKeyboardBinding() - val keyboardHolder = keyboardBinding.root - super.setupToolBarTheme(keyboardBinding) - val sharedPref = getSharedPreferences("app_preferences", Context.MODE_PRIVATE) - val currentNightMode = resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK - val isSystemDarkMode = currentNightMode == Configuration.UI_MODE_NIGHT_YES - val isUserDarkMode = sharedPref.getBoolean("dark_mode", isSystemDarkMode) - when (isUserDarkMode) { - true -> { - keyboardBinding.topKeyboardDivider.setBackgroundColor(getColor(R.color.special_key_dark)) - } - false -> { - keyboardBinding.topKeyboardDivider.setBackgroundColor(getColor(R.color.special_key_light)) - } - } - keyboardView = keyboardBinding.keyboardView - keyboardView!!.setKeyboard(keyboard!!) - keyboardView!!.mOnKeyboardActionListener = this - keyboardBinding.scribeKey.setOnClickListener { - currentState = ScribeState.IDLE - switchToCommandToolBar() - updateUI() - } - setInputView(keyboardHolder) - } - - 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 - keyboardBinding.scribeKey.setOnClickListener { - currentState = ScribeState.IDLE - setupSelectCommandView() - updateUI() - } - setInputView(keyboardHolder) - } - override fun onCreate() { super.onCreate() keyboard = MyKeyboard(this, getKeyboardLayoutXML(), enterKeyType) onCreateInputView() setupCommandBarTheme(binding) } - - private fun updateUI() { - val sharedPref = getSharedPreferences("app_preferences", Context.MODE_PRIVATE) - val currentNightMode = resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK - val isSystemDarkMode = currentNightMode == Configuration.UI_MODE_NIGHT_YES - val isUserDarkMode = sharedPref.getBoolean("dark_mode", isSystemDarkMode) - when (currentState) { - ScribeState.IDLE -> { - setupIdleView() - initializeEmojiButtons() - updateButtonVisibility(isAutoSuggestEnabled) - } - ScribeState.SELECT_COMMAND -> setupSelectCommandView() - else -> switchToToolBar() - } - updateEnterKeyColor(isUserDarkMode) - } - - private fun initializeKeyboardBinding(): KeyboardViewKeyboardBinding { - val keyboardBinding = KeyboardViewKeyboardBinding.inflate(layoutInflater) - return keyboardBinding - } } diff --git a/app/src/main/java/be/scri/services/FrenchKeyboardIME.kt b/app/src/main/java/be/scri/services/FrenchKeyboardIME.kt index 6e33a8ee..ce98a8f0 100644 --- a/app/src/main/java/be/scri/services/FrenchKeyboardIME.kt +++ b/app/src/main/java/be/scri/services/FrenchKeyboardIME.kt @@ -1,39 +1,17 @@ package be.scri.services -import android.content.Context -import android.content.res.Configuration -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() { +class FrenchKeyboardIME : SimpleKeyboardIME("French") { override fun getKeyboardLayoutXML(): Int = R.xml.keys_letters_french - enum class ScribeState { - IDLE, - SELECT_COMMAND, - TRANSLATE, - CONJUGATE, - PLURAL, - SELECT_VERB_CONJUNCTION, - SELECT_CASE_DECLENSION, - ALREADY_PLURAL, - INVALID, - DISPLAY_INFORMATION, - } - - private var isAutoSuggestEnabled: Boolean = false - private var currentState: ScribeState = ScribeState.IDLE - private lateinit var keyboardBinding: KeyboardViewKeyboardBinding override lateinit var binding: KeyboardViewCommandOptionsBinding override var keyboardView: MyKeyboardView? = null override var keyboard: MyKeyboard? = null @@ -48,41 +26,6 @@ class FrenchKeyboardIME : SimpleKeyboardIME() { override var switchToLetters = false override var hasTextBeforeCursor = false - 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 commitPeriodAfterSpace() { - if (shouldCommitPeriodAfterSpace("French")) { - val inputConnection = currentInputConnection ?: return - inputConnection.deleteSurroundingText(1, 0) - inputConnection.commitText(". ", 1) - } - } - - override fun onStartInputView( - editorInfo: EditorInfo?, - restarting: Boolean, - ) { - val sharedPref = getSharedPreferences("app_preferences", Context.MODE_PRIVATE) - val currentNightMode = resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK - val isSystemDarkMode = currentNightMode == Configuration.UI_MODE_NIGHT_YES - val isUserDarkMode = sharedPref.getBoolean("dark_mode", isSystemDarkMode) - updateEnterKeyColor(isUserDarkMode) - initializeEmojiButtons() - isAutoSuggestEnabled = sharedPref.getBoolean("emoji_suggestions_French", true) - updateButtonVisibility(isAutoSuggestEnabled) - setupIdleView() - super.onStartInputView(editorInfo, restarting) - setupCommandBarTheme(binding) - } - override fun onKey(code: Int) { val inputConnection = currentInputConnection if (keyboard == null || inputConnection == null) { @@ -147,143 +90,10 @@ class FrenchKeyboardIME : SimpleKeyboardIME() { return keyboardHolder } - private fun setupIdleView() { - val sharedPref = getSharedPreferences("app_preferences", Context.MODE_PRIVATE) - val currentNightMode = resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK - val isSystemDarkMode = currentNightMode == Configuration.UI_MODE_NIGHT_YES - val isUserDarkMode = sharedPref.getBoolean("dark_mode", isSystemDarkMode) - when (isUserDarkMode) { - true -> { - binding.translateBtn.setBackgroundColor(getColor(R.color.transparent)) - binding.conjugateBtn.setBackgroundColor(getColor(R.color.transparent)) - binding.pluralBtn.setBackgroundColor(getColor(R.color.transparent)) - binding.translateBtn.setTextColor(Color.WHITE) - binding.conjugateBtn.setTextColor(Color.WHITE) - binding.pluralBtn.setTextColor(Color.WHITE) - binding.separator2.setBackgroundColor(getColor(R.color.special_key_dark)) - binding.separator3.setBackgroundColor(getColor(R.color.special_key_dark)) - } - else -> { - binding.translateBtn.setBackgroundColor(getColor(R.color.transparent)) - binding.conjugateBtn.setBackgroundColor(getColor(R.color.transparent)) - binding.pluralBtn.setBackgroundColor(getColor(R.color.transparent)) - binding.translateBtn.setTextColor(Color.BLACK) - binding.conjugateBtn.setTextColor(Color.BLACK) - binding.pluralBtn.setTextColor(Color.BLACK) - binding.separator2.setBackgroundColor(getColor(R.color.special_key_light)) - binding.separator3.setBackgroundColor(getColor(R.color.special_key_light)) - } - } - - setupCommandBarTheme(binding) - binding.translateBtn.text = "Suggestion" - binding.conjugateBtn.text = "Suggestion" - binding.pluralBtn.text = "Suggestion" - binding.separator2.visibility = View.VISIBLE - binding.separator3.visibility = View.VISIBLE - binding.scribeKey.setOnClickListener { - currentState = ScribeState.SELECT_COMMAND - updateButtonVisibility(false) - Log.i("MY-TAG", "SELECT COMMAND STATE") - binding.scribeKey.foreground = getDrawable(R.drawable.close) - updateUI() - } - } - - private fun setupSelectCommandView() { - 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" - binding.separator2.visibility = View.GONE - binding.separator3.visibility = View.GONE - 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 { - currentState = ScribeState.TRANSLATE - Log.i("MY-TAG", "TRANSLATE STATE") - updateUI() - } - binding.conjugateBtn.setOnClickListener { - Log.i("MY-TAG", "CONJUGATE STATE") - currentState = ScribeState.CONJUGATE - updateUI() - } - binding.pluralBtn.setOnClickListener { - Log.i("MY-TAG", "PLURAL STATE") - currentState = ScribeState.PLURAL - updateUI() - } - } - - private fun switchToToolBar() { - val keyboardBinding = KeyboardViewKeyboardBinding.inflate(layoutInflater) - this.keyboardBinding = keyboardBinding - val keyboardHolder = keyboardBinding.root - keyboardView = keyboardBinding.keyboardView - keyboardView!!.setKeyboard(keyboard!!) - super.setupToolBarTheme(keyboardBinding) - keyboardView!!.mOnKeyboardActionListener = this - keyboardBinding.scribeKey.setOnClickListener { - currentState = ScribeState.IDLE - switchToCommandToolBar() - updateUI() - } - setInputView(keyboardHolder) - } - - 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 - keyboardBinding.scribeKey.setOnClickListener { - currentState = ScribeState.IDLE - setupSelectCommandView() - updateUI() - } - setInputView(keyboardHolder) - } - - private fun updateEnterKeyColor(isDarkMode: Boolean? = null) { - when (currentState) { - ScribeState.IDLE -> keyboardView?.setEnterKeyColor(null, isDarkMode = isDarkMode) - ScribeState.SELECT_COMMAND -> keyboardView?.setEnterKeyColor(null, isDarkMode = isDarkMode) - 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() - initializeEmojiButtons() - updateButtonVisibility(isAutoSuggestEnabled) - } - ScribeState.SELECT_COMMAND -> setupSelectCommandView() - else -> switchToToolBar() - } - val sharedPref = getSharedPreferences("app_preferences", Context.MODE_PRIVATE) - val currentNightMode = resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK - val isSystemDarkMode = currentNightMode == Configuration.UI_MODE_NIGHT_YES - val isUserDarkMode = sharedPref.getBoolean("dark_mode", isSystemDarkMode) - updateEnterKeyColor(isUserDarkMode) - } } diff --git a/app/src/main/java/be/scri/services/GermanKeyboardIME.kt b/app/src/main/java/be/scri/services/GermanKeyboardIME.kt index 7a6b4ad3..8c110162 100644 --- a/app/src/main/java/be/scri/services/GermanKeyboardIME.kt +++ b/app/src/main/java/be/scri/services/GermanKeyboardIME.kt @@ -1,21 +1,15 @@ package be.scri.services -import android.content.Context -import android.content.res.Configuration -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() { +class GermanKeyboardIME : SimpleKeyboardIME("German") { override fun getKeyboardLayoutXML(): Int = if (getIsAccentCharacter()) { R.xml.keys_letter_german_without_accent_character @@ -23,28 +17,6 @@ class GermanKeyboardIME : SimpleKeyboardIME() { R.xml.keys_letters_german } - private fun getIsAccentCharacter(): Boolean { - val sharedPref = getSharedPreferences("app_preferences", Context.MODE_PRIVATE) - val isAccentCharacter = sharedPref.getBoolean("disable_accent_character_German", false) - return isAccentCharacter - } - - enum class ScribeState { - IDLE, - SELECT_COMMAND, - TRANSLATE, - CONJUGATE, - PLURAL, - SELECT_VERB_CONJUNCTION, - SELECT_CASE_DECLENSION, - ALREADY_PLURAL, - INVALID, - DISPLAY_INFORMATION, - } - - private var isAutoSuggestEnabled: Boolean = false - private var currentState: ScribeState = ScribeState.IDLE - private lateinit var keyboardBinding: KeyboardViewKeyboardBinding override lateinit var binding: KeyboardViewCommandOptionsBinding override var keyboardView: MyKeyboardView? = null override var keyboard: MyKeyboard? = null @@ -59,42 +31,6 @@ class GermanKeyboardIME : SimpleKeyboardIME() { override var switchToLetters = false override var hasTextBeforeCursor = false - override fun onInitializeInterface() { - super.onInitializeInterface() - keyboard = MyKeyboard(this, getKeyboardLayoutXML(), enterKeyType) - } - - override fun onStartInputView( - editorInfo: EditorInfo?, - restarting: Boolean, - ) { - val sharedPref = getSharedPreferences("app_preferences", Context.MODE_PRIVATE) - val currentNightMode = resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK - val isSystemDarkMode = currentNightMode == Configuration.UI_MODE_NIGHT_YES - val isUserDarkMode = sharedPref.getBoolean("dark_mode", isSystemDarkMode) - updateEnterKeyColor(isUserDarkMode) - initializeEmojiButtons() - isAutoSuggestEnabled = sharedPref.getBoolean("emoji_suggestions_German", true) - updateButtonVisibility(isAutoSuggestEnabled) - setupIdleView() - super.onStartInputView(editorInfo, restarting) - onInitializeInterface() - 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) - } - - override fun commitPeriodAfterSpace() { - if (shouldCommitPeriodAfterSpace("German")) { - val inputConnection = currentInputConnection ?: return - inputConnection.deleteSurroundingText(1, 0) - inputConnection.commitText(". ", 1) - } - } - override fun onCreateInputView(): View { binding = KeyboardViewCommandOptionsBinding.inflate(layoutInflater) val keyboardHolder = binding.root @@ -113,47 +49,6 @@ class GermanKeyboardIME : SimpleKeyboardIME() { return keyboardHolder } - private fun setupIdleView() { - 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)) - binding.translateBtn.setTextColor(Color.WHITE) - binding.conjugateBtn.setTextColor(Color.WHITE) - binding.pluralBtn.setTextColor(Color.WHITE) - binding.separator2.setBackgroundColor(getColor(R.color.special_key_dark)) - binding.separator3.setBackgroundColor(getColor(R.color.special_key_dark)) - } - else -> { - binding.translateBtn.setBackgroundColor(getColor(R.color.transparent)) - binding.conjugateBtn.setBackgroundColor(getColor(R.color.transparent)) - binding.pluralBtn.setBackgroundColor(getColor(R.color.transparent)) - binding.translateBtn.setTextColor(Color.BLACK) - binding.conjugateBtn.setTextColor(Color.BLACK) - binding.pluralBtn.setTextColor(Color.BLACK) - binding.separator2.setBackgroundColor(getColor(R.color.special_key_light)) - binding.separator3.setBackgroundColor(getColor(R.color.special_key_light)) - } - } - - setupCommandBarTheme(binding) - binding.translateBtn.text = "Suggestion" - binding.conjugateBtn.text = "Suggestion" - binding.pluralBtn.text = "Suggestion" - binding.separator2.visibility = View.VISIBLE - binding.separator3.visibility = View.VISIBLE - binding.scribeKey.setOnClickListener { - currentState = ScribeState.SELECT_COMMAND - updateButtonVisibility(false) - Log.i("MY-TAG", "SELECT COMMAND STATE") - binding.scribeKey.foreground = getDrawable(R.drawable.close) - updateUI() - } - } - override fun onKey(code: Int) { val inputConnection = currentInputConnection if (keyboard == null || inputConnection == null) { @@ -204,100 +99,10 @@ class GermanKeyboardIME : SimpleKeyboardIME() { } } - private fun setupSelectCommandView() { - 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" - binding.separator2.visibility = View.GONE - binding.separator3.visibility = View.GONE - 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 { - currentState = ScribeState.TRANSLATE - Log.i("MY-TAG", "TRANSLATE STATE") - updateUI() - } - binding.conjugateBtn.setOnClickListener { - Log.i("MY-TAG", "CONJUGATE STATE") - currentState = ScribeState.CONJUGATE - updateUI() - } - binding.pluralBtn.setOnClickListener { - Log.i("MY-TAG", "PLURAL STATE") - currentState = ScribeState.PLURAL - updateUI() - } - } - - private fun switchToToolBar() { - val keyboardBinding = KeyboardViewKeyboardBinding.inflate(layoutInflater) - this.keyboardBinding = keyboardBinding - val keyboardHolder = keyboardBinding.root - keyboardView = keyboardBinding.keyboardView - keyboardView!!.setKeyboard(keyboard!!) - super.setupToolBarTheme(keyboardBinding) - keyboardView!!.mOnKeyboardActionListener = this - keyboardBinding.scribeKey.setOnClickListener { - currentState = ScribeState.IDLE - switchToCommandToolBar() - updateUI() - } - setInputView(keyboardHolder) - } - - 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 - keyboardBinding.scribeKey.setOnClickListener { - currentState = ScribeState.IDLE - setupSelectCommandView() - updateUI() - } - setInputView(keyboardHolder) - } - - private fun updateEnterKeyColor(isDarkMode: Boolean? = null) { - when (currentState) { - ScribeState.IDLE -> keyboardView?.setEnterKeyColor(null, isDarkMode = isDarkMode) - ScribeState.SELECT_COMMAND -> keyboardView?.setEnterKeyColor(null, isDarkMode = isDarkMode) - 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() { - val sharedPref = getSharedPreferences("app_preferences", Context.MODE_PRIVATE) - val currentNightMode = resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK - val isSystemDarkMode = currentNightMode == Configuration.UI_MODE_NIGHT_YES - val isUserDarkMode = sharedPref.getBoolean("dark_mode", isSystemDarkMode) - when (currentState) { - ScribeState.IDLE -> { - setupIdleView() - initializeEmojiButtons() - updateButtonVisibility(isAutoSuggestEnabled) - } - ScribeState.SELECT_COMMAND -> setupSelectCommandView() - else -> switchToToolBar() - } - updateEnterKeyColor(isUserDarkMode) - } } diff --git a/app/src/main/java/be/scri/services/ItalianKeyboardIME.kt b/app/src/main/java/be/scri/services/ItalianKeyboardIME.kt index 84852462..93aeabe3 100644 --- a/app/src/main/java/be/scri/services/ItalianKeyboardIME.kt +++ b/app/src/main/java/be/scri/services/ItalianKeyboardIME.kt @@ -1,39 +1,17 @@ package be.scri.services -import android.content.Context -import android.content.res.Configuration -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() { +class ItalianKeyboardIME : SimpleKeyboardIME("Italian") { override fun getKeyboardLayoutXML(): Int = R.xml.keys_letters_italian - enum class ScribeState { - IDLE, - SELECT_COMMAND, - TRANSLATE, - CONJUGATE, - PLURAL, - SELECT_VERB_CONJUNCTION, - SELECT_CASE_DECLENSION, - ALREADY_PLURAL, - INVALID, - DISPLAY_INFORMATION, - } - - private var isAutoSuggestEnabled: Boolean = false - private var currentState: ScribeState = ScribeState.IDLE - private lateinit var keyboardBinding: KeyboardViewKeyboardBinding override lateinit var binding: KeyboardViewCommandOptionsBinding override var keyboardView: MyKeyboardView? = null override var keyboard: MyKeyboard? = null @@ -48,41 +26,6 @@ class ItalianKeyboardIME : SimpleKeyboardIME() { override var switchToLetters = false override var hasTextBeforeCursor = false - override fun onInitializeInterface() { - super.onInitializeInterface() - keyboard = MyKeyboard(this, getKeyboardLayoutXML(), enterKeyType) - } - - override fun onStartInputView( - editorInfo: EditorInfo?, - restarting: Boolean, - ) { - val sharedPref = getSharedPreferences("app_preferences", Context.MODE_PRIVATE) - val currentNightMode = resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK - val isSystemDarkMode = currentNightMode == Configuration.UI_MODE_NIGHT_YES - val isUserDarkMode = sharedPref.getBoolean("dark_mode", isSystemDarkMode) - updateEnterKeyColor(isUserDarkMode) - initializeEmojiButtons() - isAutoSuggestEnabled = sharedPref.getBoolean("emoji_suggestions_Italian", true) - updateButtonVisibility(isAutoSuggestEnabled) - setupIdleView() - 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) - } - - override fun commitPeriodAfterSpace() { - if (shouldCommitPeriodAfterSpace("Italian")) { - val inputConnection = currentInputConnection ?: return - inputConnection.deleteSurroundingText(1, 0) - inputConnection.commitText(". ", 1) - } - } - override fun onCreateInputView(): View { binding = KeyboardViewCommandOptionsBinding.inflate(layoutInflater) val keyboardHolder = binding.root @@ -97,49 +40,6 @@ class ItalianKeyboardIME : SimpleKeyboardIME() { return keyboardHolder } - private fun setupIdleView() { - val sharedPref = getSharedPreferences("app_preferences", Context.MODE_PRIVATE) - val currentNightMode = resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK - val isSystemDarkMode = currentNightMode == Configuration.UI_MODE_NIGHT_YES - val isUserDarkMode = sharedPref.getBoolean("dark_mode", isSystemDarkMode) - when (isUserDarkMode) { - true -> { - binding.translateBtn.setBackgroundColor(getColor(R.color.transparent)) - binding.conjugateBtn.setBackgroundColor(getColor(R.color.transparent)) - binding.pluralBtn.setBackgroundColor(getColor(R.color.transparent)) - binding.translateBtn.setTextColor(Color.WHITE) - binding.conjugateBtn.setTextColor(Color.WHITE) - binding.pluralBtn.setTextColor(Color.WHITE) - binding.separator2.setBackgroundColor(getColor(R.color.special_key_dark)) - binding.separator3.setBackgroundColor(getColor(R.color.special_key_dark)) - } - else -> { - binding.translateBtn.setBackgroundColor(getColor(R.color.transparent)) - binding.conjugateBtn.setBackgroundColor(getColor(R.color.transparent)) - binding.pluralBtn.setBackgroundColor(getColor(R.color.transparent)) - binding.translateBtn.setTextColor(Color.BLACK) - binding.conjugateBtn.setTextColor(Color.BLACK) - binding.pluralBtn.setTextColor(Color.BLACK) - binding.separator2.setBackgroundColor(getColor(R.color.special_key_light)) - binding.separator3.setBackgroundColor(getColor(R.color.special_key_light)) - } - } - - setupCommandBarTheme(binding) - binding.translateBtn.text = "Suggestion" - binding.conjugateBtn.text = "Suggestion" - binding.pluralBtn.text = "Suggestion" - binding.separator2.visibility = View.VISIBLE - binding.separator3.visibility = View.VISIBLE - binding.scribeKey.setOnClickListener { - currentState = ScribeState.SELECT_COMMAND - updateButtonVisibility(false) - Log.i("MY-TAG", "SELECT COMMAND STATE") - binding.scribeKey.foreground = getDrawable(R.drawable.close) - updateUI() - } - } - override fun onKey(code: Int) { val inputConnection = currentInputConnection if (keyboard == null || inputConnection == null) { @@ -190,100 +90,10 @@ class ItalianKeyboardIME : SimpleKeyboardIME() { } } - private fun setupSelectCommandView() { - 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" - binding.separator2.visibility = View.GONE - binding.separator3.visibility = View.GONE - 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 { - currentState = ScribeState.TRANSLATE - Log.i("MY-TAG", "TRANSLATE STATE") - updateUI() - } - binding.conjugateBtn.setOnClickListener { - Log.i("MY-TAG", "CONJUGATE STATE") - currentState = ScribeState.CONJUGATE - updateUI() - } - binding.pluralBtn.setOnClickListener { - Log.i("MY-TAG", "PLURAL STATE") - currentState = ScribeState.PLURAL - updateUI() - } - } - - private fun switchToToolBar() { - val keyboardBinding = KeyboardViewKeyboardBinding.inflate(layoutInflater) - this.keyboardBinding = keyboardBinding - val keyboardHolder = keyboardBinding.root - keyboardView = keyboardBinding.keyboardView - keyboardView!!.setKeyboard(keyboard!!) - super.setupToolBarTheme(keyboardBinding) - keyboardView!!.mOnKeyboardActionListener = this - keyboardBinding.scribeKey.setOnClickListener { - currentState = ScribeState.IDLE - switchToCommandToolBar() - updateUI() - } - setInputView(keyboardHolder) - } - - 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 - keyboardBinding.scribeKey.setOnClickListener { - currentState = ScribeState.IDLE - setupSelectCommandView() - updateUI() - } - setInputView(keyboardHolder) - } - - private fun updateEnterKeyColor(isDarkMode: Boolean? = null) { - when (currentState) { - ScribeState.IDLE -> keyboardView?.setEnterKeyColor(null, isDarkMode = isDarkMode) - ScribeState.SELECT_COMMAND -> keyboardView?.setEnterKeyColor(null, isDarkMode = isDarkMode) - 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() - initializeEmojiButtons() - updateButtonVisibility(isAutoSuggestEnabled) - } - ScribeState.SELECT_COMMAND -> setupSelectCommandView() - else -> switchToToolBar() - } - val sharedPref = getSharedPreferences("app_preferences", Context.MODE_PRIVATE) - val currentNightMode = resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK - val isSystemDarkMode = currentNightMode == Configuration.UI_MODE_NIGHT_YES - val isUserDarkMode = sharedPref.getBoolean("dark_mode", isSystemDarkMode) - updateEnterKeyColor(isUserDarkMode) - } } diff --git a/app/src/main/java/be/scri/services/PortugueseKeyboardIME.kt b/app/src/main/java/be/scri/services/PortugueseKeyboardIME.kt index 8e8dc389..8f3cd31c 100644 --- a/app/src/main/java/be/scri/services/PortugueseKeyboardIME.kt +++ b/app/src/main/java/be/scri/services/PortugueseKeyboardIME.kt @@ -1,39 +1,17 @@ package be.scri.services -import android.content.Context -import android.content.res.Configuration -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() { +class PortugueseKeyboardIME : SimpleKeyboardIME("Portuguese") { override fun getKeyboardLayoutXML(): Int = R.xml.keys_letters_portuguese - enum class ScribeState { - IDLE, - SELECT_COMMAND, - TRANSLATE, - CONJUGATE, - PLURAL, - SELECT_VERB_CONJUNCTION, - SELECT_CASE_DECLENSION, - ALREADY_PLURAL, - INVALID, - DISPLAY_INFORMATION, - } - - private var isAutoSuggestEnabled: Boolean = false - private var currentState: ScribeState = ScribeState.IDLE - private lateinit var keyboardBinding: KeyboardViewKeyboardBinding override lateinit var binding: KeyboardViewCommandOptionsBinding override var keyboardView: MyKeyboardView? = null override var keyboard: MyKeyboard? = null @@ -48,41 +26,6 @@ class PortugueseKeyboardIME : SimpleKeyboardIME() { override var switchToLetters = false override var hasTextBeforeCursor = false - 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, - ) { - val sharedPref = getSharedPreferences("app_preferences", Context.MODE_PRIVATE) - val currentNightMode = resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK - val isSystemDarkMode = currentNightMode == Configuration.UI_MODE_NIGHT_YES - val isUserDarkMode = sharedPref.getBoolean("dark_mode", isSystemDarkMode) - updateEnterKeyColor(isUserDarkMode) - initializeEmojiButtons() - isAutoSuggestEnabled = sharedPref.getBoolean("emoji_suggestions_Portuguese", true) - updateButtonVisibility(isAutoSuggestEnabled) - setupIdleView() - super.onStartInputView(editorInfo, restarting) - setupCommandBarTheme(binding) - } - - override fun commitPeriodAfterSpace() { - if (shouldCommitPeriodAfterSpace("Portuguese")) { - val inputConnection = currentInputConnection ?: return - inputConnection.deleteSurroundingText(1, 0) - inputConnection.commitText(". ", 1) - } - } - override fun onCreateInputView(): View { binding = KeyboardViewCommandOptionsBinding.inflate(layoutInflater) val keyboardHolder = binding.root @@ -97,82 +40,6 @@ class PortugueseKeyboardIME : SimpleKeyboardIME() { return keyboardHolder } - private fun setupIdleView() { - val sharedPref = getSharedPreferences("app_preferences", Context.MODE_PRIVATE) - val currentNightMode = resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK - val isSystemDarkMode = currentNightMode == Configuration.UI_MODE_NIGHT_YES - val isUserDarkMode = sharedPref.getBoolean("dark_mode", isSystemDarkMode) - when (isUserDarkMode) { - true -> { - binding.translateBtn.setBackgroundColor(getColor(R.color.transparent)) - binding.conjugateBtn.setBackgroundColor(getColor(R.color.transparent)) - binding.pluralBtn.setBackgroundColor(getColor(R.color.transparent)) - binding.translateBtn.setTextColor(Color.WHITE) - binding.conjugateBtn.setTextColor(Color.WHITE) - binding.pluralBtn.setTextColor(Color.WHITE) - binding.separator2.setBackgroundColor(getColor(R.color.special_key_dark)) - binding.separator3.setBackgroundColor(getColor(R.color.special_key_dark)) - } - else -> { - binding.translateBtn.setBackgroundColor(getColor(R.color.transparent)) - binding.conjugateBtn.setBackgroundColor(getColor(R.color.transparent)) - binding.pluralBtn.setBackgroundColor(getColor(R.color.transparent)) - binding.translateBtn.setTextColor(Color.BLACK) - binding.conjugateBtn.setTextColor(Color.BLACK) - binding.pluralBtn.setTextColor(Color.BLACK) - binding.separator2.setBackgroundColor(getColor(R.color.special_key_light)) - binding.separator3.setBackgroundColor(getColor(R.color.special_key_light)) - } - } - - setupCommandBarTheme(binding) - binding.translateBtn.text = "Suggestion" - binding.conjugateBtn.text = "Suggestion" - binding.pluralBtn.text = "Suggestion" - binding.separator2.visibility = View.VISIBLE - binding.separator3.visibility = View.VISIBLE - binding.scribeKey.setOnClickListener { - currentState = ScribeState.SELECT_COMMAND - Log.i("MY-TAG", "SELECT COMMAND STATE") - updateButtonVisibility(false) - binding.scribeKey.foreground = getDrawable(R.drawable.close) - updateUI() - } - } - - private fun setupSelectCommandView() { - 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" - binding.separator2.visibility = View.GONE - binding.separator3.visibility = View.GONE - 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 { - currentState = ScribeState.TRANSLATE - Log.i("MY-TAG", "TRANSLATE STATE") - updateUI() - } - binding.conjugateBtn.setOnClickListener { - Log.i("MY-TAG", "CONJUGATE STATE") - currentState = ScribeState.CONJUGATE - updateUI() - } - binding.pluralBtn.setOnClickListener { - Log.i("MY-TAG", "PLURAL STATE") - currentState = ScribeState.PLURAL - updateUI() - } - } - override fun onKey(code: Int) { val inputConnection = currentInputConnection if (keyboard == null || inputConnection == null) { @@ -223,67 +90,10 @@ class PortugueseKeyboardIME : SimpleKeyboardIME() { } } - private fun switchToToolBar() { - val keyboardBinding = KeyboardViewKeyboardBinding.inflate(layoutInflater) - this.keyboardBinding = keyboardBinding - val keyboardHolder = keyboardBinding.root - keyboardView = keyboardBinding.keyboardView - keyboardView!!.setKeyboard(keyboard!!) - super.setupToolBarTheme(keyboardBinding) - keyboardView!!.mOnKeyboardActionListener = this - keyboardBinding.scribeKey.setOnClickListener { - currentState = ScribeState.IDLE - switchToCommandToolBar() - updateUI() - } - setInputView(keyboardHolder) - } - - 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 - keyboardBinding.scribeKey.setOnClickListener { - currentState = ScribeState.IDLE - setupSelectCommandView() - updateUI() - } - setInputView(keyboardHolder) - } - - private fun updateEnterKeyColor(isDarkMode: Boolean? = null) { - when (currentState) { - ScribeState.IDLE -> keyboardView?.setEnterKeyColor(null, isDarkMode = isDarkMode) - ScribeState.SELECT_COMMAND -> keyboardView?.setEnterKeyColor(null, isDarkMode = isDarkMode) - 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() - initializeEmojiButtons() - updateButtonVisibility(isAutoSuggestEnabled) - } - ScribeState.SELECT_COMMAND -> setupSelectCommandView() - else -> switchToToolBar() - } - val sharedPref = getSharedPreferences("app_preferences", Context.MODE_PRIVATE) - val currentNightMode = resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK - val isSystemDarkMode = currentNightMode == Configuration.UI_MODE_NIGHT_YES - val isUserDarkMode = sharedPref.getBoolean("dark_mode", isSystemDarkMode) - updateEnterKeyColor(isUserDarkMode) - } } diff --git a/app/src/main/java/be/scri/services/RussianKeyboardIME.kt b/app/src/main/java/be/scri/services/RussianKeyboardIME.kt index 6617e5e0..a0d8c94b 100644 --- a/app/src/main/java/be/scri/services/RussianKeyboardIME.kt +++ b/app/src/main/java/be/scri/services/RussianKeyboardIME.kt @@ -1,39 +1,17 @@ package be.scri.services -import android.content.Context -import android.content.res.Configuration -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() { +class RussianKeyboardIME : SimpleKeyboardIME("Russian") { override fun getKeyboardLayoutXML(): Int = R.xml.keys_letters_russian - enum class ScribeState { - IDLE, - SELECT_COMMAND, - TRANSLATE, - CONJUGATE, - PLURAL, - SELECT_VERB_CONJUNCTION, - SELECT_CASE_DECLENSION, - ALREADY_PLURAL, - INVALID, - DISPLAY_INFORMATION, - } - - private var isAutoSuggestEnabled: Boolean = false - private var currentState: ScribeState = ScribeState.IDLE - private lateinit var keyboardBinding: KeyboardViewKeyboardBinding override lateinit var binding: KeyboardViewCommandOptionsBinding override var keyboardView: MyKeyboardView? = null override var keyboard: MyKeyboard? = null @@ -48,41 +26,6 @@ class RussianKeyboardIME : SimpleKeyboardIME() { override var switchToLetters = false override var hasTextBeforeCursor = false - override fun onInitializeInterface() { - super.onInitializeInterface() - keyboard = MyKeyboard(this, getKeyboardLayoutXML(), enterKeyType) - } - - override fun onStartInputView( - editorInfo: EditorInfo?, - restarting: Boolean, - ) { - val sharedPref = getSharedPreferences("app_preferences", Context.MODE_PRIVATE) - val currentNightMode = resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK - val isSystemDarkMode = currentNightMode == Configuration.UI_MODE_NIGHT_YES - val isUserDarkMode = sharedPref.getBoolean("dark_mode", isSystemDarkMode) - updateEnterKeyColor(isUserDarkMode) - initializeEmojiButtons() - isAutoSuggestEnabled = sharedPref.getBoolean("emoji_suggestions_Russian", true) - updateButtonVisibility(isAutoSuggestEnabled) - setupIdleView() - 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) - } - - override fun commitPeriodAfterSpace() { - if (shouldCommitPeriodAfterSpace("Russian")) { - val inputConnection = currentInputConnection ?: return - inputConnection.deleteSurroundingText(1, 0) - inputConnection.commitText(". ", 1) - } - } - override fun onCreateInputView(): View { binding = KeyboardViewCommandOptionsBinding.inflate(layoutInflater) val keyboardHolder = binding.root @@ -97,48 +40,6 @@ class RussianKeyboardIME : SimpleKeyboardIME() { return keyboardHolder } - private fun setupIdleView() { - val sharedPref = getSharedPreferences("app_preferences", Context.MODE_PRIVATE) - val currentNightMode = resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK - val isSystemDarkMode = currentNightMode == Configuration.UI_MODE_NIGHT_YES - val isUserDarkMode = sharedPref.getBoolean("dark_mode", isSystemDarkMode) - when (isUserDarkMode) { - true -> { - binding.translateBtn.setBackgroundColor(getColor(R.color.transparent)) - binding.conjugateBtn.setBackgroundColor(getColor(R.color.transparent)) - binding.pluralBtn.setBackgroundColor(getColor(R.color.transparent)) - binding.translateBtn.setTextColor(Color.WHITE) - binding.conjugateBtn.setTextColor(Color.WHITE) - binding.pluralBtn.setTextColor(Color.WHITE) - binding.separator2.setBackgroundColor(getColor(R.color.special_key_dark)) - binding.separator3.setBackgroundColor(getColor(R.color.special_key_dark)) - } - else -> { - binding.translateBtn.setBackgroundColor(getColor(R.color.transparent)) - binding.conjugateBtn.setBackgroundColor(getColor(R.color.transparent)) - binding.pluralBtn.setBackgroundColor(getColor(R.color.transparent)) - binding.translateBtn.setTextColor(Color.BLACK) - binding.conjugateBtn.setTextColor(Color.BLACK) - binding.pluralBtn.setTextColor(Color.BLACK) - binding.separator2.setBackgroundColor(getColor(R.color.special_key_light)) - binding.separator3.setBackgroundColor(getColor(R.color.special_key_light)) - } - } - setupCommandBarTheme(binding) - binding.translateBtn.text = "Suggestion" - binding.conjugateBtn.text = "Suggestion" - binding.pluralBtn.text = "Suggestion" - binding.separator2.visibility = View.VISIBLE - binding.separator3.visibility = View.VISIBLE - binding.scribeKey.setOnClickListener { - currentState = ScribeState.SELECT_COMMAND - Log.i("MY-TAG", "SELECT COMMAND STATE") - updateButtonVisibility(false) - binding.scribeKey.foreground = getDrawable(R.drawable.close) - updateUI() - } - } - override fun onKey(code: Int) { val inputConnection = currentInputConnection if (keyboard == null || inputConnection == null) { @@ -189,100 +90,10 @@ class RussianKeyboardIME : SimpleKeyboardIME() { } } - private fun setupSelectCommandView() { - 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" - binding.separator2.visibility = View.GONE - binding.separator3.visibility = View.GONE - 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 { - currentState = ScribeState.TRANSLATE - Log.i("MY-TAG", "TRANSLATE STATE") - updateUI() - } - binding.conjugateBtn.setOnClickListener { - Log.i("MY-TAG", "CONJUGATE STATE") - currentState = ScribeState.CONJUGATE - updateUI() - } - binding.pluralBtn.setOnClickListener { - Log.i("MY-TAG", "PLURAL STATE") - currentState = ScribeState.PLURAL - updateUI() - } - } - - private fun switchToToolBar() { - val keyboardBinding = KeyboardViewKeyboardBinding.inflate(layoutInflater) - this.keyboardBinding = keyboardBinding - val keyboardHolder = keyboardBinding.root - keyboardView = keyboardBinding.keyboardView - keyboardView!!.setKeyboard(keyboard!!) - super.setupToolBarTheme(keyboardBinding) - keyboardView!!.mOnKeyboardActionListener = this - keyboardBinding.scribeKey.setOnClickListener { - currentState = ScribeState.IDLE - switchToCommandToolBar() - updateUI() - } - setInputView(keyboardHolder) - } - - 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 - keyboardBinding.scribeKey.setOnClickListener { - currentState = ScribeState.IDLE - setupSelectCommandView() - updateUI() - } - setInputView(keyboardHolder) - } - - private fun updateEnterKeyColor(isDarkMode: Boolean? = null) { - when (currentState) { - ScribeState.IDLE -> keyboardView?.setEnterKeyColor(null, isDarkMode = isDarkMode) - ScribeState.SELECT_COMMAND -> keyboardView?.setEnterKeyColor(null, isDarkMode = isDarkMode) - 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() - initializeEmojiButtons() - updateButtonVisibility(isAutoSuggestEnabled) - } - ScribeState.SELECT_COMMAND -> setupSelectCommandView() - else -> switchToToolBar() - } - val sharedPref = getSharedPreferences("app_preferences", Context.MODE_PRIVATE) - val currentNightMode = resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK - val isSystemDarkMode = currentNightMode == Configuration.UI_MODE_NIGHT_YES - val isUserDarkMode = sharedPref.getBoolean("dark_mode", isSystemDarkMode) - updateEnterKeyColor(isUserDarkMode) - } } diff --git a/app/src/main/java/be/scri/services/SimpleKeyboardIME.kt b/app/src/main/java/be/scri/services/SimpleKeyboardIME.kt index 65dde8d4..4c714935 100644 --- a/app/src/main/java/be/scri/services/SimpleKeyboardIME.kt +++ b/app/src/main/java/be/scri/services/SimpleKeyboardIME.kt @@ -2,6 +2,7 @@ package be.scri.services import android.content.Context import android.content.res.Configuration +import android.graphics.Color import android.inputmethodservice.InputMethodService import android.text.InputType import android.text.InputType.TYPE_CLASS_DATETIME @@ -9,6 +10,7 @@ import android.text.InputType.TYPE_CLASS_NUMBER import android.text.InputType.TYPE_CLASS_PHONE import android.text.InputType.TYPE_MASK_CLASS import android.text.TextUtils +import android.util.Log import android.view.KeyEvent import android.view.View import android.view.inputmethod.EditorInfo @@ -25,10 +27,12 @@ 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 : - InputMethodService(), +abstract class SimpleKeyboardIME( + var language: String, +) : InputMethodService(), MyKeyboardView.OnKeyboardActionListener { abstract fun getKeyboardLayoutXML(): Int @@ -56,7 +60,200 @@ abstract class SimpleKeyboardIME : private var emojiBtnTablet2: Button? = null private var emojiSpaceTablet2: View? = null private var emojiBtnTablet3: Button? = null -// abstract var keyboardViewKeyboardBinding : KeyboardViewKeyboardBinding + // abstract var keyboardViewKeyboardBinding : KeyboardViewKeyboardBinding + + protected var currentState: ScribeState = ScribeState.IDLE + protected lateinit var keyboardBinding: KeyboardViewKeyboardBinding + private var isAutoSuggestEnabled: Boolean = false + + enum class ScribeState { + IDLE, + SELECT_COMMAND, + TRANSLATE, + CONJUGATE, + PLURAL, + SELECT_VERB_CONJUNCTION, + SELECT_CASE_DECLENSION, + ALREADY_PLURAL, + INVALID, + DISPLAY_INFORMATION, + } + + fun getIsAccentCharacter(): Boolean { + val sharedPref = getSharedPreferences("app_preferences", Context.MODE_PRIVATE) + val isAccentCharacter = sharedPref.getBoolean("disable_accent_character_Swedish", false) + return isAccentCharacter + } + + private fun updateEnterKeyColor(isDarkMode: Boolean? = null) { + when (currentState) { + ScribeState.IDLE -> keyboardView?.setEnterKeyColor(null, isDarkMode = isDarkMode) + ScribeState.SELECT_COMMAND -> keyboardView?.setEnterKeyColor(null, isDarkMode = isDarkMode) + else -> keyboardView?.setEnterKeyColor(getColor(R.color.dark_scribe_blue)) + } + } + + override fun commitPeriodAfterSpace() { + if (getSharedPreferences("app_preferences", Context.MODE_PRIVATE) + .getBoolean("period_on_double_tap_$language", true) + ) { + val inputConnection = currentInputConnection ?: return + inputConnection.deleteSurroundingText(1, 0) + inputConnection.commitText(". ", 1) + } + } + + override fun onCreate() { + super.onCreate() + keyboard = MyKeyboard(this, getKeyboardLayoutXML(), enterKeyType) + onCreateInputView() + setupCommandBarTheme(binding) + keyboardBinding = KeyboardViewKeyboardBinding.inflate(layoutInflater) + } + + protected 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 + keyboardBinding.scribeKey.setOnClickListener { + currentState = ScribeState.IDLE + setupSelectCommandView() + updateUI() + } + setInputView(keyboardHolder) + } + + fun updateUI() { + val sharedPref = getSharedPreferences("app_preferences", Context.MODE_PRIVATE) + val currentNightMode = resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK + val isSystemDarkMode = currentNightMode == Configuration.UI_MODE_NIGHT_YES + val isUserDarkMode = sharedPref.getBoolean("dark_mode", isSystemDarkMode) + when (currentState) { + ScribeState.IDLE -> { + setupIdleView() + initializeEmojiButtons() + updateButtonVisibility(isAutoSuggestEnabled) + } + + ScribeState.SELECT_COMMAND -> setupSelectCommandView() + else -> switchToToolBar() + } + updateEnterKeyColor(isUserDarkMode) + } + + private fun switchToToolBar() { + this.keyboardBinding = initializeKeyboardBinding() + val keyboardHolder = keyboardBinding.root + setupToolBarTheme(keyboardBinding) + val sharedPref = getSharedPreferences("app_preferences", Context.MODE_PRIVATE) + val currentNightMode = resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK + val isSystemDarkMode = currentNightMode == Configuration.UI_MODE_NIGHT_YES + val isUserDarkMode = sharedPref.getBoolean("dark_mode", isSystemDarkMode) + when (isUserDarkMode) { + true -> { + keyboardBinding.topKeyboardDivider.setBackgroundColor(getColor(R.color.special_key_dark)) + } + + false -> { + keyboardBinding.topKeyboardDivider.setBackgroundColor(getColor(R.color.special_key_light)) + } + } + keyboardView = keyboardBinding.keyboardView + keyboardView!!.setKeyboard(keyboard!!) + keyboardView!!.mOnKeyboardActionListener = this + keyboardBinding.scribeKey.setOnClickListener { + currentState = ScribeState.IDLE + switchToCommandToolBar() + updateUI() + } + setInputView(keyboardHolder) + } + + private fun setupIdleView() { + val sharedPref = getSharedPreferences("app_preferences", Context.MODE_PRIVATE) + val currentNightMode = resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK + val isSystemDarkMode = currentNightMode == Configuration.UI_MODE_NIGHT_YES + val isUserDarkMode = sharedPref.getBoolean("dark_mode", isSystemDarkMode) + when (isUserDarkMode) { + true -> { + binding.translateBtn.setBackgroundColor(getColor(R.color.transparent)) + binding.conjugateBtn.setBackgroundColor(getColor(R.color.transparent)) + binding.pluralBtn.setBackgroundColor(getColor(R.color.transparent)) + binding.translateBtn.setTextColor(Color.WHITE) + binding.conjugateBtn.setTextColor(Color.WHITE) + binding.pluralBtn.setTextColor(Color.WHITE) + binding.separator2.setBackgroundColor(getColor(R.color.special_key_dark)) + binding.separator3.setBackgroundColor(getColor(R.color.special_key_dark)) + } + + else -> { + binding.translateBtn.setBackgroundColor(getColor(R.color.transparent)) + binding.conjugateBtn.setBackgroundColor(getColor(R.color.transparent)) + binding.pluralBtn.setBackgroundColor(getColor(R.color.transparent)) + binding.translateBtn.setTextColor(Color.BLACK) + binding.conjugateBtn.setTextColor(Color.BLACK) + binding.pluralBtn.setTextColor(Color.BLACK) + binding.separator2.setBackgroundColor(getColor(R.color.special_key_light)) + binding.separator3.setBackgroundColor(getColor(R.color.special_key_light)) + } + } + + setupCommandBarTheme(binding) + binding.translateBtn.text = "Suggestion" + binding.conjugateBtn.text = "Suggestion" + binding.pluralBtn.text = "Suggestion" + binding.separator2.visibility = View.VISIBLE + binding.separator3.visibility = View.VISIBLE + binding.scribeKey.setOnClickListener { + currentState = ScribeState.SELECT_COMMAND + updateButtonVisibility(false) + Log.i("MY-TAG", "SELECT COMMAND STATE") + binding.scribeKey.foreground = getDrawable(R.drawable.close) + updateUI() + } + } + + private fun setupSelectCommandView() { + 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)) + binding.translateBtn.text = "Translate" + binding.conjugateBtn.text = "Conjugate" + binding.pluralBtn.text = "Plural" + binding.separator2.visibility = View.GONE + binding.separator3.visibility = View.GONE + 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 { + currentState = ScribeState.TRANSLATE + Log.i("MY-TAG", "TRANSLATE STATE") + updateUI() + } + binding.conjugateBtn.setOnClickListener { + Log.i("MY-TAG", "CONJUGATE STATE") + currentState = ScribeState.CONJUGATE + updateUI() + } + binding.pluralBtn.setOnClickListener { + Log.i("MY-TAG", "PLURAL STATE") + currentState = ScribeState.PLURAL + updateUI() + } + } + + private fun initializeKeyboardBinding(): KeyboardViewKeyboardBinding { + val keyboardBinding = KeyboardViewKeyboardBinding.inflate(layoutInflater) + return keyboardBinding + } override fun onInitializeInterface() { super.onInitializeInterface() @@ -74,12 +271,6 @@ abstract class SimpleKeyboardIME : return lastChar != '.' } - override fun commitPeriodAfterSpace() { - val inputConnection = currentInputConnection ?: return - inputConnection.deleteSurroundingText(1, 0) - inputConnection.commitText(". ", 1) - } - override fun onCreateInputView(): View { binding = KeyboardViewCommandOptionsBinding.inflate(layoutInflater) val keyboardHolder = binding.root @@ -146,6 +337,7 @@ abstract class SimpleKeyboardIME : keyboardMode = keyboardSymbols R.xml.keys_symbols } + else -> { keyboardMode = keyboardLetters getKeyboardLayoutXML() @@ -360,7 +552,24 @@ abstract class SimpleKeyboardIME : } } - fun setupToolBarTheme(binding: KeyboardViewKeyboardBinding) { + override fun onStartInputView( + editorInfo: EditorInfo?, + restarting: Boolean, + ) { + val sharedPref = getSharedPreferences("app_preferences", Context.MODE_PRIVATE) + val currentNightMode = resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK + val isSystemDarkMode = currentNightMode == Configuration.UI_MODE_NIGHT_YES + val isUserDarkMode = sharedPref.getBoolean("dark_mode", isSystemDarkMode) + updateEnterKeyColor(isUserDarkMode) + initializeEmojiButtons() + isAutoSuggestEnabled = sharedPref.getBoolean("emoji_suggestions_$language", true) + updateButtonVisibility(isAutoSuggestEnabled) + setupIdleView() + super.onStartInputView(editorInfo, restarting) + setupCommandBarTheme(binding) + } + + private fun setupToolBarTheme(binding: KeyboardViewKeyboardBinding) { val sharedPref = getSharedPreferences("app_preferences", Context.MODE_PRIVATE) val currentNightMode = resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK val isSystemDarkMode = currentNightMode == Configuration.UI_MODE_NIGHT_YES @@ -369,6 +578,7 @@ abstract class SimpleKeyboardIME : true -> { binding.commandField.setBackgroundColor(getColor(R.color.md_grey_black_dark)) } + else -> { binding.commandField.setBackgroundColor(getColor(R.color.light_cmd_bar_border_color)) } @@ -384,6 +594,7 @@ abstract class SimpleKeyboardIME : 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 e0849cc1..e780f3c5 100644 --- a/app/src/main/java/be/scri/services/SpanishKeyboardIME.kt +++ b/app/src/main/java/be/scri/services/SpanishKeyboardIME.kt @@ -1,21 +1,15 @@ package be.scri.services -import android.content.Context -import android.content.res.Configuration -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() { +class SpanishKeyboardIME : SimpleKeyboardIME(language = "Spanish") { override fun getKeyboardLayoutXML(): Int = if (getIsAccentCharacter()) { R.xml.keys_letter_spanish_without_accent_character @@ -23,28 +17,6 @@ class SpanishKeyboardIME : SimpleKeyboardIME() { R.xml.keys_letters_spanish } - private fun getIsAccentCharacter(): Boolean { - val sharedPref = getSharedPreferences("app_preferences", Context.MODE_PRIVATE) - val isAccentCharacter = sharedPref.getBoolean("disable_accent_character_Spanish", false) - return isAccentCharacter - } - - enum class ScribeState { - IDLE, - SELECT_COMMAND, - TRANSLATE, - CONJUGATE, - PLURAL, - SELECT_VERB_CONJUNCTION, - SELECT_CASE_DECLENSION, - ALREADY_PLURAL, - INVALID, - DISPLAY_INFORMATION, - } - - private var isAutoSuggestEnabled: Boolean = false - private var currentState: ScribeState = ScribeState.IDLE - private lateinit var keyboardBinding: KeyboardViewKeyboardBinding override lateinit var binding: KeyboardViewCommandOptionsBinding override var keyboardView: MyKeyboardView? = null override var keyboard: MyKeyboard? = null @@ -59,41 +31,6 @@ class SpanishKeyboardIME : SimpleKeyboardIME() { override var switchToLetters = false override var hasTextBeforeCursor = false - 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, - ) { - val sharedPref = getSharedPreferences("app_preferences", Context.MODE_PRIVATE) - val currentNightMode = resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK - val isSystemDarkMode = currentNightMode == Configuration.UI_MODE_NIGHT_YES - val isUserDarkMode = sharedPref.getBoolean("dark_mode", isSystemDarkMode) - updateEnterKeyColor(isUserDarkMode) - initializeEmojiButtons() - isAutoSuggestEnabled = sharedPref.getBoolean("emoji_suggestions_Spanish", true) - updateButtonVisibility(isAutoSuggestEnabled) - setupIdleView() - super.onStartInputView(editorInfo, restarting) - setupCommandBarTheme(binding) - } - - override fun commitPeriodAfterSpace() { - if (shouldCommitPeriodAfterSpace("Spanish")) { - val inputConnection = currentInputConnection ?: return - inputConnection.deleteSurroundingText(1, 0) - inputConnection.commitText(". ", 1) - } - } - override fun onCreateInputView(): View { binding = KeyboardViewCommandOptionsBinding.inflate(layoutInflater) val keyboardHolder = binding.root @@ -108,49 +45,6 @@ class SpanishKeyboardIME : SimpleKeyboardIME() { return keyboardHolder } - private fun setupIdleView() { - val sharedPref = getSharedPreferences("app_preferences", Context.MODE_PRIVATE) - val currentNightMode = resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK - val isSystemDarkMode = currentNightMode == Configuration.UI_MODE_NIGHT_YES - val isUserDarkMode = sharedPref.getBoolean("dark_mode", isSystemDarkMode) - when (isUserDarkMode) { - true -> { - binding.translateBtn.setBackgroundColor(getColor(R.color.transparent)) - binding.conjugateBtn.setBackgroundColor(getColor(R.color.transparent)) - binding.pluralBtn.setBackgroundColor(getColor(R.color.transparent)) - binding.translateBtn.setTextColor(Color.WHITE) - binding.conjugateBtn.setTextColor(Color.WHITE) - binding.pluralBtn.setTextColor(Color.WHITE) - binding.separator2.setBackgroundColor(getColor(R.color.special_key_dark)) - binding.separator3.setBackgroundColor(getColor(R.color.special_key_dark)) - } - else -> { - binding.translateBtn.setBackgroundColor(getColor(R.color.transparent)) - binding.conjugateBtn.setBackgroundColor(getColor(R.color.transparent)) - binding.pluralBtn.setBackgroundColor(getColor(R.color.transparent)) - binding.translateBtn.setTextColor(Color.BLACK) - binding.conjugateBtn.setTextColor(Color.BLACK) - binding.pluralBtn.setTextColor(Color.BLACK) - binding.separator2.setBackgroundColor(getColor(R.color.special_key_light)) - binding.separator3.setBackgroundColor(getColor(R.color.special_key_light)) - } - } - - setupCommandBarTheme(binding) - binding.translateBtn.text = "Suggestion" - binding.conjugateBtn.text = "Suggestion" - binding.pluralBtn.text = "Suggestion" - binding.separator2.visibility = View.VISIBLE - binding.separator3.visibility = View.VISIBLE - binding.scribeKey.setOnClickListener { - currentState = ScribeState.SELECT_COMMAND - updateButtonVisibility(false) - Log.i("MY-TAG", "SELECT COMMAND STATE") - binding.scribeKey.foreground = getDrawable(R.drawable.close) - updateUI() - } - } - override fun onKey(code: Int) { val inputConnection = currentInputConnection if (keyboard == null || inputConnection == null) { @@ -201,104 +95,10 @@ class SpanishKeyboardIME : SimpleKeyboardIME() { } } - private fun setupSelectCommandView() { - 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" - binding.separator2.visibility = View.GONE - binding.separator3.visibility = View.GONE - 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 { - currentState = ScribeState.TRANSLATE - Log.i("MY-TAG", "TRANSLATE STATE") - updateUI() - } - binding.conjugateBtn.setOnClickListener { - Log.i("MY-TAG", "CONJUGATE STATE") - currentState = ScribeState.CONJUGATE - updateUI() - } - binding.pluralBtn.setOnClickListener { - Log.i("MY-TAG", "PLURAL STATE") - currentState = ScribeState.PLURAL - updateUI() - } - } - - private fun updateEnterKeyColor(isDarkMode: Boolean? = null) { - when (currentState) { - ScribeState.IDLE -> keyboardView?.setEnterKeyColor(null, isDarkMode = isDarkMode) - ScribeState.SELECT_COMMAND -> keyboardView?.setEnterKeyColor(null, isDarkMode = isDarkMode) - else -> keyboardView?.setEnterKeyColor(getColor(R.color.dark_scribe_blue)) - } - } - - private fun switchToToolBar() { - val keyboardBinding = initializeKeyboardBinding() - val keyboardHolder = keyboardBinding.root - keyboardView = keyboardBinding.keyboardView - super.setupToolBarTheme(keyboardBinding) - keyboardView!!.setKeyboard(keyboard!!) - keyboardView!!.mOnKeyboardActionListener = this - keyboardBinding.scribeKey.setOnClickListener { - currentState = ScribeState.IDLE - switchToCommandToolBar() - updateUI() - } - setInputView(keyboardHolder) - } - - 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 - keyboardBinding.scribeKey.setOnClickListener { - currentState = ScribeState.IDLE - setupSelectCommandView() - updateUI() - } - setInputView(keyboardHolder) - } - override fun onCreate() { super.onCreate() keyboard = MyKeyboard(this, getKeyboardLayoutXML(), enterKeyType) onCreateInputView() setupCommandBarTheme(binding) } - - private fun updateUI() { - when (currentState) { - ScribeState.IDLE -> { - setupIdleView() - initializeEmojiButtons() - updateButtonVisibility(isAutoSuggestEnabled) - } - ScribeState.SELECT_COMMAND -> setupSelectCommandView() - else -> switchToToolBar() - } - val sharedPref = getSharedPreferences("app_preferences", Context.MODE_PRIVATE) - val currentNightMode = resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK - val isSystemDarkMode = currentNightMode == Configuration.UI_MODE_NIGHT_YES - val isUserDarkMode = sharedPref.getBoolean("dark_mode", isSystemDarkMode) - updateEnterKeyColor(isUserDarkMode) - } - - private fun initializeKeyboardBinding(): KeyboardViewKeyboardBinding { - val keyboardBinding = KeyboardViewKeyboardBinding.inflate(layoutInflater) - return keyboardBinding - } } diff --git a/app/src/main/java/be/scri/services/SwedishKeyboardIME.kt b/app/src/main/java/be/scri/services/SwedishKeyboardIME.kt index e744c8ae..f1cfc41f 100644 --- a/app/src/main/java/be/scri/services/SwedishKeyboardIME.kt +++ b/app/src/main/java/be/scri/services/SwedishKeyboardIME.kt @@ -1,52 +1,22 @@ package be.scri.services -import android.content.Context -import android.content.res.Configuration -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() { +class SwedishKeyboardIME : SimpleKeyboardIME("Swedish") { override fun getKeyboardLayoutXML(): Int = if (getIsAccentCharacter()) { - Log.i("MY-TAG", getIsAccentCharacter().toString()) R.xml.keys_letter_swedish_without_accent_characters } else { - Log.i("MY-TAG", getIsAccentCharacter().toString()) R.xml.keys_letters_swedish } - private fun getIsAccentCharacter(): Boolean { - val sharedPref = getSharedPreferences("app_preferences", Context.MODE_PRIVATE) - val isAccentCharacter = sharedPref.getBoolean("disable_accent_character_Swedish", false) - return isAccentCharacter - } - - enum class ScribeState { - IDLE, - SELECT_COMMAND, - TRANSLATE, - CONJUGATE, - PLURAL, - SELECT_VERB_CONJUNCTION, - SELECT_CASE_DECLENSION, - ALREADY_PLURAL, - INVALID, - DISPLAY_INFORMATION, - } - - private var isAutoSuggestEnabled: Boolean = false - private var currentState: ScribeState = ScribeState.IDLE - private lateinit var keyboardBinding: KeyboardViewKeyboardBinding override lateinit var binding: KeyboardViewCommandOptionsBinding override var keyboardView: MyKeyboardView? = null override var keyboard: MyKeyboard? = null @@ -61,41 +31,6 @@ class SwedishKeyboardIME : SimpleKeyboardIME() { override var switchToLetters = false override var hasTextBeforeCursor = false - 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, - ) { - val sharedPref = getSharedPreferences("app_preferences", Context.MODE_PRIVATE) - val currentNightMode = resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK - val isSystemDarkMode = currentNightMode == Configuration.UI_MODE_NIGHT_YES - val isUserDarkMode = sharedPref.getBoolean("dark_mode", isSystemDarkMode) - updateEnterKeyColor(isUserDarkMode) - initializeEmojiButtons() - isAutoSuggestEnabled = sharedPref.getBoolean("emoji_suggestions_Swedish", true) - updateButtonVisibility(isAutoSuggestEnabled) - setupIdleView() - super.onStartInputView(editorInfo, restarting) - setupCommandBarTheme(binding) - } - - override fun commitPeriodAfterSpace() { - if (shouldCommitPeriodAfterSpace("Swedish")) { - val inputConnection = currentInputConnection ?: return - inputConnection.deleteSurroundingText(1, 0) - inputConnection.commitText(". ", 1) - } - } - override fun onKey(code: Int) { val inputConnection = currentInputConnection if (keyboard == null || inputConnection == null) { @@ -160,142 +95,10 @@ class SwedishKeyboardIME : SimpleKeyboardIME() { return keyboardHolder } - private fun setupIdleView() { - val sharedPref = getSharedPreferences("app_preferences", Context.MODE_PRIVATE) - val currentNightMode = resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK - val isSystemDarkMode = currentNightMode == Configuration.UI_MODE_NIGHT_YES - val isUserDarkMode = sharedPref.getBoolean("dark_mode", isSystemDarkMode) - when (isUserDarkMode) { - true -> { - binding.translateBtn.setBackgroundColor(getColor(R.color.transparent)) - binding.conjugateBtn.setBackgroundColor(getColor(R.color.transparent)) - binding.pluralBtn.setBackgroundColor(getColor(R.color.transparent)) - binding.translateBtn.setTextColor(Color.WHITE) - binding.conjugateBtn.setTextColor(Color.WHITE) - binding.pluralBtn.setTextColor(Color.WHITE) - binding.separator2.setBackgroundColor(getColor(R.color.special_key_dark)) - binding.separator3.setBackgroundColor(getColor(R.color.special_key_dark)) - } - else -> { - binding.translateBtn.setBackgroundColor(getColor(R.color.transparent)) - binding.conjugateBtn.setBackgroundColor(getColor(R.color.transparent)) - binding.pluralBtn.setBackgroundColor(getColor(R.color.transparent)) - binding.translateBtn.setTextColor(Color.BLACK) - binding.conjugateBtn.setTextColor(Color.BLACK) - binding.pluralBtn.setTextColor(Color.BLACK) - binding.separator2.setBackgroundColor(getColor(R.color.special_key_light)) - binding.separator3.setBackgroundColor(getColor(R.color.special_key_light)) - } - } - setupCommandBarTheme(binding) - binding.translateBtn.text = "Suggestion" - binding.conjugateBtn.text = "Suggestion" - binding.pluralBtn.text = "Suggestion" - binding.separator2.visibility = View.VISIBLE - binding.separator3.visibility = View.VISIBLE - binding.scribeKey.setOnClickListener { - currentState = ScribeState.SELECT_COMMAND - Log.i("MY-TAG", "SELECT COMMAND STATE") - updateButtonVisibility(false) - binding.scribeKey.foreground = getDrawable(R.drawable.close) - updateUI() - } - } - - private fun setupSelectCommandView() { - 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" - binding.separator2.visibility = View.GONE - binding.separator3.visibility = View.GONE - 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 { - currentState = ScribeState.TRANSLATE - Log.i("MY-TAG", "TRANSLATE STATE") - updateUI() - } - binding.conjugateBtn.setOnClickListener { - Log.i("MY-TAG", "CONJUGATE STATE") - currentState = ScribeState.CONJUGATE - updateUI() - } - binding.pluralBtn.setOnClickListener { - Log.i("MY-TAG", "PLURAL STATE") - currentState = ScribeState.PLURAL - updateUI() - } - } - - 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 { - currentState = ScribeState.IDLE - switchToCommandToolBar() - updateUI() - } - setInputView(keyboardHolder) - } - - private fun updateEnterKeyColor(isDarkMode: Boolean? = null) { - when (currentState) { - ScribeState.IDLE -> keyboardView?.setEnterKeyColor(null, isDarkMode = isDarkMode) - ScribeState.SELECT_COMMAND -> keyboardView?.setEnterKeyColor(null, isDarkMode = isDarkMode) - 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 - keyboardBinding.scribeKey.setOnClickListener { - currentState = ScribeState.IDLE - setupSelectCommandView() - updateUI() - } - setInputView(keyboardHolder) - } - override fun onCreate() { super.onCreate() keyboard = MyKeyboard(this, getKeyboardLayoutXML(), enterKeyType) onCreateInputView() setupCommandBarTheme(binding) } - - private fun updateUI() { - when (currentState) { - ScribeState.IDLE -> { - setupIdleView() - initializeEmojiButtons() - updateButtonVisibility(isAutoSuggestEnabled) - } - ScribeState.SELECT_COMMAND -> setupSelectCommandView() - else -> switchToToolBar() - } - val sharedPref = getSharedPreferences("app_preferences", Context.MODE_PRIVATE) - val currentNightMode = resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK - val isSystemDarkMode = currentNightMode == Configuration.UI_MODE_NIGHT_YES - val isUserDarkMode = sharedPref.getBoolean("dark_mode", isSystemDarkMode) - updateEnterKeyColor(isUserDarkMode) - } }