From 85cdb9b2b5e4a43ace04e97dbfa7350aa84efedc Mon Sep 17 00:00:00 2001 From: Jules Aguillon Date: Sat, 3 Jun 2023 18:11:42 +0200 Subject: 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. --- srcs/juloo.keyboard2/Keyboard2.java | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'srcs/juloo.keyboard2/Keyboard2.java') 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) -- cgit v1.2.3