mirror of
https://github.com/AngelAuraMC/Amethyst-Android.git
synced 2025-09-16 08:05:34 -04:00
Add support for many ways of losing keyboard focus
This commit is contained in:
parent
6c753f7cef
commit
50be325bb7
@ -2,6 +2,7 @@ package net.kdt.pojavlaunch.customcontrols;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
|
import android.view.KeyEvent;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
@ -30,6 +31,12 @@ public class TouchCharInput extends androidx.appcompat.widget.AppCompatEditText
|
|||||||
|
|
||||||
|
|
||||||
private boolean isDoingInternalChanges = false;
|
private boolean isDoingInternalChanges = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* We take the new chars, and send them to the game.
|
||||||
|
* If less chars are present, remove some.
|
||||||
|
* The text is always cleaned up.
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected void onTextChanged(CharSequence text, int start, int lengthBefore, int lengthAfter) {
|
protected void onTextChanged(CharSequence text, int start, int lengthBefore, int lengthAfter) {
|
||||||
super.onTextChanged(text, start, lengthBefore, lengthAfter);
|
super.onTextChanged(text, start, lengthBefore, lengthAfter);
|
||||||
@ -51,6 +58,33 @@ public class TouchCharInput extends androidx.appcompat.widget.AppCompatEditText
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* When we change from app to app, the keyboard gets disabled.
|
||||||
|
* So, we disable the object
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void onWindowFocusChanged(boolean hasWindowFocus) {
|
||||||
|
super.onWindowFocusChanged(hasWindowFocus);
|
||||||
|
disable();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Intercepts the back key to disable focus
|
||||||
|
* Does not affect the rest of the activity.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public boolean onKeyPreIme(final int keyCode, final KeyEvent event) {
|
||||||
|
if (event.getKeyCode() == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_UP) {
|
||||||
|
disable();
|
||||||
|
}
|
||||||
|
return super.onKeyPreIme(keyCode, event);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setSelection(int index) {
|
||||||
|
super.setSelection(5);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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
|
||||||
@ -84,6 +118,7 @@ public class TouchCharInput extends androidx.appcompat.widget.AppCompatEditText
|
|||||||
* Lose ability to exist, take focus and have some text being input
|
* Lose ability to exist, take focus and have some text being input
|
||||||
*/
|
*/
|
||||||
public void disable(){
|
public void disable(){
|
||||||
|
clear();
|
||||||
setVisibility(GONE);
|
setVisibility(GONE);
|
||||||
clearFocus();
|
clearFocus();
|
||||||
setEnabled(false);
|
setEnabled(false);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user