You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-05 12:10:55 +00:00
Android virtual keyboard respecting LineEdit max length.
This commit is contained in:
@@ -491,9 +491,9 @@ public class GodotIO {
|
||||
return (int)(metrics.density * 160f);
|
||||
}
|
||||
|
||||
public void showKeyboard(String p_existing_text) {
|
||||
public void showKeyboard(String p_existing_text, int p_max_input_length) {
|
||||
if (edit != null)
|
||||
edit.showKeyboard(p_existing_text);
|
||||
edit.showKeyboard(p_existing_text, p_max_input_length);
|
||||
|
||||
//InputMethodManager inputMgr = (InputMethodManager)activity.getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
//inputMgr.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
|
||||
|
||||
@@ -32,6 +32,7 @@ package org.godotengine.godot.input;
|
||||
import android.content.Context;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.text.InputFilter;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.inputmethod.EditorInfo;
|
||||
@@ -104,6 +105,7 @@ public class GodotEditText extends EditText {
|
||||
edit.append(text);
|
||||
edit.mInputWrapper.setOriginText(text);
|
||||
edit.addTextChangedListener(edit.mInputWrapper);
|
||||
setMaxInputLength(edit, msg.arg1);
|
||||
final InputMethodManager imm = (InputMethodManager)mView.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
imm.showSoftInput(edit, 0);
|
||||
}
|
||||
@@ -120,6 +122,16 @@ public class GodotEditText extends EditText {
|
||||
}
|
||||
}
|
||||
|
||||
private void setMaxInputLength(EditText p_edit_text, int p_max_input_length) {
|
||||
if (p_max_input_length >= 0) {
|
||||
InputFilter[] filters = new InputFilter[1];
|
||||
filters[0] = new InputFilter.LengthFilter(p_max_input_length);
|
||||
p_edit_text.setFilters(filters);
|
||||
} else {
|
||||
p_edit_text.setFilters(new InputFilter[] {});
|
||||
}
|
||||
}
|
||||
|
||||
// ===========================================================
|
||||
// Getter & Setter
|
||||
// ===========================================================
|
||||
@@ -149,12 +161,13 @@ public class GodotEditText extends EditText {
|
||||
// ===========================================================
|
||||
// Methods
|
||||
// ===========================================================
|
||||
public void showKeyboard(String p_existing_text) {
|
||||
public void showKeyboard(String p_existing_text, int p_max_input_length) {
|
||||
this.mOriginText = p_existing_text;
|
||||
|
||||
final Message msg = new Message();
|
||||
msg.what = HANDLER_OPEN_IME_KEYBOARD;
|
||||
msg.obj = this;
|
||||
msg.arg1 = p_max_input_length;
|
||||
sHandler.sendMessage(msg);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user