From ef3eb40f5ba6b29df903c493484ec00cb851101d Mon Sep 17 00:00:00 2001 From: tibbi Date: Sat, 15 Jan 2022 18:14:08 +0100 Subject: [PATCH] use 2 rows at mini keyboard if necessary --- .../keyboard/helpers/Constants.kt | 3 +++ .../keyboard/helpers/MyKeyboard.kt | 27 +++++++------------ 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/keyboard/helpers/Constants.kt b/app/src/main/kotlin/com/simplemobiletools/keyboard/helpers/Constants.kt index 97cf7351..1b0abff0 100644 --- a/app/src/main/kotlin/com/simplemobiletools/keyboard/helpers/Constants.kt +++ b/app/src/main/kotlin/com/simplemobiletools/keyboard/helpers/Constants.kt @@ -3,3 +3,6 @@ package com.simplemobiletools.keyboard.helpers const val SHIFT_OFF = 0 const val SHIFT_ON_ONE_CHAR = 1 const val SHIFT_ON_PERMANENT = 2 + +// limit the count of alternative characters that show up at long pressing a key +const val MAX_KEYS_PER_MINI_ROW = 5 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 106101c5..4a5633d1 100644 --- a/app/src/main/kotlin/com/simplemobiletools/keyboard/helpers/MyKeyboard.kt +++ b/app/src/main/kotlin/com/simplemobiletools/keyboard/helpers/MyKeyboard.kt @@ -418,11 +418,8 @@ class MyKeyboard { * @param layoutTemplateResId the layout template file, containing no keys. * @param characters the list of characters to display on the keyboard. One key will be created * for each character. - * @param columns the number of columns of keys to display. If this number is greater than the - * number of keys that can fit in a row, it will be ignored. If this number is -1, the - * keyboard will fit as many keys as possible in each row. */ - constructor(context: Context, layoutTemplateResId: Int, characters: CharSequence, columns: Int, horizontalPadding: Int) : + constructor(context: Context, layoutTemplateResId: Int, characters: CharSequence, horizontalPadding: Int) : this(context, layoutTemplateResId) { var x = 0 var y = 0 @@ -434,25 +431,21 @@ class MyKeyboard { row.defaultHorizontalGap = mDefaultHorizontalGap row.verticalGap = mDefaultVerticalGap row.rowEdgeFlags = EDGE_TOP or EDGE_BOTTOM - val maxColumns = if (columns == -1) { - Int.MAX_VALUE - } else { - columns - } - for (element in characters) { - val c = element - if (column >= maxColumns || x + mDefaultWidth + horizontalPadding > mDisplayWidth) { - x = 0 - y += mDefaultVerticalGap + mDefaultHeight + characters.forEachIndexed { index, character -> + val key = Key(row) + if (column >= MAX_KEYS_PER_MINI_ROW) { column = 0 + x = 0 + y += mDefaultHeight + rows.add(row) + row.mKeys.clear() } - val key = Key(row) key.x = x key.y = y - key.label = c.toString() - key.codes = arrayListOf(c.toInt()) + key.label = character.toString() + key.codes = arrayListOf(character.toInt()) column++ x += key.width + key.gap mKeys!!.add(key)