blob: b77116862bc940493b35dc503227ead7af697203 [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
21import com.android.camera.PhotoModule;
22import com.android.camera.VideoModule;
Angus Kongc4e66562013-11-22 23:03:21 -080023import com.android.camera.app.AppController;
Angus Kong612321f2013-11-18 16:17:43 -080024import com.android.camera.app.ModuleManager;
Angus Kong2bca2102014-03-11 16:27:30 -070025import com.android.camera.debug.Log;
Angus Kong612321f2013-11-18 16:17:43 -080026import com.android.camera.util.GcamHelper;
27import com.android.camera.util.PhotoSphereHelper;
28import com.android.camera.util.RefocusHelper;
Doris Liubd1b8f92014-01-03 17:59:51 -080029import com.android.camera2.R;
Angus Kong612321f2013-11-18 16:17:43 -080030
31/**
32 * A class holding the module information and registers them to
33 * {@link com.android.camera.app.ModuleManager}.
34 */
35public class ModulesInfo {
Angus Kong2bca2102014-03-11 16:27:30 -070036 private static final Log.Tag TAG = new Log.Tag("ModulesInfo");
Angus Kong612321f2013-11-18 16:17:43 -080037
Angus Kong612321f2013-11-18 16:17:43 -080038 public static void setupModules(Context context, ModuleManager moduleManager) {
Doris Liubd1b8f92014-01-03 17:59:51 -080039 int photoModuleId = context.getResources().getInteger(R.integer.camera_mode_photo);
40 registerPhotoModule(moduleManager, photoModuleId);
41 moduleManager.setDefaultModuleIndex(photoModuleId);
Doris Liubd1b8f92014-01-03 17:59:51 -080042 registerVideoModule(moduleManager, context.getResources()
43 .getInteger(R.integer.camera_mode_video));
Angus Kong612321f2013-11-18 16:17:43 -080044 if (PhotoSphereHelper.hasLightCycleCapture(context)) {
Doris Liubd1b8f92014-01-03 17:59:51 -080045 registerWideAngleModule(moduleManager, context.getResources()
46 .getInteger(R.integer.camera_mode_panorama));
47 registerPhotoSphereModule(moduleManager, context.getResources()
48 .getInteger(R.integer.camera_mode_photosphere));
Angus Kong612321f2013-11-18 16:17:43 -080049 }
50 if (RefocusHelper.hasRefocusCapture(context)) {
Doris Liubd1b8f92014-01-03 17:59:51 -080051 registerRefocusModule(moduleManager, context.getResources()
52 .getInteger(R.integer.camera_mode_refocus));
Angus Kong612321f2013-11-18 16:17:43 -080053 }
54 if (GcamHelper.hasGcamCapture()) {
Doris Liubd1b8f92014-01-03 17:59:51 -080055 registerGcamModule(moduleManager, context.getResources()
56 .getInteger(R.integer.camera_mode_gcam));
Angus Kong612321f2013-11-18 16:17:43 -080057 }
58 }
59
Doris Liubd1b8f92014-01-03 17:59:51 -080060 private static void registerPhotoModule(ModuleManager moduleManager, final int moduleId) {
Angus Kong612321f2013-11-18 16:17:43 -080061 moduleManager.registerModule(new ModuleManager.ModuleAgent() {
62 @Override
63 public int getModuleId() {
Doris Liubd1b8f92014-01-03 17:59:51 -080064 return moduleId;
Angus Kong612321f2013-11-18 16:17:43 -080065 }
66
67 @Override
68 public boolean requestAppForCamera() {
69 return true;
70 }
71
72 @Override
Angus Kongc4e66562013-11-22 23:03:21 -080073 public ModuleController createModule(AppController app) {
74 return new PhotoModule(app);
Angus Kong612321f2013-11-18 16:17:43 -080075 }
76 });
77 }
78
Doris Liubd1b8f92014-01-03 17:59:51 -080079 private static void registerVideoModule(ModuleManager moduleManager, final int moduleId) {
Angus Kong612321f2013-11-18 16:17:43 -080080 moduleManager.registerModule(new ModuleManager.ModuleAgent() {
81 @Override
82 public int getModuleId() {
Doris Liubd1b8f92014-01-03 17:59:51 -080083 return moduleId;
Angus Kong612321f2013-11-18 16:17:43 -080084 }
85
86 @Override
87 public boolean requestAppForCamera() {
88 return true;
89 }
90
91 @Override
Angus Kongc4e66562013-11-22 23:03:21 -080092 public ModuleController createModule(AppController app) {
93 return new VideoModule(app);
Angus Kong612321f2013-11-18 16:17:43 -080094 }
95 });
96 }
97
Doris Liubd1b8f92014-01-03 17:59:51 -080098 private static void registerWideAngleModule(ModuleManager moduleManager, final int moduleId) {
Angus Kong612321f2013-11-18 16:17:43 -080099 moduleManager.registerModule(new ModuleManager.ModuleAgent() {
100 @Override
101 public int getModuleId() {
Doris Liubd1b8f92014-01-03 17:59:51 -0800102 return moduleId;
Angus Kong612321f2013-11-18 16:17:43 -0800103 }
104
105 @Override
106 public boolean requestAppForCamera() {
Angus Kongaff95be2013-12-05 12:40:24 -0800107 return true;
Angus Kong612321f2013-11-18 16:17:43 -0800108 }
109
110 @Override
Angus Kongc4e66562013-11-22 23:03:21 -0800111 public ModuleController createModule(AppController app) {
Angus Kongaff95be2013-12-05 12:40:24 -0800112 return PhotoSphereHelper.createWideAnglePanoramaModule(app);
Angus Kong612321f2013-11-18 16:17:43 -0800113 }
114 });
115 }
116
Doris Liubd1b8f92014-01-03 17:59:51 -0800117 private static void registerPhotoSphereModule(ModuleManager moduleManager, final int moduleId) {
Angus Kong612321f2013-11-18 16:17:43 -0800118 moduleManager.registerModule(new ModuleManager.ModuleAgent() {
119 @Override
120 public int getModuleId() {
Doris Liubd1b8f92014-01-03 17:59:51 -0800121 return moduleId;
Angus Kong612321f2013-11-18 16:17:43 -0800122 }
123
124 @Override
125 public boolean requestAppForCamera() {
Angus Kong18500a42013-11-21 18:14:14 -0800126 return true;
Angus Kong612321f2013-11-18 16:17:43 -0800127 }
128
129 @Override
Angus Kongc4e66562013-11-22 23:03:21 -0800130 public ModuleController createModule(AppController app) {
Angus Kongaff95be2013-12-05 12:40:24 -0800131 return PhotoSphereHelper.createPanoramaModule(app);
Angus Kong612321f2013-11-18 16:17:43 -0800132 }
133 });
134 }
135
Doris Liubd1b8f92014-01-03 17:59:51 -0800136 private static void registerRefocusModule(ModuleManager moduleManager, final int moduleId) {
Angus Kong612321f2013-11-18 16:17:43 -0800137 moduleManager.registerModule(new ModuleManager.ModuleAgent() {
138 @Override
139 public int getModuleId() {
Doris Liubd1b8f92014-01-03 17:59:51 -0800140 return moduleId;
Angus Kong612321f2013-11-18 16:17:43 -0800141 }
142
143 @Override
144 public boolean requestAppForCamera() {
Angus Kong18500a42013-11-21 18:14:14 -0800145 return true;
Angus Kong612321f2013-11-18 16:17:43 -0800146 }
147
148 @Override
Angus Kongc4e66562013-11-22 23:03:21 -0800149 public ModuleController createModule(AppController app) {
Sascha Haeberling42db0352013-12-13 18:31:39 -0800150 return RefocusHelper.createRefocusModule(app);
Angus Kong612321f2013-11-18 16:17:43 -0800151 }
152 });
153 }
154
Doris Liubd1b8f92014-01-03 17:59:51 -0800155 private static void registerGcamModule(ModuleManager moduleManager, final int moduleId) {
Angus Kong612321f2013-11-18 16:17:43 -0800156 moduleManager.registerModule(new ModuleManager.ModuleAgent() {
157 @Override
158 public int getModuleId() {
Doris Liubd1b8f92014-01-03 17:59:51 -0800159 return moduleId;
Angus Kong612321f2013-11-18 16:17:43 -0800160 }
161
162 @Override
163 public boolean requestAppForCamera() {
164 return false;
165 }
166
167 @Override
Angus Kongc4e66562013-11-22 23:03:21 -0800168 public ModuleController createModule(AppController app) {
Sascha Haeberling42db0352013-12-13 18:31:39 -0800169 return GcamHelper.createGcamModule(app);
Angus Kong612321f2013-11-18 16:17:43 -0800170 }
171 });
172 }
173}