apply the primary color wherever needed

This commit is contained in:
tibbi 2022-01-17 22:22:00 +01:00
parent 9f4547c1f2
commit 69bb719aa9

View File

@ -18,7 +18,10 @@ import android.view.accessibility.AccessibilityManager
import android.widget.PopupWindow import android.widget.PopupWindow
import android.widget.TextView import android.widget.TextView
import com.simplemobiletools.commons.extensions.adjustAlpha import com.simplemobiletools.commons.extensions.adjustAlpha
import com.simplemobiletools.commons.extensions.applyColorFilter
import com.simplemobiletools.commons.extensions.getAdjustedPrimaryColor
import com.simplemobiletools.keyboard.R import com.simplemobiletools.keyboard.R
import com.simplemobiletools.keyboard.extensions.config
import com.simplemobiletools.keyboard.helpers.* import com.simplemobiletools.keyboard.helpers.*
import java.util.* import java.util.*
@ -108,6 +111,10 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
private var mShadowColor = 0 private var mShadowColor = 0
private val mBackgroundDimAmount: Float private val mBackgroundDimAmount: Float
private var mTextColor = 0
private var mBackgroundColor = 0
private var mPrimaryColor = 0
private var mPreviewText: TextView? = null private var mPreviewText: TextView? = null
private val mPreviewPopup: PopupWindow private val mPreviewPopup: PopupWindow
private var mPreviewTextSizeLarge = 0 private var mPreviewTextSizeLarge = 0
@ -276,6 +283,10 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
attributes.recycle() attributes.recycle()
} }
mTextColor = context.config.textColor
mBackgroundColor = context.config.backgroundColor
mPrimaryColor = context.getAdjustedPrimaryColor()
mBackgroundDimAmount = 0.5f mBackgroundDimAmount = 0.5f
mPreviewPopup = PopupWindow(context) mPreviewPopup = PopupWindow(context)
if (previewLayout != 0) { if (previewLayout != 0) {
@ -573,10 +584,11 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
continue continue
} }
val code = key.codes.firstOrNull() ?: -100
var keyBackground = mKeyBackground var keyBackground = mKeyBackground
if (key.codes.firstOrNull() == MyKeyboard.KEYCODE_SPACE) { if (code == MyKeyboard.KEYCODE_SPACE) {
keyBackground = resources.getDrawable(R.drawable.keyboard_space_background, context.theme) keyBackground = resources.getDrawable(R.drawable.keyboard_space_background, context.theme)
} else if (key.codes.firstOrNull() == MyKeyboard.KEYCODE_ENTER) { } else if (code == MyKeyboard.KEYCODE_ENTER) {
keyBackground = resources.getDrawable(R.drawable.keyboard_enter_background, context.theme) keyBackground = resources.getDrawable(R.drawable.keyboard_enter_background, context.theme)
} }
@ -593,6 +605,10 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
else -> intArrayOf() else -> intArrayOf()
} }
if (key.focused || code == MyKeyboard.KEYCODE_ENTER) {
keyBackground.applyColorFilter(mPrimaryColor)
}
canvas.translate((key.x + kbdPaddingLeft).toFloat(), (key.y + kbdPaddingTop).toFloat()) canvas.translate((key.x + kbdPaddingLeft).toFloat(), (key.y + kbdPaddingTop).toFloat())
keyBackground.draw(canvas) keyBackground.draw(canvas)
if (label?.isNotEmpty() == true) { if (label?.isNotEmpty() == true) {