RussianIME 全程解析4

7 deal with double click event

 

 

beacuse RussianIME has 31 characters,so one hardkey should have two character display function,how to deal with it,so just listen the keydown time ,and set one standard keydowntime max value,if people press one time,it will show A character,and if people press two times in the same hardkey quickly (keydown time is smaller than the max value),it will show B character.

The logic is

"if( bIsRussianHardboard == true && (System.currentTimeMillis() - iLastPressTime < MULTIPRESS_DELAY) && iLastKeycode == keyCode && !bIsReplaced && (KeyEvent.KEYCODE_Q == keyCode || KeyEvent.KEYCODE_P == keyCode || KeyEvent.KEYCODE_Z == keyCode || KeyEvent.KEYCODE_K == keyCode || KeyEvent.KEYCODE_L == keyCode || KeyEvent.KEYCODE_PERIOD == keyCode))"

{
                     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();
                }

 

// Convert a hardware key code to the corresponding Russian character code (in Unicode)

 

private int keyCodeToChar (int keyCode, boolean upperCase, int accentState) {
        int code;
        if (bIsReplaced) {
                if (hardCap == true)
                {
                code = sDcKeyCodeTable.get(keyCode, -1);
                }
                else
                {
                code = sDKeyCodeTable.get(keyCode, -1);
                }

                Log.d("Table","TableUsed is KeyCode");
        } else {
                code = sKeyCodeTable.get(keyCode, -1);
                Log.d("Table","TableUsed is sKeyCode");

        }
        if (accentState != ACCENT_STATE_NONE) {
                code = addAccent(code, accentState);
        }
        if (upperCase) {
                code = Character.toUpperCase(code);
        }
        return code;
    }

 

 

 

That is all.



 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章