Example usage for android.view KeyEvent KEYCODE_DPAD_UP

List of usage examples for android.view KeyEvent KEYCODE_DPAD_UP

Introduction

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

Prototype

int KEYCODE_DPAD_UP

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

Click Source Link

Document

Key code constant: Directional Pad Up key.

Usage

From source file:cn.androidy.materialdesignsample.ryanharterviewpager.ViewPager.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:
            if (isOrientationHorizontal())
                handled = arrowScroll(FOCUS_LEFT);
            break;
        case KeyEvent.KEYCODE_DPAD_RIGHT:
            if (isOrientationHorizontal())
                handled = arrowScroll(FOCUS_RIGHT);
            break;
        case KeyEvent.KEYCODE_DPAD_UP:
            if (!isOrientationHorizontal())
                handled = arrowScroll(FOCUS_UP);
            break;
        case KeyEvent.KEYCODE_DPAD_DOWN:
            if (!isOrientationHorizontal())
                handled = arrowScroll(FOCUS_DOWN);
            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.guide.ViewPager.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 w w .j a va 2  s . co  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:
            if (isOrientationHorizontal())
                handled = arrowScroll(FOCUS_LEFT);
            break;
        case KeyEvent.KEYCODE_DPAD_RIGHT:
            if (isOrientationHorizontal())
                handled = arrowScroll(FOCUS_RIGHT);
            break;
        case KeyEvent.KEYCODE_DPAD_UP:
            if (!isOrientationHorizontal())
                handled = arrowScroll(FOCUS_UP);
            break;
        case KeyEvent.KEYCODE_DPAD_DOWN:
            if (!isOrientationHorizontal())
                handled = arrowScroll(FOCUS_DOWN);
            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.glview.widget.AbsListView.java

/**
 * Sends a key to the text filter window
 *
 * @param keyCode The keycode for the event
 * @param event The actual key event/* ww w.j  a  v  a2 s .c om*/
 *
 * @return True if the text filter handled the event, false otherwise.
 */
boolean sendToTextFilter(int keyCode, int count, KeyEvent event) {
    if (!acceptFilter()) {
        return false;
    }

    boolean handled = false;
    boolean okToSend = true;
    switch (keyCode) {
    case KeyEvent.KEYCODE_DPAD_UP:
    case KeyEvent.KEYCODE_DPAD_DOWN:
    case KeyEvent.KEYCODE_DPAD_LEFT:
    case KeyEvent.KEYCODE_DPAD_RIGHT:
    case KeyEvent.KEYCODE_DPAD_CENTER:
    case KeyEvent.KEYCODE_ENTER:
        okToSend = false;
        break;
    case KeyEvent.KEYCODE_BACK:
        okToSend = false;
        break;
    case KeyEvent.KEYCODE_SPACE:
        // Only send spaces once we are filtered
        okToSend = mFiltered;
        break;
    }

    if (okToSend) {

        KeyEvent forwardEvent = event;
        if (forwardEvent.getRepeatCount() > 0) {
            forwardEvent = KeyEvent.changeTimeRepeat(event, event.getEventTime(), 0);
        }

        int action = event.getAction();
        switch (action) {
        case KeyEvent.ACTION_DOWN:
            break;

        case KeyEvent.ACTION_UP:
            break;

        case KeyEvent.ACTION_MULTIPLE:
            break;
        }
    }
    return handled;
}

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

/**
 * Sends a key to the text filter window
 *
 * @param keyCode The keycode for the event
 * @param event The actual key event//w ww  . j a v  a 2 s  .  c  o  m
 *
 * @return True if the text filter handled the event, false otherwise.
 */
boolean sendToTextFilter(int keyCode, int count, KeyEvent event) {
    if (!acceptFilter()) {
        return false;
    }

    boolean handled = false;
    boolean okToSend = true;
    switch (keyCode) {
    case KeyEvent.KEYCODE_DPAD_UP:
    case KeyEvent.KEYCODE_DPAD_DOWN:
    case KeyEvent.KEYCODE_DPAD_LEFT:
    case KeyEvent.KEYCODE_DPAD_RIGHT:
    case KeyEvent.KEYCODE_DPAD_CENTER:
    case KeyEvent.KEYCODE_ENTER:
        okToSend = false;
        break;
    case KeyEvent.KEYCODE_BACK:
        if (mFiltered && mPopup != null && mPopup.isShowing()) {
            if (event.getAction() == KeyEvent.ACTION_DOWN && event.getRepeatCount() == 0) {
                KeyEvent.DispatcherState state = getKeyDispatcherState();
                if (state != null) {
                    state.startTracking(event, this);
                }
                handled = true;
            } else if (event.getAction() == KeyEvent.ACTION_UP && event.isTracking() && !event.isCanceled()) {
                handled = true;
                mTextFilter.setText("");
            }
        }
        okToSend = false;
        break;
    case KeyEvent.KEYCODE_SPACE:
        // Only send spaces once we are filtered
        okToSend = mFiltered;
        break;
    }

    if (okToSend) {
        createTextFilter(true);

        KeyEvent forwardEvent = event;
        if (forwardEvent.getRepeatCount() > 0) {
            forwardEvent = KeyEvent.changeTimeRepeat(event, event.getEventTime(), 0);
        }

        int action = event.getAction();
        switch (action) {
        case KeyEvent.ACTION_DOWN:
            handled = mTextFilter.onKeyDown(keyCode, forwardEvent);
            break;

        case KeyEvent.ACTION_UP:
            handled = mTextFilter.onKeyUp(keyCode, forwardEvent);
            break;

        case KeyEvent.ACTION_MULTIPLE:
            handled = mTextFilter.onKeyMultiple(keyCode, count, event);
            break;
        }
    }
    return handled;
}