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:pl.pelotasplus.pongtv.PongFragment.java

@Override
public void onKeyDown(int keyCode, KeyEvent event) {
    PongView.Player player;/*ww  w.  j  a  v  a  2 s .  c  om*/

    if (event.getDeviceId() % 2 == 0) {
        player = PongView.Player.LEFT;
    } else {
        player = PongView.Player.RIGHT;
    }
    Log.e("tag", "keyCode: " + keyCode);

    if (keyCode == KeyEvent.KEYCODE_DPAD_UP || keyCode == KeyEvent.KEYCODE_DPAD_DOWN) {
        pongView.changePlayerPosition(PongView.Player.LEFT, keyCode);
    } else if (keyCode == 23) {
        pongView.changePlayerPosition(PongView.Player.RIGHT, KeyEvent.KEYCODE_DPAD_DOWN);
    } else if (keyCode == 62) {
        pongView.changePlayerPosition(PongView.Player.RIGHT, KeyEvent.KEYCODE_DPAD_UP);
    }
}

From source file:org.videolan.vlc.gui.JumpToTimeFragment.java

private void updateViews(int keyCode) {
    int delta = keyCode == KeyEvent.KEYCODE_DPAD_UP ? 1 : -1;
    int id = 0;//ww  w . ja v a  2  s. com
    if (mHours.hasFocus())
        id = mHours.getId();
    else if (mMinutes.hasFocus())
        id = mMinutes.getId();
    else if (mSeconds.hasFocus())
        id = mSeconds.getId();
    updateValue(delta, id);
}

From source file:com.google.mist.plot.MainActivity.java

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

    if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
        toggleRecording(RecordingType.POSITIVE);
        return true;
    }/*www  . j  ava2  s .  co m*/

    if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
        toggleRecording(RecordingType.NEGATIVE);
        return true;
    }

    /* To label magnet pulls with ground truth, connect with ADB and run command:
       $ input keyevent 66
       or from console, not inside adb shell,
       $ adb shell input keyevent 66
       or connect a bluetooth keyboard and hit "enter" key
     */
    if (mIsRecording && (keyCode == KeyEvent.KEYCODE_ENTER || keyCode == KeyEvent.KEYCODE_DPAD_UP
            || keyCode == KeyEvent.KEYCODE_DPAD_DOWN || keyCode == KeyEvent.KEYCODE_DPAD_LEFT
            || keyCode == KeyEvent.KEYCODE_DPAD_RIGHT)) {
        mVibrator.vibrate(30);
        int recordedLabel = 0;
        switch (keyCode) {
        case KeyEvent.KEYCODE_ENTER:
            recordedLabel = POSITIVE_LABEL;
            break;
        case KeyEvent.KEYCODE_DPAD_UP:
            recordedLabel = UP_LABEL;
            break;
        case KeyEvent.KEYCODE_DPAD_DOWN:
            recordedLabel = DOWN_LABEL;
            break;
        case KeyEvent.KEYCODE_DPAD_LEFT:
            recordedLabel = LEFT_LABEL;
            break;
        case KeyEvent.KEYCODE_DPAD_RIGHT:
            recordedLabel = RIGHT_LABEL;
            break;
        }
        long lastFiring = mSensorTime.get(mSensorTime.size() - 1);
        mPositivesTime.add(lastFiring);
        mPositivesData.add(recordedLabel);
    }

    return super.onKeyDown(keyCode, event);
}

From source file:com.commonsware.android.preso.decktastic.MainActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    switch (keyCode) {
    case KeyEvent.KEYCODE_SPACE:
    case KeyEvent.KEYCODE_DPAD_RIGHT:
    case KeyEvent.KEYCODE_DPAD_DOWN:
    case KeyEvent.KEYCODE_PAGE_DOWN:
    case KeyEvent.KEYCODE_MEDIA_NEXT:
        if (pager.canScrollHorizontally(1)) {
            pager.setCurrentItem(pager.getCurrentItem() + 1, true);
        }/*  ww w.  jav  a 2 s.com*/

        return (true);

    case KeyEvent.KEYCODE_DPAD_LEFT:
    case KeyEvent.KEYCODE_DPAD_UP:
    case KeyEvent.KEYCODE_PAGE_UP:
    case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
        if (pager.canScrollHorizontally(-1)) {
            pager.setCurrentItem(pager.getCurrentItem() - 1, true);
        }

        return (true);
    }

    return (super.onKeyDown(keyCode, event));
}

From source file:org.videolan.vlc.gui.dialogs.PickTimeFragment.java

@Override
public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
    if (event.getAction() != KeyEvent.ACTION_DOWN)
        return false;
    switch (keyCode) {
    case KeyEvent.KEYCODE_DPAD_UP:
    case KeyEvent.KEYCODE_DPAD_DOWN:
        updateViews(keyCode);/*www.j av a  2 s .  c o  m*/
        return true;
    }
    return false;
}

From source file:com.android.screenspeak.KeyboardSearchManager.java

@Override
public boolean onKeyEvent(KeyEvent event) {
    // Only handle single-key events here. The KeyComboManager will pass us combos.
    if (event.getModifiers() != 0 || !mNodeSearch.isActive()) {
        return false;
    }//from  w  w  w. j  a  v  a  2  s .  co  m

    if (event.getAction() == KeyEvent.ACTION_DOWN) {
        switch (event.getKeyCode()) {
        case KeyEvent.KEYCODE_ENTER:
            if (mHasNavigated || mNodeSearch.hasMatch()) {
                finishSearch();
                mContext.getCursorController().clickCurrent();
            } else {
                cancelSearch();
            }
            return true;
        case KeyEvent.KEYCODE_DEL:
            resetHintTime();
            final String queryText = mNodeSearch.getCurrentQuery();
            if (queryText.isEmpty()) {
                cancelSearch();
            } else {
                final String lastChar = queryText.substring(queryText.length() - 1);
                mNodeSearch.backspaceQueryText();
                mSpeechController.speak(mContext.getString(R.string.template_text_removed, lastChar),
                        SpeechController.QUEUE_MODE_FLUSH_ALL, FeedbackItem.FLAG_NO_HISTORY, null);
            }
            return true;
        case KeyEvent.KEYCODE_DPAD_UP:
            moveToEnd(NodeFocusFinder.SEARCH_BACKWARD);
            return true;
        case KeyEvent.KEYCODE_DPAD_LEFT:
            moveToNext(NodeFocusFinder.SEARCH_BACKWARD);
            return true;
        case KeyEvent.KEYCODE_DPAD_DOWN:
            moveToEnd(NodeFocusFinder.SEARCH_FORWARD);
            return true;
        case KeyEvent.KEYCODE_DPAD_RIGHT:
            moveToNext(NodeFocusFinder.SEARCH_FORWARD);
            return true;
        case KeyEvent.KEYCODE_SPACE:
            resetHintTime();
            if (mNodeSearch.tryAddQueryText(" ")) {
                mSpeechController.speak(mContext.getString(R.string.symbol_space),
                        SpeechController.QUEUE_MODE_FLUSH_ALL, FeedbackItem.FLAG_NO_HISTORY, null);
            } else {
                mContext.getFeedbackController().playAuditory(R.raw.complete);
            }
            return true;
        default:
            if (event.isPrintingKey()) {
                resetHintTime();
                final String key = String.valueOf(event.getDisplayLabel());
                if (mNodeSearch.tryAddQueryText(key)) {
                    mSpeechController.speak(key.toLowerCase(), SpeechController.QUEUE_MODE_FLUSH_ALL,
                            FeedbackItem.FLAG_NO_HISTORY, null);
                } else {
                    mContext.getFeedbackController().playAuditory(R.raw.complete);
                }
                return true;
            }
            break;
        }
    }

    return false;
}

From source file:org.videolan.vlc.gui.dialogs.PickTimeFragment.java

private void updateViews(int keyCode) {
    long delta = keyCode == KeyEvent.KEYCODE_DPAD_UP ? 1 : -1;
    int id = 0;/*from  w  ww .  j  a va 2s  .c  o m*/
    if (mMillis.hasFocus()) {
        id = mMillis.getId();
        delta = keyCode == KeyEvent.KEYCODE_DPAD_UP ? 50 : -50;
    } else if (mSeconds.hasFocus())
        id = mSeconds.getId();
    else if (mMinutes.hasFocus())
        id = mMinutes.getId();
    else if (mHours.hasFocus())
        id = mHours.getId();
    updateValue(delta, id);
}

From source file:com.vuze.android.remote.AndroidUtilsUI.java

public static boolean handleBrokenListViewScrolling(Activity a, int keyCode) {
    // Hack for FireTV 1st Gen (and possibly others):
    // sometimes scrolling up/down stops being processed by ListView,
    // even though there's more list to show.  Handle this manually
    // Dirty implemenation -- doesn't take into consideration disabled rows
    // or page-up/down/top/bottom key modifiers
    if (keyCode == KeyEvent.KEYCODE_DPAD_UP || keyCode == KeyEvent.KEYCODE_DPAD_DOWN) {
        ListView lv = null;//from www  . j  av  a 2s. co m

        View currentFocus = a.getCurrentFocus();
        if (currentFocus instanceof ListView) {
            lv = (ListView) currentFocus;
            if (lv.getChoiceMode() == ListView.CHOICE_MODE_SINGLE) {
                int position = lv.getSelectedItemPosition();
                if (keyCode == KeyEvent.KEYCODE_DPAD_UP) {
                    position--;
                } else if (keyCode == KeyEvent.KEYCODE_DPAD_DOWN) {
                    position++;
                }

                if (position > 0 && position < lv.getCount()) {
                    lv.setSelection(position);
                    return true;
                }
            }
        }

        //         // For RecyclerView, we just need to scroll the next item into
        //         // view, so that the super logic can find that the next down/up
        //         // item exists.
        //         // A PreCachingLayoutManager might also fix this problem
        //         if (currentFocus != null &&
        //               currentFocus.getParent() instanceof RecyclerView) {
        //            RecyclerView rv = (RecyclerView) currentFocus.getParent();
        //            RecyclerView.Adapter adapter = rv.getAdapter();
        //            if (adapter instanceof FlexibleRecyclerAdapter) {
        //               int position = ((FlexibleRecyclerAdapter) adapter)
        //                     .getSelectedPosition();
        //               if (position >= 0) {
        //                  if (keyCode == KeyEvent.KEYCODE_DPAD_UP) {
        //                     position--;
        //                  } else if (keyCode == KeyEvent.KEYCODE_DPAD_DOWN) {
        //                     position++;
        //                  }
        //
        //                  if (position >= 0 && position < adapter.getItemCount()) {
        //                     rv.scrollToPosition(position);
        //                     Log.d(TAG, "handleBrokenListViewScrolling: DPAD HANDLED ");
        //                     return false;
        //                  }
        //               }
        //            }
        //         }
    }

    return false;
}

From source file:com.lib.media.widget.seekbar.VerticalSeekBar.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (isEnabled()) {
        final boolean handled;
        int direction = 0;

        switch (keyCode) {
        case KeyEvent.KEYCODE_DPAD_DOWN:
            direction = (mRotationAngle == ROTATION_ANGLE_CW_90) ? 1 : -1;
            handled = true;//from w  ww  . j  av  a2  s.  c  o m
            break;
        case KeyEvent.KEYCODE_DPAD_UP:
            direction = (mRotationAngle == ROTATION_ANGLE_CW_270) ? 1 : -1;
            handled = true;
            break;
        case KeyEvent.KEYCODE_DPAD_LEFT:
        case KeyEvent.KEYCODE_DPAD_RIGHT:
            // move view focus to previous/next view
            return false;
        default:
            handled = false;
            break;
        }

        if (handled) {
            final int keyProgressIncrement = getKeyProgressIncrement();
            int progress = getProgress();

            progress += (direction * keyProgressIncrement);

            if (progress >= 0 && progress <= getMax()) {
                _setProgressFromUser(progress, true);
            }

            return true;
        }
    }

    return super.onKeyDown(keyCode, event);
}

From source file:com.anl.wxb.jieqi.view.VerticalSeekBar.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (isEnabled()) {
        final boolean handled;
        int direction = 0;

        switch (keyCode) {
        case KeyEvent.KEYCODE_DPAD_DOWN:
            direction = (mRotationAngle == ROTATION_ANGLE_CW_90) ? 1 : -1;
            handled = true;//from   ww  w . jav a2  s. co  m
            break;
        case KeyEvent.KEYCODE_DPAD_UP:
            direction = (mRotationAngle == ROTATION_ANGLE_CW_270) ? 1 : -1;
            handled = true;
            break;
        case KeyEvent.KEYCODE_DPAD_LEFT:
        case KeyEvent.KEYCODE_DPAD_RIGHT:
            handled = true;
            break;
        default:
            handled = false;
            break;
        }

        if (handled) {
            final int keyProgressIncrement = getKeyProgressIncrement();
            int progress = getProgress();

            progress += (direction * keyProgressIncrement);

            if (progress >= 0 && progress <= getMax()) {
                setProgress(progress - keyProgressIncrement, true);
            }

            return true;
        }
    }

    return super.onKeyDown(keyCode, event);
}