From eafd0d4276c459d395968733e26a374bc7a45214 Mon Sep 17 00:00:00 2001 From: Helium314 Date: Fri, 1 Dec 2023 16:16:04 +0100 Subject: [PATCH] add missing labelFlag to hindi (compact) and marathi and add debug info for some rarely occurring glitches --- .../main/assets/layouts/hindi_compact.json | 40 +++++++++++++++++++ app/src/main/assets/layouts/hindi_compact.txt | 34 ---------------- app/src/main/assets/layouts/marathi.json | 40 +++++++++++++++++++ app/src/main/assets/layouts/marathi.txt | 34 ---------------- .../keyboard/internal/KeyboardBuilder.kt | 15 ++++--- .../keyboard_parser/KeyboardParser.kt | 15 ++++++- 6 files changed, 100 insertions(+), 78 deletions(-) create mode 100644 app/src/main/assets/layouts/hindi_compact.json delete mode 100644 app/src/main/assets/layouts/hindi_compact.txt create mode 100644 app/src/main/assets/layouts/marathi.json delete mode 100644 app/src/main/assets/layouts/marathi.txt diff --git a/app/src/main/assets/layouts/hindi_compact.json b/app/src/main/assets/layouts/hindi_compact.json new file mode 100644 index 000000000..bb659ab7b --- /dev/null +++ b/app/src/main/assets/layouts/hindi_compact.json @@ -0,0 +1,40 @@ +[ + [ + { "label": "औ" }, + { "label": "ऐ" }, + { "label": "आ" }, + { "label": "ई" }, + { "label": "ऊ" }, + { "label": "ब" }, + { "label": "ह" }, + { "label": "ग" }, + { "label": "द" }, + { "label": "ज" }, + { "label": "ड" } + ], + [ + { "label": "ओ" }, + { "label": "ए" }, + { "label": "अ" }, + { "label": "इ" }, + { "label": "उ" }, + { "label": "प" }, + { "label": "र" }, + { "label": "क" }, + { "label": "त" }, + { "label": "च" }, + { "label": "ट" } + ], + [ + { "label": "ऑ" }, + { "label": "्" }, + { "label": "ं" }, + { "label": "म" }, + { "label": "न" }, + { "label": "व" }, + { "label": "ल" }, + { "label": "स" }, + { "label": "य" }, + { "label": "क्ष", "labelFlags": 128 } + ] +] diff --git a/app/src/main/assets/layouts/hindi_compact.txt b/app/src/main/assets/layouts/hindi_compact.txt deleted file mode 100644 index 33d418e78..000000000 --- a/app/src/main/assets/layouts/hindi_compact.txt +++ /dev/null @@ -1,34 +0,0 @@ -औ -ऐ -आ -ई -ऊ -ब -ह -ग -द -ज -ड - -ओ -ए -अ -इ -उ -प -र -क -त -च -ट - -ऑ -् -ं -म -न -व -ल -स -य -क्ष diff --git a/app/src/main/assets/layouts/marathi.json b/app/src/main/assets/layouts/marathi.json new file mode 100644 index 000000000..e8c8c18ac --- /dev/null +++ b/app/src/main/assets/layouts/marathi.json @@ -0,0 +1,40 @@ +[ + [ + { "label": "ौ" }, + { "label": "ै" }, + { "label": "ा" }, + { "label": "ी" }, + { "label": "ू" }, + { "label": "ब" }, + { "label": "ह" }, + { "label": "ग" }, + { "label": "द" }, + { "label": "ज" }, + { "label": "ड" } + ], + [ + { "label": "ो" }, + { "label": "े" }, + { "label": "्" }, + { "label": "ि" }, + { "label": "ु" }, + { "label": "प" }, + { "label": "र" }, + { "label": "क" }, + { "label": "त" }, + { "label": "च" }, + { "label": "ट" } + ], + [ + { "label": "ॉ" }, + { "label": "ॅ" }, + { "label": "ं" }, + { "label": "म" }, + { "label": "न" }, + { "label": "व" }, + { "label": "ल" }, + { "label": "स" }, + { "label": "य" }, + { "label": "क्ष", "labelFlags": 128 } + ] +] diff --git a/app/src/main/assets/layouts/marathi.txt b/app/src/main/assets/layouts/marathi.txt deleted file mode 100644 index e758c9a87..000000000 --- a/app/src/main/assets/layouts/marathi.txt +++ /dev/null @@ -1,34 +0,0 @@ -ौ -ै -ा -ी -ू -ब -ह -ग -द -ज -ड - -ो -े -् -ि -ु -प -र -क -त -च -ट - -ॉ -ॅ -ं -म -न -व -ल -स -य -क्ष 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 58f9781de..e58c89044 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 @@ -64,10 +64,11 @@ open class KeyboardBuilder(protected val mContext: Context, // todo: further plan // migrate other languages/layouts to this style - // add a few individual key label flags: hindi_compact -> dammit... one key and there is need for json, marathi -> same // thai and lao number rows... they should probably have none, can't do it generically // so handle it like korean // languageMoreKeys for bengali and hindi layouts are completely mixed up -> maybe need to use layoutMoreKeys... but that's not nice + // bangla (india) has different period & symbols label (should it really be latin?) + // maybe need separate key text files for _IN and _BD // test whether the layouts really are the same // comparing params with both parsers looks good, see list of detected differences below // still need to check moreKeys, there will be many more differences that might just be minor @@ -76,7 +77,7 @@ open class KeyboardBuilder(protected val mContext: Context, // that's one more reason for using language tags... // but currently it's still read from xml outside the keyboard parser, so that's fine for now // issues: - // armenian bottom row: functional keys should be narrower + // armenian bottom row (and some more): functional keys could be narrower // rtl parentheses hint label (urdu and more) // urdu and others: no labels because the moreKeys are languageMoreKeys -> need the moreKeys setting soon (at least setting to show first language moreKey if no symbol) // setting: symbol morekey(s): layout default, take from symbols, layout default but fill from symbols if empty @@ -196,14 +197,9 @@ open class KeyboardBuilder(protected val mContext: Context, // also check holo, there might be different default parameters // and compare tablet layouts (how to best force it for both parsers?) val keyParams = row[index1] - // bangla (india) has different period & symbols label (should it really be latin?) - // maybe need separate key text files for _IN and _BD - // hindi compact has a key with different label flags (marathi too? maybe i overlooked) - // lao has some sort of split number row, should be considered (how to deal with it?) - // thai also has this, leads to differences in hint labels and moreKeys if (keyParams.mLabel != xmlParams.mLabel) // currency keys (shift symbol) arranged differently - // obviously number row differences + // obviously number row differences with possibly localized variants Log.w(TAG, "label different: ${keyParams.mLabel} vs ${xmlParams.mLabel}") if (keyParams.mCode != xmlParams.mCode) Log.w(TAG, "code different: ${keyParams.mCode} vs ${xmlParams.mCode}") @@ -222,6 +218,7 @@ open class KeyboardBuilder(protected val mContext: Context, // armenian, arabic, bangla,... and many with "symbols" original shift and delete have LABEL_FLAGS_FONT_NORMAL, mine not (but my period has) // malayalam delete also has LABEL_FLAGS_AUTO_X_SCALE, mine not // tamil & telugu my delete has LABEL_FLAGS_AUTO_X_SCALE, original not + // hindi / marathi: -5 has 10, mine has 0 -> delete and LABEL_FLAGS_FONT_NORMAL Log.w(TAG, "label flags different for ${keyParams.mLabel} / ${keyParams.mCode}: ${keyParams.mLabelFlags.toString(16)} vs ${xmlParams.mLabelFlags.toString(16)}") } } @@ -275,6 +272,8 @@ open class KeyboardBuilder(protected val mContext: Context, var currentX = 0f row.forEach { it.setDimensionsFromRelativeSize(currentX, currentY) + if (DebugFlags.DEBUG_ENABLED) + Log.d(TAG, "setting size and position for ${it.mLabel}, ${it.mCode}: x ${currentX.toInt()}, w ${it.mFullWidth.toInt()}") currentX += it.mFullWidth } // need to truncate to int here, otherwise it may end up one pixel lower than original 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 11235d328..fc1243c81 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 @@ -61,8 +61,13 @@ abstract class KeyboardParser(private val params: KeyboardParams, private val co } else if (!params.mId.mNumberRowEnabled && params.mId.isAlphabetKeyboard && params.mId.locale.language != "ko") { // add number to the first 10 keys in first row // setting the correct moreKeys is handled in PopupSet - // not for korean layouts, todo: should be decided in the layout, not in the parser + // not for korean layouts (add thai and lao to this), todo: should be decided in the layout, not in the parser baseKeys.first().take(10).forEachIndexed { index, keyData -> keyData.popup.numberIndex = index } + if (DebugFlags.DEBUG_ENABLED && baseKeys.first().size < 10) { + val message = "first row only has ${baseKeys.first().size} keys: ${baseKeys.first().map { it.label }}" + Log.w(TAG, message) + Toast.makeText(context, message, Toast.LENGTH_LONG).show() + } } val functionalKeysReversed = parseFunctionalKeys().reversed() @@ -73,6 +78,8 @@ abstract class KeyboardParser(private val params: KeyboardParams, private val co baseKeys.reversed().forEachIndexed { i, it -> val row: List = if (i == 0) { // add bottom row extra keys + // todo: question mark might be different -> get it from localeKeyTexts + // also, maybe check device dimension int instead of getting this from resources, then using language labels is easier it + context.getString(R.string.key_def_extra_bottom_right) .split(",").mapNotNull { if (it.isBlank()) null else it.trim().toTextKey() } } else { @@ -118,6 +125,8 @@ abstract class KeyboardParser(private val params: KeyboardParams, private val co // but that could also be determined in toKeyParams val keyParams = key.compute(params).toKeyParams(params, keyWidth, defaultLabelFlags) paramsRow.add(keyParams) + if (DebugFlags.DEBUG_ENABLED) + Log.d(TAG, "adding key ${keyParams.mLabel}, ${keyParams.mCode}") } if (spacerWidth != 0f) { paramsRow.add(KeyParams.newSpacer(params, spacerWidth)) @@ -480,7 +489,7 @@ abstract class KeyboardParser(private val params: KeyboardParams, private val co val id = context.resources.getIdentifier("label_$this", "string", context.packageName) if (id == 0) { val message = "no resource for label $this in ${params.mId}" - Log.w(this::class.simpleName, message) + Log.w(TAG, message) if (DebugFlags.DEBUG_ENABLED) Toast.makeText(context, message, Toast.LENGTH_LONG).show() return this @@ -559,6 +568,8 @@ abstract class KeyboardParser(private val params: KeyboardParams, private val co } companion object { + private val TAG = KeyboardParser::class.simpleName + fun parseFromAssets(params: KeyboardParams, context: Context): ArrayList>? { val id = params.mId val layoutName = params.mId.mSubtype.keyboardLayoutSetName