Skip to content

Commit 826d7ca

Browse files
committed
added a universal "Send with OK in chats" option
1 parent a0bde6a commit 826d7ca

28 files changed

Lines changed: 111 additions & 32 deletions

File tree

app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<manifest xmlns:tools="http://schemas.android.com/tools"
3-
android:versionCode="1594"
3+
android:versionCode="1595"
44
android:versionName="62.0"
55
xmlns:android="http://schemas.android.com/apk/res/android">
66

app/src/main/java/io/github/sspanak/tt9/hacks/AppHacks.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,11 +164,15 @@ public boolean onBackspace(@NonNull SettingsStore settings, @NonNull InputMode i
164164
* Runs non-standard actions for certain apps and fields. Use instead of inputConnection.performEditorAction(action).
165165
* Returns "true" if the action was handled, "false" otherwise.
166166
*/
167-
public boolean onAction(int action) {
167+
public boolean onAction(@NonNull SettingsStore settings, int action) {
168168
if (inputType != null && textField != null && inputType.isSonimSearchField(action)) {
169169
return textField.sendDownUpKeyEvents(KeyEvent.KEYCODE_ENTER);
170170
}
171171

172+
if (inputType != null && textField != null && settings.getSendWithEnterInChatApps() && inputType.isChatField()) {
173+
return textField.performAction(EditorInfo.IME_ACTION_SEND);
174+
}
175+
172176
return false;
173177
}
174178

@@ -204,11 +208,15 @@ public boolean onMoveCursor(int direction) {
204208
* depending on the connected application and input field. On invalid connection or field,
205209
* it does nothing and return "false", signaling the system we have ignored the key press.
206210
*/
207-
public boolean onEnter() {
211+
public boolean onEnter(@NonNull SettingsStore settings) {
208212
if (inputType == null || textField == null) {
209213
return false;
210214
}
211215

216+
if (settings.getSendWithEnterInChatApps() && inputType.isChatField()) {
217+
return textField.performAction(EditorInfo.IME_ACTION_SEND);
218+
}
219+
212220
if (inputType.isTermux() || inputType.isMultilineTextInNonSystemApp()) {
213221
// Termux supports only ENTER, so we convert DPAD_CENTER for it.
214222
// Any extra installed apps are likely not designed for hardware keypads, so again,

app/src/main/java/io/github/sspanak/tt9/hacks/InputType.java

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import android.inputmethodservice.InputMethodService;
55
import android.view.inputmethod.EditorInfo;
66

7+
import androidx.annotation.NonNull;
78
import androidx.annotation.Nullable;
89

910
import io.github.sspanak.tt9.ime.helpers.StandardInputType;
@@ -14,6 +15,26 @@ public class InputType extends StandardInputType {
1415

1516
private final boolean isUs;
1617
private final boolean isOwnTestField;
18+
private final String[] POPULAR_CHAT_APPS = new String[] {
19+
"com.discord", // Discord
20+
"com.google.android.apps.dynamite", // Google Chat
21+
"com.instagram.android", // Instagram
22+
"com.kakao.talk", // KakaoTalk
23+
"jp.naver.line.android", // Line
24+
"chat.rocket.android", // Rocket.Chat
25+
"org.thoughtcrime.securesms", // Signal
26+
"com.Slack", // Slack
27+
"com.snapchat.android", // Snapchat
28+
"com.microsoft.teams", // M$ Teams
29+
"org.telegram.messenger", "org.telegram.messenger.web", // Telegram variants
30+
"com.ss.android.ugc.trill", // TikTok
31+
"com.viber.voip", // Viber
32+
"com.tencent.mm", // WeChat
33+
"com.wire", // Wire
34+
"com.yahoo.mobile.client.android.im", // Yahoo Messenger
35+
"com.beint.zangi", // Zangi
36+
"com.zing.zalo", // Zalo
37+
};
1738

1839
public InputType(@Nullable InputMethodService ims, EditorInfo inputField) {
1940
super(ims, inputField);
@@ -66,6 +87,17 @@ public boolean isCalculator() {
6687
}
6788

6889

90+
/**
91+
* isChatField
92+
* Detects the chat fields of most common messaging apps. Useful for the "Send with OK" hack.
93+
*/
94+
public boolean isChatField() {
95+
return
96+
isMultilineText()
97+
&& (isWhatsApp() || isMessengerChat() || isAnyOfApps(POPULAR_CHAT_APPS));
98+
}
99+
100+
69101
/**
70102
* isDuoLingoReportBug
71103
* When reporting a bug in the Duolingo app, the text field is missing the TYPE_TEXT flag, which
@@ -248,15 +280,15 @@ public boolean isTermux() {
248280

249281

250282
/**
251-
* isTeams
283+
* isTeamsInitial
252284
* M$ Teams seems to control the keyboard visibility on its own. Initially, it always reports
253285
* the input fields as TYPE_NULL, but once the keyboard accepts the show request, it switches to
254286
* TYPE_CLASS_TEXT. This method used to enforce us to stay active at all times in Teams.
255287
* The problem does not occur on all Android versions. I was able to reproduce it only on Unihertz
256288
* Atom L (Android 11), but not on Energizer H620S (Android 10). The bug report also suggests it
257289
* occurs on newer versions. See: <a href="https://github.com/sspanak/tt9/issues/749">#749</a>.
258290
*/
259-
public boolean isTeams() {
291+
public boolean isTeamsInitial() {
260292
return isAppField("com.microsoft.teams", EditorInfo.TYPE_NULL);
261293
}
262294

@@ -314,6 +346,25 @@ public boolean isDefectiveText() {
314346
}
315347

316348

349+
/**
350+
* isAnyOfApps
351+
* Checks if we are currently connected to one of the listed apps.
352+
*/
353+
protected boolean isAnyOfApps(@NonNull String[] packageNames) {
354+
if (field == null || field.packageName == null) {
355+
return false;
356+
}
357+
358+
for (String packageName : packageNames) {
359+
if (field.packageName.equals(packageName)) {
360+
return true;
361+
}
362+
}
363+
364+
return false;
365+
}
366+
367+
317368
/**
318369
* isAppField
319370
* Checks if a particular app field has specific inputType flags.

app/src/main/java/io/github/sspanak/tt9/ime/HotkeyHandler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ protected boolean onOK(int fromKey) {
9999
boolean actionPerformed;
100100

101101
if (action == TextField.IME_ACTION_ENTER) {
102-
actionPerformed = appHacks.onEnter();
102+
actionPerformed = appHacks.onEnter(settings);
103103
if (actionPerformed) {
104104
forceShowWindow();
105105
}
@@ -109,7 +109,7 @@ protected boolean onOK(int fromKey) {
109109
return actionPerformed;
110110
}
111111

112-
actionPerformed = appHacks.onAction(action) || textField.performAction(action);
112+
actionPerformed = appHacks.onAction(settings, action) || textField.performAction(action);
113113
updateShiftState(null, true, false);
114114

115115
return actionPerformed;

app/src/main/java/io/github/sspanak/tt9/ime/TypingHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ protected void determineTextCase() {
385385
* We do not want to handle any of these, hence we pass through all input to the system.
386386
*/
387387
protected int determineInputModeId() {
388-
if (!inputType.isValid() || (inputType.isLimited() && !inputType.isTeams() && !inputType.isTermux())) {
388+
if (!inputType.isValid() || (inputType.isLimited() && !inputType.isTeamsInitial() && !inputType.isTermux())) {
389389
return InputMode.MODE_PASSTHROUGH;
390390
}
391391

app/src/main/java/io/github/sspanak/tt9/preferences/settings/SettingsHacks.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,4 +110,8 @@ public boolean getMessengerReplyExtraPadding() {
110110
public void setMessengerReplyExtraPadding(boolean enabled) {
111111
getPrefsEditor().putBoolean("hack_messenger_reply_extra_padding", enabled).apply();
112112
}
113+
114+
public boolean getSendWithEnterInChatApps() {
115+
return prefs.getBoolean("hack_send_with_enter_in_chat_apps", true);
116+
}
113117
}

app/src/main/res/values-bg/strings.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,8 @@
280280
<string name="pref_hack_auto_disable_composing">Автоматично скриване на въвеждания текст</string>
281281
<string name="pref_haptic_feedback_problematic_summary">Вибрацията може да причини сривове на вашето устройство. Активирайте на собствен риск.</string>
282282
<string name="pref_hardware_key_visual_feedback">Визуализиране на натисканията</string>
283+
<string name="pref_hack_send_with_enter_in_chat_apps">Изпращане с OK в чатовете</string>
284+
<string name="pref_hack_send_with_enter_in_chat_apps_summary">Изпращане на съобщения в приложенията за чат чрез натискане на OK или централния бутон.</string>
283285
<string name="pref_show_suggestions_abc">Показване на предложения за букви</string>
284286
<string name="pref_auto_trim_trailing_space">Автоматично премахване на крайните интервали</string>
285287
<string name="edit_word_invalid_characters">Не може да се редактира „%1$s“, когато езикът е „%2$s“.</string>

app/src/main/res/values-de/strings.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,8 @@
282282
<string name="tutorial_classic_OK_swipe">Wenn es keine Vorschläge gibt, nach oben/unten wischen, um den Cursor zu bewegen.\n\nWenn Vorschläge vorhanden sind, nach oben wischen, um sie zu filtern, oder nach unten, um den Filter zu entfernen.</string>
283283
<string name="tutorial_classic_add_word">Nach links wischen, um ein Wort hinzuzufügen.</string>
284284
<string name="pref_hack_auto_disable_composing">Texterstellung automatisch deaktivieren</string>
285+
<string name="pref_hack_send_with_enter_in_chat_apps">Mit OK in Chat-Apps senden</string>
286+
<string name="pref_hack_send_with_enter_in_chat_apps_summary">Nachrichten in Chat-Apps durch Drücken von OK oder der mittleren Taste des Steuerkreuzes senden.</string>
285287
<string name="pref_show_suggestions_abc">Buchstabenvorschläge anzeigen</string>
286288
<string name="pref_auto_trim_trailing_space">Nachfolgende Leerzeichen automatisch entfernen</string>
287289
<string name="edit_word_invalid_characters">„%1$s“ kann nicht bearbeitet werden, wenn die Sprache „%2$s“ ist.</string>

app/src/main/res/values-es/strings.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,8 @@
280280
<string name="tutorial_classic_OK_swipe">Cuando no hay sugerencias, desliza hacia arriba/abajo para mover el cursor.\n\nCuando hay sugerencias, desliza hacia arriba para filtrarlas o hacia abajo para borrar el filtro.</string>
281281
<string name="tutorial_classic_add_word">Desliza hacia la izquierda para añadir una palabra.</string>
282282
<string name="pref_hack_auto_disable_composing">Desactivar automáticamente la composición de texto</string>
283+
<string name="pref_hack_send_with_enter_in_chat_apps">Enviar con OK en aplicaciones de chat</string>
284+
<string name="pref_hack_send_with_enter_in_chat_apps_summary">Enviar mensajes en aplicaciones de chat pulsando OK o el botón central del pad direccional.</string>
283285
<string name="pref_show_suggestions_abc">Mostrar sugerencias de letras</string>
284286
<string name="pref_auto_trim_trailing_space">Eliminar automáticamente los espacios finales</string>
285287
<string name="edit_word_invalid_characters">No se puede editar \"%1$s\" cuando el idioma es \"%2$s\".</string>

app/src/main/res/values-fr/strings.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,8 @@
280280
<string name="tutorial_classic_OK_swipe">Lorsqu’il n’y a pas de suggestions, balayer vers le haut/bas pour déplacer le curseur.\n\nLorsqu’il y a des suggestions, balayer vers le haut pour les filtrer ou vers le bas pour effacer le filtre.</string>
281281
<string name="tutorial_classic_add_word">Balayer vers la gauche pour ajouter un mot.</string>
282282
<string name="pref_hack_auto_disable_composing">Désactiver automatiquement la composition de texte</string>
283+
<string name="pref_hack_send_with_enter_in_chat_apps">Envoyer avec OK dans les applications de chat</string>
284+
<string name="pref_hack_send_with_enter_in_chat_apps_summary">Envoyer des messages dans les applications de chat en appuyant sur OK ou sur le bouton central du pavé directionnel.</string>
283285
<string name="pref_show_suggestions_abc">Afficher les suggestions de lettres</string>
284286
<string name="pref_auto_trim_trailing_space">Supprimer automatiquement les espaces de fin</string>
285287
<string name="edit_word_invalid_characters">Impossible de modifier « %1$s » lorsque la langue est « %2$s ».</string>

0 commit comments

Comments
 (0)