@@ -1005,6 +1005,11 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
10051005 val popupKeyboardId = popupKey.popupResId
10061006 if (popupKeyboardId != 0 ) {
10071007 mMiniKeyboardContainer = mMiniKeyboardCache[popupKey]
1008+
1009+ // For 'number' and 'phone' keyboards the count of popup keys might be bigger than count of keys in the main keyboard.
1010+ // And therefore the width of the key might be smaller than width declared in MyKeyboard.Key.width for the main keyboard.
1011+ val popupKeyWidth = popupKey.calcKeyWidth(containerWidth = mMiniKeyboardContainer?.measuredWidth ? : width)
1012+
10081013 if (mMiniKeyboardContainer == null ) {
10091014 val inflater = context.getSystemService(Context .LAYOUT_INFLATER_SERVICE ) as LayoutInflater
10101015 keyboardPopupBinding = KeyboardPopupKeyboardBinding .inflate(inflater).apply {
@@ -1013,11 +1018,10 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
10131018 }
10141019
10151020 val keyboard = if (popupKey.popupCharacters != null ) {
1016- MyKeyboard (context, popupKeyboardId, popupKey.popupCharacters!! , popupKey.width )
1021+ MyKeyboard (context, popupKeyboardId, popupKey.popupCharacters!! , popupKeyWidth )
10171022 } else {
10181023 MyKeyboard (context, popupKeyboardId, 0 )
10191024 }
1020-
10211025 mMiniKeyboard!! .setKeyboard(keyboard)
10221026 mPopupParent = this
10231027 mMiniKeyboardContainer!! .measure(
@@ -1032,8 +1036,8 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
10321036 mPopupX = popupKey.x
10331037 mPopupY = popupKey.y
10341038
1035- val widthToUse = mMiniKeyboardContainer!! .measuredWidth - (popupKey.popupCharacters!! .length / 2 ) * popupKey.width
1036- mPopupX = mPopupX + popupKey.width - widthToUse
1039+ val widthToUse = mMiniKeyboardContainer!! .measuredWidth - (popupKey.popupCharacters!! .length / 2 ) * popupKeyWidth
1040+ mPopupX = mPopupX + popupKeyWidth - widthToUse
10371041 mPopupY - = mMiniKeyboardContainer!! .measuredHeight
10381042 val x = mPopupX + mCoordinates[0 ]
10391043 val y = mPopupY + mCoordinates[1 ]
@@ -1048,7 +1052,7 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
10481052 }
10491053
10501054 val keysCnt = mMiniKeyboard!! .mKeys.size
1051- var selectedKeyIndex = Math .floor((me.x - miniKeyboardX) / popupKey.width .toDouble()).toInt()
1055+ var selectedKeyIndex = Math .floor((me.x - miniKeyboardX) / popupKeyWidth .toDouble()).toInt()
10521056 if (keysCnt > MAX_KEYS_PER_MINI_ROW ) {
10531057 selectedKeyIndex + = MAX_KEYS_PER_MINI_ROW
10541058 }
@@ -1714,4 +1718,17 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
17141718 * Returns true if there are [InlineContentView]s in [autofill_suggestions_holder]
17151719 */
17161720 private fun hasInlineViews () = (keyboardViewBinding?.autofillSuggestionsHolder?.childCount ? : 0 ) > 0
1721+
1722+ /* *
1723+ * Returns: Popup Key width depends on popup keys count
1724+ */
1725+ private fun MyKeyboard.Key.calcKeyWidth (containerWidth : Int ): Int {
1726+ val popupKeyCount = this .popupCharacters!! .length
1727+
1728+ return if (popupKeyCount > containerWidth / this .width) {
1729+ containerWidth / popupKeyCount
1730+ } else {
1731+ this .width
1732+ }
1733+ }
17171734}
0 commit comments