diff options
author | Wu-cheng Li <wuchengli@google.com> | 2011-10-13 14:49:17 +0800 |
---|---|---|
committer | Wu-cheng Li <wuchengli@google.com> | 2011-10-13 18:21:52 +0800 |
commit | 1bca5eaaa3c6d3fd36df572546715e4e515cf9e6 (patch) | |
tree | bfd1050c73758a06568fcc61f4098684b974d796 /src/com/android | |
parent | 73ab0023b4a9d86ac5fa844116a83aa6c52acf0c (diff) | |
download | packages_apps_LegacyCamera-1bca5eaaa3c6d3fd36df572546715e4e515cf9e6.zip packages_apps_LegacyCamera-1bca5eaaa3c6d3fd36df572546715e4e515cf9e6.tar.gz packages_apps_LegacyCamera-1bca5eaaa3c6d3fd36df572546715e4e515cf9e6.tar.bz2 |
Simplify code about ShutterButton.
bug:5447399
Change-Id: I240d7523509f27d333a0ef69e6e0d3228a41e9de
Diffstat (limited to 'src/com/android')
-rw-r--r-- | src/com/android/camera/Camera.java | 86 | ||||
-rwxr-xr-x | src/com/android/camera/ShutterButton.java | 14 | ||||
-rw-r--r-- | src/com/android/camera/VideoCamera.java | 46 | ||||
-rwxr-xr-x | src/com/android/camera/panorama/PanoramaActivity.java | 9 |
4 files changed, 66 insertions, 89 deletions
diff --git a/src/com/android/camera/Camera.java b/src/com/android/camera/Camera.java index 4a311de..6574b98 100644 --- a/src/com/android/camera/Camera.java +++ b/src/com/android/camera/Camera.java @@ -173,7 +173,7 @@ public class Camera extends ActivityBase implements FocusManager.Listener, private Runnable mDoSnapRunnable = new Runnable() { public void run() { - doSnap(); + onShutterButtonClick(); } }; @@ -1320,25 +1320,41 @@ public class Camera extends ActivityBase implements FocusManager.Listener, } @Override - public void onShutterButtonFocus(ShutterButton button, boolean pressed) { - switch (button.getId()) { - case R.id.shutter_button: - doFocus(pressed); - break; - } + public void onShutterButtonFocus(boolean pressed) { + if (mPausing || collapseCameraControls() || mCameraState == SNAPSHOT_IN_PROGRESS) return; + + // Do not do focus if there is not enough storage. + if (pressed && !canTakePicture()) return; + + mFocusManager.doFocus(pressed); } @Override - public void onShutterButtonClick(ShutterButton button) { - switch (button.getId()) { - case R.id.shutter_button: - doSnap(); - break; + public void onShutterButtonClick() { + if (mPausing || collapseCameraControls()) return; + + // Do not take the picture if there is not enough storage. + if (mPicturesRemaining <= 0) { + Log.i(TAG, "Not enough space or storage not ready. remaining=" + mPicturesRemaining); + return; + } + + Log.v(TAG, "onShutterButtonClick: mCameraState=" + mCameraState); + + // If the user wants to do a snapshot while the previous one is still + // in progress, remember the fact and do it after we finish the previous + // one and re-start the preview. + if (mCameraState == SNAPSHOT_IN_PROGRESS) { + mSnapshotOnIdle = true; + return; } + + mSnapshotOnIdle = false; + mFocusManager.doSnap(); } @Override - public void onShutterButtonLongPressed(ShutterButton button) { + public void onShutterButtonLongPressed() { if (mPausing || mCameraState == SNAPSHOT_IN_PROGRESS || mCameraDevice == null || mPicturesRemaining <= 0) return; @@ -1551,12 +1567,12 @@ public class Camera extends ActivityBase implements FocusManager.Listener, switch (keyCode) { case KeyEvent.KEYCODE_FOCUS: if (mFirstTimeInitialized && event.getRepeatCount() == 0) { - doFocus(true); + onShutterButtonFocus(true); } return true; case KeyEvent.KEYCODE_CAMERA: if (mFirstTimeInitialized && event.getRepeatCount() == 0) { - doSnap(); + onShutterButtonClick(); } return true; case KeyEvent.KEYCODE_DPAD_CENTER: @@ -1564,10 +1580,10 @@ public class Camera extends ActivityBase implements FocusManager.Listener, // 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. + // the shutter button gets the focus, onShutterButtonFocus() + // will be called again but it is fine. if (collapseCameraControls()) return true; - doFocus(true); + onShutterButtonFocus(true); if (mShutterButton.isInTouchMode()) { mShutterButton.requestFocusFromTouch(); } else { @@ -1586,45 +1602,13 @@ public class Camera extends ActivityBase implements FocusManager.Listener, switch (keyCode) { case KeyEvent.KEYCODE_FOCUS: if (mFirstTimeInitialized) { - doFocus(false); + onShutterButtonFocus(false); } return true; } return super.onKeyUp(keyCode, event); } - private void doSnap() { - if (mPausing || collapseCameraControls()) return; - - // Do not take the picture if there is not enough storage. - if (mPicturesRemaining <= 0) { - Log.i(TAG, "Not enough space or storage not ready. remaining=" + mPicturesRemaining); - return; - } - - Log.v(TAG, "doSnap: mCameraState=" + mCameraState); - - // If the user wants to do a snapshot while the previous one is still - // in progress, remember the fact and do it after we finish the previous - // one and re-start the preview. - if (mCameraState == SNAPSHOT_IN_PROGRESS) { - mSnapshotOnIdle = true; - return; - } - - mSnapshotOnIdle = false; - mFocusManager.doSnap(); - } - - private void doFocus(boolean pressed) { - if (mPausing || collapseCameraControls() || mCameraState == SNAPSHOT_IN_PROGRESS) return; - - // Do not do focus if there is not enough storage. - if (pressed && !canTakePicture()) return; - - mFocusManager.doFocus(pressed); - } - public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) { // Make sure we have a surface in the holder before proceeding. if (holder.getSurface() == null) { diff --git a/src/com/android/camera/ShutterButton.java b/src/com/android/camera/ShutterButton.java index e44afe5..ace154e 100755 --- a/src/com/android/camera/ShutterButton.java +++ b/src/com/android/camera/ShutterButton.java @@ -34,17 +34,17 @@ public class ShutterButton extends ImageView implements View.OnLongClickListener /** * Called when a ShutterButton has been pressed. * - * @param b The ShutterButton that was pressed. + * @param pressed The ShutterButton that was pressed. */ - void onShutterButtonFocus(ShutterButton b, boolean pressed); - void onShutterButtonClick(ShutterButton b); + void onShutterButtonFocus(boolean pressed); + void onShutterButtonClick(); } /** * A callback to be invoked when a ShutterButton's long pressed. */ public interface OnShutterButtonLongPressListener { - void onShutterButtonLongPressed(ShutterButton b); + void onShutterButtonLongPressed(); } private OnShutterButtonListener mListener; @@ -110,7 +110,7 @@ public class ShutterButton extends ImageView implements View.OnLongClickListener private void callShutterButtonFocus(boolean pressed) { if (mListener != null) { - mListener.onShutterButtonFocus(this, pressed); + mListener.onShutterButtonFocus(pressed); } } @@ -118,7 +118,7 @@ public class ShutterButton extends ImageView implements View.OnLongClickListener public boolean performClick() { boolean result = super.performClick(); if (mListener != null) { - mListener.onShutterButtonClick(this); + mListener.onShutterButtonClick(); } return result; } @@ -126,7 +126,7 @@ public class ShutterButton extends ImageView implements View.OnLongClickListener @Override public boolean onLongClick(View v) { if (mLongPressListener != null) { - mLongPressListener.onShutterButtonLongPressed(this); + mLongPressListener.onShutterButtonLongPressed(); } return false; } diff --git a/src/com/android/camera/VideoCamera.java b/src/com/android/camera/VideoCamera.java index 5fddcf7..783377e 100644 --- a/src/com/android/camera/VideoCamera.java +++ b/src/com/android/camera/VideoCamera.java @@ -599,10 +599,6 @@ public class VideoCamera extends ActivityBase doReturnToCaller(false); } - public void onShutterButtonFocus(ShutterButton button, boolean pressed) { - // Do nothing (everything happens in onShutterButtonClick). - } - private void onStopVideoRecording(boolean valid) { stopVideoRecording(); if (mIsVideoCaptureIntent) { @@ -620,30 +616,32 @@ public class VideoCamera extends ActivityBase // Consume clicks } - public void onShutterButtonClick(ShutterButton button) { - switch (button.getId()) { - case R.id.shutter_button: - if (collapseCameraControls()) return; - boolean stop = mMediaRecorderRecording; + @Override + public void onShutterButtonClick() { + if (collapseCameraControls()) return; + boolean stop = mMediaRecorderRecording; - if (stop) { - onStopVideoRecording(true); - } else { - startVideoRecording(); - } - mShutterButton.setEnabled(false); - - // Keep the shutter button disabled when in video capture intent - // mode and recording is stopped. It'll be re-enabled when - // re-take button is clicked. - if (!(mIsVideoCaptureIntent && stop)) { - mHandler.sendEmptyMessageDelayed( - ENABLE_SHUTTER_BUTTON, SHUTTER_BUTTON_TIMEOUT); - } - break; + if (stop) { + onStopVideoRecording(true); + } else { + startVideoRecording(); + } + mShutterButton.setEnabled(false); + + // Keep the shutter button disabled when in video capture intent + // mode and recording is stopped. It'll be re-enabled when + // re-take button is clicked. + if (!(mIsVideoCaptureIntent && stop)) { + mHandler.sendEmptyMessageDelayed( + ENABLE_SHUTTER_BUTTON, SHUTTER_BUTTON_TIMEOUT); } } + @Override + public void onShutterButtonFocus(boolean pressed) { + // Do nothing (everything happens in onShutterButtonClick). + } + private OnScreenHint mStorageHint; private void updateAndShowStorageHint() { diff --git a/src/com/android/camera/panorama/PanoramaActivity.java b/src/com/android/camera/panorama/PanoramaActivity.java index 53b4733..f11bc3a 100755 --- a/src/com/android/camera/panorama/PanoramaActivity.java +++ b/src/com/android/camera/panorama/PanoramaActivity.java @@ -32,10 +32,6 @@ import com.android.camera.Util; import com.android.camera.ui.RotateImageView; import com.android.camera.ui.SharePopup; -import android.animation.AnimatorSet; -import android.animation.ObjectAnimator; -import android.animation.ValueAnimator; -import android.app.Activity; import android.app.AlertDialog; import android.app.ProgressDialog; import android.content.ContentResolver; @@ -67,7 +63,6 @@ import android.view.OrientationEventListener; import android.view.View; import android.view.Window; import android.view.WindowManager; -import android.view.animation.LinearInterpolator; import android.widget.ImageView; import android.widget.TextView; @@ -703,7 +698,7 @@ public class PanoramaActivity extends ActivityBase implements } @Override - public void onShutterButtonClick(ShutterButton b) { + public void onShutterButtonClick() { // If mSurfaceTexture == null then GL setup is not finished yet. // No buttons can be pressed. if (mPausing || mThreadRunning || mSurfaceTexture == null) return; @@ -719,7 +714,7 @@ public class PanoramaActivity extends ActivityBase implements } @Override - public void onShutterButtonFocus(ShutterButton b, boolean pressed) { + public void onShutterButtonFocus(boolean pressed) { } public void reportProgress() { |