1
0
Fork 0

added a hack for Facebook Messenger to prevent keyboard hiding when trying to reply to a message and the Main View is set to 'Function Keys'

This commit is contained in:
sspanak 2025-06-13 16:40:43 +03:00 committed by Dimo Karaivanov
parent 80640daa05
commit 8742811d85
8 changed files with 84 additions and 2 deletions

View file

@ -1,6 +1,7 @@
package io.github.sspanak.tt9.hacks;
import android.view.KeyEvent;
import android.view.inputmethod.EditorInfo;
import androidx.annotation.NonNull;
@ -11,8 +12,13 @@ import io.github.sspanak.tt9.ime.helpers.TextField;
import io.github.sspanak.tt9.ime.helpers.TextSelection;
import io.github.sspanak.tt9.ime.modes.InputMode;
import io.github.sspanak.tt9.preferences.settings.SettingsStore;
import io.github.sspanak.tt9.util.Timer;
public class AppHacks {
private final static String TYPING_SESSION_TIMER = "TYPING_SESSION_TIMER";
private static boolean previousWasMessengerChat = false;
private final InputType inputType;
private final TextField textField;
private final TextSelection textSelection;
@ -137,4 +143,32 @@ public class AppHacks {
// As per the docs, we must return "false", to indicate that we have not "seen" the key press.
return false;
}
public static void onStart(@NonNull SettingsStore settings, @NonNull EditorInfo field) {
// currently, onStart() only adjusts the padding of MainSmall, so save some resources by not
// doing anything if another layout is used.
if (!settings.isMainLayoutSmall()) {
settings.setMessengerReplyExtraPadding(false);
return;
}
final InputType newInputType = new InputType(null, field);
if (newInputType.notMessenger()) {
settings.setMessengerReplyExtraPadding(false);
return;
}
final long previousSessionTime = Timer.stop(TYPING_SESSION_TIMER);
final boolean currentIsMessengerNonText = newInputType.isMessengerNonText();
if (previousSessionTime < 1000 && previousWasMessengerChat && currentIsMessengerNonText) {
settings.setMessengerReplyExtraPadding(true);
} else if (previousSessionTime > 1000 && previousWasMessengerChat) {
settings.setMessengerReplyExtraPadding(false);
}
Timer.start(TYPING_SESSION_TIMER);
previousWasMessengerChat = newInputType.isMessengerChat();
}
}

View file

@ -106,6 +106,20 @@ public class InputType extends StandardInputType {
}
public boolean notMessenger() {
return field == null || !field.packageName.equals("com.facebook.orca");
}
public boolean isMessengerChat() {
return isAppInput("com.facebook.orca", 147457);
}
public boolean isMessengerNonText() {
return isAppInput("com.facebook.orca", EditorInfo.TYPE_NULL);
}
/**
* Third-party apps are usually designed for a touch screen, so the least we can do is convert
* DPAD_CENTER to ENTER for typing new lines, regardless of the implementation of the OK key.

View file

@ -11,6 +11,7 @@ import androidx.annotation.NonNull;
import io.github.sspanak.tt9.db.DataStore;
import io.github.sspanak.tt9.db.words.DictionaryLoader;
import io.github.sspanak.tt9.hacks.AppHacks;
import io.github.sspanak.tt9.hacks.InputType;
import io.github.sspanak.tt9.ime.modes.InputModeKind;
import io.github.sspanak.tt9.languages.LanguageCollection;
@ -130,6 +131,7 @@ public class TraditionalT9 extends MainViewHandler {
@Override
protected boolean onStart(EditorInfo field) {
AppHacks.onStart(settings, field);
if (zombieChecks == 0 && !SystemSettings.isTT9Selected(this)) {
startZombieCheck();
return false;

View file

@ -83,4 +83,21 @@ class SettingsHacks extends BaseSettings {
public boolean getPrecalculateNavbarHeight() {
return prefs.getBoolean("hack_precalculate_navbar_height_v3", !DeviceInfo.IS_SAMSUNG);
}
/**
* Facebook Messenger has a bug where when trying to reply to a message, and when the keyboard
* has certain height, it somehow switches the focus outside of the text field. The problematic
* height is exactly the height when the Main View is Small or when the Command Palette is shown.
* With this hack, we tell the Main View to become taller and mitigate the issue.
* More info: <a href="https://github.com/sspanak/tt9/issues/815">Issue 815</a>. Note that the
* bug happens on every phone, not only on Freetel.
*/
public boolean getMessengerReplyExtraPadding() {
return prefs.getBoolean("hack_messenger_reply_extra_padding", false);
}
public void setMessengerReplyExtraPadding(boolean enabled) {
prefsEditor.putBoolean("hack_messenger_reply_extra_padding", enabled).apply();
}
}

View file

@ -24,6 +24,10 @@ class MainLayoutSmall extends MainLayoutTray {
if (!isCommandPaletteShown() && !isTextEditingPaletteShown()) {
height += tt9.getResources().getDimensionPixelSize(R.dimen.main_small_main_key_wrapper_height);
}
if (tt9.getSettings().getMessengerReplyExtraPadding()) {
height += tt9.getResources().getDimensionPixelSize(R.dimen.main_small_main_key_wrapper_extra_height_for_messenger);
}
}
return height;
@ -33,6 +37,9 @@ class MainLayoutSmall extends MainLayoutTray {
protected void setSoftKeysVisibility() {
if (view != null) {
view.findViewById(R.id.main_soft_keys).setVisibility(LinearLayout.VISIBLE);
view.findViewById(R.id.main_small_messenger_padding_hack).setVisibility(
tt9.getSettings().getMessengerReplyExtraPadding() ? LinearLayout.VISIBLE : LinearLayout.GONE
);
}
}

View file

@ -10,6 +10,7 @@
<LinearLayout style="@style/TTheme.MainSmall" android:id="@+id/keyboard_container">
<View style="@style/TTheme.Keyboard.TopSeparator" />
<include layout="@layout/panel_small_status_bar" />
<LinearLayout style="@style/TTheme.MainSmall.MessengerPaddingHack" android:id="@+id/main_small_messenger_padding_hack"/>
<include layout="@layout/panel_small_function_keys" android:id="@+id/main_soft_keys" />
<include

View file

@ -19,6 +19,7 @@
<dimen name="main_small_suggestion_text_size">18sp</dimen>
<dimen name="main_small_main_key_wrapper_height">46dp</dimen> <!-- key height + margin -->
<dimen name="main_small_main_key_wrapper_extra_height_for_messenger">50dp</dimen> <!-- empirically found the correct amount -->
<dimen name="main_small_command_palette_height">66dp</dimen>
<dimen name="main_small_command_palette_key_text_size">18dp</dimen>

View file

@ -142,10 +142,16 @@
Small Keys
*******************************************-->
<!-- A dummy element that adds extra height for when FB Messenger misbehaves -->
<style name="TTheme.MainSmall.MessengerPaddingHack" parent="">
<item name="android:layout_height">@dimen/main_small_main_key_wrapper_extra_height_for_messenger</item>
<item name="android:layout_width">match_parent</item>
<item name="android:orientation">horizontal</item>
<item name="android:visibility">gone</item>
</style>
<!-- Main Small view (backspace and OK) -->
<style name="TTheme.MainSmall.Wrapper" parent="">
<item name="android:baselineAligned">true</item>
<item name="android:gravity">center</item>
<item name="android:layout_height">@dimen/main_small_main_key_wrapper_height</item>
<item name="android:layout_width">match_parent</item>
<item name="android:orientation">horizontal</item>