Skip to content

Commit

Permalink
#125 Android 12: soft keyboard disappears when a formula is expanded:…
Browse files Browse the repository at this point in the history
… fixed
  • Loading branch information
mkulesh committed Oct 3, 2022
1 parent 0116d28 commit 9fc77aa
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app/src/main/java/com/mkulesh/micromath/BaseFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ public void updateModeTitle()

public void hideKeyboard()
{
formulas.showSoftKeyboard(false);
formulas.showSoftKeyboard(false, null);
}

public int getFragmentNumber()
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/java/com/mkulesh/micromath/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
12 changes: 10 additions & 2 deletions app/src/main/java/com/mkulesh/micromath/formula/FormulaList.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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()))
{
Expand All @@ -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
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 9fc77aa

Please sign in to comment.