Prevent keyboard from closing immediately after opening.

main
Cody Henthorne 2023-02-01 10:35:42 -05:00 zatwierdzone przez GitHub
rodzic 56354f6aae
commit c76ca957e1
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
1 zmienionych plików z 12 dodań i 0 usunięć

Wyświetl plik

@ -37,6 +37,7 @@ import org.thoughtcrime.securesms.util.ViewUtil;
import java.lang.reflect.Field;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.TimeUnit;
/**
* LinearLayout that, when a view container, will report back when it thinks a soft keyboard
@ -45,6 +46,8 @@ import java.util.Set;
public class KeyboardAwareLinearLayout extends LinearLayoutCompat {
private static final String TAG = Log.tag(KeyboardAwareLinearLayout.class);
private static final long KEYBOARD_DEBOUNCE = 150;
private final Rect rect = new Rect();
private final Set<OnKeyboardHiddenListener> hiddenListeners = new HashSet<>();
private final Set<OnKeyboardShownListener> shownListeners = new HashSet<>();
@ -63,6 +66,7 @@ public class KeyboardAwareLinearLayout extends LinearLayoutCompat {
private boolean keyboardOpen = false;
private int rotation = 0;
private boolean isBubble = false;
private long openedAt = 0;
public KeyboardAwareLinearLayout(Context context) {
this(context, null);
@ -183,13 +187,21 @@ public class KeyboardAwareLinearLayout extends LinearLayoutCompat {
protected void onKeyboardOpen(int keyboardHeight) {
Log.i(TAG, "onKeyboardOpen(" + keyboardHeight + ")");
keyboardOpen = true;
openedAt = System.currentTimeMillis();
notifyShownListeners();
}
protected void onKeyboardClose() {
if (System.currentTimeMillis() - openedAt < KEYBOARD_DEBOUNCE) {
Log.i(TAG, "Delaying onKeyboardClose()");
postDelayed(this::updateKeyboardState, KEYBOARD_DEBOUNCE);
return;
}
Log.i(TAG, "onKeyboardClose()");
keyboardOpen = false;
openedAt = 0;
notifyHiddenListeners();
}