Request focus when showing soft keyboard.

This commit is contained in:
akwizgran
2019-10-15 17:28:01 +01:00
parent c7db0bf6fa
commit a4f561ca1a
4 changed files with 10 additions and 10 deletions

View File

@@ -74,6 +74,7 @@ public class AliasDialogFragment extends AppCompatDialogFragment {
aliasEditText.setText(alias); aliasEditText.setText(alias);
if (alias != null) aliasEditText.setSelection(alias.length()); if (alias != null) aliasEditText.setSelection(alias.length());
// TODO: Close keyboard on accept or cancel
Button setButton = v.findViewById(R.id.setButton); Button setButton = v.findViewById(R.id.setButton);
setButton.setOnClickListener(v1 -> onSetButtonClicked()); setButton.setOnClickListener(v1 -> onSetButtonClicked());
@@ -96,11 +97,9 @@ public class AliasDialogFragment extends AppCompatDialogFragment {
@Override @Override
public void onStart() { public void onStart() {
super.onStart(); super.onStart();
if (aliasEditText.requestFocus()) { requireNonNull(getDialog().getWindow())
requireNonNull(getDialog().getWindow()) .setSoftInputMode(SOFT_INPUT_STATE_ALWAYS_VISIBLE);
.setSoftInputMode(SOFT_INPUT_STATE_ALWAYS_VISIBLE); showSoftKeyboard(aliasEditText);
showSoftKeyboard(aliasEditText);
}
} }
} }

View File

@@ -327,7 +327,6 @@ public abstract class ThreadListActivity<G extends NamedGroup, I extends ThreadI
private void updateTextInput() { private void updateTextInput() {
if (replyId != null) { if (replyId != null) {
textInput.setHint(R.string.forum_message_reply_hint); textInput.setHint(R.string.forum_message_reply_hint);
textInput.requestFocus();
textInput.showSoftKeyboard(); textInput.showSoftKeyboard();
} else { } else {
textInput.setHint(R.string.forum_new_message_hint); textInput.setHint(R.string.forum_new_message_hint);

View File

@@ -92,9 +92,11 @@ public class UiUtils {
public static final float GREY_OUT = 0.5f; public static final float GREY_OUT = 0.5f;
public static void showSoftKeyboard(View view) { public static void showSoftKeyboard(View view) {
InputMethodManager imm = requireNonNull( if (view.requestFocus()) {
getSystemService(view.getContext(), InputMethodManager.class)); InputMethodManager imm = requireNonNull(getSystemService(
imm.showSoftInput(view, SHOW_IMPLICIT); view.getContext(), InputMethodManager.class));
imm.showSoftInput(view, SHOW_IMPLICIT);
}
} }
public static void hideSoftKeyboard(View view) { public static void hideSoftKeyboard(View view) {

View File

@@ -258,7 +258,7 @@ public class EmojiTextInputView extends LinearLayout implements
} }
void showSoftKeyboard() { void showSoftKeyboard() {
imm.showSoftInput(editText, SHOW_IMPLICIT); if (editText.requestFocus()) imm.showSoftInput(editText, SHOW_IMPLICIT);
} }
void hideSoftKeyboard() { void hideSoftKeyboard() {