mirror of
https://github.com/Julow/Unexpected-Keyboard.git
synced 2024-11-22 07:13:13 +01:00
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.
This commit is contained in:
parent
69e0b4c2a2
commit
85cdb9b2b5
@ -3,6 +3,6 @@
|
||||
<key width="1.7" key0="ctrl" key1="loc switch_greekmath" key2="loc meta" key4="switch_numeric"/>
|
||||
<key width="1.1" key0="fn" key1="loc alt" key2="change_method" key3="switch_emoji" key4="config"/>
|
||||
<key width="4.4" key0="space" key7="switch_second" key5="left" key6="right" slider="true"/>
|
||||
<key width="1.1" key7="up" key6="right" key5="left" key8="down"/>
|
||||
<key width="1.1" key0="loc voice_typing" key7="up" key6="right" key5="left" key8="down"/>
|
||||
<key width="1.7" key0="enter" key2="action"/>
|
||||
</row>
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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();
|
||||
|
@ -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.
|
||||
|
@ -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)
|
||||
|
8
srcs/special_font/15.svg
Normal file
8
srcs/special_font/15.svg
Normal file
@ -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>
|
After Width: | Height: | Size: 828 B |
Binary file not shown.
Loading…
Reference in New Issue
Block a user