⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 defaultinputmethodhandler.java

📁 用于移动设备上的java虚拟机源代码
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
        if (idx == KEY_CLEAR) {            lastKey = KEYCODE_CLEAR;            setTimer(TM_CLEAR_BUFFER, 1500);            return KEYCODE_NONE;        }        //        // these flags will only be set if the user has not tried to         // change modes on their own        //        if (capWord || capSentence) {            if (imc.isNewWord() || imc.isNewSentence()) {                oldInputMode = IM_ROMAN_CAPS;                inputMode = IM_ROMAN_CAPS;            } else {                oldInputMode = IM_ROMAN_SMALL;                inputMode = IM_ROMAN_SMALL;            }            setKeyMap(inputMode, currentConstraints);           }               lastKey = keyMap[idx][charIndex];        charIndex = (charIndex + 1) % keyMap[idx].length;        // System.err.println("keyPressed: lastKey=" + lastKey);        //        // if the user holds the star key in these constraints then        // we need to tell the input client        //        if (idx == KEY_STAR && canUseSymbolTable) {            setTimer(TM_INPUT_MODE, 1000);            lastKey = KEYCODE_SHIFT;            return KEYCODE_NONE;        }        if (idx == KEY_POUND &&             (currentConstraints == TextField.NUMERIC   ||              currentConstraints == TextField.DECIMAL)) {            lastKey = KEYCODE_SIGNCHANGE;            endComposition(false);            return KEYCODE_NONE;        }        //        // if a key has more than one choice we need to cycle through them        //        if (keyMap[idx].length > 1) {            setTimer(TM_IN_COMPOSING, 1600);        } else {            endComposition(false);        }        return lastKey;    }    /**     * Handle a key released event.     * Overrides InputMethodHandler.keyReleased.     *     * @param keyCode The code of the key that was released     * @return boolean If True, this handler has handled the key release     */    public synchronized int keyReleased(int keyCode) {        if (ignoreNextKeyRelease) {            ignoreNextKeyRelease = false;            lastKey = KEYCODE_NONE;            lastKeyIndex = KEY_UNKNOWN;            return lastKey;        }        int idx = getKeyMapIndex(keyCode);        switch (idx) {            case KEY_UNKNOWN:                return KEYCODE_NONE;               case KEY_STAR:                if (timerType == TM_INPUT_MODE) {                    cancelTimer();                    if (canUseSymbolTable) {                        lastKey = KEYCODE_NONE;                        lastKeyIndex = KEY_UNKNOWN;                        switchToNextInputMode(false);                    } else {                        endComposition(false);                    }                }                break;            case KEY_CLEAR:                if (timerType == TM_CLEAR_BUFFER) {                    cancelTimer();                    endComposition(false);                }                break;        }        return lastKey;    }    /**     * Handle a key repeated event.     * Overrides InputMethodHandler.keyRepeated.     *     * @param keyCode The code of the key that was repeated     * @return boolean If True, this handler has handled the key repeat     */    public synchronized int keyRepeated(int keyCode) {        return keyPressed(keyCode);    }         /**      * Handle a typed key     *     * @param c character that was typed     * @return int Returns the character that was entered according to     *             to the current InputMode and constraints, or -1     *             if the keyCode was not recognized or will be handled     *             with a call back     */    public synchronized int keyTyped(char c) {        cancelTimer();        ignoreNextKeyRelease = false;        quickSymbolAccess = false;        endComposition(false);        if ((c == 8) || (c == 127)) {            lastKey = KEYCODE_CLEAR;        } else {            lastKey = (int)c;        }        endComposition(false);        return KEYCODE_NONE;    }    /**     * Removes any pending key presses     */    public void flush() {        cancelTimer();         ignoreNextKeyRelease = true;        lastKey = KEYCODE_NONE;        lastKeyIndex = KEY_UNKNOWN;        charIndex = 0;    }        /**     * End the on-going composition. Any keys that are pending are     * conditionally sent to the client.     *     * @param discard true to discard any pending keys     */    public synchronized void endComposition(boolean discard) {        if (lastKey == KEYCODE_NONE) {            return;        }        cancelTimer();        if (!discard && imc != null) {            imc.keyEntered(lastKey);            if (imc.isNewInputEntry()) {                capWord     =                    (currentModifiers & TextField.INITIAL_CAPS_WORD) ==                    TextField.INITIAL_CAPS_WORD;                capSentence =                    (currentModifiers & TextField.INITIAL_CAPS_SENTENCE) ==                    TextField.INITIAL_CAPS_SENTENCE;            }        }        lastKey = KEYCODE_NONE;        lastKeyIndex = KEY_UNKNOWN;        charIndex = 0;    }    /**     * Get the list of supported input modes of this handler.     * Overrides InputMethodHandler.supportedInputModes.     *     * @return String[] The array of supported input modes     */    public String[] supportedInputModes() {        return supportedCharSubset;    }    /** The '0' Timer. */    protected final static int TM_NONE         = 0;    /** The input mode timer. */    protected final static int TM_INPUT_MODE   = 1;    /** The 'in composition' timer. */    protected final static int TM_IN_COMPOSING = 2;    /** The 'clear buffer' timer. */    protected final static int TM_CLEAR_BUFFER = 3;    /** The type of timer to set. */    protected int timerType;    /**     * Set a new timer.     *     * @param type The type of Timer to set     * @param delay The length of delay for the Timer     */    protected void setTimer(int type, long delay) {        if (type != timerType) {            if (type == TM_IN_COMPOSING) {            }            timerType = type;        }        cancelTimer();        try {            timerClient = new TimerClient();            timerService.schedule(timerClient, delay);        } catch (IllegalStateException e) {            e.printStackTrace();            cancelTimer();        }    }    /** The Timer to service TimerTasks. */    protected Timer timerService = new Timer();    /** A TimerTask. */    protected TimerTask timerClient = null;    /**     * A special TimerTask class     */    class TimerClient extends TimerTask {        /**         * Simply calls timerWentOff()         */        public final void run() {            timerWentOff();        }    }    /**     * Cancel any running Timer.     */    protected synchronized void cancelTimer() {        if (timerType != TM_NONE && timerClient != null) {            timerClient.cancel();            timerClient = null;            timerType = TM_NONE;        }    }    /**     * Called by the TimerTask when a Timer executes.     */    protected synchronized void timerWentOff() {        switch (timerType) {            case TM_INPUT_MODE:                quickSymbolAccess = true;                ignoreNextKeyRelease = true;                endComposition(true);                oldInputMode = inputMode;                st.invokeSYM();                break;            case TM_CLEAR_BUFFER:                lastKey = KEYCODE_CLEARALL;                // fall through            case TM_IN_COMPOSING:                endComposition(false);                ignoreNextKeyRelease = true;                break;        }    }    /** The last key and last position of the input. */    protected int lastKey;    /** lastKey index into the key map */    protected int lastKeyIndex;    /** last character index into the key map at the */    protected int charIndex;    /** ignore the next keyRelease event */    protected boolean ignoreNextKeyRelease = false;    /**     * Switch to the next available input mode.      * Sets capWord and capSentence to false     *     * @param fromSymTable true if this is being called from      *                     the symbol table class. false otherwise     */    protected void switchToNextInputMode(boolean fromSymTable) {        if (fromSymTable && quickSymbolAccess) {            inputMode = oldInputMode;        } else if (fromSymTable) {            oldInputMode = defaultMode;            inputMode = defaultMode;        } else {            int n = 0;            // get the current input mode            while (n < allowedModesNum) {                if (allowedModes[n] == inputMode) {                    break;                }                n++;            }            n = (n + 1) % allowedModesNum;            oldInputMode = inputMode;            inputMode = allowedModes[n];            capWord = capSentence = false;        }        setKeyMap(inputMode, currentConstraints);            }    /**      * Set the appropriate keypad mapping according to the input mode     *     * @param mode The new input mode to use     * @param constraints the constraints to use     * @return true if keyMap is set.     */    protected boolean setKeyMap(int mode, int constraints) {        switch (mode) {            case IM_ROMAN_CAPS:                keyMap = upperRomanKeyMap;                break;            case IM_ROMAN_SMALL:                keyMap = lowerRomanKeyMap;                break;            case IM_NUMERIC:                keyMap = (constraints == TextField.PHONENUMBER)                        ? phoneNumericKeyMap                       : (constraints == TextField.DECIMAL                            ? decimalKeyMap                            : numericKeyMap);                break;            case IM_SYMBOL:                st.invokeSYM();                break;            case IM_NONE:                break;            default:                return false;        }           imc.showInputMode(mode);        return true;    }            /**     * Set the internal constraint and modifier variables. Determine     * the best inputMode and keyMap to use for the given constraints     *     * @param constraints Constraints to use     * @return true if the constraints were set correctly     */    public synchronized boolean setConstraints(int constraints) {        boolean ret = false;        currentConstraints = constraints & TextField.CONSTRAINT_MASK;        currentModifiers   = constraints & ~TextField.CONSTRAINT_MASK;        canUseSymbolTable = (currentConstraints == TextField.URL) ||                            (currentConstraints == TextField.EMAILADDR) ||                            (currentConstraints == TextField.ANY);        // if (constraints != currentConstraints)         {            ret = buildInputModes(currentConstraints, currentModifiers,                                  imc.getInputMode(),                                   imc.getAllowedModes());        }        // currentConstraints = constraints;        setKeyMap(inputMode, currentConstraints);        return ret;    }    /**     * Set the input mode.     *     * @param constraints The constraints     * @param modifiers The modifiers     * @param dMode the default mode, null to choose one     * @param aMode array of allowed modes, or null to use all     * @return boolean True, if the mode was valid     */    protected boolean buildInputModes(int constraints, int modifiers,                                       String dMode, String[] aMode) {        boolean ret = true;        capWord = capSentence = false;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -