Java Code Examples for android.view.KeyEvent#KEYCODE_VOLUME_UP
The following examples show how to use
android.view.KeyEvent#KEYCODE_VOLUME_UP .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: VideoCastControllerActivity.java From android with Apache License 2.0 | 6 votes |
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (mCastManager.isConnected()) { if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) { onVolumeChange((double) mVolumeIncrement); } else if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) { onVolumeChange(-(double) mVolumeIncrement); } else { // we don't want to consume non-volume key events return super.onKeyDown(keyCode, event); } if (mCastManager.getPlaybackStatus() == MediaStatus.PLAYER_STATE_PLAYING) { return super.onKeyDown(keyCode, event); } else { return true; } } return super.onKeyDown(keyCode, event); }
Example 2
Source File: ExpandedControllerActivity.java From delion with Apache License 2.0 | 6 votes |
/** * Modify remote volume by handling volume keys. * * @param controller The remote controller through which the volume will be modified. * @param event The key event. Its keycode needs to be either {@code KEYCODE_VOLUME_DOWN} or * {@code KEYCODE_VOLUME_UP} otherwise this method will return false. * @return True if the event is handled. */ private boolean handleVolumeKeyEvent(MediaRouteController controller, KeyEvent event) { if (!controller.isBeingCast()) return false; int action = event.getAction(); int keyCode = event.getKeyCode(); // Intercept the volume keys to affect only remote volume. switch (keyCode) { case KeyEvent.KEYCODE_VOLUME_DOWN: if (action == KeyEvent.ACTION_DOWN) controller.setRemoteVolume(-1); return true; case KeyEvent.KEYCODE_VOLUME_UP: if (action == KeyEvent.ACTION_DOWN) controller.setRemoteVolume(1); return true; default: return false; } }
Example 3
Source File: MainActivity.java From android with Apache License 2.0 | 6 votes |
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (mCastManager != null && mCastManager.isConnected()) { if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) { changeVolume(CastApplication.VOLUME_INCREMENT); } else if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) { changeVolume(-CastApplication.VOLUME_INCREMENT); } else { // we don't want to consume non-volume key events return super.onKeyDown(keyCode, event); } if (mCastManager.getPlaybackStatus() == MediaStatus.PLAYER_STATE_PLAYING) { return super.onKeyDown(keyCode, event); } else { return true; } } return super.onKeyDown(keyCode, event); }
Example 4
Source File: CaptureActivity.java From CodeScaner with MIT License | 6 votes |
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { switch (keyCode) { case KeyEvent.KEYCODE_BACK: setResult(RESULT_CANCELED); finish(); return true; case KeyEvent.KEYCODE_FOCUS: case KeyEvent.KEYCODE_CAMERA: // Handle these events so they don't launch the Camera app return true; // Use volume up/down to turn on light case KeyEvent.KEYCODE_VOLUME_DOWN: cameraManager.setTorch(false); return true; case KeyEvent.KEYCODE_VOLUME_UP: cameraManager.setTorch(true); return true; } return super.onKeyDown(keyCode, event); }
Example 5
Source File: ModVolumeKeySkipTrack.java From GravityBox with Apache License 2.0 | 5 votes |
@Override protected void beforeHookedMethod(MethodHookParam param) throws Throwable { if (!allowSkipTrack) return; final KeyEvent event = (KeyEvent) param.args[0]; final int keyCode = event.getKeyCode(); initManagers((Context) XposedHelpers.getObjectField(param.thisObject, "mContext")); if ((keyCode == KeyEvent.KEYCODE_VOLUME_DOWN || keyCode == KeyEvent.KEYCODE_VOLUME_UP) && (event.getFlags() & KeyEvent.FLAG_FROM_SYSTEM) != 0 && !mPowerManager.isInteractive() && mAudioManager != null && mAudioManager.isMusicActive()) { if (event.getAction() == KeyEvent.ACTION_DOWN) { mIsLongPress = false; handleVolumeLongPress(param.thisObject, keyCode); } else { handleVolumeLongPressAbort(param.thisObject); if (!mIsLongPress) { if (mShoudTriggerWakeUp) { wakeUp(); } else { mAudioManager.adjustStreamVolume(AudioManager.STREAM_MUSIC, keyCode == KeyEvent.KEYCODE_VOLUME_UP ? AudioManager.ADJUST_RAISE : AudioManager.ADJUST_LOWER, 0); } } } param.setResult(0); return; } }
Example 6
Source File: AlarmDismissActivity.java From SuntimesWidget with GNU General Public License v3.0 | 5 votes |
@Override public boolean dispatchKeyEvent (KeyEvent event) { if (mode == null && !hardwareButtonPressed) { int action = event.getAction(); int keyCode = event.getKeyCode(); if (action == KeyEvent.ACTION_DOWN) { switch (keyCode) { case KeyEvent.KEYCODE_CAMERA: case KeyEvent.KEYCODE_VOLUME_UP: case KeyEvent.KEYCODE_VOLUME_DOWN: hardwareButtonPressed = true; String alarmAction = AlarmSettings.loadPrefOnHardwareButtons(AlarmDismissActivity.this); Intent intent = AlarmNotifications.getAlarmIntent(AlarmDismissActivity.this, alarmAction, alarm.getUri()); sendBroadcast(intent); return true; default: return super.dispatchKeyEvent(event); } } else return super.dispatchKeyEvent(event); } else return super.dispatchKeyEvent(event); }
Example 7
Source File: AndroidAudioManager.java From linphone-android with GNU General Public License v3.0 | 5 votes |
public boolean onKeyVolumeAdjust(int keyCode) { if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) { adjustVolume(1); return true; } else if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) { adjustVolume(-1); return true; } return false; }
Example 8
Source File: MainActivity.java From Overchan-Android with GNU General Public License v3.0 | 5 votes |
@Override public boolean onKeyUp(int keyCode, KeyEvent event) { if (settings.scrollVolumeButtons) { switch (keyCode) { case KeyEvent.KEYCODE_VOLUME_UP: case KeyEvent.KEYCODE_VOLUME_DOWN: return true; } } return super.onKeyUp(keyCode, event); }
Example 9
Source File: MediaControlReceiver.java From IdealMedia with Apache License 2.0 | 5 votes |
@Override public void onReceive(Context context, Intent intent) { if (intent.getAction().equals(Intent.ACTION_MEDIA_BUTTON)) { KeyEvent event = intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT); if (event == null) return; if (event.getAction() != KeyEvent.ACTION_DOWN) return; switch (event.getKeyCode()) { case KeyEvent.KEYCODE_MEDIA_STOP: case KeyEvent.KEYCODE_HEADSETHOOK: case KeyEvent.KEYCODE_MEDIA_PLAY: sendMessage(context, PlayerService.PLAY); break; case KeyEvent.KEYCODE_MEDIA_PAUSE: sendMessage(context, PlayerService.PLAY); break; case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE: sendMessage(context, PlayerService.PLAY); break; case KeyEvent.KEYCODE_MEDIA_NEXT: sendMessage(context, PlayerService.NEXT); break; case KeyEvent.KEYCODE_MEDIA_PREVIOUS: sendMessage(context, PlayerService.PREV); break; case KeyEvent.KEYCODE_VOLUME_UP: sendMessage(context, PlayerService.VOLUME_UP); break; case KeyEvent.KEYCODE_VOLUME_DOWN: sendMessage(context, PlayerService.VOLUME_DOWN); break; } } }
Example 10
Source File: TalkBackService.java From talkback with Apache License 2.0 | 5 votes |
/** * Intended to mimic the behavior of onKeyEvent if this were the only service running. It will be * called from onKeyEvent, both from this service and from others in this apk (TalkBack). This * method must not block, since it will block onKeyEvent as well. * * @param keyEvent A key event * @return {@code true} if the event is handled, {@code false} otherwise. */ @Override public boolean onKeyEventShared(KeyEvent keyEvent) { if (keyEvent.getKeyCode() == KeyEvent.KEYCODE_UNKNOWN) { // Tapping on fingerprint sensor somehow files KeyEvent with KEYCODE_UNKNOW, which will change // input mode to keyboard, and cancel pending accessibility hints. It is OK to just ignore // these KeyEvents since they're unused in TalkBack. return false; } Performance perf = Performance.getInstance(); EventId eventId = perf.onEventReceived(keyEvent); if (isServiceActive()) { // Stop the TTS engine when any key (except for volume up/down key) is pressed on physical // keyboard. if (shouldInterruptByAnyKeyEvent() && keyEvent.getDeviceId() != 0 && keyEvent.getAction() == KeyEvent.ACTION_DOWN && keyEvent.getKeyCode() != KeyEvent.KEYCODE_VOLUME_DOWN && keyEvent.getKeyCode() != KeyEvent.KEYCODE_VOLUME_UP) { interruptAllFeedback(false /* stopTtsSpeechCompletely */); } } for (ServiceKeyEventListener listener : keyEventListeners) { if (!isServiceActive() && !listener.processWhenServiceSuspended()) { continue; } if (listener.onKeyEvent(keyEvent, eventId)) { perf.onHandlerDone(eventId); return true; } } return false; }
Example 11
Source File: GenericUiControls.java From BluetoothHidEmu with Apache License 2.0 | 5 votes |
/** * onKeyDown() */ @Override public boolean processKeyDown(int keyCode, KeyEvent event) { if (mEchoEditText != null && (keyCode == KeyEvent.KEYCODE_VOLUME_UP || keyCode == KeyEvent.KEYCODE_VOLUME_DOWN)) { KeyListener keyListener = mEchoEditText.getKeyListener(); keyListener.onKeyDown(mEchoEditText, mEchoEditText.getEditableText(), keyCode, event); return true; } return false; }
Example 12
Source File: VideoView.java From react-native-android-vitamio with MIT License | 5 votes |
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { boolean isKeyCodeSupported = keyCode != KeyEvent.KEYCODE_BACK && keyCode != KeyEvent.KEYCODE_VOLUME_UP && keyCode != KeyEvent.KEYCODE_VOLUME_DOWN && keyCode != KeyEvent.KEYCODE_MENU && keyCode != KeyEvent.KEYCODE_CALL && keyCode != KeyEvent.KEYCODE_ENDCALL; if (isInPlaybackState() && isKeyCodeSupported && mMediaController != null) { if (keyCode == KeyEvent.KEYCODE_HEADSETHOOK || keyCode == KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE || keyCode == KeyEvent.KEYCODE_SPACE) { if (mMediaPlayer.isPlaying()) { pause(); mMediaController.show(); } else { start(); mMediaController.hide(); } return true; } else if (keyCode == KeyEvent.KEYCODE_MEDIA_PLAY) { if (!mMediaPlayer.isPlaying()) { start(); mMediaController.hide(); } return true; } else if (keyCode == KeyEvent.KEYCODE_MEDIA_STOP || keyCode == KeyEvent.KEYCODE_MEDIA_PAUSE) { if (mMediaPlayer.isPlaying()) { pause(); mMediaController.show(); } return true; } else { toggleMediaControlsVisiblity(); } } return super.onKeyDown(keyCode, event); }
Example 13
Source File: ReadActivity.java From BookReader with Apache License 2.0 | 5 votes |
@Override public boolean onKeyUp(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) { if (SettingManager.getInstance().isVolumeFlipEnable()) { mPageWidget.nextPage(); return true;// 防止翻页有声音 } } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) { if (SettingManager.getInstance().isVolumeFlipEnable()) { mPageWidget.prePage(); return true; } } return super.onKeyUp(keyCode, event); }
Example 14
Source File: LocalPlayerActivity.java From android with Apache License 2.0 | 5 votes |
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (mLocation == PlaybackLocation.LOCAL) { return super.onKeyDown(keyCode, event); } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) { onVolumeChange(CastApplication.VOLUME_INCREMENT); } else if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) { onVolumeChange(CastApplication.VOLUME_INCREMENT); } else { return super.onKeyDown(keyCode, event); } return true; }
Example 15
Source File: CordovaWebView.java From phonegapbootcampsite with MIT License | 4 votes |
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { if(keyDownCodes.contains(keyCode)) { if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) { // only override default behavior is event bound LOG.d(TAG, "Down Key Hit"); this.loadUrl("javascript:cordova.fireDocumentEvent('volumedownbutton');"); return true; } // If volumeup key else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) { LOG.d(TAG, "Up Key Hit"); this.loadUrl("javascript:cordova.fireDocumentEvent('volumeupbutton');"); return true; } else { return super.onKeyDown(keyCode, event); } } else if(keyCode == KeyEvent.KEYCODE_BACK) { return !(this.startOfHistory()) || this.bound; } else if(keyCode == KeyEvent.KEYCODE_MENU) { //How did we get here? Is there a childView? View childView = this.getFocusedChild(); if(childView != null) { //Make sure we close the keyboard if it's present InputMethodManager imm = (InputMethodManager) cordova.getActivity().getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(childView.getWindowToken(), 0); cordova.getActivity().openOptionsMenu(); return true; } else { return super.onKeyDown(keyCode, event); } } return super.onKeyDown(keyCode, event); }
Example 16
Source File: GalleryActivity.java From MHViewer with Apache License 2.0 | 4 votes |
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (mGalleryView == null) { return super.onKeyDown(keyCode, event); } // Check volume if (Settings.getVolumePage()) { if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) { if (mLayoutMode == GalleryView.LAYOUT_RIGHT_TO_LEFT) { mGalleryView.pageRight(); } else { mGalleryView.pageLeft(); } return true; } else if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) { if (mLayoutMode == GalleryView.LAYOUT_RIGHT_TO_LEFT) { mGalleryView.pageLeft(); } else { mGalleryView.pageRight(); } return true; } } // Check keyboard and Dpad switch (keyCode) { case KeyEvent.KEYCODE_PAGE_UP: case KeyEvent.KEYCODE_DPAD_UP: if (mLayoutMode == GalleryView.LAYOUT_RIGHT_TO_LEFT) { mGalleryView.pageRight(); } else { mGalleryView.pageLeft(); } return true; case KeyEvent.KEYCODE_DPAD_LEFT: mGalleryView.pageLeft(); return true; case KeyEvent.KEYCODE_PAGE_DOWN: case KeyEvent.KEYCODE_DPAD_DOWN: if (mLayoutMode == GalleryView.LAYOUT_RIGHT_TO_LEFT) { mGalleryView.pageLeft(); } else { mGalleryView.pageRight(); } return true; case KeyEvent.KEYCODE_DPAD_RIGHT: mGalleryView.pageRight(); return true; case KeyEvent.KEYCODE_DPAD_CENTER: case KeyEvent.KEYCODE_SPACE: case KeyEvent.KEYCODE_MENU: onTapMenuArea(); return true; } return super.onKeyDown(keyCode, event); }
Example 17
Source File: CordovaWebViewImpl.java From cordova-plugin-intent with MIT License | 4 votes |
@Override public Boolean onDispatchKeyEvent(KeyEvent event) { int keyCode = event.getKeyCode(); boolean isBackButton = keyCode == KeyEvent.KEYCODE_BACK; if (event.getAction() == KeyEvent.ACTION_DOWN) { if (isBackButton && mCustomView != null) { return true; } else if (boundKeyCodes.contains(keyCode)) { return true; } else if (isBackButton) { return engine.canGoBack(); } } else if (event.getAction() == KeyEvent.ACTION_UP) { if (isBackButton && mCustomView != null) { hideCustomView(); return true; } else if (boundKeyCodes.contains(keyCode)) { String eventName = null; switch (keyCode) { case KeyEvent.KEYCODE_VOLUME_DOWN: eventName = "volumedownbutton"; break; case KeyEvent.KEYCODE_VOLUME_UP: eventName = "volumeupbutton"; break; case KeyEvent.KEYCODE_SEARCH: eventName = "searchbutton"; break; case KeyEvent.KEYCODE_MENU: eventName = "menubutton"; break; case KeyEvent.KEYCODE_BACK: eventName = "backbutton"; break; } if (eventName != null) { sendJavascriptEvent(eventName); return true; } } else if (isBackButton) { return engine.goBack(); } } return null; }
Example 18
Source File: ContentVideoView.java From android-chromium with BSD 2-Clause "Simplified" License | 4 votes |
@Override public boolean onKey(View v, int keyCode, KeyEvent event) { boolean isKeyCodeSupported = keyCode != KeyEvent.KEYCODE_BACK && keyCode != KeyEvent.KEYCODE_VOLUME_UP && keyCode != KeyEvent.KEYCODE_VOLUME_DOWN && keyCode != KeyEvent.KEYCODE_VOLUME_MUTE && keyCode != KeyEvent.KEYCODE_CALL && keyCode != KeyEvent.KEYCODE_MENU && keyCode != KeyEvent.KEYCODE_SEARCH && keyCode != KeyEvent.KEYCODE_ENDCALL; if (isInPlaybackState() && isKeyCodeSupported && mControls != null) { if (keyCode == KeyEvent.KEYCODE_HEADSETHOOK || keyCode == KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE) { if (isPlaying()) { pause(); mControls.show(); } else { start(); mControls.hide(); } return true; } else if (keyCode == KeyEvent.KEYCODE_MEDIA_PLAY) { if (!isPlaying()) { start(); mControls.hide(); } return true; } else if (keyCode == KeyEvent.KEYCODE_MEDIA_STOP || keyCode == KeyEvent.KEYCODE_MEDIA_PAUSE) { if (isPlaying()) { pause(); mControls.show(); } return true; } else { toggleMediaControlsVisiblity(); } } else if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_UP) { exitFullscreen(false); return true; } else if (keyCode == KeyEvent.KEYCODE_MENU || keyCode == KeyEvent.KEYCODE_SEARCH) { return true; } return super.onKeyDown(keyCode, event); }
Example 19
Source File: ReadActivity.java From Jreader with GNU General Public License v2.0 | 4 votes |
/** * 判断是从哪个界面进入的READ * @param keyCode * @param event * @return */ @Override public boolean onKeyDown(int keyCode, KeyEvent event) { switch (keyCode) { case KeyEvent.KEYCODE_BACK : if (show) {// 如果popwindow正在显示 getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN); show = false; mPopupWindow.dismiss(); popDismiss(); } else { ReadActivity.this.finish(); } if (!mPopupWindow.isShowing()) { hideSystemUI(); } else { // showSystemUI(); } voiceListining = false; if (voicesetpop.isShowing()) { voicesetpop.dismiss(); } return true; //音量加大及减小事件 case KeyEvent.KEYCODE_VOLUME_UP: if(!voiceListining && !show) { prePage(); }else audio.adjustStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_RAISE, AudioManager.FLAG_PLAY_SOUND | AudioManager.FLAG_SHOW_UI); return true; case KeyEvent.KEYCODE_VOLUME_DOWN: if(!voiceListining && !show) { nextPage(); }else audio.adjustStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_LOWER, AudioManager.FLAG_PLAY_SOUND | AudioManager.FLAG_SHOW_UI); return true; default: break; } return super.onKeyDown(keyCode,event); }
Example 20
Source File: CordovaWebViewImpl.java From ultimate-cordova-webview-app with MIT License | 4 votes |
@Override public Boolean onDispatchKeyEvent(KeyEvent event) { int keyCode = event.getKeyCode(); boolean isBackButton = keyCode == KeyEvent.KEYCODE_BACK; if (event.getAction() == KeyEvent.ACTION_DOWN) { if (isBackButton && mCustomView != null) { return true; } else if (boundKeyCodes.contains(keyCode)) { return true; } else if (isBackButton) { return engine.canGoBack(); } } else if (event.getAction() == KeyEvent.ACTION_UP) { if (isBackButton && mCustomView != null) { hideCustomView(); return true; } else if (boundKeyCodes.contains(keyCode)) { String eventName = null; switch (keyCode) { case KeyEvent.KEYCODE_VOLUME_DOWN: eventName = "volumedownbutton"; break; case KeyEvent.KEYCODE_VOLUME_UP: eventName = "volumeupbutton"; break; case KeyEvent.KEYCODE_SEARCH: eventName = "searchbutton"; break; case KeyEvent.KEYCODE_MENU: eventName = "menubutton"; break; case KeyEvent.KEYCODE_BACK: eventName = "backbutton"; break; } if (eventName != null) { sendJavascriptEvent(eventName); return true; } } else if (isBackButton) { return engine.goBack(); } } return null; }