Example usage for android.view KeyEvent KEYCODE_DPAD_LEFT

List of usage examples for android.view KeyEvent KEYCODE_DPAD_LEFT

Introduction

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

Prototype

int KEYCODE_DPAD_LEFT

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

Click Source Link

Document

Key code constant: Directional Pad Left key.

Usage

From source file:com.aujur.ebookreader.activity.ReadingFragment.java

public boolean dispatchKeyEvent(KeyEvent event) {

    int action = event.getAction();
    int keyCode = event.getKeyCode();

    LOG.debug("Got key event: " + keyCode + " with action " + action);

    if (searchMenuItem != null && searchMenuItem.isActionViewExpanded()) {
        boolean result = searchMenuItem.getActionView().dispatchKeyEvent(event);

        if (result) {
            return true;
        }//w w w.  jav a  2s . c  o m
    }

    final int KEYCODE_NOOK_TOUCH_BUTTON_LEFT_TOP = 92;
    final int KEYCODE_NOOK_TOUCH_BUTTON_LEFT_BOTTOM = 93;
    final int KEYCODE_NOOK_TOUCH_BUTTON_RIGHT_TOP = 94;
    final int KEYCODE_NOOK_TOUCH_BUTTON_RIGHT_BOTTOM = 95;

    boolean nook_touch_up_press = false;

    if (isAnimating() && action == KeyEvent.ACTION_DOWN) {
        stopAnimating();
        return true;
    }

    /*
     * Tricky bit of code here: if we are NOT running TTS, we want to be
     * able to start it using the play/pause button.
     * 
     * When we ARE running TTS, we'll get every media event twice: once
     * through the receiver and once here if focused.
     * 
     * So, we only try to read media events here if tts is running.
     */
    if (!ttsIsRunning() && dispatchMediaKeyEvent(event)) {
        return true;
    }

    LOG.debug("Key event is NOT a media key event.");

    switch (keyCode) {

    case KeyEvent.KEYCODE_VOLUME_DOWN:
    case KeyEvent.KEYCODE_VOLUME_UP:
        return handleVolumeButtonEvent(event);

    case KeyEvent.KEYCODE_DPAD_RIGHT:
        if (action == KeyEvent.ACTION_DOWN) {
            pageDown(Orientation.HORIZONTAL);
        }

        return true;

    case KeyEvent.KEYCODE_DPAD_LEFT:
        if (action == KeyEvent.ACTION_DOWN) {
            pageUp(Orientation.HORIZONTAL);
        }

        return true;

    case KeyEvent.KEYCODE_BACK:
        if (action == KeyEvent.ACTION_DOWN) {

            if (titleBarLayout.getVisibility() == View.VISIBLE) {
                hideTitleBar();
                updateFromPrefs();
                return true;
            } else if (bookView.hasPrevPosition()) {
                bookView.goBackInHistory();
                return true;
            }
        }

        return false;

    case KEYCODE_NOOK_TOUCH_BUTTON_LEFT_TOP:
    case KEYCODE_NOOK_TOUCH_BUTTON_RIGHT_TOP:
        nook_touch_up_press = true;
    case KEYCODE_NOOK_TOUCH_BUTTON_LEFT_BOTTOM:
    case KEYCODE_NOOK_TOUCH_BUTTON_RIGHT_BOTTOM:
        if (!Configuration.IS_NOOK_TOUCH || action == KeyEvent.ACTION_UP)
            return false;
        if (nook_touch_up_press == config.isNookUpButtonForward())
            pageDown(Orientation.HORIZONTAL);
        else
            pageUp(Orientation.HORIZONTAL);
        return true;
    }

    LOG.debug("Not handling key event: returning false.");
    return false;
}

From source file:net.zorgblub.typhon.fragment.ReadingFragment.java

public boolean dispatchKeyEvent(KeyEvent event) {

    int action = event.getAction();
    int keyCode = event.getKeyCode();

    LOG.debug("Got key event: " + keyCode + " with action " + action);

    if (searchMenuItem != null && MenuItemCompat.isActionViewExpanded(searchMenuItem)) {
        boolean result = MenuItemCompat.getActionView(searchMenuItem).dispatchKeyEvent(event);

        if (result) {
            return true;
        }/* www  .  ja  v  a  2 s .c  o m*/
    }

    final int KEYCODE_NOOK_TOUCH_BUTTON_LEFT_TOP = 92;
    final int KEYCODE_NOOK_TOUCH_BUTTON_LEFT_BOTTOM = 93;
    final int KEYCODE_NOOK_TOUCH_BUTTON_RIGHT_TOP = 94;
    final int KEYCODE_NOOK_TOUCH_BUTTON_RIGHT_BOTTOM = 95;

    boolean nook_touch_up_press = false;

    if (isAnimating() && action == KeyEvent.ACTION_DOWN) {
        stopAnimating();
        return true;
    }

    /*
       * Tricky bit of code here: if we are NOT running TTS,
     * we want to be able to start it using the play/pause button.
     *
     * When we ARE running TTS, we'll get every media event twice:
     * once through the receiver and once here if focused.
     *
     * So, we only try to read media events here if tts is running.
     */
    if (!ttsIsRunning() && dispatchMediaKeyEvent(event)) {
        return true;
    }

    LOG.debug("Key event is NOT a media key event.");

    switch (keyCode) {

    case KeyEvent.KEYCODE_VOLUME_DOWN:
    case KeyEvent.KEYCODE_VOLUME_UP:
        return handleVolumeButtonEvent(event);

    case KeyEvent.KEYCODE_DPAD_RIGHT:
        if (action == KeyEvent.ACTION_DOWN) {
            pageDown(Orientation.HORIZONTAL);
        }

        return true;

    case KeyEvent.KEYCODE_DPAD_LEFT:
        if (action == KeyEvent.ACTION_DOWN) {
            pageUp(Orientation.HORIZONTAL);
        }

        return true;

    case KeyEvent.KEYCODE_BACK:
        if (action == KeyEvent.ACTION_DOWN) {

            if (titleBarLayout.getVisibility() == View.VISIBLE) {
                hideTitleBar();
                updateFromPrefs();
                return true;
            } else if (bookView.hasPrevPosition()) {
                bookView.goBackInHistory();
                return true;
            }
        }

        return false;

    case KEYCODE_NOOK_TOUCH_BUTTON_LEFT_TOP:
    case KEYCODE_NOOK_TOUCH_BUTTON_RIGHT_TOP:
        nook_touch_up_press = true;
    case KEYCODE_NOOK_TOUCH_BUTTON_LEFT_BOTTOM:
    case KEYCODE_NOOK_TOUCH_BUTTON_RIGHT_BOTTOM:
        if (action == KeyEvent.ACTION_UP)
            return false;
        if (nook_touch_up_press == config.isNookUpButtonForward())
            pageDown(Orientation.HORIZONTAL);
        else
            pageUp(Orientation.HORIZONTAL);
        return true;
    }

    LOG.debug("Not handling key event: returning false.");
    return false;
}

From source file:com.chenglong.muscle.ui.LazyViewPager.java

/**
 * You can call this function yourself to have the scroll view perform
 * scrolling from a key event, just as if the event had been dispatched to
 * it by the view hierarchy.//w w  w .  j a v  a 2  s .c o m
 *
 * @param event The key event to execute.
 * @return Return true if the event was handled, else false.
 */
public boolean executeKeyEvent(KeyEvent event) {
    boolean handled = false;
    if (event.getAction() == KeyEvent.ACTION_DOWN) {
        switch (event.getKeyCode()) {
        case KeyEvent.KEYCODE_DPAD_LEFT:
            handled = arrowScroll(FOCUS_LEFT);
            break;
        case KeyEvent.KEYCODE_DPAD_RIGHT:
            handled = arrowScroll(FOCUS_RIGHT);
            break;
        case KeyEvent.KEYCODE_TAB:
            if (Build.VERSION.SDK_INT >= 11) {
                // The focus finder had a bug handling FOCUS_FORWARD and
                // FOCUS_BACKWARD
                // before Android 3.0. Ignore the include_tab key on those
                // devices.
                if (KeyEventCompat.hasNoModifiers(event)) {
                    handled = arrowScroll(FOCUS_FORWARD);
                } else if (KeyEventCompat.hasModifiers(event, KeyEvent.META_SHIFT_ON)) {
                    handled = arrowScroll(FOCUS_BACKWARD);
                }
            }
            break;
        }
    }
    return handled;
}

From source file:beichen.douban.ui.view.LazyViewPager.java

/**
 * You can call this function yourself to have the scroll view perform
 * scrolling from a key event, just as if the event had been dispatched to
 * it by the view hierarchy.//w  w  w .  ja  v  a 2 s .c o  m
 * 
 * @param event
 *            The key event to execute.
 * @return Return true if the event was handled, else false.
 */
public boolean executeKeyEvent(KeyEvent event) {
    boolean handled = false;
    if (event.getAction() == KeyEvent.ACTION_DOWN) {
        switch (event.getKeyCode()) {
        case KeyEvent.KEYCODE_DPAD_LEFT:
            handled = arrowScroll(FOCUS_LEFT);
            break;
        case KeyEvent.KEYCODE_DPAD_RIGHT:
            handled = arrowScroll(FOCUS_RIGHT);
            break;
        case KeyEvent.KEYCODE_TAB:
            if (Build.VERSION.SDK_INT >= 11) {
                // The focus finder had a bug handling FOCUS_FORWARD and
                // FOCUS_BACKWARD
                // before Android 3.0. Ignore the tab key on those
                // devices.
                if (KeyEventCompat.hasNoModifiers(event)) {
                    handled = arrowScroll(FOCUS_FORWARD);
                } else if (KeyEventCompat.hasModifiers(event, KeyEvent.META_SHIFT_ON)) {
                    handled = arrowScroll(FOCUS_BACKWARD);
                }
            }
            break;
        }
    }
    return handled;
}

From source file:cn.xiaowen.news.view.LazyViewPager.java

/**
 * You can call this function yourself to have the scroll view perform
 * scrolling from a key event, just as if the event had been dispatched to
 * it by the view hierarchy./*from  w  ww . j  a v  a 2  s.c o m*/
 * 
 * @param event
 *            The key event to execute.
 * @return Return true if the event was handled, else false.
 */
public boolean executeKeyEvent(KeyEvent event) {
    boolean handled = false;
    if (event.getAction() == KeyEvent.ACTION_DOWN) {
        switch (event.getKeyCode()) {
        case KeyEvent.KEYCODE_DPAD_LEFT:
            handled = arrowScroll(FOCUS_LEFT);
            break;
        case KeyEvent.KEYCODE_DPAD_RIGHT:
            handled = arrowScroll(FOCUS_RIGHT);
            break;
        case KeyEvent.KEYCODE_TAB:
            if (Build.VERSION.SDK_INT >= 11) {
                // The focus finder had a bug handling FOCUS_FORWARD and
                // FOCUS_BACKWARD
                // before Android 3.0. Ignore the tab key on those devices.
                if (KeyEventCompat.hasNoModifiers(event)) {
                    handled = arrowScroll(FOCUS_FORWARD);
                } else if (KeyEventCompat.hasModifiers(event, KeyEvent.META_SHIFT_ON)) {
                    handled = arrowScroll(FOCUS_BACKWARD);
                }
            }
            break;
        }
    }
    return handled;
}

From source file:com.tandong.sa.sherlock.widget.SearchView.java

/**
 * React to the user typing while in the suggestions list. First, check for
 * action keys. If not handled, try refocusing regular characters into the
 * EditText.//from ww w  .  j  a  v  a2  s  .  com
 */
private boolean onSuggestionsKey(View v, int keyCode, KeyEvent event) {
    // guard against possible race conditions (late arrival after dismiss)
    if (mSearchable == null) {
        return false;
    }
    if (mSuggestionsAdapter == null) {
        return false;
    }
    if (event.getAction() == KeyEvent.ACTION_DOWN && KeyEventCompat.hasNoModifiers(event)) {
        // First, check for enter or search (both of which we'll treat as a
        // "click")
        if (keyCode == KeyEvent.KEYCODE_ENTER || keyCode == KeyEvent.KEYCODE_SEARCH
                || keyCode == KeyEvent.KEYCODE_TAB) {
            int position = mQueryTextView.getListSelection();
            return onItemClicked(position, KeyEvent.KEYCODE_UNKNOWN, null);
        }

        // Next, check for left/right moves, which we use to "return" the
        // user to the edit view
        if (keyCode == KeyEvent.KEYCODE_DPAD_LEFT || keyCode == KeyEvent.KEYCODE_DPAD_RIGHT) {
            // give "focus" to text editor, with cursor at the beginning if
            // left key, at end if right key
            // TODO: Reverse left/right for right-to-left languages, e.g.
            // Arabic
            int selPoint = (keyCode == KeyEvent.KEYCODE_DPAD_LEFT) ? 0 : mQueryTextView.length();
            mQueryTextView.setSelection(selPoint);
            mQueryTextView.setListSelection(0);
            mQueryTextView.clearListSelection();
            ensureImeVisible(mQueryTextView, true);

            return true;
        }

        // Next, check for an "up and out" move
        if (keyCode == KeyEvent.KEYCODE_DPAD_UP && 0 == mQueryTextView.getListSelection()) {
            // TODO: restoreUserQuery();
            // let ACTV complete the move
            return false;
        }

        // Next, check for an "action key"
        // TODO SearchableInfo.ActionKeyInfo actionKey =
        // mSearchable.findActionKey(keyCode);
        // TODO if ((actionKey != null)
        // TODO && ((actionKey.getSuggestActionMsg() != null) || (actionKey
        // TODO .getSuggestActionMsgColumn() != null))) {
        // TODO // launch suggestion using action key column
        // TODO int position = mQueryTextView.getListSelection();
        // TODO if (position != ListView.INVALID_POSITION) {
        // TODO Cursor c = mSuggestionsAdapter.getCursor();
        // TODO if (c.moveToPosition(position)) {
        // TODO final String actionMsg = getActionKeyMessage(c, actionKey);
        // TODO if (actionMsg != null && (actionMsg.length() > 0)) {
        // TODO return onItemClicked(position, keyCode, actionMsg);
        // TODO }
        // TODO }
        // TODO }
        // TODO }
    }
    return false;
}

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

private boolean commonKey(int keyCode, int count, KeyEvent event) {
        if (mAdapter == null) {
            return false;
        }/*from ww w  .  ja v  a2 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.tct.mail.ui.ConversationViewFragment.java

@Override
public boolean onKey(View view, int keyCode, KeyEvent keyEvent) {
    if (keyEvent.getAction() == KeyEvent.ACTION_DOWN) {
        mOriginalKeyedView = view;/*w  w w.jav a2  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.appunite.list.HorizontalListView.java

private boolean commonKey(int keyCode, int count, KeyEvent event) {
    if (mAdapter == null || !mIsAttached) {
        return false;
    }// w w w . ja  va 2  s .co 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 ww w  . 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;
    }
}