Skip to content

Commit 31cf4df

Browse files
Fix: Restore keyboard dismissal logic for non-touch devices
1 parent 515bb6e commit 31cf4df

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

app/src/main/java/org/schabi/newpipe/util/KeyboardUtil.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@
1313
* </p>
1414
*/
1515
public final class KeyboardUtil {
16+
17+
/**
18+
* Flag for {@link #hideKeyboard(Activity, EditText)} to force the keyboard to hide.
19+
* This is required for non-touch devices like Fire TV where the system
20+
* flags the focus as an explicit user action.
21+
*/
22+
private static final int CLEAR_SOFT_INPUT_FORCED = 0;
23+
1624
private KeyboardUtil() {
1725
}
1826

@@ -24,6 +32,7 @@ public static void showKeyboard(final Activity activity, final EditText editText
2432
if (editText.requestFocus()) {
2533
final InputMethodManager imm = ContextCompat.getSystemService(activity,
2634
InputMethodManager.class);
35+
2736
if (!imm.showSoftInput(editText, InputMethodManager.SHOW_FORCED)) {
2837
/*
2938
* 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
4756

4857
final InputMethodManager imm = ContextCompat.getSystemService(activity,
4958
InputMethodManager.class);
50-
imm.hideSoftInputFromWindow(editText.getWindowToken(),
51-
InputMethodManager.HIDE_NOT_ALWAYS);
59+
if (imm != null) {
60+
imm.hideSoftInputFromWindow(editText.getWindowToken(), CLEAR_SOFT_INPUT_FORCED);
61+
}
5262

5363
editText.clearFocus();
5464
}

0 commit comments

Comments
 (0)