Skip to content

Commit

Permalink
Bring the voice IME chooser with a long press
Browse files Browse the repository at this point in the history
  • Loading branch information
Julow committed Dec 30, 2023
1 parent 51a41ec commit 4a5a125
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions srcs/juloo.keyboard2/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ public KeyValue apply(KeyValue key, boolean localized)
case SWITCH_BACKWARD:
return (layouts.size() > 2) ? key : null;
case SWITCH_VOICE_TYPING:
case SWITCH_VOICE_TYPING_CHOOSER:
return shouldOfferVoiceTyping ? key : null;
}
break;
Expand Down
2 changes: 2 additions & 0 deletions srcs/juloo.keyboard2/KeyModifier.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ public static KeyValue modify_long_press(KeyValue k)
{
case CHANGE_METHOD_PREV:
return KeyValue.getKeyByName("change_method");
case SWITCH_VOICE_TYPING:
return KeyValue.getKeyByName("voice_typing_chooser");
}
break;
}
Expand Down
2 changes: 2 additions & 0 deletions srcs/juloo.keyboard2/KeyValue.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public static enum Event
SWITCH_GREEKMATH,
CAPS_LOCK,
SWITCH_VOICE_TYPING,
SWITCH_VOICE_TYPING_CHOOSER,
}

// Must be evaluated in the reverse order of their values.
Expand Down Expand Up @@ -369,6 +370,7 @@ public static KeyValue getKeyByName(String name)
case "action": return eventKey("Action", Event.ACTION, FLAG_SMALLER_FONT); // Will always be replaced
case "capslock": return eventKey(0xE012, Event.CAPS_LOCK, 0);
case "voice_typing": return eventKey(0xE015, Event.SWITCH_VOICE_TYPING, FLAG_SMALLER_FONT);
case "voice_typing_chooser": return eventKey(0xE015, Event.SWITCH_VOICE_TYPING_CHOOSER, FLAG_SMALLER_FONT);

/* Key events */
case "esc": return keyeventKey("Esc", KeyEvent.KEYCODE_ESCAPE, FLAG_SMALLER_FONT);
Expand Down
5 changes: 5 additions & 0 deletions srcs/juloo.keyboard2/Keyboard2.java
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,11 @@ public void handle_event_key(KeyValue.Event ev)
Config.globalPrefs()))
_config.shouldOfferVoiceTyping = false;
break;

case SWITCH_VOICE_TYPING_CHOOSER:
VoiceImeSwitcher.choose_voice_ime(Keyboard2.this, get_imm(),
Config.globalPrefs());
break;
}
}

Expand Down
10 changes: 10 additions & 0 deletions srcs/juloo.keyboard2/VoiceImeSwitcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@ public static boolean switch_to_voice_ime(InputMethodService ims,
return true;
}

public static boolean choose_voice_ime(InputMethodService ims,
InputMethodManager imm, SharedPreferences prefs)
{
if (VERSION.SDK_INT < 11) // Due to InputMethodSubtype
return false;
List<IME> imes = get_voice_ime_list(imm);
choose_voice_ime_and_update_prefs(ims, prefs, imes);
return true;
}

/** Show the voice IME chooser popup and switch to the selected IME.
Preferences are updated so that future calls to [switch_to_voice_ime]
switch to the newly selected IME. */
Expand Down

0 comments on commit 4a5a125

Please sign in to comment.