more color updating

This commit is contained in:
tibbi 2022-01-17 22:40:10 +01:00
parent e8adf2e9ff
commit 21de46fc1d

View file

@ -20,6 +20,7 @@ import android.widget.TextView
import com.simplemobiletools.commons.extensions.adjustAlpha
import com.simplemobiletools.commons.extensions.applyColorFilter
import com.simplemobiletools.commons.extensions.getAdjustedPrimaryColor
import com.simplemobiletools.commons.extensions.getContrastColor
import com.simplemobiletools.keyboard.R
import com.simplemobiletools.keyboard.extensions.config
import com.simplemobiletools.keyboard.helpers.*
@ -343,6 +344,15 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
}
}
override fun onVisibilityChanged(changedView: View, visibility: Int) {
super.onVisibilityChanged(changedView, visibility)
if (visibility == VISIBLE) {
mTextColor = context.config.textColor
mBackgroundColor = context.config.backgroundColor
mPrimaryColor = context.getAdjustedPrimaryColor()
}
}
private fun initGestureDetector() {
if (mGestureDetector == null) {
mGestureDetector = GestureDetector(context, object : SimpleOnGestureListener() {
@ -621,6 +631,12 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
paint.typeface = Typeface.DEFAULT
}
paint.color = if (key.focused) {
mPrimaryColor.getContrastColor()
} else {
mKeyTextColor
}
// Draw the text
canvas.drawText(
label, ((key.width - padding.left - padding.right) / 2 + padding.left).toFloat(),
@ -643,6 +659,10 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
key.icon = resources.getDrawable(drawableId)
}
if (code == MyKeyboard.KEYCODE_ENTER) {
key.icon!!.applyColorFilter(mPrimaryColor.getContrastColor())
}
val drawableX = (key.width - key.icon!!.intrinsicWidth) / 2
val drawableY = (key.height - key.icon!!.intrinsicHeight) / 2
canvas.translate(drawableX.toFloat(), drawableY.toFloat())