Better use of the SRP for the 2.2 input system

This commit is contained in:
SerpentSpirale 2021-08-12 19:49:56 +02:00
parent 29a96330aa
commit 4ccfe06263
3 changed files with 27 additions and 20 deletions

View File

@ -902,25 +902,6 @@ public class BaseMainActivity extends LoggableActivity {
} }
/**
* 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 an hard keyboard is present, never trigger the soft one
if(touchCharInput.hasFocus()
|| getResources().getConfiguration().keyboard == Configuration.KEYBOARD_QWERTY){
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) { protected void setRightOverride(boolean val) {
this.rightOverride = val; this.rightOverride = val;
} }

View File

@ -63,7 +63,7 @@ public class MainActivity extends BaseMainActivity {
for(int keycode : button.getProperties().keycodes){ for(int keycode : button.getProperties().keycodes){
switch (keycode) { switch (keycode) {
case ControlData.SPECIALBTN_KEYBOARD: case ControlData.SPECIALBTN_KEYBOARD:
switchKeyboardState(); touchCharInput.switchKeyboardState();
break; break;
case ControlData.SPECIALBTN_TOGGLECTRL: case ControlData.SPECIALBTN_TOGGLECTRL:

View File

@ -1,8 +1,13 @@
package net.kdt.pojavlaunch.customcontrols; package net.kdt.pojavlaunch.customcontrols;
import static android.content.Context.INPUT_METHOD_SERVICE;
import android.content.Context; import android.content.Context;
import android.content.res.Configuration;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.view.KeyEvent; import android.view.KeyEvent;
import android.view.inputmethod.InputMethodManager;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
@ -87,6 +92,27 @@ public class TouchCharInput extends androidx.appcompat.widget.AppCompatEditText
super.setSelection(5); super.setSelection(5);
} }
/**
* Toggle on and off the soft keyboard, depending of the state
*
* @return if the keyboard is set to be shown.
*/
public boolean switchKeyboardState(){
//If an hard keyboard is present, never trigger the soft one
if(hasFocus()
|| getResources().getConfiguration().keyboard == Configuration.KEYBOARD_QWERTY){
clear();
disable();
return false;
}else{
InputMethodManager imm = (InputMethodManager) getContext().getSystemService(INPUT_METHOD_SERVICE);
enable();
postDelayed(() -> imm.showSoftInput(this, InputMethodManager.SHOW_IMPLICIT), 200);
return true;
}
}
/** /**
* Clear the EditText from any leftover inputs * Clear the EditText from any leftover inputs
* It does not affect the in-game input * It does not affect the in-game input