下面列出了android.view.inputmethod.EditorInfo#TYPE_CLASS_TEXT 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
if (onCheckIsTextEditor() && isEnabled()) {
outAttrs.inputType = getInputType();
if (mInputContentType != null) {
outAttrs.imeOptions = mInputContentType.imeOptions;
outAttrs.privateImeOptions = mInputContentType.privateImeOptions;
outAttrs.actionLabel = mInputContentType.imeActionLabel;
outAttrs.actionId = mInputContentType.imeActionId;
outAttrs.extras = mInputContentType.extras;
} else {
outAttrs.imeOptions = EditorInfo.TYPE_CLASS_TEXT;
}
}
outAttrs.initialSelStart = getSelectionStart();
outAttrs.initialSelEnd = getSelectionEnd();
return new MetInputConnection(this, true);
}
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);
}
void startExtractingText(boolean inputChanged) {
final ExtractEditText eet = mExtractEditText;
if (eet != null && getCurrentInputStarted()
&& isFullscreenMode()) {
mExtractedToken++;
ExtractedTextRequest req = new ExtractedTextRequest();
req.token = mExtractedToken;
req.flags = InputConnection.GET_TEXT_WITH_STYLES;
req.hintMaxLines = 10;
req.hintMaxChars = 10000;
InputConnection ic = getCurrentInputConnection();
mExtractedText = ic == null? null
: ic.getExtractedText(req, InputConnection.GET_EXTRACTED_TEXT_MONITOR);
if (mExtractedText == null || ic == null) {
Log.e(TAG, "Unexpected null in startExtractingText : mExtractedText = "
+ mExtractedText + ", input connection = " + ic);
}
final EditorInfo ei = getCurrentInputEditorInfo();
try {
eet.startInternalChanges();
onUpdateExtractingVisibility(ei);
onUpdateExtractingViews(ei);
int inputType = ei.inputType;
if ((inputType&EditorInfo.TYPE_MASK_CLASS)
== EditorInfo.TYPE_CLASS_TEXT) {
if ((inputType&EditorInfo.TYPE_TEXT_FLAG_IME_MULTI_LINE) != 0) {
inputType |= EditorInfo.TYPE_TEXT_FLAG_MULTI_LINE;
}
}
eet.setInputType(inputType);
eet.setHint(ei.hintText);
if (mExtractedText != null) {
eet.setEnabled(true);
eet.setExtractedText(mExtractedText);
} else {
eet.setEnabled(false);
eet.setText("");
}
} finally {
eet.finishInternalChanges();
}
if (inputChanged) {
onExtractingInputChanged(ei);
}
}
}
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;
}
}
@VisibleForTesting
AdapterInputConnection(View view, ImeAdapter imeAdapter, EditorInfo outAttrs) {
super(view, true);
mInternalView = view;
mImeAdapter = imeAdapter;
mImeAdapter.setInputConnection(this);
mSingleLine = true;
outAttrs.imeOptions = EditorInfo.IME_FLAG_NO_FULLSCREEN
| EditorInfo.IME_FLAG_NO_EXTRACT_UI;
outAttrs.inputType = EditorInfo.TYPE_CLASS_TEXT
| EditorInfo.TYPE_TEXT_VARIATION_WEB_EDIT_TEXT;
if (imeAdapter.getTextInputType() == ImeAdapter.sTextInputTypeText) {
// Normal text field
outAttrs.inputType |= EditorInfo.TYPE_TEXT_FLAG_AUTO_CORRECT;
outAttrs.imeOptions |= EditorInfo.IME_ACTION_GO;
} else if (imeAdapter.getTextInputType() == ImeAdapter.sTextInputTypeTextArea ||
imeAdapter.getTextInputType() == ImeAdapter.sTextInputTypeContentEditable) {
// TextArea or contenteditable.
outAttrs.inputType |= EditorInfo.TYPE_TEXT_FLAG_MULTI_LINE
| EditorInfo.TYPE_TEXT_FLAG_CAP_SENTENCES
| EditorInfo.TYPE_TEXT_FLAG_AUTO_CORRECT;
outAttrs.imeOptions |= EditorInfo.IME_ACTION_NONE;
mSingleLine = false;
} else if (imeAdapter.getTextInputType() == ImeAdapter.sTextInputTypePassword) {
// Password
outAttrs.inputType = InputType.TYPE_CLASS_TEXT
| InputType.TYPE_TEXT_VARIATION_WEB_PASSWORD;
outAttrs.imeOptions |= EditorInfo.IME_ACTION_GO;
} else if (imeAdapter.getTextInputType() == ImeAdapter.sTextInputTypeSearch) {
// Search
outAttrs.imeOptions |= EditorInfo.IME_ACTION_SEARCH;
} else if (imeAdapter.getTextInputType() == ImeAdapter.sTextInputTypeUrl) {
// Url
// TYPE_TEXT_VARIATION_URI prevents Tab key from showing, so
// exclude it for now.
outAttrs.imeOptions |= EditorInfo.IME_ACTION_GO;
} else if (imeAdapter.getTextInputType() == ImeAdapter.sTextInputTypeEmail) {
// Email
outAttrs.inputType = InputType.TYPE_CLASS_TEXT
| InputType.TYPE_TEXT_VARIATION_WEB_EMAIL_ADDRESS;
outAttrs.imeOptions |= EditorInfo.IME_ACTION_GO;
} else if (imeAdapter.getTextInputType() == ImeAdapter.sTextInputTypeTel) {
// Telephone
// Number and telephone do not have both a Tab key and an
// action in default OSK, so set the action to NEXT
outAttrs.inputType = InputType.TYPE_CLASS_PHONE;
outAttrs.imeOptions |= EditorInfo.IME_ACTION_NEXT;
} else if (imeAdapter.getTextInputType() == ImeAdapter.sTextInputTypeNumber) {
// Number
outAttrs.inputType = InputType.TYPE_CLASS_NUMBER
| InputType.TYPE_NUMBER_VARIATION_NORMAL;
outAttrs.imeOptions |= EditorInfo.IME_ACTION_NEXT;
}
outAttrs.initialSelStart = imeAdapter.getInitialSelectionStart();
outAttrs.initialSelEnd = imeAdapter.getInitialSelectionEnd();
mLastUpdateSelectionStart = imeAdapter.getInitialSelectionStart();
mLastUpdateSelectionEnd = imeAdapter.getInitialSelectionEnd();
}
@VisibleForTesting
AdapterInputConnection(View view, ImeAdapter imeAdapter, EditorInfo outAttrs) {
super(view, true);
mInternalView = view;
mImeAdapter = imeAdapter;
mImeAdapter.setInputConnection(this);
mSingleLine = true;
outAttrs.imeOptions = EditorInfo.IME_FLAG_NO_FULLSCREEN
| EditorInfo.IME_FLAG_NO_EXTRACT_UI;
outAttrs.inputType = EditorInfo.TYPE_CLASS_TEXT
| EditorInfo.TYPE_TEXT_VARIATION_WEB_EDIT_TEXT;
if (imeAdapter.getTextInputType() == ImeAdapter.sTextInputTypeText) {
// Normal text field
outAttrs.inputType |= EditorInfo.TYPE_TEXT_FLAG_AUTO_CORRECT;
outAttrs.imeOptions |= EditorInfo.IME_ACTION_GO;
} else if (imeAdapter.getTextInputType() == ImeAdapter.sTextInputTypeTextArea ||
imeAdapter.getTextInputType() == ImeAdapter.sTextInputTypeContentEditable) {
// TextArea or contenteditable.
outAttrs.inputType |= EditorInfo.TYPE_TEXT_FLAG_MULTI_LINE
| EditorInfo.TYPE_TEXT_FLAG_CAP_SENTENCES
| EditorInfo.TYPE_TEXT_FLAG_AUTO_CORRECT;
outAttrs.imeOptions |= EditorInfo.IME_ACTION_NONE;
mSingleLine = false;
} else if (imeAdapter.getTextInputType() == ImeAdapter.sTextInputTypePassword) {
// Password
outAttrs.inputType = InputType.TYPE_CLASS_TEXT
| InputType.TYPE_TEXT_VARIATION_WEB_PASSWORD;
outAttrs.imeOptions |= EditorInfo.IME_ACTION_GO;
} else if (imeAdapter.getTextInputType() == ImeAdapter.sTextInputTypeSearch) {
// Search
outAttrs.imeOptions |= EditorInfo.IME_ACTION_SEARCH;
} else if (imeAdapter.getTextInputType() == ImeAdapter.sTextInputTypeUrl) {
// Url
// TYPE_TEXT_VARIATION_URI prevents Tab key from showing, so
// exclude it for now.
outAttrs.imeOptions |= EditorInfo.IME_ACTION_GO;
} else if (imeAdapter.getTextInputType() == ImeAdapter.sTextInputTypeEmail) {
// Email
outAttrs.inputType = InputType.TYPE_CLASS_TEXT
| InputType.TYPE_TEXT_VARIATION_WEB_EMAIL_ADDRESS;
outAttrs.imeOptions |= EditorInfo.IME_ACTION_GO;
} else if (imeAdapter.getTextInputType() == ImeAdapter.sTextInputTypeTel) {
// Telephone
// Number and telephone do not have both a Tab key and an
// action in default OSK, so set the action to NEXT
outAttrs.inputType = InputType.TYPE_CLASS_PHONE;
outAttrs.imeOptions |= EditorInfo.IME_ACTION_NEXT;
} else if (imeAdapter.getTextInputType() == ImeAdapter.sTextInputTypeNumber) {
// Number
outAttrs.inputType = InputType.TYPE_CLASS_NUMBER
| InputType.TYPE_NUMBER_VARIATION_NORMAL;
outAttrs.imeOptions |= EditorInfo.IME_ACTION_NEXT;
}
outAttrs.initialSelStart = imeAdapter.getInitialSelectionStart();
outAttrs.initialSelEnd = imeAdapter.getInitialSelectionEnd();
mLastUpdateSelectionStart = imeAdapter.getInitialSelectionStart();
mLastUpdateSelectionEnd = imeAdapter.getInitialSelectionEnd();
}