下面列出了android.view.inputmethod.EditorInfo#TYPE_CLASS_NUMBER 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private void resetKeyboardLayout() {
if ((mEditorInfo.inputType & EditorInfo.TYPE_CLASS_NUMBER) == EditorInfo.TYPE_CLASS_NUMBER) {
mKeyboardView.setKeyboard(getSymbolsKeyboard());
} else {
mKeyboardView.setKeyboard(mCurrentKeyboard.getAlphabeticKeyboard());
}
handleShift(false);
updateCandidates();
}
private static boolean isPasswordInputType(int inputType) {
final int variation =
inputType & (EditorInfo.TYPE_MASK_CLASS | EditorInfo.TYPE_MASK_VARIATION);
return variation
== (EditorInfo.TYPE_CLASS_TEXT | EditorInfo.TYPE_TEXT_VARIATION_PASSWORD)
|| variation
== (EditorInfo.TYPE_CLASS_TEXT | EditorInfo.TYPE_TEXT_VARIATION_WEB_PASSWORD)
|| variation
== (EditorInfo.TYPE_CLASS_NUMBER | EditorInfo.TYPE_NUMBER_VARIATION_PASSWORD);
}
private static boolean isPasswordInputType(int inputType) {
final int variation =
inputType & (EditorInfo.TYPE_MASK_CLASS | EditorInfo.TYPE_MASK_VARIATION);
return variation
== (EditorInfo.TYPE_CLASS_TEXT | EditorInfo.TYPE_TEXT_VARIATION_PASSWORD)
|| variation
== (EditorInfo.TYPE_CLASS_TEXT | EditorInfo.TYPE_TEXT_VARIATION_WEB_PASSWORD)
|| variation
== (EditorInfo.TYPE_CLASS_NUMBER | EditorInfo.TYPE_NUMBER_VARIATION_PASSWORD);
}
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
if(preference instanceof EditTextPreference && newValue instanceof String) {
EditText prefText = ((EditTextPreference) preference).getEditText();
int editorType = prefText.getInputType();
if(EditorInfo.TYPE_CLASS_NUMBER == (EditorInfo.TYPE_CLASS_NUMBER & editorType)) {
// Try to convert to double
double res;
try {
res = Double.valueOf((String)newValue);
} catch (NumberFormatException ex) {
return false;
}
if(EditorInfo.TYPE_NUMBER_FLAG_SIGNED != (EditorInfo.TYPE_NUMBER_FLAG_SIGNED & editorType)) {
// Must be superior than 0
if(res < 0) {
return false;
}
}
if(EditorInfo.TYPE_NUMBER_FLAG_SIGNED != (EditorInfo.TYPE_NUMBER_FLAG_SIGNED & editorType)) {
// Must be an integer
if(Double.compare(res % 1,0) != 0) {
return false;
}
}
}
return true;
}
return true;
}
private static boolean isNumberInputType(int inputType) {
return inputType == EditorInfo.TYPE_CLASS_NUMBER;
}
public void setInputType(EditorInfo editorInfo) {
/**
* do not use the enter key to fire some kind of action!
*/
// editorInfo.imeOptions |= EditorInfo.IME_ACTION_NONE;
Component txtCmp = Display.getInstance().getCurrent().getFocused();
if (txtCmp != null && txtCmp instanceof TextArea) {
TextArea txt = (TextArea) txtCmp;
if (txt.isSingleLineTextArea()) {
editorInfo.imeOptions |= EditorInfo.IME_ACTION_DONE;
} else {
editorInfo.imeOptions |= EditorInfo.IME_ACTION_NONE;
}
int inputType = 0;
int constraint = txt.getConstraint();
if ((constraint & TextArea.PASSWORD) == TextArea.PASSWORD) {
constraint = constraint ^ TextArea.PASSWORD;
}
switch (constraint) {
case TextArea.NUMERIC:
inputType = EditorInfo.TYPE_CLASS_NUMBER | EditorInfo.TYPE_NUMBER_FLAG_SIGNED;
break;
case TextArea.DECIMAL:
inputType = EditorInfo.TYPE_CLASS_NUMBER | EditorInfo.TYPE_NUMBER_FLAG_DECIMAL;
break;
case TextArea.PHONENUMBER:
inputType = EditorInfo.TYPE_CLASS_PHONE;
break;
case TextArea.EMAILADDR:
inputType = EditorInfo.TYPE_CLASS_TEXT | EditorInfo.TYPE_TEXT_VARIATION_EMAIL_ADDRESS;
break;
case TextArea.URL:
inputType = EditorInfo.TYPE_CLASS_TEXT | EditorInfo.TYPE_TEXT_VARIATION_URI;
break;
default:
inputType = EditorInfo.TYPE_CLASS_TEXT;
break;
}
editorInfo.inputType = inputType;
}
}