@Override public boolean onKeyDown(int keyCode, KeyEvent event) { switch (keyCode) { case KeyEvent.KEYCODE_FOCUS: if (mFirstTimeInitialized && event.getRepeatCount() == 0) { doFocus(true); } return true; case KeyEvent.KEYCODE_CAMERA: if (mFirstTimeInitialized && event.getRepeatCount() == 0) { doSnap(); } return true; case 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. doFocus(true); if (mShutterButton.isInTouchMode()) { mShutterButton.requestFocusFromTouch(); } else { mShutterButton.requestFocus(); } mShutterButton.setPressed(true); } return true; } return super.onKeyDown(keyCode, event); }
@Override public void onShutterButtonFocus(ShutterButton button, boolean pressed) { if (mPausing) { return; } switch (button.getId()) { case R.id.shutter_button: doFocus(pressed); break; } }
@Override public void onShutterButtonClick(ShutterButton button) { if (mPausing) { return; } switch (button.getId()) { case R.id.shutter_button: doSnap(); break; } }
// Snapshots can only be taken after this is called. It should be called // once only. We could have done these things in onCreate() but we want to // make preview screen appear as soon as possible. private void initializeFirstTime() { if (mFirstTimeInitialized) return; // Create orientation listenter. This should be done first because it // takes some time to get first orientation. mOrientationListener = new OrientationEventListener(this) { @Override public void onOrientationChanged(int orientation) { // We keep the last known orientation. So if the user // first orient the camera then point the camera to if (orientation == ORIENTATION_UNKNOWN) return; mLastOrientation = roundOrientation(orientation); int orientationCompensation = mLastOrientation + getDisplayRotation(); if (mOrientationCompensation != orientationCompensation) { mOrientationCompensation = orientationCompensation; setOrientationIndicator(mOrientationCompensation); } } }; mOrientationListener.enable(); keepMediaProviderInstance(); checkStorage(); // Initialize last picture button. mContentResolver = getContentResolver(); // Initialize shutter button. mShutterButton = (ShutterButton) findViewById(R.id.shutter_button); mShutterButton.setOnShutterButtonListener(this); mShutterButton.setVisibility(View.VISIBLE); mFocusRectangle = (FocusRectangle) findViewById(R.id.focus_rectangle); updateFocusIndicator(); initializeScreenBrightness(); installIntentFilter(); mFirstTimeInitialized = true; }