Fix virtual keyboard for decimal values on Android
This commit is contained in:
parent
13a0d6e9b2
commit
6f91c00056
|
@ -34,10 +34,13 @@ import org.godotengine.godot.*;
|
|||
|
||||
import android.content.Context;
|
||||
import android.content.res.Configuration;
|
||||
import android.os.Build;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.text.InputFilter;
|
||||
import android.text.InputType;
|
||||
import android.text.TextUtils;
|
||||
import android.text.method.DigitsKeyListener;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.inputmethod.EditorInfo;
|
||||
|
@ -45,6 +48,7 @@ import android.view.inputmethod.InputMethodManager;
|
|||
import android.widget.EditText;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.Locale;
|
||||
|
||||
public class GodotEditText extends EditText {
|
||||
// ===========================================================
|
||||
|
@ -137,6 +141,7 @@ public class GodotEditText extends EditText {
|
|||
}
|
||||
|
||||
int inputType = InputType.TYPE_CLASS_TEXT;
|
||||
String acceptCharacters = null;
|
||||
switch (edit.getKeyboardType()) {
|
||||
case KEYBOARD_TYPE_DEFAULT:
|
||||
inputType = InputType.TYPE_CLASS_TEXT;
|
||||
|
@ -148,7 +153,8 @@ public class GodotEditText extends EditText {
|
|||
inputType = InputType.TYPE_CLASS_NUMBER;
|
||||
break;
|
||||
case KEYBOARD_TYPE_NUMBER_DECIMAL:
|
||||
inputType = InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_SIGNED;
|
||||
inputType = InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_SIGNED | InputType.TYPE_NUMBER_FLAG_DECIMAL;
|
||||
acceptCharacters = "0123456789,.- ";
|
||||
break;
|
||||
case KEYBOARD_TYPE_PHONE:
|
||||
inputType = InputType.TYPE_CLASS_PHONE;
|
||||
|
@ -165,6 +171,14 @@ public class GodotEditText extends EditText {
|
|||
}
|
||||
edit.setInputType(inputType);
|
||||
|
||||
if (!TextUtils.isEmpty(acceptCharacters)) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
edit.setKeyListener(DigitsKeyListener.getInstance(Locale.getDefault()));
|
||||
} else {
|
||||
edit.setKeyListener(DigitsKeyListener.getInstance(acceptCharacters));
|
||||
}
|
||||
}
|
||||
|
||||
edit.mInputWrapper.setOriginText(text);
|
||||
edit.addTextChangedListener(edit.mInputWrapper);
|
||||
final InputMethodManager imm = (InputMethodManager)mRenderView.getView().getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
|
|
Loading…
Reference in New Issue