List of usage examples for android.view KeyEvent KEYCODE_TV_INPUT
int KEYCODE_TV_INPUT
To view the source code for android.view KeyEvent KEYCODE_TV_INPUT.
Click Source Link
From source file:com.android.tv.TvApplication.java
/** * Handles the global key KEYCODE_TV_INPUT. *//*from ww w . j a va2s . c om*/ public void handleTvInputKey() { TvInputManager tvInputManager = (TvInputManager) getSystemService(Context.TV_INPUT_SERVICE); List<TvInputInfo> tvInputs = tvInputManager.getTvInputList(); int inputCount = 0; boolean hasTunerInput = false; for (TvInputInfo input : tvInputs) { if (input.isPassthroughInput()) { if (!input.isHidden(this)) { ++inputCount; } } else if (!hasTunerInput) { hasTunerInput = true; ++inputCount; } } if (inputCount < 2) { return; } Activity activityToHandle = mMainActivityWrapper.isResumed() ? mMainActivityWrapper.getMainActivity() : mSelectInputActivity; if (activityToHandle != null) { // If startActivity is called, MainActivity.onPause is unnecessarily called. To // prevent it, MainActivity.dispatchKeyEvent is directly called. activityToHandle.dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_TV_INPUT)); activityToHandle.dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_TV_INPUT)); } else if (mMainActivityWrapper.isStarted()) { Bundle extras = new Bundle(); extras.putString(Utils.EXTRA_KEY_ACTION, Utils.EXTRA_ACTION_SHOW_TV_INPUT); startMainActivity(extras); } else { startActivity(new Intent(this, SelectInputActivity.class).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)); } }
From source file:com.android.tv.ui.TvOverlayManager.java
/** * Handles the onKeyUp event of the {@link MainActivity}. */// w ww.j a v a2s . co m @KeyHandlerResultType public int onKeyUp(int keyCode, KeyEvent event) { // Handle media key here because it is related to the menu. if (isMediaStartKey(keyCode)) { // The media key should not be passed up to the system in any cases. if (mCurrentDialog != null || mProgramGuide.isActive() || mSideFragmentManager.isActive() || mSearchFragment.isVisible() || mTransitionManager.isKeypadChannelSwitchActive() || mTransitionManager.isSelectInputActive() || mSetupFragmentActive || mNewSourcesFragmentActive) { // Do not handle media key when any pop-ups which can handle keys are active. return MainActivity.KEY_EVENT_HANDLER_RESULT_HANDLED; } TimeShiftManager timeShiftManager = mMainActivity.getTimeShiftManager(); if (!timeShiftManager.isAvailable()) { return MainActivity.KEY_EVENT_HANDLER_RESULT_HANDLED; } switch (keyCode) { case KeyEvent.KEYCODE_MEDIA_PLAY: timeShiftManager.play(); showMenu(Menu.REASON_PLAY_CONTROLS_PLAY); break; case KeyEvent.KEYCODE_MEDIA_PAUSE: timeShiftManager.pause(); showMenu(Menu.REASON_PLAY_CONTROLS_PAUSE); break; case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE: timeShiftManager.togglePlayPause(); showMenu(Menu.REASON_PLAY_CONTROLS_PLAY_PAUSE); break; case KeyEvent.KEYCODE_MEDIA_REWIND: timeShiftManager.rewind(); showMenu(Menu.REASON_PLAY_CONTROLS_REWIND); break; case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD: timeShiftManager.fastForward(); showMenu(Menu.REASON_PLAY_CONTROLS_FAST_FORWARD); break; case KeyEvent.KEYCODE_MEDIA_PREVIOUS: timeShiftManager.jumpToPrevious(); showMenu(Menu.REASON_PLAY_CONTROLS_JUMP_TO_PREVIOUS); break; case KeyEvent.KEYCODE_MEDIA_NEXT: timeShiftManager.jumpToNext(); showMenu(Menu.REASON_PLAY_CONTROLS_JUMP_TO_NEXT); break; default: // Does nothing. break; } return MainActivity.KEY_EVENT_HANDLER_RESULT_HANDLED; } if (keyCode == KeyEvent.KEYCODE_I || keyCode == KeyEvent.KEYCODE_TV_INPUT) { if (mTransitionManager.isSelectInputActive()) { mSelectInputView.onKeyUp(keyCode, event); } else { showSelectInputView(); } return MainActivity.KEY_EVENT_HANDLER_RESULT_HANDLED; } if (mCurrentDialog != null) { // Consumes the keys while a Dialog is showing. // This can be happen while a Dialog isn't created yet. return MainActivity.KEY_EVENT_HANDLER_RESULT_HANDLED; } if (mProgramGuide.isActive()) { if (keyCode == KeyEvent.KEYCODE_BACK) { mProgramGuide.onBackPressed(); return MainActivity.KEY_EVENT_HANDLER_RESULT_HANDLED; } return MainActivity.KEY_EVENT_HANDLER_RESULT_DISPATCH_TO_OVERLAY; } if (mSideFragmentManager.isActive()) { if (keyCode == KeyEvent.KEYCODE_BACK || mSideFragmentManager.isHideKeyForCurrentPanel(keyCode)) { mSideFragmentManager.popSideFragment(); return MainActivity.KEY_EVENT_HANDLER_RESULT_HANDLED; } return MainActivity.KEY_EVENT_HANDLER_RESULT_DISPATCH_TO_OVERLAY; } if (mMenu.isActive() || mTransitionManager.isSceneActive()) { if (keyCode == KeyEvent.KEYCODE_BACK) { TimeShiftManager timeShiftManager = mMainActivity.getTimeShiftManager(); if (timeShiftManager.isPaused()) { timeShiftManager.play(); } hideOverlays(TvOverlayManager.FLAG_HIDE_OVERLAYS_KEEP_SIDE_PANELS | TvOverlayManager.FLAG_HIDE_OVERLAYS_KEEP_DIALOG | TvOverlayManager.FLAG_HIDE_OVERLAYS_KEEP_FRAGMENT); return MainActivity.KEY_EVENT_HANDLER_RESULT_HANDLED; } if (mMenu.isActive()) { if (KeypadChannelSwitchView.isChannelNumberKey(keyCode)) { mMainActivity.showKeypadChannelSwitchView(keyCode); return MainActivity.KEY_EVENT_HANDLER_RESULT_HANDLED; } return MainActivity.KEY_EVENT_HANDLER_RESULT_DISPATCH_TO_OVERLAY; } } if (mTransitionManager.isKeypadChannelSwitchActive()) { if (keyCode == KeyEvent.KEYCODE_BACK) { mTransitionManager.goToEmptyScene(true); return MainActivity.KEY_EVENT_HANDLER_RESULT_HANDLED; } return mKeypadChannelSwitchView.onKeyUp(keyCode, event) ? MainActivity.KEY_EVENT_HANDLER_RESULT_HANDLED : MainActivity.KEY_EVENT_HANDLER_RESULT_NOT_HANDLED; } if (mTransitionManager.isSelectInputActive()) { if (keyCode == KeyEvent.KEYCODE_BACK) { mTransitionManager.goToEmptyScene(true); return MainActivity.KEY_EVENT_HANDLER_RESULT_HANDLED; } return mSelectInputView.onKeyUp(keyCode, event) ? MainActivity.KEY_EVENT_HANDLER_RESULT_HANDLED : MainActivity.KEY_EVENT_HANDLER_RESULT_NOT_HANDLED; } if (mSetupFragmentActive) { if (keyCode == KeyEvent.KEYCODE_BACK) { closeSetupFragment(true); return MainActivity.KEY_EVENT_HANDLER_RESULT_HANDLED; } return MainActivity.KEY_EVENT_HANDLER_RESULT_DISPATCH_TO_OVERLAY; } if (mNewSourcesFragmentActive) { if (keyCode == KeyEvent.KEYCODE_BACK) { closeNewSourcesFragment(true); return MainActivity.KEY_EVENT_HANDLER_RESULT_HANDLED; } return MainActivity.KEY_EVENT_HANDLER_RESULT_DISPATCH_TO_OVERLAY; } return MainActivity.KEY_EVENT_HANDLER_RESULT_PASSTHROUGH; }