Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions app/src/main/java/org/schabi/newpipe/util/KeyboardUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@
* </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() {
}

Expand All @@ -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
Expand All @@ -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();
}
Expand Down
Loading