mms 收件人编辑框 信息编辑框 输入法到输入框

本文详细探讨了Android下如何创建一个输入法,包括RecipientEditTextView的触摸事件处理,创建芯片、构建背景等步骤。同时讲解了ComposeMessageActivity中如何显示编辑框,并监听文本变化。此外,还介绍了TextView的文本监听机制,InputConnection接口用于键盘输入的操作,如deleteSurroundingText、commitText和sendKeyEvent。最后提到了InputMethodManager和ViewRootImpl在按键事件传递中的作用。
摘要由CSDN通过智能技术生成

 

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()//键盘按钮

 

  1. public interface InputConnection {  
  2.   public boolean deleteSurroundingText(int beforeLength, int afterLength);  //删除输入的字符  
  3.   public boolean commitText(CharSequence text, int newCursorPosition);  //输入字符  
  4.   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

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值