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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -1,29 +1,29 @@
q %
d \
r |
w =
b [
j ]
f <
u >
p {
; }
q
d
r
w
b
j
f
u
p
;
a @
s #
h $$$
t _
g &
y -
n +
e (
o )
i /
a
s
h
t
g
y
n
e
o
i
z *
x "
m '
c :
v ;
k !
l ?
z
x
m
c
v
k
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
// 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
// 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
// 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
addLocaleKeyTextsToParams(mContext, mParams, sv.mShowMoreMoreKeys)
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)
determineAbsoluteValues()
} 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.spellcheck.AndroidSpellCheckerService
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.ScriptUtils
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
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>> =
parseLayoutString(getLayoutFromAssets(layoutName))
@ -87,11 +89,22 @@ abstract class KeyboardParser(private val params: KeyboardParams, private val co
// replace first symbols row with number row
baseKeys[0] = params.mLocaleKeyTexts.getNumberRow()
} 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 != "lo"
&& 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
// 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
@ -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 functionalKeysReversed = parseFunctionalKeys(R.string.key_def_functional).reversed()
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(
val defaultLabelFlags: Int = 0,
// 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
import kotlinx.serialization.Serializable
import org.dslul.openboard.inputmethod.keyboard.internal.KeySpecParser
import org.dslul.openboard.inputmethod.keyboard.internal.KeyboardParams
// taken from FlorisBoard, considerably modified
@ -19,13 +20,14 @@ open class PopupSet<T : AbstractKeyData>(
open fun getPopupKeyLabels(params: KeyboardParams): Collection<String>? {
if (main == null && relevant == null) return null
val moreKeys = mutableListOf<String>()
main?.getLabel(params)?.let { moreKeys.add(it) }
relevant?.let { moreKeys.addAll(it.map { it.getLabel(params) }) }
main?.getLabel(params)?.let { moreKeys.add(KeySpecParser.getLabel(it)!!) }
relevant?.let { moreKeys.addAll(it.map { KeySpecParser.getLabel(it.getLabel(params))!! }) }
if (moreKeys.isEmpty()) return null
return moreKeys
}
var numberIndex: Int? = null
var symbol: String? = null // maybe list of keys?
}
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.rtlLabel
import org.dslul.openboard.inputmethod.latin.R
import org.dslul.openboard.inputmethod.latin.settings.Settings
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_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_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_ORDER_DEFAULT = "$MORE_KEYS_LANGUAGE_PRIORITY,true;$MORE_KEYS_NUMBER,true;$MORE_KEYS_SYMBOLS,true;$MORE_KEYS_LAYOUT,true;$MORE_KEYS_LANGUAGE,true"
// todo:
// take moreKeys from symbols layout (in a separate commit)
// maybe also add a (simple) parser cache... or cache the layout somewhere else?
// that might be annoying with base and full layout (functional keys and spacers)
// because base layout not available later... put it to keyParams?
// or create symbol moreKeys in the parser? that should work best, there we have proper access to layouts
// could be done later:
// some way to allow hint labels in symbols layout
// remove duplicate symbol moreKeys
// in remove_symbol_duplicates.patch
// 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>? {
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 ->
when (type) {
MORE_KEYS_NUMBER -> params.mLocaleKeyTexts.getNumberLabel(popupSet?.numberIndex)?.let { moreKeys.add(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_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) }
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?
@ -66,16 +72,17 @@ fun getHintLabel(popupSet: PopupSet<*>?, params: KeyboardParams, label: String):
when (type) {
MORE_KEYS_NUMBER -> params.mLocaleKeyTexts.getNumberLabel(popupSet?.numberIndex)?.let { hintLabel = it }
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_PRIORITY -> params.mLocaleKeyTexts.getPriorityMoreKeys(label)?.let { hintLabel = it.firstOrNull() }
}
if (hintLabel != null) break
}
// don't do the rtl transform, hint label is only the label
return hintLabel?.let { if (it == "$$$") transformLabel(it, params) else it }
// avoid e.g. !autoColumnOrder! as label
// this will avoid having labels on comma and period keys
return hintLabel?.let { transformLabel(it, params) }
?.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) {
override fun onCreateViewHolder(p0: ViewGroup, p1: Int): RecyclerView.ViewHolder {
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) { }
}
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
val switch = p0.itemView.findViewById<SwitchCompat>(R.id.morekeys_switch)
switch?.isChecked = wasChecked
switch?.isEnabled = !(key.contains(Settings.PREF_MORE_KEYS_ORDER) && text == MORE_KEYS_LAYOUT) // layout can't be disabled
switch?.setOnCheckedChangeListener { _, isChecked ->
val position = orderedItems.indexOfFirst { it.first == text }
orderedItems[position] = text to isChecked