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.app;
18
19import android.content.Context;
20import android.content.Intent;
21
22import com.android.camera.module.ModuleController;
23import com.android.camera.settings.SettingsManager;
24
25import java.util.List;
26
27/**
28 * The module manager which maintains the
29 * {@link ModuleManagerImpl.ModuleAgent}.
30 */
31public interface ModuleManager {
32    public static int MODULE_INDEX_NONE = -1;
33
34    /**
35     * The module agent which is responsible for maintaining the static
36     * characteristics and the creation of the module.
37     */
38    public static interface ModuleAgent {
39
40        /**
41         * @return The module ID.
42         */
43        public int getModuleId();
44
45        /**
46         * @return Whether the module will request the app for the camera.
47         */
48        public boolean requestAppForCamera();
49
50        /**
51         * @return A string which is used to get the namespace for settings in
52         * the module scope.
53         */
54        public String getScopeNamespace();
55
56        /**
57         * Creates the module.
58         *
59         * @param app The {@link com.android.camera.app.AppController} which
60         *            creates this module.
61         * @param intent The {@link android.content.Intent} which starts the activity.
62         * @return The module.
63         */
64        public ModuleController createModule(AppController app, Intent intent);
65    }
66
67    /**
68     * Registers a module. A module will be available only if its agent is
69     * registered. The registration might fail.
70     *
71     * @param agent The {@link com.android.camera.app.ModuleManager.ModuleAgent}
72     *              of the module.
73     * @throws java.lang.NullPointerException if the {@code agent} is null.
74     * @throws java.lang.IllegalArgumentException if the module ID is
75     * {@code MODULE_INDEX} or another module with the sameID is registered
76     * already.
77     */
78    void registerModule(ModuleAgent agent);
79
80    /**
81     * Unregister a module.
82     *
83     * @param moduleId The module ID.
84     * @return Whether the un-registration succeeds.
85     */
86    boolean unregisterModule(int moduleId);
87
88    /**
89     * @return A {@link java.util.List} of the
90     * {@link com.android.camera.app.ModuleManager.ModuleAgent} of all the
91     * registered modules.
92     */
93    List<ModuleAgent> getRegisteredModuleAgents();
94
95    /**
96     * @return A {@link java.util.List} of the
97     * {@link com.android.camera.app.ModuleManager.ModuleAgent} of all the
98     * registered modules' indices.
99     */
100    List<Integer> getSupportedModeIndexList();
101
102    /**
103     * Sets the default module index. No-op if the module index does not exist.
104     *
105     * @param moduleId The ID of the default module.
106     * @return Whether the {@code moduleId} exists.
107     */
108    boolean setDefaultModuleIndex(int moduleId);
109
110    /**
111     * @return The default module index. {@code MODULE_INDEX_NONE} if not set.
112     */
113    int getDefaultModuleIndex();
114
115    /**
116     * Returns the {@link com.android.camera.app.ModuleManager.ModuleAgent} by
117     * the module ID.
118     *
119     * @param moduleId The module ID.
120     * @return The agent.
121     */
122    ModuleAgent getModuleAgent(int moduleId);
123
124    /**
125     * Gets the mode that can be switched to from the given mode id through
126     * quick switch.
127     *
128     * @param moduleId index of the mode to switch from
129     * @param settingsManager settings manager for querying last used camera module
130     * @param context the context the activity is running in
131     * @return mode id to quick switch to if index is valid, otherwise returns
132     *         the given mode id itself
133     */
134    int getQuickSwitchToModuleId(int moduleId, SettingsManager settingsManager, Context context);
135}
136