mirror of
https://github.com/AngelAuraMC/Amethyst-Android.git
synced 2025-09-15 15:48:26 -04:00
W.I.P Full virtual keyboard compatibility
This commit is contained in:
parent
b05cc6576f
commit
c417894438
@ -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
|
||||
|
@ -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<charSequence.length(); ++j){
|
||||
CallbackBridge.sendKeycode(LWJGLGLFWKeycode.GLFW_KEY_BACKSPACE, '\u0008', 0, 0, true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTextChanged(CharSequence charSequence, int start, int lengthBefore, int lengthAfter) {
|
||||
if(isClearingText) return;
|
||||
|
||||
for (int i=0; i<charSequence.length(); ++i){
|
||||
CallbackBridge.sendChar(charSequence.charAt(i));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterTextChanged(Editable editable) {
|
||||
if(isClearingText){
|
||||
isClearingText = false;
|
||||
editable.clear();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Clear the EditText from any leftover inputs
|
||||
* It does not affect the in-game input
|
||||
*/
|
||||
public void clear(){
|
||||
isClearingText = true;
|
||||
setText(" ");
|
||||
}
|
||||
|
||||
/**
|
||||
* Send the text stored to the game
|
||||
*/
|
||||
private void send(){
|
||||
//TODO proper focus removal ?
|
||||
BaseMainActivity.sendKeyPress(LWJGLGLFWKeycode.GLFW_KEY_ENTER);
|
||||
clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* This function deals with anything that has to be executed when the constructor is called
|
||||
*/
|
||||
private void setup(){
|
||||
//The text watcher used to look and send text
|
||||
addTextChangedListener(mTextWatcher);
|
||||
|
||||
setOnEditorActionListener((textView, i, keyEvent) -> {
|
||||
//TODO remove the focus from the EditText ?
|
||||
send();
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
}
|
@ -46,6 +46,18 @@
|
||||
android:layout_height="wrap_content"
|
||||
app:srcCompat="@drawable/pointer" />
|
||||
|
||||
<net.kdt.pojavlaunch.customcontrols.TouchCharInput
|
||||
android:imeOptions="flagNoFullscreen|flagNoPersonalizedLearning|actionSend"
|
||||
android:inputType="text|textNoSuggestions|textImeMultiLine"
|
||||
android:background="@android:color/darker_gray"
|
||||
android:id="@+id/editTextTextPersonName2"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:ems="10"
|
||||
android:layout_marginTop="20px"
|
||||
|
||||
android:text="" />
|
||||
|
||||
</net.kdt.pojavlaunch.customcontrols.ControlLayout>
|
||||
|
||||
<LinearLayout
|
||||
|
Loading…
x
Reference in New Issue
Block a user