热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

RussianIME全程解析3

5transfertheinputtextintoappKeyeventInputConnectionicgetCurrentInputCo

5  transfer the inputtext into app

 

Keyevent

  1. InputConnection ic = getCurrentInputConnection();
  2. long eventTime = SystemClock.uptimeMillis();
  3. ic.sendKeyEvent(new KeyEvent(eventTime, eventTime,
  4.     KeyEvent.ACTION_DOWN, keyEventCode, 0, 0, 0, 0,
  5.     KeyEvent.FLAG_SOFT_KEYBOARD|KeyEvent.FLAG_KEEP_TOUCH_MODE));
  6. ic.sendKeyEvent(new KeyEvent(SystemClock.uptimeMillis(), eventTime,
  7.     KeyEvent.ACTION_UP, keyEventCode, 0, 0, 0, 0,
  8.     KeyEvent.FLAG_SOFT_KEYBOARD|KeyEvent.FLAG_KEEP_TOUCH_MODE));
InputMethodService.sendDownUpKeyEvents(keyEventCode);

input by lenovo
  1. InputConnection ic = getCurrentInputConnection();
  2. ic.setComposingText("Composi", 1);
6 deal with the hard keybard event

if you want to deal with the hard key event ,you can overide the InputMethodService.onKeyDown() and InputMethodService.onKeyUp();if not ,just use the super.onKey*.


@Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        switch (keyCode) {
            case KeyEvent.KEYCODE_BACK:
                if (event.getRepeatCount() == 0 && mInputView != null) {
                    if (mInputView.handleBack()) {
                        return true;
                    }
                }
                break;
            case KeyEvent.KEYCODE_DPAD_DOWN:
            case KeyEvent.KEYCODE_DPAD_UP:
            case KeyEvent.KEYCODE_DPAD_LEFT:
            case KeyEvent.KEYCODE_DPAD_RIGHT:
                break;
        }
        if( bIsRussianHardboard == true && (System.currentTimeMillis() - iLastPressTime                 {
                     bIsReplaced = true;
                     Log.i("isReplace", bIsReplaced + ";" );

                        iLastPressTime = -1;
                        final InputConnection ic = getCurrentInputConnection();
                        CharSequence lastChar = ic.getTextBeforeCursor(2, 0);
                        if (lastChar != null && lastChar.length() == 1
                                    && (lastChar.charAt(0)== '/u0419'||lastChar.charAt(0)== '/u042F'||lastChar.charAt(0)== '/u0416'||lastChar.charAt(0)== '/u0425'||lastChar.charAt(0)== '/u041B'||lastChar.charAt(0) ==KEYCODE_PERIOD))
                        {
                                Log.i("LASTCHAR", lastChar.charAt(0)+ ";");
                                hardCap = true;

                        }
                        else
                        {
                                hardCap = false;
                        }
                        handleBackspace();

                }
        else
                {
                bIsReplaced = false;


                iLastKeycode = keyCode;
                iLastPressTime = System.currentTimeMillis();
                }
      // sym is used to make the change of russian and english in russiankeyboard mode
        if (event.isSymPressed())
            {
                changeKeyboardLanguage();
                mHardKeyboard.updateMetaStateAfterKeypress(HardKeyboardState.META_SHIFT, true);
                return true;
               }

        // Do translation into Russian if necessary
        if (KeyboardSwitcher.LANGUAGE_RU == mKeyboardSwitcher.getKeyboardLanguage()
                        && handleHardKeyRussian(keyCode, event)) {

            bIsRussianHardboard = true;
            return true;
        } else {
            return super.onKeyDown(keyCode, event);
        }



    }
 @Override
    public boolean onKeyUp(int keyCode, KeyEvent event) {
        switch (keyCode) {
            case KeyEvent.KEYCODE_DPAD_DOWN:
            case KeyEvent.KEYCODE_DPAD_UP:
            case KeyEvent.KEYCODE_DPAD_LEFT:
            case KeyEvent.KEYCODE_DPAD_RIGHT:
                // Enable shift key and DPAD to do selections
                if (mInputView != null && mInputView.isShown() && mInputView.isShifted()) {
                    event = new KeyEvent(event.getDownTime(), event.getEventTime(),
                            event.getAction(), event.getKeyCode(), event.getRepeatCount(),
                            event.getDeviceId(), event.getScanCode(),
                            KeyEvent.META_SHIFT_LEFT_ON | KeyEvent.META_SHIFT_ON);
                    InputConnection ic = getCurrentInputConnection();
                    if (ic != null) ic.sendKeyEvent(event);
                    return true;
                }
                break;
        }
        return super.onKeyUp(keyCode, event);
    }


推荐阅读
author-avatar
一粒星尘ch
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有