mirror of
https://github.com/TeamNewPipe/NewPipe
synced 2026-06-27 23:18:50 +00:00
Merge pull request #13373 from KartikeyTripathi469/fix/keyboard-regression-13337
Fix: Force keyboard dismissal on non-touch devices (#13337)
This commit is contained in:
@@ -13,6 +13,14 @@ import androidx.core.content.ContextCompat;
|
||||
* </p>
|
||||
*/
|
||||
public final class KeyboardUtil {
|
||||
|
||||
/**
|
||||
* Flag for {@link #hideKeyboard(Activity, EditText)} to force the keyboard to hide.
|
||||
* This is required for non-touch devices like Fire TV where the system
|
||||
* flags the focus as an explicit user action.
|
||||
*/
|
||||
private static final int CLEAR_SOFT_INPUT_FORCED = 0;
|
||||
|
||||
private KeyboardUtil() {
|
||||
}
|
||||
|
||||
@@ -24,6 +32,7 @@ public final class KeyboardUtil {
|
||||
if (editText.requestFocus()) {
|
||||
final InputMethodManager imm = ContextCompat.getSystemService(activity,
|
||||
InputMethodManager.class);
|
||||
|
||||
if (!imm.showSoftInput(editText, InputMethodManager.SHOW_FORCED)) {
|
||||
/*
|
||||
* Sometimes the keyboard can't be shown because Android's ImeFocusController is in
|
||||
@@ -47,8 +56,9 @@ public final class KeyboardUtil {
|
||||
|
||||
final InputMethodManager imm = ContextCompat.getSystemService(activity,
|
||||
InputMethodManager.class);
|
||||
imm.hideSoftInputFromWindow(editText.getWindowToken(),
|
||||
InputMethodManager.HIDE_NOT_ALWAYS);
|
||||
if (imm != null) {
|
||||
imm.hideSoftInputFromWindow(editText.getWindowToken(), CLEAR_SOFT_INPUT_FORCED);
|
||||
}
|
||||
|
||||
editText.clearFocus();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user