OSDN Git Service

Decouple OneCameraManager and CameraActivity.
authorSenpo Hu <senpo@google.com>
Wed, 4 Mar 2015 01:45:35 +0000 (17:45 -0800)
committerSenpo Hu <senpo@google.com>
Wed, 4 Mar 2015 20:29:17 +0000 (12:29 -0800)
1. To allow other activity (such as SettingsActivity) to
create OneCameraManager.

2. Also simplify OneCameraManager.open() and OneCameraCreator.create()
interface by introducing OneCameraCaptureSetting. From time to time,
we always need to change these interfaces if we want to pass in more
things to OneCamera. This solves the headache and also removes the
dependency between OneCameraCreator and SettingsManager.

Bug: 18523154
Change-Id: Ifb9077bb046740c600dab3b3b369a0f422dbbbeb

src/com/android/camera/CameraActivity.java
src/com/android/camera/CaptureModule.java
src/com/android/camera/captureintent/state/StateOpeningCamera.java
src/com/android/camera/one/OneCameraCaptureSetting.java [new file with mode: 0644]
src/com/android/camera/one/OneCameraManager.java
src/com/android/camera/one/config/OneCameraFeatureConfig.java
src/com/android/camera/one/config/OneCameraFeatureConfigCreator.java
src/com/android/camera/one/v1/OneCameraManagerImpl.java
src/com/android/camera/one/v2/OneCameraManagerImpl.java
src_pd/com/android/camera/one/v2/OneCameraCreator.java

index 00a3eb7..c6c2491 100644 (file)
@@ -1419,7 +1419,8 @@ public class CameraActivity extends QuickActivity
         mOrientationManager = new OrientationManagerImpl(this, mMainHandler);
         mSettingsManager = getServices().getSettingsManager();
         mSoundPlayer = new SoundPlayer(mAppContext);
-        mFeatureConfig = OneCameraFeatureConfigCreator.createDefault(getContentResolver());
+        mFeatureConfig = OneCameraFeatureConfigCreator.createDefault(getContentResolver(),
+                getServices().getMemoryManager());
 
         profile.mark();
         if (!Glide.isSetup()) {
@@ -1448,8 +1449,8 @@ public class CameraActivity extends QuickActivity
         }
         profile.mark("Glide.setup");
         try {
-            mCameraManager = OneCameraManager.get(this, ResolutionUtil.getDisplayMetrics(this),
-                    mFeatureConfig);
+            mCameraManager = OneCameraManager.get(
+                    mFeatureConfig, mAppContext, ResolutionUtil.getDisplayMetrics(this));
         } catch (OneCameraException e) {
             // Log error and continue. Modules requiring OneCamera should check
             // and handle if null by showing error dialog or other treatment.
index 9f55104..c2d9ba0 100644 (file)
@@ -57,6 +57,7 @@ import com.android.camera.one.OneCamera.Facing;
 import com.android.camera.one.OneCamera.OpenCallback;
 import com.android.camera.one.OneCamera.PhotoCaptureParameters;
 import com.android.camera.one.OneCameraAccessException;
+import com.android.camera.one.OneCameraCaptureSetting;
 import com.android.camera.one.OneCameraCharacteristics;
 import com.android.camera.one.OneCameraManager;
 import com.android.camera.one.v2.OneCameraManagerImpl;
@@ -1212,15 +1213,20 @@ public class CaptureModule extends CameraModule implements
         // Only enable GCam on the back camera
         boolean useHdr = mHdrPlusEnabled && mCameraFacing == Facing.BACK;
 
+        OneCameraCaptureSetting captureSetting;
         // Read the preferred picture size from the setting.
         try {
-            mPictureSize = mAppController.getResolutionSetting().getPictureSize(mCameraFacing);
+            captureSetting = OneCameraCaptureSetting.create(
+                    mCameraFacing, mAppController.getResolutionSetting(), mSettingsManager,
+                    mAppController.getModuleScope(), useHdr);
         } catch (OneCameraAccessException ex) {
             mAppController.showErrorAndFinish(R.string.cannot_connect_camera);
             return;
         }
+        mPictureSize = captureSetting.getCaptureSize();
 
-        mCameraManager.open(mCameraFacing, useHdr, mPictureSize,
+        mCameraManager.open(captureSetting, mCameraHandler, mainThread,
+                imageRotationCalculator, mBurstController, mSoundPlayer,
                 new OpenCallback() {
                     @Override
                     public void onFailure() {
@@ -1312,7 +1318,7 @@ public class CaptureModule extends CameraModule implements
                                     }
                                 });
                         }
-                }, mCameraHandler, mainThread, imageRotationCalculator, mBurstController);
+                });
         guard.stop("mCameraManager.open()");
     }
 
index 628bf2b..eec1bca 100644 (file)
@@ -18,6 +18,7 @@ package com.android.camera.captureintent.state;
 
 import com.google.common.base.Optional;
 
+import com.android.camera.SoundPlayer;
 import com.android.camera.async.RefCountBase;
 import com.android.camera.burst.BurstFacadeFactory;
 import com.android.camera.captureintent.event.Event;
@@ -26,6 +27,7 @@ import com.android.camera.captureintent.event.EventOnOpenCameraSucceeded;
 import com.android.camera.debug.Log;
 import com.android.camera.one.OneCamera;
 import com.android.camera.one.OneCameraAccessException;
+import com.android.camera.one.OneCameraCaptureSetting;
 import com.android.camera.one.OneCameraCharacteristics;
 import com.android.camera.one.v2.photo.ImageRotationCalculator;
 import com.android.camera.one.v2.photo.ImageRotationCalculatorImpl;
@@ -114,10 +116,15 @@ public final class StateOpeningCamera extends State {
             return Optional.of((State) StateFatal.from(this, mResourceConstructed));
         }
 
+        OneCameraCaptureSetting captureSetting;
         try {
-            /** Read the picture size from the setting. */
-            mPictureSize = mResourceConstructed.get().getResolutionSetting().getPictureSize(
-                    mCameraFacing);
+            captureSetting = OneCameraCaptureSetting.create(
+                    mCameraFacing,
+                    mResourceConstructed.get().getResolutionSetting(),
+                    mResourceConstructed.get().getAppController().getSettingsManager(),
+                    mResourceConstructed.get().getAppController().getModuleScope(),
+                    false);
+            mPictureSize = captureSetting.getCaptureSize();
         } catch (OneCameraAccessException ex) {
             Log.e(TAG, "Failed while open camera", ex);
             return Optional.of((State) StateFatal.from(this, mResourceConstructed));
@@ -125,15 +132,15 @@ public final class StateOpeningCamera extends State {
 
         final ImageRotationCalculator imageRotationCalculator = ImageRotationCalculatorImpl.from(
                 mResourceConstructed.get().getOrientationManager(), mCameraCharacteristics);
+
         mResourceConstructed.get().getCameraManager().open(
-                mCameraFacing,
-                false,
-                mPictureSize,
-                mCameraOpenCallback,
+                captureSetting,
                 mResourceConstructed.get().getCameraHandler(),
                 mResourceConstructed.get().getMainThread(),
                 imageRotationCalculator,
-                new BurstFacadeFactory.BurstFacadeStub());
+                new BurstFacadeFactory.BurstFacadeStub(),
+                new SoundPlayer(mResourceConstructed.get().getContext()),
+                mCameraOpenCallback);
         return Optional.absent();
     }
 
diff --git a/src/com/android/camera/one/OneCameraCaptureSetting.java b/src/com/android/camera/one/OneCameraCaptureSetting.java
new file mode 100644 (file)
index 0000000..3882f2d
--- /dev/null
@@ -0,0 +1,97 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.camera.one;
+
+import com.android.camera.async.Observable;
+import com.android.camera.settings.Keys;
+import com.android.camera.settings.ResolutionSetting;
+import com.android.camera.settings.SettingObserver;
+import com.android.camera.settings.SettingsManager;
+import com.android.camera.util.Size;
+
+/**
+ * Contains related settings to configure a camera for a particular type of
+ * capture.
+ */
+public class OneCameraCaptureSetting {
+    private final OneCamera.Facing mCameraFacing;
+    private final Size mCaptureSize;
+    private final Observable<OneCamera.PhotoCaptureParameters.Flash> mFlashSetting;
+    private final Observable<Integer> mExposureSetting;
+    private final Observable<Boolean> mHdrSceneSetting;
+    private final boolean mIsHdrPlusEnabled;
+
+    public static OneCameraCaptureSetting create(
+            OneCamera.Facing cameraFacing,
+            ResolutionSetting resolutionSetting,
+            SettingsManager settingsManager,
+            String cameraSettingScope,
+            boolean isHdrPlusEnabled) throws OneCameraAccessException {
+        Observable<OneCamera.PhotoCaptureParameters.Flash> flashSetting = new FlashSetting(
+                SettingObserver.ofString(settingsManager, cameraSettingScope, Keys.KEY_FLASH_MODE));
+        Observable<Integer> exposureSetting = SettingObserver.ofInteger(
+                settingsManager, cameraSettingScope, Keys.KEY_EXPOSURE);
+        Observable<Boolean> hdrSceneSetting = SettingObserver.ofBoolean(
+                settingsManager, SettingsManager.SCOPE_GLOBAL, Keys.KEY_CAMERA_HDR);
+        return new OneCameraCaptureSetting(
+                cameraFacing,
+                resolutionSetting.getPictureSize(cameraFacing),
+                flashSetting,
+                exposureSetting,
+                hdrSceneSetting,
+                isHdrPlusEnabled);
+    }
+
+    private OneCameraCaptureSetting(
+            OneCamera.Facing cameraFacing,
+            Size captureSize,
+            Observable<OneCamera.PhotoCaptureParameters.Flash> flashSetting,
+            Observable<Integer> exposureSetting,
+            Observable<Boolean> hdrSceneSetting,
+            boolean isHdrPlusEnabled) {
+        mCameraFacing = cameraFacing;
+        mCaptureSize = captureSize;
+        mFlashSetting = flashSetting;
+        mExposureSetting = exposureSetting;
+        mHdrSceneSetting = hdrSceneSetting;
+        mIsHdrPlusEnabled = isHdrPlusEnabled;
+    }
+
+    public OneCamera.Facing getCameraFacing() {
+        return mCameraFacing;
+    }
+
+    public Size getCaptureSize() {
+        return mCaptureSize;
+    }
+
+    public Observable<OneCamera.PhotoCaptureParameters.Flash> getFlashSetting() {
+        return mFlashSetting;
+    }
+
+    public Observable<Integer> getExposureSetting() {
+        return mExposureSetting;
+    }
+
+    public Observable<Boolean> getHdrSceneSetting() {
+        return mHdrSceneSetting;
+    }
+
+    public boolean isHdrPlusEnabled() {
+        return mIsHdrPlusEnabled;
+    }
+}
index c8ace24..d017ee4 100644 (file)
 
 package com.android.camera.one;
 
+import android.content.Context;
 import android.os.Handler;
 import android.util.DisplayMetrics;
 
-import com.android.camera.CameraActivity;
+import com.android.camera.SoundPlayer;
 import com.android.camera.async.MainThread;
 import com.android.camera.burst.BurstFacade;
 import com.android.camera.debug.Log.Tag;
@@ -27,6 +28,7 @@ import com.android.camera.one.OneCamera.Facing;
 import com.android.camera.one.OneCamera.OpenCallback;
 import com.android.camera.one.config.OneCameraFeatureConfig;
 import com.android.camera.one.v2.photo.ImageRotationCalculator;
+import com.android.camera.settings.SettingsManager;
 import com.android.camera.util.Size;
 import com.google.common.base.Optional;
 
@@ -44,23 +46,24 @@ public abstract class OneCameraManager {
      * Exactly one call will always be made to a single method in the provided
      * {@link OpenCallback}.
      *
-     * @param facing which camera to open. The first camera found in the given
-     *            direction will be opened.
-     * @param enableHdr if an HDR feature exists, open a camera that supports it
-     * @param captureSize the capture size. This must be one of the supported
-     *            sizes.
-     * @param callback this listener is called when the camera was opened or
-     *            when it failed to open.
+     * @param captureSetting the related settings to configure the camera for capture.
      * @param handler the handler on which callback methods are invoked.
      * @param mainThread Main thread executor
      * @param imageRotationCalculator Image rotation calculator required for
      *            Camera Factory initialization
      * @param burstController the burst facade to configure
+     * @param soundPlayer the sound player.
+     * @param openCallback this listener is called when the camera was opened or
+     *            when it failed to open.
      */
-    public abstract void open(Facing facing, boolean enableHdr, Size captureSize,
-            OpenCallback callback, Handler handler,
-            MainThread mainThread, final ImageRotationCalculator imageRotationCalculator,
-            BurstFacade burstController);
+    public abstract void open(
+            OneCameraCaptureSetting captureSetting,
+            Handler handler,
+            MainThread mainThread,
+            ImageRotationCalculator imageRotationCalculator,
+            BurstFacade burstController,
+            SoundPlayer soundPlayer,
+            OpenCallback openCallback);
 
     // TODO: Move this to OneCameraCharacteristics class.
     /**
@@ -87,9 +90,11 @@ public abstract class OneCameraManager {
      * @throws OneCameraException Thrown if an error occurred while trying to
      *             access the camera.
      */
-    public static OneCameraManager get(CameraActivity activity, DisplayMetrics displayMetrics,
-            OneCameraFeatureConfig featureConfig) throws OneCameraException {
-        return create(activity, displayMetrics, featureConfig);
+    public static OneCameraManager get(
+            OneCameraFeatureConfig featureConfig,
+            Context context,
+            DisplayMetrics displayMetrics) throws OneCameraException {
+        return create(featureConfig, context, displayMetrics);
     }
 
     /**
@@ -98,13 +103,14 @@ public abstract class OneCameraManager {
      * @throws OneCameraException Thrown if an error occurred while trying to
      *             access the camera.
      */
-    private static OneCameraManager create(CameraActivity activity, DisplayMetrics displayMetrics,
-             OneCameraFeatureConfig featureConfig) throws OneCameraException {
-        Optional<OneCameraManager> manager =
-                com.android.camera.one.v2.OneCameraManagerImpl.create(activity, displayMetrics,
-                        featureConfig);
+    private static OneCameraManager create(
+            OneCameraFeatureConfig featureConfig,
+            Context context,
+            DisplayMetrics displayMetrics) throws OneCameraException {
+        Optional<OneCameraManager> manager = com.android.camera.one.v2.OneCameraManagerImpl.create(
+                        featureConfig, context, displayMetrics);
         if (!manager.isPresent()) {
-            manager = com.android.camera.one.v1.OneCameraManagerImpl.create(activity);
+            manager = com.android.camera.one.v1.OneCameraManagerImpl.create();
         }
         if (!manager.isPresent()) {
             throw new OneCameraException("No camera manager is available.");
index adf3c9e..15e86fb 100644 (file)
@@ -80,13 +80,27 @@ public class OneCameraFeatureConfig {
     private final Function<CameraCharacteristics, CaptureSupportLevel> mCaptureModeDetector;
     /** The level of HDR+ support. */
     private final HdrPlusSupportLevel mHdrPlusSupportLevel;
+    /**
+     * The maximum amount of memory can be consumed by all opened cameras
+     * during capture and processing, in megabytes.
+     */
+    private final int mMaxMemoryMB;
+
+    /**
+     * The maximum number of images the camera should allocate in the image reader.
+     */
+    private final int mMaxAllowedImageReaderCount;
 
     OneCameraFeatureConfig(boolean useCaptureModule,
             Function<CameraCharacteristics, CaptureSupportLevel> captureModeDetector,
-            HdrPlusSupportLevel hdrPlusSupportLevel) {
+            HdrPlusSupportLevel hdrPlusSupportLevel,
+            int maxMemoryMB,
+            int maxAllowedImageReaderCount) {
         mUseCaptureModule = useCaptureModule;
         mCaptureModeDetector = captureModeDetector;
         mHdrPlusSupportLevel = hdrPlusSupportLevel;
+        mMaxMemoryMB = maxMemoryMB;
+        mMaxAllowedImageReaderCount = maxAllowedImageReaderCount;
     }
 
     /**
@@ -111,4 +125,20 @@ public class OneCameraFeatureConfig {
     public HdrPlusSupportLevel getHdrPlusSupportLevel() {
         return mHdrPlusSupportLevel;
     }
+
+    /**
+     * @return The maximum amount of memory can be consumed by all opened
+     *         cameras during capture and processing, in megabytes.
+     */
+    public int getMaxMemoryMB() {
+        return mMaxMemoryMB;
+    }
+
+    /**
+     * @return The maximum number of images the camera should allocate in the
+     *         image reader.
+     */
+    public int getMaxAllowedImageReaderCount() {
+        return mMaxAllowedImageReaderCount;
+    }
 }
index 5613c88..e08907f 100644 (file)
@@ -19,6 +19,7 @@ package com.android.camera.one.config;
 import android.content.ContentResolver;
 import android.hardware.camera2.CameraCharacteristics;
 
+import com.android.camera.app.MemoryManager;
 import com.android.camera.debug.Log;
 import com.android.camera.one.config.OneCameraFeatureConfig.CaptureSupportLevel;
 import com.android.camera.one.config.OneCameraFeatureConfig.HdrPlusSupportLevel;
@@ -37,7 +38,8 @@ public class OneCameraFeatureConfigCreator {
     /**
      * Create the default camera feature config.
      */
-    public static OneCameraFeatureConfig createDefault(ContentResolver contentResolver) {
+    public static OneCameraFeatureConfig createDefault(ContentResolver contentResolver,
+            MemoryManager memoryManager) {
         // Enable CaptureModule on all L devices unless the device is
         // black-listed.
         boolean useCaptureModule = ApiHelper.HAS_CAMERA_2_API
@@ -49,7 +51,9 @@ public class OneCameraFeatureConfigCreator {
                 GcamHelper.determineHdrPlusSupportLevel(contentResolver, useCaptureModule);
         return new OneCameraFeatureConfig(useCaptureModule,
                 buildCaptureModuleDetector(contentResolver),
-                hdrPlusSupportLevel);
+                hdrPlusSupportLevel,
+                memoryManager.getMaxAllowedNativeMemoryAllocation(),
+                GservicesHelper.getMaxAllowedImageReaderCount(contentResolver));
     }
 
     private static Function<CameraCharacteristics, CaptureSupportLevel> buildCaptureModuleDetector(
index b7aa4ba..b7dd9f3 100644 (file)
@@ -20,15 +20,18 @@ import android.hardware.Camera;
 import android.os.Handler;
 
 import com.android.camera.CameraActivity;
+import com.android.camera.SoundPlayer;
 import com.android.camera.async.MainThread;
 import com.android.camera.burst.BurstFacade;
 import com.android.camera.debug.Log;
 import com.android.camera.one.OneCamera.Facing;
 import com.android.camera.one.OneCamera.OpenCallback;
 import com.android.camera.one.OneCameraAccessException;
+import com.android.camera.one.OneCameraCaptureSetting;
 import com.android.camera.one.OneCameraCharacteristics;
 import com.android.camera.one.OneCameraManager;
 import com.android.camera.one.v2.photo.ImageRotationCalculator;
+import com.android.camera.settings.SettingsManager;
 import com.android.camera.util.Size;
 import com.google.common.base.Optional;
 /**
@@ -46,7 +49,7 @@ public class OneCameraManagerImpl extends OneCameraManager {
     private OneCameraCharacteristics mBackCameraCharacteristics;
     private OneCameraCharacteristics mFrontCameraCharacteristics;
 
-    public static Optional<OneCameraManager> create(CameraActivity activity) {
+    public static Optional<OneCameraManager> create() {
         int numberOfCameras;
         Camera.CameraInfo[] cameraInfos;
         try {
@@ -92,10 +95,14 @@ public class OneCameraManagerImpl extends OneCameraManager {
     }
 
     @Override
-    public void open(Facing facing, boolean enableHdr, Size pictureSize,
-            OpenCallback callback, Handler handler,
+    public void open(
+            OneCameraCaptureSetting captureSetting,
+            Handler handler,
             MainThread mainThread,
-            ImageRotationCalculator imageRotationCalculator, BurstFacade burstController) {
+            ImageRotationCalculator imageRotationCalculator,
+            BurstFacade burstController,
+            SoundPlayer soundPlayer,
+            OpenCallback openCallback) {
         throw new RuntimeException("Not implemented yet.");
     }
 
index 8546df3..4cab1b0 100644 (file)
@@ -17,6 +17,7 @@
 package com.android.camera.one.v2;
 
 import android.annotation.TargetApi;
+import android.content.Context;
 import android.hardware.camera2.CameraAccessException;
 import android.hardware.camera2.CameraCharacteristics;
 import android.hardware.camera2.CameraDevice;
@@ -25,9 +26,7 @@ import android.os.Build;
 import android.os.Handler;
 import android.util.DisplayMetrics;
 
-import com.android.camera.CameraActivity;
 import com.android.camera.SoundPlayer;
-import com.android.camera.app.AppController;
 import com.android.camera.async.MainThread;
 import com.android.camera.burst.BurstFacade;
 import com.android.camera.debug.Log;
@@ -36,14 +35,13 @@ import com.android.camera.one.OneCamera;
 import com.android.camera.one.OneCamera.Facing;
 import com.android.camera.one.OneCamera.OpenCallback;
 import com.android.camera.one.OneCameraAccessException;
+import com.android.camera.one.OneCameraCaptureSetting;
 import com.android.camera.one.OneCameraCharacteristics;
 import com.android.camera.one.OneCameraManager;
 import com.android.camera.one.config.OneCameraFeatureConfig;
 import com.android.camera.one.v2.photo.ImageRotationCalculator;
 import com.android.camera.util.AndroidServices;
 import com.android.camera.util.ApiHelper;
-import com.android.camera.util.GservicesHelper;
-import com.android.camera.util.Size;
 
 import com.google.common.base.Optional;
 
@@ -54,16 +52,15 @@ import com.google.common.base.Optional;
 public class OneCameraManagerImpl extends OneCameraManager {
     private static final Tag TAG = new Tag("OneCameraMgrImpl2");
 
-    private final AppController mAppController;
+    private final Context mContext;
     private final OneCameraFeatureConfig mFeatureConfig;
     private final CameraManager mCameraManager;
-    private final int mMaxMemoryMB;
-    private final int mMaxImages;
     private final DisplayMetrics mDisplayMetrics;
-    private final SoundPlayer mSoundPlayer;
 
-    public static Optional<OneCameraManager> create(CameraActivity activity,
-            DisplayMetrics displayMetrics, OneCameraFeatureConfig featureConfig) {
+    public static Optional<OneCameraManager> create(
+            OneCameraFeatureConfig featureConfig,
+            Context context,
+            DisplayMetrics displayMetrics) {
         if (!ApiHelper.HAS_CAMERA_2_API) {
             return Optional.absent();
         }
@@ -74,14 +71,8 @@ public class OneCameraManagerImpl extends OneCameraManager {
             Log.e(TAG, "camera2.CameraManager is not available.");
             return Optional.absent();
         }
-        final int maxMemoryMB = activity.getServices().getMemoryManager()
-                .getMaxAllowedNativeMemoryAllocation();
-        final SoundPlayer soundPlayer = activity.getSoundPlayer();
-        final int maxImages = GservicesHelper.
-                getMaxAllowedImageReaderCount(activity.getContentResolver());
         OneCameraManager oneCameraManager = new OneCameraManagerImpl(
-                activity, featureConfig, cameraManager, maxMemoryMB, maxImages, displayMetrics,
-                soundPlayer);
+                featureConfig, context, cameraManager, displayMetrics);
         return Optional.of(oneCameraManager);
     }
 
@@ -89,29 +80,28 @@ public class OneCameraManagerImpl extends OneCameraManager {
      * Instantiates a new {@link OneCameraManager} for Camera2 API.
      *
      * @param cameraManager the underlying Camera2 camera manager.
-     * @param maxMemoryMB maximum amount of memory opened cameras should consume
-     *            during capture and processing, in megabytes.
      */
-    public OneCameraManagerImpl(AppController appController, OneCameraFeatureConfig featureConfig,
-            CameraManager cameraManager, int maxMemoryMB, int maxImages,
-            DisplayMetrics displayMetrics, SoundPlayer soundPlayer) {
-        mAppController = appController;
+    public OneCameraManagerImpl(OneCameraFeatureConfig featureConfig,
+            Context context,
+            CameraManager cameraManager,
+            DisplayMetrics displayMetrics) {
         mFeatureConfig = featureConfig;
+        mContext = context;
         mCameraManager = cameraManager;
-        mMaxMemoryMB = maxMemoryMB;
-        mMaxImages = maxImages;
         mDisplayMetrics = displayMetrics;
-        mSoundPlayer = soundPlayer;
     }
 
     @Override
-    public void open(Facing facing, final boolean useHdr, final Size pictureSize,
-            final OpenCallback openCallback,
-            Handler handler, final MainThread mainThread,
+    public void open(
+            final OneCameraCaptureSetting captureSetting,
+            final Handler handler,
+            final MainThread mainThread,
             final ImageRotationCalculator imageRotationCalculator,
-            final BurstFacade burstController) {
+            final BurstFacade burstController,
+            final SoundPlayer soundPlayer,
+            final OpenCallback openCallback) {
         try {
-            final String cameraId = getCameraId(facing);
+            final String cameraId = getCameraId(captureSetting.getCameraFacing());
             Log.i(TAG, "Opening Camera ID " + cameraId);
             mCameraManager.openCamera(cameraId, new CameraDevice.StateCallback() {
                 // We may get multiple calls to StateCallback, but only the
@@ -158,10 +148,17 @@ public class OneCameraManagerImpl extends OneCameraManager {
                                     .getCameraCharacteristics(device.getId());
                             // TODO: Set boolean based on whether HDR+ is
                             // enabled.
-                            OneCamera oneCamera = OneCameraCreator.create(mAppController, useHdr,
-                                    mFeatureConfig, device, characteristics, pictureSize,
-                                    mMaxMemoryMB, mMaxImages, mDisplayMetrics, mSoundPlayer,
-                                    mainThread, imageRotationCalculator, burstController);
+                            OneCamera oneCamera = OneCameraCreator.create(
+                                    device,
+                                    characteristics,
+                                    mFeatureConfig,
+                                    captureSetting,
+                                    mDisplayMetrics,
+                                    mContext,
+                                    mainThread,
+                                    imageRotationCalculator,
+                                    burstController,
+                                    soundPlayer);
                             openCallback.onCameraOpened(oneCamera);
                         } catch (CameraAccessException e) {
                             Log.d(TAG, "Could not get camera characteristics");
index 248caa9..acdc7a8 100644 (file)
 
 package com.android.camera.one.v2;
 
+import android.content.Context;
 import android.hardware.camera2.CameraCharacteristics;
 import android.hardware.camera2.CameraDevice;
 import android.util.DisplayMetrics;
 
 import com.android.camera.SoundPlayer;
-import com.android.camera.app.AppController;
 import com.android.camera.async.MainThread;
 import com.android.camera.burst.BurstFacade;
 import com.android.camera.one.OneCamera;
+import com.android.camera.one.OneCameraCaptureSetting;
 import com.android.camera.one.config.OneCameraFeatureConfig;
 import com.android.camera.one.v2.photo.ImageRotationCalculator;
 import com.android.camera.util.Size;
 
 public class OneCameraCreator {
-    public static OneCamera create(AppController context, boolean useHdr,
-            OneCameraFeatureConfig featureConfig, CameraDevice device,
-            CameraCharacteristics characteristics, Size pictureSize,
-            int maxMemoryMB, int maxImages,
-            DisplayMetrics displayMetrics, SoundPlayer soundPlayer,
-            MainThread mainThread, ImageRotationCalculator imageRotationCalculator,
-            BurstFacade burstController) {
+    public static OneCamera create(
+            CameraDevice device,
+            CameraCharacteristics characteristics,
+            OneCameraFeatureConfig featureConfig,
+            OneCameraCaptureSetting captureSetting,
+            DisplayMetrics displayMetrics,
+            Context context,
+            MainThread mainThread,
+            ImageRotationCalculator imageRotationCalculator,
+            BurstFacade burstController,
+            SoundPlayer soundPlayer) {
         // TODO: Might want to switch current camera to vendor HDR.
-        return new OneCameraImpl(device, characteristics, pictureSize);
+        return new OneCameraImpl(device, characteristics, captureSetting.getCaptureSize());
     }
 }