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:org.mariotaku.harmony.activity.MusicPlaybackActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (mService == null)
        return super.onKeyDown(keyCode, event);
    final int repcnt = event.getRepeatCount();

    switch (keyCode) {
    case KeyEvent.KEYCODE_DPAD_LEFT:
        if (!useDpadMusicControl()) {
            break;
        }//from ww  w  .j  a  va  2 s  . c  o 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: {
        doNext();
        return true;
    }
    case KeyEvent.KEYCODE_P: {
        doPrev();
        return true;
    }
    case KeyEvent.KEYCODE_DPAD_CENTER:
    case KeyEvent.KEYCODE_SPACE: {
        doPauseResume();
        return true;
    }
    }
    return super.onKeyDown(keyCode, event);
}

From source file:com.oakesville.mythling.MediaPagerActivity.java

@Override
public boolean dispatchKeyEvent(KeyEvent event) {
    if (event.getAction() == KeyEvent.ACTION_DOWN) {
        if (event.getKeyCode() == KeyEvent.KEYCODE_DPAD_DOWN) {
            if ((getCurrentFocus().getParent() instanceof View
                    && ((View) getCurrentFocus().getParent()).getId() == R.id.button_bar)
                    || getCurrentFocus().getId() == R.id.title_text) {
                findViewById(R.id.pager_position).requestFocus();
                return true;
            }/*from ww  w  . j  ava2s.c o  m*/
        } else if (event.getKeyCode() == KeyEvent.KEYCODE_DPAD_RIGHT) {
            if (getCurrentFocus().getId() == R.id.pager_position) {
                if (pager.getCurrentItem() < getListables().size() - 1) {
                    pager.setCurrentItem(pager.getCurrentItem() + 1);
                    positionBar.setProgress(pager.getCurrentItem());
                    return true;
                }
            }
        } else if (event.getKeyCode() == KeyEvent.KEYCODE_DPAD_LEFT) {
            if (getCurrentFocus().getId() == R.id.pager_position) {
                if (pager.getCurrentItem() > 0) {
                    pager.setCurrentItem(pager.getCurrentItem() - 1);
                    positionBar.setProgress(pager.getCurrentItem());
                    return true;
                }
            }
        } else if (event.getKeyCode() == KeyEvent.KEYCODE_MEDIA_FAST_FORWARD) {
            pager.setCurrentItem(getListables().size() - 1);
            positionBar.setProgress(getListables().size() - 1);
            return true;
        } else if (event.getKeyCode() == KeyEvent.KEYCODE_MEDIA_REWIND) {
            pager.setCurrentItem(0);
            positionBar.setProgress(0);
            return true;
        } else if (event.getKeyCode() == KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE
                || event.getKeyCode() == KeyEvent.KEYCODE_MEDIA_PLAY) {
            Listable listable = getListables().get(pager.getCurrentItem());
            if (listable instanceof Item) {
                playItem((Item) listable);
                return true;
            }
        }
    }
    return super.dispatchKeyEvent(event);
}

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;
        }//from w  ww  .  j  a va 2s. co 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.mstar.tv.tvplayer.philips.setting.SettingSliderFragment.java

public void updateView(String data, int dataPositon, boolean isPicShift) {
    firstSelect = TvSettingMenuActivity.firstSelectPositon;
    mIsPicShift = isPicShift;//from   w ww .  java2  s.  c o m
    if (firstSelect == SettingKarrays.SETTING_PHOTO) {
        if (mIsPicShift) {
            //???
            switch (dataPositon) {
            case 0:
                currentIndex = K_TvPictureManager.getInstance().K_getPCHPos();
                Log.v(TAG, "=========hpos===currentIndex=" + currentIndex);
                break;
            case 1:
                currentIndex = K_TvPictureManager.getInstance().K_getPCVPos();
                Log.v(TAG, "=========vpos===currentIndex=" + currentIndex);
                break;
            case 2:
                currentIndex = K_TvPictureManager.getInstance().K_getPCClock();
                Log.v(TAG, "=========clock===currentIndex=" + currentIndex);
                break;
            case 3:
                currentIndex = K_TvPictureManager.getInstance().K_getPCPhase();
                Log.v(TAG, "=========phase===currentIndex=" + currentIndex);
                break;

            default:
                break;
            }
        } else {
            switch (dataPositon) {
            case 1:
                currentIndex = K_TvPictureManager.getInstance().K_getVideoItem(K_Constants.PICTURE_CONTRAST);
                break;
            case 2:
                currentIndex = K_TvPictureManager.getInstance().K_getVideoItem(K_Constants.PICTURE_BRIGHTNESS);
                break;
            case 3:
                currentIndex = K_TvPictureManager.getInstance().K_getVideoItem(K_Constants.PICTURE_SATURATION);
                break;
            case 4:
                currentIndex = K_TvPictureManager.getInstance().K_getVideoItem(K_Constants.PICTURE_SHARPNESS);
                break;

            default:
                break;
            }
        }
    } else if (firstSelect == SettingKarrays.SETTING_SOUND) {
        switch (dataPositon) {
        case 1:
            currentIndex = K_TvAudioManager.getInstance().K_getBass();
            break;
        case 2:
            currentIndex = K_TvAudioManager.getInstance().K_getTreble();
            ;
            break;
        case 3:
            currentIndex = K_TvAudioManager.getInstance().K_getBalance();
            break;
        default:
            break;
        }
    } else if (firstSelect == SettingKarrays.SETTING_ECO) {
        switch (dataPositon) {
        case 1:
            currentIndex = K_SettingModel.getInstance().K_getAjustBacklightIndex(mCotext);
            break;
        default:
            break;
        }
    } else if (firstSelect == SettingKarrays.SETTING_TV) {
        switch (dataPositon) {
        case 4:
            currentIndex = getSleepModeProgressIndex();
            break;
        default:
            break;
        }
    }

    if (firstSelect == SettingKarrays.SETTING_TV && dataPositon == 4) {
        vseekbar_title.setText(data + mCotext.getResources().getString(R.string.minute));
        seekBar.setMax(240);
        cursor_top.setText(240 + "");
        cursor_center.setText(120 + "");
        cursor_button.setText("0");
    } else if (firstSelect == SettingKarrays.SETTING_SOUND && dataPositon == 3) {
        vseekbar_title.setText(data);
        seekBar.setMax(100);
        cursor_top.setText("R50");
        cursor_center.setText("0");
        cursor_button.setText("L50");
    } else {
        vseekbar_title.setText(data);
        seekBar.setMax(100);
        cursor_top.setText(100 + "");
        cursor_center.setText(50 + "");
        cursor_button.setText("0");
    }

    seekBar.setProgress(currentIndex);
    if (firstSelect == SettingKarrays.SETTING_SOUND && dataPositon == 3) {
        if (seekBar.getProgress() < 50) {
            progressVal.setText("L" + (50 - seekBar.getProgress()));
        } else if (seekBar.getProgress() == 50) {
            progressVal.setText("0");
        } else {
            progressVal.setText("R" + (seekBar.getProgress() - 50));
        }
    } else {
        progressVal.setText(String.valueOf(seekBar.getProgress()));
    }
    up_img.setBackgroundResource(R.drawable.slider_arrow_up_highlighted);
    down_img.setBackgroundResource(R.drawable.slider_arrow_down_highlighted);
    final int flag = dataPositon;
    seekBar.setOnKeyListener(new OnKeyListener() {

        @Override
        public boolean onKey(View arg0, int keyCode, KeyEvent keyevent) {
            if (keyevent.getAction() == KeyEvent.ACTION_DOWN) {
                switch (keyCode) {
                case KeyEvent.KEYCODE_DPAD_UP:

                    if (firstSelect == SettingKarrays.SETTING_SOUND && flag == 3) {
                        seekBar.incrementProgressBy(1);
                        if (seekBar.getProgress() < 50) {
                            progressVal.setText("L" + (50 - seekBar.getProgress()));
                        } else if (seekBar.getProgress() == 50) {
                            progressVal.setText("0");
                        } else {
                            progressVal.setText("R" + (seekBar.getProgress() - 50));
                        }
                    } else if (firstSelect == SettingKarrays.SETTING_TV && flag == 4) {

                        setSleepModeProgress(true);

                    } else {
                        seekBar.incrementProgressBy(1);
                        progressVal.setText(String.valueOf(seekBar.getProgress()));
                    }
                    up_img.setBackgroundResource(R.drawable.slider_arrow_up_pressed);
                    down_img.setBackgroundResource(R.drawable.slider_arrow_down_highlighted);
                    updateSeekbarData(flag, seekBar);
                    return true;
                case KeyEvent.KEYCODE_DPAD_DOWN:

                    if (firstSelect == SettingKarrays.SETTING_SOUND && flag == 3) {
                        seekBar.incrementProgressBy(-1);
                        if (seekBar.getProgress() < 50) {
                            progressVal.setText("L" + (50 - seekBar.getProgress()));
                        } else if (seekBar.getProgress() == 50) {
                            progressVal.setText("0");
                        } else {
                            progressVal.setText("R" + (seekBar.getProgress() - 50));
                        }
                    } else if (firstSelect == SettingKarrays.SETTING_TV && flag == 4) {

                        setSleepModeProgress(false);

                    } else {
                        seekBar.incrementProgressBy(-1);
                        progressVal.setText(String.valueOf(seekBar.getProgress()));
                    }
                    up_img.setBackgroundResource(R.drawable.slider_arrow_up_highlighted);
                    down_img.setBackgroundResource(R.drawable.slider_arrow_down_pressed);
                    updateSeekbarData(flag, seekBar);
                    return true;
                case KeyEvent.KEYCODE_DPAD_LEFT:
                    getActivity().onKeyDown(keyCode, keyevent);
                    return true;
                case KeyEvent.KEYCODE_DPAD_RIGHT:

                    return true;
                default:
                    break;
                }

            }
            return false;
        }

        private void setSleepModeProgress(boolean up) {
            int progress = 0;
            if (up) {
                switch (seekBar.getProgress()) {
                case 0:
                    sleepMode = K_Constants.SLEEP_TIME_10MIN;
                    progress = 10;
                    break;
                case 10:
                    sleepMode = K_Constants.SLEEP_TIME_20MIN;
                    progress = 20;
                    break;
                case 20:
                    sleepMode = K_Constants.SLEEP_TIME_30MIN;
                    progress = 30;
                    break;
                case 30:
                    sleepMode = K_Constants.SLEEP_TIME_60MIN;
                    progress = 60;
                    break;
                case 60:
                    sleepMode = K_Constants.SLEEP_TIME_90MIN;
                    progress = 90;
                    break;
                case 90:
                    sleepMode = K_Constants.SLEEP_TIME_120MIN;
                    progress = 120;
                    break;
                case 120:
                    sleepMode = K_Constants.SLEEP_TIME_180MIN;
                    progress = 180;
                    break;
                case 180:
                    sleepMode = K_Constants.SLEEP_TIME_240MIN;
                    progress = 240;
                    break;
                case 240:
                    return;

                default:
                    break;
                }
            } else {
                switch (seekBar.getProgress()) {
                case 240:
                    sleepMode = K_Constants.SLEEP_TIME_180MIN;
                    progress = 180;
                    break;
                case 180:
                    sleepMode = K_Constants.SLEEP_TIME_120MIN;
                    progress = 120;
                    break;
                case 120:
                    sleepMode = K_Constants.SLEEP_TIME_90MIN;
                    progress = 90;
                    break;
                case 90:
                    sleepMode = K_Constants.SLEEP_TIME_60MIN;
                    progress = 60;
                    break;
                case 60:
                    sleepMode = K_Constants.SLEEP_TIME_30MIN;
                    progress = 30;
                    break;
                case 30:
                    sleepMode = K_Constants.SLEEP_TIME_20MIN;
                    progress = 20;
                    break;
                case 20:
                    sleepMode = K_Constants.SLEEP_TIME_10MIN;
                    progress = 10;
                    break;
                case 10:
                    sleepMode = K_Constants.SLEEP_TIME_OFF;
                    progress = 0;
                    break;
                case 0:
                    return;

                default:
                    break;
                }
            }
            seekBar.setProgress(progress);
            progressVal.setText(String.valueOf(seekBar.getProgress()));

        }
    });
}

From source file:com.mstar.tv.tvplayer.philips.setting.SettingFirstFragment.java

public boolean onKeyDown(int keyCode, KeyEvent event) {
    int position = getSelectedItemPosition();
    switch (keyCode) {
    case KeyEvent.KEYCODE_DPAD_LEFT:
        break;/*from  w ww . j  a v a 2s .c o m*/
    case KeyEvent.KEYCODE_DPAD_RIGHT:
        if (TvSettingMenuActivity.firstSelectPositon == SettingKarrays.SETTING_ECO) {
            if (getSelectedItemPosition() != 2) {
                mCallback.onFirstSelectedData(dataArray, getSelectedItemPosition());
            }
        } else if (TvSettingMenuActivity.firstSelectPositon == SettingKarrays.SETTING_TV) {
            if (position != 0 && position != 6) {//yzh:5-->6
                mCallback.onFirstSelectedData(dataArray, getSelectedItemPosition());
            }
        } else if (TvSettingMenuActivity.firstSelectPositon == SettingKarrays.SETTING_CHANNEL) {
            if (position != 0 && position != 1) {
                mCallback.onFirstSelectedData(dataArray, getSelectedItemPosition());
            }
        } else {
            mCallback.onFirstSelectedData(dataArray, getSelectedItemPosition());
        }
        break;
    }
    return false;
}

From source file:com.vuze.android.remote.fragment.FilesFragment.java

public View onCreateView(android.view.LayoutInflater inflater, android.view.ViewGroup container,
        Bundle savedInstanceState) {/*from  w  w w . j  ava 2  s . com*/

    if (AndroidUtils.DEBUG) {
        Log.d(TAG, "onCreateview " + this);
    }

    View view = inflater.inflate(R.layout.frag_torrent_files, container, false);

    FragmentActivity activity = getActivity();

    progressBar = (ProgressBar) activity.findViewById(R.id.details_progress_bar);

    viewAreaToggleEditMode = view.findViewById(R.id.files_area_toggleditmode);
    tvScrollTitle = (TextView) view.findViewById(R.id.files_scrolltitle);

    btnEditMode = (CompoundButton) view.findViewById(R.id.files_editmode);
    if (btnEditMode != null) {
        btnEditMode.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                if (adapter == null) {
                    return;
                }
                adapter.setInEditMode(btnEditMode.isChecked());
            }
        });
    }

    final SwipeRefreshLayoutExtra swipeRefresh = (SwipeRefreshLayoutExtra) view
            .findViewById(R.id.swipe_container);
    if (swipeRefresh != null) {
        swipeRefresh.setExtraLayout(R.layout.swipe_layout_extra);
        swipeRefresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                if (sessionInfo == null) {
                    return;
                }
                showProgressBar();
                sessionInfo.executeRpc(new RpcExecuter() {
                    @Override
                    public void executeRpc(TransmissionRPC rpc) {
                        rpc.getTorrentFileInfo(TAG, torrentID, null, new TorrentListReceivedListener() {

                            @Override
                            public void rpcTorrentListReceived(String callID, List<?> addedTorrentMaps,
                                    List<?> removedTorrentIDs) {
                                AndroidUtils.runOnUIThread(FilesFragment.this, new Runnable() {
                                    @Override
                                    public void run() {
                                        swipeRefresh.setRefreshing(false);
                                    }
                                });
                            }
                        });
                    }
                });

            }
        });
        swipeRefresh.setOnExtraViewVisibilityChange(this);
    }

    listview = (RecyclerView) view.findViewById(R.id.files_list);
    listview.setLayoutManager(new PreCachingLayoutManager(getContext()));
    listview.setAdapter(adapter);

    listview.setOnKeyListener(new View.OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            {
                if (event.getAction() != KeyEvent.ACTION_DOWN) {
                    return false;
                }
                switch (keyCode) {
                case KeyEvent.KEYCODE_DPAD_RIGHT: {
                    // expand
                    int i = adapter.getSelectedPosition();
                    FilesAdapterDisplayObject item = adapter.getItem(i);
                    if (item instanceof FilesAdapterDisplayFolder) {
                        if (!((FilesAdapterDisplayFolder) item).expand) {
                            ((FilesAdapterDisplayFolder) item).expand = true;
                            adapter.getFilter().filter("");
                            return true;
                        }
                    }
                    break;
                }

                case KeyEvent.KEYCODE_DPAD_LEFT: {
                    // collapse
                    int i = adapter.getSelectedPosition();
                    FilesAdapterDisplayObject item = adapter.getItem(i);
                    if (item instanceof FilesAdapterDisplayFolder) {
                        if (((FilesAdapterDisplayFolder) item).expand) {
                            ((FilesAdapterDisplayFolder) item).expand = false;
                            adapter.getFilter().filter("");
                            return true;
                        }
                    }
                    break;
                }

                case KeyEvent.KEYCODE_MEDIA_PLAY:
                case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE: {
                    launchOrStreamFile();
                    return true;
                }
                }

                return false;
            }
        }
    });

    listview.setOnScrollListener(new RecyclerView.OnScrollListener() {
        int firstVisibleItem = 0;

        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            super.onScrolled(recyclerView, dx, dy);
            LinearLayoutManager lm = (LinearLayoutManager) listview.getLayoutManager();
            int firstVisibleItem = lm.findFirstCompletelyVisibleItemPosition();
            if (firstVisibleItem != this.firstVisibleItem) {
                this.firstVisibleItem = firstVisibleItem;
                FilesAdapterDisplayObject itemAtPosition = adapter.getItem(firstVisibleItem);
                //               Log.d(TAG, "itemAt" + firstVisibleItem + " is " + itemAtPosition);
                //               Log.d(TAG, "tvScrollTitle=" + tvScrollTitle);
                //               Log.d(TAG, "viewAreaToggleEditMode=" + viewAreaToggleEditMode);

                if (itemAtPosition == null) {
                    return;
                }
                if (itemAtPosition.parent != null) {
                    if (viewAreaToggleEditMode != null) {
                        viewAreaToggleEditMode.setVisibility(View.GONE);
                    }
                    if (tvScrollTitle != null) {
                        tvScrollTitle.setVisibility(View.VISIBLE);
                        tvScrollTitle.setText(itemAtPosition.parent.folder);
                    }
                } else {
                    if (viewAreaToggleEditMode != null) {
                        viewAreaToggleEditMode.setVisibility(View.VISIBLE);
                    }
                    if (tvScrollTitle != null) {
                        if (viewAreaToggleEditMode != null) {
                            tvScrollTitle.setVisibility(View.INVISIBLE);
                        }
                        tvScrollTitle.setText("");
                    }
                }
            }
        }
    });

    FlexibleRecyclerSelectionListener rs = new FlexibleRecyclerSelectionListener<FilesTreeAdapter, FilesAdapterDisplayObject>() {
        @Override
        public void onItemSelected(FilesTreeAdapter adapter, final int position, boolean isChecked) {
        }

        @Override
        public void onItemClick(FilesTreeAdapter adapter, int position) {
            if (AndroidUtils.usesNavigationControl()) {
                FilesAdapterDisplayObject oItem = adapter.getItem(position);
                if (adapter.isInEditMode()) {
                    adapter.flipWant(oItem);
                    return;
                }
                if (oItem instanceof FilesAdapterDisplayFolder) {
                    FilesAdapterDisplayFolder oFolder = (FilesAdapterDisplayFolder) oItem;
                    oFolder.expand = !oFolder.expand;
                    adapter.getFilter().filter("");
                } else {
                    showFileContextMenu();
                }
            }
        }

        @Override
        public boolean onItemLongClick(FilesTreeAdapter adapter, int position) {
            if (AndroidUtils.usesNavigationControl()) {
                if (showFileContextMenu()) {
                    return true;
                }
            }
            return false;
        }

        @Override
        public void onItemCheckedChanged(FilesTreeAdapter adapter, FilesAdapterDisplayObject item,
                boolean isChecked) {

            if (adapter.getCheckedItemCount() == 0) {
                finishActionMode();
            } else {
                // Update the subtitle with file name
                showContextualActions();
            }

            AndroidUtils.invalidateOptionsMenuHC(getActivity(), mActionMode);
        }
    };

    adapter = new FilesTreeAdapter(this.getActivity(), rs);
    adapter.setSessionInfo(sessionInfo);
    adapter.setMultiCheckModeAllowed(false);
    adapter.setCheckOnSelectedAfterMS(100);
    listview.setAdapter(adapter);

    return view;
}

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

public boolean moveCursor(int direction, int granularity) {
    if (mCurrentText == null) {
        return false;
    }/* w w  w  .ja v  a 2 s  .com*/
    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;//from   w  ww . ja  v a  2 s . com
    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: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;
        }//  ww  w. ja  v  a  2s .  c om
        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);
}