Skip to content

Commit

Permalink
fix:Corrected the keyboard color and keys colors based on condtions
Browse files Browse the repository at this point in the history
  • Loading branch information
angrezichatterbox committed Sep 21, 2024
1 parent 88b765a commit cc7f1bf
Show file tree
Hide file tree
Showing 13 changed files with 461 additions and 49 deletions.
63 changes: 54 additions & 9 deletions app/src/main/java/be/scri/services/EnglishKeyboardIME.kt
Original file line number Diff line number Diff line change
@@ -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() {
Expand Down Expand Up @@ -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
Expand All @@ -65,20 +71,38 @@ 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()
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 = ""
Expand All @@ -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 {
Expand All @@ -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) {
Expand Down Expand Up @@ -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
Expand All @@ -167,13 +202,15 @@ class EnglishKeyboardIME : SimpleKeyboardIME() {
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
Expand All @@ -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()
}
}
50 changes: 47 additions & 3 deletions app/src/main/java/be/scri/services/FrenchKeyboardIME.kt
Original file line number Diff line number Diff line change
@@ -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() {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -102,16 +113,30 @@ 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()
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 = ""
Expand All @@ -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"
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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()
}
}
50 changes: 47 additions & 3 deletions app/src/main/java/be/scri/services/GermanKeyboardIME.kt
Original file line number Diff line number Diff line change
@@ -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() {
Expand Down Expand Up @@ -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)
Expand All @@ -67,16 +78,30 @@ 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()
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 = ""
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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()
}
}
Loading

0 comments on commit cc7f1bf

Please sign in to comment.