Fix soft keyboard popping up when the text was selected when the other keyboard was open.

Fixes #11780
fork-5.53.8
Fumiaki Yoshimatsu 2022-03-12 18:13:58 -05:00 zatwierdzone przez Cody Henthorne
rodzic cb74833dc2
commit 6d41d1f6d2
2 zmienionych plików z 29 dodań i 1 usunięć

Wyświetl plik

@ -1,6 +1,8 @@
package org.thoughtcrime.securesms.components;
import android.content.Context;
import android.os.Build;
import android.text.InputType;
import android.util.AttributeSet;
import android.widget.EditText;
@ -12,6 +14,7 @@ import org.thoughtcrime.securesms.util.ServiceUtil;
public class InputAwareLayout extends KeyboardAwareLinearLayout implements OnKeyboardShownListener {
private InputView current;
private int previousInputType = InputType.TYPE_NULL;
public InputAwareLayout(Context context) {
this(context, null);
@ -44,6 +47,8 @@ public class InputAwareLayout extends KeyboardAwareLinearLayout implements OnKey
input.show(getKeyboardHeight(), current != null);
current = input;
}
setShowSoftInputOnFocusCompat(imeTarget, false);
}
public InputView getCurrentInput() {
@ -53,6 +58,8 @@ public class InputAwareLayout extends KeyboardAwareLinearLayout implements OnKey
public void hideCurrentInput(EditText imeTarget) {
if (isKeyboardOpen()) hideSoftkey(imeTarget, null);
else hideAttachedInput(false);
setShowSoftInputOnFocusCompat(imeTarget, true);
}
public void hideAttachedInput(boolean instant) {
@ -65,6 +72,13 @@ public class InputAwareLayout extends KeyboardAwareLinearLayout implements OnKey
}
public void showSoftkey(final EditText inputTarget) {
showSoftkey(inputTarget, false);
}
public void showSoftkey(final EditText inputTarget, boolean force) {
if (!force && isInputOpen()) return;
setShowSoftInputOnFocusCompat(inputTarget, true);
postOnKeyboardOpen(new Runnable() {
@Override public void run() {
hideAttachedInput(true);
@ -85,6 +99,20 @@ public class InputAwareLayout extends KeyboardAwareLinearLayout implements OnKey
.hideSoftInputFromWindow(inputTarget.getWindowToken(), 0);
}
private void setShowSoftInputOnFocusCompat(EditText imeTarget, boolean show) {
if (Build.VERSION.SDK_INT >= 21) {
imeTarget.setShowSoftInputOnFocus(show);
} else if (show) {
if (previousInputType != InputType.TYPE_NULL) {
imeTarget.setInputType(previousInputType);
}
} else {
previousInputType = imeTarget.getInputType();
imeTarget.setRawInputType(InputType.TYPE_CLASS_TEXT);
imeTarget.setTextIsSelectable(true);
}
}
public interface InputView {
void show(int height, boolean immediate);
void hide(boolean immediate);

Wyświetl plik

@ -3273,7 +3273,7 @@ public class ConversationParentFragment extends Fragment
emojiDrawerStub.get().setFragmentManager(getChildFragmentManager());
if (container.getCurrentInput() == emojiDrawerStub.get()) {
container.showSoftkey(composeText);
container.showSoftkey(composeText, true);
} else {
container.show(composeText, emojiDrawerStub.get());
}