From 57b34876f09e5838d16047e621cb6e597d3a7961 Mon Sep 17 00:00:00 2001 From: Dmitriy Chernysh Date: Sat, 14 Oct 2023 15:55:47 +0300 Subject: [PATCH 1/3] Autofill crash. Tested with Bitwarden. Fix #248 --- .../keyboard/services/SimpleKeyboardIME.kt | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/keyboard/services/SimpleKeyboardIME.kt b/app/src/main/kotlin/com/simplemobiletools/keyboard/services/SimpleKeyboardIME.kt index 88adcd8..42122be 100644 --- a/app/src/main/kotlin/com/simplemobiletools/keyboard/services/SimpleKeyboardIME.kt +++ b/app/src/main/kotlin/com/simplemobiletools/keyboard/services/SimpleKeyboardIME.kt @@ -2,6 +2,7 @@ package com.simplemobiletools.keyboard.services import android.annotation.SuppressLint import android.content.SharedPreferences +import android.graphics.Bitmap import android.graphics.drawable.Icon import android.graphics.drawable.LayerDrawable import android.graphics.drawable.RippleDrawable @@ -38,6 +39,7 @@ import com.simplemobiletools.keyboard.extensions.safeStorageContext import com.simplemobiletools.keyboard.helpers.* import com.simplemobiletools.keyboard.interfaces.OnKeyboardActionListener import com.simplemobiletools.keyboard.views.MyKeyboardView +import java.io.ByteArrayOutputStream import java.util.Locale // based on https://www.androidauthority.com/lets-build-custom-keyboard-android-832362/ @@ -435,10 +437,12 @@ class SimpleKeyboardIME : InputMethodService(), OnKeyboardActionListener, Shared val maxWidth = resources.getDimensionPixelSize(R.dimen.suggestion_max_width) val height = resources.getDimensionPixelSize(R.dimen.label_text_size) + verticalPadding * 2 + val chipBackgroundIcon: Icon = rippleBg.toBitmap(width = maxWidth, height = height).toIcon() val chipStyle = ViewStyle.Builder() - .setBackground(Icon.createWithBitmap(rippleBg.toBitmap(width = maxWidth, height = height))) + //Don't use Icon.createWithBitmap(), it crashes the app. Issue https://github.com/SimpleMobileTools/Simple-Keyboard/issues/248 + .setBackground(chipBackgroundIcon) .setPadding(horizontalPadding, verticalPadding, horizontalPadding, verticalPadding) .build() @@ -471,4 +475,14 @@ class SimpleKeyboardIME : InputMethodService(), OnKeyboardActionListener, Shared override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences?, key: String?) { keyboardView?.setupKeyboard() } + + private fun Bitmap.toIcon(): Icon { + val byteArray: ByteArray = ByteArrayOutputStream().let { outputStream -> + this.compress(Bitmap.CompressFormat.PNG, 100, outputStream) + outputStream.toByteArray() + } + this.recycle() + + return Icon.createWithData(byteArray, 0, byteArray.size) + } } From e74c76b59fdbb4bc886f656c7e24f3bf55a9cf04 Mon Sep 17 00:00:00 2001 From: Dmitriy Chernysh Date: Sat, 14 Oct 2023 17:52:44 +0300 Subject: [PATCH 2/3] Fix. If setting "Show numbers on a separate row" is turned ON, small top special characters are not displayed for numeric keyboard --- .../com/simplemobiletools/keyboard/views/MyKeyboardView.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 74bc370..4caeb5b 100644 --- a/app/src/main/kotlin/com/simplemobiletools/keyboard/views/MyKeyboardView.kt +++ b/app/src/main/kotlin/com/simplemobiletools/keyboard/views/MyKeyboardView.kt @@ -598,7 +598,7 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut label, (key.width / 2).toFloat(), key.height / 2 + (paint.textSize - paint.descent()) / 2, paint ) - if (key.topSmallNumber.isNotEmpty() && !context.config.showNumbersRow) { + if (key.topSmallNumber.isNotEmpty() && !(context.config.showNumbersRow && Regex("\\d").matches(key.topSmallNumber))) { canvas.drawText(key.topSmallNumber, key.width - mTopSmallNumberMarginWidth, mTopSmallNumberMarginHeight, smallLetterPaint) } From 079c69f8d34dbd407ade71a3e3649eef15a78713 Mon Sep 17 00:00:00 2001 From: Tibor Kaputa Date: Sat, 14 Oct 2023 21:07:10 +0200 Subject: [PATCH 3/3] Update SimpleKeyboardIME.kt --- .../simplemobiletools/keyboard/services/SimpleKeyboardIME.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/keyboard/services/SimpleKeyboardIME.kt b/app/src/main/kotlin/com/simplemobiletools/keyboard/services/SimpleKeyboardIME.kt index 42122be..500b08d 100644 --- a/app/src/main/kotlin/com/simplemobiletools/keyboard/services/SimpleKeyboardIME.kt +++ b/app/src/main/kotlin/com/simplemobiletools/keyboard/services/SimpleKeyboardIME.kt @@ -441,7 +441,7 @@ class SimpleKeyboardIME : InputMethodService(), OnKeyboardActionListener, Shared val chipStyle = ViewStyle.Builder() - //Don't use Icon.createWithBitmap(), it crashes the app. Issue https://github.com/SimpleMobileTools/Simple-Keyboard/issues/248 + // don't use Icon.createWithBitmap(), it crashes the app. Issue https://github.com/SimpleMobileTools/Simple-Keyboard/issues/248 .setBackground(chipBackgroundIcon) .setPadding(horizontalPadding, verticalPadding, horizontalPadding, verticalPadding) .build()