RecipientEditTextView.java
onTouchEvent( )
createChip() / selectChip()
constructChipSpan()
createChipBitmap(
// Create the background of the chip.
result.bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
)
ComposeMessageActivity.java
onOptionsItemSelected(){
switch (item.getItemId()) {
case MENU_ADD_SUBJECT:
showSubjectEditor(true);
mWorkingMessage.setSubject("", true);
updateSendButtonState();
mSubjectTextEditor.requestFocus();
break;
}
showSubjectEditor( mSubjectTextEditor.addTextChangedListener(mSubjectEditorWatcher);)
private final TextWatcher mSubjectEditorWatcher = new TextWatcher() {
beforeTextChanged()
onTextChanged()
afterTextChanged()
}
TextView.java
addTextChangedListener( mListeners.add(watcher); )
private void sendBeforeTextChanged(CharSequence text, int start, int before, int after) {
if (mListeners != null) {
final ArrayList<TextWatcher> list = mListeners;
final int count = list.size();
for (int i = 0; i < count; i++) {
list.get(i).beforeTextChanged(text, start, before, after);
}
}
// The spans that are inside or intersect the modified region no longer make sense
removeIntersectingNonAdjacentSpans(start, start + before, SpellCheckSpan.class);
removeIntersectingNonAdjacentSpans(start, start + before, SuggestionSpan.class);
}
/**
* Not private so it can be called from an inner class without going
* through a thunk.
*/
void sendOnTextChanged(CharSequence text, int start, int before, int after) {
if (mListeners != null) {
final ArrayList<TextWatcher> list = mListeners;
final int count = list.size();
for (int i = 0; i < count; i++) {
list.get(i).onTextChanged(text, start, before, after);
}
}
if (mEditor != null) mEditor.sendOnTextChanged(start, after);
}
setText(){
sendBeforeTextChanged
sendOnTextChanged
}
Android下创建一个输入法
http://www.cnblogs.com/palance/p/5059575.html
setComposingText()//键盘输入
commitText()//键盘输入
onKeyDown()//键盘按钮
- public interface InputConnection {
- public boolean deleteSurroundingText(int beforeLength, int afterLength); //删除输入的字符
- public boolean commitText(CharSequence text, int newCursorPosition); //输入字符
- public boolean sendKeyEvent(KeyEvent event); //注入按键
- }
InputMethodService.java
sendKeyChar( ic.commitText() )
InputConnectionWrapper implements InputConnection
commitText()
EditableInputConnection.java //一般输入框
commitText(super.commitText())
BaseInputConnection.java
/**
* Default implementation replaces any existing composing text with
* the given text. In addition, only if dummy mode, a key event is
* sent for the new text and the current editable buffer cleared.
*/
public boolean commitText(CharSequence text, int newCursorPosition) {
if (DEBUG) Log.v(TAG, "commitText " + text);
replaceText(text, newCursorPosition, false);
sendCurrentText();
return true;
}
private void replaceText(CharSequence text, int newCursorPosition,
boolean composing) {
final Editable content = getEditable();
content.replace(a, b, text);
}
sendCurrentText()
/**
* Provides standard implementation for sending a key event to the window
* attached to the input connection's view.
*/
public boolean sendKeyEvent(KeyEvent event) {
mIMM.dispatchKeyEventFromInputMethod(mTargetView, event);
return false;
}
replaceText(Editable.replace())
SpannableStringBuilder.java
replace()
按键
---------------------------------------------------------------------------------------------------------------
InputMethodManager.java
dispatchKeyEventFromInputMethod( viewRootImpl.dispatchKeyFromIme(event); )
ViewRootImpl.java
dispatchKeyFromIme()
MSG_DISPATCH_KEY_FROM_IME
enqueueInputEvent(event, null, QueuedInputEvent.FLAG_DELIVER_POST_IME, true);
doProcessInputEvents()
deliverInputEvent()--->processKeyEvent(mView.dispatchKeyEventPreIme(event))
DecorView.java
dispatchKeyEventPreIme(){
return isDown ? mWindow.onKeyDown(mFeatureId, event.getKeyCode(), event)
: mWindow.onKeyUp(mFeatureId, event.getKeyCode(), event);
}
WebViewClassic.java //浏览器输入框
Android的文本跟输入-创建输入法(一)
http://blog.csdn.net/yuanyuan_186/article/details/8561094