From 80583a299a9c8964cf09e482380c3bda0670ad6f Mon Sep 17 00:00:00 2001 From: Chih-yu Huang Date: Fri, 18 Nov 2011 14:40:47 +0800 Subject: Fix NPE in panorama when camera failed to connect. bug:5637587 Change-Id: Iea275b4e3780a41f4a0c3fe0845acbfdb1e95cd1 --- .../android/camera/panorama/PanoramaActivity.java | 38 ++++++++++------------ 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/src/com/android/camera/panorama/PanoramaActivity.java b/src/com/android/camera/panorama/PanoramaActivity.java index a99e7be..be0df40 100755 --- a/src/com/android/camera/panorama/PanoramaActivity.java +++ b/src/com/android/camera/panorama/PanoramaActivity.java @@ -320,7 +320,7 @@ public class PanoramaActivity extends ActivityBase implements }; } - private void setupCamera() { + private void setupCamera() throws CameraHardwareException, CameraDisabledException { openCamera(); Parameters parameters = mCameraDevice.getParameters(); setupCaptureParams(parameters); @@ -336,18 +336,10 @@ public class PanoramaActivity extends ActivityBase implements } } - private void openCamera() { - try { - int backCameraId = CameraHolder.instance().getBackCameraId(); - mCameraDevice = Util.openCamera(this, backCameraId); - mCameraOrientation = Util.getCameraOrientation(backCameraId); - } catch (CameraHardwareException e) { - Util.showErrorAndFinish(this, R.string.cannot_connect_camera); - return; - } catch (CameraDisabledException e) { - Util.showErrorAndFinish(this, R.string.camera_disabled); - return; - } + private void openCamera() throws CameraHardwareException, CameraDisabledException { + int backCameraId = CameraHolder.instance().getBackCameraId(); + mCameraDevice = Util.openCamera(this, backCameraId); + mCameraOrientation = Util.getCameraOrientation(backCameraId); } private boolean findBestPreviewSize(List supportedSizes, boolean need4To3, @@ -988,15 +980,21 @@ public class PanoramaActivity extends ActivityBase implements mOrientationEventListener.enable(); mCaptureState = CAPTURE_STATE_VIEWFINDER; - setupCamera(); + try { + setupCamera(); - // Camera must be initialized before MosaicFrameProcessor is initialized. The preview size - // has to be decided by camera device. - initMosaicFrameProcessorIfNeeded(); - mMosaicView.onResume(); + // Camera must be initialized before MosaicFrameProcessor is initialized. + // The preview size has to be decided by camera device. + initMosaicFrameProcessorIfNeeded(); + mMosaicView.onResume(); - initThumbnailButton(); - keepScreenOnAwhile(); + initThumbnailButton(); + keepScreenOnAwhile(); + } catch (CameraHardwareException e) { + Util.showErrorAndFinish(this, R.string.cannot_connect_camera); + } catch (CameraDisabledException e) { + Util.showErrorAndFinish(this, R.string.camera_disabled); + } } /** -- cgit v1.1