Skip to content

Commit 8107e02

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

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,25 @@ public static void showKeyboard(final Activity activity, final EditText editText
4040
}
4141
}
4242

43+
/**
44+
* Flag for {@link #hideKeyboard(Activity, EditText)} ...
45+
* This is required for non-touch devices like Fire TV where the system
46+
* flags the focus as an explicit user action.
47+
*/
48+
private static final int CLEAR_SOFT_INPUT_FORCED = 0;
49+
4350
public static void hideKeyboard(final Activity activity, final EditText editText) {
4451
if (activity == null || editText == null) {
4552
return;
4653
}
4754

4855
final InputMethodManager imm = ContextCompat.getSystemService(activity,
4956
InputMethodManager.class);
50-
imm.hideSoftInputFromWindow(editText.getWindowToken(),
51-
InputMethodManager.HIDE_NOT_ALWAYS);
57+
if (imm != null) {
58+
imm.hideSoftInputFromWindow(editText.getWindowToken(), CLEAR_SOFT_INPUT_FORCED);
59+
}
5260

5361
editText.clearFocus();
5462
}
63+
}
5564
}

0 commit comments

Comments
 (0)