use better stroke color at pure White or Black backgrounds

This commit is contained in:
tibbi 2022-01-29 20:38:31 +01:00
parent 7a48011aa4
commit 5058167c04
1 changed files with 11 additions and 2 deletions

View File

@ -272,7 +272,7 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
if (changedView == mini_keyboard_view) {
val previewBackground = background as LayerDrawable
previewBackground.findDrawableByLayerId(R.id.button_background_shape).applyColorFilter(mBackgroundColor.darkenColor(4))
previewBackground.findDrawableByLayerId(R.id.button_background_stroke).applyColorFilter(mBackgroundColor.lightenColor())
previewBackground.findDrawableByLayerId(R.id.button_background_stroke).applyColorFilter(getPreviewStrokeColor())
background = previewBackground
} else {
background.applyColorFilter(mBackgroundColor.darkenColor(2))
@ -819,7 +819,7 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
val previewBackground = mPreviewText!!.background as LayerDrawable
previewBackground.findDrawableByLayerId(R.id.button_background_shape).applyColorFilter(mBackgroundColor.darkenColor(4))
previewBackground.findDrawableByLayerId(R.id.button_background_stroke).applyColorFilter(mBackgroundColor.lightenColor())
previewBackground.findDrawableByLayerId(R.id.button_background_stroke).applyColorFilter(getPreviewStrokeColor())
mPreviewText!!.background = previewBackground
mPreviewText!!.setTextColor(mTextColor)
@ -1379,6 +1379,15 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
mClipboardManagerHolder?.clips_list?.adapter = adapter
}
// stroke is usually the lighter version of the background color, but if it becomes white or black, it might be invisible. So use light grey there.
private fun getPreviewStrokeColor(): Int {
var strokeColor = mBackgroundColor.lightenColor()
if (strokeColor == Color.WHITE || strokeColor == Color.BLACK) {
strokeColor = resources.getColor(R.color.divider_grey)
}
return strokeColor
}
private fun closing() {
if (mPreviewPopup.isShowing) {
mPreviewPopup.dismiss()