diff options
author | Wu-cheng Li <wuchengli@google.com> | 2010-08-31 15:04:22 -0700 |
---|---|---|
committer | Wu-cheng Li <wuchengli@google.com> | 2010-08-31 15:22:50 -0700 |
commit | 068a2e745b284b33af161d629adb9b7839be32d1 (patch) | |
tree | ab92dce26cfb77695d23600cfa4b86d3443a7adb /src | |
parent | 454c6838bb220142d05fbd6f1858ba31cc034eda (diff) | |
download | LegacyCamera-068a2e745b284b33af161d629adb9b7839be32d1.zip LegacyCamera-068a2e745b284b33af161d629adb9b7839be32d1.tar.gz LegacyCamera-068a2e745b284b33af161d629adb9b7839be32d1.tar.bz2 |
Stop and restart the preview in surfaceChanged.
If surface is changed, applications should call setPreviewDisplay
again.
Change-Id: I91072e6daba841db486b54240bb85c455588aaee
Diffstat (limited to 'src')
-rw-r--r-- | src/com/android/camera/Camera.java | 19 | ||||
-rw-r--r-- | src/com/android/camera/VideoCamera.java | 53 |
2 files changed, 27 insertions, 45 deletions
diff --git a/src/com/android/camera/Camera.java b/src/com/android/camera/Camera.java index cb76226..4008f82 100644 --- a/src/com/android/camera/Camera.java +++ b/src/com/android/camera/Camera.java @@ -1283,12 +1283,7 @@ public class Camera extends NoSearchActivity implements View.OnClickListener, // Start the preview if it is not started. if (!mPreviewing && !mStartPreviewFail) { resetExposureCompensation(); - try { - startPreview(); - } catch (CameraHardwareException e) { - showCameraErrorAndFinish(); - return; - } + if (!restartPreview()) return; } if (mSurfaceHolder != null) { @@ -1615,13 +1610,14 @@ public class Camera extends NoSearchActivity implements View.OnClickListener, ress.getString(R.string.cannot_connect_camera)); } - private void restartPreview() { + private boolean restartPreview() { try { startPreview(); } catch (CameraHardwareException e) { showCameraErrorAndFinish(); - return; + return false; } + return true; } private void setPreviewDisplay(SurfaceHolder holder) { @@ -2110,12 +2106,7 @@ public class Camera extends NoSearchActivity implements View.OnClickListener, // Restart the preview. resetExposureCompensation(); - try { - startPreview(); - } catch (CameraHardwareException e) { - showCameraErrorAndFinish(); - return; - } + if (!restartPreview()) return; initializeZoom(); diff --git a/src/com/android/camera/VideoCamera.java b/src/com/android/camera/VideoCamera.java index 8916b1b..59f6ab9 100644 --- a/src/com/android/camera/VideoCamera.java +++ b/src/com/android/camera/VideoCamera.java @@ -246,13 +246,23 @@ public class VideoCamera extends NoSearchActivity return dateFormat.format(date); } - private void showCameraBusyAndFinish() { + private void showCameraErrorAndFinish() { Resources ress = getResources(); Util.showFatalErrorAndFinish(VideoCamera.this, ress.getString(R.string.camera_error_title), ress.getString(R.string.cannot_connect_camera)); } + private boolean restartPreview() { + try { + startPreview(); + } catch (CameraHardwareException e) { + showCameraErrorAndFinish(); + return false; + } + return true; + } + @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); @@ -360,7 +370,7 @@ public class VideoCamera extends NoSearchActivity try { startPreviewThread.join(); if (mStartPreviewFail) { - showCameraBusyAndFinish(); + showCameraErrorAndFinish(); return; } } catch (InterruptedException ex) { @@ -582,12 +592,7 @@ public class VideoCamera extends NoSearchActivity readVideoPreferences(); resizeForPreviewAspectRatio(); if (!mPreviewing && !mStartPreviewFail) { - try { - startPreview(); - } catch (CameraHardwareException e) { - showCameraBusyAndFinish(); - return; - } + if (!restartPreview()) return; } keepScreenOnAwhile(); @@ -627,11 +632,6 @@ public class VideoCamera extends NoSearchActivity private void startPreview() throws CameraHardwareException { Log.v(TAG, "startPreview"); - if (mPreviewing) { - // After recording a video, preview is not stopped. So just return. - return; - } - if (mCameraDevice == null) { // If the activity is paused and resumed, camera device has been // released and we need to open the camera. @@ -780,6 +780,8 @@ public class VideoCamera extends NoSearchActivity return; } + mSurfaceHolder = holder; + if (mPausing) { // We're pausing, the screen is off and we already stopped // video recording. We don't want to start the camera again @@ -795,21 +797,20 @@ public class VideoCamera extends NoSearchActivity // finish the activity, so it's OK to ignore it. if (mCameraDevice == null) return; - if (mMediaRecorderRecording) { - stopVideoRecording(); - } - // Set preview display if the surface is being created. Preview was // already started. if (holder.isCreating()) { setPreviewDisplay(holder); mCameraDevice.unlock(); mHandler.sendEmptyMessage(INIT_RECORDER); + } else { + stopVideoRecording(); + restartPreview(); + initializeRecorder(); } } public void surfaceCreated(SurfaceHolder holder) { - mSurfaceHolder = holder; } public void surfaceDestroyed(SurfaceHolder holder) { @@ -1108,13 +1109,7 @@ public class VideoCamera extends NoSearchActivity mPreferences.setLocalId(this, mCameraId); CameraSettings.upgradeLocalPreferences(mPreferences.getLocal()); - // Restart preview - try { - startPreview(); - } catch (CameraHardwareException e) { - showCameraBusyAndFinish(); - return; - } + restartPreview(); // Reload the UI. initializeHeadUpDisplay(); @@ -1525,12 +1520,8 @@ public class VideoCamera extends NoSearchActivity // It is assumed media recorder is released before // onSharedPreferenceChanged, so we can close the camera here. closeCamera(); - try { - resizeForPreviewAspectRatio(); - startPreview(); // Parameters will be set in startPreview(). - } catch (CameraHardwareException e) { - showCameraBusyAndFinish(); - } + resizeForPreviewAspectRatio(); + restartPreview(); // Parameters will be set in startPreview(). } else { try { // We need to lock the camera before writing parameters. |