diff options
author | Linux Build Service Account <lnxbuild@localhost> | 2014-11-04 23:11:01 -0800 |
---|---|---|
committer | Gerrit - the friendly Code Review server <code-review@localhost> | 2014-11-04 23:11:01 -0800 |
commit | 5344e1a11b8cab7f351bbaa27e7e17e28ed026b0 (patch) | |
tree | f7c37dea5169a059429a3f400c6c99001041106a /src/com | |
parent | 6d7c20c785ec5f1c54dceeef187357184331277c (diff) | |
parent | e354e1e5fb21ec7808584a3528e74e0ceb86ead4 (diff) | |
download | android_packages_apps_Snap-5344e1a11b8cab7f351bbaa27e7e17e28ed026b0.tar.gz android_packages_apps_Snap-5344e1a11b8cab7f351bbaa27e7e17e28ed026b0.tar.bz2 android_packages_apps_Snap-5344e1a11b8cab7f351bbaa27e7e17e28ed026b0.zip |
Merge "SnapdragonCamera: Fix NPE in camera open if UI creation takes time."
Diffstat (limited to 'src/com')
-rw-r--r-- | src/com/android/camera/FocusOverlayManager.java | 8 | ||||
-rw-r--r-- | src/com/android/camera/PhotoModule.java | 38 |
2 files changed, 37 insertions, 9 deletions
diff --git a/src/com/android/camera/FocusOverlayManager.java b/src/com/android/camera/FocusOverlayManager.java index 5efbf0178..c5ffef5c5 100644 --- a/src/com/android/camera/FocusOverlayManager.java +++ b/src/com/android/camera/FocusOverlayManager.java @@ -146,6 +146,10 @@ public class FocusOverlayManager { mUI = ui; } + public void setPhotoUI(FocusUI ui) { + mUI = ui; + } + public void setParameters(Parameters parameters) { // parameters can only be null when onConfigurationChanged is called // before camera is open. We will just return in this case, because @@ -530,7 +534,9 @@ public class FocusOverlayManager { if (!mInitialized) return; // Put focus indicator to the center. clear reset position - mUI.clearFocus(); + if (mUI != null) { + mUI.clearFocus(); + } // Initialize mFocusArea. mFocusArea = null; // Initialize mMeteringArea. diff --git a/src/com/android/camera/PhotoModule.java b/src/com/android/camera/PhotoModule.java index f9ef6fbe6..32b6a941e 100644 --- a/src/com/android/camera/PhotoModule.java +++ b/src/com/android/camera/PhotoModule.java @@ -586,7 +586,7 @@ public class PhotoModule return; } Log.v(TAG, "onPreviewUIReady"); - if (mCameraState == PREVIEW_STOPPED) { + if (mCameraState == PREVIEW_STOPPED || mCameraState == INIT) { startPreview(); } else { SurfaceTexture st = mUI.getSurfaceTexture(); @@ -624,6 +624,7 @@ public class PhotoModule Log.v(TAG, "onCameraOpened"); openCameraCommon(); resizeForPreviewAspectRatio(); + updateFocusManager(mUI); } private void switchCamera() { @@ -2224,12 +2225,22 @@ public class PhotoModule mInitialParams, this, mMirror, mActivity.getMainLooper(), mUI); } - View root = mUI.getRootView(); - // These depend on camera parameters. + } + + private void updateFocusManager(PhotoUI mUI) { + // Idea here is to let focus manager create in camera open thread + // (in initializeFocusManager) even if photoUI is null by that time so + // as to not block start preview process. Once UI creation is done, + // we will update focus manager with proper UI. + if (mFocusManager != null && mUI != null) { + mFocusManager.setPhotoUI(mUI); - int width = root.getWidth(); - int height = root.getHeight(); - mFocusManager.setPreviewSize(width, height); + View root = mUI.getRootView(); + // These depend on camera parameters. + int width = root.getWidth(); + int height = root.getHeight(); + mFocusManager.setPreviewSize(width, height); + } } @Override @@ -2437,7 +2448,11 @@ public class PhotoModule mDisplayRotation = CameraUtil.getDisplayRotation(mActivity); mDisplayOrientation = CameraUtil.getDisplayOrientation(mDisplayRotation, mCameraId); mCameraDisplayOrientation = mDisplayOrientation; - mUI.setDisplayOrientation(mDisplayOrientation); + // This will be called again in checkDisplayRotation(), so there + // should not be any problem even if mUI is null. + if (mUI != null) { + mUI.setDisplayOrientation(mDisplayOrientation); + } if (mFocusManager != null) { mFocusManager.setDisplayOrientation(mDisplayOrientation); } @@ -2462,7 +2477,14 @@ public class PhotoModule Log.v(TAG, "startPreview"); - SurfaceTexture st = mUI.getSurfaceTexture(); + SurfaceTexture st = null; + if (mUI != null) { + st = mUI.getSurfaceTexture(); + } + // Surfacetexture could be null here, but its still valid and safe to set null + // surface before startpreview. This will help in basic preview setup and + // surface creation in parallel. Once valid surface is ready in onPreviewUIReady() + // we set the surface to camera to actually start preview. mCameraDevice.setPreviewTexture(st); if (!mCameraPreviewParamsReady) { |