- Clean up the TouchInput system

- The textbox is invisible (I mean very very small)
This commit is contained in:
SerpentSpirale
2021-08-08 12:29:40 +02:00
committed by ArtDev
parent 98faa6561c
commit 6c753f7cef
2 changed files with 24 additions and 46 deletions

View File

@@ -1,11 +1,7 @@
package net.kdt.pojavlaunch.customcontrols;
import android.content.Context;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.AttributeSet;
import android.view.KeyEvent;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
@@ -32,34 +28,27 @@ public class TouchCharInput extends androidx.appcompat.widget.AppCompatEditText
setup();
}
private boolean isDoingInternalChanges = false;
TextWatcher mTextWatcher = new TextWatcher() {
//TODO Engineer a more performant system
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
if(isDoingInternalChanges) return;
for(int j=0; j<charSequence.length(); ++j){
@Override
protected void onTextChanged(CharSequence text, int start, int lengthBefore, int lengthAfter) {
super.onTextChanged(text, start, lengthBefore, lengthAfter);
if(isDoingInternalChanges){
isDoingInternalChanges = false;
return;
}
if(lengthAfter < lengthBefore){
for(int i=0; i< lengthBefore-lengthAfter; ++i){
CallbackBridge.sendKeycode(LWJGLGLFWKeycode.GLFW_KEY_BACKSPACE, '\u0008', 0, 0, true);
}
}
@Override
public void onTextChanged(CharSequence charSequence, int start, int lengthBefore, int lengthAfter) {
if(isDoingInternalChanges) return;
for (int i=0; i<charSequence.length(); ++i){
CallbackBridge.sendChar(charSequence.charAt(i));
}else{
for(int i=lengthBefore, index=lengthBefore+start; i < lengthAfter; ++i){
CallbackBridge.sendChar(text.charAt(index));
}
}
@Override
public void afterTextChanged(Editable editable) {
isDoingInternalChanges = false;
}
};
clear();
}
/**
@@ -68,14 +57,14 @@ public class TouchCharInput extends androidx.appcompat.widget.AppCompatEditText
*/
public void clear(){
isDoingInternalChanges = true;
setText("");
setText(" ");
setSelection(5);
}
/**
* Send the text stored to the game
* Send the enter key.
*/
private void send(){
//TODO proper focus removal ?
private void sendEnter(){
BaseMainActivity.sendKeyPress(LWJGLGLFWKeycode.GLFW_KEY_ENTER);
clear();
}
@@ -95,10 +84,8 @@ public class TouchCharInput extends androidx.appcompat.widget.AppCompatEditText
* Lose ability to exist, take focus and have some text being input
*/
public void disable(){
setVisibility(GONE);
clearFocus();
//setFocusable(false);
setEnabled(false);
}
@@ -108,17 +95,11 @@ public class TouchCharInput extends androidx.appcompat.widget.AppCompatEditText
* 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();
sendEnter();
return false;
});
isDoingInternalChanges = true;
setText("");
clear();
disable();
}

View File

@@ -51,12 +51,9 @@
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="" />
android:layout_width="1dp"
android:layout_height="1dp"
android:ems="10" />
</net.kdt.pojavlaunch.customcontrols.ControlLayout>