From d797ba33c3ea1b4ef196dd70fe75a920028aa158 Mon Sep 17 00:00:00 2001 From: ismailnurudeen Date: Wed, 8 Feb 2023 17:27:55 +0100 Subject: [PATCH 1/7] feat: added secondary icon attribute to key. --- .../keyboard/helpers/MyKeyboard.kt | 22 +++++++++---- .../keyboard/views/MyKeyboardView.kt | 32 +++++++++++++++---- app/src/main/res/values/attrs.xml | 2 ++ 3 files changed, 43 insertions(+), 13 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/keyboard/helpers/MyKeyboard.kt b/app/src/main/kotlin/com/simplemobiletools/keyboard/helpers/MyKeyboard.kt index a442d03..69d37b3 100644 --- a/app/src/main/kotlin/com/simplemobiletools/keyboard/helpers/MyKeyboard.kt +++ b/app/src/main/kotlin/com/simplemobiletools/keyboard/helpers/MyKeyboard.kt @@ -138,6 +138,9 @@ class MyKeyboard { /** Icon to display instead of a label. Icon takes precedence over a label */ var icon: Drawable? = null + /** Icon to display top left of an icon.*/ + var secondaryIcon: Drawable? = null + /** Width of the key, not including the gap */ var width: Int @@ -204,6 +207,9 @@ class MyKeyboard { icon = a.getDrawable(R.styleable.MyKeyboard_Key_keyIcon) icon?.setBounds(0, 0, icon!!.intrinsicWidth, icon!!.intrinsicHeight) + secondaryIcon = a.getDrawable(R.styleable.MyKeyboard_Key_secondaryKeyIcon) + secondaryIcon?.setBounds(0, 0, secondaryIcon!!.intrinsicWidth, secondaryIcon!!.intrinsicHeight) + label = a.getText(R.styleable.MyKeyboard_Key_keyLabel) ?: "" topSmallNumber = a.getString(R.styleable.MyKeyboard_Key_topSmallNumber) ?: "" @@ -230,10 +236,12 @@ class MyKeyboard { fun isInside(x: Int, y: Int): Boolean { val leftEdge = edgeFlags and EDGE_LEFT > 0 val rightEdge = edgeFlags and EDGE_RIGHT > 0 - return ((x >= this.x || leftEdge && x <= this.x + width) - && (x < this.x + width || rightEdge && x >= this.x) - && (y >= this.y && y <= this.y + height) - && (y < this.y + height && y >= this.y)) + return ( + (x >= this.x || leftEdge && x <= this.x + width) && + (x < this.x + width || rightEdge && x >= this.x) && + (y >= this.y && y <= this.y + height) && + (y < this.y + height && y >= this.y) + ) } } @@ -249,7 +257,7 @@ class MyKeyboard { mDefaultHorizontalGap = 0 mDefaultWidth = mDisplayWidth / 10 mDefaultHeight = mDefaultWidth - mKeyboardHeightMultiplier = getKeyboardHeightMultiplier(context.config.keyboardHeightMultiplier); + mKeyboardHeightMultiplier = getKeyboardHeightMultiplier(context.config.keyboardHeightMultiplier) mKeys = ArrayList() mEnterKeyType = enterKeyType loadKeyboard(context, context.resources.getXml(xmlLayoutResId)) @@ -273,7 +281,7 @@ class MyKeyboard { row.defaultHeight = mDefaultHeight row.defaultWidth = keyWidth row.defaultHorizontalGap = mDefaultHorizontalGap - mKeyboardHeightMultiplier = getKeyboardHeightMultiplier(context.config.keyboardHeightMultiplier); + mKeyboardHeightMultiplier = getKeyboardHeightMultiplier(context.config.keyboardHeightMultiplier) characters.forEachIndexed { index, character -> val key = Key(row) @@ -386,7 +394,7 @@ class MyKeyboard { } private fun getKeyboardHeightMultiplier(multiplierType: Int): Float { - return when(multiplierType) { + return when (multiplierType) { KEYBOARD_HEIGHT_MULTIPLIER_SMALL -> 1.0F KEYBOARD_HEIGHT_MULTIPLIER_MEDIUM -> 1.2F KEYBOARD_HEIGHT_MULTIPLIER_LARGE -> 1.4F 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 c4d8ea9..9121603 100644 --- a/app/src/main/kotlin/com/simplemobiletools/keyboard/views/MyKeyboardView.kt +++ b/app/src/main/kotlin/com/simplemobiletools/keyboard/views/MyKeyboardView.kt @@ -612,13 +612,33 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut } else if (code == KEYCODE_DELETE || code == KEYCODE_SHIFT || code == KEYCODE_EMOJI) { key.icon!!.applyColorFilter(mTextColor) } + val keyIcon = key.icon!! + val secondaryIcon = key.secondaryIcon - val drawableX = (key.width - key.icon!!.intrinsicWidth) / 2 - val drawableY = (key.height - key.icon!!.intrinsicHeight) / 2 - canvas.translate(drawableX.toFloat(), drawableY.toFloat()) - key.icon!!.setBounds(0, 0, key.icon!!.intrinsicWidth, key.icon!!.intrinsicHeight) - key.icon!!.draw(canvas) - canvas.translate(-drawableX.toFloat(), -drawableY.toFloat()) + if (secondaryIcon != null) { + val keyIconWidth = keyIcon.intrinsicWidth * 1 + val keyIconHeight = keyIcon.intrinsicWidth * 1 + val secondaryIconWidth = (secondaryIcon.intrinsicWidth * 0.6).toInt() + val secondaryIconHeight = (secondaryIcon.intrinsicHeight * 0.6).toInt() + + secondaryIcon.setBounds(key.width - secondaryIconWidth, 0, key.width, secondaryIconHeight) + secondaryIcon.draw(canvas) + + val drawableX = (key.width - keyIconWidth) / 2 + val drawableY = (key.height - keyIconHeight) / 2 + canvas.translate(drawableX.toFloat(), drawableY.toFloat() / 1.5f) + + keyIcon.setBounds(0, 0, keyIconWidth, keyIconHeight) + keyIcon.draw(canvas) + canvas.translate(-drawableX.toFloat(), -drawableY.toFloat()) + } else { + val drawableX = (key.width - keyIcon.intrinsicWidth) / 2 + val drawableY = (key.height - keyIcon.intrinsicHeight) / 2 + canvas.translate(drawableX.toFloat(), drawableY.toFloat()) + keyIcon.setBounds(0, 0, keyIcon.intrinsicWidth, keyIcon.intrinsicHeight) + keyIcon.draw(canvas) + canvas.translate(-drawableX.toFloat(), -drawableY.toFloat()) + } } canvas.translate(-key.x.toFloat(), -key.y.toFloat()) } diff --git a/app/src/main/res/values/attrs.xml b/app/src/main/res/values/attrs.xml index 79cbc9e..695614c 100644 --- a/app/src/main/res/values/attrs.xml +++ b/app/src/main/res/values/attrs.xml @@ -33,6 +33,8 @@ + + From eb8adc9a1a326017f0ae975de4646f154e3de4d0 Mon Sep 17 00:00:00 2001 From: ismailnurudeen Date: Wed, 8 Feb 2023 17:29:15 +0100 Subject: [PATCH 2/7] feat: added globe icon to emoji key to indicate language changeable. --- app/src/main/res/drawable/ic_language_outlined.xml | 5 +++++ app/src/main/res/xml/keys_letters_bengali.xml | 1 + app/src/main/res/xml/keys_letters_bulgarian.xml | 1 + app/src/main/res/xml/keys_letters_english_dvorak.xml | 1 + app/src/main/res/xml/keys_letters_english_qwerty.xml | 1 + app/src/main/res/xml/keys_letters_english_qwertz.xml | 1 + app/src/main/res/xml/keys_letters_french.xml | 1 + app/src/main/res/xml/keys_letters_german.xml | 1 + app/src/main/res/xml/keys_letters_greek.xml | 1 + app/src/main/res/xml/keys_letters_lithuanian.xml | 1 + app/src/main/res/xml/keys_letters_romanian.xml | 1 + app/src/main/res/xml/keys_letters_russian.xml | 1 + app/src/main/res/xml/keys_letters_slovenian.xml | 1 + app/src/main/res/xml/keys_letters_spanish_qwerty.xml | 1 + app/src/main/res/xml/keys_letters_turkish_q.xml | 1 + 15 files changed, 19 insertions(+) create mode 100644 app/src/main/res/drawable/ic_language_outlined.xml diff --git a/app/src/main/res/drawable/ic_language_outlined.xml b/app/src/main/res/drawable/ic_language_outlined.xml new file mode 100644 index 0000000..b7f1596 --- /dev/null +++ b/app/src/main/res/drawable/ic_language_outlined.xml @@ -0,0 +1,5 @@ + + + diff --git a/app/src/main/res/xml/keys_letters_bengali.xml b/app/src/main/res/xml/keys_letters_bengali.xml index 7c83c21..423caae 100644 --- a/app/src/main/res/xml/keys_letters_bengali.xml +++ b/app/src/main/res/xml/keys_letters_bengali.xml @@ -162,6 +162,7 @@ app:code="-6" app:keyEdgeFlags="left" app:keyIcon="@drawable/ic_emoji_emotions_outline_vector" + app:secondaryKeyIcon="@drawable/ic_language_outlined" app:keyWidth="10%p" /> Date: Wed, 8 Feb 2023 17:56:17 +0100 Subject: [PATCH 3/7] fix: added paddingTop to secondaryIcon and aligned it properly. --- .../keyboard/views/MyKeyboardView.kt | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 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 9121603..35ffb4d 100644 --- a/app/src/main/kotlin/com/simplemobiletools/keyboard/views/MyKeyboardView.kt +++ b/app/src/main/kotlin/com/simplemobiletools/keyboard/views/MyKeyboardView.kt @@ -616,17 +616,19 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut val secondaryIcon = key.secondaryIcon if (secondaryIcon != null) { - val keyIconWidth = keyIcon.intrinsicWidth * 1 - val keyIconHeight = keyIcon.intrinsicWidth * 1 - val secondaryIconWidth = (secondaryIcon.intrinsicWidth * 0.6).toInt() - val secondaryIconHeight = (secondaryIcon.intrinsicHeight * 0.6).toInt() + val keyIconWidth = keyIcon.intrinsicWidth + val keyIconHeight = keyIcon.intrinsicWidth + val secondaryIconWidth = (secondaryIcon.intrinsicWidth * .6).toInt() + val secondaryIconHeight = (secondaryIcon.intrinsicHeight * .6).toInt() - secondaryIcon.setBounds(key.width - secondaryIconWidth, 0, key.width, secondaryIconHeight) + val paddingTop = 16 // Add padding top to secondaryIcon + secondaryIcon.setBounds(key.width - secondaryIconWidth, paddingTop, key.width, secondaryIconHeight + paddingTop) secondaryIcon.draw(canvas) val drawableX = (key.width - keyIconWidth) / 2 val drawableY = (key.height - keyIconHeight) / 2 - canvas.translate(drawableX.toFloat(), drawableY.toFloat() / 1.5f) + + canvas.translate(drawableX.toFloat(), drawableY.toFloat()) keyIcon.setBounds(0, 0, keyIconWidth, keyIconHeight) keyIcon.draw(canvas) From b14f7c67cc7ad5d8cdd2a899f6d3207dc1e533a2 Mon Sep 17 00:00:00 2001 From: ismailnurudeen Date: Fri, 10 Feb 2023 10:41:10 +0100 Subject: [PATCH 4/7] fix: set secondaryIcon color to textColor --- .../com/simplemobiletools/keyboard/views/MyKeyboardView.kt | 2 ++ 1 file changed, 2 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 35ffb4d..6d232cf 100644 --- a/app/src/main/kotlin/com/simplemobiletools/keyboard/views/MyKeyboardView.kt +++ b/app/src/main/kotlin/com/simplemobiletools/keyboard/views/MyKeyboardView.kt @@ -609,8 +609,10 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut if (code == KEYCODE_ENTER) { key.icon!!.applyColorFilter(mPrimaryColor.getContrastColor()) + key.secondaryIcon?.applyColorFilter(mPrimaryColor.getContrastColor()) } else if (code == KEYCODE_DELETE || code == KEYCODE_SHIFT || code == KEYCODE_EMOJI) { key.icon!!.applyColorFilter(mTextColor) + key.secondaryIcon?.applyColorFilter(mTextColor) } val keyIcon = key.icon!! val secondaryIcon = key.secondaryIcon From 9eed3982e01567108d61a3a13dc1679d98ca62b4 Mon Sep 17 00:00:00 2001 From: ismailnurudeen Date: Fri, 10 Feb 2023 10:42:55 +0100 Subject: [PATCH 5/7] fix: reduced primary icon size and made secondary icon relative to primary icon. --- .../keyboard/views/MyKeyboardView.kt | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 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 6d232cf..65404c3 100644 --- a/app/src/main/kotlin/com/simplemobiletools/keyboard/views/MyKeyboardView.kt +++ b/app/src/main/kotlin/com/simplemobiletools/keyboard/views/MyKeyboardView.kt @@ -618,14 +618,10 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut val secondaryIcon = key.secondaryIcon if (secondaryIcon != null) { - val keyIconWidth = keyIcon.intrinsicWidth - val keyIconHeight = keyIcon.intrinsicWidth - val secondaryIconWidth = (secondaryIcon.intrinsicWidth * .6).toInt() - val secondaryIconHeight = (secondaryIcon.intrinsicHeight * .6).toInt() - - val paddingTop = 16 // Add padding top to secondaryIcon - secondaryIcon.setBounds(key.width - secondaryIconWidth, paddingTop, key.width, secondaryIconHeight + paddingTop) - secondaryIcon.draw(canvas) + val keyIconWidth = (keyIcon.intrinsicWidth * .8).toInt() + val keyIconHeight = (keyIcon.intrinsicWidth * .8).toInt() + val secondaryIconWidth = (secondaryIcon.intrinsicWidth * .4).toInt() + val secondaryIconHeight = (secondaryIcon.intrinsicHeight * .4).toInt() val drawableX = (key.width - keyIconWidth) / 2 val drawableY = (key.height - keyIconHeight) / 2 @@ -634,6 +630,17 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut keyIcon.setBounds(0, 0, keyIconWidth, keyIconHeight) keyIcon.draw(canvas) + + val secIconPaddingBottom = 8 + val secIconPaddingRight = 4 + secondaryIcon.setBounds( + keyIconWidth - secIconPaddingRight, + -secIconPaddingBottom, + (keyIconWidth + secondaryIconWidth) - secIconPaddingRight, + secondaryIconHeight - secIconPaddingBottom + ) + secondaryIcon.draw(canvas) + canvas.translate(-drawableX.toFloat(), -drawableY.toFloat()) } else { val drawableX = (key.width - keyIcon.intrinsicWidth) / 2 From ec9625b8f8ef457eb49164d68486e942b0a4135c Mon Sep 17 00:00:00 2001 From: ismailnurudeen Date: Sat, 11 Feb 2023 22:23:02 +0100 Subject: [PATCH 6/7] fix: properly placed secondary icon to the top right corner of key. --- .../keyboard/views/MyKeyboardView.kt | 36 +++++++++++-------- 1 file changed, 21 insertions(+), 15 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 65404c3..80148a9 100644 --- a/app/src/main/kotlin/com/simplemobiletools/keyboard/views/MyKeyboardView.kt +++ b/app/src/main/kotlin/com/simplemobiletools/keyboard/views/MyKeyboardView.kt @@ -618,30 +618,36 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut val secondaryIcon = key.secondaryIcon if (secondaryIcon != null) { - val keyIconWidth = (keyIcon.intrinsicWidth * .8).toInt() - val keyIconHeight = (keyIcon.intrinsicWidth * .8).toInt() - val secondaryIconWidth = (secondaryIcon.intrinsicWidth * .4).toInt() - val secondaryIconHeight = (secondaryIcon.intrinsicHeight * .4).toInt() + val keyIconWidth = (keyIcon.intrinsicWidth * .8f).toInt() + val keyIconHeight = (keyIcon.intrinsicHeight * .8f).toInt() + val secondaryIconWidth = (secondaryIcon.intrinsicWidth * .6f).toInt() + val secondaryIconHeight = (secondaryIcon.intrinsicHeight * .6f).toInt() - val drawableX = (key.width - keyIconWidth) / 2 - val drawableY = (key.height - keyIconHeight) / 2 + val centerX = key.width / 2 + val centerY = key.height / 2 - canvas.translate(drawableX.toFloat(), drawableY.toFloat()) + val keyIconLeft = centerX - keyIconWidth / 2 + val keyIconTop = centerY - keyIconHeight / 2 - keyIcon.setBounds(0, 0, keyIconWidth, keyIconHeight) + keyIcon.setBounds(keyIconLeft, keyIconTop, keyIconLeft + keyIconWidth, keyIconTop + keyIconHeight) keyIcon.draw(canvas) - val secIconPaddingBottom = 8 - val secIconPaddingRight = 4 + val secondaryIconPaddingRight = 8 + val secondaryIconLeft = key.width - secondaryIconPaddingRight - secondaryIconWidth + val secondaryIconRight = secondaryIconLeft + secondaryIconWidth + + val secondaryIconTop = 12 // This will act as a topPadding + val secondaryIconBottom = secondaryIconTop + secondaryIconHeight + secondaryIcon.setBounds( - keyIconWidth - secIconPaddingRight, - -secIconPaddingBottom, - (keyIconWidth + secondaryIconWidth) - secIconPaddingRight, - secondaryIconHeight - secIconPaddingBottom + secondaryIconLeft, + secondaryIconTop, + secondaryIconRight, + secondaryIconBottom ) secondaryIcon.draw(canvas) - canvas.translate(-drawableX.toFloat(), -drawableY.toFloat()) + secondaryIcon.draw(canvas) } else { val drawableX = (key.width - keyIcon.intrinsicWidth) / 2 val drawableY = (key.height - keyIcon.intrinsicHeight) / 2 From 6a46af16c12d7b0a2b734a50a4bbad629feee6d8 Mon Sep 17 00:00:00 2001 From: Tibor Kaputa Date: Sat, 11 Feb 2023 23:19:32 +0100 Subject: [PATCH 7/7] adding some tiny globe and emoji changes --- .../simplemobiletools/keyboard/views/MyKeyboardView.kt | 8 ++++---- 1 file changed, 4 insertions(+), 4 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 80148a9..262450e 100644 --- a/app/src/main/kotlin/com/simplemobiletools/keyboard/views/MyKeyboardView.kt +++ b/app/src/main/kotlin/com/simplemobiletools/keyboard/views/MyKeyboardView.kt @@ -618,8 +618,8 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut val secondaryIcon = key.secondaryIcon if (secondaryIcon != null) { - val keyIconWidth = (keyIcon.intrinsicWidth * .8f).toInt() - val keyIconHeight = (keyIcon.intrinsicHeight * .8f).toInt() + val keyIconWidth = (keyIcon.intrinsicWidth * 0.9f).toInt() + val keyIconHeight = (keyIcon.intrinsicHeight * 0.9f).toInt() val secondaryIconWidth = (secondaryIcon.intrinsicWidth * .6f).toInt() val secondaryIconHeight = (secondaryIcon.intrinsicHeight * .6f).toInt() @@ -632,11 +632,11 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut keyIcon.setBounds(keyIconLeft, keyIconTop, keyIconLeft + keyIconWidth, keyIconTop + keyIconHeight) keyIcon.draw(canvas) - val secondaryIconPaddingRight = 8 + val secondaryIconPaddingRight = 10 val secondaryIconLeft = key.width - secondaryIconPaddingRight - secondaryIconWidth val secondaryIconRight = secondaryIconLeft + secondaryIconWidth - val secondaryIconTop = 12 // This will act as a topPadding + val secondaryIconTop = 14 // This will act as a topPadding val secondaryIconBottom = secondaryIconTop + secondaryIconHeight secondaryIcon.setBounds(