Introduce toggling system for all keyboards

This commit is contained in:
SerpentSpirale 2021-08-06 23:47:09 +02:00 committed by ArtDev
parent 1f2d599ce5
commit e74fb95f98
3 changed files with 52 additions and 32 deletions

View file

@ -883,22 +883,23 @@ public class BaseMainActivity extends LoggableActivity {
// Catch back as Esc keycode at another place
sendKeyPress(LWJGLGLFWKeycode.GLFW_KEY_ESCAPE);
}
public void hideKeyboard() {
try {
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
if (getCurrentFocus() != null && getCurrentFocus().getWindowToken() != null) {
((InputMethodManager) getSystemService(INPUT_METHOD_SERVICE)).hideSoftInputFromWindow((this).getCurrentFocus().getWindowToken(), 0);
}
} catch (Exception e) {
e.printStackTrace();
}
}
public void showKeyboard() {
((InputMethodManager) getSystemService(INPUT_METHOD_SERVICE)).toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);
minecraftGLView.requestFocusFromTouch();
minecraftGLView.requestFocus();
/**
* Toggle on and off the soft keyboard, depending of the state
* The condition is prone to errors if the keyboard is being hidden without the consent
* of the current TouchCharInput
*/
public void switchKeyboardState(){
if(touchCharInput.hasFocus()){
touchCharInput.clear();
touchCharInput.disable();
}else{
InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
touchCharInput.enable();
touchCharInput.postDelayed(() -> imm.showSoftInput(touchCharInput, InputMethodManager.SHOW_IMPLICIT), 200);
}
}
protected void setRightOverride(boolean val) {