예제 #1
0
        public override bool onKeyDown(int keyCode, android.view.KeyEvent @event)
        {
            bool handled = false;

            switch (keyCode)
            {
            case android.view.KeyEvent.KEYCODE_DPAD_UP:
            case android.view.KeyEvent.KEYCODE_DPAD_DOWN:
            case android.view.KeyEvent.KEYCODE_DPAD_LEFT:
            case android.view.KeyEvent.KEYCODE_DPAD_RIGHT:
            case android.view.KeyEvent.KEYCODE_ENTER:
            case android.view.KeyEvent.KEYCODE_DPAD_CENTER:
            {
                break;
            }

            case android.view.KeyEvent.KEYCODE_DEL:
            {
                switch (mMode)
                {
                case DIGITS_AND_LETTERS:
                {
                    handled  = mDigits.onKeyDown(keyCode, @event);
                    handled &= mLetters.onKeyDown(keyCode, @event);
                    break;
                }

                case DIGITS_AND_LETTERS_NO_DIGITS:
                {
                    handled = mLetters.onKeyDown(keyCode, @event);
                    if (((android.text.Editable)mLetters.getText()).Length == ((android.text.Editable
                                                                                )mDigits.getText()).Length)
                    {
                        setMode(DIGITS_AND_LETTERS);
                    }
                    break;
                }

                case DIGITS_AND_LETTERS_NO_LETTERS:
                {
                    if (((android.text.Editable)mDigits.getText()).Length == ((android.text.Editable)
                                                                              mLetters.getText()).Length)
                    {
                        mLetters.onKeyDown(keyCode, @event);
                        setMode(DIGITS_AND_LETTERS);
                    }
                    handled = mDigits.onKeyDown(keyCode, @event);
                    break;
                }

                case DIGITS_ONLY:
                {
                    handled = mDigits.onKeyDown(keyCode, @event);
                    break;
                }

                case LETTERS_ONLY:
                {
                    handled = mLetters.onKeyDown(keyCode, @event);
                    break;
                }
                }
                break;
            }

            default:
            {
                switch (mMode)
                {
                case DIGITS_AND_LETTERS:
                {
                    //mIsQwerty = msg.getKeyIsQwertyKeyboard();
                    handled = mLetters.onKeyDown(keyCode, @event);
                    // pass this throw so the shift state is correct (for example,
                    // on a standard QWERTY keyboard, * and 8 are on the same key)
                    if (android.view.KeyEvent.isModifierKey(keyCode))
                    {
                        mDigits.onKeyDown(keyCode, @event);
                        handled = true;
                        break;
                    }
                    // Only check to see if the digit is valid if the key is a printing key
                    // in the TextKeyListener. This prevents us from hiding the digits
                    // line when keys like UP and DOWN are hit.
                    // XXX note that KEYCODE_TAB is special-cased here for
                    // devices that share tab and 0 on a single key.
                    bool isPrint = @event.isPrintingKey();
                    if (isPrint || keyCode == android.view.KeyEvent.KEYCODE_SPACE || keyCode == android.view.KeyEvent
                        .KEYCODE_TAB)
                    {
                        char c = @event.getMatch(android.text.method.DialerKeyListener.CHARACTERS);
                        if (c != 0)
                        {
                            handled &= mDigits.onKeyDown(keyCode, @event);
                        }
                        else
                        {
                            setMode(DIGITS_AND_LETTERS_NO_DIGITS);
                        }
                    }
                    break;
                }

                case DIGITS_AND_LETTERS_NO_LETTERS:
                case DIGITS_ONLY:
                {
                    handled = mDigits.onKeyDown(keyCode, @event);
                    break;
                }

                case DIGITS_AND_LETTERS_NO_DIGITS:
                case LETTERS_ONLY:
                {
                    handled = mLetters.onKeyDown(keyCode, @event);
                    break;
                }
                }
                break;
            }
            }
            if (!handled)
            {
                return(base.onKeyDown(keyCode, @event));
            }
            else
            {
                return(true);
            }
        }