From 31cf4dfb3166ddc720bf1c3cd92545b126667608 Mon Sep 17 00:00:00 2001 From: Kartikey Tripathi Date: Fri, 27 Mar 2026 22:10:34 +0530 Subject: [PATCH] Fix: Restore keyboard dismissal logic for non-touch devices --- .../java/org/schabi/newpipe/util/KeyboardUtil.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/util/KeyboardUtil.java b/app/src/main/java/org/schabi/newpipe/util/KeyboardUtil.java index 679f3e042f8..c15fc2fd4ba 100644 --- a/app/src/main/java/org/schabi/newpipe/util/KeyboardUtil.java +++ b/app/src/main/java/org/schabi/newpipe/util/KeyboardUtil.java @@ -13,6 +13,14 @@ *

*/ 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 static void showKeyboard(final Activity activity, final EditText editText 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 static void hideKeyboard(final Activity activity, final EditText editText 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(); }