diff --git a/app/src/main/java/com/mkulesh/micromath/BaseFragment.java b/app/src/main/java/com/mkulesh/micromath/BaseFragment.java index c2c47716..58eef643 100644 --- a/app/src/main/java/com/mkulesh/micromath/BaseFragment.java +++ b/app/src/main/java/com/mkulesh/micromath/BaseFragment.java @@ -395,7 +395,7 @@ public void updateModeTitle() public void hideKeyboard() { - formulas.showSoftKeyboard(false); + formulas.showSoftKeyboard(false, null); } public int getFragmentNumber() diff --git a/app/src/main/java/com/mkulesh/micromath/MainActivity.java b/app/src/main/java/com/mkulesh/micromath/MainActivity.java index 7d0ad37a..9bc80546 100644 --- a/app/src/main/java/com/mkulesh/micromath/MainActivity.java +++ b/app/src/main/java/com/mkulesh/micromath/MainActivity.java @@ -203,6 +203,11 @@ private void initGUI() public void onDrawerOpened(View drawerView) { super.onDrawerOpened(drawerView); + final BaseFragment baseFragment = getVisibleFragment(); + if (baseFragment != null) + { + baseFragment.hideKeyboard(); + } } }; CompatUtils.setDrawerListener(mDrawerLayout, mDrawerToggle); diff --git a/app/src/main/java/com/mkulesh/micromath/formula/FormulaList.java b/app/src/main/java/com/mkulesh/micromath/formula/FormulaList.java index c6ba7f90..9e5f88c1 100644 --- a/app/src/main/java/com/mkulesh/micromath/formula/FormulaList.java +++ b/app/src/main/java/com/mkulesh/micromath/formula/FormulaList.java @@ -27,6 +27,7 @@ import android.widget.LinearLayout; import android.widget.Toast; +import androidx.annotation.Nullable; import androidx.appcompat.app.AppCompatActivity; import androidx.preference.PreferenceManager; @@ -1313,7 +1314,7 @@ public void callObjectManipulator(Manipulator manipulator) } } - public void showSoftKeyboard(boolean flag) + public void showSoftKeyboard(boolean flag, @Nullable View view) { if (ViewUtils.isHardwareKeyboardAvailable(getContext())) { @@ -1322,7 +1323,14 @@ public void showSoftKeyboard(boolean flag) InputMethodManager imm = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE); if (flag) { - imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY); + if (view != null) + { + imm.showSoftInput(view, 0); + } + else + { + imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY); + } } else { diff --git a/app/src/main/java/com/mkulesh/micromath/formula/TermField.java b/app/src/main/java/com/mkulesh/micromath/formula/TermField.java index c0245b69..2f4fb55a 100644 --- a/app/src/main/java/com/mkulesh/micromath/formula/TermField.java +++ b/app/src/main/java/com/mkulesh/micromath/formula/TermField.java @@ -363,7 +363,7 @@ public boolean setEditableFocus(FocusType type) else if (type == FormulaBase.FocusType.FIRST_EDITABLE || isEmpty()) { text.requestFocus(); - formulaRoot.getFormulaList().showSoftKeyboard(true); + formulaRoot.getFormulaList().showSoftKeyboard(true, text); return true; } return false;