fix NullPointerException in keyboard hack

This commit is contained in:
Vincent Breitmoser
2014-10-02 19:35:03 +02:00
parent b6916a9b40
commit a361e82a4d

View File

@@ -209,6 +209,10 @@ public class PassphraseDialogFragment extends DialogFragment implements OnEditor
mPassphraseEditText.post(new Runnable() { mPassphraseEditText.post(new Runnable() {
@Override @Override
public void run() { public void run() {
// The activity might already be gone! Nvm in that case.
if (getActivity() == null) {
return;
}
InputMethodManager imm = (InputMethodManager) getActivity() InputMethodManager imm = (InputMethodManager) getActivity()
.getSystemService(Context.INPUT_METHOD_SERVICE); .getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(mPassphraseEditText, InputMethodManager.SHOW_IMPLICIT); imm.showSoftInput(mPassphraseEditText, InputMethodManager.SHOW_IMPLICIT);
@@ -342,13 +346,18 @@ public class PassphraseDialogFragment extends DialogFragment implements OnEditor
} }
private void hideKeyboard() { private void hideKeyboard() {
// The activity which called the dialog might no longer exist. Nvm in that case...
if (getActivity() == null) {
return;
}
InputMethodManager inputManager = (InputMethodManager) getActivity() InputMethodManager inputManager = (InputMethodManager) getActivity()
.getSystemService(Context.INPUT_METHOD_SERVICE); .getSystemService(Context.INPUT_METHOD_SERVICE);
//check if no view has focus: //check if no view has focus:
View v = getActivity().getCurrentFocus(); View v = getActivity().getCurrentFocus();
if (v == null) if (v == null) {
return; return;
}
inputManager.hideSoftInputFromWindow(v.getWindowToken(), 0); inputManager.hideSoftInputFromWindow(v.getWindowToken(), 0);
} }