From bd3e73ea10e920a917e394ba517e5bda90eaeeda Mon Sep 17 00:00:00 2001 From: Helium314 Date: Tue, 28 Nov 2023 09:18:47 +0100 Subject: [PATCH] non-null comute for KeyData, comments --- .../inputmethod/keyboard/internal/KeyboardBuilder.kt | 12 +++++++++--- .../internal/keyboard_parser/KeyboardParser.kt | 10 ++++++---- .../internal/keyboard_parser/floris/KeyData.kt | 3 +++ 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/org/dslul/openboard/inputmethod/keyboard/internal/KeyboardBuilder.kt b/app/src/main/java/org/dslul/openboard/inputmethod/keyboard/internal/KeyboardBuilder.kt index d97f73925..38ce9e5ea 100644 --- a/app/src/main/java/org/dslul/openboard/inputmethod/keyboard/internal/KeyboardBuilder.kt +++ b/app/src/main/java/org/dslul/openboard/inputmethod/keyboard/internal/KeyboardBuilder.kt @@ -65,12 +65,18 @@ open class KeyboardBuilder(protected val mContext: Context, // todo: further plan // release next version before continuing, testing current state for a while is likely necessary // migrate other languages/layouts to this style - // may be tricky in some cases, like additional row, or no shift key, or pc qwerty layout - // also the integrated number row might cause issues, and should be removed / ignored - // at least some of these layouts will need more complicated definition + // may be tricky in some cases, like additional row, or no shift key + // also the integrated number row is weird together with the number row setting, and should be removed / ignored + // at least some of these layouts will need more complicated definition and have separate shift layouts // test the zwnj key // label flags: some should be set by keyboard, not by row/letter // e.g. arabic looks weird with number row in holo being bold, but all other letters normal + // migrate pcqwerty to this style + // this will be more complicated... + // linked shift keys might be easy + // distance below number row with high row, but reduced key height? + // consider settings key needs to disappear if device is locked + // ignore number row setting? // migrate keypad layouts to this style // will need more configurable layout definition -> another parser, or do it with compatible jsons // make the remove duplicate moreKey thing an option? diff --git a/app/src/main/java/org/dslul/openboard/inputmethod/keyboard/internal/keyboard_parser/KeyboardParser.kt b/app/src/main/java/org/dslul/openboard/inputmethod/keyboard/internal/keyboard_parser/KeyboardParser.kt index e4df88f8b..42a7b0dc8 100644 --- a/app/src/main/java/org/dslul/openboard/inputmethod/keyboard/internal/keyboard_parser/KeyboardParser.kt +++ b/app/src/main/java/org/dslul/openboard/inputmethod/keyboard/internal/keyboard_parser/KeyboardParser.kt @@ -110,7 +110,7 @@ abstract class KeyboardParser(private val params: KeyboardParams, private val co for (key in row) { // todo: maybe autoScale / autoXScale if label has more than 2 characters (exception for emojis?) // but that could also be determined in toKeyParams - val keyParams = key.compute(params)?.toKeyParams(params, keyWidth, defaultLabelFlags) ?: continue + val keyParams = key.compute(params).toKeyParams(params, keyWidth, defaultLabelFlags) paramsRow.add(keyParams) } if (spacerWidth != 0f) { @@ -130,7 +130,7 @@ abstract class KeyboardParser(private val params: KeyboardParams, private val co // so the symbols keyboard is higher than the normal one // not a new issue, but should be solved in this migration // how? possibly scale all keyboards to height of main alphabet? (consider suggestion strip) - keysInRows.forEach { it.forEach { it.mRelativeHeight *= heightRescale } } + keysInRows.forEach { key -> key.forEach { it.mRelativeHeight *= heightRescale } } } return keysInRows @@ -295,7 +295,7 @@ abstract class KeyboardParser(private val params: KeyboardParams, private val co "!icon/space_key|!code/key_space", // !icon/space_key_for_number_layout in number layout, but not on tablet params, width, // will not be used for normal space (only in number layouts) - 0, // todo (later): alignIconToBottom for non-tablet number layout + 0, // todo (later): alignIconToBottom for non-tablet number layout -> check what it does / whether it's necessary Key.BACKGROUND_TYPE_SPACEBAR, null ) @@ -342,7 +342,9 @@ abstract class KeyboardParser(private val params: KeyboardParams, private val co FunctionalKey.EMOJI_COM -> if (params.mId.mMode == KeyboardId.MODE_URL || params.mId.mMode == KeyboardId.MODE_EMAIL) getFunctionalKeyParams(FunctionalKey.COM, width) else getFunctionalKeyParams(FunctionalKey.EMOJI, width) - FunctionalKey.COM -> KeyParams( // todo: label and moreKeys could be in localeKeyTexts, handled like currency key + FunctionalKey.COM -> KeyParams( + // todo (later): label and moreKeys could be in localeKeyTexts, handled like currency key + // better not in the text files, because it should be handled in a more fine grained way ".com", params, width, diff --git a/app/src/main/java/org/dslul/openboard/inputmethod/keyboard/internal/keyboard_parser/floris/KeyData.kt b/app/src/main/java/org/dslul/openboard/inputmethod/keyboard/internal/keyboard_parser/floris/KeyData.kt index 88cfdf9cb..c9eb618a1 100644 --- a/app/src/main/java/org/dslul/openboard/inputmethod/keyboard/internal/keyboard_parser/floris/KeyData.kt +++ b/app/src/main/java/org/dslul/openboard/inputmethod/keyboard/internal/keyboard_parser/floris/KeyData.kt @@ -99,6 +99,9 @@ interface KeyData : AbstractKeyData { const val GROUP_KANA: Int = 97 } + // make it non-nullable for simplicity, and to reflect current implementations + override fun compute(params: KeyboardParams): KeyData + fun isSpaceKey(): Boolean { return type == KeyType.CHARACTER && (code == KeyCode.SPACE || code == KeyCode.CJK_SPACE || code == KeyCode.HALF_SPACE || code == KeyCode.KESHIDA)