List of usage examples for android.view KeyEvent getKeyCode
public final int getKeyCode()
From source file:org.bangbang.support.v4.widget.HListView.java
@Override public boolean dispatchKeyEvent(KeyEvent event) { // Dispatch in the normal way boolean handled = super.dispatchKeyEvent(event); if (!handled) { // If we didn't handle it... View focused = getFocusedChild(); if (focused != null && event.getAction() == KeyEvent.ACTION_DOWN) { // ... and our focused child didn't handle it // ... give it to ourselves so we can scroll if necessary handled = onKeyDown(event.getKeyCode(), event); }/* w w w .j a v a 2 s .c o m*/ } return handled; }
From source file:com.gxapplications.android.gxsuite.launcher.Launcher.java
@Override public boolean dispatchKeyEvent(KeyEvent event) { if (event.getAction() == KeyEvent.ACTION_DOWN) { switch (event.getKeyCode()) { case KeyEvent.KEYCODE_HOME: return true; case KeyEvent.KEYCODE_VOLUME_DOWN: if (doesFileExist(DUMP_STATE_PROPERTY)) { dumpState();//w w w . j a v a 2 s . c o m return true; } break; } } else if (event.getAction() == KeyEvent.ACTION_UP) { switch (event.getKeyCode()) { case KeyEvent.KEYCODE_HOME: return true; } } return super.dispatchKeyEvent(event); }
From source file:org.pocketworkstation.pckeyboard.LatinIME.java
@Override public boolean onKeyUp(int keyCode, KeyEvent event) { switch (keyCode) { case KeyEvent.KEYCODE_DPAD_DOWN: case KeyEvent.KEYCODE_DPAD_UP: case KeyEvent.KEYCODE_DPAD_LEFT: case KeyEvent.KEYCODE_DPAD_RIGHT: LatinKeyboardView inputView = mKeyboardSwitcher.getInputView(); // Enable shift key and DPAD to do selections if (inputView != null && inputView.isShown() && inputView.getShiftState() == Keyboard.SHIFT_ON) { event = new KeyEvent(event.getDownTime(), event.getEventTime(), event.getAction(), event.getKeyCode(), event.getRepeatCount(), event.getDeviceId(), event.getScanCode(), KeyEvent.META_SHIFT_LEFT_ON | KeyEvent.META_SHIFT_ON); InputConnection ic = getCurrentInputConnection(); if (ic != null) ic.sendKeyEvent(event);/*from w ww . j a v a2s .com*/ return true; } break; case KeyEvent.KEYCODE_VOLUME_UP: if (!mVolUpAction.equals("none") && isKeyboardVisible()) { return doSwipeAction(mVolUpAction); } break; case KeyEvent.KEYCODE_VOLUME_DOWN: if (!mVolDownAction.equals("none") && isKeyboardVisible()) { return doSwipeAction(mVolDownAction); } break; } return super.onKeyUp(keyCode, event); }
From source file:com.appunite.list.HorizontalListView.java
@Override public boolean dispatchKeyEvent(KeyEvent event) { // Dispatch in the normal way boolean handled = super.dispatchKeyEvent(event); if (!handled) { // If we didn't handle it... View focused = getFocusedChild(); if (focused != null && event.getAction() == KeyEvent.ACTION_DOWN) { // ... and our focused child didn't handle it // ... give it to ourselves so we can scroll if necessary handled = onKeyDown(event.getKeyCode(), event); }// w ww .ja v a2 s. c o m } return handled; }
From source file:net.nightwhistler.pageturner.activity.ReadingFragment.java
@TargetApi(Build.VERSION_CODES.FROYO) private boolean handleVolumeButtonEvent(KeyEvent event) { //Disable volume button handling during TTS if (!config.isVolumeKeyNavEnabled() || ttsIsRunning()) { return false; }// w ww.j a v a 2 s .c om Activity activity = getActivity(); if (activity == null) { return false; } boolean invert = false; int rotation = Surface.ROTATION_0; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO) { Display display = activity.getWindowManager().getDefaultDisplay(); rotation = display.getRotation(); } switch (rotation) { case Surface.ROTATION_0: case Surface.ROTATION_90: invert = false; break; case Surface.ROTATION_180: case Surface.ROTATION_270: invert = true; break; } if (event.getAction() != KeyEvent.ACTION_DOWN) { return true; } if (event.getKeyCode() == KeyEvent.KEYCODE_VOLUME_UP) { if (invert) { pageDown(Orientation.HORIZONTAL); } else { pageUp(Orientation.HORIZONTAL); } } else if (event.getKeyCode() == KeyEvent.KEYCODE_VOLUME_DOWN) { if (invert) { pageUp(Orientation.HORIZONTAL); } else { pageDown(Orientation.HORIZONTAL); } } return true; }
From source file:net.zorgblub.typhon.fragment.ReadingFragment.java
@TargetApi(Build.VERSION_CODES.FROYO) private boolean handleVolumeButtonEvent(KeyEvent event) { //Disable volume button handling during TTS if (!config.isVolumeKeyNavEnabled() || ttsIsRunning()) { return false; }/* w w w . ja va 2 s . co m*/ Activity activity = getActivity(); if (activity == null) { return false; } boolean invert = false; int rotation = Surface.ROTATION_0; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO) { Display display = activity.getWindowManager().getDefaultDisplay(); rotation = display.getRotation(); } switch (rotation) { case Surface.ROTATION_0: case Surface.ROTATION_90: invert = false; break; case Surface.ROTATION_180: case Surface.ROTATION_270: invert = true; break; } if (event.getAction() != KeyEvent.ACTION_DOWN) { return true; } if (event.getKeyCode() == KeyEvent.KEYCODE_VOLUME_UP) { if (config.isVolumeKeyNavChaptersEnabled()) { if (invert) { bookView.navigateForward(); } else { bookView.navigateBack(); } } else { if (invert) { pageDown(Orientation.HORIZONTAL); } else { pageUp(Orientation.HORIZONTAL); } } } else if (event.getKeyCode() == KeyEvent.KEYCODE_VOLUME_DOWN) { if (config.isVolumeKeyNavChaptersEnabled()) { if (invert) { bookView.navigateBack(); } else { bookView.navigateForward(); } } else { if (invert) { pageUp(Orientation.HORIZONTAL); } else { pageDown(Orientation.HORIZONTAL); } } } return true; }
From source file:org.distantshoresmedia.keyboard.LatinIME.java
@Override public boolean onKeyUp(int keyCode, KeyEvent event) { switch (keyCode) { case KeyEvent.KEYCODE_DPAD_DOWN: case KeyEvent.KEYCODE_DPAD_UP: case KeyEvent.KEYCODE_DPAD_LEFT: case KeyEvent.KEYCODE_DPAD_RIGHT: // If tutorial is visible, don't allow dpad to work if (mTutorial != null) { return true; }// w ww .ja va 2 s .c o m TKKeyboardView inputView = mKeyboardSwitcher.getInputView(); // Enable shift key and DPAD to do selections if (inputView != null && inputView.isShown() && inputView.getShiftState() == Keyboard.SHIFT_ON) { event = new KeyEvent(event.getDownTime(), event.getEventTime(), event.getAction(), event.getKeyCode(), event.getRepeatCount(), event.getDeviceId(), event.getScanCode(), KeyEvent.META_SHIFT_LEFT_ON | KeyEvent.META_SHIFT_ON); InputConnection ic = getCurrentInputConnection(); if (ic != null) ic.sendKeyEvent(event); return true; } break; case KeyEvent.KEYCODE_VOLUME_UP: if (!mVolUpAction.equals("none") && isKeyboardVisible()) { return doSwipeAction(mVolUpAction); } break; case KeyEvent.KEYCODE_VOLUME_DOWN: if (!mVolDownAction.equals("none") && isKeyboardVisible()) { return doSwipeAction(mVolDownAction); } break; } return super.onKeyUp(keyCode, event); }
From source file:com.aujur.ebookreader.activity.ReadingFragment.java
@TargetApi(Build.VERSION_CODES.FROYO) private boolean handleVolumeButtonEvent(KeyEvent event) { // Disable volume button handling during TTS if (!config.isVolumeKeyNavEnabled() || ttsIsRunning()) { return false; }// www. j a va 2s .c om Activity activity = getActivity(); if (activity == null) { return false; } boolean invert = false; int rotation = Surface.ROTATION_0; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO) { Display display = activity.getWindowManager().getDefaultDisplay(); rotation = display.getRotation(); } switch (rotation) { case Surface.ROTATION_0: case Surface.ROTATION_90: invert = false; break; case Surface.ROTATION_180: case Surface.ROTATION_270: invert = true; break; } if (event.getAction() != KeyEvent.ACTION_DOWN) { return true; } if (event.getKeyCode() == KeyEvent.KEYCODE_VOLUME_UP) { if (invert) { pageDown(Orientation.HORIZONTAL); } else { pageUp(Orientation.HORIZONTAL); } } else if (event.getKeyCode() == KeyEvent.KEYCODE_VOLUME_DOWN) { if (invert) { pageUp(Orientation.HORIZONTAL); } else { pageDown(Orientation.HORIZONTAL); } } return true; }
From source file:com.android.tv.MainActivity.java
@Override public boolean onKeyUp(int keyCode, KeyEvent event) { /*//from ww w . j a va 2s .c o m * The following keyboard keys map to these remote keys or "debug actions" * - -------- * A KEYCODE_MEDIA_AUDIO_TRACK * D debug: show debug options * E updateChannelBannerAndShowIfNeeded * I KEYCODE_TV_INPUT * O debug: show display mode option * P debug: togglePipView * S KEYCODE_CAPTIONS: select subtitle * W debug: toggle screen size * V KEYCODE_MEDIA_RECORD debug: record the current channel for 30 sec * X KEYCODE_BUTTON_X KEYCODE_PROG_BLUE debug: record current channel for a few minutes * Y KEYCODE_BUTTON_Y KEYCODE_PROG_GREEN debug: Play a recording */ if (SystemProperties.LOG_KEYEVENT.getValue()) { Log.d(TAG, "onKeyUp(" + keyCode + ", " + event + ")"); } // If we are in the middle of channel change, finish it before showing overlays. finishChannelChangeIfNeeded(); if (event.getKeyCode() == KeyEvent.KEYCODE_SEARCH) { showSearchActivity(); return true; } switch (mOverlayManager.onKeyUp(keyCode, event)) { case KEY_EVENT_HANDLER_RESULT_DISPATCH_TO_OVERLAY: return super.onKeyUp(keyCode, event); case KEY_EVENT_HANDLER_RESULT_HANDLED: return true; case KEY_EVENT_HANDLER_RESULT_NOT_HANDLED: return false; case KEY_EVENT_HANDLER_RESULT_PASSTHROUGH: default: // pass through } if (mSearchFragment.isVisible()) { if (keyCode == KeyEvent.KEYCODE_BACK) { getFragmentManager().popBackStack(); return true; } return super.onKeyUp(keyCode, event); } if (keyCode == KeyEvent.KEYCODE_BACK) { // When the event is from onUnhandledInputEvent, onBackPressed is not automatically // called. Therefore, we need to explicitly call onBackPressed(). onBackPressed(); return true; } if (!mChannelTuner.areAllChannelsLoaded()) { // Now channel map is under loading. } else if (mChannelTuner.getBrowsableChannelCount() == 0) { switch (keyCode) { case KeyEvent.KEYCODE_CHANNEL_UP: case KeyEvent.KEYCODE_DPAD_UP: case KeyEvent.KEYCODE_CHANNEL_DOWN: case KeyEvent.KEYCODE_DPAD_DOWN: case KeyEvent.KEYCODE_NUMPAD_ENTER: case KeyEvent.KEYCODE_DPAD_CENTER: case KeyEvent.KEYCODE_E: case KeyEvent.KEYCODE_MENU: showSettingsFragment(); return true; } } else { if (KeypadChannelSwitchView.isChannelNumberKey(keyCode)) { showKeypadChannelSwitchView(keyCode); return true; } switch (keyCode) { case KeyEvent.KEYCODE_DPAD_RIGHT: if (!PermissionUtils.hasModifyParentalControls(this)) { // TODO: support this feature for non-system LC app. b/23939816 return true; } PinDialogFragment dialog = null; if (mTvView.isScreenBlocked()) { dialog = new PinDialogFragment(PinDialogFragment.PIN_DIALOG_TYPE_UNLOCK_CHANNEL, new PinDialogFragment.ResultListener() { @Override public void done(boolean success) { if (success) { unblockScreen(mTvView); mIsCurrentChannelUnblockedByUser = true; } } }); } else if (mTvView.getBlockedContentRating() != null) { final TvContentRating rating = mTvView.getBlockedContentRating(); dialog = new PinDialogFragment(PinDialogFragment.PIN_DIALOG_TYPE_UNLOCK_PROGRAM, new PinDialogFragment.ResultListener() { @Override public void done(boolean success) { if (success) { mLastAllowedRatingForCurrentChannel = rating; mTvView.unblockContent(rating); } } }); } if (dialog != null) { mOverlayManager.showDialogFragment(PinDialogFragment.DIALOG_TAG, dialog, false); } return true; case KeyEvent.KEYCODE_ENTER: case KeyEvent.KEYCODE_NUMPAD_ENTER: case KeyEvent.KEYCODE_E: case KeyEvent.KEYCODE_DPAD_CENTER: case KeyEvent.KEYCODE_MENU: if (event.isCanceled()) { // Ignore canceled key. // Note that if there's a TIS granted RECEIVE_INPUT_EVENT, // fallback keys not blacklisted will have FLAG_CANCELED. // See dispatchKeyEvent() for detail. return true; } if (keyCode != KeyEvent.KEYCODE_MENU) { updateChannelBannerAndShowIfNeeded(UPDATE_CHANNEL_BANNER_REASON_FORCE_SHOW); } if (keyCode != KeyEvent.KEYCODE_E) { mOverlayManager.showMenu( mTvView.isRecordingPlayback() ? Menu.REASON_RECORDING_PLAYBACK : Menu.REASON_NONE); } return true; case KeyEvent.KEYCODE_CHANNEL_UP: case KeyEvent.KEYCODE_DPAD_UP: case KeyEvent.KEYCODE_CHANNEL_DOWN: case KeyEvent.KEYCODE_DPAD_DOWN: // Channel change is already done in the head of this method. return true; case KeyEvent.KEYCODE_S: if (!SystemProperties.USE_DEBUG_KEYS.getValue()) { break; } case KeyEvent.KEYCODE_CAPTIONS: { mOverlayManager.getSideFragmentManager().show(new ClosedCaptionFragment()); return true; } case KeyEvent.KEYCODE_A: if (!SystemProperties.USE_DEBUG_KEYS.getValue()) { break; } case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK: { mOverlayManager.getSideFragmentManager().show(new MultiAudioFragment()); return true; } case KeyEvent.KEYCODE_GUIDE: { mOverlayManager.showProgramGuide(); return true; } case KeyEvent.KEYCODE_INFO: { mOverlayManager.showBanner(); return true; } } } if (SystemProperties.USE_DEBUG_KEYS.getValue()) { switch (keyCode) { case KeyEvent.KEYCODE_W: { mDebugNonFullSizeScreen = !mDebugNonFullSizeScreen; if (mDebugNonFullSizeScreen) { FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) mTvView.getLayoutParams(); params.width = 960; params.height = 540; params.gravity = Gravity.START; mTvView.setLayoutParams(params); } else { FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) mTvView.getLayoutParams(); params.width = ViewGroup.LayoutParams.MATCH_PARENT; params.height = ViewGroup.LayoutParams.MATCH_PARENT; params.gravity = Gravity.CENTER; mTvView.setLayoutParams(params); } return true; } case KeyEvent.KEYCODE_P: { togglePipView(); return true; } case KeyEvent.KEYCODE_CTRL_LEFT: case KeyEvent.KEYCODE_CTRL_RIGHT: { mUseKeycodeBlacklist = !mUseKeycodeBlacklist; return true; } case KeyEvent.KEYCODE_O: { mOverlayManager.getSideFragmentManager().show(new DisplayModeFragment()); return true; } case KeyEvent.KEYCODE_D: mOverlayManager.getSideFragmentManager().show(new DebugOptionFragment()); return true; case KeyEvent.KEYCODE_MEDIA_RECORD: // TODO(DVR) handle with debug_keys set case KeyEvent.KEYCODE_V: { DvrManager dvrManager = TvApplication.getSingletons(this).getDvrManager(); long startTime = System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(5); long endTime = System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(35); dvrManager.addSchedule(getCurrentChannel(), startTime, endTime); return true; } case KeyEvent.KEYCODE_PROG_BLUE: case KeyEvent.KEYCODE_BUTTON_X: case KeyEvent.KEYCODE_X: { if (CommonFeatures.DVR.isEnabled(this)) { Channel channel = mTvView.getCurrentChannel(); long channelId = channel.getId(); Program p = mProgramDataManager.getCurrentProgram(channelId); if (p == null) { long now = System.currentTimeMillis(); mDvrManager.addSchedule(channel, now, now + TimeUnit.MINUTES.toMillis(1)); } else { mDvrManager.addSchedule(p, mDvrManager.getScheduledRecordingsThatConflict(p)); } return true; } } case KeyEvent.KEYCODE_PROG_YELLOW: case KeyEvent.KEYCODE_BUTTON_Y: case KeyEvent.KEYCODE_Y: { if (CommonFeatures.DVR.isEnabled(this) && BuildCompat.isAtLeastN()) { // TODO(DVR) only get finished recordings. List<RecordedProgram> recordedPrograms = mDvrDataManager.getRecordedPrograms(); Log.d(TAG, "Found " + recordedPrograms.size() + " recordings"); if (recordedPrograms.isEmpty()) { Toast.makeText(this, "No finished recording to play", Toast.LENGTH_LONG).show(); } else { RecordedProgram r = recordedPrograms.get(0); Intent intent = new Intent(this, DvrPlayActivity.class); intent.putExtra(ScheduledRecording.RECORDING_ID_EXTRA, r.getId()); startActivity(intent); } return true; } } } } return super.onKeyUp(keyCode, event); }
From source file:com.android.launcher3.Launcher.java
@Override public boolean dispatchKeyEvent(KeyEvent event) { if (event.getAction() == KeyEvent.ACTION_DOWN) { switch (event.getKeyCode()) { case KeyEvent.KEYCODE_HOME: return true; case KeyEvent.KEYCODE_VOLUME_DOWN: if (Utilities.isPropertyEnabled(DUMP_STATE_PROPERTY)) { dumpState();//w w w .j a va 2 s . c o m return true; } break; } } else if (event.getAction() == KeyEvent.ACTION_UP) { switch (event.getKeyCode()) { case KeyEvent.KEYCODE_HOME: return true; } } return super.dispatchKeyEvent(event); }