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(); }