2 * Copyright (C) 2014 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package com.android.camera.one;
19 import android.content.Context;
20 import android.graphics.Bitmap;
21 import android.location.Location;
22 import android.net.Uri;
23 import android.view.Surface;
25 import com.android.camera.session.CaptureSession;
26 import com.android.camera.util.Size;
31 * OneCamera is a camera API tailored around our Google Camera application
32 * needs. It's not a general purpose API but instead offers an API with exactly
33 * what's needed from the app's side.
35 public interface OneCamera {
37 /** Which way the camera is facing. */
38 public static enum Facing {
43 * Auto focus system status; 1:1 mapping from camera2 AF_STATE.
45 * <li>{@link #INACTIVE}</li>
46 * <li>{@link #ACTIVE_SCAN}</li>
47 * <li>{@link #ACTIVE_FOCUSED}</li>
48 * <li>{@link #ACTIVE_UNFOCUSED}</li>
49 * <li>{@link #PASSIVE_SCAN}</li>
50 * <li>{@link #PASSIVE_FOCUSED}</li>
51 * <li>{@link #PASSIVE_UNFOCUSED}</li>
54 public static enum AutoFocusState {
55 /** Indicates AF system is inactive for some reason (could be an error). */
57 /** Indicates active scan in progress. */
59 /** Indicates active scan success (in focus). */
61 /** Indicates active scan failure (not in focus). */
63 /** Indicates passive scan in progress. */
65 /** Indicates passive scan success (in focus). */
67 /** Indicates passive scan failure (not in focus). */
72 * Auto focus system mode.
74 * <li>{@link #CONTINUOUS_PICTURE}</li>
75 * <li>{@link #AUTO}</li>
78 public static enum AutoFocusMode {
79 /** System is continuously focusing. */
81 /** System is running a triggered scan. */
86 * Classes implementing this interface will be called when the camera was
87 * opened or failed to open.
89 public static interface OpenCallback {
91 * Called when the camera was opened successfully.
93 * @param camera the camera instance that was successfully opened
95 public void onCameraOpened(OneCamera camera);
98 * Called if opening the camera failed.
100 public void onFailure();
104 * Classes implementing this interface will be called when the camera was
107 public static interface CloseCallback {
108 /** Called when the camera was fully closed. */
109 public void onCameraClosed();
113 * Classes implementing this interface can be informed when we're ready to
114 * take a picture of if setting up the capture pipeline failed.
116 public static interface CaptureReadyCallback {
117 /** After this is called, the system is ready for capture requests. */
118 public void onReadyForCapture();
121 * Indicates that something went wrong during setup and the system is
122 * not ready for capture requests.
124 public void onSetupFailed();
128 * Classes implementing this interface can be informed when the state of
131 public static interface ReadyStateChangedListener {
133 * Called when the camera is either ready or not ready to take a picture
136 public void onReadyStateChanged(boolean readyForCapture);
140 * A class implementing this interface can be passed into the call to take a
141 * picture in order to receive the resulting image or updated about the
144 public static interface PictureCallback {
146 * Called near the the when an image is being exposed for cameras which
147 * are exposing a single frame, so that a UI can be presented for the
150 public void onQuickExpose();
153 * Called when a thumbnail image is provided before the final image is
156 public void onThumbnailResult(Bitmap bitmap);
159 * Called when the final picture is done taking
161 * @param session the capture session
163 public void onPictureTaken(CaptureSession session);
166 * Called when the picture has been saved to disk.
168 * @param uri the URI of the stored data.
170 public void onPictureSaved(Uri uri);
173 * Called when picture taking failed.
175 public void onPictureTakenFailed();
178 * Called when capture session is reporting a processing update. This
179 * should only be called by capture sessions that require the user to
180 * hold still for a while.
182 * @param progress a value from 0...1, indicating the current processing
185 public void onTakePictureProgress(float progress);
189 * Classes implementing this interface will be called whenever the camera
190 * encountered an error.
192 public static interface CameraErrorListener {
193 /** Called when the camera encountered an error. */
194 public void onCameraError();
198 * Classes implementing this interface will be called when the state of the
199 * focus changes. Guaranteed not to stay stuck in scanning state past some
200 * reasonable timeout even if Camera API is stuck.
202 public static interface FocusStateListener {
204 * Called when state of auto focus system changes.
206 * @param state Current auto focus state.
207 * @param frameNumber Frame number if available.
209 public void onFocusStatusUpdate(AutoFocusState state, long frameNumber);
213 * Parameters to be given to photo capture requests.
215 public static final class PhotoCaptureParameters {
219 * Has to be in sync with R.arrays.pref_camera_flashmode_entryvalues.
221 public static enum Flash {
225 /** The title/filename (without suffix) for this capture. */
226 public String title = null;
227 /** Called when the capture is completed or failed. */
228 public PictureCallback callback = null;
229 /** The device orientation so we can compute the right JPEG rotation. */
230 public int orientation = Integer.MIN_VALUE;
231 /** The heading of the device at time of capture. In degrees. */
232 public int heading = Integer.MIN_VALUE;
233 /** Flash mode for this capture. */
234 public Flash flashMode = Flash.AUTO;
235 /** The location of this capture. */
236 public Location location = null;
238 /** Set this to provide a debug folder for this capture. */
239 public File debugDataFolder;
242 * Checks whether all required values are set. If one is missing, it
243 * throws a {@link RuntimeException}.
245 public void checkSanity() {
246 checkRequired(title);
247 checkRequired(callback);
248 checkRequired(orientation);
249 checkRequired(heading);
252 private void checkRequired(int num) {
253 if (num == Integer.MIN_VALUE) {
254 throw new RuntimeException("Photo capture parameter missing.");
258 private void checkRequired(Object obj) {
260 throw new RuntimeException("Photo capture parameter missing.");
266 * Meters and triggers auto focus scan with ROI around tap point.
268 * Normalized coordinates are referenced to portrait preview window with 0,0
269 * top left and 1,1 bottom right. Rotation has no effect.
271 * @param nx normalized x coordinate.
272 * @param nx normalized y coordinate.
274 public void triggerFocusAndMeterAtPoint(float nx, float ny);
277 * Call this to take a picture.
279 * @param params parameters for taking pictures.
280 * @param session the capture session for this picture.
282 public void takePicture(PhotoCaptureParameters params, CaptureSession session);
285 * Sets or replaces a listener that is called whenever the camera encounters
288 public void setCameraErrorListener(CameraErrorListener listener);
291 * Sets or replaces a listener that is called whenever the focus state of
292 * the camera changes.
294 public void setFocusStateListener(FocusStateListener listener);
297 * Sets or replaces a listener that is called whenever the state of the
298 * camera changes to be either ready or not ready to take another picture.
300 public void setReadyStateChangedListener(ReadyStateChangedListener listener);
303 * Starts a preview stream and renders it to the given surface.
305 public void startPreview(Surface surface, CaptureReadyCallback listener);
308 * Sets the size of the viewfinder.
310 * The preview size requested from the camera device will depend on this as
311 * well as the requested photo/video aspect ratio.
313 public void setViewfinderSize(int width, int height);
316 * @return Whether this camera supports flash.
317 * @param if true, returns whether flash is supported in enhanced mode. If
318 * false, whether flash is supported in normal capture mode.
320 public boolean isFlashSupported(boolean enhanced);
323 * @return Whether this camera supports enhanced mode, such as HDR.
325 public boolean isSupportingEnhancedMode();
330 * @param closeCallback Optional. Called as soon as the camera is fully
333 public void close(CloseCallback closeCallback);
336 * @return A list of all supported resolutions.
338 public Size[] getSupportedSizes();
341 * @return The aspect ratio of the full size capture (usually the native
342 * resolution of the camera).
344 public float getFullSizeAspectRatio();
347 * @return Whether this camera is facing to the back.
349 public boolean isBackFacing();
352 * @return Whether this camera is facing to the front.
354 public boolean isFrontFacing();
357 * Get the maximum zoom value.
359 * @return A float number to represent the maximum zoom value(>= 1.0).
361 public float getMaxZoom();
364 * This function sets the current zoom ratio value.
366 * The zoom range must be [1.0, maxZoom]. The maxZoom can be queried by
367 * {@link #getMaxZoom}.
369 * @param zoom Zoom ratio value passed to scaler.
371 public void setZoom(float zoom);
374 * Based on the selected picture size, this returns the best preview size.
376 * @param pictureSize the picture size as selected by the user. A camera
377 * might choose not to obey these and therefore the returned
378 * preview size might not match the aspect ratio of the given
380 * @param context the android application context
381 * @return The preview size that best matches the picture aspect ratio that
384 public Size pickPreviewSize(Size pictureSize, Context context);