sending messages with OK in Facebook Messenger is now possible
This commit is contained in:
parent
5314ed1320
commit
c7045b79af
9 changed files with 118 additions and 7 deletions
|
|
@ -28,6 +28,8 @@
|
||||||
<string name="pref_category_hacks">Съвместимост</string>
|
<string name="pref_category_hacks">Съвместимост</string>
|
||||||
<string name="pref_category_appearance">Облик</string>
|
<string name="pref_category_appearance">Облик</string>
|
||||||
<string name="pref_category_function_keys">Бутони за бърз достъп</string>
|
<string name="pref_category_function_keys">Бутони за бърз достъп</string>
|
||||||
|
<string name="pref_hack_fb_messenger">Изпращай съобщения с ОК в Messenger</string>
|
||||||
|
<string name="pref_hack_fb_messenger_summary">Позволява изпращането на съобщения с бутона ОК във Facebook Messenger и Messenger Lite.</string>
|
||||||
<string name="pref_show_soft_function_keys">Бутони на екрана</string>
|
<string name="pref_show_soft_function_keys">Бутони на екрана</string>
|
||||||
<string name="key_back">Назад</string>
|
<string name="key_back">Назад</string>
|
||||||
<string name="key_call">Зелена слушалка</string>
|
<string name="key_call">Зелена слушалка</string>
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,8 @@
|
||||||
<string name="pref_category_appearance">Apparance</string>
|
<string name="pref_category_appearance">Apparance</string>
|
||||||
<string name="dictionary_load_bad_char">Echec du chargement. Mot inadmissible «%1$s» à la ligne %2$d de langue «%3$s».</string>
|
<string name="dictionary_load_bad_char">Echec du chargement. Mot inadmissible «%1$s» à la ligne %2$d de langue «%3$s».</string>
|
||||||
<string name="dictionary_truncated">Le dictionaire est supprimé avec succès.</string>
|
<string name="dictionary_truncated">Le dictionaire est supprimé avec succès.</string>
|
||||||
|
<string name="pref_hack_fb_messenger">Envoyer des messages avec OK dans Messenger</string>
|
||||||
|
<string name="pref_hack_fb_messenger_summary">La touche OK servira pour envoyer des messages dans Facebook Messenger et Messenger Lite.</string>
|
||||||
<string name="pref_show_soft_function_keys">Boutons à l\'écran</string>
|
<string name="pref_show_soft_function_keys">Boutons à l\'écran</string>
|
||||||
<string name="dictionary_loading_indeterminate">Chargement du dictionnaire</string>
|
<string name="dictionary_loading_indeterminate">Chargement du dictionnaire</string>
|
||||||
<string name="dictionary_load_cancelled">Chargement est annulé.</string>
|
<string name="dictionary_load_cancelled">Chargement est annulé.</string>
|
||||||
|
|
|
||||||
|
|
@ -42,6 +42,8 @@
|
||||||
<string name="pref_auto_text_case">Авто заглавные буквы</string>
|
<string name="pref_auto_text_case">Авто заглавные буквы</string>
|
||||||
<string name="pref_auto_text_case_summary">Автоматически начинать предложение с заглавной буквы.</string>
|
<string name="pref_auto_text_case_summary">Автоматически начинать предложение с заглавной буквы.</string>
|
||||||
<string name="pref_double_zero_char">Символ при двойном нажатии клавиши 0</string>
|
<string name="pref_double_zero_char">Символ при двойном нажатии клавиши 0</string>
|
||||||
|
<string name="pref_hack_fb_messenger">Отправка сообщения с «ОК» в Messenger</string>
|
||||||
|
<string name="pref_hack_fb_messenger_summary">Позволяет отправлять сообщения с помощью кнопки «ОК» в Facebook Messenger и Messenger Lite.</string>
|
||||||
<string name="pref_show_soft_function_keys">Кнопки на экране</string>
|
<string name="pref_show_soft_function_keys">Кнопки на экране</string>
|
||||||
<string name="dictionary_load_bad_char">Не удалось загрузить словарь. Проблема в слове «%1$s» в строке %2$d для языка «%3$s».</string>
|
<string name="dictionary_load_bad_char">Не удалось загрузить словарь. Проблема в слове «%1$s» в строке %2$d для языка «%3$s».</string>
|
||||||
<string name="dictionary_missing_go_load_it">Отсутствует словарь для языка «%1$s». Вы можете загрузить его в Настройках.</string>
|
<string name="dictionary_missing_go_load_it">Отсутствует словарь для языка «%1$s». Вы можете загрузить его в Настройках.</string>
|
||||||
|
|
|
||||||
|
|
@ -41,6 +41,8 @@
|
||||||
<string name="pref_auto_text_case">Авто заголовні букви</string>
|
<string name="pref_auto_text_case">Авто заголовні букви</string>
|
||||||
<string name="pref_auto_text_case_summary">Автоматично починати речення з заголовної букви.</string>
|
<string name="pref_auto_text_case_summary">Автоматично починати речення з заголовної букви.</string>
|
||||||
<string name="pref_double_zero_char">Символ при подвійному натисканні клавіші 0</string>
|
<string name="pref_double_zero_char">Символ при подвійному натисканні клавіші 0</string>
|
||||||
|
<string name="pref_hack_fb_messenger">Надсилати повідомлення з «ОК» до Messenger</string>
|
||||||
|
<string name="pref_hack_fb_messenger_summary">Дозволяє надсилати повідомлення за допомогою клавіші «ОК» у Facebook Messenger і Messenger Lite.</string>
|
||||||
<string name="pref_show_soft_function_keys">Кнопки на екрані</string>
|
<string name="pref_show_soft_function_keys">Кнопки на екрані</string>
|
||||||
<string name="key_back">Назад</string>
|
<string name="key_back">Назад</string>
|
||||||
<string name="key_call">Виклик</string>
|
<string name="key_call">Виклик</string>
|
||||||
|
|
|
||||||
|
|
@ -47,6 +47,8 @@
|
||||||
<string name="pref_debug_logs" translatable="false">Detailed Debug Logs</string>
|
<string name="pref_debug_logs" translatable="false">Detailed Debug Logs</string>
|
||||||
<string name="pref_system_logs" translatable="false">System Logs</string>
|
<string name="pref_system_logs" translatable="false">System Logs</string>
|
||||||
<string name="pref_double_zero_char">Character for Double 0-key Press</string>
|
<string name="pref_double_zero_char">Character for Double 0-key Press</string>
|
||||||
|
<string name="pref_hack_fb_messenger">Send messages with OK in Messenger</string>
|
||||||
|
<string name="pref_hack_fb_messenger_summary">Allows sending messages with the OK key in Facebook Messenger and Messenger Lite.</string>
|
||||||
<string name="pref_show_soft_function_keys">Show On-Screen Keys</string>
|
<string name="pref_show_soft_function_keys">Show On-Screen Keys</string>
|
||||||
<string name="pref_show_soft_numpad">Show On-Screen Numpad</string>
|
<string name="pref_show_soft_numpad">Show On-Screen Numpad</string>
|
||||||
<string name="pref_show_soft_numpad_summary" translatable="false">(BETA)</string>
|
<string name="pref_show_soft_numpad_summary" translatable="false">(BETA)</string>
|
||||||
|
|
|
||||||
|
|
@ -23,5 +23,11 @@
|
||||||
app:title="@string/pref_alternative_suggestion_scrolling"
|
app:title="@string/pref_alternative_suggestion_scrolling"
|
||||||
app:summary="@string/pref_alternative_suggestion_scrolling_summary"/>
|
app:summary="@string/pref_alternative_suggestion_scrolling_summary"/>
|
||||||
|
|
||||||
|
<SwitchPreferenceCompat
|
||||||
|
app:key="pref_hack_fb_messenger"
|
||||||
|
app:layout="@layout/pref_switch"
|
||||||
|
app:title="@string/pref_hack_fb_messenger"
|
||||||
|
app:summary="@string/pref_hack_fb_messenger_summary"/>
|
||||||
|
|
||||||
</PreferenceCategory>
|
</PreferenceCategory>
|
||||||
</PreferenceScreen>
|
</PreferenceScreen>
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ import android.view.View;
|
||||||
import android.view.inputmethod.EditorInfo;
|
import android.view.inputmethod.EditorInfo;
|
||||||
import android.view.inputmethod.InputConnection;
|
import android.view.inputmethod.InputConnection;
|
||||||
|
|
||||||
|
import io.github.sspanak.tt9.Logger;
|
||||||
import io.github.sspanak.tt9.ime.helpers.Key;
|
import io.github.sspanak.tt9.ime.helpers.Key;
|
||||||
import io.github.sspanak.tt9.preferences.SettingsStore;
|
import io.github.sspanak.tt9.preferences.SettingsStore;
|
||||||
|
|
||||||
|
|
@ -74,7 +75,10 @@ abstract class KeyPadHandler extends InputMethodService {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void onStartInput(EditorInfo inputField, boolean restarting) {
|
public void onStartInput(EditorInfo inputField, boolean restarting) {
|
||||||
// Logger.d("T9.onStartInput", "inputType: " + inputField.inputType + " fieldId: " + inputField.fieldId + " fieldName: " + inputField.fieldName + " packageName: " + inputField.packageName + " privateImeOptions: " + inputField.privateImeOptions + " imeOptions: " + inputField.imeOptions + " extras: " + inputField.extras);
|
Logger.d(
|
||||||
|
"KeyPadHandler",
|
||||||
|
"===> Start Up; packageName: " + inputField.packageName + " inputType: " + inputField.inputType + " fieldId: " + inputField.fieldId + " fieldName: " + inputField.fieldName + " privateImeOptions: " + inputField.privateImeOptions + " imeOptions: " + inputField.imeOptions + " extras: " + inputField.extras
|
||||||
|
);
|
||||||
currentInputConnection = getCurrentInputConnection();
|
currentInputConnection = getCurrentInputConnection();
|
||||||
onStart(inputField);
|
onStart(inputField);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ public class AppHacks {
|
||||||
* weird side effects occur. Nevertheless, all other text fields in the app are fine, so we detect only these two particular ones.
|
* weird side effects occur. Nevertheless, all other text fields in the app are fine, so we detect only these two particular ones.
|
||||||
*/
|
*/
|
||||||
private boolean isKindleInvertedTextField() {
|
private boolean isKindleInvertedTextField() {
|
||||||
return editorInfo != null && editorInfo.inputType == 1 && editorInfo.packageName.contains("com.amazon.kindle");
|
return isAppField("com.amazon.kindle", EditorInfo.TYPE_CLASS_TEXT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -42,10 +42,52 @@ public class AppHacks {
|
||||||
* and are ignored by TT9 by default. In order not to ignore Termux, we need this.
|
* and are ignored by TT9 by default. In order not to ignore Termux, we need this.
|
||||||
*/
|
*/
|
||||||
public boolean isTermux() {
|
public boolean isTermux() {
|
||||||
return editorInfo != null && editorInfo.inputType == 0 && editorInfo.fieldId > 0 && editorInfo.packageName.contains("com.termux");
|
return isAppField("com.termux", EditorInfo.TYPE_NULL) && editorInfo.fieldId > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* isMessenger
|
||||||
|
* Facebook Messenger has flaky support for sending messages. To fix that, we detect the chat input field and send the appropriate
|
||||||
|
* key codes to it. See "onFbMessengerEnter()" for info how the hack works.
|
||||||
|
*/
|
||||||
|
private boolean isMessenger() {
|
||||||
|
return isAppField(
|
||||||
|
"com.facebook.orca",
|
||||||
|
EditorInfo.TYPE_CLASS_TEXT | EditorInfo.TYPE_TEXT_FLAG_MULTI_LINE | EditorInfo.TYPE_TEXT_FLAG_CAP_SENTENCES
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* isMessengerLite
|
||||||
|
* Facebook Messenger Lite does not support sending messages with OK/ENTER. To enable that, we
|
||||||
|
* detect the chat field and apply the proper series of commands to it. See "onFbMessengerEnter()" for info how the hack works.
|
||||||
|
*/
|
||||||
|
private boolean isMessengerLite() {
|
||||||
|
return isAppField(
|
||||||
|
"com.facebook.mlite",
|
||||||
|
EditorInfo.TYPE_CLASS_TEXT | EditorInfo.TYPE_TEXT_FLAG_MULTI_LINE | EditorInfo.TYPE_TEXT_FLAG_CAP_SENTENCES | EditorInfo.TYPE_TEXT_FLAG_AUTO_CORRECT
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* isAppField
|
||||||
|
* Detects a particular input field of a particular application.
|
||||||
|
*/
|
||||||
|
private boolean isAppField(String appPackageName, int fieldSpec) {
|
||||||
|
return
|
||||||
|
editorInfo != null
|
||||||
|
&& ((editorInfo.inputType & fieldSpec) == fieldSpec)
|
||||||
|
&& editorInfo.packageName.equals(appPackageName);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* setComposingTextWithHighlightedStem
|
||||||
|
* A compatibility function for text fields that do not support SpannableString. Effectively disables highlighting.
|
||||||
|
*/
|
||||||
public boolean setComposingTextWithHighlightedStem(@NonNull String word) {
|
public boolean setComposingTextWithHighlightedStem(@NonNull String word) {
|
||||||
if (isKindleInvertedTextField()) {
|
if (isKindleInvertedTextField()) {
|
||||||
textField.setComposingText(word);
|
textField.setComposingText(word);
|
||||||
|
|
@ -55,6 +97,7 @@ public class AppHacks {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* onBackspace
|
* onBackspace
|
||||||
* Performs extra Backspace operations and returns "false", or completely replaces Backspace and returns "true". When "true" is
|
* Performs extra Backspace operations and returns "false", or completely replaces Backspace and returns "true". When "true" is
|
||||||
|
|
@ -82,6 +125,8 @@ public class AppHacks {
|
||||||
if (isTermux()) {
|
if (isTermux()) {
|
||||||
sendDownUpKeyEvents(KeyEvent.KEYCODE_ENTER);
|
sendDownUpKeyEvents(KeyEvent.KEYCODE_ENTER);
|
||||||
return true;
|
return true;
|
||||||
|
} else if (isMessenger() || isMessengerLite()) {
|
||||||
|
return onEnterFbMessenger();
|
||||||
}
|
}
|
||||||
|
|
||||||
return onEnterDefault();
|
return onEnterDefault();
|
||||||
|
|
@ -121,6 +166,45 @@ public class AppHacks {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* onEnterFbMessenger
|
||||||
|
* Once we have detected the chat message field we apply the appropriate key combo to send the message.
|
||||||
|
*/
|
||||||
|
private boolean onEnterFbMessenger() {
|
||||||
|
if (textField == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// in case the setting is disabled, just type a new line as one would expect
|
||||||
|
if (!settings.getFbMessengerHack()) {
|
||||||
|
inputConnection.commitText("\n", 1);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// do not send any commands if the user has not typed anything or the field is invalid
|
||||||
|
if (!textField.isThereText()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isMessenger()) {
|
||||||
|
// Messenger responds only to ENTER, but not DPAD_CENTER, so we make sure to send the correct code,
|
||||||
|
// no matter how the hardware key is implemented.
|
||||||
|
sendDownUpKeyEvents(KeyEvent.KEYCODE_ENTER);
|
||||||
|
} else {
|
||||||
|
// Messenger Lite responds to no key codes, so we trick it by going right to the Send button, pressing it,
|
||||||
|
// then going back to the chat field.
|
||||||
|
sendDownUpKeyEvents(KeyEvent.KEYCODE_DPAD_RIGHT);
|
||||||
|
sendDownUpKeyEvents(KeyEvent.KEYCODE_DPAD_RIGHT);
|
||||||
|
sendDownUpKeyEvents(KeyEvent.KEYCODE_DPAD_CENTER);
|
||||||
|
sendDownUpKeyEvents(KeyEvent.KEYCODE_DPAD_LEFT);
|
||||||
|
sendDownUpKeyEvents(KeyEvent.KEYCODE_DPAD_LEFT);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private void sendDownUpKeyEvents(int keyCode) {
|
private void sendDownUpKeyEvents(int keyCode) {
|
||||||
if (inputConnection != null) {
|
if (inputConnection != null) {
|
||||||
inputConnection.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, keyCode));
|
inputConnection.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, keyCode));
|
||||||
|
|
|
||||||
|
|
@ -265,10 +265,6 @@ public class SettingsStore {
|
||||||
|
|
||||||
/************* internal settings *************/
|
/************* internal settings *************/
|
||||||
|
|
||||||
public int getSuggestionScrollingDelay() {
|
|
||||||
return prefs.getBoolean("pref_alternative_suggestion_scrolling", false) ? 200 : 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getDictionaryImportProgressUpdateInterval() { return 250; /* ms */ }
|
public int getDictionaryImportProgressUpdateInterval() { return 250; /* ms */ }
|
||||||
public int getDictionaryImportWordChunkSize() { return 1000; /* words */ }
|
public int getDictionaryImportWordChunkSize() { return 1000; /* words */ }
|
||||||
|
|
||||||
|
|
@ -284,4 +280,15 @@ public class SettingsStore {
|
||||||
|
|
||||||
public int getWordFrequencyMax() { return 25500; }
|
public int getWordFrequencyMax() { return 25500; }
|
||||||
public int getWordFrequencyNormalizationDivider() { return 100; } // normalized frequency = getWordFrequencyMax() / getWordFrequencyNormalizationDivider()
|
public int getWordFrequencyNormalizationDivider() { return 100; } // normalized frequency = getWordFrequencyMax() / getWordFrequencyNormalizationDivider()
|
||||||
|
|
||||||
|
|
||||||
|
/************* hack settings *************/
|
||||||
|
|
||||||
|
public int getSuggestionScrollingDelay() {
|
||||||
|
return prefs.getBoolean("pref_alternative_suggestion_scrolling", false) ? 200 : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean getFbMessengerHack() {
|
||||||
|
return prefs.getBoolean("pref_hack_fb_messenger", false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue