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
17package com.android.camera.module;
18
19import android.content.Context;
20
21import com.android.camera.CaptureModule;
22import com.android.camera.PhotoModule;
23import com.android.camera.VideoModule;
24import com.android.camera.app.AppController;
25import com.android.camera.app.ModuleManager;
26import com.android.camera.debug.DebugPropertyHelper;
27import com.android.camera.debug.Log;
28import com.android.camera.util.GcamHelper;
29import com.android.camera.util.PhotoSphereHelper;
30import com.android.camera.util.RefocusHelper;
31import com.android.camera.util.SystemProperties;
32import com.android.camera2.R;
33
34/**
35 * A class holding the module information and registers them to
36 * {@link com.android.camera.app.ModuleManager}.
37 */
38public class ModulesInfo {
39    private static final Log.Tag TAG = new Log.Tag("ModulesInfo");
40
41    /** Selects CaptureModule if true, PhotoModule if false. */
42    private static final boolean ENABLE_CAPTURE_MODULE =
43            DebugPropertyHelper.isCaptureModuleEnabled();
44
45    public static void setupModules(Context context, ModuleManager moduleManager) {
46        int photoModuleId = context.getResources().getInteger(R.integer.camera_mode_photo);
47        registerPhotoModule(moduleManager, photoModuleId);
48        moduleManager.setDefaultModuleIndex(photoModuleId);
49        registerVideoModule(moduleManager, context.getResources()
50                .getInteger(R.integer.camera_mode_video));
51        if (PhotoSphereHelper.hasLightCycleCapture(context)) {
52            registerWideAngleModule(moduleManager, context.getResources()
53                    .getInteger(R.integer.camera_mode_panorama));
54            registerPhotoSphereModule(moduleManager, context.getResources()
55                    .getInteger(R.integer.camera_mode_photosphere));
56        }
57        if (RefocusHelper.hasRefocusCapture(context)) {
58            registerRefocusModule(moduleManager, context.getResources()
59                    .getInteger(R.integer.camera_mode_refocus));
60        }
61        if (GcamHelper.hasGcamAsSeparateModule()) {
62            registerGcamModule(moduleManager, context.getResources()
63                    .getInteger(R.integer.camera_mode_gcam));
64        }
65    }
66
67    private static void registerPhotoModule(ModuleManager moduleManager, final int moduleId) {
68        moduleManager.registerModule(new ModuleManager.ModuleAgent() {
69            @Override
70            public int getModuleId() {
71                return moduleId;
72            }
73
74            @Override
75            public boolean requestAppForCamera() {
76                // 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;
81            }
82
83            @Override
84            public ModuleController createModule(AppController app) {
85                return ENABLE_CAPTURE_MODULE ? new CaptureModule(app) : new PhotoModule(app);
86            }
87        });
88    }
89
90    private static void registerVideoModule(ModuleManager moduleManager, final int moduleId) {
91        moduleManager.registerModule(new ModuleManager.ModuleAgent() {
92            @Override
93            public int getModuleId() {
94                return moduleId;
95            }
96
97            @Override
98            public boolean requestAppForCamera() {
99                return true;
100            }
101
102            @Override
103            public ModuleController createModule(AppController app) {
104                return new VideoModule(app);
105            }
106        });
107    }
108
109    private static void registerWideAngleModule(ModuleManager moduleManager, final int moduleId) {
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 ModuleController createModule(AppController app) {
123                return PhotoSphereHelper.createWideAnglePanoramaModule(app);
124            }
125        });
126    }
127
128    private static void registerPhotoSphereModule(ModuleManager moduleManager, final int moduleId) {
129        moduleManager.registerModule(new ModuleManager.ModuleAgent() {
130            @Override
131            public int getModuleId() {
132                return moduleId;
133            }
134
135            @Override
136            public boolean requestAppForCamera() {
137                return true;
138            }
139
140            @Override
141            public ModuleController createModule(AppController app) {
142                return PhotoSphereHelper.createPanoramaModule(app);
143            }
144        });
145    }
146
147    private static void registerRefocusModule(ModuleManager moduleManager, final int moduleId) {
148        moduleManager.registerModule(new ModuleManager.ModuleAgent() {
149            @Override
150            public int getModuleId() {
151                return moduleId;
152            }
153
154            @Override
155            public boolean requestAppForCamera() {
156                return true;
157            }
158
159            @Override
160            public ModuleController createModule(AppController app) {
161                return RefocusHelper.createRefocusModule(app);
162            }
163        });
164    }
165
166    private static void registerGcamModule(ModuleManager moduleManager, final int moduleId) {
167        moduleManager.registerModule(new ModuleManager.ModuleAgent() {
168            @Override
169            public int getModuleId() {
170                return moduleId;
171            }
172
173            @Override
174            public boolean requestAppForCamera() {
175                return false;
176            }
177
178            @Override
179            public ModuleController createModule(AppController app) {
180                return GcamHelper.createGcamModule(app);
181            }
182        });
183    }
184}
185