• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2013 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.module;
18 
19 import android.content.Context;
20 import android.content.Intent;
21 import android.content.res.Resources;
22 
23 import com.android.camera.CaptureModule;
24 import com.android.camera.PhotoModule;
25 import com.android.camera.VideoModule;
26 import com.android.camera.app.AppController;
27 import com.android.camera.app.ModuleManager;
28 import com.android.camera.captureintent.CaptureIntentModule;
29 import com.android.camera.debug.Log;
30 import com.android.camera.one.OneCamera;
31 import com.android.camera.one.OneCameraException;
32 import com.android.camera.one.config.OneCameraFeatureConfig;
33 import com.android.camera.one.config.OneCameraFeatureConfig.HdrPlusSupportLevel;
34 import com.android.camera.settings.SettingsScopeNamespaces;
35 import com.android.camera.util.GcamHelper;
36 import com.android.camera.util.PhotoSphereHelper;
37 import com.android.camera.util.RefocusHelper;
38 import com.android.camera2.R;
39 
40 /**
41  * A class holding the module information and registers them to
42  * {@link com.android.camera.app.ModuleManager}.
43  */
44 public class ModulesInfo {
45     private static final Log.Tag TAG = new Log.Tag("ModulesInfo");
46 
setupModules(Context context, ModuleManager moduleManager, OneCameraFeatureConfig config)47     public static void setupModules(Context context, ModuleManager moduleManager,
48             OneCameraFeatureConfig config) {
49         Resources res = context.getResources();
50         int photoModuleId = context.getResources().getInteger(R.integer.camera_mode_photo);
51         registerPhotoModule(moduleManager, photoModuleId, SettingsScopeNamespaces.PHOTO,
52                 config.isUsingCaptureModule());
53         moduleManager.setDefaultModuleIndex(photoModuleId);
54         registerVideoModule(moduleManager, res.getInteger(R.integer.camera_mode_video),
55                 SettingsScopeNamespaces.VIDEO);
56         if (PhotoSphereHelper.hasLightCycleCapture(context)) {
57             registerWideAngleModule(moduleManager, res.getInteger(R.integer.camera_mode_panorama),
58                     SettingsScopeNamespaces.PANORAMA);
59             registerPhotoSphereModule(moduleManager,
60                     res.getInteger(R.integer.camera_mode_photosphere),
61                     SettingsScopeNamespaces.PANORAMA);
62         }
63         if (RefocusHelper.hasRefocusCapture(context)) {
64             registerRefocusModule(moduleManager, res.getInteger(R.integer.camera_mode_refocus),
65                     SettingsScopeNamespaces.REFOCUS);
66         }
67         if (GcamHelper.hasGcamAsSeparateModule(config)) {
68             registerGcamModule(moduleManager, res.getInteger(R.integer.camera_mode_gcam),
69                     SettingsScopeNamespaces.PHOTO,
70                     config.getHdrPlusSupportLevel(OneCamera.Facing.BACK));
71         }
72         int imageCaptureIntentModuleId = res.getInteger(R.integer.camera_mode_capture_intent);
73         registerCaptureIntentModule(moduleManager, imageCaptureIntentModuleId,
74                 SettingsScopeNamespaces.PHOTO, config.isUsingCaptureModule());
75     }
76 
registerPhotoModule(ModuleManager moduleManager, final int moduleId, final String namespace, final boolean enableCaptureModule)77     private static void registerPhotoModule(ModuleManager moduleManager, final int moduleId,
78             final String namespace, final boolean enableCaptureModule) {
79         moduleManager.registerModule(new ModuleManager.ModuleAgent() {
80 
81             @Override
82             public int getModuleId() {
83                 return moduleId;
84             }
85 
86             @Override
87             public boolean requestAppForCamera() {
88                 // The PhotoModule requests the old app camere, while the new
89                 // capture module is using OneCamera. At some point we'll
90                 // refactor all modules to use OneCamera, then the new module
91                 // doesn't have to manage it itself.
92                 return !enableCaptureModule;
93             }
94 
95             @Override
96             public String getScopeNamespace() {
97                 return namespace;
98             }
99 
100             @Override
101             public ModuleController createModule(AppController app, Intent intent) {
102                 Log.v(TAG, "EnableCaptureModule = " + enableCaptureModule);
103                 return enableCaptureModule ? new CaptureModule(app) : new PhotoModule(app);
104             }
105         });
106     }
107 
registerVideoModule(ModuleManager moduleManager, final int moduleId, final String namespace)108     private static void registerVideoModule(ModuleManager moduleManager, final int moduleId,
109             final String namespace) {
110         moduleManager.registerModule(new ModuleManager.ModuleAgent() {
111             @Override
112             public int getModuleId() {
113                 return moduleId;
114             }
115 
116             @Override
117             public boolean requestAppForCamera() {
118                 return true;
119             }
120 
121             @Override
122             public String getScopeNamespace() {
123                 return namespace;
124             }
125 
126             @Override
127             public ModuleController createModule(AppController app, Intent intent) {
128                 return new VideoModule(app);
129             }
130         });
131     }
132 
registerWideAngleModule(ModuleManager moduleManager, final int moduleId, final String namespace)133     private static void registerWideAngleModule(ModuleManager moduleManager, final int moduleId,
134             final String namespace) {
135         moduleManager.registerModule(new ModuleManager.ModuleAgent() {
136             @Override
137             public int getModuleId() {
138                 return moduleId;
139             }
140 
141             @Override
142             public boolean requestAppForCamera() {
143                 return true;
144             }
145 
146             @Override
147             public String getScopeNamespace() {
148                 return namespace;
149             }
150 
151             @Override
152             public ModuleController createModule(AppController app, Intent intent) {
153                 return PhotoSphereHelper.createWideAnglePanoramaModule(app);
154             }
155         });
156     }
157 
registerPhotoSphereModule(ModuleManager moduleManager, final int moduleId, final String namespace)158     private static void registerPhotoSphereModule(ModuleManager moduleManager, final int moduleId,
159             final String namespace) {
160         moduleManager.registerModule(new ModuleManager.ModuleAgent() {
161             @Override
162             public int getModuleId() {
163                 return moduleId;
164             }
165 
166             @Override
167             public boolean requestAppForCamera() {
168                 return true;
169             }
170 
171             @Override
172             public String getScopeNamespace() {
173                 return namespace;
174             }
175 
176             @Override
177             public ModuleController createModule(AppController app, Intent intent) {
178                 return PhotoSphereHelper.createPanoramaModule(app);
179             }
180         });
181     }
182 
registerRefocusModule(ModuleManager moduleManager, final int moduleId, final String namespace)183     private static void registerRefocusModule(ModuleManager moduleManager, final int moduleId,
184             final String namespace) {
185         moduleManager.registerModule(new ModuleManager.ModuleAgent() {
186             @Override
187             public int getModuleId() {
188                 return moduleId;
189             }
190 
191             @Override
192             public boolean requestAppForCamera() {
193                 return true;
194             }
195 
196             @Override
197             public String getScopeNamespace() {
198                 return namespace;
199             }
200 
201             @Override
202             public ModuleController createModule(AppController app, Intent intent) {
203                 return RefocusHelper.createRefocusModule(app);
204             }
205         });
206     }
207 
registerGcamModule(ModuleManager moduleManager, final int moduleId, final String namespace, final HdrPlusSupportLevel hdrPlusSupportLevel)208     private static void registerGcamModule(ModuleManager moduleManager, final int moduleId,
209             final String namespace, final HdrPlusSupportLevel hdrPlusSupportLevel) {
210         moduleManager.registerModule(new ModuleManager.ModuleAgent() {
211             @Override
212             public int getModuleId() {
213                 return moduleId;
214             }
215 
216             @Override
217             public boolean requestAppForCamera() {
218                 return false;
219             }
220 
221             @Override
222             public String getScopeNamespace() {
223                 return namespace;
224             }
225 
226             @Override
227             public ModuleController createModule(AppController app, Intent intent) {
228                 return GcamHelper.createGcamModule(app, hdrPlusSupportLevel);
229             }
230         });
231     }
232 
registerCaptureIntentModule(ModuleManager moduleManager, final int moduleId, final String namespace, final boolean enableCaptureModule)233     private static void registerCaptureIntentModule(ModuleManager moduleManager, final int moduleId,
234             final String namespace, final boolean enableCaptureModule) {
235         moduleManager.registerModule(new ModuleManager.ModuleAgent() {
236             @Override
237             public int getModuleId() {
238                 return moduleId;
239             }
240 
241             @Override
242             public boolean requestAppForCamera() {
243                 return !enableCaptureModule;
244             }
245 
246             @Override
247             public String getScopeNamespace() {
248                 return namespace;
249             }
250 
251             @Override
252             public ModuleController createModule(AppController app, Intent intent) {
253                 if(enableCaptureModule) {
254                     try {
255                         return new CaptureIntentModule(app, intent, namespace);
256                     } catch (OneCameraException ignored) {
257                     }
258                 }
259                 return new PhotoModule(app);
260             }
261         });
262     }
263 }
264