Skip to content

Commit

Permalink
Merge "List of included changes: - Add nullability check to avoid crash"
Browse files Browse the repository at this point in the history
  • Loading branch information
Yun Liu authored and Gerrit Code Review committed Nov 23, 2021
2 parents 61c5460 + 7d8ca18 commit b735025
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.TextView;
Expand Down Expand Up @@ -80,8 +81,11 @@ protected void onCreate(Bundle savedInstanceState) {
private void hideKeyboard() {
InputMethodManager inputMethodManager =
(InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow(
getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
View view = getCurrentFocus();
if (inputMethodManager != null && view != null) {
inputMethodManager.hideSoftInputFromWindow(
view.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
}
}

private String getInputText() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,13 @@ class MainActivityKotlin : AppCompatActivity() {

private fun hideKeyboard() {
val inputMethodManager = getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
inputMethodManager.hideSoftInputFromWindow(
getCurrentFocus()!!.getWindowToken(),
InputMethodManager.HIDE_NOT_ALWAYS
)
val view = getCurrentFocus()
if (inputMethodManager != null && view != null) {
inputMethodManager.hideSoftInputFromWindow(
view.getWindowToken(),
InputMethodManager.HIDE_NOT_ALWAYS
)
}
}

private fun getInputText(): String {
Expand Down

0 comments on commit b735025

Please sign in to comment.