diff options
| author | Jules Aguillon | 2023-06-03 18:11:42 +0200 |
|---|---|---|
| committer | Jules Aguillon | 2023-06-03 18:11:42 +0200 |
| commit | 85cdb9b2b5e4a43ace04e97dbfa7350aa84efedc (patch) | |
| tree | 93480372487b307bbb75ad401d800639f0ce7389 /srcs | |
| parent | 69e0b4c2a2424b83ce0ec876938ec3e73dd5b612 (diff) | |
| download | unexpected-keyboard-85cdb9b2b5e4a43ace04e97dbfa7350aa84efedc.tar.gz unexpected-keyboard-85cdb9b2b5e4a43ace04e97dbfa7350aa84efedc.zip | |
Add Voice Typing key
The new key switches to any installed "voice" input method.
If several input methods matches, no effort is made to choose.
Might misbehave with some input methods other than Google's on API < 28.
It is placed on the middle of the arrows on the bottom bar. It is
enabled by default and can be removed in the "Extra keys" option.
The key is not removed from the keyboard if no voice input method
exists.
Diffstat (limited to 'srcs')
| -rw-r--r-- | srcs/juloo.keyboard2/ExtraKeyCheckBoxPreference.java | 3 | ||||
| -rw-r--r-- | srcs/juloo.keyboard2/KeyEventHandler.java | 2 | ||||
| -rw-r--r-- | srcs/juloo.keyboard2/KeyValue.java | 3 | ||||
| -rw-r--r-- | srcs/juloo.keyboard2/Keyboard2.java | 22 | ||||
| -rw-r--r-- | srcs/special_font/15.svg | 8 | ||||
| -rw-r--r-- | srcs/special_font/result.ttf | bin | 8660 -> 8732 bytes |
6 files changed, 38 insertions, 0 deletions
diff --git a/srcs/juloo.keyboard2/ExtraKeyCheckBoxPreference.java b/srcs/juloo.keyboard2/ExtraKeyCheckBoxPreference.java index 8938d2d..8f7471a 100644 --- a/srcs/juloo.keyboard2/ExtraKeyCheckBoxPreference.java +++ b/srcs/juloo.keyboard2/ExtraKeyCheckBoxPreference.java @@ -16,6 +16,7 @@ public class ExtraKeyCheckBoxPreference extends CheckBoxPreference { "alt", "meta", + "voice_typing", "accent_aigu", "accent_grave", "accent_double_aigu", @@ -56,6 +57,8 @@ public class ExtraKeyCheckBoxPreference extends CheckBoxPreference { switch (name) { + case "voice_typing": + return true; default: return false; } diff --git a/srcs/juloo.keyboard2/KeyEventHandler.java b/srcs/juloo.keyboard2/KeyEventHandler.java index 1a591c8..70b54b9 100644 --- a/srcs/juloo.keyboard2/KeyEventHandler.java +++ b/srcs/juloo.keyboard2/KeyEventHandler.java @@ -59,6 +59,7 @@ class KeyEventHandler implements Config.IKeyEventHandler case SWITCH_SECOND_BACK: _recv.set_layout(Layout.Primary); break; case SWITCH_GREEKMATH: _recv.set_layout(Layout.Greekmath); break; case CAPS_LOCK: _recv.set_shift_state(true, true); break; + case SWITCH_VOICE_TYPING: _recv.switch_voice_typing(); break; } break; case Keyevent: @@ -182,6 +183,7 @@ class KeyEventHandler implements Config.IKeyEventHandler { public void switchInputMethod(); public void switchToPrevInputMethod(); + public void switch_voice_typing(); public void setPane_emoji(); public void setPane_normal(); public void showKeyboardConfig(); diff --git a/srcs/juloo.keyboard2/KeyValue.java b/srcs/juloo.keyboard2/KeyValue.java index 3e84ce8..9f4d985 100644 --- a/srcs/juloo.keyboard2/KeyValue.java +++ b/srcs/juloo.keyboard2/KeyValue.java @@ -19,6 +19,7 @@ final class KeyValue SWITCH_SECOND_BACK, SWITCH_GREEKMATH, CAPS_LOCK, + SWITCH_VOICE_TYPING, } // Must be evaluated in the reverse order of their values. @@ -343,6 +344,7 @@ final class KeyValue case "change_method_prev": return eventKey(0x09, Event.CHANGE_METHOD_PREV, FLAG_SMALLER_FONT); case "action": return eventKey("Action", Event.ACTION, FLAG_SMALLER_FONT); // Will always be replaced case "capslock": return eventKey(0x12, Event.CAPS_LOCK, 0); + case "voice_typing": return eventKey(0x15, Event.SWITCH_VOICE_TYPING, FLAG_SMALLER_FONT); case "esc": return keyeventKey("Esc", KeyEvent.KEYCODE_ESCAPE, FLAG_SMALLER_FONT); case "enter": return keyeventKey(0x0E, KeyEvent.KEYCODE_ENTER, 0); @@ -451,6 +453,7 @@ final class KeyValue /* Keys description is shown in the settings. */ addKeyDescr("capslock", "Caps lock"); addKeyDescr("switch_greekmath", "Greek & math symbols"); + addKeyDescr("voice_typing", "Voice typing"); } // Substitute for [assert], which has no effect on Android. diff --git a/srcs/juloo.keyboard2/Keyboard2.java b/srcs/juloo.keyboard2/Keyboard2.java index c41a22f..e5bd726 100644 --- a/srcs/juloo.keyboard2/Keyboard2.java +++ b/srcs/juloo.keyboard2/Keyboard2.java @@ -399,6 +399,28 @@ public class Keyboard2 extends InputMethodService Keyboard2.this.switchToPreviousInputMethod(); } + public void switch_voice_typing() + { + if (VERSION.SDK_INT < 11) // Due to InputMethodSubtype + return; + InputMethodManager imm = (InputMethodManager)getSystemService(INPUT_METHOD_SERVICE); + for (InputMethodInfo im : imm.getEnabledInputMethodList()) + { + for (InputMethodSubtype imst : imm.getEnabledInputMethodSubtypeList(im, true)) + { + // Switch to the first IM that has a subtype of this mode + if (imst.getMode().equals("voice")) + { + // Best-effort. Good enough for triggering Google's voice typing + if (VERSION.SDK_INT < 28) + Keyboard2.this.switchInputMethod(im.getId()); + else + Keyboard2.this.switchInputMethod(im.getId(), imst); + } + } + } + } + public void setPane_emoji() { if (_emojiPane == null) diff --git a/srcs/special_font/15.svg b/srcs/special_font/15.svg new file mode 100644 index 0000000..a966f26 --- /dev/null +++ b/srcs/special_font/15.svg @@ -0,0 +1,8 @@ +<?xml version="1.0" standalone="no"?> +<!-- Google's Material Icons "Mic" (modified) --> +<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd" > +<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" viewBox="-10 0 1010 1000"> + <path fill="currentColor" +d="M500 583.333q-51.875 0 -88.4375 -36.5625t-36.5625 -88.4375v-250q0 -51.875 36.5625 -88.4375t88.4375 -36.5625t88.4375 36.5625t36.5625 88.4375v250q0 51.875 -36.5625 88.4375t-88.4375 36.5625zM708.333 458.333h83.334q0 109.513 -71.6299 191.209 +q-71.6289 81.6963 -178.37 97.125v128.333h-83.334v-128.333q-106.741 -15.4287 -178.37 -97.125q-71.6299 -81.6963 -71.6299 -191.209h83.334q0 86.25 61.042 147.292q61.041 61.042 147.291 61.042t147.291 -61.042q61.042 -61.042 61.042 -147.292z" /> +</svg> diff --git a/srcs/special_font/result.ttf b/srcs/special_font/result.ttf Binary files differindex c7a8ca0..429006b 100644 --- a/srcs/special_font/result.ttf +++ b/srcs/special_font/result.ttf |
