diff options
| author | Jules Aguillon | 2022-01-09 20:26:06 +0100 |
|---|---|---|
| committer | Jules Aguillon | 2022-01-09 20:26:06 +0100 |
| commit | 53113cadd9654c827ae306905dae4d738dedf818 (patch) | |
| tree | fe56afe810939608893fd82732e9f7f29105a563 /srcs/juloo.keyboard2/Keyboard2.java | |
| parent | 4b43645c4b6632d0cd2388b90e7bc2bbde98087e (diff) | |
| download | unexpected-keyboard-53113cadd9654c827ae306905dae4d738dedf818.tar.gz unexpected-keyboard-53113cadd9654c827ae306905dae4d738dedf818.zip | |
Add the Action key
It is placed on the top-right of the enter key on every layouts.
It sends a special event (performEditorAction) instead of writing a
newline.
The "actionId" is passed through the EditorInfo object in an obfuscated
way so it's not clear whether it's using the right one.
Diffstat (limited to 'srcs/juloo.keyboard2/Keyboard2.java')
| -rw-r--r-- | srcs/juloo.keyboard2/Keyboard2.java | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/srcs/juloo.keyboard2/Keyboard2.java b/srcs/juloo.keyboard2/Keyboard2.java index 2d807cf..f54b3fa 100644 --- a/srcs/juloo.keyboard2/Keyboard2.java +++ b/srcs/juloo.keyboard2/Keyboard2.java @@ -138,10 +138,45 @@ public class Keyboard2 extends InputMethodService } } + private String actionLabel_of_imeAction(int action) + { + switch (action) + { + case EditorInfo.IME_ACTION_UNSPECIFIED: + case EditorInfo.IME_ACTION_NEXT: return "Next"; + case EditorInfo.IME_ACTION_DONE: return "Done"; + case EditorInfo.IME_ACTION_GO: return "Go"; + case EditorInfo.IME_ACTION_PREVIOUS: return "Prev"; + case EditorInfo.IME_ACTION_SEARCH: return "Search"; + case EditorInfo.IME_ACTION_SEND: return "Send"; + case EditorInfo.IME_ACTION_NONE: + default: return null; + } + } + + private void refreshEditorInfo(EditorInfo info) + { + // First try to look at 'info.actionLabel', if it isn't set, look at + // 'imeOptions'. + if (info.actionLabel != null) + { + _config.actionLabel = info.actionLabel.toString(); + _config.actionId = info.actionId; + } + else + { + int action = info.imeOptions & EditorInfo.IME_MASK_ACTION; + _config.actionLabel = actionLabel_of_imeAction(action); // Might be null + _config.actionId = action; + } + } + @Override public void onStartInputView(EditorInfo info, boolean restarting) { + // Update '_config' before calling 'KeyboardView.setKeyboard' refreshSubtypeImm(); + refreshEditorInfo(info); if ((info.inputType & InputType.TYPE_CLASS_NUMBER) != 0) _keyboardView.setKeyboard(getLayout(R.xml.numeric)); else @@ -200,6 +235,14 @@ public class Keyboard2 extends InputMethodService setInputView(_keyboardView); } + public void performAction() + { + InputConnection conn = getCurrentInputConnection(); + if (conn == null) + return; + conn.performEditorAction(_config.actionId); + } + public void setLayout(int res_id) { if (res_id == -1) |
