@Override public boolean onKeyDown(int keyCode, KeyEvent event) { switch (keyCode) { case KeyEvent.KEYCODE_FOCUS: Log.i(TAG, "doSnap: KeyEvent.KEYCODE_FOCUS"); if (mFirstTimeInitialized && event.getRepeatCount() == 0) { doFocus(true); } return true; case KeyEvent.KEYCODE_CAMERA: Log.i(TAG, "doSnap: KeyEvent.KEYCODE_CAMERA"); if (mFirstTimeInitialized && event.getRepeatCount() == 0) { doSnap(); } return true; case KeyEvent.KEYCODE_DPAD_CENTER: Log.i(TAG, "doSnap:KeyEvent.KEYCODE_DPAD_CENTER"); // If we get a dpad center event without any focused view, move // the focus to the shutter button and press it. if (mFirstTimeInitialized && event.getRepeatCount() == 0) { // Start auto-focus immediately to reduce shutter lag. After // the shutter button gets the focus, doFocus() will be // called again but it is fine. if (mHeadUpDisplay.collapse()) return true; doFocus(true); if (mShutterButton.isInTouchMode()) { mShutterButton.requestFocusFromTouch(); } else { mShutterButton.requestFocus(); } mShutterButton.setPressed(true); } return true; case KeyEvent.KEYCODE_BACK: Log.i(TAG, "KeyEvent.KEYCODE_BACK"); if(mCameraDevice!=null){ mCameraDevice.sendCommand(CAMERA_CMD_FRONT_CAMERA, 0, 0); mCameraDevice.sendCommand(CAMERA_CMD_BACK_CAMERA, 0, 0); finish(); } return true; case KeyEvent.KEYCODE_HOME: Log.i(TAG, "KeyEvent.KEYCODE_HOME"); if(mCameraDevice!=null){ mCameraDevice.sendCommand(CAMERA_CMD_FRONT_CAMERA, 0, 0); mCameraDevice.sendCommand(CAMERA_CMD_BACK_CAMERA, 0, 0); finish(); } return true; }