• 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.app;
18 
19 import android.app.Activity;
20 import android.app.Dialog;
21 import android.content.Context;
22 import android.content.Intent;
23 import android.graphics.Bitmap;
24 import android.graphics.Matrix;
25 import android.graphics.RectF;
26 import android.graphics.SurfaceTexture;
27 import android.net.Uri;
28 import android.view.View;
29 import android.widget.FrameLayout;
30 
31 import com.android.camera.ButtonManager;
32 import com.android.camera.FatalErrorHandler;
33 import com.android.camera.SoundPlayer;
34 import com.android.camera.module.ModuleController;
35 import com.android.camera.one.OneCameraOpener;
36 import com.android.camera.one.config.OneCameraFeatureConfig;
37 import com.android.camera.settings.ResolutionSetting;
38 import com.android.camera.settings.SettingsManager;
39 import com.android.camera.ui.AbstractTutorialOverlay;
40 import com.android.camera.ui.PreviewStatusListener;
41 
42 /**
43  * The controller at app level.
44  */
45 public interface AppController {
46 
47     /**
48      * An interface which defines the shutter events listener.
49      */
50     public interface ShutterEventsListener {
51         /**
52          * Called when the shutter state is changed to pressed.
53          */
onShutterPressed()54         public void onShutterPressed();
55 
56         /**
57          * Called when the shutter state is changed to released.
58          */
onShutterReleased()59         public void onShutterReleased();
60 
61         /**
62          * Called when the shutter is clicked.
63          */
onShutterClicked()64         public void onShutterClicked();
65 
66         /**
67          * Called when the shutter is long pressed.
68          */
onShutterLongPressed()69         public void onShutterLongPressed();
70     }
71 
72     /**
73      * @return the {@link android.content.Context} being used.
74      */
getAndroidContext()75     public Context getAndroidContext();
76 
77     /** @return the camera feature configuration for the device. */
getCameraFeatureConfig()78     public OneCameraFeatureConfig getCameraFeatureConfig();
79 
80     /**
81      * Creates a new dialog which can be shown in the app.
82      *
83      * @return  {@link android.app.Dialog} of the app.
84      */
createDialog()85     public Dialog createDialog();
86 
87     /**
88      * @return a String scope uniquely identifing the current module.
89      */
getModuleScope()90     public String getModuleScope();
91 
92     /**
93      * @return a String scope uniquely identifing the current camera id.
94      */
getCameraScope()95     public String getCameraScope();
96 
97     /**
98      * Starts an activity.
99      *
100      * @param intent Used to start the activity.
101      */
launchActivityByIntent(Intent intent)102     public void launchActivityByIntent(Intent intent);
103 
104     /**
105      * See {@link Activity#openContextMenu(View)}
106      */
openContextMenu(View view)107     public void openContextMenu(View view);
108 
109     /**
110      * See {@link Activity#registerForContextMenu(View)}
111      */
registerForContextMenu(View view)112     public void registerForContextMenu(View view);
113 
114     /**
115      * Returns whether the app is currently paused.
116      */
isPaused()117     public boolean isPaused();
118 
119     /**
120      * Returns the current module controller.
121      */
getCurrentModuleController()122     public ModuleController getCurrentModuleController();
123 
124     /**
125      * Returns the currently active module index.
126      */
getCurrentModuleIndex()127     public int getCurrentModuleIndex();
128 
129     /**
130      * Returns the module ID for a specific mode.
131      */
getModuleId(int modeIndex)132     public int getModuleId(int modeIndex);
133 
134     /**
135      * Gets the mode that can be switched to from the given mode id through
136      * quick switch.
137      *
138      * @param currentModuleIndex index of the current mode
139      * @return mode id to quick switch to if index is valid, otherwise returns
140      *         the given mode id itself
141      */
getQuickSwitchToModuleId(int currentModuleIndex)142     public int getQuickSwitchToModuleId(int currentModuleIndex);
143 
144     /**
145      * Based on a mode switcher index, choose the correct module index.
146      *
147      * @param modeIndex mode switcher index.
148      * @return module index.
149      */
getPreferredChildModeIndex(int modeIndex)150     public int getPreferredChildModeIndex(int modeIndex);
151 
152     /**
153      * This gets called when mode is changed.
154      *
155      * @param moduleIndex index of the new module to switch to
156      */
onModeSelected(int moduleIndex)157     public void onModeSelected(int moduleIndex);
158 
159     /**
160      * This gets called when settings is selected and settings dialog needs to open.
161      */
onSettingsSelected()162     public void onSettingsSelected();
163 
164     /********************** UI / Camera preview **********************/
165 
166 
167     /**
168      * Freeze what is currently shown on screen until the next preview frame comes
169      * in. This can be used for camera switch to hide the UI changes underneath
170      * until preview is ready.
171      */
freezeScreenUntilPreviewReady()172     public void freezeScreenUntilPreviewReady();
173 
174     /**
175      * Returns the {@link android.graphics.SurfaceTexture} used by the preview
176      * UI.
177      */
getPreviewBuffer()178     public SurfaceTexture getPreviewBuffer();
179 
180     /**
181      * Gets called from module when preview is ready to start.
182      */
onPreviewReadyToStart()183     public void onPreviewReadyToStart();
184 
185     /**
186      * Gets called from module when preview is started.
187      */
onPreviewStarted()188     public void onPreviewStarted();
189 
190     /**
191      * Adds a listener to receive callbacks when preview area changes.
192      */
addPreviewAreaSizeChangedListener( PreviewStatusListener.PreviewAreaChangedListener listener)193     public void addPreviewAreaSizeChangedListener(
194             PreviewStatusListener.PreviewAreaChangedListener listener);
195 
196     /**
197      * Removes a listener that receives callbacks when preview area changes.
198      */
removePreviewAreaSizeChangedListener( PreviewStatusListener.PreviewAreaChangedListener listener)199     public void removePreviewAreaSizeChangedListener(
200             PreviewStatusListener.PreviewAreaChangedListener listener);
201 
202     /**
203      * Sets up one shot preview callback in order to notify UI when the next
204      * preview frame comes in.
205      */
setupOneShotPreviewListener()206     public void setupOneShotPreviewListener();
207 
208     /**
209      * Gets called from module when preview aspect ratio has changed.
210      *
211      * @param aspectRatio aspect ratio of preview stream
212      */
updatePreviewAspectRatio(float aspectRatio)213     public void updatePreviewAspectRatio(float aspectRatio);
214 
215     /**
216      * Gets called from module when the module needs to change the transform
217      * matrix of the preview TextureView. It does not modify the matrix before
218      * applying it.
219      *
220      * @param matrix transform matrix to be set on preview TextureView
221      * @param aspectRatio the desired aspect ratio of the preview
222      */
updatePreviewTransformFullscreen(Matrix matrix, float aspectRatio)223     public void updatePreviewTransformFullscreen(Matrix matrix, float aspectRatio);
224 
225     /**
226      * Call this to find the full rect available for a full screen preview
227      *
228      * @return the rect of the full screen minus any decor.
229      */
getFullscreenRect()230     public RectF getFullscreenRect();
231 
232     /**
233      * Gets called from module when the module needs to change the transform
234      * matrix of the preview TextureView. It is encouraged to use
235      * {@link #updatePreviewAspectRatio(float)} over this function, unless the
236      * module needs to rotate the surface texture using transform matrix.
237      *
238      * @param matrix transform matrix to be set on preview TextureView
239      */
updatePreviewTransform(Matrix matrix)240     public void updatePreviewTransform(Matrix matrix);
241 
242     /**
243      * Sets the preview status listener, which will get notified when TextureView
244      * surface has changed
245      *
246      * @param previewStatusListener the listener to get callbacks
247      */
setPreviewStatusListener(PreviewStatusListener previewStatusListener)248     public void setPreviewStatusListener(PreviewStatusListener previewStatusListener);
249 
250     /**
251      * Returns the {@link android.widget.FrameLayout} as the root of the module
252      * layout.
253      */
getModuleLayoutRoot()254     public FrameLayout getModuleLayoutRoot();
255 
256     /**
257      * Locks the system orientation.
258      */
lockOrientation()259     public void lockOrientation();
260 
261     /**
262      * Unlocks the system orientation.
263      */
unlockOrientation()264     public void unlockOrientation();
265 
266     /********************** Shutter button  **********************/
267 
268     /**
269      * Sets the shutter events listener.
270      *
271      * @param listener The listener.
272      */
setShutterEventsListener(ShutterEventsListener listener)273     public void setShutterEventsListener(ShutterEventsListener listener);
274 
275     /**
276      * Enables/Disables the shutter.
277      */
setShutterEnabled(boolean enabled)278     public void setShutterEnabled(boolean enabled);
279 
280     /**
281      * Checks whether the shutter is enabled.
282      */
isShutterEnabled()283     public boolean isShutterEnabled();
284 
285     /********************** Capture animation **********************/
286 
287     /**
288      * Starts flash animation with optional shorter flash.
289      *
290      * @param shortFlash true for shorter flash (faster cameras).
291      */
startFlashAnimation(boolean shortFlash)292     public void startFlashAnimation(boolean shortFlash);
293 
294     /**
295      * Starts normal pre-capture animation.
296      */
startPreCaptureAnimation()297     public void startPreCaptureAnimation();
298 
299     /**
300      * Cancels the pre-capture animation.
301      */
cancelPreCaptureAnimation()302     public void cancelPreCaptureAnimation();
303 
304     /**
305      * Starts the post-capture animation with the current preview image.
306      */
startPostCaptureAnimation()307     public void startPostCaptureAnimation();
308 
309     /**
310      * Starts the post-capture animation with the given thumbnail.
311      *
312      * @param thumbnail The thumbnail for the animation.
313      */
startPostCaptureAnimation(Bitmap thumbnail)314     public void startPostCaptureAnimation(Bitmap thumbnail);
315 
316     /**
317      * Cancels the post-capture animation.
318      */
cancelPostCaptureAnimation()319     public void cancelPostCaptureAnimation();
320 
321     /********************** Media saving **********************/
322 
323     /**
324      * Notifies the app of the newly captured media.
325      */
notifyNewMedia(Uri uri)326     public void notifyNewMedia(Uri uri);
327 
328     /********************** App-level resources **********************/
329 
330     /**
331      * Keeps the screen turned on.
332      *
333      * @param enabled Whether to keep the screen on.
334      */
enableKeepScreenOn(boolean enabled)335     public void enableKeepScreenOn(boolean enabled);
336 
337     /**
338      * Returns the {@link com.android.camera.app.CameraProvider}.
339      */
getCameraProvider()340     public CameraProvider getCameraProvider();
341 
342     /**
343      * Returns the new camera API manager.
344      */
getCameraOpener()345     public OneCameraOpener getCameraOpener();
346 
347     /**
348      * Returns the {@link OrientationManagerImpl}.
349      *
350      * @return {@code null} if not available yet.
351      */
getOrientationManager()352     public OrientationManager getOrientationManager();
353 
354     /**
355      * Returns the {@link LocationManager}.
356      *
357      * @return {@code null} if not available yet.
358      */
getLocationManager()359     public LocationManager getLocationManager();
360 
361     /**
362      * Returns the {@link SettingsManager}.
363      */
getSettingsManager()364     public SettingsManager getSettingsManager();
365 
366     /**
367      * Returns the {@link com.android.camera.settings.ResolutionSetting}.
368      *
369      * @return the current resolution setting.
370      */
getResolutionSetting()371     public ResolutionSetting getResolutionSetting();
372 
373     /**
374      * @return Common services and functionality to be shared.
375      */
getServices()376     public CameraServices getServices();
377 
378     /**
379      * @return The error handler to invoke for errors.
380      */
getFatalErrorHandler()381     public FatalErrorHandler getFatalErrorHandler();
382 
383     /**
384      * Returns the {@link com.android.camera.app.CameraAppUI}.
385      *
386      * @return {@code null} if not available yet.
387      */
getCameraAppUI()388     public CameraAppUI getCameraAppUI();
389 
390     /**
391      * Returns the {@link com.android.camera.app.ModuleManager}.
392      *
393      * @return {@code null} if not available yet.
394      */
getModuleManager()395     public ModuleManager getModuleManager();
396 
397     /**
398      * Returns the {@link com.android.camera.ButtonManager}.
399      */
getButtonManager()400     public ButtonManager getButtonManager();
401 
402     /** Returns a sound player that can be used to play custom sounds. */
getSoundPlayer()403     public SoundPlayer getSoundPlayer();
404 
405     /** Whether auto-rotate is enabled.*/
isAutoRotateScreen()406     public boolean isAutoRotateScreen();
407 
408     /**
409      * Shows the given tutorial overlay.
410      */
showTutorial(AbstractTutorialOverlay tutorial)411     public void showTutorial(AbstractTutorialOverlay tutorial);
412 
413     /**
414      * Finishes the activity since the intent is completed successfully.
415      *
416      * @param resultIntent The intent that carries the result.
417      */
finishActivityWithIntentCompleted(Intent resultIntent)418     public void finishActivityWithIntentCompleted(Intent resultIntent);
419 
420     /**
421      * Finishes the activity since the intent got canceled.
422      */
finishActivityWithIntentCanceled()423     public void finishActivityWithIntentCanceled();
424 }
425