From 21de46fc1dd542d2c4219e022001bb4ba54d0e19 Mon Sep 17 00:00:00 2001 From: tibbi Date: Mon, 17 Jan 2022 22:40:10 +0100 Subject: [PATCH] more color updating --- .../keyboard/views/MyKeyboardView.kt | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/app/src/main/kotlin/com/simplemobiletools/keyboard/views/MyKeyboardView.kt b/app/src/main/kotlin/com/simplemobiletools/keyboard/views/MyKeyboardView.kt index 200e061..f7114ae 100644 --- a/app/src/main/kotlin/com/simplemobiletools/keyboard/views/MyKeyboardView.kt +++ b/app/src/main/kotlin/com/simplemobiletools/keyboard/views/MyKeyboardView.kt @@ -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())