Avoid suppressing Arabic numerals as morekeys when number row is active (for languages that use Indo-Arabic numerals)

This commit is contained in:
Aleksandras Kostarevas 2024-08-01 15:45:57 +03:00
parent 084dec1a47
commit da25fc282d
3 changed files with 32 additions and 13 deletions

View File

@ -443,6 +443,9 @@
<attr name="keyPreviewTextColor" format="color" />
<!-- Size of the text for key press feedback popup, in the proportion of key height. -->
<attr name="keyPreviewTextRatio" format="fraction" />
<!-- If true, numbers will not be suppressed in moreKeys due to enabled number row (This should be set to true for number row keys) -->
<attr name="doNotSuppressNumbersInMoreKeys" format="boolean" />
</declare-styleable>
<declare-styleable name="Keyboard_Include">

View File

@ -24,41 +24,51 @@
<Key
latin:keySpec="!text/keyspec_symbols_1"
latin:additionalMoreKeys="!text/additional_morekeys_symbols_1"
latin:moreKeys="!text/morekeys_symbols_1" />
latin:moreKeys="!text/morekeys_symbols_1"
latin:doNotSuppressNumbersInMoreKeys="true" />
<Key
latin:keySpec="!text/keyspec_symbols_2"
latin:additionalMoreKeys="!text/additional_morekeys_symbols_2"
latin:moreKeys="!text/morekeys_symbols_2" />
latin:moreKeys="!text/morekeys_symbols_2"
latin:doNotSuppressNumbersInMoreKeys="true" />
<Key
latin:keySpec="!text/keyspec_symbols_3"
latin:additionalMoreKeys="!text/additional_morekeys_symbols_3"
latin:moreKeys="!text/morekeys_symbols_3" />
latin:moreKeys="!text/morekeys_symbols_3"
latin:doNotSuppressNumbersInMoreKeys="true" />
<Key
latin:keySpec="!text/keyspec_symbols_4"
latin:additionalMoreKeys="!text/additional_morekeys_symbols_4"
latin:moreKeys="!text/morekeys_symbols_4" />
latin:moreKeys="!text/morekeys_symbols_4"
latin:doNotSuppressNumbersInMoreKeys="true" />
<Key
latin:keySpec="!text/keyspec_symbols_5"
latin:additionalMoreKeys="!text/additional_morekeys_symbols_5"
latin:moreKeys="!text/morekeys_symbols_5" />
latin:moreKeys="!text/morekeys_symbols_5"
latin:doNotSuppressNumbersInMoreKeys="true" />
<Key
latin:keySpec="!text/keyspec_symbols_6"
latin:additionalMoreKeys="!text/additional_morekeys_symbols_6"
latin:moreKeys="!text/morekeys_symbols_6" />
latin:moreKeys="!text/morekeys_symbols_6"
latin:doNotSuppressNumbersInMoreKeys="true" />
<Key
latin:keySpec="!text/keyspec_symbols_7"
latin:additionalMoreKeys="!text/additional_morekeys_symbols_7"
latin:moreKeys="!text/morekeys_symbols_7" />
latin:moreKeys="!text/morekeys_symbols_7"
latin:doNotSuppressNumbersInMoreKeys="true" />
<Key
latin:keySpec="!text/keyspec_symbols_8"
latin:additionalMoreKeys="!text/additional_morekeys_symbols_8"
latin:moreKeys="!text/morekeys_symbols_8" />
latin:moreKeys="!text/morekeys_symbols_8"
latin:doNotSuppressNumbersInMoreKeys="true" />
<Key
latin:keySpec="!text/keyspec_symbols_9"
latin:additionalMoreKeys="!text/additional_morekeys_symbols_9"
latin:moreKeys="!text/morekeys_symbols_9" />
latin:moreKeys="!text/morekeys_symbols_9"
latin:doNotSuppressNumbersInMoreKeys="true" />
<Key
latin:keySpec="!text/keyspec_symbols_0"
latin:additionalMoreKeys="!text/additional_morekeys_symbols_0"
latin:moreKeys="!text/morekeys_symbols_0" />
latin:moreKeys="!text/morekeys_symbols_0"
latin:doNotSuppressNumbersInMoreKeys="true" />
</merge>

View File

@ -327,7 +327,13 @@ public class Key implements Comparable<Key> {
}
moreKeys = MoreKeySpec.insertAdditionalMoreKeys(moreKeys, additionalMoreKeys);
if(params.mId.mNumberRow && moreKeys != null) {
boolean shouldSuppressNumbersInMoreKeys = moreKeys != null &&
// Number row is active
params.mId.mNumberRow &&
// This key is not part of number row
style.getFlags(keyAttr, R.styleable.Keyboard_Key_doNotSuppressNumbersInMoreKeys) == 0;
if(shouldSuppressNumbersInMoreKeys) {
moreKeys = Arrays.stream(moreKeys)
.filter(s -> !s.matches("\\d+"))
.toArray(String[]::new);
@ -372,7 +378,7 @@ public class Key implements Comparable<Key> {
String hintLabelCandidate = moreKeys[0];
if(hintLabelCandidate.startsWith("\\")) hintLabelCandidate = hintLabelCandidate.substring(1);
if(hintLabelCandidate.length() == 1) {
if(hintLabelCandidate.length() < 3) {
hintLabel = needsToUpcase
? StringUtils.toTitleCaseOfKeyLabel(hintLabelCandidate, localeForUpcasing)
: hintLabelCandidate;
@ -471,7 +477,7 @@ public class Key implements Comparable<Key> {
String hintLabelCandidate = moreKeys[0].mLabel;
if(hintLabelCandidate.startsWith("\\")) hintLabelCandidate = hintLabelCandidate.substring(1);
if(hintLabelCandidate.length() == 1) {
if(hintLabelCandidate.length() < 3) {
hintLabel = moreKeys[0].mNeedsToUpperCase
? StringUtils.toTitleCaseOfKeyLabel(hintLabelCandidate, moreKeys[0].mLocale)
: hintLabelCandidate;