Example usage for android.view KeyEvent KEYCODE_DPAD_RIGHT

List of usage examples for android.view KeyEvent KEYCODE_DPAD_RIGHT

Introduction

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

Prototype

int KEYCODE_DPAD_RIGHT

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

Click Source Link

Document

Key code constant: Directional Pad Right key.

Usage

From source file:org.mariotaku.harmony.activity.MusicPlaybackActivity.java

@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {

    switch (keyCode) {
    case KeyEvent.KEYCODE_DPAD_LEFT:
        if (!useDpadMusicControl()) {
            break;
        }/*ww  w .  ja v a  2  s .  c o m*/
        if (mService != null) {
            if (!mSeeking && mStartSeekPos >= 0) {
                mPlayPauseButton.requestFocus();
                if (mStartSeekPos < 1000) {
                    mService.prev();
                } else {
                    mService.seek(0);
                }
            } else {
                scanBackward(-1, event.getEventTime() - event.getDownTime());
                mPlayPauseButton.requestFocus();
                mStartSeekPos = -1;
            }
        }
        mSeeking = false;
        mPosOverride = -1;
        return true;
    case KeyEvent.KEYCODE_DPAD_RIGHT:
        if (!useDpadMusicControl()) {
            break;
        }
        if (mService != null) {
            if (!mSeeking && mStartSeekPos >= 0) {
                mPlayPauseButton.requestFocus();
                mService.next();
            } else {
                scanForward(-1, event.getEventTime() - event.getDownTime());
                mPlayPauseButton.requestFocus();
                mStartSeekPos = -1;
            }
        }
        mSeeking = false;
        mPosOverride = -1;
        return true;
    }
    return super.onKeyUp(keyCode, event);
}

From source file:com.googlecode.eyesfree.brailleback.BrailleIME.java

public boolean moveCursor(int direction, int granularity) {
    if (mCurrentText == null) {
        return false;
    }/*from  w  w w  .j  a  v  a2 s.  c  om*/
    switch (granularity) {
    case AccessibilityNodeInfoCompat.MOVEMENT_GRANULARITY_CHARACTER:
        int keyCode = (direction == DIRECTION_BACKWARD) ? KeyEvent.KEYCODE_DPAD_LEFT
                : KeyEvent.KEYCODE_DPAD_RIGHT;
        return sendAndroidKey(keyCode);
    case AccessibilityNodeInfoCompat.MOVEMENT_GRANULARITY_PARAGRAPH:
        if (!isMultiLineField()) {
            return false;
        }
        int newPos = (direction == DIRECTION_BACKWARD) ? findParagraphBreakBackward()
                : findParagraphBreakForward();
        // newPos == the length means having the insertion point after
        // the last character, so the below comparison is correct.
        if (newPos < 0 || newPos > mCurrentText.length()) {
            return false;
        }
        return setCursor(getCurrentInputConnection(), newPos);
    }
    return false;
}

From source file:br.com.carlosrafaelgn.fplay.ActivityBrowserRadio.java

@Override
public boolean onBgListViewKeyDown(BgListView bgListView, int keyCode, KeyEvent event) {
    int p;/*  w  ww.  j  a  v  a 2 s.c  o m*/
    switch (keyCode) {
    case KeyEvent.KEYCODE_DPAD_LEFT:
        if (btnSearch.getVisibility() == View.VISIBLE)
            btnSearch.requestFocus();
        else
            btnGoBack.requestFocus();
        return true;
    case KeyEvent.KEYCODE_DPAD_RIGHT:
        btnGoBackToPlayer.requestFocus();
        return true;
    case KeyEvent.KEYCODE_ENTER:
    case KeyEvent.KEYCODE_DPAD_CENTER:
    case KeyEvent.KEYCODE_0:
    case KeyEvent.KEYCODE_SPACE:
        p = radioStationList.getSelection();
        if (p >= 0)
            processItemClick(p);
        return true;
    }
    return false;
}

From source file:info.guardianproject.otr.app.im.app.ContactListActivity.java

private static boolean isReadable(int keyCode, KeyEvent event) {
    if (KeyEvent.isModifierKey(keyCode) || event.isSystem()) {
        return false;
    }//  www. jav  a2s . co  m

    switch (keyCode) {
    case KeyEvent.KEYCODE_DPAD_CENTER:
    case KeyEvent.KEYCODE_DPAD_DOWN:
    case KeyEvent.KEYCODE_DPAD_LEFT:
    case KeyEvent.KEYCODE_DPAD_RIGHT:
    case KeyEvent.KEYCODE_DPAD_UP:
    case KeyEvent.KEYCODE_ENTER:
        return false;
    }

    return true;
}

From source file:org.yammp.app.MusicPlaybackActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {

    int repcnt = event.getRepeatCount();

    switch (keyCode) {

    case KeyEvent.KEYCODE_DPAD_LEFT:
        if (!useDpadMusicControl()) {
            break;
        }/* w  ww.  j  a v  a  2s  .  co m*/
        if (!mPrevButton.hasFocus()) {
            mPrevButton.requestFocus();
        }
        scanBackward(repcnt, event.getEventTime() - event.getDownTime());
        return true;
    case KeyEvent.KEYCODE_DPAD_RIGHT:
        if (!useDpadMusicControl()) {
            break;
        }
        if (!mNextButton.hasFocus()) {
            mNextButton.requestFocus();
        }
        scanForward(repcnt, event.getEventTime() - event.getDownTime());
        return true;

    // case KeyEvent.KEYCODE_R:
    // toggleRepeat();
    // return true;
    //
    // case KeyEvent.KEYCODE_S:
    // toggleShuffle();
    // return true;

    case KeyEvent.KEYCODE_N:
        if (mService != null) {
            try {
                mService.next();
                return true;
            } catch (RemoteException e) {
                e.printStackTrace();
            }
        } else
            return false;

    case KeyEvent.KEYCODE_P:
        if (mService != null) {
            try {
                mService.prev();
                return true;
            } catch (RemoteException e) {
                e.printStackTrace();
            }
        } else
            return false;

    case KeyEvent.KEYCODE_DPAD_CENTER:
    case KeyEvent.KEYCODE_SPACE:
        doPauseResume();
        return true;
    }
    return super.onKeyDown(keyCode, event);
}

From source file:org.mozilla.gecko.AwesomeBar.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    // This method is called only if the key event was not handled
    // by any of the views, which usually means the edit box lost focus
    if (keyCode == KeyEvent.KEYCODE_BACK || keyCode == KeyEvent.KEYCODE_MENU
            || keyCode == KeyEvent.KEYCODE_SEARCH || keyCode == KeyEvent.KEYCODE_DPAD_UP
            || keyCode == KeyEvent.KEYCODE_DPAD_DOWN || keyCode == KeyEvent.KEYCODE_DPAD_LEFT
            || keyCode == KeyEvent.KEYCODE_DPAD_RIGHT || keyCode == KeyEvent.KEYCODE_DPAD_CENTER
            || keyCode == KeyEvent.KEYCODE_DEL || keyCode == KeyEvent.KEYCODE_VOLUME_UP
            || keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
        return super.onKeyDown(keyCode, event);
    } else {//from   ww w .jav  a2 s.com
        int selStart = -1;
        int selEnd = -1;
        if (mText.hasSelection()) {
            selStart = mText.getSelectionStart();
            selEnd = mText.getSelectionEnd();
        }

        // Return focus to the edit box, and dispatch the event to it
        mText.requestFocusFromTouch();

        if (selStart >= 0) {
            // Restore the selection, which gets lost due to the focus switch
            mText.setSelection(selStart, selEnd);
        }

        mText.dispatchKeyEvent(event);
        return true;
    }
}

From source file:uk.org.downiesoft.slideshow.SlidesFragment.java

/**
 * Called by parent activity to handle cursor key events.
 * @param keyCode The keycode associated with the key pressed.
 * @return true if the keycode was consumed.
 *//*from   w w  w.j a  v a 2 s.c  o  m*/
public boolean onKeyUp(int keyCode) {
    switch (keyCode) {
    case KeyEvent.KEYCODE_DPAD_LEFT:
        prevImage(1);
        return true;
    case KeyEvent.KEYCODE_DPAD_RIGHT:
    case KeyEvent.KEYCODE_SPACE:
        nextImage(-1);
        return true;
    case KeyEvent.KEYCODE_DPAD_UP:
        mUiHider.hideUi();
        return true;
    case KeyEvent.KEYCODE_DPAD_DOWN:
        mUiHider.showUi(false);
        return true;
    }
    return false;
}

From source file:android.support.v17.leanback.app.PlaybackSupportFragment.java

private boolean onInterceptInputEvent(InputEvent event) {
    final boolean controlsHidden = !mControlVisible;
    if (DEBUG)/*from ww  w.j  av  a  2  s  .co m*/
        Log.v(TAG, "onInterceptInputEvent hidden " + controlsHidden + " " + event);
    boolean consumeEvent = false;
    int keyCode = KeyEvent.KEYCODE_UNKNOWN;
    int keyAction = 0;

    if (event instanceof KeyEvent) {
        keyCode = ((KeyEvent) event).getKeyCode();
        keyAction = ((KeyEvent) event).getAction();
        if (mInputEventHandler != null) {
            consumeEvent = mInputEventHandler.onKey(getView(), keyCode, (KeyEvent) event);
        }
    }

    switch (keyCode) {
    case KeyEvent.KEYCODE_DPAD_CENTER:
    case KeyEvent.KEYCODE_DPAD_DOWN:
    case KeyEvent.KEYCODE_DPAD_UP:
    case KeyEvent.KEYCODE_DPAD_LEFT:
    case KeyEvent.KEYCODE_DPAD_RIGHT:
        // Event may be consumed; regardless, if controls are hidden then these keys will
        // bring up the controls.
        if (controlsHidden) {
            consumeEvent = true;
        }
        if (keyAction == KeyEvent.ACTION_DOWN) {
            tickle();
        }
        break;
    case KeyEvent.KEYCODE_BACK:
    case KeyEvent.KEYCODE_ESCAPE:
        if (mInSeek) {
            // when in seek, the SeekUi will handle the BACK.
            return false;
        }
        // If controls are not hidden, back will be consumed to fade
        // them out (even if the key was consumed by the handler).
        if (!controlsHidden) {
            consumeEvent = true;

            if (((KeyEvent) event).getAction() == KeyEvent.ACTION_UP) {
                hideControlsOverlay(true);
            }
        }
        break;
    default:
        if (consumeEvent) {
            if (keyAction == KeyEvent.ACTION_DOWN) {
                tickle();
            }
        }
    }
    return consumeEvent;
}

From source file:com.hippo.widget.BothScrollView.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 ww .ja  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) {
    mTempRect.setEmpty();

    if (!canScrollHorizontally()) {
        if (isFocused() && event.getKeyCode() != KeyEvent.KEYCODE_BACK) {
            View currentFocused = findFocus();
            if (currentFocused == this) {
                currentFocused = null;
            }
            View nextFocused = FocusFinder.getInstance().findNextFocus(this, currentFocused, View.FOCUS_RIGHT);
            return nextFocused != null && nextFocused != this && nextFocused.requestFocus(View.FOCUS_RIGHT);
        }
        return false;
    }

    if (!canScrollVertically()) {
        if (isFocused() && event.getKeyCode() != KeyEvent.KEYCODE_BACK) {
            View currentFocused = findFocus();
            if (currentFocused == this) {
                currentFocused = null;
            }
            View nextFocused = FocusFinder.getInstance().findNextFocus(this, currentFocused, View.FOCUS_DOWN);
            return nextFocused != null && nextFocused != this && nextFocused.requestFocus(View.FOCUS_DOWN);
        }
        return false;
    }

    boolean handled = false;
    if (event.getAction() == KeyEvent.ACTION_DOWN) {
        switch (event.getKeyCode()) {
        case KeyEvent.KEYCODE_DPAD_LEFT:
            if (!event.isAltPressed()) {
                handled = arrowScrollHorizontally(View.FOCUS_LEFT);
            } else {
                handled = fullScroll(View.FOCUS_LEFT);
            }
            break;
        case KeyEvent.KEYCODE_DPAD_RIGHT:
            if (!event.isAltPressed()) {
                handled = arrowScrollHorizontally(View.FOCUS_RIGHT);
            } else {
                handled = fullScroll(View.FOCUS_RIGHT);
            }
            break;
        case KeyEvent.KEYCODE_DPAD_UP:
            if (!event.isAltPressed()) {
                handled = arrowScrollVertically(View.FOCUS_UP);
            } else {
                handled = fullScroll(View.FOCUS_UP);
            }
            break;
        case KeyEvent.KEYCODE_DPAD_DOWN:
            if (!event.isAltPressed()) {
                handled = arrowScrollVertically(View.FOCUS_DOWN);
            } else {
                handled = fullScroll(View.FOCUS_DOWN);
            }
            break;
        case KeyEvent.KEYCODE_SPACE:
            if (event.isCtrlPressed()) {
                pageScroll(event.isShiftPressed() ? View.FOCUS_LEFT : View.FOCUS_RIGHT);
            } else {
                pageScroll(event.isShiftPressed() ? View.FOCUS_UP : View.FOCUS_DOWN);
            }
            break;
        }
    }

    return handled;
}