Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "Done" action to the keyboard, so we can easily hide the keyboard. #4

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,15 @@ public void onClick(View v) {
});
}

@Override
public void onWindowFocusChanged(boolean hasWindowFocus) {
super.onWindowFocusChanged(hasWindowFocus);
if (!hasWindowFocus) // onPause() called
{
hideKeyBoard(getContext());
}
}

@Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
Expand All @@ -197,6 +206,7 @@ public void onVisibilityChange(boolean isVisible) {
public void onFocusChange(View v, boolean hasFocus) {
showDate(date, hasFocus);
showFullDateLayout(hasFocus);
if (!hasFocus) hideKeyBoard(getContext());
}
});

Expand Down Expand Up @@ -551,6 +561,11 @@ private void showKeyboard(Context context) {
InputMethodManager inputMethodManager = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
if (inputMethodManager != null) inputMethodManager.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
}

private void hideKeyBoard(Context context) {
InputMethodManager imm = (InputMethodManager)context.getSystemService(Context.INPUT_METHOD_SERVICE);
if(imm != null) imm.hideSoftInputFromWindow(this.getWindowToken(), 0);
}
//endregion

//region UTILS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
android:digits="0123456789"
android:inputType="number|none"
android:textSize="0sp"
android:imeOptions="actionDone"
tools:ignore="LabelFor,TextFields" />

<LinearLayout
Expand Down