diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/BaseMainActivity.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/BaseMainActivity.java index b9c2e533a..79cc1f83c 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/BaseMainActivity.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/BaseMainActivity.java @@ -29,6 +29,7 @@ import org.lwjgl.glfw.*; public class BaseMainActivity extends LoggableActivity { public static volatile ClipboardManager GLOBAL_CLIPBOARD; + public TouchCharInput touchCharInput; volatile public static boolean isInputStackCall; @@ -121,8 +122,10 @@ public class BaseMainActivity extends LoggableActivity { setContentView(resId); try { + // FIXME: is it safe fot multi thread? GLOBAL_CLIPBOARD = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE); + touchCharInput = findViewById(R.id.editTextTextPersonName2); logFile = new File(Tools.DIR_GAME_HOME, "latestlog.txt"); logFile.delete(); @@ -623,8 +626,29 @@ public class BaseMainActivity extends LoggableActivity { @Override public boolean dispatchKeyEvent(KeyEvent event) { + /* + Toast.makeText(this, event.toString(),Toast.LENGTH_LONG).show(); + Toast.makeText(this, event.getUnicodeChar() + "",Toast.LENGTH_LONG).show(); + Toast.makeText(this, event.getDevice().toString(), Toast.LENGTH_LONG).show(); + + */ + + //Filtering useless events - if(event.getRepeatCount() != 0 || event.getAction() == KeyEvent.ACTION_MULTIPLE || event.getKeyCode() == KeyEvent.KEYCODE_UNKNOWN || (event.getFlags() & KeyEvent.FLAG_FALLBACK) == KeyEvent.FLAG_FALLBACK) return true; + if(event.getRepeatCount() != 0 + || event.getAction() == KeyEvent.ACTION_MULTIPLE + || event.getKeyCode() == KeyEvent.KEYCODE_UNKNOWN + || (event.getFlags() & KeyEvent.FLAG_FALLBACK) == KeyEvent.FLAG_FALLBACK) return true; + Toast.makeText(this, "FIRST VERIF PASSED", Toast.LENGTH_LONG).show(); + + //Sometimes, key events comes from SOME keys of the software keyboard + //Even weirder, is is unknown why a key or another is selected to trigger a keyEvent + if((event.getFlags() & KeyEvent.FLAG_SOFT_KEYBOARD) == KeyEvent.FLAG_SOFT_KEYBOARD){ + touchCharInput.dispatchKeyEvent(event); + return true; + } + Toast.makeText(this, "SECOND VERIF PASSED", Toast.LENGTH_LONG).show(); + //Sometimes, key events may come from the mouse if(event.getDevice() != null diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/TouchCharInput.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/TouchCharInput.java new file mode 100644 index 000000000..fb10be65a --- /dev/null +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/TouchCharInput.java @@ -0,0 +1,106 @@ +package net.kdt.pojavlaunch.customcontrols; + +import android.content.Context; +import android.os.Bundle; +import android.text.Editable; +import android.text.TextWatcher; +import android.util.AttributeSet; +import android.view.KeyEvent; +import android.view.inputmethod.EditorInfo; +import android.view.inputmethod.InputConnection; +import android.widget.TextView; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.core.view.inputmethod.EditorInfoCompat; +import androidx.core.view.inputmethod.InputConnectionCompat; +import androidx.core.view.inputmethod.InputContentInfoCompat; + +import net.kdt.pojavlaunch.BaseMainActivity; +import net.kdt.pojavlaunch.LWJGLGLFWKeycode; + +import org.lwjgl.glfw.CallbackBridge; + +/** + * This class is intended for sending characters used in chat via the virtual keyboard + */ +public class TouchCharInput extends androidx.appcompat.widget.AppCompatEditText { + public TouchCharInput(@NonNull Context context) { + super(context); + setup(); + } + public TouchCharInput(@NonNull Context context, @Nullable AttributeSet attrs) { + super(context, attrs); + setup(); + } + public TouchCharInput(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + setup(); + } + + private boolean isClearingText = false; + + TextWatcher mTextWatcher = new TextWatcher() { + //TODO Engineer a more performant system + @Override + public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) { + if(isClearingText) return; + + for(int j=0; j { + //TODO remove the focus from the EditText ? + send(); + return false; + }); + } + +} diff --git a/app_pojavlauncher/src/main/res/layout/main_with_customctrl.xml b/app_pojavlauncher/src/main/res/layout/main_with_customctrl.xml index cff6aafc4..2beada168 100644 --- a/app_pojavlauncher/src/main/res/layout/main_with_customctrl.xml +++ b/app_pojavlauncher/src/main/res/layout/main_with_customctrl.xml @@ -46,6 +46,18 @@ android:layout_height="wrap_content" app:srcCompat="@drawable/pointer" /> + +