determine symbols from symbols layout instead of putting the keys on each keyboard layout separately

This commit is contained in:
Helium314 2023-12-27 23:12:10 +01:00
parent c5c42bc5d7
commit 2c03623b8a
22 changed files with 461 additions and 435 deletions

View file

@ -1,38 +1,38 @@
[ [
[ [
{ "label": "a", "popup": { "main": { "label": "%" } } }, { "label": "a" },
{ "label": "z", "popup": { "main": { "label": "\\" } } }, { "label": "z" },
{ "label": "e", "popup": { "main": { "label": "|" } } }, { "label": "e" },
{ "label": "r", "popup": { "main": { "label": "=" } } }, { "label": "r" },
{ "label": "t", "popup": { "main": { "label": "[" } } }, { "label": "t" },
{ "label": "y", "popup": { "main": { "label": "]" } } }, { "label": "y" },
{ "label": "u", "popup": { "main": { "label": "<" } } }, { "label": "u" },
{ "label": "i", "popup": { "main": { "label": ">" } } }, { "label": "i" },
{ "label": "o", "popup": { "main": { "label": "{" } } }, { "label": "o" },
{ "label": "p", "popup": { "main": { "label": "}" } } } { "label": "p" }
], ],
[ [
{ "label": "q", "popup": { "main": { "label": "@" } } }, { "label": "q" },
{ "label": "s", "popup": { "main": { "label": "#" } } }, { "label": "s" },
{ "label": "d", "popup": { "main": { "label": "$$$" } } }, { "label": "d" },
{ "label": "f", "popup": { "main": { "label": "_" } } }, { "label": "f" },
{ "label": "g", "popup": { "main": { "label": "&" } } }, { "label": "g" },
{ "label": "h", "popup": { "main": { "label": "-" } } }, { "label": "h" },
{ "label": "j", "popup": { "main": { "label": "+" } } }, { "label": "j" },
{ "label": "k", "popup": { "main": { "label": "(" } } }, { "label": "k" },
{ "label": "l", "popup": { "main": { "label": ")" } } }, { "label": "l" },
{ "label": "m", "popup": { "main": { "label": "/" } } } { "label": "m" }
], ],
[ [
{ "label": "w", "popup": { "main": { "label": "*" } } }, { "label": "w" },
{ "label": "x", "popup": { "main": { "label": "\"" } } }, { "label": "x" },
{ "label": "c", "popup": { "main": { "label": "'" } } }, { "label": "c" },
{ "label": "v", "popup": { "main": { "label": ":" } } }, { "label": "v" },
{ "label": "b", "popup": { "main": { "label": ";" } } }, { "label": "b" },
{ "label": "n", "popup": { "main": { "label": "!" } } }, { "label": "n" },
{ "$": "shift_state_selector", { "$": "shift_state_selector",
"shiftedManual": { "label": "?" }, "shiftedManual": { "label": "?" },
"default": { "label": "'", "popup": { "main": { "label": "?" } } } "default": { "label": "'" }
} }
] ]
] ]

View file

@ -10,24 +10,24 @@
з з
х х
ф @ ф
ы # ы
в $$$ в
а % а
п & п
р _ р
о / о
л - л
д + д
ж ( ж
э ) э
я * я
ч " ч
с ' с
м : м
і ; і
т ! т
ь ? ь
б < б
ю > ю

View file

@ -1,29 +1,29 @@
b % b
é \ è é è
p | p
o = o
v [ v
d ] d
l < l
j > j
z { z
w } w
a @ a
u # u
i $$$ i
e _ e
c & c
t - t
s + s
r ( r
n ) n
m / m
y * y
x " x
k ' k
q : q
g ; g
h ! h
f ? f

View file

@ -1,40 +1,38 @@
[ [
[ [
{ "label": "q", "popup": { "main": { "label": "%" } } }, { "label": "q" },
{ "label": "w", "popup": { "main": { "label": "\\" } } }, { "label": "w" },
{ "label": "f", "popup": { "main": { "label": "|" } } }, { "label": "f" },
{ "label": "p", "popup": { "main": { "label": "=" } } }, { "label": "p" },
{ "label": "g", "popup": { "main": { "label": "[" } } }, { "label": "g" },
{ "label": "j", "popup": { "main": { "label": "]" } } }, { "label": "j" },
{ "label": "l", "popup": { "main": { "label": "<" } } }, { "label": "l" },
{ "label": "u", "popup": { "main": { "label": ">" } } }, { "label": "u" },
{ "label": "y", "popup": { "main": { "label": "{" } } }, { "label": "y" },
{ "$": "shift_state_selector", { "$": "shift_state_selector",
"shiftedManual": { "label": ":" }, "shiftedManual": { "label": ":" },
"default": { "label": ";", "popup": { "relevant": [ "default": { "label": ";", "popup": { "main": { "label": ":" } } }
{ "label": ":" }, { "label": "}" }
] } }
} }
], ],
[ [
{ "label": "a", "popup": { "main": { "label": "@" } } }, { "label": "a" },
{ "label": "r", "popup": { "main": { "label": "#" } } }, { "label": "r" },
{ "label": "s", "popup": { "main": { "label": "$$$" } } }, { "label": "s" },
{ "label": "t", "popup": { "main": { "label": "_" } } }, { "label": "t" },
{ "label": "d", "popup": { "main": { "label": "&" } } }, { "label": "d" },
{ "label": "h", "popup": { "main": { "label": "-" } } }, { "label": "h" },
{ "label": "n", "popup": { "main": { "label": "+" } } }, { "label": "n" },
{ "label": "e", "popup": { "main": { "label": "(" } } }, { "label": "e" },
{ "label": "i", "popup": { "main": { "label": ")" } } }, { "label": "i" },
{ "label": "o", "popup": { "main": { "label": "…" } } } { "label": "o" }
], ],
[ [
{ "label": "z", "popup": { "main": { "label": "*" } } }, { "label": "z" },
{ "label": "x", "popup": { "main": { "label": "\"" } } }, { "label": "x" },
{ "label": "c", "popup": { "main": { "label": "'" } } }, { "label": "c" },
{ "label": "v", "popup": { "main": { "label": ":" } } }, { "label": "v" },
{ "label": "b", "popup": { "main": { "label": ";" } } }, { "label": "b" },
{ "label": "k", "popup": { "main": { "label": "!" } } }, { "label": "k" },
{ "label": "m", "popup": { "main": { "label": "?" } } } { "label": "m" }
] ]
] ]

View file

@ -1,40 +1,38 @@
[ [
[ [
{ "label": "q", "popup": { "main": { "label": "%" } } }, { "label": "q" },
{ "label": "w", "popup": { "main": { "label": "\\" } } }, { "label": "w" },
{ "label": "f", "popup": { "main": { "label": "|" } } }, { "label": "f" },
{ "label": "p", "popup": { "main": { "label": "=" } } }, { "label": "p" },
{ "label": "b", "popup": { "main": { "label": "[" } } }, { "label": "b" },
{ "label": "j", "popup": { "main": { "label": "]" } } }, { "label": "j" },
{ "label": "l", "popup": { "main": { "label": "<" } } }, { "label": "l" },
{ "label": "u", "popup": { "main": { "label": ">" } } }, { "label": "u" },
{ "label": "y", "popup": { "main": { "label": "{" } } }, { "label": "y" },
{ "$": "shift_state_selector", { "$": "shift_state_selector",
"shiftedManual": { "label": ":" }, "shiftedManual": { "label": ":" },
"default": { "label": ";", "popup": { "relevant": [ "default": { "label": ";", "popup": { "main": { "label": ":" } } }
{ "label": ":" }, { "label": "}" }
] } }
} }
], ],
[ [
{ "label": "a", "popup": { "main": { "label": "@" } } }, { "label": "a" },
{ "label": "r", "popup": { "main": { "label": "#" } } }, { "label": "r" },
{ "label": "s", "popup": { "main": { "label": "$$$" } } }, { "label": "s" },
{ "label": "t", "popup": { "main": { "label": "_" } } }, { "label": "t" },
{ "label": "g", "popup": { "main": { "label": "&" } } }, { "label": "g" },
{ "label": "m", "popup": { "main": { "label": "-" } } }, { "label": "m" },
{ "label": "n", "popup": { "main": { "label": "+" } } }, { "label": "n" },
{ "label": "e", "popup": { "main": { "label": "(" } } }, { "label": "e" },
{ "label": "i", "popup": { "main": { "label": ")" } } }, { "label": "i" },
{ "label": "o", "popup": { "main": { "label": "…" } } } { "label": "o" }
], ],
[ [
{ "label": "z", "popup": { "main": { "label": "*" } } }, { "label": "z" },
{ "label": "x", "popup": { "main": { "label": "\"" } } }, { "label": "x" },
{ "label": "c", "popup": { "main": { "label": "'" } } }, { "label": "c" },
{ "label": "d", "popup": { "main": { "label": ":" } } }, { "label": "d" },
{ "label": "v", "popup": { "main": { "label": ";" } } }, { "label": "v" },
{ "label": "k", "popup": { "main": { "label": "!" } } }, { "label": "k" },
{ "label": "h", "popup": { "main": { "label": "?" } } } { "label": "h" }
] ]
] ]

View file

@ -1,29 +1,29 @@
ŝ % ŝ
ĝ \ ĝ
e | e
r = r
t [ t
ŭ ] ŭ
u < u
i > i
o { o
p } p
a @ a
s # s
d $$$ d
f _ f
g & g
h - h
j + j
k ( k
l ) l
ĵ ĵ
z * z
ĉ " ĉ
c ' c
v : v
b ; b
n ! n
m ? m

View file

@ -15,23 +15,23 @@
{ "label": "π" } { "label": "π" }
], ],
[ [
{ "label": "α", "popup": { "main": { "label": "@" } } }, { "label": "α" },
{ "label": "σ", "popup": { "main": { "label": "#" } } }, { "label": "σ" },
{ "label": "δ", "popup": { "main": { "label": "$$$" } } }, { "label": "δ" },
{ "label": "φ", "popup": { "main": { "label": "%" } } }, { "label": "φ" },
{ "label": "γ", "popup": { "main": { "label": "&" } } }, { "label": "γ" },
{ "label": "η", "popup": { "main": { "label": "-" } } }, { "label": "η" },
{ "label": "ξ", "popup": { "main": { "label": "+" } } }, { "label": "ξ" },
{ "label": "κ", "popup": { "main": { "label": "(" } } }, { "label": "κ" },
{ "label": "λ", "popup": { "main": { "label": ")" } } } { "label": "λ" }
], ],
[ [
{ "label": "ζ", "popup": { "main": { "label": "*" } } }, { "label": "ζ" },
{ "label": "χ", "popup": { "main": { "label": "\"" } } }, { "label": "χ" },
{ "label": "ψ", "popup": { "main": { "label": "'" } } }, { "label": "ψ" },
{ "label": "ω", "popup": { "main": { "label": ":" } } }, { "label": "ω" },
{ "label": "β", "popup": { "main": { "label": ";" } } }, { "label": "β" },
{ "label": "ν", "popup": { "main": { "label": "!" } } }, { "label": "ν" },
{ "label": "μ", "popup": { "main": { "label": "?" } } } { "label": "μ" }
] ]
] ]

View file

@ -1,32 +1,32 @@
w % w
l \ l
r | r
b = b
z [ z
; ] ;
q < q
u > u
d { d
j } j
s @ s
h # h
n $$$ n
t _ t
, ,
. .
a - a
e ( e
o ) o
i / i
m * m
v " v
c ' c
g : g
p ; p
x ! x
k ? k
f f
y y

View file

@ -10,24 +10,24 @@
з з
х х
ф @ ф
ы # ы
в $$$ в
а % а
п & п
р _ р
о / о
л - л
д + д
ж ( ж
э ) э
я * я
ч " ч
с ' с
м : м
и ; и
т ! т
ь ? ь
б < б
ю > ю

View file

@ -10,24 +10,24 @@
з з
х х
ф @ ф
ы # ы
в $$$ в
а % а
п & п
р _ р
о / о
л - л
д + д
ж ( ж
э ) э
я * я
ч " ч
с ' с
м : м
и ; и
т ! т
ь ? ь
б < б
ю > ю

View file

@ -1,28 +1,28 @@
q % q
w \ w
e | e
r = r
t [ t
y ] y
u < u
i > i
o { o
p } p
a @ a
s # s
d $$$ d
f _ f
g & g
h - h
j + j
k ( k
l ) l
z * z
x " x
c ' c
v : v
b ; b
n ! n
m ? m

View file

@ -1,28 +1,28 @@
q % q
w \ w
e | e
r = r
t [ t
z ] z
u < u
i > i
o { o
p } p
a @ a
s # s
d $$$ d
f _ f
g & g
h - h
j + j
k ( k
l ) l
y * y
x " x
c ' c
v : v
b ; b
n ! n
m ? m

View file

@ -10,24 +10,24 @@
з з
х х
ф @ ф
ы # ы
в $$$ в
а % а
п & п
р _ р
о / о
л - л
д + д
ж ( ж
э ) э
я * я
ч " ч
с ' с
м : м
и ; и
т ! т
ь ? ь
б < б
ю > ю

View file

@ -1,20 +1,20 @@
~ % ‰
` \
| |
• ♪ ♥ ♠ ♦ ♣ =
[
π Π ]
÷ <
× >
¶ § {
}
@ @
# #
$$$ $$$
% ‰ _ \% ‰
& &
- _ — · - — ·
+ ± + ±
( !fixedColumnOrder!3 < { [ ( !fixedColumnOrder!3 < { [
) !fixedColumnOrder!3 > } ] ) !fixedColumnOrder!3 > } ]

View file

@ -1,20 +1,20 @@
~ ٪ % ‰
` \
| |
• ♪ ♥ ♠ ♦ ♣ =
[
π Π ]
÷ <
× >
¶ § {
﴿ {
٬ @ ٬ @
٫ # ٫ #
$$$ $$$
٪ % ‰ _ ٪ \% ‰
& &
- _ — · - — ·
+ ± + ±
( !fixedColumnOrder!4 < { [ ( !fixedColumnOrder!4 < { [
) !fixedColumnOrder!4 ﴿ > } ] ) !fixedColumnOrder!4 ﴿ > } ]

View file

@ -10,24 +10,24 @@
з з
х х
ф @ ф
і # і
в $$$ в
а % а
п & п
р _ р
о / о
л - л
д + д
ж ( ж
є ) є
я * я
ч " ч
с ' с
м : м
и ; и
т ! т
ь ? ь
б < б
ю > ю

View file

@ -1,37 +1,37 @@
[ [
[ [
{ "label": "q", "popup": { "main": { "label": "%" } } }, { "label": "q" },
{ "label": "w", "popup": { "main": { "label": "\\" } } }, { "label": "w" },
{ "label": "e", "popup": { "main": { "label": "|" } } }, { "label": "e" },
{ "label": "r", "popup": { "main": { "label": "=" } } }, { "label": "r" },
{ "label": "t", "popup": { "main": { "label": "[" } } }, { "label": "t" },
{ "label": "y", "popup": { "main": { "label": "]" } } }, { "label": "y" },
{ "label": "u", "popup": { "main": { "label": "<" } } }, { "label": "u" },
{ "label": "i", "popup": { "main": { "label": ">" } } }, { "label": "i" },
{ "label": "o", "popup": { "main": { "label": "{" } } }, { "label": "o" },
{ "label": "p", "popup": { "main": { "label": "}" } } }, { "label": "p" },
{ "label": "oʻ", "labelFlags": 128 } { "label": "oʻ", "labelFlags": 128 }
], ],
[ [
{ "label": "a", "popup": { "main": { "label": "@" } } }, { "label": "a" },
{ "label": "s", "popup": { "main": { "label": "#" } } }, { "label": "s" },
{ "label": "d", "popup": { "main": { "label": "$$$" } } }, { "label": "d" },
{ "label": "f", "popup": { "main": { "label": "_" } } }, { "label": "f" },
{ "label": "g", "popup": { "main": { "label": "&" } } }, { "label": "g" },
{ "label": "h", "popup": { "main": { "label": "-" } } }, { "label": "h" },
{ "label": "j", "popup": { "main": { "label": "+" } } }, { "label": "j" },
{ "label": "k", "popup": { "main": { "label": "(" } } }, { "label": "k" },
{ "label": "l", "popup": { "main": { "label": ")" } } }, { "label": "l" },
{ "label": "gʻ", "labelFlags": 128 }, { "label": "gʻ", "labelFlags": 128 },
{ "label": "ʼ" } { "label": "ʼ" }
], ],
[ [
{ "label": "z", "popup": { "main": { "label": "*" } } }, { "label": "z" },
{ "label": "x", "popup": { "main": { "label": "\"" } } }, { "label": "x" },
{ "label": "c", "popup": { "main": { "label": "'" } } }, { "label": "c" },
{ "label": "v", "popup": { "main": { "label": ":" } } }, { "label": "v" },
{ "label": "b", "popup": { "main": { "label": ";" } } }, { "label": "b" },
{ "label": "n", "popup": { "main": { "label": "!" } } }, { "label": "n" },
{ "label": "m", "popup": { "main": { "label": "?" } } } { "label": "m" }
] ]
] ]

View file

@ -1,29 +1,29 @@
q % q
d \ d
r | r
w = w
b [ b
j ] j
f < f
u > u
p { p
; } ;
a @ a
s # s
h $$$ h
t _ t
g & g
y - y
n + n
e ( e
o ) o
i / i
z * z
x " x
m ' m
c : c
v ; v
k ! k
l ? l

View file

@ -77,9 +77,6 @@ open class KeyboardBuilder<KP : KeyboardParams>(protected val mContext: Context,
// does glide typing work with multiple letters on one key? if not, users should be notified // does glide typing work with multiple letters on one key? if not, users should be notified
// maybe allow users to define their own symbol and shift-symbol layouts // maybe allow users to define their own symbol and shift-symbol layouts
// allow users to import layouts, which essentially just fills the text from a file // allow users to import layouts, which essentially just fills the text from a file
// add setting to use moreKeys from symbol layout (always, never, only if none defined)
// should also have sth related to hint, because hint and start morekey maybe should stay
// option to add language extra keys for all layouts?
// labelFlags should be set correctly // labelFlags should be set correctly
// alignHintLabelToBottom: on lxx and rounded themes, but did not find what it actually does... // alignHintLabelToBottom: on lxx and rounded themes, but did not find what it actually does...
@ -120,7 +117,8 @@ open class KeyboardBuilder<KP : KeyboardParams>(protected val mContext: Context,
val sv = Settings.getInstance().current val sv = Settings.getInstance().current
addLocaleKeyTextsToParams(mContext, mParams, sv.mShowMoreMoreKeys) addLocaleKeyTextsToParams(mContext, mParams, sv.mShowMoreMoreKeys)
mParams.mMoreKeyTypes.addAll(sv.mMoreKeyTypes) mParams.mMoreKeyTypes.addAll(sv.mMoreKeyTypes)
mParams.mMoreKeyLabelSources.addAll(sv.mMoreKeyLabelSources) // add label source only if moreKey type enabled
sv.mMoreKeyLabelSources.forEach { if (it in sv.mMoreKeyTypes) mParams.mMoreKeyLabelSources.add(it) }
keysInRows = KeyboardParser.parseFromAssets(mParams, mContext) keysInRows = KeyboardParser.parseFromAssets(mParams, mContext)
determineAbsoluteValues() determineAbsoluteValues()
} catch (e: Exception) { } catch (e: Exception) {

View file

@ -24,6 +24,8 @@ import org.dslul.openboard.inputmethod.latin.define.DebugFlags
import org.dslul.openboard.inputmethod.latin.settings.Settings import org.dslul.openboard.inputmethod.latin.settings.Settings
import org.dslul.openboard.inputmethod.latin.spellcheck.AndroidSpellCheckerService import org.dslul.openboard.inputmethod.latin.spellcheck.AndroidSpellCheckerService
import org.dslul.openboard.inputmethod.latin.utils.InputTypeUtils import org.dslul.openboard.inputmethod.latin.utils.InputTypeUtils
import org.dslul.openboard.inputmethod.latin.utils.MORE_KEYS_LAYOUT
import org.dslul.openboard.inputmethod.latin.utils.MORE_KEYS_NUMBER
import org.dslul.openboard.inputmethod.latin.utils.RunInLocale import org.dslul.openboard.inputmethod.latin.utils.RunInLocale
import org.dslul.openboard.inputmethod.latin.utils.ScriptUtils import org.dslul.openboard.inputmethod.latin.utils.ScriptUtils
import org.dslul.openboard.inputmethod.latin.utils.sumOf import org.dslul.openboard.inputmethod.latin.utils.sumOf
@ -44,9 +46,9 @@ abstract class KeyboardParser(private val params: KeyboardParams, private val co
Key.LABEL_FLAGS_DISABLE_HINT_LABEL // reproduce the no-hints in symbol layouts, todo: add setting Key.LABEL_FLAGS_DISABLE_HINT_LABEL // reproduce the no-hints in symbol layouts, todo: add setting
else 0 else 0
protected abstract fun getLayoutFromAssets(layoutName: String): String abstract fun getLayoutFromAssets(layoutName: String): String
protected abstract fun parseCoreLayout(layoutContent: String): MutableList<List<KeyData>> abstract fun parseCoreLayout(layoutContent: String): MutableList<List<KeyData>>
fun parseLayoutFromAssets(layoutName: String): ArrayList<ArrayList<KeyParams>> = fun parseLayoutFromAssets(layoutName: String): ArrayList<ArrayList<KeyParams>> =
parseLayoutString(getLayoutFromAssets(layoutName)) parseLayoutString(getLayoutFromAssets(layoutName))
@ -87,11 +89,22 @@ abstract class KeyboardParser(private val params: KeyboardParams, private val co
// replace first symbols row with number row // replace first symbols row with number row
baseKeys[0] = params.mLocaleKeyTexts.getNumberRow() baseKeys[0] = params.mLocaleKeyTexts.getNumberRow()
} else if (!params.mId.mNumberRowEnabled && params.mId.isAlphabetKeyboard } else if (!params.mId.mNumberRowEnabled && params.mId.isAlphabetKeyboard
&& params.mId.locale.language != "ko" // todo: move this decision to some other place!
&& !(params.mId.locale.language == "ko" && baseKeys.size == 4)
&& params.mId.locale.language != "th" && params.mId.locale.language != "th"
&& params.mId.locale.language != "lo" && params.mId.locale.language != "lo"
&& params.mId.mSubtype.keyboardLayoutSetName != "pcqwerty" && params.mId.mSubtype.keyboardLayoutSetName != "pcqwerty"
) { ) {
if (baseKeys[0].any { it.popup.main != null || !it.popup.relevant.isNullOrEmpty() } // first row of baseKeys has any layout more key
&& params.mMoreKeyLabelSources.let {
val layout = it.indexOf(MORE_KEYS_LAYOUT)
val number = it.indexOf(MORE_KEYS_NUMBER)
layout != -1 && layout < number // layout before number label
}
) {
// remove number from labels, to avoid awkward mix of numbers and others caused by layout more keys
params.mMoreKeyLabelSources.remove(MORE_KEYS_NUMBER)
}
// add number to the first 10 keys in first row // add number to the first 10 keys in first row
// setting the correct moreKeys is handled in PopupSet // setting the correct moreKeys is handled in PopupSet
// not for korean/lao/thai layouts, todo: should be decided in the layout / layoutInfos, not in the parser // not for korean/lao/thai layouts, todo: should be decided in the layout / layoutInfos, not in the parser
@ -103,6 +116,20 @@ abstract class KeyboardParser(private val params: KeyboardParams, private val co
} }
} }
if (params.mId.isAlphabetKeyboard) {
// fill popup symbols
val symbolsLayoutName = if (ScriptUtils.getScriptFromSpellCheckerLocale(params.mId.locale) == ScriptUtils.SCRIPT_ARABIC)
"symbols_arabic"
else "symbols"
val p = SimpleKeyboardParser(params, context)
p.parseCoreLayout(p.getLayoutFromAssets(symbolsLayoutName)).forEachIndexed { i, row ->
val baseRow = baseKeys.getOrNull(i) ?: return@forEachIndexed
row.forEachIndexed { j, key ->
baseRow.getOrNull(j)?.popup?.symbol = key.label
}
}
}
val keysInRows = ArrayList<ArrayList<KeyParams>>() val keysInRows = ArrayList<ArrayList<KeyParams>>()
val functionalKeysReversed = parseFunctionalKeys(R.string.key_def_functional).reversed() val functionalKeysReversed = parseFunctionalKeys(R.string.key_def_functional).reversed()
val functionalKeysTop = parseFunctionalKeys(R.string.key_def_functional_top_row) val functionalKeysTop = parseFunctionalKeys(R.string.key_def_functional_top_row)
@ -815,6 +842,7 @@ abstract class KeyboardParser(private val params: KeyboardParams, private val co
} }
// todo: actually this should be in some separate file, or maybe part of an (extended) key texts
data class LayoutInfos( data class LayoutInfos(
val defaultLabelFlags: Int = 0, val defaultLabelFlags: Int = 0,
// disabled by default, but enabled for all alphabet layouts // disabled by default, but enabled for all alphabet layouts

View file

@ -6,6 +6,7 @@
package org.dslul.openboard.inputmethod.keyboard.internal.keyboard_parser.floris package org.dslul.openboard.inputmethod.keyboard.internal.keyboard_parser.floris
import kotlinx.serialization.Serializable import kotlinx.serialization.Serializable
import org.dslul.openboard.inputmethod.keyboard.internal.KeySpecParser
import org.dslul.openboard.inputmethod.keyboard.internal.KeyboardParams import org.dslul.openboard.inputmethod.keyboard.internal.KeyboardParams
// taken from FlorisBoard, considerably modified // taken from FlorisBoard, considerably modified
@ -19,13 +20,14 @@ open class PopupSet<T : AbstractKeyData>(
open fun getPopupKeyLabels(params: KeyboardParams): Collection<String>? { open fun getPopupKeyLabels(params: KeyboardParams): Collection<String>? {
if (main == null && relevant == null) return null if (main == null && relevant == null) return null
val moreKeys = mutableListOf<String>() val moreKeys = mutableListOf<String>()
main?.getLabel(params)?.let { moreKeys.add(it) } main?.getLabel(params)?.let { moreKeys.add(KeySpecParser.getLabel(it)!!) }
relevant?.let { moreKeys.addAll(it.map { it.getLabel(params) }) } relevant?.let { moreKeys.addAll(it.map { KeySpecParser.getLabel(it.getLabel(params))!! }) }
if (moreKeys.isEmpty()) return null if (moreKeys.isEmpty()) return null
return moreKeys return moreKeys
} }
var numberIndex: Int? = null var numberIndex: Int? = null
var symbol: String? = null // maybe list of keys?
} }
class SimplePopups(val moreKeys: Collection<String>?) : PopupSet<AbstractKeyData>() { class SimplePopups(val moreKeys: Collection<String>?) : PopupSet<AbstractKeyData>() {

View file

@ -18,35 +18,41 @@ import org.dslul.openboard.inputmethod.keyboard.internal.KeyboardParams
import org.dslul.openboard.inputmethod.keyboard.internal.keyboard_parser.floris.PopupSet import org.dslul.openboard.inputmethod.keyboard.internal.keyboard_parser.floris.PopupSet
import org.dslul.openboard.inputmethod.keyboard.internal.keyboard_parser.rtlLabel import org.dslul.openboard.inputmethod.keyboard.internal.keyboard_parser.rtlLabel
import org.dslul.openboard.inputmethod.latin.R import org.dslul.openboard.inputmethod.latin.R
import org.dslul.openboard.inputmethod.latin.settings.Settings
import java.util.Collections import java.util.Collections
private const val MORE_KEYS_NUMBER = "more_keys_number" const val MORE_KEYS_NUMBER = "more_keys_number"
private const val MORE_KEYS_LANGUAGE_PRIORITY = "more_keys_language_priority" private const val MORE_KEYS_LANGUAGE_PRIORITY = "more_keys_language_priority"
private const val MORE_KEYS_LAYOUT = "more_keys_layout" const val MORE_KEYS_LAYOUT = "more_keys_layout"
private const val MORE_KEYS_SYMBOLS = "more_keys_symbols" private const val MORE_KEYS_SYMBOLS = "more_keys_symbols"
private const val MORE_KEYS_LANGUAGE = "more_keys_language" private const val MORE_KEYS_LANGUAGE = "more_keys_language"
const val MORE_KEYS_LABEL_DEFAULT = "$MORE_KEYS_NUMBER,true;$MORE_KEYS_LANGUAGE_PRIORITY,false;$MORE_KEYS_LAYOUT,true;$MORE_KEYS_SYMBOLS,true;$MORE_KEYS_LANGUAGE,false" const val MORE_KEYS_LABEL_DEFAULT = "$MORE_KEYS_NUMBER,true;$MORE_KEYS_LANGUAGE_PRIORITY,false;$MORE_KEYS_LAYOUT,true;$MORE_KEYS_SYMBOLS,true;$MORE_KEYS_LANGUAGE,false"
const val MORE_KEYS_ORDER_DEFAULT = "$MORE_KEYS_LANGUAGE_PRIORITY,true;$MORE_KEYS_NUMBER,true;$MORE_KEYS_SYMBOLS,true;$MORE_KEYS_LAYOUT,true;$MORE_KEYS_LANGUAGE,true" const val MORE_KEYS_ORDER_DEFAULT = "$MORE_KEYS_LANGUAGE_PRIORITY,true;$MORE_KEYS_NUMBER,true;$MORE_KEYS_SYMBOLS,true;$MORE_KEYS_LAYOUT,true;$MORE_KEYS_LANGUAGE,true"
// todo: // todo:
// take moreKeys from symbols layout (in a separate commit) // could be done later:
// maybe also add a (simple) parser cache... or cache the layout somewhere else? // some way to allow hint labels in symbols layout
// that might be annoying with base and full layout (functional keys and spacers) // remove duplicate symbol moreKeys
// because base layout not available later... put it to keyParams? // in remove_symbol_duplicates.patch
// or create symbol moreKeys in the parser? that should work best, there we have proper access to layouts // issues, see comments
// maybe put "language" moreKeys into a different category when not using alphabet layout
// because disabling language moreKeys will remove e.g. quote moreKeys
fun createMoreKeysArray(popupSet: PopupSet<*>?, params: KeyboardParams, label: String): Array<String>? { fun createMoreKeysArray(popupSet: PopupSet<*>?, params: KeyboardParams, label: String): Array<String>? {
val moreKeys = mutableSetOf<String>() // often moreKeys are empty, so we want to avoid unnecessarily creating sets
val moreKeysDelegate = lazy { mutableSetOf<String>() }
val moreKeys by moreKeysDelegate
params.mMoreKeyTypes.forEach { type -> params.mMoreKeyTypes.forEach { type ->
when (type) { when (type) {
MORE_KEYS_NUMBER -> params.mLocaleKeyTexts.getNumberLabel(popupSet?.numberIndex)?.let { moreKeys.add(it) } MORE_KEYS_NUMBER -> params.mLocaleKeyTexts.getNumberLabel(popupSet?.numberIndex)?.let { moreKeys.add(it) }
MORE_KEYS_LAYOUT -> popupSet?.getPopupKeyLabels(params)?.let { moreKeys.addAll(it) } MORE_KEYS_LAYOUT -> popupSet?.getPopupKeyLabels(params)?.let { moreKeys.addAll(it) }
MORE_KEYS_SYMBOLS -> {} // todo MORE_KEYS_SYMBOLS -> popupSet?.symbol?.let { moreKeys.add(it) }
MORE_KEYS_LANGUAGE -> params.mLocaleKeyTexts.getMoreKeys(label)?.let { moreKeys.addAll(it) } MORE_KEYS_LANGUAGE -> params.mLocaleKeyTexts.getMoreKeys(label)?.let { moreKeys.addAll(it) }
MORE_KEYS_LANGUAGE_PRIORITY -> params.mLocaleKeyTexts.getPriorityMoreKeys(label)?.let { moreKeys.addAll(it) } MORE_KEYS_LANGUAGE_PRIORITY -> params.mLocaleKeyTexts.getPriorityMoreKeys(label)?.let { moreKeys.addAll(it) }
} }
} }
if (moreKeys.isEmpty()) return null if (!moreKeysDelegate.isInitialized() || moreKeys.isEmpty())
return null
val fco = moreKeys.firstOrNull { it.startsWith(Key.MORE_KEYS_FIXED_COLUMN_ORDER) } val fco = moreKeys.firstOrNull { it.startsWith(Key.MORE_KEYS_FIXED_COLUMN_ORDER) }
if (fco != null && fco.substringAfter(Key.MORE_KEYS_FIXED_COLUMN_ORDER).toIntOrNull() != moreKeys.size - 1) { if (fco != null && fco.substringAfter(Key.MORE_KEYS_FIXED_COLUMN_ORDER).toIntOrNull() != moreKeys.size - 1) {
moreKeys.remove(fco) // maybe rather adjust the number instead of remove? moreKeys.remove(fco) // maybe rather adjust the number instead of remove?
@ -66,16 +72,17 @@ fun getHintLabel(popupSet: PopupSet<*>?, params: KeyboardParams, label: String):
when (type) { when (type) {
MORE_KEYS_NUMBER -> params.mLocaleKeyTexts.getNumberLabel(popupSet?.numberIndex)?.let { hintLabel = it } MORE_KEYS_NUMBER -> params.mLocaleKeyTexts.getNumberLabel(popupSet?.numberIndex)?.let { hintLabel = it }
MORE_KEYS_LAYOUT -> popupSet?.getPopupKeyLabels(params)?.let { hintLabel = it.firstOrNull() } MORE_KEYS_LAYOUT -> popupSet?.getPopupKeyLabels(params)?.let { hintLabel = it.firstOrNull() }
MORE_KEYS_SYMBOLS -> {} // todo MORE_KEYS_SYMBOLS -> popupSet?.symbol?.let { hintLabel = it }
MORE_KEYS_LANGUAGE -> params.mLocaleKeyTexts.getMoreKeys(label)?.let { hintLabel = it.firstOrNull() } MORE_KEYS_LANGUAGE -> params.mLocaleKeyTexts.getMoreKeys(label)?.let { hintLabel = it.firstOrNull() }
MORE_KEYS_LANGUAGE_PRIORITY -> params.mLocaleKeyTexts.getPriorityMoreKeys(label)?.let { hintLabel = it.firstOrNull() } MORE_KEYS_LANGUAGE_PRIORITY -> params.mLocaleKeyTexts.getPriorityMoreKeys(label)?.let { hintLabel = it.firstOrNull() }
} }
if (hintLabel != null) break if (hintLabel != null) break
} }
// avoid e.g. !autoColumnOrder! as label // don't do the rtl transform, hint label is only the label
// this will avoid having labels on comma and period keys return hintLabel?.let { if (it == "$$$") transformLabel(it, params) else it }
return hintLabel?.let { transformLabel(it, params) } // avoid e.g. !autoColumnOrder! as label
// this will avoid having labels on comma and period keys
?.takeIf { !it.startsWith("!") || it == "!" } ?.takeIf { !it.startsWith("!") || it == "!" }
} }
@ -115,12 +122,6 @@ fun reorderMoreKeysDialog(context: Context, key: String, defaultSetting: String,
val adapter = object : ListAdapter<Pair<String, Boolean>, RecyclerView.ViewHolder>(callback) { val adapter = object : ListAdapter<Pair<String, Boolean>, RecyclerView.ViewHolder>(callback) {
override fun onCreateViewHolder(p0: ViewGroup, p1: Int): RecyclerView.ViewHolder { override fun onCreateViewHolder(p0: ViewGroup, p1: Int): RecyclerView.ViewHolder {
val b = LayoutInflater.from(context).inflate(R.layout.morekeys_list_item, rv, false) val b = LayoutInflater.from(context).inflate(R.layout.morekeys_list_item, rv, false)
// wtf? this results in transparent background, but when the background is set in xml it's fine?
// but of course when setting in xml i need to duplicate the entire thing except for background because of api things
// why tf is it so complicated to just use the dialog's background?
// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
// b.setBackgroundColor(android.R.attr.colorBackgroundFloating)
// }
return object : RecyclerView.ViewHolder(b) { } return object : RecyclerView.ViewHolder(b) { }
} }
override fun onBindViewHolder(p0: RecyclerView.ViewHolder, p1: Int) { override fun onBindViewHolder(p0: RecyclerView.ViewHolder, p1: Int) {
@ -130,6 +131,7 @@ fun reorderMoreKeysDialog(context: Context, key: String, defaultSetting: String,
p0.itemView.findViewById<TextView>(R.id.morekeys_type)?.text = displayText p0.itemView.findViewById<TextView>(R.id.morekeys_type)?.text = displayText
val switch = p0.itemView.findViewById<SwitchCompat>(R.id.morekeys_switch) val switch = p0.itemView.findViewById<SwitchCompat>(R.id.morekeys_switch)
switch?.isChecked = wasChecked switch?.isChecked = wasChecked
switch?.isEnabled = !(key.contains(Settings.PREF_MORE_KEYS_ORDER) && text == MORE_KEYS_LAYOUT) // layout can't be disabled
switch?.setOnCheckedChangeListener { _, isChecked -> switch?.setOnCheckedChangeListener { _, isChecked ->
val position = orderedItems.indexOfFirst { it.first == text } val position = orderedItems.indexOfFirst { it.first == text }
orderedItems[position] = text to isChecked orderedItems[position] = text to isChecked