mirror of
https://gitlab.futo.org/keyboard/latinime.git
synced 2024-09-28 14:54:30 +01:00
Add some common actions into moreKeys
This commit is contained in:
parent
75d0f66024
commit
89b437d93a
13
java/res/drawable/maximize.xml
Normal file
13
java/res/drawable/maximize.xml
Normal file
@ -0,0 +1,13 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:pathData="M8,3H5a2,2 0,0 0,-2 2v3m18,0V5a2,2 0,0 0,-2 -2h-3m0,18h3a2,2 0,0 0,2 -2v-3M3,16v3a2,2 0,0 0,2 2h3"
|
||||
android:strokeLineJoin="round"
|
||||
android:strokeWidth="2"
|
||||
android:fillColor="#00000000"
|
||||
android:strokeColor="#ffffff"
|
||||
android:strokeLineCap="round"/>
|
||||
</vector>
|
41
java/res/drawable/scissors.xml
Normal file
41
java/res/drawable/scissors.xml
Normal file
@ -0,0 +1,41 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:pathData="M6,6m-3,0a3,3 0,1 1,6 0a3,3 0,1 1,-6 0"
|
||||
android:strokeLineJoin="round"
|
||||
android:strokeWidth="2"
|
||||
android:fillColor="#00000000"
|
||||
android:strokeColor="#ffffff"
|
||||
android:strokeLineCap="round"/>
|
||||
<path
|
||||
android:pathData="M6,18m-3,0a3,3 0,1 1,6 0a3,3 0,1 1,-6 0"
|
||||
android:strokeLineJoin="round"
|
||||
android:strokeWidth="2"
|
||||
android:fillColor="#00000000"
|
||||
android:strokeColor="#ffffff"
|
||||
android:strokeLineCap="round"/>
|
||||
<path
|
||||
android:pathData="M20,4L8.12,15.88"
|
||||
android:strokeLineJoin="round"
|
||||
android:strokeWidth="2"
|
||||
android:fillColor="#00000000"
|
||||
android:strokeColor="#ffffff"
|
||||
android:strokeLineCap="round"/>
|
||||
<path
|
||||
android:pathData="M14.47,14.48L20,20"
|
||||
android:strokeLineJoin="round"
|
||||
android:strokeWidth="2"
|
||||
android:fillColor="#00000000"
|
||||
android:strokeColor="#ffffff"
|
||||
android:strokeLineCap="round"/>
|
||||
<path
|
||||
android:pathData="M8.12,8.12L12,12"
|
||||
android:strokeLineJoin="round"
|
||||
android:strokeWidth="2"
|
||||
android:fillColor="#00000000"
|
||||
android:strokeColor="#ffffff"
|
||||
android:strokeLineCap="round"/>
|
||||
</vector>
|
@ -4,6 +4,9 @@
|
||||
<string name="system_voice_input_action_title">Voice Input (System)</string>
|
||||
<string name="theme_switcher_action_title">Theme Switcher</string>
|
||||
<string name="emoji_action_title">Emojis</string>
|
||||
<string name="select_all_action_title">Select All</string>
|
||||
<string name="cut_action_title">Cut to Clipboard</string>
|
||||
<string name="copy_action_title">Copy to Clipboard</string>
|
||||
<string name="clipboard_action_title">Paste from Clipboard</string>
|
||||
<string name="clipboard_manager_action_title">Clipboard Manager</string>
|
||||
<string name="undo_action_title">Undo</string>
|
||||
|
@ -24,7 +24,7 @@
|
||||
<Key
|
||||
latin:keySpec="a"
|
||||
latin:keyHintLabel="\@"
|
||||
latin:additionalMoreKeys="\\@"
|
||||
latin:additionalMoreKeys="\\@,!icon/action_select_all|!code/action_select_all"
|
||||
latin:moreKeys="!text/morekeys_a" />
|
||||
<Key
|
||||
latin:keySpec="s"
|
||||
|
@ -24,21 +24,21 @@
|
||||
<Key
|
||||
latin:keySpec="z"
|
||||
latin:keyHintLabel="*"
|
||||
latin:additionalMoreKeys="*"
|
||||
latin:additionalMoreKeys="*,!icon/action_undo|!code/action_undo"
|
||||
latin:moreKeys="!text/morekeys_z" />
|
||||
<Key
|
||||
latin:keySpec="!text/keyspec_x"
|
||||
latin:keyHintLabel="""
|
||||
latin:additionalMoreKeys="""
|
||||
latin:additionalMoreKeys="",!icon/action_cut|!code/action_cut"
|
||||
latin:moreKeys="!text/morekeys_x" />
|
||||
<Key
|
||||
latin:keySpec="c"
|
||||
latin:keyHintLabel="'"
|
||||
latin:additionalMoreKeys="'"
|
||||
latin:additionalMoreKeys="',!icon/action_copy|!code/action_copy"
|
||||
latin:moreKeys="!text/morekeys_c" />
|
||||
<Key
|
||||
latin:keySpec="v"
|
||||
latin:keyHintLabel=":"
|
||||
latin:additionalMoreKeys=":"
|
||||
latin:additionalMoreKeys=":,!icon/action_paste|!code/action_paste"
|
||||
latin:moreKeys="!text/morekeys_v" />
|
||||
</merge>
|
||||
|
@ -20,6 +20,7 @@ import static org.futo.inputmethod.latin.common.Constants.CODE_ACTION_0;
|
||||
import static org.futo.inputmethod.latin.common.Constants.CODE_UNSPECIFIED;
|
||||
|
||||
import org.futo.inputmethod.latin.common.Constants;
|
||||
import org.futo.inputmethod.latin.uix.actions.ActionRegistry;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
@ -35,7 +36,7 @@ public final class KeyboardCodesSet {
|
||||
|
||||
public static int getCode(final String name) {
|
||||
if(name.startsWith(ACTION_CODE_PREFIX)) {
|
||||
int id = CODE_ACTION_0 + Integer.parseInt(name.substring(ACTION_CODE_PREFIX.length()));
|
||||
int id = CODE_ACTION_0 + ActionRegistry.INSTANCE.parseAction(name);
|
||||
if(id >= CODE_UNSPECIFIED) throw new RuntimeException("Action ID too high!");
|
||||
return id;
|
||||
}
|
||||
|
@ -24,8 +24,8 @@ import androidx.datastore.preferences.core.floatPreferencesKey
|
||||
import com.google.android.material.color.DynamicColors
|
||||
import org.futo.inputmethod.keyboard.internal.KeyboardIconsSet
|
||||
import org.futo.inputmethod.latin.R
|
||||
import org.futo.inputmethod.latin.uix.actions.ActionRegistry
|
||||
import org.futo.inputmethod.latin.uix.actions.AllActions
|
||||
import org.futo.inputmethod.latin.uix.actions.AllActionsMap
|
||||
import org.futo.inputmethod.latin.uix.theme.DarkColorScheme
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
@ -249,15 +249,6 @@ class BasicThemeProvider(val context: Context, val overrideColorScheme: ColorSch
|
||||
colors[R.styleable.MainKeyboardView_gestureTrailColor] = primary
|
||||
colors[R.styleable.MainKeyboardView_slidingKeyInputPreviewColor] = primary
|
||||
|
||||
val overrideDrawable: (Int, Int, Int) -> Unit = { a, b, color ->
|
||||
drawables[a] = AppCompatResources.getDrawable(
|
||||
context,
|
||||
b
|
||||
)!!.apply {
|
||||
setTint(color)
|
||||
}
|
||||
}
|
||||
|
||||
addIcon(KeyboardIconsSet.NAME_SHIFT_KEY, R.drawable.shift, onBackground)
|
||||
addIcon(KeyboardIconsSet.NAME_SHIFT_KEY_SHIFTED, R.drawable.shiftshifted, onBackground)
|
||||
addIcon(KeyboardIconsSet.NAME_DELETE_KEY, R.drawable.delete, onBackground)
|
||||
@ -277,28 +268,15 @@ class BasicThemeProvider(val context: Context, val overrideColorScheme: ColorSch
|
||||
addIcon(KeyboardIconsSet.NAME_EMOJI_ACTION_KEY, R.drawable.smile, onPrimary)
|
||||
addIcon(KeyboardIconsSet.NAME_EMOJI_NORMAL_KEY, R.drawable.smile, onBackground)
|
||||
|
||||
AllActions.forEachIndexed { i, it ->
|
||||
// Add by name (action_emoji)
|
||||
AllActionsMap.forEach { (i, it) ->
|
||||
addIcon("action_${i}", it.icon, onBackground)
|
||||
}
|
||||
|
||||
// No good replacements for these icons yet, but we set them anyway for setTint
|
||||
overrideDrawable(R.styleable.Keyboard_iconEnterKey, R.drawable.sym_keyboard_return_lxx_light, enterKeyForeground)
|
||||
overrideDrawable(R.styleable.Keyboard_iconGoKey, R.drawable.sym_keyboard_go_lxx_light, enterKeyForeground)
|
||||
overrideDrawable(R.styleable.Keyboard_iconNextKey, R.drawable.sym_keyboard_next_lxx_light, enterKeyForeground)
|
||||
overrideDrawable(R.styleable.Keyboard_iconDoneKey, R.drawable.sym_keyboard_done_lxx_light, enterKeyForeground)
|
||||
overrideDrawable(R.styleable.Keyboard_iconPreviousKey, R.drawable.sym_keyboard_previous_lxx_light, enterKeyForeground)
|
||||
overrideDrawable(R.styleable.Keyboard_iconSearchKey, R.drawable.sym_keyboard_search_lxx_light, enterKeyForeground)
|
||||
|
||||
overrideDrawable(R.styleable.Keyboard_iconZwjKey, R.drawable.sym_keyboard_zwj_lxx_dark, onPrimary)
|
||||
overrideDrawable(R.styleable.Keyboard_iconZwnjKey, R.drawable.sym_keyboard_zwnj_lxx_dark, onBackground)
|
||||
|
||||
overrideDrawable(R.styleable.Keyboard_iconDeleteKey, R.drawable.delete, onBackground)
|
||||
overrideDrawable(R.styleable.Keyboard_iconSettingsKey, R.drawable.settings, onBackground)
|
||||
overrideDrawable(R.styleable.Keyboard_iconEmojiActionKey, R.drawable.smile, onPrimary)
|
||||
overrideDrawable(R.styleable.Keyboard_iconEmojiNormalKey, R.drawable.smile, onBackground)
|
||||
overrideDrawable(R.styleable.Keyboard_iconLanguageSwitchKey, R.drawable.globe, onBackground)
|
||||
overrideDrawable(R.styleable.Keyboard_iconShiftKey, R.drawable.shift, onBackground)
|
||||
overrideDrawable(R.styleable.Keyboard_iconShiftKeyShifted, R.drawable.shiftshifted, onBackground)
|
||||
// Add by id (action_0)
|
||||
AllActions.forEachIndexed { i, it ->
|
||||
addIcon("action_${i}", it.icon, onBackground)
|
||||
}
|
||||
|
||||
if(!showKeyHints) {
|
||||
colors[R.styleable.Keyboard_Key_keyHintLetterColor] = transparent
|
||||
@ -314,10 +292,6 @@ class BasicThemeProvider(val context: Context, val overrideColorScheme: ColorSch
|
||||
|
||||
// Note: We don't fully hide some things, but fade them away as they may be important landmarks
|
||||
colors[R.styleable.Keyboard_Key_functionalTextColor] = onBackgroundThird
|
||||
overrideDrawable(R.styleable.Keyboard_iconShiftKey, R.drawable.shift, onBackgroundThird)
|
||||
overrideDrawable(R.styleable.Keyboard_iconShiftKeyShifted, R.drawable.shiftshifted, onBackgroundThird)
|
||||
overrideDrawable(R.styleable.Keyboard_iconDeleteKey, R.drawable.delete, onBackgroundThird)
|
||||
overrideDrawable(R.styleable.Keyboard_iconEmojiNormalKey, R.drawable.smile, transparent)
|
||||
}
|
||||
|
||||
keyboardBackground = coloredRectangle(primaryKeyboardColor)
|
||||
|
@ -665,11 +665,13 @@ class UixManager(private val latinIME: LatinIME) {
|
||||
}
|
||||
|
||||
fun triggerAction(id: Int) {
|
||||
if(currWindowAction == null) {
|
||||
onActionActivated(
|
||||
AllActions.getOrNull(id) ?: throw IllegalArgumentException("No such action with ID $id")
|
||||
)
|
||||
val action = AllActions.getOrNull(id) ?: throw IllegalArgumentException("No such action with ID $id")
|
||||
|
||||
if(currWindowAction != null && action.windowImpl != null) {
|
||||
closeActionWindow()
|
||||
}
|
||||
|
||||
onActionActivated(action)
|
||||
}
|
||||
|
||||
fun requestForgetWord(suggestedWordInfo: SuggestedWords.SuggestedWordInfo) {
|
||||
|
@ -1,14 +0,0 @@
|
||||
package org.futo.inputmethod.latin.uix.actions
|
||||
|
||||
import android.view.KeyEvent
|
||||
import org.futo.inputmethod.latin.R
|
||||
import org.futo.inputmethod.latin.uix.Action
|
||||
|
||||
val ClipboardAction = Action(
|
||||
icon = R.drawable.clipboard,
|
||||
name = R.string.clipboard_action_title,
|
||||
simplePressImpl = { manager, _ ->
|
||||
manager.sendKeyEvent(KeyEvent.KEYCODE_V, KeyEvent.META_CTRL_ON)
|
||||
},
|
||||
windowImpl = null,
|
||||
)
|
@ -0,0 +1,41 @@
|
||||
package org.futo.inputmethod.latin.uix.actions
|
||||
|
||||
import android.view.KeyEvent
|
||||
import org.futo.inputmethod.latin.R
|
||||
import org.futo.inputmethod.latin.uix.Action
|
||||
|
||||
val SelectAllAction = Action(
|
||||
icon = R.drawable.maximize,
|
||||
name = R.string.select_all_action_title,
|
||||
simplePressImpl = { manager, _ ->
|
||||
manager.sendKeyEvent(KeyEvent.KEYCODE_A, KeyEvent.META_CTRL_ON)
|
||||
},
|
||||
windowImpl = null,
|
||||
)
|
||||
|
||||
val CutAction = Action(
|
||||
icon = R.drawable.scissors,
|
||||
name = R.string.cut_action_title,
|
||||
simplePressImpl = { manager, _ ->
|
||||
manager.sendKeyEvent(KeyEvent.KEYCODE_X, KeyEvent.META_CTRL_ON)
|
||||
},
|
||||
windowImpl = null,
|
||||
)
|
||||
|
||||
val CopyAction = Action(
|
||||
icon = R.drawable.copy,
|
||||
name = R.string.copy_action_title,
|
||||
simplePressImpl = { manager, _ ->
|
||||
manager.sendKeyEvent(KeyEvent.KEYCODE_C, KeyEvent.META_CTRL_ON)
|
||||
},
|
||||
windowImpl = null,
|
||||
)
|
||||
|
||||
val PasteAction = Action(
|
||||
icon = R.drawable.clipboard,
|
||||
name = R.string.clipboard_action_title,
|
||||
simplePressImpl = { manager, _ ->
|
||||
manager.sendKeyEvent(KeyEvent.KEYCODE_V, KeyEvent.META_CTRL_ON)
|
||||
},
|
||||
windowImpl = null,
|
||||
)
|
@ -2,6 +2,7 @@ package org.futo.inputmethod.latin.uix.actions
|
||||
|
||||
import android.content.Context
|
||||
import androidx.datastore.preferences.core.stringPreferencesKey
|
||||
import org.futo.inputmethod.keyboard.internal.KeyboardCodesSet
|
||||
import org.futo.inputmethod.latin.uix.Action
|
||||
import org.futo.inputmethod.latin.uix.USE_SYSTEM_VOICE_INPUT
|
||||
import org.futo.inputmethod.latin.uix.getSetting
|
||||
@ -10,26 +11,34 @@ val ExpandableActionItems = stringPreferencesKey("expandableActions")
|
||||
val PinnedActionItems = stringPreferencesKey("pinnedActions")
|
||||
|
||||
// Note: indices must stay stable
|
||||
val AllActions = listOf(
|
||||
EmojiAction,
|
||||
SettingsAction,
|
||||
ClipboardAction,
|
||||
TextEditAction,
|
||||
ThemeAction,
|
||||
UndoAction,
|
||||
RedoAction,
|
||||
VoiceInputAction,
|
||||
SystemVoiceInputAction,
|
||||
SwitchLanguageAction,
|
||||
ClipboardHistoryAction,
|
||||
MemoryDebugAction
|
||||
val AllActionsMap = mapOf(
|
||||
"emoji" to EmojiAction,
|
||||
"settings" to SettingsAction,
|
||||
"paste" to PasteAction,
|
||||
"text_edit" to TextEditAction,
|
||||
"themes" to ThemeAction,
|
||||
"undo" to UndoAction,
|
||||
"redo" to RedoAction,
|
||||
"voice_input" to VoiceInputAction,
|
||||
"system_voice_input" to SystemVoiceInputAction,
|
||||
"switch_language" to SwitchLanguageAction,
|
||||
"clipboard_history" to ClipboardHistoryAction,
|
||||
"mem_dbg" to MemoryDebugAction,
|
||||
"cut" to CutAction,
|
||||
"copy" to CopyAction,
|
||||
"select_all" to SelectAllAction
|
||||
)
|
||||
|
||||
val ActionToId = AllActionsMap.entries.associate { it.value to it.key }
|
||||
|
||||
val AllActions = AllActionsMap.values.toList()
|
||||
|
||||
val ActionIdToInt = AllActionsMap.entries.associate { it.key to AllActions.indexOf(it.value) }
|
||||
|
||||
object ActionRegistry {
|
||||
val EnterActions = "!fixedColumnOrder!4,!needsDividers!," +
|
||||
listOf(SwitchLanguageAction, TextEditAction, ClipboardHistoryAction, EmojiAction, UndoAction, RedoAction).map {
|
||||
AllActions.indexOf(it)
|
||||
ActionToId[it]
|
||||
}.joinToString(separator = ",") {
|
||||
"!icon/action_$it|!code/action_$it"
|
||||
}
|
||||
@ -70,6 +79,16 @@ object ActionRegistry {
|
||||
action
|
||||
}
|
||||
}
|
||||
|
||||
fun parseAction(actionString: String): Int {
|
||||
val action = if(actionString.startsWith(KeyboardCodesSet.ACTION_CODE_PREFIX)) {
|
||||
actionString.substring(KeyboardCodesSet.ACTION_CODE_PREFIX.length)
|
||||
} else {
|
||||
actionString
|
||||
}
|
||||
|
||||
return action.toIntOrNull() ?: ActionIdToInt[action] ?: throw IllegalArgumentException("Unknown action $actionString")
|
||||
}
|
||||
}
|
||||
|
||||
val DefaultActions = listOf(
|
||||
@ -77,7 +96,7 @@ val DefaultActions = listOf(
|
||||
TextEditAction,
|
||||
UndoAction,
|
||||
RedoAction,
|
||||
ClipboardAction,
|
||||
PasteAction,
|
||||
SettingsAction,
|
||||
ThemeAction,
|
||||
MemoryDebugAction,
|
||||
|
Loading…
Reference in New Issue
Block a user