From 5058167c04d726a60d6b4a7a87d7d1c82527de79 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sat, 29 Jan 2022 20:38:31 +0100 Subject: [PATCH] use better stroke color at pure White or Black backgrounds --- .../keyboard/views/MyKeyboardView.kt | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) 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 a77e0fc..abe0a1e 100644 --- a/app/src/main/kotlin/com/simplemobiletools/keyboard/views/MyKeyboardView.kt +++ b/app/src/main/kotlin/com/simplemobiletools/keyboard/views/MyKeyboardView.kt @@ -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()