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