Newer
Older
package org.futo.inputmethod.v2keyboard
import android.view.inputmethod.EditorInfo
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import org.futo.inputmethod.keyboard.KeyboardId
import org.futo.inputmethod.keyboard.internal.KeyboardIconsSet
import org.futo.inputmethod.keyboard.internal.KeyboardParams
import org.futo.inputmethod.latin.common.Constants
import org.futo.inputmethod.latin.uix.actions.AllActionKeys
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import org.futo.inputmethod.latin.utils.InputTypeUtils
val FunctionalAttributes = KeyAttributes(
width = KeyWidth.FunctionalKey,
style = KeyVisualStyle.Functional,
anchored = true,
showPopup = false,
moreKeyMode = MoreKeyMode.OnlyExplicit,
labelFlags = LabelFlags(followKeyLetterRatio = false, followKeyLargeLetterRatio = false, followKeyLabelRatio = false)
)
private val ShiftMoreKeys = listOf("!noPanelAutoMoreKey!", " |!code/key_capslock")
val TemplateShiftKey = CaseSelector(
normal = BaseKey(
spec = "!icon/shift_key|!code/key_shift",
moreKeys = ShiftMoreKeys,
attributes = FunctionalAttributes
),
shifted = BaseKey(
spec = "!icon/shift_key_shifted|!code/key_shift",
moreKeys = ShiftMoreKeys,
attributes = FunctionalAttributes
),
shiftLocked = BaseKey(
spec = "!icon/shift_key_shifted|!code/key_shift",
moreKeys = ShiftMoreKeys,
attributes = FunctionalAttributes.copy(style = KeyVisualStyle.StickyOn)
),
symbols = BaseKey(
spec = "!text/keylabel_to_more_symbol|!code/key_shift",
attributes = FunctionalAttributes
),
symbolsShifted = BaseKey(
spec = "!text/keylabel_to_symbol|!code/key_shift",
attributes = FunctionalAttributes
)
)
val TemplateDeleteKey = BaseKey(
spec = "!icon/delete_key|!code/key_delete",
attributes = FunctionalAttributes.copy(repeatableEnabled = true)
)
val TemplateSymbolsKey = BaseKey(
spec = "!text/keylabel_to_symbol|!code/key_switch_alpha_symbol",
attributes = FunctionalAttributes
)
val TemplateAlphabetKey = BaseKey(
spec = "!text/keylabel_to_alpha|!code/key_switch_alpha_symbol",
attributes = FunctionalAttributes
)
val TemplateNumberKey = BaseKey(
spec = "!icon/numpad|!code/key_to_number_layout",
attributes = KeyAttributes(
showPopup = false
)
)
val TemplateSpaceKey = BaseKey(
spec = "!icon/space_key|!code/key_space",
attributes = KeyAttributes(
width = KeyWidth.Grow,
style = KeyVisualStyle.Spacebar,
showPopup = false,
longPressEnabled = true,
moreKeyMode = MoreKeyMode.OnlyExplicit
)
)
val TemplateAlt0Key = BaseKey(
spec = "0|!code/key_to_alt_0_layout",
attributes = FunctionalAttributes
)
val TemplateAlt1Key = BaseKey(
spec = "1|!code/key_to_alt_1_layout",
attributes = FunctionalAttributes
)
val TemplateAlt2Key = BaseKey(
spec = "2|!code/key_to_alt_2_layout",
attributes = FunctionalAttributes
)
@Serializable
@SerialName("enter")
data class EnterKey(
val attributes: KeyAttributes = KeyAttributes(width = KeyWidth.FunctionalKey)
) : AbstractKey {
override fun countsToKeyCoordinate(params: KeyboardParams, row: Row, keyboard: Keyboard): Boolean = false
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
override fun computeData(
params: KeyboardParams,
row: Row,
keyboard: Keyboard,
coordinate: KeyCoordinate
): ComputedKeyData {
val attributes = attributes.getEffectiveAttributes(row, keyboard)
// Icon, etc depend on editorInfo.
val icon = when(params.mId.imeAction()) {
EditorInfo.IME_ACTION_UNSPECIFIED -> KeyboardIconsSet.NAME_ENTER_KEY
EditorInfo.IME_ACTION_NONE -> KeyboardIconsSet.NAME_ENTER_KEY
EditorInfo.IME_ACTION_GO -> KeyboardIconsSet.NAME_GO_KEY
EditorInfo.IME_ACTION_SEARCH -> KeyboardIconsSet.NAME_SEARCH_KEY
EditorInfo.IME_ACTION_SEND -> KeyboardIconsSet.NAME_SEND_KEY
EditorInfo.IME_ACTION_NEXT -> KeyboardIconsSet.NAME_NEXT_KEY
EditorInfo.IME_ACTION_DONE -> KeyboardIconsSet.NAME_DONE_KEY
EditorInfo.IME_ACTION_PREVIOUS -> KeyboardIconsSet.NAME_PREVIOUS_KEY
InputTypeUtils.IME_ACTION_CUSTOM_LABEL -> KeyboardIconsSet.NAME_ENTER_KEY
else -> KeyboardIconsSet.NAME_ENTER_KEY
}
val moreKeys = if(params.mId.navigateNext() || params.mId.navigatePrevious()) {
"!text/keyspec_emoji_action_key_navigation"
} else {
"!text/keyspec_emoji_action_key"
}.let {
MoreKeysBuilder(
code = Constants.CODE_ENTER,
mode = attributes.moreKeyMode!!,
coordinate = coordinate,
row = row,
keyboard = keyboard,
params = params
).insertMoreKeys(it).build(false)
}
return ComputedKeyData(
label = "",
code = Constants.CODE_ENTER,
outputText = null,
width = attributes.width ?: KeyWidth.FunctionalKey,
icon = icon,
style = KeyVisualStyle.Action,
anchored = true,
showPopup = false,
moreKeys = moreKeys.specs,
longPressEnabled = true,
repeatable = false,
moreKeyFlags = moreKeys.flags,
countsToKeyCoordinate = false,
labelFlags = 0
)
}
}
@Serializable
@SerialName("action")
data class ActionKey(
val attributes: KeyAttributes = KeyAttributes()
) : AbstractKey {
override fun countsToKeyCoordinate(params: KeyboardParams, row: Row, keyboard: Keyboard): Boolean = false
override fun computeData(
params: KeyboardParams,
row: Row,
keyboard: Keyboard,
coordinate: KeyCoordinate
): ComputedKeyData? {
if(!params.mId.mBottomEmojiKeyEnabled) {
return null
}
val attributes = attributes.getEffectiveAttributes(row, keyboard)
val actionId = params.mId.mBottomActionKeyId
return ComputedKeyData(
label = "",
code = Constants.CODE_ACTION_0 + actionId,
outputText = null,
width = attributes.width ?: KeyWidth.Regular,
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
style = attributes.style ?: KeyVisualStyle.Functional,
anchored = true,
showPopup = false,
moreKeys = listOf(),
longPressEnabled = true,
repeatable = false,
moreKeyFlags = 0,
countsToKeyCoordinate = false,
hint = "",
labelFlags = 0
)
}
}
@Serializable
@SerialName("contextual")
data class ContextualKey(
val attributes: KeyAttributes = KeyAttributes(),
val fallbackKey: Key? = null
) : AbstractKey {
val keys = mapOf(
KeyboardId.MODE_EMAIL to BaseKey(spec = "@", attributes = attributes),
KeyboardId.MODE_URL to BaseKey(spec = "/", attributes = attributes),
KeyboardId.MODE_DATETIME to BaseKey(spec = "/", moreKeys = listOf(":"), attributes = attributes),
KeyboardId.MODE_DATE to BaseKey(spec = "/", attributes = attributes),
KeyboardId.MODE_TIME to BaseKey(spec = ":", attributes = attributes),
)
private fun selectKey(params: KeyboardParams, keyboard: Keyboard): Key? {
if(keyboard.useZWNJKey) {
return TemplateZWNJKey
}
val key = keys[params.mId.mMode] ?: fallbackKey
return key
}
override fun countsToKeyCoordinate(params: KeyboardParams, row: Row, keyboard: Keyboard): Boolean {
return selectKey(params, keyboard)?.countsToKeyCoordinate(params, row, keyboard) ?: false
}
override fun computeData(
params: KeyboardParams,
row: Row,
keyboard: Keyboard,
coordinate: KeyCoordinate
): ComputedKeyData? {
return selectKey(params, keyboard)?.computeData(params, row, keyboard, coordinate)
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
}
}
val TemplateEnterKey = EnterKey()
val TemplateActionKey = ActionKey()
val TemplateContextualKey = ContextualKey()
val TemplateGapKey = GapKey()
val TemplateZWNJKey = BaseKey(
spec = "!icon/zwnj_key|\u200C",
moreKeys = listOf("!icon/zwj_key|\u200D"),
attributes = KeyAttributes(
showPopup = false,
moreKeyMode = MoreKeyMode.OnlyExplicit
)
)
val TemplateKeys = mapOf(
"shift" to TemplateShiftKey,
"delete" to TemplateDeleteKey,
"space" to TemplateSpaceKey,
"enter" to TemplateEnterKey,
"symbols" to TemplateSymbolsKey,
"alphabet" to TemplateAlphabetKey,
"action" to TemplateActionKey,
"number" to TemplateNumberKey,
"contextual" to TemplateContextualKey,
"zwnj" to TemplateZWNJKey,
"gap" to TemplateGapKey,
"alt0" to TemplateAlt0Key,
"alt1" to TemplateAlt1Key,
"alt2" to TemplateAlt2Key,
)