List of usage examples for android.view KeyEvent KEYCODE_VOLUME_UP
int KEYCODE_VOLUME_UP
To view the source code for android.view KeyEvent KEYCODE_VOLUME_UP.
Click Source Link
From source file:com.arthurtimberly.fragments.CaptureFragment.java
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); final LaunchActivity activity = (LaunchActivity) getActivity(); SharedPreferences preferences = PreferenceManager .getDefaultSharedPreferences(activity.getApplicationContext()); /*// w ww . jav a 2 s. co m * Reset frames. */ // force to use 4 photos /* String numPhotosPref = preferences.getString(getString(R.string.pref__number_of_photos_key), getString(R.string.pref__number_of_photos_default)); */ mFramesTotal = 4;//Integer.parseInt(numPhotosPref); mFrameIndex = 0; mFramesData = new byte[mFramesTotal][]; /* * Initialize and set key event handlers. */ mBackPressedHandler = new LaunchActivity.BackPressedHandler() { @Override public boolean onBackPressed() { // If capture sequence is running, exit capture sequence on back pressed event. if (mIsCaptureSequenceRunning) { activity.replaceFragment(CaptureFragment.newInstance(mUseFrontFacing), false, true); } return mIsCaptureSequenceRunning; } }; activity.setBackPressedHandler(mBackPressedHandler); mKeyEventHandler = new LaunchActivity.KeyEventHandler() { @Override public boolean onKeyEvent(KeyEvent event) { final int keyCode = event.getKeyCode(); if (keyCode == KeyEvent.KEYCODE_ENTER || keyCode == KeyEvent.KEYCODE_VOLUME_UP) { mStartButton.dispatchKeyEvent(event); return true; } return false; } }; activity.setKeyEventHandler(mKeyEventHandler); /* * Functionalize views. */ mPreferencesButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent preferencesIntent = new Intent(activity, MyPreferenceActivity.class); startActivity(preferencesIntent); } }); // Show switch button only if more than one camera is available. if (mNumCameras > 1) { mSwitchButton.setVisibility(View.VISIBLE); mSwitchButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // Switch camera. boolean useFrontFacing = false; CameraInfo cameraInfo = new CameraInfo(); if (mCameraId != INVALID_CAMERA_ID) { Camera.getCameraInfo(mCameraId, cameraInfo); if (cameraInfo.facing == CameraInfo.CAMERA_FACING_BACK) { useFrontFacing = true; } // Relaunch fragment with new camera. activity.replaceFragment(CaptureFragment.newInstance(useFrontFacing), false, true); } } }); } // Get trigger mode preference. /* String triggerPref = preferences.getString(getString(R.string.pref__trigger_key), getString(R.string.pref__trigger_default)); if (triggerPref.equals(getString(R.string.pref__trigger_countdown))) { mTriggerMode = TRIGGER_MODE_COUNTDOWN; } else if (triggerPref.equals(getString(R.string.pref__trigger_burst))) { mTriggerMode = TRIGGER_MODE_BURST; } else { mTriggerMode = TRIGGER_MODE_MANUAL; } */ // force to use countdown mode mTriggerMode = TRIGGER_MODE_COUNTDOWN; // Configure title and start button text. mTitle.setText(String.format(getString(R.string.capture__title_frame), mFrameIndex + 1, mFramesTotal)); if (mTriggerMode == TRIGGER_MODE_MANUAL) { // Update title. mStartButton.setText(getString(R.string.capture__start_manual_button_text)); } else { mStartButton.setText(getString(R.string.capture__start_countdown_button_text)); } // Configure start button behaviour. mStartButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { onStartButtonPressedImpl(); } }); mStartButton.setOnKeyListener(new View.OnKeyListener() { @Override public boolean onKey(View v, int keyCode, KeyEvent event) { onStartButtonPressedImpl(); return true; } }); }
From source file:org.easyaccess.phonedialer.CallingScreen.java
@Override public boolean onKeyUp(int keyCode, KeyEvent event) { if (KeyEvent.KEYCODE_VOLUME_UP == event.getKeyCode()) { if (Utils.ringing == 1) { // announce the caller name/number announceCaller(this.callerDetails); return true; } else if (Utils.ringing == 0 && Utils.off_hook == 1) { // activate loudspeaker Utils.audioManager = (AudioManager) getApplicationContext().getSystemService(Context.AUDIO_SERVICE); if (Utils.audioManager.isSpeakerphoneOn() == false) { Utils.audioManager.setSpeakerphoneOn(true); } else { // deactivate loudspeaker Utils.audioManager.setSpeakerphoneOn(false); }//from w w w .j av a 2 s .c o m return true; } } else if (KeyEvent.KEYCODE_VOLUME_DOWN == event.getKeyCode()) { if (Utils.ringing == 1) { // mute the ringtone muteRingtone(); return true; } else if (Utils.ringing == 0 && Utils.off_hook == 1) { if (Utils.audioManager.isMicrophoneMute() == true) { Utils.audioManager.setMicrophoneMute(false); } else { Utils.audioManager.setMicrophoneMute(true); } return true; } } return super.onKeyUp(keyCode, event); }
From source file:com.google.zxing.client.android.CaptureActivity.java
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { switch (keyCode) { case KeyEvent.KEYCODE_BACK: if (source == IntentSource.NATIVE_APP_INTENT) { setResult(RESULT_CANCELED);/* w w w. jav a 2s.c om*/ finish(); return true; } break; 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); }
From source file:uk.org.ngo.squeezer.framework.BaseActivity.java
@Override @CallSuper/* w ww.j av a 2 s . co m*/ public boolean onKeyDown(int keyCode, KeyEvent event) { switch (keyCode) { case KeyEvent.KEYCODE_VOLUME_UP: return changeVolumeBy(+5); case KeyEvent.KEYCODE_VOLUME_DOWN: return changeVolumeBy(-5); } return super.onKeyDown(keyCode, event); }
From source file:com.qiusheng.cast.CastActivity.java
/** * Processes volume up and volume down actions upon receiving them as key * events./* w w w . ja v a 2 s . c o m*/ */ @Override public boolean dispatchKeyEvent(KeyEvent event) { int action = event.getAction(); int keyCode = event.getKeyCode(); switch (keyCode) { case KeyEvent.KEYCODE_VOLUME_UP: if (action == KeyEvent.ACTION_DOWN) { double currentVolume; if (mMessageStream != null) { currentVolume = mMessageStream.getVolume(); logVIfEnabled(TAG, "Volume up from " + currentVolume); if (currentVolume < 1.0) { logVIfEnabled(TAG, "New volume: " + (currentVolume + VOLUME_INCREMENT)); onSetVolume(currentVolume + VOLUME_INCREMENT); } } else { Log.e(TAG, "dispatchKeyEvent - volume up - mMessageStream==null"); } } return true; case KeyEvent.KEYCODE_VOLUME_DOWN: if (action == KeyEvent.ACTION_DOWN) { double currentVolume; if (mMessageStream != null) { currentVolume = mMessageStream.getVolume(); logVIfEnabled(TAG, "Volume down from: " + currentVolume); if (currentVolume > 0.0) { logVIfEnabled(TAG, "New volume: " + (currentVolume - VOLUME_INCREMENT)); onSetVolume(currentVolume - VOLUME_INCREMENT); } } else { Log.e(TAG, "dispatchKeyEvent - volume down - mMessageStream==null"); } } return true; default: return super.dispatchKeyEvent(event); } }
From source file:com.stasbar.knowyourself.alarms.AlarmActivity.java
@Override public boolean dispatchKeyEvent(@NonNull KeyEvent keyEvent) { // Do this in dispatch to intercept a few of the system keys. LOGGER.v("dispatchKeyEvent: %s", keyEvent); switch (keyEvent.getKeyCode()) { // Volume keys and camera keys dismiss the alarm. case KeyEvent.KEYCODE_POWER: case KeyEvent.KEYCODE_VOLUME_UP: case KeyEvent.KEYCODE_VOLUME_DOWN: case KeyEvent.KEYCODE_VOLUME_MUTE: case KeyEvent.KEYCODE_HEADSETHOOK: case KeyEvent.KEYCODE_CAMERA: case KeyEvent.KEYCODE_FOCUS: if (!mAlarmHandled && keyEvent.getAction() == KeyEvent.ACTION_UP) { switch (mVolumeBehavior) { case SettingsActivity.VOLUME_BEHAVIOR_SNOOZE: snooze();//ww w . ja v a2s. c om break; case SettingsActivity.VOLUME_BEHAVIOR_DISMISS: dismiss(); break; default: break; } } return true; default: return super.dispatchKeyEvent(keyEvent); } }
From source file:uk.org.ngo.squeezer.framework.BaseActivity.java
@Override @CallSuper/* ww w . j av a2s . com*/ public boolean onKeyUp(int keyCode, @NonNull KeyEvent event) { switch (keyCode) { case KeyEvent.KEYCODE_VOLUME_UP: case KeyEvent.KEYCODE_VOLUME_DOWN: return true; } return super.onKeyUp(keyCode, event); }
From source file:com.jwork.spycamera.MainFragment.java
public boolean onKeyDown(int keyCode, KeyEvent event) { log.v(this, "onKeyDown(keycode:" + keyCode + ")"); if (keyCode == KeyEvent.KEYCODE_BACK) { return controller.pressBack(); } else if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) { return controller.pressVolumeDown(); // //TODO // LinearLayout linearLayout = (LinearLayout) view.findViewById(R.id.linearLayoutPreview); // linearLayout.removeView(svPreview); // return true; } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) { return controller.pressVolumeUp(); // //TODO // LinearLayout linearLayout = (LinearLayout) view.findViewById(R.id.linearLayoutPreview); // linearLayout.addView(svPreview, 1); // return true; } else if (keyCode == KeyEvent.KEYCODE_MENU) { return controller.pressMenu(); }//ww w.j av a 2s. co m return false; }
From source file:com.android.deskclock.alarms.AlarmActivity.java
@Override public boolean dispatchKeyEvent(@NonNull KeyEvent keyEvent) { // Do this in dispatch to intercept a few of the system keys. LogUtils.v(LOGTAG, "dispatchKeyEvent: %s", keyEvent); switch (keyEvent.getKeyCode()) { // Volume keys and camera keys dismiss the alarm. case KeyEvent.KEYCODE_POWER: case KeyEvent.KEYCODE_VOLUME_UP: case KeyEvent.KEYCODE_VOLUME_DOWN: case KeyEvent.KEYCODE_VOLUME_MUTE: case KeyEvent.KEYCODE_CAMERA: case KeyEvent.KEYCODE_FOCUS: if (!mAlarmHandled && keyEvent.getAction() == KeyEvent.ACTION_UP) { switch (mVolumeBehavior) { case SettingsActivity.VOLUME_BEHAVIOR_SNOOZE: snooze();//from ww w. j av a 2 s . com break; case SettingsActivity.VOLUME_BEHAVIOR_DISMISS: dismiss(); break; default: break; } } return true; default: return super.dispatchKeyEvent(keyEvent); } }
From source file:org.protocoderrunner.base.BaseActivity.java
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { MLog.d(TAG, "" + keyCode); if (AppSettings.OVERRIDE_VOLUME_BUTTONS && (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN || keyCode == KeyEvent.KEYCODE_VOLUME_UP)) { return true; }//from www.jav a 2s. c om if (keyCode == KeyEvent.KEYCODE_BACK && AppSettings.CLOSE_WITH_BACK) { finish(); return true; } return super.onKeyDown(keyCode, event); }