Home | History | Annotate | Download | only in resource
      1 /*
      2  * Copyright (C) 2015 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package com.android.camera.captureintent.resource;
     18 
     19 import android.content.Context;
     20 import android.content.Intent;
     21 import android.os.Handler;
     22 import android.os.HandlerThread;
     23 
     24 import com.android.camera.FatalErrorHandler;
     25 import com.android.camera.SoundPlayer;
     26 import com.android.camera.app.AppController;
     27 import com.android.camera.app.LocationManager;
     28 import com.android.camera.app.OrientationManager;
     29 import com.android.camera.async.MainThread;
     30 import com.android.camera.async.RefCountBase;
     31 import com.android.camera.burst.BurstFacade;
     32 import com.android.camera.captureintent.CaptureIntentModuleUI;
     33 import com.android.camera.one.OneCameraManager;
     34 import com.android.camera.one.OneCameraOpener;
     35 import com.android.camera.settings.CameraFacingSetting;
     36 import com.android.camera.settings.ResolutionSetting;
     37 import com.android.camera.settings.SettingsManager;
     38 
     39 public final class ResourceConstructedImpl implements ResourceConstructed {
     40     private final Intent mIntent;
     41     private final CaptureIntentModuleUI mModuleUI;
     42     private final String mSettingScopeNamespace;
     43     private final MainThread mMainThread;
     44     private final Context mContext;
     45     private final OneCameraOpener mOneCameraOpener;
     46     private final OneCameraManager mOneCameraManager;
     47     private final LocationManager mLocationManager;
     48     private final OrientationManager mOrientationManager;
     49     private final SettingsManager mSettingsManager;
     50     private final BurstFacade mBurstFacade;
     51     private final CameraFacingSetting mCameraFacingSetting;
     52     private final ResolutionSetting mResolutionSetting;
     53     private final HandlerThread mCameraThread;
     54     private final Handler mCameraHandler;
     55     private final FatalErrorHandler mFatalErrorHandler;
     56     private final SoundPlayer mSoundPlayer;
     57 
     58     // TODO: Hope one day we could get rid of AppController.
     59     private final AppController mAppController;
     60 
     61     /**
     62      * Creates a reference counted {@link ResourceConstructedImpl} object.
     63      */
     64     public static RefCountBase<ResourceConstructed> create(
     65             Intent intent,
     66             CaptureIntentModuleUI moduleUI,
     67             String settingScopeNamespace,
     68             MainThread mainThread,
     69             Context context,
     70             OneCameraOpener oneCameraOpener,
     71             OneCameraManager oneCameraManager,
     72             LocationManager locationManager,
     73             OrientationManager orientationManager,
     74             SettingsManager settingsManager,
     75             BurstFacade burstFacade,
     76             AppController appController,
     77             FatalErrorHandler fatalErrorHandler) {
     78         final CameraFacingSetting cameraFacingSetting = new CameraFacingSetting(
     79                 context.getResources(), settingsManager, settingScopeNamespace);
     80         final ResolutionSetting resolutionSetting = new ResolutionSetting(
     81                 settingsManager, oneCameraManager, context.getContentResolver());
     82         return new RefCountBase<ResourceConstructed>(new ResourceConstructedImpl(
     83                 intent, moduleUI, settingScopeNamespace, mainThread, context, oneCameraOpener,
     84                 oneCameraManager, locationManager, orientationManager, settingsManager, burstFacade,
     85                 cameraFacingSetting, resolutionSetting, appController, fatalErrorHandler));
     86     }
     87 
     88     private ResourceConstructedImpl(
     89             Intent intent,
     90             CaptureIntentModuleUI moduleUI,
     91             String settingScopeNamespace,
     92             MainThread mainThread,
     93             Context context,
     94             OneCameraOpener cameraManager,
     95             OneCameraManager hardwareManager,
     96             LocationManager locationManager,
     97             OrientationManager orientationManager,
     98             SettingsManager settingsManager,
     99             BurstFacade burstFacade,
    100             CameraFacingSetting cameraFacingSetting,
    101             ResolutionSetting resolutionSetting,
    102             AppController appController,
    103             FatalErrorHandler fatalErrorHandler) {
    104         mIntent = intent;
    105         mModuleUI = moduleUI;
    106         mSettingScopeNamespace = settingScopeNamespace;
    107         mMainThread = mainThread;
    108         mContext = context;
    109         mOneCameraOpener = cameraManager;
    110         mOneCameraManager = hardwareManager;
    111         mLocationManager = locationManager;
    112         mOrientationManager = orientationManager;
    113         mSettingsManager = settingsManager;
    114         mBurstFacade = burstFacade;
    115         mCameraFacingSetting = cameraFacingSetting;
    116         mResolutionSetting = resolutionSetting;
    117         mFatalErrorHandler = fatalErrorHandler;
    118         mSoundPlayer = new SoundPlayer(mContext);
    119         mAppController = appController;
    120 
    121         mCameraThread = new HandlerThread("ImageCaptureIntentModule.CameraHandler");
    122         mCameraThread.start();
    123         mCameraHandler = new Handler(mCameraThread.getLooper());
    124     }
    125 
    126     @Override
    127     public void close() {
    128         mCameraThread.quit();
    129     }
    130 
    131     @Override
    132     public Intent getIntent() {
    133         return mIntent;
    134     }
    135 
    136     @Override
    137     public CaptureIntentModuleUI getModuleUI() {
    138         return mModuleUI;
    139     }
    140 
    141     @Override
    142     public String getSettingScopeNamespace() {
    143         return mSettingScopeNamespace;
    144     }
    145 
    146     @Override
    147     public MainThread getMainThread() {
    148         return mMainThread;
    149     }
    150 
    151     @Override
    152     public Context getContext() {
    153         return mContext;
    154     }
    155 
    156     @Override
    157     public OneCameraManager getOneCameraManager() {
    158         return mOneCameraManager;
    159     }
    160 
    161     @Override
    162     public OneCameraOpener getOneCameraOpener() {
    163         return mOneCameraOpener;
    164     }
    165 
    166     @Override
    167     public LocationManager getLocationManager() {
    168         return mLocationManager;
    169     }
    170 
    171     @Override
    172     public OrientationManager getOrientationManager() {
    173         return mOrientationManager;
    174     }
    175 
    176     @Override
    177     public SettingsManager getSettingsManager() {
    178         return mSettingsManager;
    179     }
    180 
    181     @Override
    182     public BurstFacade getBurstFacade() {
    183         return mBurstFacade;
    184     }
    185 
    186     @Override
    187     public CameraFacingSetting getCameraFacingSetting() {
    188         return mCameraFacingSetting;
    189     }
    190 
    191     @Override
    192     public ResolutionSetting getResolutionSetting() {
    193         return mResolutionSetting;
    194     }
    195 
    196     @Override
    197     public Handler getCameraHandler() {
    198         return mCameraHandler;
    199     }
    200 
    201     @Override
    202     public SoundPlayer getSoundPlayer() {
    203         return mSoundPlayer;
    204     }
    205 
    206     @Override
    207     public AppController getAppController() {
    208         return mAppController;
    209     }
    210 
    211     @Override
    212     public FatalErrorHandler getFatalErrorHandler() {
    213         return mFatalErrorHandler;
    214     }
    215 }
    216