Example usage for android.view KeyEvent ACTION_UP

List of usage examples for android.view KeyEvent ACTION_UP

Introduction

In this page you can find the example usage for android.view KeyEvent ACTION_UP.

Prototype

int ACTION_UP

To view the source code for android.view KeyEvent ACTION_UP.

Click Source Link

Document

#getAction value: the key has been released.

Usage

From source file:org.distantshoresmedia.keyboard.LatinIME.java

private void sendSpecialKey(int code) {
    if (!isConnectbot()) {
        commitTyped(getCurrentInputConnection(), true);
        sendModifiedKeyDownUp(code);/*ww w.  jav a2 s  . c o m*/
        return;
    }

    // TODO(klausw): properly support xterm sequences for Ctrl/Alt modifiers?
    // See http://slackware.osuosl.org/slackware-12.0/source/l/ncurses/xterm.terminfo
    // and the output of "$ infocmp -1L". Support multiple sets, and optional 
    // true numpad keys?
    if (ESC_SEQUENCES == null) {
        ESC_SEQUENCES = new HashMap<Integer, String>();
        CTRL_SEQUENCES = new HashMap<Integer, Integer>();

        // VT escape sequences without leading Escape
        ESC_SEQUENCES.put(-TKKeyboardView.KEYCODE_HOME, "[1~");
        ESC_SEQUENCES.put(-TKKeyboardView.KEYCODE_END, "[4~");
        ESC_SEQUENCES.put(-TKKeyboardView.KEYCODE_PAGE_UP, "[5~");
        ESC_SEQUENCES.put(-TKKeyboardView.KEYCODE_PAGE_DOWN, "[6~");
        ESC_SEQUENCES.put(-TKKeyboardView.KEYCODE_FKEY_F1, "OP");
        ESC_SEQUENCES.put(-TKKeyboardView.KEYCODE_FKEY_F2, "OQ");
        ESC_SEQUENCES.put(-TKKeyboardView.KEYCODE_FKEY_F3, "OR");
        ESC_SEQUENCES.put(-TKKeyboardView.KEYCODE_FKEY_F4, "OS");
        ESC_SEQUENCES.put(-TKKeyboardView.KEYCODE_FKEY_F5, "[15~");
        ESC_SEQUENCES.put(-TKKeyboardView.KEYCODE_FKEY_F6, "[17~");
        ESC_SEQUENCES.put(-TKKeyboardView.KEYCODE_FKEY_F7, "[18~");
        ESC_SEQUENCES.put(-TKKeyboardView.KEYCODE_FKEY_F8, "[19~");
        ESC_SEQUENCES.put(-TKKeyboardView.KEYCODE_FKEY_F9, "[20~");
        ESC_SEQUENCES.put(-TKKeyboardView.KEYCODE_FKEY_F10, "[21~");
        ESC_SEQUENCES.put(-TKKeyboardView.KEYCODE_FKEY_F11, "[23~");
        ESC_SEQUENCES.put(-TKKeyboardView.KEYCODE_FKEY_F12, "[24~");
        ESC_SEQUENCES.put(-TKKeyboardView.KEYCODE_FORWARD_DEL, "[3~");
        ESC_SEQUENCES.put(-TKKeyboardView.KEYCODE_INSERT, "[2~");

        // Special ConnectBot hack: Ctrl-1 to Ctrl-0 for F1-F10.
        CTRL_SEQUENCES.put(-TKKeyboardView.KEYCODE_FKEY_F1, KeyEvent.KEYCODE_1);
        CTRL_SEQUENCES.put(-TKKeyboardView.KEYCODE_FKEY_F2, KeyEvent.KEYCODE_2);
        CTRL_SEQUENCES.put(-TKKeyboardView.KEYCODE_FKEY_F3, KeyEvent.KEYCODE_3);
        CTRL_SEQUENCES.put(-TKKeyboardView.KEYCODE_FKEY_F4, KeyEvent.KEYCODE_4);
        CTRL_SEQUENCES.put(-TKKeyboardView.KEYCODE_FKEY_F5, KeyEvent.KEYCODE_5);
        CTRL_SEQUENCES.put(-TKKeyboardView.KEYCODE_FKEY_F6, KeyEvent.KEYCODE_6);
        CTRL_SEQUENCES.put(-TKKeyboardView.KEYCODE_FKEY_F7, KeyEvent.KEYCODE_7);
        CTRL_SEQUENCES.put(-TKKeyboardView.KEYCODE_FKEY_F8, KeyEvent.KEYCODE_8);
        CTRL_SEQUENCES.put(-TKKeyboardView.KEYCODE_FKEY_F9, KeyEvent.KEYCODE_9);
        CTRL_SEQUENCES.put(-TKKeyboardView.KEYCODE_FKEY_F10, KeyEvent.KEYCODE_0);

        // Natively supported by ConnectBot
        // ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_DPAD_UP, "OA");
        // ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_DPAD_DOWN, "OB");
        // ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_DPAD_LEFT, "OD");
        // ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_DPAD_RIGHT, "OC");

        // No VT equivalents?
        // ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_DPAD_CENTER, "");
        // ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_SYSRQ, "");
        // ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_BREAK, "");
        // ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_NUM_LOCK, "");
        // ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_SCROLL_LOCK, "");
    }
    InputConnection ic = getCurrentInputConnection();
    Integer ctrlseq = null;
    if (mConnectbotTabHack) {
        ctrlseq = CTRL_SEQUENCES.get(code);
    }
    String seq = ESC_SEQUENCES.get(code);

    if (ctrlseq != null) {
        if (mModAlt) {
            // send ESC prefix for "Alt"
            ic.commitText(Character.toString((char) 27), 1);
        }
        ic.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DPAD_CENTER));
        ic.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_DPAD_CENTER));
        ic.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, ctrlseq));
        ic.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, ctrlseq));
    } else if (seq != null) {
        if (mModAlt) {
            // send ESC prefix for "Alt"
            ic.commitText(Character.toString((char) 27), 1);
        }
        // send ESC prefix of escape sequence
        ic.commitText(Character.toString((char) 27), 1);
        ic.commitText(seq, 1);
    } else {
        // send key code, let connectbot handle it
        sendDownUpKeyEvents(code);
    }
    handleModifierKeysUp(false, false);
}

From source file:org.pocketworkstation.pckeyboard.LatinIME.java

private void sendSpecialKey(int code) {
    if (!isConnectbot()) {
        commitTyped(getCurrentInputConnection(), true);
        sendModifiedKeyDownUp(code);//from   w  w  w. j  a  v a 2  s .  c  o m
        return;
    }

    // TODO(klausw): properly support xterm sequences for Ctrl/Alt modifiers?
    // See http://slackware.osuosl.org/slackware-12.0/source/l/ncurses/xterm.terminfo
    // and the output of "$ infocmp -1L". Support multiple sets, and optional 
    // true numpad keys?
    if (ESC_SEQUENCES == null) {
        ESC_SEQUENCES = new HashMap<Integer, String>();
        CTRL_SEQUENCES = new HashMap<Integer, Integer>();

        // VT escape sequences without leading Escape
        ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_HOME, "[1~");
        ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_END, "[4~");
        ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_PAGE_UP, "[5~");
        ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_PAGE_DOWN, "[6~");
        ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_FKEY_F1, "OP");
        ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_FKEY_F2, "OQ");
        ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_FKEY_F3, "OR");
        ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_FKEY_F4, "OS");
        ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_FKEY_F5, "[15~");
        ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_FKEY_F6, "[17~");
        ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_FKEY_F7, "[18~");
        ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_FKEY_F8, "[19~");
        ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_FKEY_F9, "[20~");
        ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_FKEY_F10, "[21~");
        ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_FKEY_F11, "[23~");
        ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_FKEY_F12, "[24~");
        ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_FORWARD_DEL, "[3~");
        ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_INSERT, "[2~");

        // Special ConnectBot hack: Ctrl-1 to Ctrl-0 for F1-F10.
        CTRL_SEQUENCES.put(-LatinKeyboardView.KEYCODE_FKEY_F1, KeyEvent.KEYCODE_1);
        CTRL_SEQUENCES.put(-LatinKeyboardView.KEYCODE_FKEY_F2, KeyEvent.KEYCODE_2);
        CTRL_SEQUENCES.put(-LatinKeyboardView.KEYCODE_FKEY_F3, KeyEvent.KEYCODE_3);
        CTRL_SEQUENCES.put(-LatinKeyboardView.KEYCODE_FKEY_F4, KeyEvent.KEYCODE_4);
        CTRL_SEQUENCES.put(-LatinKeyboardView.KEYCODE_FKEY_F5, KeyEvent.KEYCODE_5);
        CTRL_SEQUENCES.put(-LatinKeyboardView.KEYCODE_FKEY_F6, KeyEvent.KEYCODE_6);
        CTRL_SEQUENCES.put(-LatinKeyboardView.KEYCODE_FKEY_F7, KeyEvent.KEYCODE_7);
        CTRL_SEQUENCES.put(-LatinKeyboardView.KEYCODE_FKEY_F8, KeyEvent.KEYCODE_8);
        CTRL_SEQUENCES.put(-LatinKeyboardView.KEYCODE_FKEY_F9, KeyEvent.KEYCODE_9);
        CTRL_SEQUENCES.put(-LatinKeyboardView.KEYCODE_FKEY_F10, KeyEvent.KEYCODE_0);

        // Natively supported by ConnectBot
        // ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_DPAD_UP, "OA");
        // ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_DPAD_DOWN, "OB");
        // ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_DPAD_LEFT, "OD");
        // ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_DPAD_RIGHT, "OC");

        // No VT equivalents?
        // ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_DPAD_CENTER, "");
        // ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_SYSRQ, "");
        // ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_BREAK, "");
        // ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_NUM_LOCK, "");
        // ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_SCROLL_LOCK, "");
    }
    InputConnection ic = getCurrentInputConnection();
    Integer ctrlseq = null;
    if (mConnectbotTabHack) {
        ctrlseq = CTRL_SEQUENCES.get(code);
    }
    String seq = ESC_SEQUENCES.get(code);

    if (ctrlseq != null) {
        if (mModAlt) {
            // send ESC prefix for "Alt"
            ic.commitText(Character.toString((char) 27), 1);
        }
        ic.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DPAD_CENTER));
        ic.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_DPAD_CENTER));
        ic.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, ctrlseq));
        ic.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, ctrlseq));
    } else if (seq != null) {
        if (mModAlt) {
            // send ESC prefix for "Alt"
            ic.commitText(Character.toString((char) 27), 1);
        }
        // send ESC prefix of escape sequence
        ic.commitText(Character.toString((char) 27), 1);
        ic.commitText(seq, 1);
    } else {
        // send key code, let connectbot handle it
        sendDownUpKeyEvents(code);
    }
    handleModifierKeysUp(false, false);
}

From source file:com.android.launcher2.Launcher.java

@Override
public boolean dispatchKeyEvent(KeyEvent event) {
    if (event.getAction() == KeyEvent.ACTION_DOWN) {
        switch (event.getKeyCode()) {
        case KeyEvent.KEYCODE_HOME:
            return true;
        case KeyEvent.KEYCODE_VOLUME_DOWN:
            if (isPropertyEnabled(DUMP_STATE_PROPERTY)) {
                dumpState();/*from  w ww  .  j  a  v a  2  s.  c o m*/
                return true;
            }
            break;
        }
    } else if (event.getAction() == KeyEvent.ACTION_UP) {
        switch (event.getKeyCode()) {
        case KeyEvent.KEYCODE_HOME:
            return true;
        }
    }

    return super.dispatchKeyEvent(event);
}

From source file:org.distantshoresmedia.keyboard.LatinIME.java

private void sendTab() {
    InputConnection ic = getCurrentInputConnection();
    boolean tabHack = isConnectbot() && mConnectbotTabHack;

    // FIXME: tab and ^I don't work in connectbot, hackish workaround
    if (tabHack) {
        if (mModAlt) {
            // send ESC prefix
            ic.commitText(Character.toString((char) 27), 1);
        }//from  w  w  w . j  av  a 2  s .co m
        ic.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DPAD_CENTER));
        ic.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_DPAD_CENTER));
        ic.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_I));
        ic.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_I));
    } else {
        sendModifiedKeyDownUp(KeyEvent.KEYCODE_TAB);
    }
}

From source file:com.gxapplications.android.gxsuite.launcher.Launcher.java

@Override
public boolean dispatchKeyEvent(KeyEvent event) {
    if (event.getAction() == KeyEvent.ACTION_DOWN) {
        switch (event.getKeyCode()) {
        case KeyEvent.KEYCODE_HOME:
            return true;
        case KeyEvent.KEYCODE_VOLUME_DOWN:
            if (doesFileExist(DUMP_STATE_PROPERTY)) {
                dumpState();//from ww w .j  a v a  2 s.  c o m
                return true;
            }
            break;
        }
    } else if (event.getAction() == KeyEvent.ACTION_UP) {
        switch (event.getKeyCode()) {
        case KeyEvent.KEYCODE_HOME:
            return true;
        }
    }

    return super.dispatchKeyEvent(event);
}

From source file:org.bangbang.support.v4.widget.HListView.java

private boolean commonKey(int keyCode, int count, KeyEvent event) {
        if (mAdapter == null) {
            return false;
        }/*www  .ja  v a  2  s  .  c  o  m*/

        if (mDataChanged) {
            layoutChildren();
        }

        boolean handled = false;
        int action = event.getAction();

        if (action != KeyEvent.ACTION_UP) {
            if (mSelectedPosition < 0) {
                switch (keyCode) {
                case KeyEvent.KEYCODE_DPAD_UP:
                case KeyEvent.KEYCODE_DPAD_DOWN:
                case KeyEvent.KEYCODE_DPAD_CENTER:
                case KeyEvent.KEYCODE_ENTER:
                case KeyEvent.KEYCODE_SPACE:
                    if (resurrectSelection()) {
                        return true;
                    }
                }
            }
            switch (keyCode) {
            case KeyEvent.KEYCODE_DPAD_LEFT:
                if (!event.isAltPressed()) {
                    while (count > 0) {
                        handled = arrowScroll(FOCUS_LEFT);
                        count--;
                    }
                } else {
                    handled = fullScroll(FOCUS_LEFT);
                }
                break;

            case KeyEvent.KEYCODE_DPAD_RIGHT:
                if (!event.isAltPressed()) {
                    while (count > 0) {
                        handled = arrowScroll(FOCUS_RIGHT);
                        count--;
                    }
                } else {
                    handled = fullScroll(FOCUS_RIGHT);
                }
                break;

            case KeyEvent.KEYCODE_DPAD_UP:
                handled = handleHorizontalFocusWithinListItem(View.FOCUS_UP);
                break;
            case KeyEvent.KEYCODE_DPAD_DOWN:
                handled = handleHorizontalFocusWithinListItem(View.FOCUS_DOWN);
                break;

            case KeyEvent.KEYCODE_DPAD_CENTER:
            case KeyEvent.KEYCODE_ENTER:
                if (mItemCount > 0 && event.getRepeatCount() == 0) {
                    keyPressed();
                }
                handled = true;
                break;

            case KeyEvent.KEYCODE_SPACE:
                if (mPopup == null || !mPopup.isShowing()) {
                    if (!event.isShiftPressed()) {
                        pageScroll(FOCUS_DOWN);
                    } else {
                        pageScroll(FOCUS_UP);
                    }
                    handled = true;
                }
                break;
            }
        }

        if (!handled) {
            handled = sendToTextFilter(keyCode, count, event);
        }

        if (handled) {
            return true;
        } else {
            switch (action) {
            case KeyEvent.ACTION_DOWN:
                return super.onKeyDown(keyCode, event);

            case KeyEvent.ACTION_UP:
                return super.onKeyUp(keyCode, event);

            case KeyEvent.ACTION_MULTIPLE:
                return super.onKeyMultiple(keyCode, count, event);

            default: // shouldn't happen
                return false;
            }
        }
    }

From source file:com.appunite.list.HorizontalListView.java

private boolean commonKey(int keyCode, int count, KeyEvent event) {
    if (mAdapter == null || !mIsAttached) {
        return false;
    }//from  w  w w .  jav a2 s.c  o  m
    // TODO I stopped swaping heare (j.m.)
    if (mDataChanged) {
        layoutChildren();
    }

    boolean handled = false;
    int action = event.getAction();

    if (action != KeyEvent.ACTION_UP) {
        switch (keyCode) {
        case KeyEvent.KEYCODE_DPAD_RIGHT:
            if (KeyEventCompat.hasNoModifiers(event)) {
                handled = resurrectSelectionIfNeeded();
                if (!handled) {
                    while (count-- > 0) {
                        if (arrowScroll(FOCUS_RIGHT)) {
                            handled = true;
                        } else {
                            break;
                        }
                    }
                }
            } else if (KeyEventCompat.hasModifiers(event, KeyEvent.META_ALT_ON)) {
                handled = resurrectSelectionIfNeeded() || fullScroll(FOCUS_RIGHT);
            }
            break;

        case KeyEvent.KEYCODE_DPAD_LEFT:
            if (KeyEventCompat.hasNoModifiers(event)) {
                handled = resurrectSelectionIfNeeded();
                if (!handled) {
                    while (count-- > 0) {
                        if (arrowScroll(FOCUS_LEFT)) {
                            handled = true;
                        } else {
                            break;
                        }
                    }
                }
            } else if (KeyEventCompat.hasModifiers(event, KeyEvent.META_ALT_ON)) {
                handled = resurrectSelectionIfNeeded() || fullScroll(FOCUS_LEFT);
            }
            break;

        case KeyEvent.KEYCODE_DPAD_UP:
            if (KeyEventCompat.hasNoModifiers(event)) {
                handled = handleHorizontalFocusWithinListItem(View.FOCUS_UP);
            }
            break;

        case KeyEvent.KEYCODE_DPAD_DOWN:
            if (KeyEventCompat.hasNoModifiers(event)) {
                handled = handleHorizontalFocusWithinListItem(View.FOCUS_DOWN);
            }
            break;

        case KeyEvent.KEYCODE_DPAD_CENTER:
        case KeyEvent.KEYCODE_ENTER:
            if (KeyEventCompat.hasNoModifiers(event)) {
                handled = resurrectSelectionIfNeeded();
                if (!handled && event.getRepeatCount() == 0 && getChildCount() > 0) {
                    keyPressed();
                    handled = true;
                }
            }
            break;

        case KeyEvent.KEYCODE_SPACE:
            if (mPopup == null || !mPopup.isShowing()) {
                if (KeyEventCompat.hasNoModifiers(event)) {
                    handled = resurrectSelectionIfNeeded() || pageScroll(FOCUS_RIGHT);
                } else if (KeyEventCompat.hasModifiers(event, KeyEvent.META_SHIFT_ON)) {
                    handled = resurrectSelectionIfNeeded() || pageScroll(FOCUS_LEFT);
                }
                handled = true;
            }
            break;

        case KeyEvent.KEYCODE_PAGE_UP:
            if (KeyEventCompat.hasNoModifiers(event)) {
                handled = resurrectSelectionIfNeeded() || pageScroll(FOCUS_LEFT);
            } else if (KeyEventCompat.hasModifiers(event, KeyEvent.META_ALT_ON)) {
                handled = resurrectSelectionIfNeeded() || fullScroll(FOCUS_LEFT);
            }
            break;

        case KeyEvent.KEYCODE_PAGE_DOWN:
            if (KeyEventCompat.hasNoModifiers(event)) {
                handled = resurrectSelectionIfNeeded() || pageScroll(FOCUS_RIGHT);
            } else if (KeyEventCompat.hasModifiers(event, KeyEvent.META_ALT_ON)) {
                handled = resurrectSelectionIfNeeded() || fullScroll(FOCUS_RIGHT);
            }
            break;

        case KeyEvent.KEYCODE_MOVE_HOME:
            if (KeyEventCompat.hasNoModifiers(event)) {
                handled = resurrectSelectionIfNeeded() || fullScroll(FOCUS_LEFT);
            }
            break;

        case KeyEvent.KEYCODE_MOVE_END:
            if (KeyEventCompat.hasNoModifiers(event)) {
                handled = resurrectSelectionIfNeeded() || fullScroll(FOCUS_RIGHT);
            }
            break;

        case KeyEvent.KEYCODE_TAB:
            // XXX Sometimes it is useful to be able to TAB through the items in
            //     a ListView sequentially.  Unfortunately this can create an
            //     asymmetry in TAB navigation order unless the list selection
            //     always reverts to the top or bottom when receiving TAB focus from
            //     another widget.  Leaving this behavior disabled for now but
            //     perhaps it should be configurable (and more comprehensive).
            if (false) {
                if (KeyEventCompat.hasNoModifiers(event)) {
                    handled = resurrectSelectionIfNeeded() || arrowScroll(FOCUS_RIGHT);
                } else if (KeyEventCompat.hasModifiers(event, KeyEvent.META_SHIFT_ON)) {
                    handled = resurrectSelectionIfNeeded() || arrowScroll(FOCUS_LEFT);
                }
            }
            break;
        }
    }

    if (handled) {
        return true;
    }

    if (sendToTextFilter(keyCode, count, event)) {
        return true;
    }

    switch (action) {
    case KeyEvent.ACTION_DOWN:
        return super.onKeyDown(keyCode, event);

    case KeyEvent.ACTION_UP:
        return super.onKeyUp(keyCode, event);

    case KeyEvent.ACTION_MULTIPLE:
        return super.onKeyMultiple(keyCode, count, event);

    default: // shouldn't happen
        return false;
    }
}

From source file:com.appunite.list.ListView.java

private boolean commonKey(int keyCode, int count, KeyEvent event) {
    if (mAdapter == null || !mIsAttached) {
        return false;
    }/*from   w ww .  ja v a  2 s  .c  o  m*/

    if (mDataChanged) {
        layoutChildren();
    }

    boolean handled = false;
    int action = event.getAction();

    if (action != KeyEvent.ACTION_UP) {
        switch (keyCode) {
        case KeyEvent.KEYCODE_DPAD_UP:
            if (KeyEventCompat.hasNoModifiers(event)) {
                handled = resurrectSelectionIfNeeded();
                if (!handled) {
                    while (count-- > 0) {
                        if (arrowScroll(FOCUS_UP)) {
                            handled = true;
                        } else {
                            break;
                        }
                    }
                }
            } else if (KeyEventCompat.hasModifiers(event, KeyEvent.META_ALT_ON)) {
                handled = resurrectSelectionIfNeeded() || fullScroll(FOCUS_UP);
            }
            break;

        case KeyEvent.KEYCODE_DPAD_DOWN:
            if (KeyEventCompat.hasNoModifiers(event)) {
                handled = resurrectSelectionIfNeeded();
                if (!handled) {
                    while (count-- > 0) {
                        if (arrowScroll(FOCUS_DOWN)) {
                            handled = true;
                        } else {
                            break;
                        }
                    }
                }
            } else if (KeyEventCompat.hasModifiers(event, KeyEvent.META_ALT_ON)) {
                handled = resurrectSelectionIfNeeded() || fullScroll(FOCUS_DOWN);
            }
            break;

        case KeyEvent.KEYCODE_DPAD_LEFT:
            if (KeyEventCompat.hasNoModifiers(event)) {
                handled = handleHorizontalFocusWithinListItem(View.FOCUS_LEFT);
            }
            break;

        case KeyEvent.KEYCODE_DPAD_RIGHT:
            if (KeyEventCompat.hasNoModifiers(event)) {
                handled = handleHorizontalFocusWithinListItem(View.FOCUS_RIGHT);
            }
            break;

        case KeyEvent.KEYCODE_DPAD_CENTER:
        case KeyEvent.KEYCODE_ENTER:
            if (KeyEventCompat.hasNoModifiers(event)) {
                handled = resurrectSelectionIfNeeded();
                if (!handled && event.getRepeatCount() == 0 && getChildCount() > 0) {
                    keyPressed();
                    handled = true;
                }
            }
            break;

        case KeyEvent.KEYCODE_SPACE:
            if (mPopup == null || !mPopup.isShowing()) {
                if (KeyEventCompat.hasNoModifiers(event)) {
                    handled = resurrectSelectionIfNeeded() || pageScroll(FOCUS_DOWN);
                } else if (KeyEventCompat.hasModifiers(event, KeyEvent.META_SHIFT_ON)) {
                    handled = resurrectSelectionIfNeeded() || pageScroll(FOCUS_UP);
                }
                handled = true;
            }
            break;

        case KeyEvent.KEYCODE_PAGE_UP:
            if (KeyEventCompat.hasNoModifiers(event)) {
                handled = resurrectSelectionIfNeeded() || pageScroll(FOCUS_UP);
            } else if (KeyEventCompat.hasModifiers(event, KeyEvent.META_ALT_ON)) {
                handled = resurrectSelectionIfNeeded() || fullScroll(FOCUS_UP);
            }
            break;

        case KeyEvent.KEYCODE_PAGE_DOWN:
            if (KeyEventCompat.hasNoModifiers(event)) {
                handled = resurrectSelectionIfNeeded() || pageScroll(FOCUS_DOWN);
            } else if (KeyEventCompat.hasModifiers(event, KeyEvent.META_ALT_ON)) {
                handled = resurrectSelectionIfNeeded() || fullScroll(FOCUS_DOWN);
            }
            break;

        case KeyEvent.KEYCODE_MOVE_HOME:
            if (KeyEventCompat.hasNoModifiers(event)) {
                handled = resurrectSelectionIfNeeded() || fullScroll(FOCUS_UP);
            }
            break;

        case KeyEvent.KEYCODE_MOVE_END:
            if (KeyEventCompat.hasNoModifiers(event)) {
                handled = resurrectSelectionIfNeeded() || fullScroll(FOCUS_DOWN);
            }
            break;

        case KeyEvent.KEYCODE_TAB:
            // XXX Sometimes it is useful to be able to TAB through the items in
            //     a ListView sequentially.  Unfortunately this can create an
            //     asymmetry in TAB navigation order unless the list selection
            //     always reverts to the top or bottom when receiving TAB focus from
            //     another widget.  Leaving this behavior disabled for now but
            //     perhaps it should be configurable (and more comprehensive).
            if (false) {
                if (KeyEventCompat.hasNoModifiers(event)) {
                    handled = resurrectSelectionIfNeeded() || arrowScroll(FOCUS_DOWN);
                } else if (KeyEventCompat.hasModifiers(event, KeyEvent.META_SHIFT_ON)) {
                    handled = resurrectSelectionIfNeeded() || arrowScroll(FOCUS_UP);
                }
            }
            break;
        }
    }

    if (handled) {
        return true;
    }

    if (sendToTextFilter(keyCode, count, event)) {
        return true;
    }

    switch (action) {
    case KeyEvent.ACTION_DOWN:
        return super.onKeyDown(keyCode, event);

    case KeyEvent.ACTION_UP:
        return super.onKeyUp(keyCode, event);

    case KeyEvent.ACTION_MULTIPLE:
        return super.onKeyMultiple(keyCode, count, event);

    default: // shouldn't happen
        return false;
    }
}

From source file:com.tct.mail.ui.ConversationViewFragment.java

@Override
public boolean onKey(View view, int keyCode, KeyEvent keyEvent) {
    if (keyEvent.getAction() == KeyEvent.ACTION_DOWN) {
        mOriginalKeyedView = view;//from   ww  w  . j a v a 2  s.com
    }

    if (mOriginalKeyedView != null) {
        final int id = mOriginalKeyedView.getId();
        final boolean isActionUp = keyEvent.getAction() == KeyEvent.ACTION_UP;
        final boolean isLeft = keyCode == KeyEvent.KEYCODE_DPAD_LEFT;
        final boolean isRight = keyCode == KeyEvent.KEYCODE_DPAD_RIGHT;
        final boolean isUp = keyCode == KeyEvent.KEYCODE_DPAD_UP;
        final boolean isDown = keyCode == KeyEvent.KEYCODE_DPAD_DOWN;

        // First we run the event by the controller
        // We manually check if the view+direction combination should shift focus away from the
        // conversation view to the thread list in two-pane landscape mode.
        final boolean isTwoPaneLand = mNavigationController.isTwoPaneLandscape();
        final boolean navigateAway = mConversationContainer.shouldNavigateAway(id, isLeft, isTwoPaneLand);
        if (mNavigationController.onInterceptKeyFromCV(keyCode, keyEvent, navigateAway)) {
            return true;
        }

        // If controller didn't handle the event, check directional interception.
        if ((isLeft || isRight)
                && mConversationContainer.shouldInterceptLeftRightEvents(id, isLeft, isRight, isTwoPaneLand)) {
            return true;
        } else if (isUp || isDown) {
            // We don't do anything on up/down for overlay
            if (id == R.id.conversation_topmost_overlay) {
                return true;
            }

            // We manually handle up/down navigation through the overlay items because the
            // system's default isn't optimal for two-pane landscape since it's not a real list.
            final int position = mConversationContainer.getViewPosition(mOriginalKeyedView);
            final View next = mConversationContainer.getNextOverlayView(position, isDown);
            if (next != null) {
                if (isActionUp) {
                    next.requestFocus();

                    // Make sure that v is in view
                    final int[] coords = new int[2];
                    next.getLocationOnScreen(coords);
                    final int bottom = coords[1] + next.getHeight();
                    if (bottom > mMaxScreenHeight) {
                        mWebView.scrollBy(0, bottom - mMaxScreenHeight);
                    } else if (coords[1] < mTopOfVisibleScreen) {
                        mWebView.scrollBy(0, coords[1] - mTopOfVisibleScreen);
                    }
                }
                return true;
            } else {
                // Special case two end points
                // Start is marked as index 1 because we are currently not allowing focus on
                // conversation view header.
                if ((position == mConversationContainer.getOverlayCount() - 1 && isDown)
                        || (position == 1 && isUp)) {
                    mTopmostOverlay.requestFocus();
                    // Scroll to the the top if we hit the first item
                    if (isUp) {
                        mWebView.scrollTo(0, 0);
                    }
                    return true;
                }
            }
        }

        // Finally we handle the special keys
        if (keyCode == KeyEvent.KEYCODE_BACK && id != R.id.conversation_topmost_overlay) {
            if (isActionUp) {
                mTopmostOverlay.requestFocus();
            }
            //TS: wenggangjin 2014-11-21 EMAIL BUGFIX_845619 MOD_S
            //                return true;
            return false;
            //TS: wenggangjin 2014-11-21 EMAIL BUGFIX_845619 MOD_E
        } else if (keyCode == KeyEvent.KEYCODE_ENTER && id == R.id.conversation_topmost_overlay) {
            if (isActionUp) {
                mConversationContainer.focusFirstMessageHeader();
                mWebView.scrollTo(0, 0);
            }
            return true;
        }
    }
    return false;
}

From source file:com.zhongsou.souyue.ui.HListView.java

@TargetApi(11)
private boolean commonKey(int keyCode, int count, KeyEvent event) {
    if (mAdapter == null || !mIsAttached) {
        return false;
    }/*from w  ww.  ja  v a  2s.  c o m*/

    if (mDataChanged) {
        layoutChildren();
    }

    if (android.os.Build.VERSION.SDK_INT < 11) {
        return false;
    }

    boolean handled = false;
    int action = event.getAction();

    if (action != KeyEvent.ACTION_UP) {
        switch (keyCode) {
        case KeyEvent.KEYCODE_DPAD_UP:
            if (event.hasNoModifiers()) {
                handled = resurrectSelectionIfNeeded();
                if (!handled) {
                    while (count-- > 0) {
                        if (arrowScroll(FOCUS_UP)) {
                            handled = true;
                        } else {
                            break;
                        }
                    }
                }
            } else if (event.hasModifiers(KeyEvent.META_ALT_ON)) {
                handled = resurrectSelectionIfNeeded() || fullScroll(FOCUS_UP);
            }
            break;

        case KeyEvent.KEYCODE_DPAD_DOWN:
            if (event.hasNoModifiers()) {
                handled = resurrectSelectionIfNeeded();
                if (!handled) {
                    while (count-- > 0) {
                        if (arrowScroll(FOCUS_DOWN)) {
                            handled = true;
                        } else {
                            break;
                        }
                    }
                }
            } else if (event.hasModifiers(KeyEvent.META_ALT_ON)) {
                handled = resurrectSelectionIfNeeded() || fullScroll(FOCUS_DOWN);
            }
            break;

        case KeyEvent.KEYCODE_DPAD_LEFT:
            if (event.hasNoModifiers()) {
                handled = handleHorizontalFocusWithinListItem(View.FOCUS_LEFT);
            }
            break;

        case KeyEvent.KEYCODE_DPAD_RIGHT:
            if (event.hasNoModifiers()) {
                handled = handleHorizontalFocusWithinListItem(View.FOCUS_RIGHT);
            }
            break;

        case KeyEvent.KEYCODE_DPAD_CENTER:
        case KeyEvent.KEYCODE_ENTER:
            if (event.hasNoModifiers()) {
                handled = resurrectSelectionIfNeeded();
                if (!handled && event.getRepeatCount() == 0 && getChildCount() > 0) {
                    keyPressed();
                    handled = true;
                }
            }
            break;

        case KeyEvent.KEYCODE_SPACE:

            if (event.hasNoModifiers()) {
                handled = resurrectSelectionIfNeeded() || pageScroll(FOCUS_DOWN);
            } else if (event.hasModifiers(KeyEvent.META_SHIFT_ON)) {
                handled = resurrectSelectionIfNeeded() || pageScroll(FOCUS_UP);
            }
            handled = true;
            break;

        case KeyEvent.KEYCODE_PAGE_UP:
            if (event.hasNoModifiers()) {
                handled = resurrectSelectionIfNeeded() || pageScroll(FOCUS_UP);
            } else if (event.hasModifiers(KeyEvent.META_ALT_ON)) {
                handled = resurrectSelectionIfNeeded() || fullScroll(FOCUS_UP);
            }
            break;

        case KeyEvent.KEYCODE_PAGE_DOWN:
            if (event.hasNoModifiers()) {
                handled = resurrectSelectionIfNeeded() || pageScroll(FOCUS_DOWN);
            } else if (event.hasModifiers(KeyEvent.META_ALT_ON)) {
                handled = resurrectSelectionIfNeeded() || fullScroll(FOCUS_DOWN);
            }
            break;

        case KeyEvent.KEYCODE_MOVE_HOME:
            if (event.hasNoModifiers()) {
                handled = resurrectSelectionIfNeeded() || fullScroll(FOCUS_UP);
            }
            break;

        case KeyEvent.KEYCODE_MOVE_END:
            if (event.hasNoModifiers()) {
                handled = resurrectSelectionIfNeeded() || fullScroll(FOCUS_DOWN);
            }
            break;

        case KeyEvent.KEYCODE_TAB:
            break;
        }
    }

    if (handled) {
        return true;
    }

    switch (action) {
    case KeyEvent.ACTION_DOWN:
        return super.onKeyDown(keyCode, event);

    case KeyEvent.ACTION_UP:
        return super.onKeyUp(keyCode, event);

    case KeyEvent.ACTION_MULTIPLE:
        return super.onKeyMultiple(keyCode, count, event);

    default: // shouldn't happen
        return false;
    }
}