Skip to content

Commit 4ef2d8b

Browse files
author
tuoli
committed
Android 增加TextField控件对密码和数字键盘的类型支持
1 parent 7b36583 commit 4ef2d8b

3 files changed

Lines changed: 41 additions & 1 deletion

File tree

Android/LuaViewSDK/src/com/taobao/luaview/fun/mapper/ui/UIEditTextMethodMapper.java

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import com.taobao.luaview.userdata.ui.UDEditText;
1313
import com.taobao.luaview.util.LuaViewUtil;
1414

15+
import org.luaj.vm2.LuaString;
1516
import org.luaj.vm2.LuaValue;
1617
import org.luaj.vm2.Varargs;
1718

@@ -29,7 +30,8 @@ public class UIEditTextMethodMapper<U extends UDEditText> extends UITextViewMeth
2930
private static final String TAG = "UIEditTextMethodMapper";
3031
private static final String[] sMethods = new String[]{
3132
"hint",//0
32-
"placeholder"//1
33+
"placeholder",//1
34+
"inputType"//2
3335
};
3436

3537
@Override
@@ -45,12 +47,33 @@ public Varargs invoke(int code, U target, Varargs varargs) {
4547
return hint(target, varargs);
4648
case 1:
4749
return placeholder(target, varargs);
50+
case 2:
51+
return inputType(target, varargs);
4852
}
4953
return super.invoke(code, target, varargs);
5054
}
5155

5256
//--------------------------------------- API --------------------------------------------------
5357

58+
/**
59+
* 键盘类型
60+
*/
61+
public LuaValue inputType(U view, Varargs varargs) {
62+
if (varargs.narg() > 1) {
63+
return setInputType(view, varargs);
64+
} else {
65+
return getInputType(view, varargs);
66+
}
67+
}
68+
69+
public LuaValue setInputType(U view, Varargs varargs) {
70+
final CharSequence type = LuaViewUtil.getText(varargs.optvalue(2, NIL));
71+
return view.setInputType(type);
72+
}
73+
74+
public LuaValue getInputType(U view, Varargs varargs) {
75+
return null;
76+
}
5477

5578
/**
5679
* 获取placeHolder内容

Android/LuaViewSDK/src/com/taobao/luaview/userdata/ui/UDEditText.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
package com.taobao.luaview.userdata.ui;
1010

1111
import android.text.Editable;
12+
import android.text.InputType;
1213
import android.text.TextWatcher;
1314
import android.widget.EditText;
1415

@@ -30,6 +31,20 @@ public UDEditText(EditText view, Globals globals, LuaValue metatable, Varargs in
3031
super(view, globals, metatable, initParams);
3132
}
3233

34+
public UDEditText setInputType(CharSequence text) {
35+
EditText view = getView();
36+
if (view != null) {
37+
if (text.equals("number")) {
38+
view.setInputType(InputType.TYPE_CLASS_NUMBER);
39+
} else if(text.equals("password")) {
40+
view.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
41+
} else {
42+
view.setInputType(InputType.TYPE_CLASS_TEXT);
43+
}
44+
}
45+
return this;
46+
}
47+
3348
/**
3449
* 设置提示文本
3550
*

Android/LuaViewSDK/src/com/taobao/luaview/view/LVEditText.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
package com.taobao.luaview.view;
1010

11+
import android.text.InputType;
1112
import android.widget.EditText;
1213

1314
import com.taobao.luaview.userdata.constants.UDFontSize;
@@ -32,6 +33,7 @@ public LVEditText(Globals globals, LuaValue metaTable, Varargs varargs) {
3233
super(globals.getContext());
3334
this.mLuaUserdata = new UDEditText(this, globals, metaTable, varargs);
3435
this.setTextSize(UDFontSize.FONTSIZE_SMALL);
36+
this.setInputType(InputType.TYPE_CLASS_TEXT);
3537
}
3638

3739
@Override

0 commit comments

Comments
 (0)