blob: 7f87f4e81dc4af6f9a08977c27bbd23071499046 [file] [log] [blame]
Angus Kong612321f2013-11-18 16:17:43 -08001/*
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
17package com.android.camera.module;
18
19import android.content.Context;
20
Sascha Haeberlingf8df06c2014-07-30 20:17:30 -070021import com.android.camera.CaptureModule;
Angus Kong612321f2013-11-18 16:17:43 -080022import com.android.camera.PhotoModule;
23import com.android.camera.VideoModule;
Angus Kongc4e66562013-11-22 23:03:21 -080024import com.android.camera.app.AppController;
Angus Kong612321f2013-11-18 16:17:43 -080025import com.android.camera.app.ModuleManager;
Andy Huibers99a37d82014-08-14 22:24:41 -070026import com.android.camera.debug.DebugPropertyHelper;
Angus Kong2bca2102014-03-11 16:27:30 -070027import com.android.camera.debug.Log;
Puneet Lall9cd94d72014-10-14 14:05:11 -070028import com.android.camera.util.ApiHelper;
Angus Kong612321f2013-11-18 16:17:43 -080029import com.android.camera.util.GcamHelper;
30import com.android.camera.util.PhotoSphereHelper;
31import com.android.camera.util.RefocusHelper;
Sascha Haeberlingf8df06c2014-07-30 20:17:30 -070032import com.android.camera.util.SystemProperties;
Doris Liubd1b8f92014-01-03 17:59:51 -080033import com.android.camera2.R;
Angus Kong612321f2013-11-18 16:17:43 -080034
35/**
36 * A class holding the module information and registers them to
37 * {@link com.android.camera.app.ModuleManager}.
38 */
39public class ModulesInfo {
Angus Kong2bca2102014-03-11 16:27:30 -070040 private static final Log.Tag TAG = new Log.Tag("ModulesInfo");
Angus Kong612321f2013-11-18 16:17:43 -080041
Andy Huibers99a37d82014-08-14 22:24:41 -070042 /** Selects CaptureModule if true, PhotoModule if false. */
Puneet Lall9cd94d72014-10-14 14:05:11 -070043 private static final boolean ENABLE_CAPTURE_MODULE = ApiHelper.HAS_CAMERA_2_API;
Sascha Haeberlingf8df06c2014-07-30 20:17:30 -070044
Angus Kong612321f2013-11-18 16:17:43 -080045 public static void setupModules(Context context, ModuleManager moduleManager) {
Doris Liubd1b8f92014-01-03 17:59:51 -080046 int photoModuleId = context.getResources().getInteger(R.integer.camera_mode_photo);
47 registerPhotoModule(moduleManager, photoModuleId);
48 moduleManager.setDefaultModuleIndex(photoModuleId);
Doris Liubd1b8f92014-01-03 17:59:51 -080049 registerVideoModule(moduleManager, context.getResources()
50 .getInteger(R.integer.camera_mode_video));
Angus Kong612321f2013-11-18 16:17:43 -080051 if (PhotoSphereHelper.hasLightCycleCapture(context)) {
Doris Liubd1b8f92014-01-03 17:59:51 -080052 registerWideAngleModule(moduleManager, context.getResources()
53 .getInteger(R.integer.camera_mode_panorama));
54 registerPhotoSphereModule(moduleManager, context.getResources()
55 .getInteger(R.integer.camera_mode_photosphere));
Angus Kong612321f2013-11-18 16:17:43 -080056 }
57 if (RefocusHelper.hasRefocusCapture(context)) {
Doris Liubd1b8f92014-01-03 17:59:51 -080058 registerRefocusModule(moduleManager, context.getResources()
59 .getInteger(R.integer.camera_mode_refocus));
Angus Kong612321f2013-11-18 16:17:43 -080060 }
Sascha Haeberling4c1bffe2014-08-21 10:01:00 -070061 if (GcamHelper.hasGcamAsSeparateModule()) {
Doris Liubd1b8f92014-01-03 17:59:51 -080062 registerGcamModule(moduleManager, context.getResources()
63 .getInteger(R.integer.camera_mode_gcam));
Angus Kong612321f2013-11-18 16:17:43 -080064 }
65 }
66
Doris Liubd1b8f92014-01-03 17:59:51 -080067 private static void registerPhotoModule(ModuleManager moduleManager, final int moduleId) {
Angus Kong612321f2013-11-18 16:17:43 -080068 moduleManager.registerModule(new ModuleManager.ModuleAgent() {
69 @Override
70 public int getModuleId() {
Doris Liubd1b8f92014-01-03 17:59:51 -080071 return moduleId;
Angus Kong612321f2013-11-18 16:17:43 -080072 }
73
74 @Override
75 public boolean requestAppForCamera() {
Sascha Haeberlingf8df06c2014-07-30 20:17:30 -070076 // The PhotoModule requests the old app camere, while the new
77 // capture module is using OneCamera. At some point we'll
78 // refactor all modules to use OneCamera, then the new module
79 // doesn't have to manage it itself.
80 return !ENABLE_CAPTURE_MODULE;
Angus Kong612321f2013-11-18 16:17:43 -080081 }
82
83 @Override
Angus Kongc4e66562013-11-22 23:03:21 -080084 public ModuleController createModule(AppController app) {
Sascha Haeberlingf8df06c2014-07-30 20:17:30 -070085 return ENABLE_CAPTURE_MODULE ? new CaptureModule(app) : new PhotoModule(app);
Angus Kong612321f2013-11-18 16:17:43 -080086 }
87 });
88 }
89
Doris Liubd1b8f92014-01-03 17:59:51 -080090 private static void registerVideoModule(ModuleManager moduleManager, final int moduleId) {
Angus Kong612321f2013-11-18 16:17:43 -080091 moduleManager.registerModule(new ModuleManager.ModuleAgent() {
92 @Override
93 public int getModuleId() {
Doris Liubd1b8f92014-01-03 17:59:51 -080094 return moduleId;
Angus Kong612321f2013-11-18 16:17:43 -080095 }
96
97 @Override
98 public boolean requestAppForCamera() {
99 return true;
100 }
101
102 @Override
Angus Kongc4e66562013-11-22 23:03:21 -0800103 public ModuleController createModule(AppController app) {
104 return new VideoModule(app);
Angus Kong612321f2013-11-18 16:17:43 -0800105 }
106 });
107 }
108
Doris Liubd1b8f92014-01-03 17:59:51 -0800109 private static void registerWideAngleModule(ModuleManager moduleManager, final int moduleId) {
Angus Kong612321f2013-11-18 16:17:43 -0800110 moduleManager.registerModule(new ModuleManager.ModuleAgent() {
111 @Override
112 public int getModuleId() {
Doris Liubd1b8f92014-01-03 17:59:51 -0800113 return moduleId;
Angus Kong612321f2013-11-18 16:17:43 -0800114 }
115
116 @Override
117 public boolean requestAppForCamera() {
Angus Kongaff95be2013-12-05 12:40:24 -0800118 return true;
Angus Kong612321f2013-11-18 16:17:43 -0800119 }
120
121 @Override
Angus Kongc4e66562013-11-22 23:03:21 -0800122 public ModuleController createModule(AppController app) {
Angus Kongaff95be2013-12-05 12:40:24 -0800123 return PhotoSphereHelper.createWideAnglePanoramaModule(app);
Angus Kong612321f2013-11-18 16:17:43 -0800124 }
125 });
126 }
127
Doris Liubd1b8f92014-01-03 17:59:51 -0800128 private static void registerPhotoSphereModule(ModuleManager moduleManager, final int moduleId) {
Angus Kong612321f2013-11-18 16:17:43 -0800129 moduleManager.registerModule(new ModuleManager.ModuleAgent() {
130 @Override
131 public int getModuleId() {
Doris Liubd1b8f92014-01-03 17:59:51 -0800132 return moduleId;
Angus Kong612321f2013-11-18 16:17:43 -0800133 }
134
135 @Override
136 public boolean requestAppForCamera() {
Angus Kong18500a42013-11-21 18:14:14 -0800137 return true;
Angus Kong612321f2013-11-18 16:17:43 -0800138 }
139
140 @Override
Angus Kongc4e66562013-11-22 23:03:21 -0800141 public ModuleController createModule(AppController app) {
Angus Kongaff95be2013-12-05 12:40:24 -0800142 return PhotoSphereHelper.createPanoramaModule(app);
Angus Kong612321f2013-11-18 16:17:43 -0800143 }
144 });
145 }
146
Doris Liubd1b8f92014-01-03 17:59:51 -0800147 private static void registerRefocusModule(ModuleManager moduleManager, final int moduleId) {
Angus Kong612321f2013-11-18 16:17:43 -0800148 moduleManager.registerModule(new ModuleManager.ModuleAgent() {
149 @Override
150 public int getModuleId() {
Doris Liubd1b8f92014-01-03 17:59:51 -0800151 return moduleId;
Angus Kong612321f2013-11-18 16:17:43 -0800152 }
153
154 @Override
155 public boolean requestAppForCamera() {
Angus Kong18500a42013-11-21 18:14:14 -0800156 return true;
Angus Kong612321f2013-11-18 16:17:43 -0800157 }
158
159 @Override
Angus Kongc4e66562013-11-22 23:03:21 -0800160 public ModuleController createModule(AppController app) {
Sascha Haeberling42db0352013-12-13 18:31:39 -0800161 return RefocusHelper.createRefocusModule(app);
Angus Kong612321f2013-11-18 16:17:43 -0800162 }
163 });
164 }
165
Doris Liubd1b8f92014-01-03 17:59:51 -0800166 private static void registerGcamModule(ModuleManager moduleManager, final int moduleId) {
Angus Kong612321f2013-11-18 16:17:43 -0800167 moduleManager.registerModule(new ModuleManager.ModuleAgent() {
168 @Override
169 public int getModuleId() {
Doris Liubd1b8f92014-01-03 17:59:51 -0800170 return moduleId;
Angus Kong612321f2013-11-18 16:17:43 -0800171 }
172
173 @Override
174 public boolean requestAppForCamera() {
175 return false;
176 }
177
178 @Override
Angus Kongc4e66562013-11-22 23:03:21 -0800179 public ModuleController createModule(AppController app) {
Sascha Haeberling42db0352013-12-13 18:31:39 -0800180 return GcamHelper.createGcamModule(app);
Angus Kong612321f2013-11-18 16:17:43 -0800181 }
182 });
183 }
184}