blob: acf0677559fd2b80643227ad5b7f504467138977 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2008 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 android.hardware;
18
Eino-Ville Talvala788717c2013-02-15 18:30:15 -080019import android.app.ActivityThread;
Wu-cheng Li10e09c62011-07-18 09:09:41 +080020import android.annotation.SdkConstant;
21import android.annotation.SdkConstant.SdkConstantType;
Dianne Hackborn45ecf292016-02-22 13:55:34 -080022import android.app.job.JobInfo;
Eino-Ville Talvala4f8e5ce2012-10-08 18:16:35 -070023import android.content.Context;
Mathias Agopiana696f5d2010-02-17 17:53:09 -080024import android.graphics.ImageFormat;
Wu-cheng Li4c2292e2011-07-22 02:37:11 +080025import android.graphics.Point;
Wu-cheng Li30771b72011-04-02 06:19:46 +080026import android.graphics.Rect;
Jamie Gennisfd6f39e2010-12-20 12:15:00 -080027import android.graphics.SurfaceTexture;
Eino-Ville Talvala4f8e5ce2012-10-08 18:16:35 -070028import android.media.IAudioService;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080029import android.os.Handler;
Eino-Ville Talvala4f8e5ce2012-10-08 18:16:35 -070030import android.os.IBinder;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080031import android.os.Looper;
32import android.os.Message;
Eino-Ville Talvala4f8e5ce2012-10-08 18:16:35 -070033import android.os.RemoteException;
34import android.os.ServiceManager;
Eino-Ville Talvala7005b672013-04-02 15:46:38 -070035import android.renderscript.Allocation;
36import android.renderscript.Element;
37import android.renderscript.RenderScript;
38import android.renderscript.RSIllegalArgumentException;
39import android.renderscript.Type;
Wu-cheng Libde61a52011-06-07 18:23:14 +080040import android.util.Log;
Ali Utku Selen0a120182011-02-09 14:11:22 +010041import android.text.TextUtils;
Wu-cheng Libde61a52011-06-07 18:23:14 +080042import android.view.Surface;
43import android.view.SurfaceHolder;
44
45import java.io.IOException;
46import java.lang.ref.WeakReference;
47import java.util.ArrayList;
Igor Murashkin7d9a8ff2014-03-18 18:14:41 -070048import java.util.LinkedHashMap;
Wu-cheng Libde61a52011-06-07 18:23:14 +080049import java.util.List;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080050
Lazar Trsic8ea56f62015-07-07 17:31:20 +020051import static android.system.OsConstants.*;
52
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080053/**
Dan Egnorbfcbeff2010-07-12 15:12:54 -070054 * The Camera class is used to set image capture settings, start/stop preview,
55 * snap pictures, and retrieve frames for encoding for video. This class is a
56 * client for the Camera service, which manages the actual camera hardware.
Scott Maindf4578e2009-09-10 12:22:07 -070057 *
Dan Egnorbfcbeff2010-07-12 15:12:54 -070058 * <p>To access the device camera, you must declare the
Wu-cheng Li7478ea62009-09-16 18:52:55 +080059 * {@link android.Manifest.permission#CAMERA} permission in your Android
Scott Maindf4578e2009-09-10 12:22:07 -070060 * Manifest. Also be sure to include the
61 * <a href="{@docRoot}guide/topics/manifest/uses-feature-element.html">&lt;uses-feature></a>
Dan Egnorbfcbeff2010-07-12 15:12:54 -070062 * manifest element to declare camera features used by your application.
Wu-cheng Li7478ea62009-09-16 18:52:55 +080063 * For example, if you use the camera and auto-focus feature, your Manifest
Scott Maindf4578e2009-09-10 12:22:07 -070064 * should include the following:</p>
65 * <pre> &lt;uses-permission android:name="android.permission.CAMERA" />
66 * &lt;uses-feature android:name="android.hardware.camera" />
67 * &lt;uses-feature android:name="android.hardware.camera.autofocus" /></pre>
68 *
Dan Egnorbfcbeff2010-07-12 15:12:54 -070069 * <p>To take pictures with this class, use the following steps:</p>
70 *
71 * <ol>
Dan Egnor341ff132010-07-20 11:30:17 -070072 * <li>Obtain an instance of Camera from {@link #open(int)}.
Dan Egnorbfcbeff2010-07-12 15:12:54 -070073 *
74 * <li>Get existing (default) settings with {@link #getParameters()}.
75 *
76 * <li>If necessary, modify the returned {@link Camera.Parameters} object and call
77 * {@link #setParameters(Camera.Parameters)}.
78 *
Eino-Ville Talvala6c91e2c2016-03-25 11:54:39 -070079 * <li>Call {@link #setDisplayOrientation(int)} to ensure correct orientation of preview.
Dan Egnorbfcbeff2010-07-12 15:12:54 -070080 *
81 * <li><b>Important</b>: Pass a fully initialized {@link SurfaceHolder} to
82 * {@link #setPreviewDisplay(SurfaceHolder)}. Without a surface, the camera
83 * will be unable to start the preview.
84 *
85 * <li><b>Important</b>: Call {@link #startPreview()} to start updating the
86 * preview surface. Preview must be started before you can take a picture.
87 *
88 * <li>When you want, call {@link #takePicture(Camera.ShutterCallback,
89 * Camera.PictureCallback, Camera.PictureCallback, Camera.PictureCallback)} to
90 * capture a photo. Wait for the callbacks to provide the actual image data.
91 *
92 * <li>After taking a picture, preview display will have stopped. To take more
93 * photos, call {@link #startPreview()} again first.
94 *
95 * <li>Call {@link #stopPreview()} to stop updating the preview surface.
96 *
97 * <li><b>Important:</b> Call {@link #release()} to release the camera for
98 * use by other applications. Applications should release the camera
99 * immediately in {@link android.app.Activity#onPause()} (and re-{@link #open()}
100 * it in {@link android.app.Activity#onResume()}).
101 * </ol>
102 *
103 * <p>To quickly switch to video recording mode, use these steps:</p>
104 *
105 * <ol>
106 * <li>Obtain and initialize a Camera and start preview as described above.
107 *
108 * <li>Call {@link #unlock()} to allow the media process to access the camera.
109 *
110 * <li>Pass the camera to {@link android.media.MediaRecorder#setCamera(Camera)}.
111 * See {@link android.media.MediaRecorder} information about video recording.
112 *
113 * <li>When finished recording, call {@link #reconnect()} to re-acquire
114 * and re-lock the camera.
115 *
116 * <li>If desired, restart preview and take more photos or videos.
117 *
118 * <li>Call {@link #stopPreview()} and {@link #release()} as described above.
119 * </ol>
120 *
121 * <p>This class is not thread-safe, and is meant for use from one event thread.
122 * Most long-running operations (preview, focus, photo capture, etc) happen
123 * asynchronously and invoke callbacks as necessary. Callbacks will be invoked
Dan Egnor341ff132010-07-20 11:30:17 -0700124 * on the event thread {@link #open(int)} was called from. This class's methods
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700125 * must never be called from multiple threads at once.</p>
126 *
Scott Maindf4578e2009-09-10 12:22:07 -0700127 * <p class="caution"><strong>Caution:</strong> Different Android-powered devices
128 * may have different hardware specifications, such as megapixel ratings and
129 * auto-focus capabilities. In order for your application to be compatible with
Wu-cheng Li7478ea62009-09-16 18:52:55 +0800130 * more devices, you should not make assumptions about the device camera
Scott Maindf4578e2009-09-10 12:22:07 -0700131 * specifications.</p>
Joe Fernandez6c5c3c32011-10-18 14:57:05 -0700132 *
133 * <div class="special reference">
134 * <h3>Developer Guides</h3>
135 * <p>For more information about using cameras, read the
136 * <a href="{@docRoot}guide/topics/media/camera.html">Camera</a> developer guide.</p>
137 * </div>
Eino-Ville Talvalab942b052014-07-10 17:45:03 -0700138 *
139 * @deprecated We recommend using the new {@link android.hardware.camera2} API for new
140 * applications.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800141 */
Eino-Ville Talvalab942b052014-07-10 17:45:03 -0700142@Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800143public class Camera {
144 private static final String TAG = "Camera";
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800145
Wu-cheng Lid2c29292010-05-28 17:32:41 +0800146 // These match the enums in frameworks/base/include/camera/Camera.h
Benny Wongda83f462009-08-12 12:01:27 -0500147 private static final int CAMERA_MSG_ERROR = 0x001;
148 private static final int CAMERA_MSG_SHUTTER = 0x002;
149 private static final int CAMERA_MSG_FOCUS = 0x004;
150 private static final int CAMERA_MSG_ZOOM = 0x008;
151 private static final int CAMERA_MSG_PREVIEW_FRAME = 0x010;
152 private static final int CAMERA_MSG_VIDEO_FRAME = 0x020;
153 private static final int CAMERA_MSG_POSTVIEW_FRAME = 0x040;
154 private static final int CAMERA_MSG_RAW_IMAGE = 0x080;
155 private static final int CAMERA_MSG_COMPRESSED_IMAGE = 0x100;
Wu-cheng Li4c2292e2011-07-22 02:37:11 +0800156 private static final int CAMERA_MSG_RAW_IMAGE_NOTIFY = 0x200;
Wu-cheng Libb1e2752011-07-30 05:00:37 +0800157 private static final int CAMERA_MSG_PREVIEW_METADATA = 0x400;
Wu-cheng Li9d062cf2011-11-14 20:30:14 +0800158 private static final int CAMERA_MSG_FOCUS_MOVE = 0x800;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800159
Ashok Bhat4838e332014-01-03 14:37:19 +0000160 private long mNativeContext; // accessed by native methods
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800161 private EventHandler mEventHandler;
162 private ShutterCallback mShutterCallback;
163 private PictureCallback mRawImageCallback;
164 private PictureCallback mJpegCallback;
165 private PreviewCallback mPreviewCallback;
Eino-Ville Talvala7005b672013-04-02 15:46:38 -0700166 private boolean mUsingPreviewAllocation;
Dave Sparkse8b26e12009-07-14 10:35:40 -0700167 private PictureCallback mPostviewCallback;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800168 private AutoFocusCallback mAutoFocusCallback;
Wu-cheng Li9d062cf2011-11-14 20:30:14 +0800169 private AutoFocusMoveCallback mAutoFocusMoveCallback;
Wu-cheng Li3f4639a2010-04-04 15:05:41 +0800170 private OnZoomChangeListener mZoomListener;
Wu-cheng Li4c2292e2011-07-22 02:37:11 +0800171 private FaceDetectionListener mFaceListener;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800172 private ErrorCallback mErrorCallback;
173 private boolean mOneShot;
Andrew Harp94927df2009-10-20 01:47:05 -0400174 private boolean mWithBuffer;
Wu-cheng Li4c2292e2011-07-22 02:37:11 +0800175 private boolean mFaceDetectionRunning = false;
Igor Murashkina1d66272014-06-20 11:22:11 -0700176 private final Object mAutoFocusCallbackLock = new Object();
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800177
Ruben Brunkfeb50af2014-05-09 19:58:49 -0700178 private static final int NO_ERROR = 0;
Ruben Brunkfeb50af2014-05-09 19:58:49 -0700179
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800180 /**
Dianne Hackborn45ecf292016-02-22 13:55:34 -0800181 * @deprecated This broadcast is no longer delivered by the system; use
182 * {@link android.app.job.JobInfo.Builder JobInfo.Builder}.{@link android.app.job.JobInfo.Builder#addTriggerContentUri}
183 * instead.
Wu-cheng Li10e09c62011-07-18 09:09:41 +0800184 * Broadcast Action: A new picture is taken by the camera, and the entry of
185 * the picture has been added to the media store.
186 * {@link android.content.Intent#getData} is URI of the picture.
187 */
188 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
Dianne Hackborn45ecf292016-02-22 13:55:34 -0800189 @Deprecated
Wu-cheng Li10e09c62011-07-18 09:09:41 +0800190 public static final String ACTION_NEW_PICTURE = "android.hardware.action.NEW_PICTURE";
191
192 /**
Dianne Hackborn45ecf292016-02-22 13:55:34 -0800193 * @deprecated This broadcast is no longer delivered by the system; use
194 * {@link android.app.job.JobInfo.Builder JobInfo.Builder}.{@link android.app.job.JobInfo.Builder#addTriggerContentUri}
195 * instead.
Wu-cheng Li10e09c62011-07-18 09:09:41 +0800196 * Broadcast Action: A new video is recorded by the camera, and the entry
197 * of the video has been added to the media store.
198 * {@link android.content.Intent#getData} is URI of the video.
199 */
200 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
Dianne Hackborn45ecf292016-02-22 13:55:34 -0800201 @Deprecated
Wu-cheng Li10e09c62011-07-18 09:09:41 +0800202 public static final String ACTION_NEW_VIDEO = "android.hardware.action.NEW_VIDEO";
203
204 /**
Zhijun He4c913802014-06-16 16:42:35 -0700205 * Camera HAL device API version 1.0
206 * @hide
207 */
208 public static final int CAMERA_HAL_API_VERSION_1_0 = 0x100;
209
210 /**
211 * A constant meaning the normal camera connect/open will be used.
Zhijun He4c913802014-06-16 16:42:35 -0700212 */
Igor Murashkina1d66272014-06-20 11:22:11 -0700213 private static final int CAMERA_HAL_API_VERSION_NORMAL_CONNECT = -2;
Zhijun He4c913802014-06-16 16:42:35 -0700214
215 /**
216 * Used to indicate HAL version un-specified.
217 */
218 private static final int CAMERA_HAL_API_VERSION_UNSPECIFIED = -1;
Igor Murashkina1d66272014-06-20 11:22:11 -0700219
Zhijun He4c913802014-06-16 16:42:35 -0700220 /**
Wu-cheng Li4c2292e2011-07-22 02:37:11 +0800221 * Hardware face detection. It does not use much CPU.
Wu-cheng Li4c2292e2011-07-22 02:37:11 +0800222 */
Wu-cheng Lic0c683b2011-08-04 00:11:00 +0800223 private static final int CAMERA_FACE_DETECTION_HW = 0;
Wu-cheng Li4c2292e2011-07-22 02:37:11 +0800224
225 /**
Wu-cheng Lic0c683b2011-08-04 00:11:00 +0800226 * Software face detection. It uses some CPU.
Wu-cheng Li4c2292e2011-07-22 02:37:11 +0800227 */
Wu-cheng Lic0c683b2011-08-04 00:11:00 +0800228 private static final int CAMERA_FACE_DETECTION_SW = 1;
Wu-cheng Li4c2292e2011-07-22 02:37:11 +0800229
230 /**
Dan Egnor341ff132010-07-20 11:30:17 -0700231 * Returns the number of physical cameras available on this device.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800232 */
Chih-Chung Change25cc652010-05-06 16:36:58 +0800233 public native static int getNumberOfCameras();
234
235 /**
Dan Egnor341ff132010-07-20 11:30:17 -0700236 * Returns the information about a particular camera.
Chih-Chung Changb8bb78f2010-06-10 13:32:16 +0800237 * If {@link #getNumberOfCameras()} returns N, the valid id is 0 to N-1.
Chih-Chung Changb8bb78f2010-06-10 13:32:16 +0800238 */
Eino-Ville Talvala4f8e5ce2012-10-08 18:16:35 -0700239 public static void getCameraInfo(int cameraId, CameraInfo cameraInfo) {
240 _getCameraInfo(cameraId, cameraInfo);
241 IBinder b = ServiceManager.getService(Context.AUDIO_SERVICE);
242 IAudioService audioService = IAudioService.Stub.asInterface(b);
243 try {
244 if (audioService.isCameraSoundForced()) {
245 // Only set this when sound is forced; otherwise let native code
246 // decide.
247 cameraInfo.canDisableShutterSound = false;
248 }
249 } catch (RemoteException e) {
250 Log.e(TAG, "Audio service is unavailable for queries");
251 }
252 }
253 private native static void _getCameraInfo(int cameraId, CameraInfo cameraInfo);
Chih-Chung Changb8bb78f2010-06-10 13:32:16 +0800254
255 /**
256 * Information about a camera
Eino-Ville Talvalab942b052014-07-10 17:45:03 -0700257 *
258 * @deprecated We recommend using the new {@link android.hardware.camera2} API for new
259 * applications.
Chih-Chung Changb8bb78f2010-06-10 13:32:16 +0800260 */
Eino-Ville Talvalab942b052014-07-10 17:45:03 -0700261 @Deprecated
Chih-Chung Changb8bb78f2010-06-10 13:32:16 +0800262 public static class CameraInfo {
Wu-cheng Li78366602010-09-15 14:08:15 -0700263 /**
264 * The facing of the camera is opposite to that of the screen.
265 */
Chih-Chung Changb8bb78f2010-06-10 13:32:16 +0800266 public static final int CAMERA_FACING_BACK = 0;
Wu-cheng Li78366602010-09-15 14:08:15 -0700267
268 /**
269 * The facing of the camera is the same as that of the screen.
270 */
Chih-Chung Changb8bb78f2010-06-10 13:32:16 +0800271 public static final int CAMERA_FACING_FRONT = 1;
272
273 /**
Joe Fernandez464cb212011-10-04 16:56:47 -0700274 * The direction that the camera faces. It should be
Chih-Chung Changb8bb78f2010-06-10 13:32:16 +0800275 * CAMERA_FACING_BACK or CAMERA_FACING_FRONT.
276 */
Wu-cheng Li78366602010-09-15 14:08:15 -0700277 public int facing;
Chih-Chung Changb8bb78f2010-06-10 13:32:16 +0800278
279 /**
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -0700280 * <p>The orientation of the camera image. The value is the angle that the
Chih-Chung Changb8bb78f2010-06-10 13:32:16 +0800281 * camera image needs to be rotated clockwise so it shows correctly on
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -0700282 * the display in its natural orientation. It should be 0, 90, 180, or 270.</p>
Chih-Chung Changb8bb78f2010-06-10 13:32:16 +0800283 *
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -0700284 * <p>For example, suppose a device has a naturally tall screen. The
Wu-cheng Li2fe6fca2010-10-15 14:42:23 +0800285 * back-facing camera sensor is mounted in landscape. You are looking at
286 * the screen. If the top side of the camera sensor is aligned with the
287 * right edge of the screen in natural orientation, the value should be
288 * 90. If the top side of a front-facing camera sensor is aligned with
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -0700289 * the right of the screen, the value should be 270.</p>
Chih-Chung Changb8bb78f2010-06-10 13:32:16 +0800290 *
291 * @see #setDisplayOrientation(int)
Brad Fitzpatrick69ea4e12011-01-05 11:13:40 -0800292 * @see Parameters#setRotation(int)
293 * @see Parameters#setPreviewSize(int, int)
294 * @see Parameters#setPictureSize(int, int)
295 * @see Parameters#setJpegThumbnailSize(int, int)
Chih-Chung Changb8bb78f2010-06-10 13:32:16 +0800296 */
Wu-cheng Li78366602010-09-15 14:08:15 -0700297 public int orientation;
Eino-Ville Talvalaf7c6c5a2012-09-19 11:46:11 -0700298
299 /**
300 * <p>Whether the shutter sound can be disabled.</p>
301 *
302 * <p>On some devices, the camera shutter sound cannot be turned off
303 * through {@link #enableShutterSound enableShutterSound}. This field
304 * can be used to determine whether a call to disable the shutter sound
305 * will succeed.</p>
306 *
307 * <p>If this field is set to true, then a call of
308 * {@code enableShutterSound(false)} will be successful. If set to
309 * false, then that call will fail, and the shutter sound will be played
310 * when {@link Camera#takePicture takePicture} is called.</p>
311 */
312 public boolean canDisableShutterSound;
Chih-Chung Changb8bb78f2010-06-10 13:32:16 +0800313 };
314
315 /**
Wu-cheng Lia1c41e12012-02-23 19:01:00 -0800316 * Creates a new Camera object to access a particular hardware camera. If
317 * the same camera is opened by other applications, this will throw a
318 * RuntimeException.
319 *
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700320 * <p>You must call {@link #release()} when you are done using the camera,
321 * otherwise it will remain locked and be unavailable to other applications.
322 *
Dan Egnor341ff132010-07-20 11:30:17 -0700323 * <p>Your application should only have one Camera object active at a time
324 * for a particular hardware camera.
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700325 *
326 * <p>Callbacks from other methods are delivered to the event loop of the
327 * thread which called open(). If this thread has no event loop, then
328 * callbacks are delivered to the main application event loop. If there
329 * is no main application event loop, callbacks are not delivered.
330 *
331 * <p class="caution"><b>Caution:</b> On some devices, this method may
332 * take a long time to complete. It is best to call this method from a
333 * worker thread (possibly using {@link android.os.AsyncTask}) to avoid
334 * blocking the main application UI thread.
335 *
Dan Egnor341ff132010-07-20 11:30:17 -0700336 * @param cameraId the hardware camera to access, between 0 and
Wu-cheng Lia48b70f2010-11-09 01:55:44 +0800337 * {@link #getNumberOfCameras()}-1.
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700338 * @return a new Camera object, connected, locked and ready for use.
Wu-cheng Lia1c41e12012-02-23 19:01:00 -0800339 * @throws RuntimeException if opening the camera fails (for example, if the
340 * camera is in use by another process or device policy manager has
341 * disabled the camera).
Wu-cheng Lifacc8ce2011-06-17 13:09:40 +0800342 * @see android.app.admin.DevicePolicyManager#getCameraDisabled(android.content.ComponentName)
Chih-Chung Change25cc652010-05-06 16:36:58 +0800343 */
344 public static Camera open(int cameraId) {
Wu-cheng Li7bc1b212012-04-19 12:23:31 +0800345 return new Camera(cameraId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800346 }
347
Chih-Chung Change25cc652010-05-06 16:36:58 +0800348 /**
Wu-cheng Lia48b70f2010-11-09 01:55:44 +0800349 * Creates a new Camera object to access the first back-facing camera on the
350 * device. If the device does not have a back-facing camera, this returns
351 * null.
Wu-cheng Li78366602010-09-15 14:08:15 -0700352 * @see #open(int)
Chih-Chung Change25cc652010-05-06 16:36:58 +0800353 */
354 public static Camera open() {
Wu-cheng Lia48b70f2010-11-09 01:55:44 +0800355 int numberOfCameras = getNumberOfCameras();
356 CameraInfo cameraInfo = new CameraInfo();
357 for (int i = 0; i < numberOfCameras; i++) {
358 getCameraInfo(i, cameraInfo);
359 if (cameraInfo.facing == CameraInfo.CAMERA_FACING_BACK) {
Wu-cheng Li7bc1b212012-04-19 12:23:31 +0800360 return new Camera(i);
Wu-cheng Lia48b70f2010-11-09 01:55:44 +0800361 }
362 }
363 return null;
Chih-Chung Change25cc652010-05-06 16:36:58 +0800364 }
365
Zhijun He4c913802014-06-16 16:42:35 -0700366 /**
367 * Creates a new Camera object to access a particular hardware camera with
368 * given hal API version. If the same camera is opened by other applications
369 * or the hal API version is not supported by this device, this will throw a
370 * RuntimeException.
371 * <p>
372 * You must call {@link #release()} when you are done using the camera,
373 * otherwise it will remain locked and be unavailable to other applications.
374 * <p>
375 * Your application should only have one Camera object active at a time for
376 * a particular hardware camera.
377 * <p>
378 * Callbacks from other methods are delivered to the event loop of the
379 * thread which called open(). If this thread has no event loop, then
380 * callbacks are delivered to the main application event loop. If there is
381 * no main application event loop, callbacks are not delivered.
382 * <p class="caution">
383 * <b>Caution:</b> On some devices, this method may take a long time to
384 * complete. It is best to call this method from a worker thread (possibly
385 * using {@link android.os.AsyncTask}) to avoid blocking the main
386 * application UI thread.
387 *
388 * @param cameraId The hardware camera to access, between 0 and
389 * {@link #getNumberOfCameras()}-1.
Igor Murashkina1d66272014-06-20 11:22:11 -0700390 * @param halVersion The HAL API version this camera device to be opened as.
Zhijun He4c913802014-06-16 16:42:35 -0700391 * @return a new Camera object, connected, locked and ready for use.
Igor Murashkina1d66272014-06-20 11:22:11 -0700392 *
393 * @throws IllegalArgumentException if the {@code halVersion} is invalid
394 *
Zhijun He4c913802014-06-16 16:42:35 -0700395 * @throws RuntimeException if opening the camera fails (for example, if the
396 * camera is in use by another process or device policy manager has disabled
397 * the camera).
Igor Murashkina1d66272014-06-20 11:22:11 -0700398 *
Zhijun He4c913802014-06-16 16:42:35 -0700399 * @see android.app.admin.DevicePolicyManager#getCameraDisabled(android.content.ComponentName)
Igor Murashkina1d66272014-06-20 11:22:11 -0700400 * @see #CAMERA_HAL_API_VERSION_1_0
Zhijun He4c913802014-06-16 16:42:35 -0700401 *
402 * @hide
403 */
404 public static Camera openLegacy(int cameraId, int halVersion) {
Igor Murashkina1d66272014-06-20 11:22:11 -0700405 if (halVersion < CAMERA_HAL_API_VERSION_1_0) {
406 throw new IllegalArgumentException("Invalid HAL version " + halVersion);
407 }
408
Zhijun He4c913802014-06-16 16:42:35 -0700409 return new Camera(cameraId, halVersion);
410 }
411
412 /**
413 * Create a legacy camera object.
414 *
415 * @param cameraId The hardware camera to access, between 0 and
416 * {@link #getNumberOfCameras()}-1.
417 * @param halVersion The HAL API version this camera device to be opened as.
418 */
419 private Camera(int cameraId, int halVersion) {
Igor Murashkina1d66272014-06-20 11:22:11 -0700420 int err = cameraInitVersion(cameraId, halVersion);
Zhijun He4c913802014-06-16 16:42:35 -0700421 if (checkInitErrors(err)) {
Lazar Trsic8ea56f62015-07-07 17:31:20 +0200422 if (err == -EACCES) {
423 throw new RuntimeException("Fail to connect to camera service");
424 } else if (err == -ENODEV) {
425 throw new RuntimeException("Camera initialization failed");
426 } else if (err == -ENOSYS) {
427 throw new RuntimeException("Camera initialization failed because some methods"
428 + " are not implemented");
429 } else if (err == -EOPNOTSUPP) {
430 throw new RuntimeException("Camera initialization failed because the hal"
431 + " version is not supported by this device");
432 } else if (err == -EINVAL) {
433 throw new RuntimeException("Camera initialization failed because the input"
434 + " arugments are invalid");
435 } else if (err == -EBUSY) {
436 throw new RuntimeException("Camera initialization failed because the camera"
437 + " device was already opened");
438 } else if (err == -EUSERS) {
439 throw new RuntimeException("Camera initialization failed because the max"
440 + " number of camera devices were already opened");
Zhijun He4c913802014-06-16 16:42:35 -0700441 }
Lazar Trsic8ea56f62015-07-07 17:31:20 +0200442 // Should never hit this.
443 throw new RuntimeException("Unknown camera error");
Zhijun He4c913802014-06-16 16:42:35 -0700444 }
445 }
446
Igor Murashkina1d66272014-06-20 11:22:11 -0700447 private int cameraInitVersion(int cameraId, int halVersion) {
Zhijun He4c913802014-06-16 16:42:35 -0700448 mShutterCallback = null;
449 mRawImageCallback = null;
450 mJpegCallback = null;
451 mPreviewCallback = null;
452 mPostviewCallback = null;
453 mUsingPreviewAllocation = false;
454 mZoomListener = null;
455
456 Looper looper;
457 if ((looper = Looper.myLooper()) != null) {
458 mEventHandler = new EventHandler(this, looper);
459 } else if ((looper = Looper.getMainLooper()) != null) {
460 mEventHandler = new EventHandler(this, looper);
461 } else {
462 mEventHandler = null;
463 }
464
Svetoslavfbf0eca2015-05-01 16:52:41 -0700465 return native_setup(new WeakReference<Camera>(this), cameraId, halVersion,
466 ActivityThread.currentOpPackageName());
Zhijun He4c913802014-06-16 16:42:35 -0700467 }
468
Igor Murashkina1d66272014-06-20 11:22:11 -0700469 private int cameraInitNormal(int cameraId) {
470 return cameraInitVersion(cameraId, CAMERA_HAL_API_VERSION_NORMAL_CONNECT);
471 }
472
473 /**
474 * Connect to the camera service using #connectLegacy
475 *
476 * <p>
477 * This acts the same as normal except that it will return
478 * the detailed error code if open fails instead of
479 * converting everything into {@code NO_INIT}.</p>
480 *
481 * <p>Intended to use by the camera2 shim only, do <i>not</i> use this for other code.</p>
482 *
483 * @return a detailed errno error code, or {@code NO_ERROR} on success
484 *
485 * @hide
486 */
487 public int cameraInitUnspecified(int cameraId) {
488 return cameraInitVersion(cameraId, CAMERA_HAL_API_VERSION_UNSPECIFIED);
489 }
490
491 /** used by Camera#open, Camera#open(int) */
Wu-cheng Li7bc1b212012-04-19 12:23:31 +0800492 Camera(int cameraId) {
Igor Murashkina1d66272014-06-20 11:22:11 -0700493 int err = cameraInitNormal(cameraId);
Ruben Brunkfeb50af2014-05-09 19:58:49 -0700494 if (checkInitErrors(err)) {
Lazar Trsic8ea56f62015-07-07 17:31:20 +0200495 if (err == -EACCES) {
496 throw new RuntimeException("Fail to connect to camera service");
497 } else if (err == -ENODEV) {
498 throw new RuntimeException("Camera initialization failed");
Ruben Brunkfeb50af2014-05-09 19:58:49 -0700499 }
Lazar Trsic8ea56f62015-07-07 17:31:20 +0200500 // Should never hit this.
501 throw new RuntimeException("Unknown camera error");
Ruben Brunkfeb50af2014-05-09 19:58:49 -0700502 }
503 }
504
Ruben Brunkfeb50af2014-05-09 19:58:49 -0700505
506 /**
507 * @hide
508 */
509 public static boolean checkInitErrors(int err) {
510 return err != NO_ERROR;
511 }
512
513 /**
514 * @hide
515 */
516 public static Camera openUninitialized() {
517 return new Camera();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800518 }
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800519
Wu-cheng Li1c04a332011-11-22 18:21:18 +0800520 /**
521 * An empty Camera for testing purpose.
522 */
523 Camera() {
524 }
525
Igor Murashkina1d66272014-06-20 11:22:11 -0700526 @Override
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800527 protected void finalize() {
Eino-Ville Talvalae0cc55a2011-11-08 10:12:09 -0800528 release();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800529 }
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800530
Zhijun He4c913802014-06-16 16:42:35 -0700531 private native final int native_setup(Object camera_this, int cameraId, int halVersion,
Eino-Ville Talvala788717c2013-02-15 18:30:15 -0800532 String packageName);
533
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800534 private native final void native_release();
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800535
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800536
537 /**
538 * Disconnects and releases the Camera object resources.
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700539 *
540 * <p>You must call this as soon as you're done with the Camera object.</p>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800541 */
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800542 public final void release() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800543 native_release();
Wu-cheng Li4c2292e2011-07-22 02:37:11 +0800544 mFaceDetectionRunning = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800545 }
546
547 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700548 * Unlocks the camera to allow another process to access it.
549 * Normally, the camera is locked to the process with an active Camera
550 * object until {@link #release()} is called. To allow rapid handoff
551 * between processes, you can call this method to release the camera
552 * temporarily for another process to use; once the other process is done
553 * you can call {@link #reconnect()} to reclaim the camera.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800554 *
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700555 * <p>This must be done before calling
Wu-cheng Li42419ce2011-06-01 17:22:24 +0800556 * {@link android.media.MediaRecorder#setCamera(Camera)}. This cannot be
557 * called after recording starts.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800558 *
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700559 * <p>If you are not recording video, you probably do not need this method.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800560 *
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700561 * @throws RuntimeException if the camera cannot be unlocked.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800562 */
Wu-cheng Liffe1cf22009-09-10 16:49:17 +0800563 public native final void unlock();
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800564
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800565 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700566 * Re-locks the camera to prevent other processes from accessing it.
567 * Camera objects are locked by default unless {@link #unlock()} is
568 * called. Normally {@link #reconnect()} is used instead.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800569 *
Wu-cheng Li53b30912011-10-12 19:43:51 +0800570 * <p>Since API level 14, camera is automatically locked for applications in
Wu-cheng Li42419ce2011-06-01 17:22:24 +0800571 * {@link android.media.MediaRecorder#start()}. Applications can use the
572 * camera (ex: zoom) after recording starts. There is no need to call this
573 * after recording starts or stops.
574 *
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700575 * <p>If you are not recording video, you probably do not need this method.
576 *
577 * @throws RuntimeException if the camera cannot be re-locked (for
578 * example, if the camera is still in use by another process).
579 */
580 public native final void lock();
581
582 /**
583 * Reconnects to the camera service after another process used it.
584 * After {@link #unlock()} is called, another process may use the
585 * camera; when the process is done, you must reconnect to the camera,
586 * which will re-acquire the lock and allow you to continue using the
587 * camera.
588 *
Wu-cheng Li53b30912011-10-12 19:43:51 +0800589 * <p>Since API level 14, camera is automatically locked for applications in
Wu-cheng Li42419ce2011-06-01 17:22:24 +0800590 * {@link android.media.MediaRecorder#start()}. Applications can use the
591 * camera (ex: zoom) after recording starts. There is no need to call this
592 * after recording starts or stops.
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700593 *
594 * <p>If you are not recording video, you probably do not need this method.
595 *
596 * @throws IOException if a connection cannot be re-established (for
597 * example, if the camera is still in use by another process).
598 */
599 public native final void reconnect() throws IOException;
600
601 /**
602 * Sets the {@link Surface} to be used for live preview.
Jamie Gennisfd6f39e2010-12-20 12:15:00 -0800603 * Either a surface or surface texture is necessary for preview, and
604 * preview is necessary to take pictures. The same surface can be re-set
605 * without harm. Setting a preview surface will un-set any preview surface
606 * texture that was set via {@link #setPreviewTexture}.
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700607 *
608 * <p>The {@link SurfaceHolder} must already contain a surface when this
609 * method is called. If you are using {@link android.view.SurfaceView},
610 * you will need to register a {@link SurfaceHolder.Callback} with
611 * {@link SurfaceHolder#addCallback(SurfaceHolder.Callback)} and wait for
612 * {@link SurfaceHolder.Callback#surfaceCreated(SurfaceHolder)} before
613 * calling setPreviewDisplay() or starting preview.
614 *
615 * <p>This method must be called before {@link #startPreview()}. The
616 * one exception is that if the preview surface is not set (or set to null)
617 * before startPreview() is called, then this method may be called once
618 * with a non-null parameter to set the preview surface. (This allows
619 * camera setup and surface creation to happen in parallel, saving time.)
620 * The preview surface may not otherwise change while preview is running.
621 *
622 * @param holder containing the Surface on which to place the preview,
623 * or null to remove the preview surface
624 * @throws IOException if the method fails (for example, if the surface
625 * is unavailable or unsuitable).
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800626 */
627 public final void setPreviewDisplay(SurfaceHolder holder) throws IOException {
Wu-cheng Lib8a10fe2009-06-23 23:37:36 +0800628 if (holder != null) {
Ruben Brunkfeb50af2014-05-09 19:58:49 -0700629 setPreviewSurface(holder.getSurface());
Wu-cheng Lib8a10fe2009-06-23 23:37:36 +0800630 } else {
Ruben Brunkfeb50af2014-05-09 19:58:49 -0700631 setPreviewSurface((Surface)null);
Wu-cheng Lib8a10fe2009-06-23 23:37:36 +0800632 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800633 }
634
Ruben Brunkfeb50af2014-05-09 19:58:49 -0700635 /**
636 * @hide
637 */
638 public native final void setPreviewSurface(Surface surface) throws IOException;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800639
640 /**
Jamie Gennisfd6f39e2010-12-20 12:15:00 -0800641 * Sets the {@link SurfaceTexture} to be used for live preview.
642 * Either a surface or surface texture is necessary for preview, and
643 * preview is necessary to take pictures. The same surface texture can be
644 * re-set without harm. Setting a preview surface texture will un-set any
645 * preview surface that was set via {@link #setPreviewDisplay}.
646 *
647 * <p>This method must be called before {@link #startPreview()}. The
648 * one exception is that if the preview surface texture is not set (or set
649 * to null) before startPreview() is called, then this method may be called
650 * once with a non-null parameter to set the preview surface. (This allows
651 * camera setup and surface creation to happen in parallel, saving time.)
652 * The preview surface texture may not otherwise change while preview is
653 * running.
654 *
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -0700655 * <p>The timestamps provided by {@link SurfaceTexture#getTimestamp()} for a
Eino-Ville Talvalae309a0f2011-03-21 11:04:34 -0700656 * SurfaceTexture set as the preview texture have an unspecified zero point,
657 * and cannot be directly compared between different cameras or different
658 * instances of the same camera, or across multiple runs of the same
659 * program.
660 *
Eino-Ville Talvala108708b2012-03-05 11:00:43 -0800661 * <p>If you are using the preview data to create video or still images,
662 * strongly consider using {@link android.media.MediaActionSound} to
663 * properly indicate image capture or recording start/stop to the user.</p>
664 *
665 * @see android.media.MediaActionSound
666 * @see android.graphics.SurfaceTexture
667 * @see android.view.TextureView
Jamie Gennisfd6f39e2010-12-20 12:15:00 -0800668 * @param surfaceTexture the {@link SurfaceTexture} to which the preview
669 * images are to be sent or null to remove the current preview surface
670 * texture
671 * @throws IOException if the method fails (for example, if the surface
672 * texture is unavailable or unsuitable).
673 */
Glenn Kastendbc289d2011-02-09 10:15:44 -0800674 public native final void setPreviewTexture(SurfaceTexture surfaceTexture) throws IOException;
Jamie Gennisfd6f39e2010-12-20 12:15:00 -0800675
676 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700677 * Callback interface used to deliver copies of preview frames as
678 * they are displayed.
679 *
680 * @see #setPreviewCallback(Camera.PreviewCallback)
681 * @see #setOneShotPreviewCallback(Camera.PreviewCallback)
682 * @see #setPreviewCallbackWithBuffer(Camera.PreviewCallback)
683 * @see #startPreview()
Eino-Ville Talvalab942b052014-07-10 17:45:03 -0700684 *
685 * @deprecated We recommend using the new {@link android.hardware.camera2} API for new
686 * applications.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800687 */
Eino-Ville Talvalab942b052014-07-10 17:45:03 -0700688 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800689 public interface PreviewCallback
690 {
691 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700692 * Called as preview frames are displayed. This callback is invoked
Dan Egnor341ff132010-07-20 11:30:17 -0700693 * on the event thread {@link #open(int)} was called from.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800694 *
Eino-Ville Talvala95151632012-05-02 16:21:18 -0700695 * <p>If using the {@link android.graphics.ImageFormat#YV12} format,
696 * refer to the equations in {@link Camera.Parameters#setPreviewFormat}
697 * for the arrangement of the pixel data in the preview callback
698 * buffers.
699 *
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700700 * @param data the contents of the preview frame in the format defined
Mathias Agopiana696f5d2010-02-17 17:53:09 -0800701 * by {@link android.graphics.ImageFormat}, which can be queried
Scott Maindf4578e2009-09-10 12:22:07 -0700702 * with {@link android.hardware.Camera.Parameters#getPreviewFormat()}.
Scott Mainda0a56d2009-09-10 18:08:37 -0700703 * If {@link android.hardware.Camera.Parameters#setPreviewFormat(int)}
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800704 * is never called, the default will be the YCbCr_420_SP
705 * (NV21) format.
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700706 * @param camera the Camera service object.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800707 */
708 void onPreviewFrame(byte[] data, Camera camera);
709 };
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800710
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800711 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700712 * Starts capturing and drawing preview frames to the screen.
Eino-Ville Talvalac5f94d82011-02-18 11:02:42 -0800713 * Preview will not actually start until a surface is supplied
714 * with {@link #setPreviewDisplay(SurfaceHolder)} or
715 * {@link #setPreviewTexture(SurfaceTexture)}.
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700716 *
717 * <p>If {@link #setPreviewCallback(Camera.PreviewCallback)},
718 * {@link #setOneShotPreviewCallback(Camera.PreviewCallback)}, or
719 * {@link #setPreviewCallbackWithBuffer(Camera.PreviewCallback)} were
720 * called, {@link Camera.PreviewCallback#onPreviewFrame(byte[], Camera)}
721 * will be called when preview data becomes available.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800722 */
723 public native final void startPreview();
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800724
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800725 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700726 * Stops capturing and drawing preview frames to the surface, and
727 * resets the camera for a future call to {@link #startPreview()}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800728 */
Wu-cheng Li4c2292e2011-07-22 02:37:11 +0800729 public final void stopPreview() {
730 _stopPreview();
731 mFaceDetectionRunning = false;
Chih-yu Huang664d72e2011-09-23 18:59:38 +0800732
733 mShutterCallback = null;
734 mRawImageCallback = null;
735 mPostviewCallback = null;
736 mJpegCallback = null;
Wu-cheng Lif05c1d62012-05-02 23:29:47 +0800737 synchronized (mAutoFocusCallbackLock) {
738 mAutoFocusCallback = null;
739 }
Wu-cheng Li9d062cf2011-11-14 20:30:14 +0800740 mAutoFocusMoveCallback = null;
Wu-cheng Li4c2292e2011-07-22 02:37:11 +0800741 }
742
743 private native final void _stopPreview();
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800744
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800745 /**
746 * Return current preview state.
747 *
748 * FIXME: Unhide before release
749 * @hide
750 */
751 public native final boolean previewEnabled();
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800752
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800753 /**
Eino-Ville Talvala108708b2012-03-05 11:00:43 -0800754 * <p>Installs a callback to be invoked for every preview frame in addition
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700755 * to displaying them on the screen. The callback will be repeatedly called
756 * for as long as preview is active. This method can be called at any time,
Eino-Ville Talvala108708b2012-03-05 11:00:43 -0800757 * even while preview is live. Any other preview callbacks are
758 * overridden.</p>
759 *
760 * <p>If you are using the preview data to create video or still images,
761 * strongly consider using {@link android.media.MediaActionSound} to
762 * properly indicate image capture or recording start/stop to the user.</p>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800763 *
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700764 * @param cb a callback object that receives a copy of each preview frame,
765 * or null to stop receiving callbacks.
Eino-Ville Talvala108708b2012-03-05 11:00:43 -0800766 * @see android.media.MediaActionSound
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800767 */
768 public final void setPreviewCallback(PreviewCallback cb) {
769 mPreviewCallback = cb;
770 mOneShot = false;
Andrew Harp94927df2009-10-20 01:47:05 -0400771 mWithBuffer = false;
Eino-Ville Talvala7005b672013-04-02 15:46:38 -0700772 if (cb != null) {
773 mUsingPreviewAllocation = false;
774 }
Dave Sparksa6118c62009-10-13 02:28:54 -0700775 // Always use one-shot mode. We fake camera preview mode by
776 // doing one-shot preview continuously.
Andrew Harp94927df2009-10-20 01:47:05 -0400777 setHasPreviewCallback(cb != null, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800778 }
779
780 /**
Eino-Ville Talvala108708b2012-03-05 11:00:43 -0800781 * <p>Installs a callback to be invoked for the next preview frame in
782 * addition to displaying it on the screen. After one invocation, the
783 * callback is cleared. This method can be called any time, even when
784 * preview is live. Any other preview callbacks are overridden.</p>
785 *
786 * <p>If you are using the preview data to create video or still images,
787 * strongly consider using {@link android.media.MediaActionSound} to
788 * properly indicate image capture or recording start/stop to the user.</p>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800789 *
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700790 * @param cb a callback object that receives a copy of the next preview frame,
791 * or null to stop receiving callbacks.
Eino-Ville Talvala108708b2012-03-05 11:00:43 -0800792 * @see android.media.MediaActionSound
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800793 */
794 public final void setOneShotPreviewCallback(PreviewCallback cb) {
Andrew Harp94927df2009-10-20 01:47:05 -0400795 mPreviewCallback = cb;
796 mOneShot = true;
797 mWithBuffer = false;
Eino-Ville Talvala7005b672013-04-02 15:46:38 -0700798 if (cb != null) {
799 mUsingPreviewAllocation = false;
800 }
Andrew Harp94927df2009-10-20 01:47:05 -0400801 setHasPreviewCallback(cb != null, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800802 }
803
Andrew Harp94927df2009-10-20 01:47:05 -0400804 private native final void setHasPreviewCallback(boolean installed, boolean manualBuffer);
805
806 /**
Eino-Ville Talvala108708b2012-03-05 11:00:43 -0800807 * <p>Installs a callback to be invoked for every preview frame, using
808 * buffers supplied with {@link #addCallbackBuffer(byte[])}, in addition to
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700809 * displaying them on the screen. The callback will be repeatedly called
Eino-Ville Talvala108708b2012-03-05 11:00:43 -0800810 * for as long as preview is active and buffers are available. Any other
811 * preview callbacks are overridden.</p>
Andrew Harp94927df2009-10-20 01:47:05 -0400812 *
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700813 * <p>The purpose of this method is to improve preview efficiency and frame
814 * rate by allowing preview frame memory reuse. You must call
815 * {@link #addCallbackBuffer(byte[])} at some point -- before or after
Eino-Ville Talvala108708b2012-03-05 11:00:43 -0800816 * calling this method -- or no callbacks will received.</p>
Andrew Harp94927df2009-10-20 01:47:05 -0400817 *
Eino-Ville Talvala108708b2012-03-05 11:00:43 -0800818 * <p>The buffer queue will be cleared if this method is called with a null
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700819 * callback, {@link #setPreviewCallback(Camera.PreviewCallback)} is called,
Eino-Ville Talvala108708b2012-03-05 11:00:43 -0800820 * or {@link #setOneShotPreviewCallback(Camera.PreviewCallback)} is
821 * called.</p>
822 *
823 * <p>If you are using the preview data to create video or still images,
824 * strongly consider using {@link android.media.MediaActionSound} to
825 * properly indicate image capture or recording start/stop to the user.</p>
Andrew Harp94927df2009-10-20 01:47:05 -0400826 *
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700827 * @param cb a callback object that receives a copy of the preview frame,
828 * or null to stop receiving callbacks and clear the buffer queue.
829 * @see #addCallbackBuffer(byte[])
Eino-Ville Talvala108708b2012-03-05 11:00:43 -0800830 * @see android.media.MediaActionSound
Andrew Harp94927df2009-10-20 01:47:05 -0400831 */
832 public final void setPreviewCallbackWithBuffer(PreviewCallback cb) {
833 mPreviewCallback = cb;
834 mOneShot = false;
835 mWithBuffer = true;
Eino-Ville Talvala7005b672013-04-02 15:46:38 -0700836 if (cb != null) {
837 mUsingPreviewAllocation = false;
838 }
Andrew Harp94927df2009-10-20 01:47:05 -0400839 setHasPreviewCallback(cb != null, true);
840 }
841
842 /**
Wu-cheng Li3f4639a2010-04-04 15:05:41 +0800843 * Adds a pre-allocated buffer to the preview callback buffer queue.
844 * Applications can add one or more buffers to the queue. When a preview
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700845 * frame arrives and there is still at least one available buffer, the
846 * buffer will be used and removed from the queue. Then preview callback is
847 * invoked with the buffer. If a frame arrives and there is no buffer left,
848 * the frame is discarded. Applications should add buffers back when they
849 * finish processing the data in them.
Wu-cheng Lic10275a2010-03-09 13:49:21 -0800850 *
Eino-Ville Talvala95151632012-05-02 16:21:18 -0700851 * <p>For formats besides YV12, the size of the buffer is determined by
852 * multiplying the preview image width, height, and bytes per pixel. The
853 * width and height can be read from
854 * {@link Camera.Parameters#getPreviewSize()}. Bytes per pixel can be
855 * computed from {@link android.graphics.ImageFormat#getBitsPerPixel(int)} /
856 * 8, using the image format from
857 * {@link Camera.Parameters#getPreviewFormat()}.
858 *
859 * <p>If using the {@link android.graphics.ImageFormat#YV12} format, the
860 * size can be calculated using the equations listed in
861 * {@link Camera.Parameters#setPreviewFormat}.
Andrew Harp94927df2009-10-20 01:47:05 -0400862 *
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700863 * <p>This method is only necessary when
James Donge00cab72011-02-17 16:38:06 -0800864 * {@link #setPreviewCallbackWithBuffer(PreviewCallback)} is used. When
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700865 * {@link #setPreviewCallback(PreviewCallback)} or
866 * {@link #setOneShotPreviewCallback(PreviewCallback)} are used, buffers
James Donge00cab72011-02-17 16:38:06 -0800867 * are automatically allocated. When a supplied buffer is too small to
868 * hold the preview frame data, preview callback will return null and
869 * the buffer will be removed from the buffer queue.
Andrew Harp94927df2009-10-20 01:47:05 -0400870 *
Eino-Ville Talvala95151632012-05-02 16:21:18 -0700871 * @param callbackBuffer the buffer to add to the queue. The size of the
872 * buffer must match the values described above.
Wu-cheng Li5b9bcda2010-03-07 14:59:28 -0800873 * @see #setPreviewCallbackWithBuffer(PreviewCallback)
Andrew Harp94927df2009-10-20 01:47:05 -0400874 */
James Donge00cab72011-02-17 16:38:06 -0800875 public final void addCallbackBuffer(byte[] callbackBuffer)
876 {
877 _addCallbackBuffer(callbackBuffer, CAMERA_MSG_PREVIEW_FRAME);
878 }
879
880 /**
881 * Adds a pre-allocated buffer to the raw image callback buffer queue.
882 * Applications can add one or more buffers to the queue. When a raw image
883 * frame arrives and there is still at least one available buffer, the
884 * buffer will be used to hold the raw image data and removed from the
885 * queue. Then raw image callback is invoked with the buffer. If a raw
886 * image frame arrives but there is no buffer left, the frame is
887 * discarded. Applications should add buffers back when they finish
888 * processing the data in them by calling this method again in order
889 * to avoid running out of raw image callback buffers.
890 *
891 * <p>The size of the buffer is determined by multiplying the raw image
892 * width, height, and bytes per pixel. The width and height can be
893 * read from {@link Camera.Parameters#getPictureSize()}. Bytes per pixel
894 * can be computed from
895 * {@link android.graphics.ImageFormat#getBitsPerPixel(int)} / 8,
896 * using the image format from {@link Camera.Parameters#getPreviewFormat()}.
897 *
898 * <p>This method is only necessary when the PictureCallbck for raw image
899 * is used while calling {@link #takePicture(Camera.ShutterCallback,
900 * Camera.PictureCallback, Camera.PictureCallback, Camera.PictureCallback)}.
901 *
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -0700902 * <p>Please note that by calling this method, the mode for
903 * application-managed callback buffers is triggered. If this method has
904 * never been called, null will be returned by the raw image callback since
905 * there is no image callback buffer available. Furthermore, When a supplied
906 * buffer is too small to hold the raw image data, raw image callback will
907 * return null and the buffer will be removed from the buffer queue.
James Donge00cab72011-02-17 16:38:06 -0800908 *
909 * @param callbackBuffer the buffer to add to the raw image callback buffer
910 * queue. The size should be width * height * (bits per pixel) / 8. An
911 * null callbackBuffer will be ignored and won't be added to the queue.
912 *
913 * @see #takePicture(Camera.ShutterCallback,
914 * Camera.PictureCallback, Camera.PictureCallback, Camera.PictureCallback)}.
915 *
916 * {@hide}
917 */
918 public final void addRawImageCallbackBuffer(byte[] callbackBuffer)
919 {
920 addCallbackBuffer(callbackBuffer, CAMERA_MSG_RAW_IMAGE);
921 }
922
923 private final void addCallbackBuffer(byte[] callbackBuffer, int msgType)
924 {
925 // CAMERA_MSG_VIDEO_FRAME may be allowed in the future.
926 if (msgType != CAMERA_MSG_PREVIEW_FRAME &&
927 msgType != CAMERA_MSG_RAW_IMAGE) {
928 throw new IllegalArgumentException(
929 "Unsupported message type: " + msgType);
930 }
931
932 _addCallbackBuffer(callbackBuffer, msgType);
933 }
934
935 private native final void _addCallbackBuffer(
936 byte[] callbackBuffer, int msgType);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800937
Eino-Ville Talvala7005b672013-04-02 15:46:38 -0700938 /**
939 * <p>Create a {@link android.renderscript RenderScript}
940 * {@link android.renderscript.Allocation Allocation} to use as a
941 * destination of preview callback frames. Use
942 * {@link #setPreviewCallbackAllocation setPreviewCallbackAllocation} to use
943 * the created Allocation as a destination for camera preview frames.</p>
944 *
945 * <p>The Allocation will be created with a YUV type, and its contents must
946 * be accessed within Renderscript with the {@code rsGetElementAtYuv_*}
947 * accessor methods. Its size will be based on the current
948 * {@link Parameters#getPreviewSize preview size} configured for this
949 * camera.</p>
950 *
951 * @param rs the RenderScript context for this Allocation.
952 * @param usage additional usage flags to set for the Allocation. The usage
953 * flag {@link android.renderscript.Allocation#USAGE_IO_INPUT} will always
954 * be set on the created Allocation, but additional flags may be provided
955 * here.
956 * @return a new YUV-type Allocation with dimensions equal to the current
957 * preview size.
958 * @throws RSIllegalArgumentException if the usage flags are not compatible
959 * with an YUV Allocation.
960 * @see #setPreviewCallbackAllocation
961 * @hide
962 */
963 public final Allocation createPreviewAllocation(RenderScript rs, int usage)
964 throws RSIllegalArgumentException {
965 Parameters p = getParameters();
966 Size previewSize = p.getPreviewSize();
967 Type.Builder yuvBuilder = new Type.Builder(rs,
968 Element.createPixel(rs,
969 Element.DataType.UNSIGNED_8,
970 Element.DataKind.PIXEL_YUV));
971 // Use YV12 for wide compatibility. Changing this requires also
972 // adjusting camera service's format selection.
973 yuvBuilder.setYuvFormat(ImageFormat.YV12);
974 yuvBuilder.setX(previewSize.width);
975 yuvBuilder.setY(previewSize.height);
976
977 Allocation a = Allocation.createTyped(rs, yuvBuilder.create(),
978 usage | Allocation.USAGE_IO_INPUT);
979
980 return a;
981 }
982
983 /**
984 * <p>Set an {@link android.renderscript.Allocation Allocation} as the
985 * target of preview callback data. Use this method for efficient processing
986 * of camera preview data with RenderScript. The Allocation must be created
987 * with the {@link #createPreviewAllocation createPreviewAllocation }
988 * method.</p>
989 *
990 * <p>Setting a preview allocation will disable any active preview callbacks
991 * set by {@link #setPreviewCallback setPreviewCallback} or
992 * {@link #setPreviewCallbackWithBuffer setPreviewCallbackWithBuffer}, and
993 * vice versa. Using a preview allocation still requires an active standard
994 * preview target to be set, either with
995 * {@link #setPreviewTexture setPreviewTexture} or
996 * {@link #setPreviewDisplay setPreviewDisplay}.</p>
997 *
998 * <p>To be notified when new frames are available to the Allocation, use
999 * {@link android.renderscript.Allocation#setIoInputNotificationHandler Allocation.setIoInputNotificationHandler}. To
1000 * update the frame currently accessible from the Allocation to the latest
1001 * preview frame, call
1002 * {@link android.renderscript.Allocation#ioReceive Allocation.ioReceive}.</p>
1003 *
1004 * <p>To disable preview into the Allocation, call this method with a
1005 * {@code null} parameter.</p>
1006 *
1007 * <p>Once a preview allocation is set, the preview size set by
1008 * {@link Parameters#setPreviewSize setPreviewSize} cannot be changed. If
1009 * you wish to change the preview size, first remove the preview allocation
1010 * by calling {@code setPreviewCallbackAllocation(null)}, then change the
1011 * preview size, create a new preview Allocation with
1012 * {@link #createPreviewAllocation createPreviewAllocation}, and set it as
1013 * the new preview callback allocation target.</p>
1014 *
1015 * <p>If you are using the preview data to create video or still images,
1016 * strongly consider using {@link android.media.MediaActionSound} to
1017 * properly indicate image capture or recording start/stop to the user.</p>
1018 *
1019 * @param previewAllocation the allocation to use as destination for preview
1020 * @throws IOException if configuring the camera to use the Allocation for
1021 * preview fails.
1022 * @throws IllegalArgumentException if the Allocation's dimensions or other
1023 * parameters don't meet the requirements.
1024 * @see #createPreviewAllocation
1025 * @see #setPreviewCallback
1026 * @see #setPreviewCallbackWithBuffer
1027 * @hide
1028 */
1029 public final void setPreviewCallbackAllocation(Allocation previewAllocation)
1030 throws IOException {
1031 Surface previewSurface = null;
1032 if (previewAllocation != null) {
1033 Parameters p = getParameters();
1034 Size previewSize = p.getPreviewSize();
1035 if (previewSize.width != previewAllocation.getType().getX() ||
1036 previewSize.height != previewAllocation.getType().getY()) {
1037 throw new IllegalArgumentException(
1038 "Allocation dimensions don't match preview dimensions: " +
1039 "Allocation is " +
1040 previewAllocation.getType().getX() +
1041 ", " +
1042 previewAllocation.getType().getY() +
1043 ". Preview is " + previewSize.width + ", " +
1044 previewSize.height);
1045 }
1046 if ((previewAllocation.getUsage() &
1047 Allocation.USAGE_IO_INPUT) == 0) {
1048 throw new IllegalArgumentException(
1049 "Allocation usage does not include USAGE_IO_INPUT");
1050 }
1051 if (previewAllocation.getType().getElement().getDataKind() !=
1052 Element.DataKind.PIXEL_YUV) {
1053 throw new IllegalArgumentException(
1054 "Allocation is not of a YUV type");
1055 }
1056 previewSurface = previewAllocation.getSurface();
1057 mUsingPreviewAllocation = true;
1058 } else {
1059 mUsingPreviewAllocation = false;
1060 }
1061 setPreviewCallbackSurface(previewSurface);
1062 }
1063
1064 private native final void setPreviewCallbackSurface(Surface s);
1065
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001066 private class EventHandler extends Handler
1067 {
Igor Murashkina1d66272014-06-20 11:22:11 -07001068 private final Camera mCamera;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001069
1070 public EventHandler(Camera c, Looper looper) {
1071 super(looper);
1072 mCamera = c;
1073 }
1074
1075 @Override
1076 public void handleMessage(Message msg) {
1077 switch(msg.what) {
Dave Sparksc62f9bd2009-06-26 13:33:32 -07001078 case CAMERA_MSG_SHUTTER:
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001079 if (mShutterCallback != null) {
1080 mShutterCallback.onShutter();
1081 }
1082 return;
Dave Sparksc62f9bd2009-06-26 13:33:32 -07001083
1084 case CAMERA_MSG_RAW_IMAGE:
Dave Sparkse8b26e12009-07-14 10:35:40 -07001085 if (mRawImageCallback != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001086 mRawImageCallback.onPictureTaken((byte[])msg.obj, mCamera);
Dave Sparkse8b26e12009-07-14 10:35:40 -07001087 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001088 return;
1089
Dave Sparksc62f9bd2009-06-26 13:33:32 -07001090 case CAMERA_MSG_COMPRESSED_IMAGE:
Dave Sparkse8b26e12009-07-14 10:35:40 -07001091 if (mJpegCallback != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001092 mJpegCallback.onPictureTaken((byte[])msg.obj, mCamera);
Dave Sparkse8b26e12009-07-14 10:35:40 -07001093 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001094 return;
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001095
Dave Sparksc62f9bd2009-06-26 13:33:32 -07001096 case CAMERA_MSG_PREVIEW_FRAME:
Eino-Ville Talvalaca367b72012-05-30 16:01:33 -07001097 PreviewCallback pCb = mPreviewCallback;
1098 if (pCb != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001099 if (mOneShot) {
Dave Sparksa6118c62009-10-13 02:28:54 -07001100 // Clear the callback variable before the callback
1101 // in case the app calls setPreviewCallback from
1102 // the callback function
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001103 mPreviewCallback = null;
Andrew Harp94927df2009-10-20 01:47:05 -04001104 } else if (!mWithBuffer) {
Dave Sparksa6118c62009-10-13 02:28:54 -07001105 // We're faking the camera preview mode to prevent
1106 // the app from being flooded with preview frames.
1107 // Set to oneshot mode again.
Andrew Harp94927df2009-10-20 01:47:05 -04001108 setHasPreviewCallback(true, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001109 }
Eino-Ville Talvalaca367b72012-05-30 16:01:33 -07001110 pCb.onPreviewFrame((byte[])msg.obj, mCamera);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001111 }
1112 return;
1113
Dave Sparkse8b26e12009-07-14 10:35:40 -07001114 case CAMERA_MSG_POSTVIEW_FRAME:
1115 if (mPostviewCallback != null) {
1116 mPostviewCallback.onPictureTaken((byte[])msg.obj, mCamera);
1117 }
1118 return;
1119
Dave Sparksc62f9bd2009-06-26 13:33:32 -07001120 case CAMERA_MSG_FOCUS:
Wu-cheng Lif05c1d62012-05-02 23:29:47 +08001121 AutoFocusCallback cb = null;
1122 synchronized (mAutoFocusCallbackLock) {
1123 cb = mAutoFocusCallback;
1124 }
1125 if (cb != null) {
1126 boolean success = msg.arg1 == 0 ? false : true;
1127 cb.onAutoFocus(success, mCamera);
Dave Sparkse8b26e12009-07-14 10:35:40 -07001128 }
1129 return;
1130
1131 case CAMERA_MSG_ZOOM:
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08001132 if (mZoomListener != null) {
1133 mZoomListener.onZoomChange(msg.arg1, msg.arg2 != 0, mCamera);
Dave Sparkse8b26e12009-07-14 10:35:40 -07001134 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001135 return;
1136
Wu-cheng Libb1e2752011-07-30 05:00:37 +08001137 case CAMERA_MSG_PREVIEW_METADATA:
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08001138 if (mFaceListener != null) {
Wu-cheng Lif0d6a482011-07-28 05:30:59 +08001139 mFaceListener.onFaceDetection((Face[])msg.obj, mCamera);
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08001140 }
1141 return;
1142
Dave Sparksc62f9bd2009-06-26 13:33:32 -07001143 case CAMERA_MSG_ERROR :
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001144 Log.e(TAG, "Error " + msg.arg1);
Dave Sparkse8b26e12009-07-14 10:35:40 -07001145 if (mErrorCallback != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001146 mErrorCallback.onError(msg.arg1, mCamera);
Dave Sparkse8b26e12009-07-14 10:35:40 -07001147 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001148 return;
1149
Wu-cheng Li9d062cf2011-11-14 20:30:14 +08001150 case CAMERA_MSG_FOCUS_MOVE:
1151 if (mAutoFocusMoveCallback != null) {
1152 mAutoFocusMoveCallback.onAutoFocusMoving(msg.arg1 == 0 ? false : true, mCamera);
1153 }
1154 return;
1155
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001156 default:
1157 Log.e(TAG, "Unknown message type " + msg.what);
1158 return;
1159 }
1160 }
1161 }
1162
1163 private static void postEventFromNative(Object camera_ref,
1164 int what, int arg1, int arg2, Object obj)
1165 {
1166 Camera c = (Camera)((WeakReference)camera_ref).get();
1167 if (c == null)
1168 return;
1169
1170 if (c.mEventHandler != null) {
1171 Message m = c.mEventHandler.obtainMessage(what, arg1, arg2, obj);
1172 c.mEventHandler.sendMessage(m);
1173 }
1174 }
1175
1176 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -07001177 * Callback interface used to notify on completion of camera auto focus.
1178 *
Wu-cheng Li7478ea62009-09-16 18:52:55 +08001179 * <p>Devices that do not support auto-focus will receive a "fake"
1180 * callback to this interface. If your application needs auto-focus and
Scott Maindf4578e2009-09-10 12:22:07 -07001181 * should not be installed on devices <em>without</em> auto-focus, you must
1182 * declare that your app uses the
Wu-cheng Li7478ea62009-09-16 18:52:55 +08001183 * {@code android.hardware.camera.autofocus} feature, in the
Scott Maindf4578e2009-09-10 12:22:07 -07001184 * <a href="{@docRoot}guide/topics/manifest/uses-feature-element.html">&lt;uses-feature></a>
1185 * manifest element.</p>
Dan Egnorbfcbeff2010-07-12 15:12:54 -07001186 *
1187 * @see #autoFocus(AutoFocusCallback)
Eino-Ville Talvalab942b052014-07-10 17:45:03 -07001188 * @deprecated We recommend using the new {@link android.hardware.camera2} API for new
1189 * applications.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001190 */
Eino-Ville Talvalab942b052014-07-10 17:45:03 -07001191 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001192 public interface AutoFocusCallback
1193 {
1194 /**
Brad Fitzpatrick69ea4e12011-01-05 11:13:40 -08001195 * Called when the camera auto focus completes. If the camera
1196 * does not support auto-focus and autoFocus is called,
1197 * onAutoFocus will be called immediately with a fake value of
1198 * <code>success</code> set to <code>true</code>.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001199 *
Wu-cheng Lib4f95be2011-09-22 11:43:28 +08001200 * The auto-focus routine does not lock auto-exposure and auto-white
1201 * balance after it completes.
Eino-Ville Talvala83d33522011-05-13 10:25:00 -07001202 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001203 * @param success true if focus was successful, false if otherwise
1204 * @param camera the Camera service object
Eino-Ville Talvala83d33522011-05-13 10:25:00 -07001205 * @see android.hardware.Camera.Parameters#setAutoExposureLock(boolean)
1206 * @see android.hardware.Camera.Parameters#setAutoWhiteBalanceLock(boolean)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001207 */
1208 void onAutoFocus(boolean success, Camera camera);
Wu-cheng Li53b30912011-10-12 19:43:51 +08001209 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001210
1211 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -07001212 * Starts camera auto-focus and registers a callback function to run when
1213 * the camera is focused. This method is only valid when preview is active
1214 * (between {@link #startPreview()} and before {@link #stopPreview()}).
1215 *
1216 * <p>Callers should check
1217 * {@link android.hardware.Camera.Parameters#getFocusMode()} to determine if
1218 * this method should be called. If the camera does not support auto-focus,
1219 * it is a no-op and {@link AutoFocusCallback#onAutoFocus(boolean, Camera)}
Wu-cheng Li36322db2009-09-18 18:59:21 +08001220 * callback will be called immediately.
Dan Egnorbfcbeff2010-07-12 15:12:54 -07001221 *
Scott Mainda0a56d2009-09-10 18:08:37 -07001222 * <p>If your application should not be installed
Wu-cheng Li7478ea62009-09-16 18:52:55 +08001223 * on devices without auto-focus, you must declare that your application
1224 * uses auto-focus with the
Scott Maindf4578e2009-09-10 12:22:07 -07001225 * <a href="{@docRoot}guide/topics/manifest/uses-feature-element.html">&lt;uses-feature></a>
1226 * manifest element.</p>
Dan Egnorbfcbeff2010-07-12 15:12:54 -07001227 *
Wu-cheng Li068ef422009-09-27 13:19:36 -07001228 * <p>If the current flash mode is not
1229 * {@link android.hardware.Camera.Parameters#FLASH_MODE_OFF}, flash may be
Dan Egnorbfcbeff2010-07-12 15:12:54 -07001230 * fired during auto-focus, depending on the driver and camera hardware.<p>
Wu-cheng Li7478ea62009-09-16 18:52:55 +08001231 *
Wu-cheng Li53b30912011-10-12 19:43:51 +08001232 * <p>Auto-exposure lock {@link android.hardware.Camera.Parameters#getAutoExposureLock()}
Wu-cheng Lib4f95be2011-09-22 11:43:28 +08001233 * and auto-white balance locks {@link android.hardware.Camera.Parameters#getAutoWhiteBalanceLock()}
1234 * do not change during and after autofocus. But auto-focus routine may stop
1235 * auto-exposure and auto-white balance transiently during focusing.
Eino-Ville Talvala83d33522011-05-13 10:25:00 -07001236 *
Wu-cheng Li53b30912011-10-12 19:43:51 +08001237 * <p>Stopping preview with {@link #stopPreview()}, or triggering still
1238 * image capture with {@link #takePicture(Camera.ShutterCallback,
1239 * Camera.PictureCallback, Camera.PictureCallback)}, will not change the
1240 * the focus position. Applications must call cancelAutoFocus to reset the
1241 * focus.</p>
1242 *
Eino-Ville Talvala108708b2012-03-05 11:00:43 -08001243 * <p>If autofocus is successful, consider using
1244 * {@link android.media.MediaActionSound} to properly play back an autofocus
1245 * success sound to the user.</p>
1246 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001247 * @param cb the callback to run
Dan Egnorbfcbeff2010-07-12 15:12:54 -07001248 * @see #cancelAutoFocus()
Eino-Ville Talvala83d33522011-05-13 10:25:00 -07001249 * @see android.hardware.Camera.Parameters#setAutoExposureLock(boolean)
1250 * @see android.hardware.Camera.Parameters#setAutoWhiteBalanceLock(boolean)
Eino-Ville Talvala108708b2012-03-05 11:00:43 -08001251 * @see android.media.MediaActionSound
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001252 */
1253 public final void autoFocus(AutoFocusCallback cb)
1254 {
Wu-cheng Lif05c1d62012-05-02 23:29:47 +08001255 synchronized (mAutoFocusCallbackLock) {
James Dong248ba232012-04-28 21:30:46 -07001256 mAutoFocusCallback = cb;
James Dong248ba232012-04-28 21:30:46 -07001257 }
Wu-cheng Lif05c1d62012-05-02 23:29:47 +08001258 native_autoFocus();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001259 }
1260 private native final void native_autoFocus();
1261
1262 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -07001263 * Cancels any auto-focus function in progress.
1264 * Whether or not auto-focus is currently in progress,
1265 * this function will return the focus position to the default.
Chih-Chung Chang244f8c22009-09-15 14:51:56 +08001266 * If the camera does not support auto-focus, this is a no-op.
Dan Egnorbfcbeff2010-07-12 15:12:54 -07001267 *
1268 * @see #autoFocus(Camera.AutoFocusCallback)
Chih-Chung Chang244f8c22009-09-15 14:51:56 +08001269 */
1270 public final void cancelAutoFocus()
1271 {
Wu-cheng Lif05c1d62012-05-02 23:29:47 +08001272 synchronized (mAutoFocusCallbackLock) {
James Dong248ba232012-04-28 21:30:46 -07001273 mAutoFocusCallback = null;
James Dong248ba232012-04-28 21:30:46 -07001274 }
Wu-cheng Lif05c1d62012-05-02 23:29:47 +08001275 native_cancelAutoFocus();
1276 // CAMERA_MSG_FOCUS should be removed here because the following
1277 // scenario can happen:
1278 // - An application uses the same thread for autoFocus, cancelAutoFocus
1279 // and looper thread.
1280 // - The application calls autoFocus.
1281 // - HAL sends CAMERA_MSG_FOCUS, which enters the looper message queue.
1282 // Before event handler's handleMessage() is invoked, the application
1283 // calls cancelAutoFocus and autoFocus.
1284 // - The application gets the old CAMERA_MSG_FOCUS and thinks autofocus
1285 // has been completed. But in fact it is not.
1286 //
1287 // As documented in the beginning of the file, apps should not use
1288 // multiple threads to call autoFocus and cancelAutoFocus at the same
1289 // time. It is HAL's responsibility not to send a CAMERA_MSG_FOCUS
1290 // message after native_cancelAutoFocus is called.
1291 mEventHandler.removeMessages(CAMERA_MSG_FOCUS);
Chih-Chung Chang244f8c22009-09-15 14:51:56 +08001292 }
1293 private native final void native_cancelAutoFocus();
1294
1295 /**
Wu-cheng Li9d062cf2011-11-14 20:30:14 +08001296 * Callback interface used to notify on auto focus start and stop.
1297 *
Wu-cheng Li65745392012-04-12 18:07:16 +08001298 * <p>This is only supported in continuous autofocus modes -- {@link
1299 * Parameters#FOCUS_MODE_CONTINUOUS_VIDEO} and {@link
1300 * Parameters#FOCUS_MODE_CONTINUOUS_PICTURE}. Applications can show
1301 * autofocus animation based on this.</p>
Eino-Ville Talvalab942b052014-07-10 17:45:03 -07001302 *
1303 * @deprecated We recommend using the new {@link android.hardware.camera2} API for new
1304 * applications.
Wu-cheng Li9d062cf2011-11-14 20:30:14 +08001305 */
Eino-Ville Talvalab942b052014-07-10 17:45:03 -07001306 @Deprecated
Wu-cheng Li9d062cf2011-11-14 20:30:14 +08001307 public interface AutoFocusMoveCallback
1308 {
1309 /**
1310 * Called when the camera auto focus starts or stops.
1311 *
1312 * @param start true if focus starts to move, false if focus stops to move
Wu-cheng Li65745392012-04-12 18:07:16 +08001313 * @param camera the Camera service object
Wu-cheng Li9d062cf2011-11-14 20:30:14 +08001314 */
1315 void onAutoFocusMoving(boolean start, Camera camera);
1316 }
1317
1318 /**
1319 * Sets camera auto-focus move callback.
1320 *
1321 * @param cb the callback to run
Wu-cheng Li9d062cf2011-11-14 20:30:14 +08001322 */
1323 public void setAutoFocusMoveCallback(AutoFocusMoveCallback cb) {
1324 mAutoFocusMoveCallback = cb;
1325 enableFocusMoveCallback((mAutoFocusMoveCallback != null) ? 1 : 0);
1326 }
1327
1328 private native void enableFocusMoveCallback(int enable);
1329
1330 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -07001331 * Callback interface used to signal the moment of actual image capture.
1332 *
1333 * @see #takePicture(ShutterCallback, PictureCallback, PictureCallback, PictureCallback)
Eino-Ville Talvalab942b052014-07-10 17:45:03 -07001334 *
1335 * @deprecated We recommend using the new {@link android.hardware.camera2} API for new
1336 * applications.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001337 */
Eino-Ville Talvalab942b052014-07-10 17:45:03 -07001338 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001339 public interface ShutterCallback
1340 {
1341 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -07001342 * Called as near as possible to the moment when a photo is captured
1343 * from the sensor. This is a good opportunity to play a shutter sound
1344 * or give other feedback of camera operation. This may be some time
1345 * after the photo was triggered, but some time before the actual data
1346 * is available.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001347 */
1348 void onShutter();
1349 }
1350
1351 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -07001352 * Callback interface used to supply image data from a photo capture.
1353 *
1354 * @see #takePicture(ShutterCallback, PictureCallback, PictureCallback, PictureCallback)
Eino-Ville Talvalab942b052014-07-10 17:45:03 -07001355 *
1356 * @deprecated We recommend using the new {@link android.hardware.camera2} API for new
1357 * applications.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001358 */
Eino-Ville Talvalab942b052014-07-10 17:45:03 -07001359 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001360 public interface PictureCallback {
1361 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -07001362 * Called when image data is available after a picture is taken.
1363 * The format of the data depends on the context of the callback
1364 * and {@link Camera.Parameters} settings.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001365 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001366 * @param data a byte array of the picture data
1367 * @param camera the Camera service object
1368 */
1369 void onPictureTaken(byte[] data, Camera camera);
1370 };
1371
1372 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -07001373 * Equivalent to takePicture(shutter, raw, null, jpeg).
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001374 *
Dan Egnorbfcbeff2010-07-12 15:12:54 -07001375 * @see #takePicture(ShutterCallback, PictureCallback, PictureCallback, PictureCallback)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001376 */
1377 public final void takePicture(ShutterCallback shutter, PictureCallback raw,
1378 PictureCallback jpeg) {
Dave Sparkse8b26e12009-07-14 10:35:40 -07001379 takePicture(shutter, raw, null, jpeg);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001380 }
James Donge00cab72011-02-17 16:38:06 -08001381 private native final void native_takePicture(int msgType);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001382
Dave Sparkse8b26e12009-07-14 10:35:40 -07001383 /**
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001384 * Triggers an asynchronous image capture. The camera service will initiate
1385 * a series of callbacks to the application as the image capture progresses.
1386 * The shutter callback occurs after the image is captured. This can be used
1387 * to trigger a sound to let the user know that image has been captured. The
1388 * raw callback occurs when the raw image data is available (NOTE: the data
James Donge00cab72011-02-17 16:38:06 -08001389 * will be null if there is no raw image callback buffer available or the
1390 * raw image callback buffer is not large enough to hold the raw image).
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001391 * The postview callback occurs when a scaled, fully processed postview
1392 * image is available (NOTE: not all hardware supports this). The jpeg
1393 * callback occurs when the compressed image is available. If the
1394 * application does not need a particular callback, a null can be passed
1395 * instead of a callback method.
Dave Sparkse8b26e12009-07-14 10:35:40 -07001396 *
Dan Egnorbfcbeff2010-07-12 15:12:54 -07001397 * <p>This method is only valid when preview is active (after
1398 * {@link #startPreview()}). Preview will be stopped after the image is
1399 * taken; callers must call {@link #startPreview()} again if they want to
Wu-cheng Li42419ce2011-06-01 17:22:24 +08001400 * re-start preview or take more pictures. This should not be called between
1401 * {@link android.media.MediaRecorder#start()} and
1402 * {@link android.media.MediaRecorder#stop()}.
Wu-cheng Li40057ce2009-12-02 18:57:29 +08001403 *
Dan Egnorbfcbeff2010-07-12 15:12:54 -07001404 * <p>After calling this method, you must not call {@link #startPreview()}
1405 * or take another picture until the JPEG callback has returned.
1406 *
1407 * @param shutter the callback for image capture moment, or null
1408 * @param raw the callback for raw (uncompressed) image data, or null
Dave Sparkse8b26e12009-07-14 10:35:40 -07001409 * @param postview callback with postview image data, may be null
Dan Egnorbfcbeff2010-07-12 15:12:54 -07001410 * @param jpeg the callback for JPEG image data, or null
Dave Sparkse8b26e12009-07-14 10:35:40 -07001411 */
1412 public final void takePicture(ShutterCallback shutter, PictureCallback raw,
1413 PictureCallback postview, PictureCallback jpeg) {
1414 mShutterCallback = shutter;
1415 mRawImageCallback = raw;
1416 mPostviewCallback = postview;
1417 mJpegCallback = jpeg;
James Donge00cab72011-02-17 16:38:06 -08001418
1419 // If callback is not set, do not send me callbacks.
1420 int msgType = 0;
1421 if (mShutterCallback != null) {
1422 msgType |= CAMERA_MSG_SHUTTER;
1423 }
1424 if (mRawImageCallback != null) {
1425 msgType |= CAMERA_MSG_RAW_IMAGE;
1426 }
1427 if (mPostviewCallback != null) {
1428 msgType |= CAMERA_MSG_POSTVIEW_FRAME;
1429 }
1430 if (mJpegCallback != null) {
1431 msgType |= CAMERA_MSG_COMPRESSED_IMAGE;
1432 }
1433
1434 native_takePicture(msgType);
Wu-cheng Lie9c6c9c2012-05-29 16:47:44 +08001435 mFaceDetectionRunning = false;
Dave Sparkse8b26e12009-07-14 10:35:40 -07001436 }
1437
1438 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -07001439 * Zooms to the requested value smoothly. The driver will notify {@link
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08001440 * OnZoomChangeListener} of the zoom value and whether zoom is stopped at
1441 * the time. For example, suppose the current zoom is 0 and startSmoothZoom
Dan Egnorbfcbeff2010-07-12 15:12:54 -07001442 * is called with value 3. The
1443 * {@link Camera.OnZoomChangeListener#onZoomChange(int, boolean, Camera)}
1444 * method will be called three times with zoom values 1, 2, and 3.
1445 * Applications can call {@link #stopSmoothZoom} to stop the zoom earlier.
1446 * Applications should not call startSmoothZoom again or change the zoom
1447 * value before zoom stops. If the supplied zoom value equals to the current
1448 * zoom value, no zoom callback will be generated. This method is supported
1449 * if {@link android.hardware.Camera.Parameters#isSmoothZoomSupported}
1450 * returns true.
Wu-cheng Li36f68b82009-09-28 16:14:58 -07001451 *
1452 * @param value zoom value. The valid range is 0 to {@link
1453 * android.hardware.Camera.Parameters#getMaxZoom}.
Wu-cheng Li0ca25192010-03-29 16:21:12 +08001454 * @throws IllegalArgumentException if the zoom value is invalid.
1455 * @throws RuntimeException if the method fails.
Dan Egnorbfcbeff2010-07-12 15:12:54 -07001456 * @see #setZoomChangeListener(OnZoomChangeListener)
Wu-cheng Li36f68b82009-09-28 16:14:58 -07001457 */
1458 public native final void startSmoothZoom(int value);
1459
1460 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -07001461 * Stops the smooth zoom. Applications should wait for the {@link
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08001462 * OnZoomChangeListener} to know when the zoom is actually stopped. This
1463 * method is supported if {@link
Wu-cheng Li8cbb8f52010-02-28 23:19:55 -08001464 * android.hardware.Camera.Parameters#isSmoothZoomSupported} is true.
Wu-cheng Li0ca25192010-03-29 16:21:12 +08001465 *
1466 * @throws RuntimeException if the method fails.
Wu-cheng Li36f68b82009-09-28 16:14:58 -07001467 */
1468 public native final void stopSmoothZoom();
1469
1470 /**
Wu-cheng Li2fe6fca2010-10-15 14:42:23 +08001471 * Set the clockwise rotation of preview display in degrees. This affects
1472 * the preview frames and the picture displayed after snapshot. This method
1473 * is useful for portrait mode applications. Note that preview display of
Wu-cheng Lib982fb42010-10-19 17:19:09 +08001474 * front-facing cameras is flipped horizontally before the rotation, that
1475 * is, the image is reflected along the central vertical axis of the camera
1476 * sensor. So the users can see themselves as looking into a mirror.
Chih-Chung Changd1d77062010-01-22 17:49:48 -08001477 *
Brad Fitzpatrick69ea4e12011-01-05 11:13:40 -08001478 * <p>This does not affect the order of byte array passed in {@link
Wu-cheng Li2fe6fca2010-10-15 14:42:23 +08001479 * PreviewCallback#onPreviewFrame}, JPEG pictures, or recorded videos. This
1480 * method is not allowed to be called during preview.
Chih-Chung Changd1d77062010-01-22 17:49:48 -08001481 *
Brad Fitzpatrick69ea4e12011-01-05 11:13:40 -08001482 * <p>If you want to make the camera image show in the same orientation as
1483 * the display, you can use the following code.
Chih-Chung Changb8bb78f2010-06-10 13:32:16 +08001484 * <pre>
Chih-Chung Chang724c5222010-06-14 18:57:15 +08001485 * public static void setCameraDisplayOrientation(Activity activity,
1486 * int cameraId, android.hardware.Camera camera) {
1487 * android.hardware.Camera.CameraInfo info =
1488 * new android.hardware.Camera.CameraInfo();
1489 * android.hardware.Camera.getCameraInfo(cameraId, info);
1490 * int rotation = activity.getWindowManager().getDefaultDisplay()
1491 * .getRotation();
1492 * int degrees = 0;
1493 * switch (rotation) {
1494 * case Surface.ROTATION_0: degrees = 0; break;
1495 * case Surface.ROTATION_90: degrees = 90; break;
1496 * case Surface.ROTATION_180: degrees = 180; break;
1497 * case Surface.ROTATION_270: degrees = 270; break;
1498 * }
Chih-Chung Changb8bb78f2010-06-10 13:32:16 +08001499 *
Wu-cheng Li2fe6fca2010-10-15 14:42:23 +08001500 * int result;
1501 * if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
1502 * result = (info.orientation + degrees) % 360;
1503 * result = (360 - result) % 360; // compensate the mirror
1504 * } else { // back-facing
1505 * result = (info.orientation - degrees + 360) % 360;
1506 * }
Chih-Chung Chang724c5222010-06-14 18:57:15 +08001507 * camera.setDisplayOrientation(result);
1508 * }
Chih-Chung Changb8bb78f2010-06-10 13:32:16 +08001509 * </pre>
Wu-cheng Lid3033622011-10-07 13:13:54 +08001510 *
1511 * <p>Starting from API level 14, this method can be called when preview is
1512 * active.
1513 *
Eino-Ville Talvala6c91e2c2016-03-25 11:54:39 -07001514 * <p><b>Note: </b>Before API level 24, the default value for orientation is 0. Starting in
1515 * API level 24, the default orientation will be such that applications in forced-landscape mode
1516 * will have correct preview orientation, which may be either a default of 0 or
1517 * 180. Applications that operate in portrait mode or allow for changing orientation must still
1518 * call this method after each orientation change to ensure correct preview display in all
1519 * cases.</p>
1520 *
Chih-Chung Changd1d77062010-01-22 17:49:48 -08001521 * @param degrees the angle that the picture will be rotated clockwise.
Eino-Ville Talvala6c91e2c2016-03-25 11:54:39 -07001522 * Valid values are 0, 90, 180, and 270.
Wu-cheng Li2fe6fca2010-10-15 14:42:23 +08001523 * @see #setPreviewDisplay(SurfaceHolder)
Chih-Chung Changd1d77062010-01-22 17:49:48 -08001524 */
1525 public native final void setDisplayOrientation(int degrees);
1526
1527 /**
Eino-Ville Talvala487acdf2012-09-24 11:30:24 -07001528 * <p>Enable or disable the default shutter sound when taking a picture.</p>
Eino-Ville Talvala69fe5272012-09-07 12:26:40 -07001529 *
Eino-Ville Talvala487acdf2012-09-24 11:30:24 -07001530 * <p>By default, the camera plays the system-defined camera shutter sound
1531 * when {@link #takePicture} is called. Using this method, the shutter sound
1532 * can be disabled. It is strongly recommended that an alternative shutter
1533 * sound is played in the {@link ShutterCallback} when the system shutter
1534 * sound is disabled.</p>
Eino-Ville Talvala69fe5272012-09-07 12:26:40 -07001535 *
Eino-Ville Talvala487acdf2012-09-24 11:30:24 -07001536 * <p>Note that devices may not always allow disabling the camera shutter
1537 * sound. If the shutter sound state cannot be set to the desired value,
1538 * this method will return false. {@link CameraInfo#canDisableShutterSound}
1539 * can be used to determine whether the device will allow the shutter sound
1540 * to be disabled.</p>
Eino-Ville Talvala69fe5272012-09-07 12:26:40 -07001541 *
1542 * @param enabled whether the camera should play the system shutter sound
1543 * when {@link #takePicture takePicture} is called.
Eino-Ville Talvala487acdf2012-09-24 11:30:24 -07001544 * @return {@code true} if the shutter sound state was successfully
1545 * changed. {@code false} if the shutter sound state could not be
1546 * changed. {@code true} is also returned if shutter sound playback
1547 * is already set to the requested state.
Eino-Ville Talvala69fe5272012-09-07 12:26:40 -07001548 * @see #takePicture
Eino-Ville Talvala487acdf2012-09-24 11:30:24 -07001549 * @see CameraInfo#canDisableShutterSound
Eino-Ville Talvala69fe5272012-09-07 12:26:40 -07001550 * @see ShutterCallback
Eino-Ville Talvala69fe5272012-09-07 12:26:40 -07001551 */
Eino-Ville Talvala4f8e5ce2012-10-08 18:16:35 -07001552 public final boolean enableShutterSound(boolean enabled) {
1553 if (!enabled) {
1554 IBinder b = ServiceManager.getService(Context.AUDIO_SERVICE);
1555 IAudioService audioService = IAudioService.Stub.asInterface(b);
1556 try {
1557 if (audioService.isCameraSoundForced()) return false;
1558 } catch (RemoteException e) {
1559 Log.e(TAG, "Audio service is unavailable for queries");
1560 }
1561 }
1562 return _enableShutterSound(enabled);
1563 }
1564
Igor Murashkin66533622014-08-19 14:51:47 -07001565 /**
1566 * Disable the shutter sound unconditionally.
1567 *
1568 * <p>
1569 * This is only guaranteed to work for legacy cameras
1570 * (i.e. initialized with {@link #cameraInitUnspecified}). Trying to call this on
1571 * a regular camera will force a conditional check in the camera service.
1572 * </p>
1573 *
1574 * @return {@code true} if the shutter sound state was successfully
1575 * changed. {@code false} if the shutter sound state could not be
1576 * changed. {@code true} is also returned if shutter sound playback
1577 * is already set to the requested state.
1578 *
1579 * @hide
1580 */
1581 public final boolean disableShutterSound() {
1582 return _enableShutterSound(/*enabled*/false);
1583 }
1584
Eino-Ville Talvala4f8e5ce2012-10-08 18:16:35 -07001585 private native final boolean _enableShutterSound(boolean enabled);
Eino-Ville Talvala69fe5272012-09-07 12:26:40 -07001586
1587 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -07001588 * Callback interface for zoom changes during a smooth zoom operation.
1589 *
1590 * @see #setZoomChangeListener(OnZoomChangeListener)
1591 * @see #startSmoothZoom(int)
Eino-Ville Talvalab942b052014-07-10 17:45:03 -07001592 *
1593 * @deprecated We recommend using the new {@link android.hardware.camera2} API for new
1594 * applications.
Dave Sparkse8b26e12009-07-14 10:35:40 -07001595 */
Eino-Ville Talvalab942b052014-07-10 17:45:03 -07001596 @Deprecated
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08001597 public interface OnZoomChangeListener
Dave Sparkse8b26e12009-07-14 10:35:40 -07001598 {
1599 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -07001600 * Called when the zoom value has changed during a smooth zoom.
Wu-cheng Li36f68b82009-09-28 16:14:58 -07001601 *
1602 * @param zoomValue the current zoom value. In smooth zoom mode, camera
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08001603 * calls this for every new zoom value.
Wu-cheng Li36f68b82009-09-28 16:14:58 -07001604 * @param stopped whether smooth zoom is stopped. If the value is true,
1605 * this is the last zoom update for the application.
Dave Sparkse8b26e12009-07-14 10:35:40 -07001606 * @param camera the Camera service object
1607 */
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08001608 void onZoomChange(int zoomValue, boolean stopped, Camera camera);
Dave Sparkse8b26e12009-07-14 10:35:40 -07001609 };
1610
1611 /**
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08001612 * Registers a listener to be notified when the zoom value is updated by the
Wu-cheng Li36f68b82009-09-28 16:14:58 -07001613 * camera driver during smooth zoom.
Wu-cheng Li8cbb8f52010-02-28 23:19:55 -08001614 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08001615 * @param listener the listener to notify
Wu-cheng Li8cbb8f52010-02-28 23:19:55 -08001616 * @see #startSmoothZoom(int)
Dave Sparkse8b26e12009-07-14 10:35:40 -07001617 */
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08001618 public final void setZoomChangeListener(OnZoomChangeListener listener)
Dave Sparkse8b26e12009-07-14 10:35:40 -07001619 {
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08001620 mZoomListener = listener;
Dave Sparkse8b26e12009-07-14 10:35:40 -07001621 }
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001622
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08001623 /**
1624 * Callback interface for face detected in the preview frame.
1625 *
Eino-Ville Talvalab942b052014-07-10 17:45:03 -07001626 * @deprecated We recommend using the new {@link android.hardware.camera2} API for new
1627 * applications.
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08001628 */
Eino-Ville Talvalab942b052014-07-10 17:45:03 -07001629 @Deprecated
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08001630 public interface FaceDetectionListener
1631 {
1632 /**
1633 * Notify the listener of the detected faces in the preview frame.
1634 *
Wu-cheng Li53b30912011-10-12 19:43:51 +08001635 * @param faces The detected faces in a list
Joe Fernandez464cb212011-10-04 16:56:47 -07001636 * @param camera The {@link Camera} service object
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08001637 */
Wu-cheng Lif0d6a482011-07-28 05:30:59 +08001638 void onFaceDetection(Face[] faces, Camera camera);
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08001639 }
1640
1641 /**
Wu-cheng Lic0c683b2011-08-04 00:11:00 +08001642 * Registers a listener to be notified about the faces detected in the
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08001643 * preview frame.
1644 *
1645 * @param listener the listener to notify
Wu-cheng Lic0c683b2011-08-04 00:11:00 +08001646 * @see #startFaceDetection()
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08001647 */
1648 public final void setFaceDetectionListener(FaceDetectionListener listener)
1649 {
1650 mFaceListener = listener;
1651 }
1652
1653 /**
Wu-cheng Lic0c683b2011-08-04 00:11:00 +08001654 * Starts the face detection. This should be called after preview is started.
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08001655 * The camera will notify {@link FaceDetectionListener} of the detected
1656 * faces in the preview frame. The detected faces may be the same as the
1657 * previous ones. Applications should call {@link #stopFaceDetection} to
1658 * stop the face detection. This method is supported if {@link
Wu-cheng Lic0c683b2011-08-04 00:11:00 +08001659 * Parameters#getMaxNumDetectedFaces()} returns a number larger than 0.
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08001660 * If the face detection has started, apps should not call this again.
1661 *
Wu-cheng Li8c136702011-08-12 20:25:00 +08001662 * <p>When the face detection is running, {@link Parameters#setWhiteBalance(String)},
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08001663 * {@link Parameters#setFocusAreas(List)}, and {@link Parameters#setMeteringAreas(List)}
Wu-cheng Li8c136702011-08-12 20:25:00 +08001664 * have no effect. The camera uses the detected faces to do auto-white balance,
1665 * auto exposure, and autofocus.
1666 *
1667 * <p>If the apps call {@link #autoFocus(AutoFocusCallback)}, the camera
1668 * will stop sending face callbacks. The last face callback indicates the
1669 * areas used to do autofocus. After focus completes, face detection will
1670 * resume sending face callbacks. If the apps call {@link
1671 * #cancelAutoFocus()}, the face callbacks will also resume.</p>
1672 *
1673 * <p>After calling {@link #takePicture(Camera.ShutterCallback, Camera.PictureCallback,
1674 * Camera.PictureCallback)} or {@link #stopPreview()}, and then resuming
1675 * preview with {@link #startPreview()}, the apps should call this method
1676 * again to resume face detection.</p>
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08001677 *
Wu-cheng Lic0c683b2011-08-04 00:11:00 +08001678 * @throws IllegalArgumentException if the face detection is unsupported.
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08001679 * @throws RuntimeException if the method fails or the face detection is
1680 * already running.
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08001681 * @see FaceDetectionListener
1682 * @see #stopFaceDetection()
Wu-cheng Lic0c683b2011-08-04 00:11:00 +08001683 * @see Parameters#getMaxNumDetectedFaces()
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08001684 */
Wu-cheng Lic0c683b2011-08-04 00:11:00 +08001685 public final void startFaceDetection() {
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08001686 if (mFaceDetectionRunning) {
1687 throw new RuntimeException("Face detection is already running");
1688 }
Wu-cheng Lic0c683b2011-08-04 00:11:00 +08001689 _startFaceDetection(CAMERA_FACE_DETECTION_HW);
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08001690 mFaceDetectionRunning = true;
1691 }
1692
1693 /**
Wu-cheng Lic0c683b2011-08-04 00:11:00 +08001694 * Stops the face detection.
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08001695 *
Joe Fernandez464cb212011-10-04 16:56:47 -07001696 * @see #startFaceDetection()
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08001697 */
1698 public final void stopFaceDetection() {
1699 _stopFaceDetection();
1700 mFaceDetectionRunning = false;
1701 }
1702
1703 private native final void _startFaceDetection(int type);
1704 private native final void _stopFaceDetection();
1705
1706 /**
Joe Fernandez464cb212011-10-04 16:56:47 -07001707 * Information about a face identified through camera face detection.
Wu-cheng Li53b30912011-10-12 19:43:51 +08001708 *
Joe Fernandez464cb212011-10-04 16:56:47 -07001709 * <p>When face detection is used with a camera, the {@link FaceDetectionListener} returns a
1710 * list of face objects for use in focusing and metering.</p>
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08001711 *
Joe Fernandez464cb212011-10-04 16:56:47 -07001712 * @see FaceDetectionListener
Eino-Ville Talvalab942b052014-07-10 17:45:03 -07001713 * @deprecated We recommend using the new {@link android.hardware.camera2} API for new
1714 * applications.
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08001715 */
Eino-Ville Talvalab942b052014-07-10 17:45:03 -07001716 @Deprecated
Wu-cheng Lif0d6a482011-07-28 05:30:59 +08001717 public static class Face {
Wu-cheng Lic0c683b2011-08-04 00:11:00 +08001718 /**
1719 * Create an empty face.
1720 */
Wu-cheng Libb1e2752011-07-30 05:00:37 +08001721 public Face() {
1722 }
1723
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08001724 /**
1725 * Bounds of the face. (-1000, -1000) represents the top-left of the
1726 * camera field of view, and (1000, 1000) represents the bottom-right of
Wu-cheng Lic0c683b2011-08-04 00:11:00 +08001727 * the field of view. For example, suppose the size of the viewfinder UI
1728 * is 800x480. The rect passed from the driver is (-1000, -1000, 0, 0).
Wu-cheng Li8c136702011-08-12 20:25:00 +08001729 * The corresponding viewfinder rect should be (0, 0, 400, 240). It is
1730 * guaranteed left < right and top < bottom. The coordinates can be
1731 * smaller than -1000 or bigger than 1000. But at least one vertex will
1732 * be within (-1000, -1000) and (1000, 1000).
Wu-cheng Lif0d6a482011-07-28 05:30:59 +08001733 *
1734 * <p>The direction is relative to the sensor orientation, that is, what
1735 * the sensor sees. The direction is not affected by the rotation or
Wu-cheng Li8c136702011-08-12 20:25:00 +08001736 * mirroring of {@link #setDisplayOrientation(int)}. The face bounding
1737 * rectangle does not provide any information about face orientation.</p>
1738 *
1739 * <p>Here is the matrix to convert driver coordinates to View coordinates
1740 * in pixels.</p>
1741 * <pre>
1742 * Matrix matrix = new Matrix();
1743 * CameraInfo info = CameraHolder.instance().getCameraInfo()[cameraId];
1744 * // Need mirror for front camera.
1745 * boolean mirror = (info.facing == CameraInfo.CAMERA_FACING_FRONT);
1746 * matrix.setScale(mirror ? -1 : 1, 1);
1747 * // This is the value for android.hardware.Camera.setDisplayOrientation.
1748 * matrix.postRotate(displayOrientation);
1749 * // Camera driver coordinates range from (-1000, -1000) to (1000, 1000).
1750 * // UI coordinates range from (0, 0) to (width, height).
1751 * matrix.postScale(view.getWidth() / 2000f, view.getHeight() / 2000f);
1752 * matrix.postTranslate(view.getWidth() / 2f, view.getHeight() / 2f);
1753 * </pre>
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08001754 *
Joe Fernandez464cb212011-10-04 16:56:47 -07001755 * @see #startFaceDetection()
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08001756 */
Wu-cheng Libb1e2752011-07-30 05:00:37 +08001757 public Rect rect;
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08001758
1759 /**
Eino-Ville Talvala8df3b2b2012-09-15 14:30:12 -07001760 * <p>The confidence level for the detection of the face. The range is 1 to
1761 * 100. 100 is the highest confidence.</p>
1762 *
1763 * <p>Depending on the device, even very low-confidence faces may be
1764 * listed, so applications should filter out faces with low confidence,
1765 * depending on the use case. For a typical point-and-shoot camera
1766 * application that wishes to display rectangles around detected faces,
1767 * filtering out faces with confidence less than 50 is recommended.</p>
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08001768 *
Joe Fernandez464cb212011-10-04 16:56:47 -07001769 * @see #startFaceDetection()
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08001770 */
Wu-cheng Libb1e2752011-07-30 05:00:37 +08001771 public int score;
Wei Huad52b3082011-08-19 13:01:51 -07001772
1773 /**
1774 * An unique id per face while the face is visible to the tracker. If
1775 * the face leaves the field-of-view and comes back, it will get a new
1776 * id. This is an optional field, may not be supported on all devices.
1777 * If not supported, id will always be set to -1. The optional fields
1778 * are supported as a set. Either they are all valid, or none of them
1779 * are.
1780 */
1781 public int id = -1;
1782
1783 /**
1784 * The coordinates of the center of the left eye. The coordinates are in
1785 * the same space as the ones for {@link #rect}. This is an optional
1786 * field, may not be supported on all devices. If not supported, the
1787 * value will always be set to null. The optional fields are supported
1788 * as a set. Either they are all valid, or none of them are.
1789 */
1790 public Point leftEye = null;
1791
1792 /**
1793 * The coordinates of the center of the right eye. The coordinates are
1794 * in the same space as the ones for {@link #rect}.This is an optional
1795 * field, may not be supported on all devices. If not supported, the
1796 * value will always be set to null. The optional fields are supported
1797 * as a set. Either they are all valid, or none of them are.
1798 */
1799 public Point rightEye = null;
1800
1801 /**
1802 * The coordinates of the center of the mouth. The coordinates are in
1803 * the same space as the ones for {@link #rect}. This is an optional
1804 * field, may not be supported on all devices. If not supported, the
1805 * value will always be set to null. The optional fields are supported
1806 * as a set. Either they are all valid, or none of them are.
1807 */
1808 public Point mouth = null;
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08001809 }
1810
Dan Egnorbfcbeff2010-07-12 15:12:54 -07001811 /**
1812 * Unspecified camera error.
1813 * @see Camera.ErrorCallback
1814 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001815 public static final int CAMERA_ERROR_UNKNOWN = 1;
Dan Egnorbfcbeff2010-07-12 15:12:54 -07001816
1817 /**
Ruben Brunke91b9252015-04-14 13:38:06 -07001818 * Camera was disconnected due to use by higher priority user.
1819 * @see Camera.ErrorCallback
1820 */
1821 public static final int CAMERA_ERROR_EVICTED = 2;
1822
1823 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -07001824 * Media server died. In this case, the application must release the
1825 * Camera object and instantiate a new one.
1826 * @see Camera.ErrorCallback
1827 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001828 public static final int CAMERA_ERROR_SERVER_DIED = 100;
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001829
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001830 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -07001831 * Callback interface for camera error notification.
1832 *
1833 * @see #setErrorCallback(ErrorCallback)
Eino-Ville Talvalab942b052014-07-10 17:45:03 -07001834 *
1835 * @deprecated We recommend using the new {@link android.hardware.camera2} API for new
1836 * applications.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001837 */
Eino-Ville Talvalab942b052014-07-10 17:45:03 -07001838 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001839 public interface ErrorCallback
1840 {
1841 /**
1842 * Callback for camera errors.
1843 * @param error error code:
1844 * <ul>
1845 * <li>{@link #CAMERA_ERROR_UNKNOWN}
1846 * <li>{@link #CAMERA_ERROR_SERVER_DIED}
1847 * </ul>
1848 * @param camera the Camera service object
1849 */
1850 void onError(int error, Camera camera);
1851 };
1852
1853 /**
1854 * Registers a callback to be invoked when an error occurs.
Dan Egnorbfcbeff2010-07-12 15:12:54 -07001855 * @param cb The callback to run
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001856 */
1857 public final void setErrorCallback(ErrorCallback cb)
1858 {
1859 mErrorCallback = cb;
1860 }
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001861
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001862 private native final void native_setParameters(String params);
1863 private native final String native_getParameters();
1864
1865 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -07001866 * Changes the settings for this Camera service.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001867 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001868 * @param params the Parameters to use for this Camera service
Wu-cheng Li99a3f3e2010-11-19 15:56:16 +08001869 * @throws RuntimeException if any parameter is invalid or not supported.
Dan Egnorbfcbeff2010-07-12 15:12:54 -07001870 * @see #getParameters()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001871 */
1872 public void setParameters(Parameters params) {
Eino-Ville Talvala7005b672013-04-02 15:46:38 -07001873 // If using preview allocations, don't allow preview size changes
1874 if (mUsingPreviewAllocation) {
1875 Size newPreviewSize = params.getPreviewSize();
1876 Size currentPreviewSize = getParameters().getPreviewSize();
1877 if (newPreviewSize.width != currentPreviewSize.width ||
1878 newPreviewSize.height != currentPreviewSize.height) {
1879 throw new IllegalStateException("Cannot change preview size" +
1880 " while a preview allocation is configured.");
1881 }
1882 }
1883
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001884 native_setParameters(params.flatten());
1885 }
1886
1887 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -07001888 * Returns the current settings for this Camera service.
1889 * If modifications are made to the returned Parameters, they must be passed
1890 * to {@link #setParameters(Camera.Parameters)} to take effect.
1891 *
1892 * @see #setParameters(Camera.Parameters)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001893 */
1894 public Parameters getParameters() {
1895 Parameters p = new Parameters();
1896 String s = native_getParameters();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001897 p.unflatten(s);
1898 return p;
1899 }
1900
1901 /**
Wu-cheng Li1c04a332011-11-22 18:21:18 +08001902 * Returns an empty {@link Parameters} for testing purpose.
1903 *
Ken Wakasaf76a50c2012-03-09 19:56:35 +09001904 * @return a Parameter object.
Wu-cheng Li1c04a332011-11-22 18:21:18 +08001905 *
1906 * @hide
1907 */
1908 public static Parameters getEmptyParameters() {
1909 Camera camera = new Camera();
1910 return camera.new Parameters();
1911 }
1912
1913 /**
Igor Murashkindf6242e2014-07-01 18:06:13 -07001914 * Returns a copied {@link Parameters}; for shim use only.
1915 *
1916 * @param parameters a non-{@code null} parameters
1917 * @return a Parameter object, with all the parameters copied from {@code parameters}.
1918 *
1919 * @throws NullPointerException if {@code parameters} was {@code null}
1920 * @hide
1921 */
1922 public static Parameters getParametersCopy(Camera.Parameters parameters) {
1923 if (parameters == null) {
1924 throw new NullPointerException("parameters must not be null");
1925 }
1926
1927 Camera camera = parameters.getOuter();
1928 Parameters p = camera.new Parameters();
1929 p.copyFrom(parameters);
1930
1931 return p;
1932 }
1933
1934 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -07001935 * Image size (width and height dimensions).
Eino-Ville Talvalab942b052014-07-10 17:45:03 -07001936 * @deprecated We recommend using the new {@link android.hardware.camera2} API for new
1937 * applications.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001938 */
Eino-Ville Talvalab942b052014-07-10 17:45:03 -07001939 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001940 public class Size {
1941 /**
1942 * Sets the dimensions for pictures.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001943 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001944 * @param w the photo width (pixels)
1945 * @param h the photo height (pixels)
1946 */
1947 public Size(int w, int h) {
1948 width = w;
1949 height = h;
1950 }
Wu-cheng Li4c4300c2010-01-23 15:45:39 +08001951 /**
1952 * Compares {@code obj} to this size.
1953 *
1954 * @param obj the object to compare this size with.
1955 * @return {@code true} if the width and height of {@code obj} is the
1956 * same as those of this size. {@code false} otherwise.
1957 */
1958 @Override
1959 public boolean equals(Object obj) {
1960 if (!(obj instanceof Size)) {
1961 return false;
1962 }
1963 Size s = (Size) obj;
1964 return width == s.width && height == s.height;
1965 }
1966 @Override
1967 public int hashCode() {
1968 return width * 32713 + height;
1969 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001970 /** width of the picture */
1971 public int width;
1972 /** height of the picture */
1973 public int height;
1974 };
1975
1976 /**
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07001977 * <p>The Area class is used for choosing specific metering and focus areas for
1978 * the camera to use when calculating auto-exposure, auto-white balance, and
1979 * auto-focus.</p>
1980 *
1981 * <p>To find out how many simultaneous areas a given camera supports, use
1982 * {@link Parameters#getMaxNumMeteringAreas()} and
1983 * {@link Parameters#getMaxNumFocusAreas()}. If metering or focusing area
1984 * selection is unsupported, these methods will return 0.</p>
1985 *
1986 * <p>Each Area consists of a rectangle specifying its bounds, and a weight
1987 * that determines its importance. The bounds are relative to the camera's
1988 * current field of view. The coordinates are mapped so that (-1000, -1000)
1989 * is always the top-left corner of the current field of view, and (1000,
1990 * 1000) is always the bottom-right corner of the current field of
1991 * view. Setting Areas with bounds outside that range is not allowed. Areas
1992 * with zero or negative width or height are not allowed.</p>
1993 *
1994 * <p>The weight must range from 1 to 1000, and represents a weight for
1995 * every pixel in the area. This means that a large metering area with
1996 * the same weight as a smaller area will have more effect in the
1997 * metering result. Metering areas can overlap and the driver
1998 * will add the weights in the overlap region.</p>
Wu-cheng Li30771b72011-04-02 06:19:46 +08001999 *
Wu-cheng Libde61a52011-06-07 18:23:14 +08002000 * @see Parameters#setFocusAreas(List)
2001 * @see Parameters#getFocusAreas()
2002 * @see Parameters#getMaxNumFocusAreas()
2003 * @see Parameters#setMeteringAreas(List)
2004 * @see Parameters#getMeteringAreas()
2005 * @see Parameters#getMaxNumMeteringAreas()
Eino-Ville Talvalab942b052014-07-10 17:45:03 -07002006 *
2007 * @deprecated We recommend using the new {@link android.hardware.camera2} API for new
2008 * applications.
Wu-cheng Li30771b72011-04-02 06:19:46 +08002009 */
Eino-Ville Talvalab942b052014-07-10 17:45:03 -07002010 @Deprecated
Wu-cheng Li30771b72011-04-02 06:19:46 +08002011 public static class Area {
2012 /**
2013 * Create an area with specified rectangle and weight.
2014 *
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07002015 * @param rect the bounds of the area.
2016 * @param weight the weight of the area.
Wu-cheng Li30771b72011-04-02 06:19:46 +08002017 */
2018 public Area(Rect rect, int weight) {
2019 this.rect = rect;
2020 this.weight = weight;
2021 }
2022 /**
2023 * Compares {@code obj} to this area.
2024 *
2025 * @param obj the object to compare this area with.
2026 * @return {@code true} if the rectangle and weight of {@code obj} is
2027 * the same as those of this area. {@code false} otherwise.
2028 */
2029 @Override
2030 public boolean equals(Object obj) {
2031 if (!(obj instanceof Area)) {
2032 return false;
2033 }
2034 Area a = (Area) obj;
2035 if (rect == null) {
2036 if (a.rect != null) return false;
2037 } else {
2038 if (!rect.equals(a.rect)) return false;
2039 }
2040 return weight == a.weight;
2041 }
2042
Wu-cheng Libde61a52011-06-07 18:23:14 +08002043 /**
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07002044 * Bounds of the area. (-1000, -1000) represents the top-left of the
2045 * camera field of view, and (1000, 1000) represents the bottom-right of
2046 * the field of view. Setting bounds outside that range is not
2047 * allowed. Bounds with zero or negative width or height are not
2048 * allowed.
Wu-cheng Libde61a52011-06-07 18:23:14 +08002049 *
2050 * @see Parameters#getFocusAreas()
2051 * @see Parameters#getMeteringAreas()
2052 */
Wu-cheng Li30771b72011-04-02 06:19:46 +08002053 public Rect rect;
2054
Wu-cheng Libde61a52011-06-07 18:23:14 +08002055 /**
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07002056 * Weight of the area. The weight must range from 1 to 1000, and
2057 * represents a weight for every pixel in the area. This means that a
2058 * large metering area with the same weight as a smaller area will have
2059 * more effect in the metering result. Metering areas can overlap and
2060 * the driver will add the weights in the overlap region.
Wu-cheng Libde61a52011-06-07 18:23:14 +08002061 *
2062 * @see Parameters#getFocusAreas()
2063 * @see Parameters#getMeteringAreas()
2064 */
Wu-cheng Li30771b72011-04-02 06:19:46 +08002065 public int weight;
Wu-cheng Libde61a52011-06-07 18:23:14 +08002066 }
Wu-cheng Li30771b72011-04-02 06:19:46 +08002067
2068 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -07002069 * Camera service settings.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002070 *
2071 * <p>To make camera parameters take effect, applications have to call
Dan Egnorbfcbeff2010-07-12 15:12:54 -07002072 * {@link Camera#setParameters(Camera.Parameters)}. For example, after
2073 * {@link Camera.Parameters#setWhiteBalance} is called, white balance is not
2074 * actually changed until {@link Camera#setParameters(Camera.Parameters)}
2075 * is called with the changed parameters object.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002076 *
2077 * <p>Different devices may have different camera capabilities, such as
2078 * picture size or flash modes. The application should query the camera
2079 * capabilities before setting parameters. For example, the application
Dan Egnorbfcbeff2010-07-12 15:12:54 -07002080 * should call {@link Camera.Parameters#getSupportedColorEffects()} before
2081 * calling {@link Camera.Parameters#setColorEffect(String)}. If the
2082 * camera does not support color effects,
2083 * {@link Camera.Parameters#getSupportedColorEffects()} will return null.
Eino-Ville Talvalab942b052014-07-10 17:45:03 -07002084 *
2085 * @deprecated We recommend using the new {@link android.hardware.camera2} API for new
2086 * applications.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002087 */
Eino-Ville Talvalab942b052014-07-10 17:45:03 -07002088 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002089 public class Parameters {
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002090 // Parameter keys to communicate with the camera driver.
2091 private static final String KEY_PREVIEW_SIZE = "preview-size";
2092 private static final String KEY_PREVIEW_FORMAT = "preview-format";
2093 private static final String KEY_PREVIEW_FRAME_RATE = "preview-frame-rate";
Wu-cheng Li454630f2010-08-11 16:48:05 -07002094 private static final String KEY_PREVIEW_FPS_RANGE = "preview-fps-range";
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002095 private static final String KEY_PICTURE_SIZE = "picture-size";
2096 private static final String KEY_PICTURE_FORMAT = "picture-format";
Wu-cheng Li4c4300c2010-01-23 15:45:39 +08002097 private static final String KEY_JPEG_THUMBNAIL_SIZE = "jpeg-thumbnail-size";
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002098 private static final String KEY_JPEG_THUMBNAIL_WIDTH = "jpeg-thumbnail-width";
2099 private static final String KEY_JPEG_THUMBNAIL_HEIGHT = "jpeg-thumbnail-height";
2100 private static final String KEY_JPEG_THUMBNAIL_QUALITY = "jpeg-thumbnail-quality";
2101 private static final String KEY_JPEG_QUALITY = "jpeg-quality";
2102 private static final String KEY_ROTATION = "rotation";
2103 private static final String KEY_GPS_LATITUDE = "gps-latitude";
2104 private static final String KEY_GPS_LONGITUDE = "gps-longitude";
2105 private static final String KEY_GPS_ALTITUDE = "gps-altitude";
2106 private static final String KEY_GPS_TIMESTAMP = "gps-timestamp";
Ray Chen055c9862010-02-23 10:45:42 +08002107 private static final String KEY_GPS_PROCESSING_METHOD = "gps-processing-method";
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002108 private static final String KEY_WHITE_BALANCE = "whitebalance";
2109 private static final String KEY_EFFECT = "effect";
2110 private static final String KEY_ANTIBANDING = "antibanding";
2111 private static final String KEY_SCENE_MODE = "scene-mode";
2112 private static final String KEY_FLASH_MODE = "flash-mode";
Wu-cheng Li36322db2009-09-18 18:59:21 +08002113 private static final String KEY_FOCUS_MODE = "focus-mode";
Wu-cheng Li30771b72011-04-02 06:19:46 +08002114 private static final String KEY_FOCUS_AREAS = "focus-areas";
2115 private static final String KEY_MAX_NUM_FOCUS_AREAS = "max-num-focus-areas";
Wu-cheng Li6c8d2762010-01-27 22:55:14 +08002116 private static final String KEY_FOCAL_LENGTH = "focal-length";
2117 private static final String KEY_HORIZONTAL_VIEW_ANGLE = "horizontal-view-angle";
2118 private static final String KEY_VERTICAL_VIEW_ANGLE = "vertical-view-angle";
Wu-cheng Liff723b62010-02-09 13:38:19 +08002119 private static final String KEY_EXPOSURE_COMPENSATION = "exposure-compensation";
Wu-cheng Li24b326a2010-02-20 17:47:04 +08002120 private static final String KEY_MAX_EXPOSURE_COMPENSATION = "max-exposure-compensation";
2121 private static final String KEY_MIN_EXPOSURE_COMPENSATION = "min-exposure-compensation";
2122 private static final String KEY_EXPOSURE_COMPENSATION_STEP = "exposure-compensation-step";
Eino-Ville Talvala3773eef2011-04-15 13:51:42 -07002123 private static final String KEY_AUTO_EXPOSURE_LOCK = "auto-exposure-lock";
2124 private static final String KEY_AUTO_EXPOSURE_LOCK_SUPPORTED = "auto-exposure-lock-supported";
Eino-Ville Talvalad9c2601a2011-05-13 10:19:59 -07002125 private static final String KEY_AUTO_WHITEBALANCE_LOCK = "auto-whitebalance-lock";
2126 private static final String KEY_AUTO_WHITEBALANCE_LOCK_SUPPORTED = "auto-whitebalance-lock-supported";
Wu-cheng Lie98e4c82011-04-12 19:34:29 +08002127 private static final String KEY_METERING_AREAS = "metering-areas";
2128 private static final String KEY_MAX_NUM_METERING_AREAS = "max-num-metering-areas";
Wu-cheng Li8cbb8f52010-02-28 23:19:55 -08002129 private static final String KEY_ZOOM = "zoom";
2130 private static final String KEY_MAX_ZOOM = "max-zoom";
2131 private static final String KEY_ZOOM_RATIOS = "zoom-ratios";
2132 private static final String KEY_ZOOM_SUPPORTED = "zoom-supported";
2133 private static final String KEY_SMOOTH_ZOOM_SUPPORTED = "smooth-zoom-supported";
Wu-cheng Lie339c5e2010-05-13 19:31:02 +08002134 private static final String KEY_FOCUS_DISTANCES = "focus-distances";
James Dongdd0b16c2010-09-21 16:23:48 -07002135 private static final String KEY_VIDEO_SIZE = "video-size";
2136 private static final String KEY_PREFERRED_PREVIEW_SIZE_FOR_VIDEO =
2137 "preferred-preview-size-for-video";
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08002138 private static final String KEY_MAX_NUM_DETECTED_FACES_HW = "max-num-detected-faces-hw";
2139 private static final String KEY_MAX_NUM_DETECTED_FACES_SW = "max-num-detected-faces-sw";
Wu-cheng Li25d8fb52011-08-02 13:20:36 +08002140 private static final String KEY_RECORDING_HINT = "recording-hint";
Wu-cheng Li98bb2512011-08-30 21:33:10 +08002141 private static final String KEY_VIDEO_SNAPSHOT_SUPPORTED = "video-snapshot-supported";
Eino-Ville Talvala037abb82011-10-11 12:41:58 -07002142 private static final String KEY_VIDEO_STABILIZATION = "video-stabilization";
2143 private static final String KEY_VIDEO_STABILIZATION_SUPPORTED = "video-stabilization-supported";
Wu-cheng Lie339c5e2010-05-13 19:31:02 +08002144
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002145 // Parameter key suffix for supported values.
2146 private static final String SUPPORTED_VALUES_SUFFIX = "-values";
2147
Wu-cheng Li8cbb8f52010-02-28 23:19:55 -08002148 private static final String TRUE = "true";
Eino-Ville Talvala3773eef2011-04-15 13:51:42 -07002149 private static final String FALSE = "false";
Wu-cheng Li8cbb8f52010-02-28 23:19:55 -08002150
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002151 // Values for white balance settings.
2152 public static final String WHITE_BALANCE_AUTO = "auto";
2153 public static final String WHITE_BALANCE_INCANDESCENT = "incandescent";
2154 public static final String WHITE_BALANCE_FLUORESCENT = "fluorescent";
2155 public static final String WHITE_BALANCE_WARM_FLUORESCENT = "warm-fluorescent";
2156 public static final String WHITE_BALANCE_DAYLIGHT = "daylight";
2157 public static final String WHITE_BALANCE_CLOUDY_DAYLIGHT = "cloudy-daylight";
2158 public static final String WHITE_BALANCE_TWILIGHT = "twilight";
2159 public static final String WHITE_BALANCE_SHADE = "shade";
2160
2161 // Values for color effect settings.
2162 public static final String EFFECT_NONE = "none";
2163 public static final String EFFECT_MONO = "mono";
2164 public static final String EFFECT_NEGATIVE = "negative";
2165 public static final String EFFECT_SOLARIZE = "solarize";
2166 public static final String EFFECT_SEPIA = "sepia";
2167 public static final String EFFECT_POSTERIZE = "posterize";
2168 public static final String EFFECT_WHITEBOARD = "whiteboard";
2169 public static final String EFFECT_BLACKBOARD = "blackboard";
2170 public static final String EFFECT_AQUA = "aqua";
2171
2172 // Values for antibanding settings.
2173 public static final String ANTIBANDING_AUTO = "auto";
2174 public static final String ANTIBANDING_50HZ = "50hz";
2175 public static final String ANTIBANDING_60HZ = "60hz";
2176 public static final String ANTIBANDING_OFF = "off";
2177
2178 // Values for flash mode settings.
2179 /**
2180 * Flash will not be fired.
2181 */
2182 public static final String FLASH_MODE_OFF = "off";
Wu-cheng Li36f68b82009-09-28 16:14:58 -07002183
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002184 /**
Wu-cheng Li068ef422009-09-27 13:19:36 -07002185 * Flash will be fired automatically when required. The flash may be fired
2186 * during preview, auto-focus, or snapshot depending on the driver.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002187 */
2188 public static final String FLASH_MODE_AUTO = "auto";
Wu-cheng Li36f68b82009-09-28 16:14:58 -07002189
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002190 /**
Wu-cheng Li068ef422009-09-27 13:19:36 -07002191 * Flash will always be fired during snapshot. The flash may also be
2192 * fired during preview or auto-focus depending on the driver.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002193 */
2194 public static final String FLASH_MODE_ON = "on";
Wu-cheng Li36f68b82009-09-28 16:14:58 -07002195
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002196 /**
2197 * Flash will be fired in red-eye reduction mode.
2198 */
2199 public static final String FLASH_MODE_RED_EYE = "red-eye";
Wu-cheng Li36f68b82009-09-28 16:14:58 -07002200
Wu-cheng Li36322db2009-09-18 18:59:21 +08002201 /**
Wu-cheng Li068ef422009-09-27 13:19:36 -07002202 * Constant emission of light during preview, auto-focus and snapshot.
2203 * This can also be used for video recording.
Wu-cheng Li36322db2009-09-18 18:59:21 +08002204 */
Wu-cheng Li068ef422009-09-27 13:19:36 -07002205 public static final String FLASH_MODE_TORCH = "torch";
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002206
Wu-cheng Li00e21f82010-05-28 16:43:38 +08002207 /**
2208 * Scene mode is off.
2209 */
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002210 public static final String SCENE_MODE_AUTO = "auto";
Wu-cheng Li00e21f82010-05-28 16:43:38 +08002211
2212 /**
2213 * Take photos of fast moving objects. Same as {@link
2214 * #SCENE_MODE_SPORTS}.
2215 */
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002216 public static final String SCENE_MODE_ACTION = "action";
Wu-cheng Li00e21f82010-05-28 16:43:38 +08002217
2218 /**
2219 * Take people pictures.
2220 */
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002221 public static final String SCENE_MODE_PORTRAIT = "portrait";
Wu-cheng Li00e21f82010-05-28 16:43:38 +08002222
2223 /**
2224 * Take pictures on distant objects.
2225 */
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002226 public static final String SCENE_MODE_LANDSCAPE = "landscape";
Wu-cheng Li00e21f82010-05-28 16:43:38 +08002227
2228 /**
2229 * Take photos at night.
2230 */
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002231 public static final String SCENE_MODE_NIGHT = "night";
Wu-cheng Li00e21f82010-05-28 16:43:38 +08002232
2233 /**
2234 * Take people pictures at night.
2235 */
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002236 public static final String SCENE_MODE_NIGHT_PORTRAIT = "night-portrait";
Wu-cheng Li00e21f82010-05-28 16:43:38 +08002237
2238 /**
2239 * Take photos in a theater. Flash light is off.
2240 */
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002241 public static final String SCENE_MODE_THEATRE = "theatre";
Wu-cheng Li00e21f82010-05-28 16:43:38 +08002242
2243 /**
2244 * Take pictures on the beach.
2245 */
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002246 public static final String SCENE_MODE_BEACH = "beach";
Wu-cheng Li00e21f82010-05-28 16:43:38 +08002247
2248 /**
2249 * Take pictures on the snow.
2250 */
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002251 public static final String SCENE_MODE_SNOW = "snow";
Wu-cheng Li00e21f82010-05-28 16:43:38 +08002252
2253 /**
2254 * Take sunset photos.
2255 */
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002256 public static final String SCENE_MODE_SUNSET = "sunset";
Wu-cheng Li00e21f82010-05-28 16:43:38 +08002257
2258 /**
2259 * Avoid blurry pictures (for example, due to hand shake).
2260 */
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002261 public static final String SCENE_MODE_STEADYPHOTO = "steadyphoto";
Wu-cheng Li00e21f82010-05-28 16:43:38 +08002262
2263 /**
2264 * For shooting firework displays.
2265 */
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002266 public static final String SCENE_MODE_FIREWORKS = "fireworks";
Wu-cheng Li00e21f82010-05-28 16:43:38 +08002267
2268 /**
2269 * Take photos of fast moving objects. Same as {@link
2270 * #SCENE_MODE_ACTION}.
2271 */
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002272 public static final String SCENE_MODE_SPORTS = "sports";
Wu-cheng Li00e21f82010-05-28 16:43:38 +08002273
2274 /**
2275 * Take indoor low-light shot.
2276 */
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002277 public static final String SCENE_MODE_PARTY = "party";
Wu-cheng Li00e21f82010-05-28 16:43:38 +08002278
2279 /**
2280 * Capture the naturally warm color of scenes lit by candles.
2281 */
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002282 public static final String SCENE_MODE_CANDLELIGHT = "candlelight";
2283
Wu-cheng Lic58b4232010-03-29 17:21:28 +08002284 /**
2285 * Applications are looking for a barcode. Camera driver will be
2286 * optimized for barcode reading.
2287 */
2288 public static final String SCENE_MODE_BARCODE = "barcode";
2289
Wu-cheng Li36322db2009-09-18 18:59:21 +08002290 /**
Eino-Ville Talvalada2f0ea2012-09-10 12:03:35 -07002291 * Capture a scene using high dynamic range imaging techniques. The
2292 * camera will return an image that has an extended dynamic range
2293 * compared to a regular capture. Capturing such an image may take
2294 * longer than a regular capture.
Eino-Ville Talvalada2f0ea2012-09-10 12:03:35 -07002295 */
2296 public static final String SCENE_MODE_HDR = "hdr";
2297
2298 /**
Wu-cheng Lif008f3e2010-08-17 13:44:35 -07002299 * Auto-focus mode. Applications should call {@link
2300 * #autoFocus(AutoFocusCallback)} to start the focus in this mode.
Wu-cheng Li36322db2009-09-18 18:59:21 +08002301 */
2302 public static final String FOCUS_MODE_AUTO = "auto";
Wu-cheng Li36f68b82009-09-28 16:14:58 -07002303
Wu-cheng Li36322db2009-09-18 18:59:21 +08002304 /**
2305 * Focus is set at infinity. Applications should not call
2306 * {@link #autoFocus(AutoFocusCallback)} in this mode.
2307 */
2308 public static final String FOCUS_MODE_INFINITY = "infinity";
Wu-cheng Lif008f3e2010-08-17 13:44:35 -07002309
2310 /**
2311 * Macro (close-up) focus mode. Applications should call
2312 * {@link #autoFocus(AutoFocusCallback)} to start the focus in this
2313 * mode.
2314 */
Wu-cheng Li36322db2009-09-18 18:59:21 +08002315 public static final String FOCUS_MODE_MACRO = "macro";
Wu-cheng Li36f68b82009-09-28 16:14:58 -07002316
Wu-cheng Li36322db2009-09-18 18:59:21 +08002317 /**
2318 * Focus is fixed. The camera is always in this mode if the focus is not
2319 * adjustable. If the camera has auto-focus, this mode can fix the
2320 * focus, which is usually at hyperfocal distance. Applications should
2321 * not call {@link #autoFocus(AutoFocusCallback)} in this mode.
2322 */
2323 public static final String FOCUS_MODE_FIXED = "fixed";
2324
Wu-cheng Lic58b4232010-03-29 17:21:28 +08002325 /**
2326 * Extended depth of field (EDOF). Focusing is done digitally and
2327 * continuously. Applications should not call {@link
2328 * #autoFocus(AutoFocusCallback)} in this mode.
2329 */
2330 public static final String FOCUS_MODE_EDOF = "edof";
2331
Wu-cheng Li699fe932010-08-05 11:50:25 -07002332 /**
Wu-cheng Lid45cb722010-09-20 16:15:32 -07002333 * Continuous auto focus mode intended for video recording. The camera
Wu-cheng Lib9ac75d2011-08-16 21:14:16 +08002334 * continuously tries to focus. This is the best choice for video
2335 * recording because the focus changes smoothly . Applications still can
2336 * call {@link #takePicture(Camera.ShutterCallback,
2337 * Camera.PictureCallback, Camera.PictureCallback)} in this mode but the
2338 * subject may not be in focus. Auto focus starts when the parameter is
Wu-cheng Li53b30912011-10-12 19:43:51 +08002339 * set.
2340 *
2341 * <p>Since API level 14, applications can call {@link
2342 * #autoFocus(AutoFocusCallback)} in this mode. The focus callback will
2343 * immediately return with a boolean that indicates whether the focus is
2344 * sharp or not. The focus position is locked after autoFocus call. If
2345 * applications want to resume the continuous focus, cancelAutoFocus
2346 * must be called. Restarting the preview will not resume the continuous
2347 * autofocus. To stop continuous focus, applications should change the
2348 * focus mode to other modes.
2349 *
2350 * @see #FOCUS_MODE_CONTINUOUS_PICTURE
Wu-cheng Li699fe932010-08-05 11:50:25 -07002351 */
Wu-cheng Lid45cb722010-09-20 16:15:32 -07002352 public static final String FOCUS_MODE_CONTINUOUS_VIDEO = "continuous-video";
Wu-cheng Li699fe932010-08-05 11:50:25 -07002353
Wu-cheng Lib9ac75d2011-08-16 21:14:16 +08002354 /**
2355 * Continuous auto focus mode intended for taking pictures. The camera
2356 * continuously tries to focus. The speed of focus change is more
2357 * aggressive than {@link #FOCUS_MODE_CONTINUOUS_VIDEO}. Auto focus
Wu-cheng Li53b30912011-10-12 19:43:51 +08002358 * starts when the parameter is set.
2359 *
Wu-cheng Li0f4f97b2011-10-27 18:07:01 +08002360 * <p>Applications can call {@link #autoFocus(AutoFocusCallback)} in
2361 * this mode. If the autofocus is in the middle of scanning, the focus
2362 * callback will return when it completes. If the autofocus is not
2363 * scanning, the focus callback will immediately return with a boolean
2364 * that indicates whether the focus is sharp or not. The apps can then
2365 * decide if they want to take a picture immediately or to change the
2366 * focus mode to auto, and run a full autofocus cycle. The focus
2367 * position is locked after autoFocus call. If applications want to
2368 * resume the continuous focus, cancelAutoFocus must be called.
2369 * Restarting the preview will not resume the continuous autofocus. To
2370 * stop continuous focus, applications should change the focus mode to
2371 * other modes.
Wu-cheng Lib9ac75d2011-08-16 21:14:16 +08002372 *
2373 * @see #FOCUS_MODE_CONTINUOUS_VIDEO
Wu-cheng Lib9ac75d2011-08-16 21:14:16 +08002374 */
2375 public static final String FOCUS_MODE_CONTINUOUS_PICTURE = "continuous-picture";
2376
Wu-cheng Lie339c5e2010-05-13 19:31:02 +08002377 // Indices for focus distance array.
2378 /**
2379 * The array index of near focus distance for use with
2380 * {@link #getFocusDistances(float[])}.
2381 */
2382 public static final int FOCUS_DISTANCE_NEAR_INDEX = 0;
2383
2384 /**
2385 * The array index of optimal focus distance for use with
2386 * {@link #getFocusDistances(float[])}.
2387 */
2388 public static final int FOCUS_DISTANCE_OPTIMAL_INDEX = 1;
2389
2390 /**
2391 * The array index of far focus distance for use with
2392 * {@link #getFocusDistances(float[])}.
2393 */
2394 public static final int FOCUS_DISTANCE_FAR_INDEX = 2;
2395
Wu-cheng Lica099612010-05-06 16:47:30 +08002396 /**
Wu-cheng Li454630f2010-08-11 16:48:05 -07002397 * The array index of minimum preview fps for use with {@link
2398 * #getPreviewFpsRange(int[])} or {@link
2399 * #getSupportedPreviewFpsRange()}.
Wu-cheng Li454630f2010-08-11 16:48:05 -07002400 */
2401 public static final int PREVIEW_FPS_MIN_INDEX = 0;
2402
2403 /**
2404 * The array index of maximum preview fps for use with {@link
2405 * #getPreviewFpsRange(int[])} or {@link
2406 * #getSupportedPreviewFpsRange()}.
Wu-cheng Li454630f2010-08-11 16:48:05 -07002407 */
2408 public static final int PREVIEW_FPS_MAX_INDEX = 1;
2409
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002410 // Formats for setPreviewFormat and setPictureFormat.
2411 private static final String PIXEL_FORMAT_YUV422SP = "yuv422sp";
2412 private static final String PIXEL_FORMAT_YUV420SP = "yuv420sp";
Chih-Chung Changeb68c462009-09-18 18:37:44 +08002413 private static final String PIXEL_FORMAT_YUV422I = "yuv422i-yuyv";
Wu-cheng Li10a1b302011-02-22 15:49:25 +08002414 private static final String PIXEL_FORMAT_YUV420P = "yuv420p";
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002415 private static final String PIXEL_FORMAT_RGB565 = "rgb565";
2416 private static final String PIXEL_FORMAT_JPEG = "jpeg";
Wu-cheng Li70fb9082011-08-02 17:49:50 +08002417 private static final String PIXEL_FORMAT_BAYER_RGGB = "bayer-rggb";
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002418
Igor Murashkin7d9a8ff2014-03-18 18:14:41 -07002419 /**
2420 * Order matters: Keys that are {@link #set(String, String) set} later
2421 * will take precedence over keys that are set earlier (if the two keys
2422 * conflict with each other).
2423 *
2424 * <p>One example is {@link #setPreviewFpsRange(int, int)} , since it
2425 * conflicts with {@link #setPreviewFrameRate(int)} whichever key is set later
2426 * is the one that will take precedence.
2427 * </p>
2428 */
2429 private final LinkedHashMap<String, String> mMap;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002430
2431 private Parameters() {
Igor Murashkin7d9a8ff2014-03-18 18:14:41 -07002432 mMap = new LinkedHashMap<String, String>(/*initialCapacity*/64);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002433 }
2434
2435 /**
Igor Murashkindf6242e2014-07-01 18:06:13 -07002436 * Overwrite existing parameters with a copy of the ones from {@code other}.
2437 *
2438 * <b>For use by the legacy shim only.</b>
2439 *
2440 * @hide
2441 */
2442 public void copyFrom(Parameters other) {
2443 if (other == null) {
2444 throw new NullPointerException("other must not be null");
2445 }
2446
2447 mMap.putAll(other.mMap);
2448 }
2449
2450 private Camera getOuter() {
2451 return Camera.this;
2452 }
2453
Ruben Brunkd1f113d2014-07-11 11:46:20 -07002454
2455 /**
2456 * Value equality check.
2457 *
2458 * @hide
2459 */
2460 public boolean same(Parameters other) {
2461 if (this == other) {
2462 return true;
2463 }
2464 return other != null && Parameters.this.mMap.equals(other.mMap);
2465 }
2466
Igor Murashkindf6242e2014-07-01 18:06:13 -07002467 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002468 * Writes the current Parameters to the log.
2469 * @hide
2470 * @deprecated
2471 */
Igor Murashkina1d66272014-06-20 11:22:11 -07002472 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002473 public void dump() {
2474 Log.e(TAG, "dump: size=" + mMap.size());
2475 for (String k : mMap.keySet()) {
2476 Log.e(TAG, "dump: " + k + "=" + mMap.get(k));
2477 }
2478 }
2479
2480 /**
2481 * Creates a single string with all the parameters set in
2482 * this Parameters object.
2483 * <p>The {@link #unflatten(String)} method does the reverse.</p>
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002484 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002485 * @return a String with all values from this Parameters object, in
2486 * semi-colon delimited key-value pairs
2487 */
2488 public String flatten() {
Ali Utku Selen0a120182011-02-09 14:11:22 +01002489 StringBuilder flattened = new StringBuilder(128);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002490 for (String k : mMap.keySet()) {
2491 flattened.append(k);
2492 flattened.append("=");
2493 flattened.append(mMap.get(k));
2494 flattened.append(";");
2495 }
2496 // chop off the extra semicolon at the end
2497 flattened.deleteCharAt(flattened.length()-1);
2498 return flattened.toString();
2499 }
2500
2501 /**
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002502 * Takes a flattened string of parameters and adds each one to
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002503 * this Parameters object.
2504 * <p>The {@link #flatten()} method does the reverse.</p>
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002505 *
2506 * @param flattened a String of parameters (key-value paired) that
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002507 * are semi-colon delimited
2508 */
2509 public void unflatten(String flattened) {
2510 mMap.clear();
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002511
Ali Utku Selen0a120182011-02-09 14:11:22 +01002512 TextUtils.StringSplitter splitter = new TextUtils.SimpleStringSplitter(';');
2513 splitter.setString(flattened);
2514 for (String kv : splitter) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002515 int pos = kv.indexOf('=');
2516 if (pos == -1) {
2517 continue;
2518 }
2519 String k = kv.substring(0, pos);
2520 String v = kv.substring(pos + 1);
2521 mMap.put(k, v);
2522 }
2523 }
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002524
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002525 public void remove(String key) {
2526 mMap.remove(key);
2527 }
2528
2529 /**
2530 * Sets a String parameter.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002531 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002532 * @param key the key name for the parameter
2533 * @param value the String value of the parameter
2534 */
2535 public void set(String key, String value) {
Eino-Ville Talvalacb569232012-03-12 11:36:58 -07002536 if (key.indexOf('=') != -1 || key.indexOf(';') != -1 || key.indexOf(0) != -1) {
2537 Log.e(TAG, "Key \"" + key + "\" contains invalid character (= or ; or \\0)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002538 return;
2539 }
Eino-Ville Talvalacb569232012-03-12 11:36:58 -07002540 if (value.indexOf('=') != -1 || value.indexOf(';') != -1 || value.indexOf(0) != -1) {
2541 Log.e(TAG, "Value \"" + value + "\" contains invalid character (= or ; or \\0)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002542 return;
2543 }
2544
Igor Murashkin7d9a8ff2014-03-18 18:14:41 -07002545 put(key, value);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002546 }
2547
2548 /**
2549 * Sets an integer parameter.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002550 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002551 * @param key the key name for the parameter
2552 * @param value the int value of the parameter
2553 */
2554 public void set(String key, int value) {
Igor Murashkin7d9a8ff2014-03-18 18:14:41 -07002555 put(key, Integer.toString(value));
2556 }
2557
2558 private void put(String key, String value) {
2559 /*
2560 * Remove the key if it already exists.
2561 *
2562 * This way setting a new value for an already existing key will always move
2563 * that key to be ordered the latest in the map.
2564 */
2565 mMap.remove(key);
2566 mMap.put(key, value);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002567 }
2568
Wu-cheng Lie98e4c82011-04-12 19:34:29 +08002569 private void set(String key, List<Area> areas) {
Wu-cheng Lif715bf92011-04-14 14:04:18 +08002570 if (areas == null) {
2571 set(key, "(0,0,0,0,0)");
2572 } else {
2573 StringBuilder buffer = new StringBuilder();
2574 for (int i = 0; i < areas.size(); i++) {
2575 Area area = areas.get(i);
2576 Rect rect = area.rect;
2577 buffer.append('(');
2578 buffer.append(rect.left);
2579 buffer.append(',');
2580 buffer.append(rect.top);
2581 buffer.append(',');
2582 buffer.append(rect.right);
2583 buffer.append(',');
2584 buffer.append(rect.bottom);
2585 buffer.append(',');
2586 buffer.append(area.weight);
2587 buffer.append(')');
2588 if (i != areas.size() - 1) buffer.append(',');
2589 }
2590 set(key, buffer.toString());
Wu-cheng Lie98e4c82011-04-12 19:34:29 +08002591 }
Wu-cheng Lie98e4c82011-04-12 19:34:29 +08002592 }
2593
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002594 /**
2595 * Returns the value of a String parameter.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002596 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002597 * @param key the key name for the parameter
2598 * @return the String value of the parameter
2599 */
2600 public String get(String key) {
2601 return mMap.get(key);
2602 }
2603
2604 /**
2605 * Returns the value of an integer parameter.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002606 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002607 * @param key the key name for the parameter
2608 * @return the int value of the parameter
2609 */
2610 public int getInt(String key) {
2611 return Integer.parseInt(mMap.get(key));
2612 }
2613
2614 /**
Wu-cheng Li26274fa2011-05-05 14:36:28 +08002615 * Sets the dimensions for preview pictures. If the preview has already
2616 * started, applications should stop the preview first before changing
2617 * preview size.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002618 *
Wu-cheng Lic157e0c2010-10-07 18:36:07 +08002619 * The sides of width and height are based on camera orientation. That
2620 * is, the preview size is the size before it is rotated by display
2621 * orientation. So applications need to consider the display orientation
2622 * while setting preview size. For example, suppose the camera supports
2623 * both 480x320 and 320x480 preview sizes. The application wants a 3:2
2624 * preview ratio. If the display orientation is set to 0 or 180, preview
2625 * size should be set to 480x320. If the display orientation is set to
2626 * 90 or 270, preview size should be set to 320x480. The display
2627 * orientation should also be considered while setting picture size and
2628 * thumbnail size.
2629 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002630 * @param width the width of the pictures, in pixels
2631 * @param height the height of the pictures, in pixels
Wu-cheng Lic157e0c2010-10-07 18:36:07 +08002632 * @see #setDisplayOrientation(int)
2633 * @see #getCameraInfo(int, CameraInfo)
2634 * @see #setPictureSize(int, int)
2635 * @see #setJpegThumbnailSize(int, int)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002636 */
2637 public void setPreviewSize(int width, int height) {
2638 String v = Integer.toString(width) + "x" + Integer.toString(height);
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002639 set(KEY_PREVIEW_SIZE, v);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002640 }
2641
2642 /**
2643 * Returns the dimensions setting for preview pictures.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002644 *
James Dongdd0b16c2010-09-21 16:23:48 -07002645 * @return a Size object with the width and height setting
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002646 * for the preview picture
2647 */
2648 public Size getPreviewSize() {
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002649 String pair = get(KEY_PREVIEW_SIZE);
2650 return strToSize(pair);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002651 }
2652
2653 /**
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002654 * Gets the supported preview sizes.
2655 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08002656 * @return a list of Size object. This method will always return a list
Wu-cheng Li9c799382009-12-04 19:59:18 +08002657 * with at least one element.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002658 */
2659 public List<Size> getSupportedPreviewSizes() {
2660 String str = get(KEY_PREVIEW_SIZE + SUPPORTED_VALUES_SUFFIX);
2661 return splitSize(str);
2662 }
2663
2664 /**
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07002665 * <p>Gets the supported video frame sizes that can be used by
2666 * MediaRecorder.</p>
James Dongdd0b16c2010-09-21 16:23:48 -07002667 *
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07002668 * <p>If the returned list is not null, the returned list will contain at
James Dongdd0b16c2010-09-21 16:23:48 -07002669 * least one Size and one of the sizes in the returned list must be
2670 * passed to MediaRecorder.setVideoSize() for camcorder application if
2671 * camera is used as the video source. In this case, the size of the
2672 * preview can be different from the resolution of the recorded video
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07002673 * during video recording.</p>
James Dongdd0b16c2010-09-21 16:23:48 -07002674 *
2675 * @return a list of Size object if camera has separate preview and
2676 * video output; otherwise, null is returned.
2677 * @see #getPreferredPreviewSizeForVideo()
2678 */
2679 public List<Size> getSupportedVideoSizes() {
2680 String str = get(KEY_VIDEO_SIZE + SUPPORTED_VALUES_SUFFIX);
2681 return splitSize(str);
2682 }
2683
2684 /**
2685 * Returns the preferred or recommended preview size (width and height)
2686 * in pixels for video recording. Camcorder applications should
2687 * set the preview size to a value that is not larger than the
2688 * preferred preview size. In other words, the product of the width
2689 * and height of the preview size should not be larger than that of
2690 * the preferred preview size. In addition, we recommend to choose a
2691 * preview size that has the same aspect ratio as the resolution of
2692 * video to be recorded.
2693 *
2694 * @return the preferred preview size (width and height) in pixels for
2695 * video recording if getSupportedVideoSizes() does not return
2696 * null; otherwise, null is returned.
2697 * @see #getSupportedVideoSizes()
2698 */
2699 public Size getPreferredPreviewSizeForVideo() {
2700 String pair = get(KEY_PREFERRED_PREVIEW_SIZE_FOR_VIDEO);
2701 return strToSize(pair);
2702 }
2703
2704 /**
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07002705 * <p>Sets the dimensions for EXIF thumbnail in Jpeg picture. If
Wu-cheng Li4c4300c2010-01-23 15:45:39 +08002706 * applications set both width and height to 0, EXIF will not contain
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07002707 * thumbnail.</p>
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002708 *
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07002709 * <p>Applications need to consider the display orientation. See {@link
2710 * #setPreviewSize(int,int)} for reference.</p>
Wu-cheng Lic157e0c2010-10-07 18:36:07 +08002711 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002712 * @param width the width of the thumbnail, in pixels
2713 * @param height the height of the thumbnail, in pixels
Wu-cheng Lic157e0c2010-10-07 18:36:07 +08002714 * @see #setPreviewSize(int,int)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002715 */
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002716 public void setJpegThumbnailSize(int width, int height) {
2717 set(KEY_JPEG_THUMBNAIL_WIDTH, width);
2718 set(KEY_JPEG_THUMBNAIL_HEIGHT, height);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002719 }
2720
2721 /**
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002722 * Returns the dimensions for EXIF thumbnail in Jpeg picture.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002723 *
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002724 * @return a Size object with the height and width setting for the EXIF
2725 * thumbnails
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002726 */
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002727 public Size getJpegThumbnailSize() {
2728 return new Size(getInt(KEY_JPEG_THUMBNAIL_WIDTH),
2729 getInt(KEY_JPEG_THUMBNAIL_HEIGHT));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002730 }
2731
2732 /**
Wu-cheng Li4c4300c2010-01-23 15:45:39 +08002733 * Gets the supported jpeg thumbnail sizes.
2734 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08002735 * @return a list of Size object. This method will always return a list
Wu-cheng Li4c4300c2010-01-23 15:45:39 +08002736 * with at least two elements. Size 0,0 (no thumbnail) is always
2737 * supported.
2738 */
2739 public List<Size> getSupportedJpegThumbnailSizes() {
2740 String str = get(KEY_JPEG_THUMBNAIL_SIZE + SUPPORTED_VALUES_SUFFIX);
2741 return splitSize(str);
2742 }
2743
2744 /**
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002745 * Sets the quality of the EXIF thumbnail in Jpeg picture.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002746 *
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002747 * @param quality the JPEG quality of the EXIF thumbnail. The range is 1
2748 * to 100, with 100 being the best.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002749 */
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002750 public void setJpegThumbnailQuality(int quality) {
2751 set(KEY_JPEG_THUMBNAIL_QUALITY, quality);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002752 }
2753
2754 /**
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002755 * Returns the quality setting for the EXIF thumbnail in Jpeg picture.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002756 *
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002757 * @return the JPEG quality setting of the EXIF thumbnail.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002758 */
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002759 public int getJpegThumbnailQuality() {
2760 return getInt(KEY_JPEG_THUMBNAIL_QUALITY);
2761 }
2762
2763 /**
2764 * Sets Jpeg quality of captured picture.
2765 *
2766 * @param quality the JPEG quality of captured picture. The range is 1
2767 * to 100, with 100 being the best.
2768 */
2769 public void setJpegQuality(int quality) {
2770 set(KEY_JPEG_QUALITY, quality);
2771 }
2772
2773 /**
2774 * Returns the quality setting for the JPEG picture.
2775 *
2776 * @return the JPEG picture quality setting.
2777 */
2778 public int getJpegQuality() {
2779 return getInt(KEY_JPEG_QUALITY);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002780 }
2781
2782 /**
Wu-cheng Lia18e9012010-02-10 13:05:29 +08002783 * Sets the rate at which preview frames are received. This is the
2784 * target frame rate. The actual frame rate depends on the driver.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002785 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002786 * @param fps the frame rate (frames per second)
Wu-cheng Li5f1e69c2010-08-18 11:39:12 -07002787 * @deprecated replaced by {@link #setPreviewFpsRange(int,int)}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002788 */
Wu-cheng Li5f1e69c2010-08-18 11:39:12 -07002789 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002790 public void setPreviewFrameRate(int fps) {
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002791 set(KEY_PREVIEW_FRAME_RATE, fps);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002792 }
2793
2794 /**
Wu-cheng Lia18e9012010-02-10 13:05:29 +08002795 * Returns the setting for the rate at which preview frames are
2796 * received. This is the target frame rate. The actual frame rate
2797 * depends on the driver.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002798 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002799 * @return the frame rate setting (frames per second)
Wu-cheng Li5f1e69c2010-08-18 11:39:12 -07002800 * @deprecated replaced by {@link #getPreviewFpsRange(int[])}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002801 */
Wu-cheng Li5f1e69c2010-08-18 11:39:12 -07002802 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002803 public int getPreviewFrameRate() {
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002804 return getInt(KEY_PREVIEW_FRAME_RATE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002805 }
2806
2807 /**
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002808 * Gets the supported preview frame rates.
2809 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08002810 * @return a list of supported preview frame rates. null if preview
2811 * frame rate setting is not supported.
Wu-cheng Li5f1e69c2010-08-18 11:39:12 -07002812 * @deprecated replaced by {@link #getSupportedPreviewFpsRange()}
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002813 */
Wu-cheng Li5f1e69c2010-08-18 11:39:12 -07002814 @Deprecated
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002815 public List<Integer> getSupportedPreviewFrameRates() {
2816 String str = get(KEY_PREVIEW_FRAME_RATE + SUPPORTED_VALUES_SUFFIX);
2817 return splitInt(str);
2818 }
2819
2820 /**
Hai Guo4a68e3c2012-12-05 21:50:28 +08002821 * Sets the minimum and maximum preview fps. This controls the rate of
Wu-cheng Li1620d112010-08-27 15:09:20 -07002822 * preview frames received in {@link PreviewCallback}. The minimum and
Wu-cheng Li454630f2010-08-11 16:48:05 -07002823 * maximum preview fps must be one of the elements from {@link
2824 * #getSupportedPreviewFpsRange}.
2825 *
2826 * @param min the minimum preview fps (scaled by 1000).
2827 * @param max the maximum preview fps (scaled by 1000).
2828 * @throws RuntimeException if fps range is invalid.
2829 * @see #setPreviewCallbackWithBuffer(Camera.PreviewCallback)
2830 * @see #getSupportedPreviewFpsRange()
Wu-cheng Li454630f2010-08-11 16:48:05 -07002831 */
2832 public void setPreviewFpsRange(int min, int max) {
2833 set(KEY_PREVIEW_FPS_RANGE, "" + min + "," + max);
2834 }
2835
2836 /**
2837 * Returns the current minimum and maximum preview fps. The values are
2838 * one of the elements returned by {@link #getSupportedPreviewFpsRange}.
2839 *
2840 * @return range the minimum and maximum preview fps (scaled by 1000).
2841 * @see #PREVIEW_FPS_MIN_INDEX
2842 * @see #PREVIEW_FPS_MAX_INDEX
2843 * @see #getSupportedPreviewFpsRange()
Wu-cheng Li454630f2010-08-11 16:48:05 -07002844 */
2845 public void getPreviewFpsRange(int[] range) {
2846 if (range == null || range.length != 2) {
2847 throw new IllegalArgumentException(
Wu-cheng Li5f1e69c2010-08-18 11:39:12 -07002848 "range must be an array with two elements.");
Wu-cheng Li454630f2010-08-11 16:48:05 -07002849 }
2850 splitInt(get(KEY_PREVIEW_FPS_RANGE), range);
2851 }
2852
2853 /**
2854 * Gets the supported preview fps (frame-per-second) ranges. Each range
2855 * contains a minimum fps and maximum fps. If minimum fps equals to
2856 * maximum fps, the camera outputs frames in fixed frame rate. If not,
2857 * the camera outputs frames in auto frame rate. The actual frame rate
2858 * fluctuates between the minimum and the maximum. The values are
2859 * multiplied by 1000 and represented in integers. For example, if frame
2860 * rate is 26.623 frames per second, the value is 26623.
2861 *
2862 * @return a list of supported preview fps ranges. This method returns a
2863 * list with at least one element. Every element is an int array
2864 * of two values - minimum fps and maximum fps. The list is
2865 * sorted from small to large (first by maximum fps and then
2866 * minimum fps).
2867 * @see #PREVIEW_FPS_MIN_INDEX
2868 * @see #PREVIEW_FPS_MAX_INDEX
Wu-cheng Li454630f2010-08-11 16:48:05 -07002869 */
2870 public List<int[]> getSupportedPreviewFpsRange() {
2871 String str = get(KEY_PREVIEW_FPS_RANGE + SUPPORTED_VALUES_SUFFIX);
2872 return splitRange(str);
2873 }
2874
2875 /**
Wu-cheng Li7478ea62009-09-16 18:52:55 +08002876 * Sets the image format for preview pictures.
Scott Mainda0a56d2009-09-10 18:08:37 -07002877 * <p>If this is never called, the default format will be
Mathias Agopiana696f5d2010-02-17 17:53:09 -08002878 * {@link android.graphics.ImageFormat#NV21}, which
Scott Maindf4578e2009-09-10 12:22:07 -07002879 * uses the NV21 encoding format.</p>
Wu-cheng Li7478ea62009-09-16 18:52:55 +08002880 *
Eino-Ville Talvala95151632012-05-02 16:21:18 -07002881 * <p>Use {@link Parameters#getSupportedPreviewFormats} to get a list of
2882 * the available preview formats.
2883 *
2884 * <p>It is strongly recommended that either
2885 * {@link android.graphics.ImageFormat#NV21} or
2886 * {@link android.graphics.ImageFormat#YV12} is used, since
2887 * they are supported by all camera devices.</p>
2888 *
2889 * <p>For YV12, the image buffer that is received is not necessarily
2890 * tightly packed, as there may be padding at the end of each row of
2891 * pixel data, as described in
2892 * {@link android.graphics.ImageFormat#YV12}. For camera callback data,
2893 * it can be assumed that the stride of the Y and UV data is the
2894 * smallest possible that meets the alignment requirements. That is, if
2895 * the preview size is <var>width x height</var>, then the following
2896 * equations describe the buffer index for the beginning of row
2897 * <var>y</var> for the Y plane and row <var>c</var> for the U and V
2898 * planes:
2899 *
Neil Fuller71fbb812015-11-30 09:51:33 +00002900 * <pre>{@code
Eino-Ville Talvala95151632012-05-02 16:21:18 -07002901 * yStride = (int) ceil(width / 16.0) * 16;
2902 * uvStride = (int) ceil( (yStride / 2) / 16.0) * 16;
2903 * ySize = yStride * height;
2904 * uvSize = uvStride * height / 2;
2905 * yRowIndex = yStride * y;
2906 * uRowIndex = ySize + uvSize + uvStride * c;
2907 * vRowIndex = ySize + uvStride * c;
Neil Fuller71fbb812015-11-30 09:51:33 +00002908 * size = ySize + uvSize * 2;
Eino-Ville Talvala95151632012-05-02 16:21:18 -07002909 * }
Neil Fuller71fbb812015-11-30 09:51:33 +00002910 *</pre>
Eino-Ville Talvala95151632012-05-02 16:21:18 -07002911 *
2912 * @param pixel_format the desired preview picture format, defined by
2913 * one of the {@link android.graphics.ImageFormat} constants. (E.g.,
2914 * <var>ImageFormat.NV21</var> (default), or
2915 * <var>ImageFormat.YV12</var>)
2916 *
Mathias Agopiana696f5d2010-02-17 17:53:09 -08002917 * @see android.graphics.ImageFormat
Eino-Ville Talvala95151632012-05-02 16:21:18 -07002918 * @see android.hardware.Camera.Parameters#getSupportedPreviewFormats
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002919 */
2920 public void setPreviewFormat(int pixel_format) {
2921 String s = cameraFormatForPixelFormat(pixel_format);
2922 if (s == null) {
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002923 throw new IllegalArgumentException(
2924 "Invalid pixel_format=" + pixel_format);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002925 }
2926
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002927 set(KEY_PREVIEW_FORMAT, s);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002928 }
2929
2930 /**
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08002931 * Returns the image format for preview frames got from
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002932 * {@link PreviewCallback}.
Wu-cheng Li7478ea62009-09-16 18:52:55 +08002933 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08002934 * @return the preview format.
2935 * @see android.graphics.ImageFormat
Eino-Ville Talvala95151632012-05-02 16:21:18 -07002936 * @see #setPreviewFormat
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002937 */
2938 public int getPreviewFormat() {
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002939 return pixelFormatForCameraFormat(get(KEY_PREVIEW_FORMAT));
2940 }
2941
2942 /**
Wu-cheng Lif9293e72011-02-25 13:35:10 +08002943 * Gets the supported preview formats. {@link android.graphics.ImageFormat#NV21}
2944 * is always supported. {@link android.graphics.ImageFormat#YV12}
2945 * is always supported since API level 12.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002946 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08002947 * @return a list of supported preview formats. This method will always
2948 * return a list with at least one element.
2949 * @see android.graphics.ImageFormat
Eino-Ville Talvala95151632012-05-02 16:21:18 -07002950 * @see #setPreviewFormat
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002951 */
2952 public List<Integer> getSupportedPreviewFormats() {
2953 String str = get(KEY_PREVIEW_FORMAT + SUPPORTED_VALUES_SUFFIX);
Chih-Chung Changeb68c462009-09-18 18:37:44 +08002954 ArrayList<Integer> formats = new ArrayList<Integer>();
2955 for (String s : split(str)) {
2956 int f = pixelFormatForCameraFormat(s);
Mathias Agopiana696f5d2010-02-17 17:53:09 -08002957 if (f == ImageFormat.UNKNOWN) continue;
Chih-Chung Changeb68c462009-09-18 18:37:44 +08002958 formats.add(f);
2959 }
2960 return formats;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002961 }
2962
2963 /**
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07002964 * <p>Sets the dimensions for pictures.</p>
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002965 *
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07002966 * <p>Applications need to consider the display orientation. See {@link
2967 * #setPreviewSize(int,int)} for reference.</p>
Wu-cheng Lic157e0c2010-10-07 18:36:07 +08002968 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002969 * @param width the width for pictures, in pixels
2970 * @param height the height for pictures, in pixels
Wu-cheng Lic157e0c2010-10-07 18:36:07 +08002971 * @see #setPreviewSize(int,int)
2972 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002973 */
2974 public void setPictureSize(int width, int height) {
2975 String v = Integer.toString(width) + "x" + Integer.toString(height);
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002976 set(KEY_PICTURE_SIZE, v);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002977 }
2978
2979 /**
2980 * Returns the dimension setting for pictures.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002981 *
2982 * @return a Size object with the height and width setting
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002983 * for pictures
2984 */
2985 public Size getPictureSize() {
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002986 String pair = get(KEY_PICTURE_SIZE);
2987 return strToSize(pair);
2988 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002989
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002990 /**
2991 * Gets the supported picture sizes.
2992 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08002993 * @return a list of supported picture sizes. This method will always
2994 * return a list with at least one element.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002995 */
2996 public List<Size> getSupportedPictureSizes() {
2997 String str = get(KEY_PICTURE_SIZE + SUPPORTED_VALUES_SUFFIX);
2998 return splitSize(str);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002999 }
3000
3001 /**
3002 * Sets the image format for pictures.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003003 *
3004 * @param pixel_format the desired picture format
Mathias Agopiana696f5d2010-02-17 17:53:09 -08003005 * (<var>ImageFormat.NV21</var>,
3006 * <var>ImageFormat.RGB_565</var>, or
3007 * <var>ImageFormat.JPEG</var>)
3008 * @see android.graphics.ImageFormat
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003009 */
3010 public void setPictureFormat(int pixel_format) {
3011 String s = cameraFormatForPixelFormat(pixel_format);
3012 if (s == null) {
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003013 throw new IllegalArgumentException(
3014 "Invalid pixel_format=" + pixel_format);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003015 }
3016
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003017 set(KEY_PICTURE_FORMAT, s);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003018 }
3019
3020 /**
3021 * Returns the image format for pictures.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003022 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08003023 * @return the picture format
3024 * @see android.graphics.ImageFormat
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003025 */
3026 public int getPictureFormat() {
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003027 return pixelFormatForCameraFormat(get(KEY_PICTURE_FORMAT));
3028 }
3029
3030 /**
3031 * Gets the supported picture formats.
3032 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08003033 * @return supported picture formats. This method will always return a
3034 * list with at least one element.
3035 * @see android.graphics.ImageFormat
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003036 */
3037 public List<Integer> getSupportedPictureFormats() {
Wu-cheng Li9c799382009-12-04 19:59:18 +08003038 String str = get(KEY_PICTURE_FORMAT + SUPPORTED_VALUES_SUFFIX);
3039 ArrayList<Integer> formats = new ArrayList<Integer>();
3040 for (String s : split(str)) {
3041 int f = pixelFormatForCameraFormat(s);
Mathias Agopiana696f5d2010-02-17 17:53:09 -08003042 if (f == ImageFormat.UNKNOWN) continue;
Wu-cheng Li9c799382009-12-04 19:59:18 +08003043 formats.add(f);
3044 }
3045 return formats;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003046 }
3047
3048 private String cameraFormatForPixelFormat(int pixel_format) {
3049 switch(pixel_format) {
Mathias Agopiana696f5d2010-02-17 17:53:09 -08003050 case ImageFormat.NV16: return PIXEL_FORMAT_YUV422SP;
3051 case ImageFormat.NV21: return PIXEL_FORMAT_YUV420SP;
3052 case ImageFormat.YUY2: return PIXEL_FORMAT_YUV422I;
Wu-cheng Li10a1b302011-02-22 15:49:25 +08003053 case ImageFormat.YV12: return PIXEL_FORMAT_YUV420P;
Mathias Agopiana696f5d2010-02-17 17:53:09 -08003054 case ImageFormat.RGB_565: return PIXEL_FORMAT_RGB565;
3055 case ImageFormat.JPEG: return PIXEL_FORMAT_JPEG;
3056 default: return null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003057 }
3058 }
3059
3060 private int pixelFormatForCameraFormat(String format) {
3061 if (format == null)
Mathias Agopiana696f5d2010-02-17 17:53:09 -08003062 return ImageFormat.UNKNOWN;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003063
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003064 if (format.equals(PIXEL_FORMAT_YUV422SP))
Mathias Agopiana696f5d2010-02-17 17:53:09 -08003065 return ImageFormat.NV16;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003066
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003067 if (format.equals(PIXEL_FORMAT_YUV420SP))
Mathias Agopiana696f5d2010-02-17 17:53:09 -08003068 return ImageFormat.NV21;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003069
Chih-Chung Changeb68c462009-09-18 18:37:44 +08003070 if (format.equals(PIXEL_FORMAT_YUV422I))
Mathias Agopiana696f5d2010-02-17 17:53:09 -08003071 return ImageFormat.YUY2;
Chih-Chung Changeb68c462009-09-18 18:37:44 +08003072
Wu-cheng Li10a1b302011-02-22 15:49:25 +08003073 if (format.equals(PIXEL_FORMAT_YUV420P))
3074 return ImageFormat.YV12;
3075
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003076 if (format.equals(PIXEL_FORMAT_RGB565))
Mathias Agopiana696f5d2010-02-17 17:53:09 -08003077 return ImageFormat.RGB_565;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003078
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003079 if (format.equals(PIXEL_FORMAT_JPEG))
Mathias Agopiana696f5d2010-02-17 17:53:09 -08003080 return ImageFormat.JPEG;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003081
Mathias Agopiana696f5d2010-02-17 17:53:09 -08003082 return ImageFormat.UNKNOWN;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003083 }
3084
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003085 /**
Wu-cheng Li8969ea12012-04-20 17:38:09 +08003086 * Sets the clockwise rotation angle in degrees relative to the
3087 * orientation of the camera. This affects the pictures returned from
3088 * JPEG {@link PictureCallback}. The camera driver may set orientation
3089 * in the EXIF header without rotating the picture. Or the driver may
3090 * rotate the picture and the EXIF thumbnail. If the Jpeg picture is
Igor Murashkina1b02db2013-06-11 15:25:20 -07003091 * rotated, the orientation in the EXIF header will be missing or 1 (row
3092 * #0 is top and column #0 is left side).
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003093 *
Igor Murashkina1b02db2013-06-11 15:25:20 -07003094 * <p>
3095 * If applications want to rotate the picture to match the orientation
3096 * of what users see, apps should use
3097 * {@link android.view.OrientationEventListener} and
3098 * {@link android.hardware.Camera.CameraInfo}. The value from
3099 * OrientationEventListener is relative to the natural orientation of
3100 * the device. CameraInfo.orientation is the angle between camera
3101 * orientation and natural device orientation. The sum of the two is the
3102 * rotation angle for back-facing camera. The difference of the two is
3103 * the rotation angle for front-facing camera. Note that the JPEG
3104 * pictures of front-facing cameras are not mirrored as in preview
3105 * display.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003106 *
Igor Murashkina1b02db2013-06-11 15:25:20 -07003107 * <p>
3108 * For example, suppose the natural orientation of the device is
Wu-cheng Li2fb818c2010-09-13 20:02:01 -07003109 * portrait. The device is rotated 270 degrees clockwise, so the device
Wu-cheng Li2fe6fca2010-10-15 14:42:23 +08003110 * orientation is 270. Suppose a back-facing camera sensor is mounted in
3111 * landscape and the top side of the camera sensor is aligned with the
3112 * right edge of the display in natural orientation. So the camera
3113 * orientation is 90. The rotation should be set to 0 (270 + 90).
Wu-cheng Li2fb818c2010-09-13 20:02:01 -07003114 *
Brad Fitzpatrick69ea4e12011-01-05 11:13:40 -08003115 * <p>The reference code is as follows.
Wu-cheng Li2fb818c2010-09-13 20:02:01 -07003116 *
Eino-Ville Talvalae0cc55a2011-11-08 10:12:09 -08003117 * <pre>
Scott Main9a10bf02011-08-24 19:09:48 -07003118 * public void onOrientationChanged(int orientation) {
Wu-cheng Li2fb818c2010-09-13 20:02:01 -07003119 * if (orientation == ORIENTATION_UNKNOWN) return;
3120 * android.hardware.Camera.CameraInfo info =
3121 * new android.hardware.Camera.CameraInfo();
3122 * android.hardware.Camera.getCameraInfo(cameraId, info);
3123 * orientation = (orientation + 45) / 90 * 90;
Wu-cheng Li2fe6fca2010-10-15 14:42:23 +08003124 * int rotation = 0;
3125 * if (info.facing == CameraInfo.CAMERA_FACING_FRONT) {
3126 * rotation = (info.orientation - orientation + 360) % 360;
3127 * } else { // back-facing camera
3128 * rotation = (info.orientation + orientation) % 360;
3129 * }
3130 * mParameters.setRotation(rotation);
Wu-cheng Li2fb818c2010-09-13 20:02:01 -07003131 * }
Eino-Ville Talvalae0cc55a2011-11-08 10:12:09 -08003132 * </pre>
Wu-cheng Li2fb818c2010-09-13 20:02:01 -07003133 *
3134 * @param rotation The rotation angle in degrees relative to the
3135 * orientation of the camera. Rotation can only be 0,
3136 * 90, 180 or 270.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003137 * @throws IllegalArgumentException if rotation value is invalid.
3138 * @see android.view.OrientationEventListener
Wu-cheng Li2fb818c2010-09-13 20:02:01 -07003139 * @see #getCameraInfo(int, CameraInfo)
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003140 */
3141 public void setRotation(int rotation) {
3142 if (rotation == 0 || rotation == 90 || rotation == 180
3143 || rotation == 270) {
3144 set(KEY_ROTATION, Integer.toString(rotation));
3145 } else {
3146 throw new IllegalArgumentException(
3147 "Invalid rotation=" + rotation);
3148 }
3149 }
3150
3151 /**
3152 * Sets GPS latitude coordinate. This will be stored in JPEG EXIF
3153 * header.
3154 *
3155 * @param latitude GPS latitude coordinate.
3156 */
3157 public void setGpsLatitude(double latitude) {
3158 set(KEY_GPS_LATITUDE, Double.toString(latitude));
3159 }
3160
3161 /**
3162 * Sets GPS longitude coordinate. This will be stored in JPEG EXIF
3163 * header.
3164 *
3165 * @param longitude GPS longitude coordinate.
3166 */
3167 public void setGpsLongitude(double longitude) {
3168 set(KEY_GPS_LONGITUDE, Double.toString(longitude));
3169 }
3170
3171 /**
3172 * Sets GPS altitude. This will be stored in JPEG EXIF header.
3173 *
3174 * @param altitude GPS altitude in meters.
3175 */
3176 public void setGpsAltitude(double altitude) {
3177 set(KEY_GPS_ALTITUDE, Double.toString(altitude));
3178 }
3179
3180 /**
3181 * Sets GPS timestamp. This will be stored in JPEG EXIF header.
3182 *
3183 * @param timestamp GPS timestamp (UTC in seconds since January 1,
3184 * 1970).
3185 */
3186 public void setGpsTimestamp(long timestamp) {
3187 set(KEY_GPS_TIMESTAMP, Long.toString(timestamp));
3188 }
3189
3190 /**
Eino-Ville Talvalad8407272015-11-08 18:27:20 -08003191 * Sets GPS processing method. The method will be stored in a UTF-8 string up to 31 bytes
3192 * long, in the JPEG EXIF header.
Ray Chen055c9862010-02-23 10:45:42 +08003193 *
3194 * @param processing_method The processing method to get this location.
3195 */
3196 public void setGpsProcessingMethod(String processing_method) {
3197 set(KEY_GPS_PROCESSING_METHOD, processing_method);
3198 }
3199
3200 /**
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003201 * Removes GPS latitude, longitude, altitude, and timestamp from the
3202 * parameters.
3203 */
3204 public void removeGpsData() {
3205 remove(KEY_GPS_LATITUDE);
3206 remove(KEY_GPS_LONGITUDE);
3207 remove(KEY_GPS_ALTITUDE);
3208 remove(KEY_GPS_TIMESTAMP);
Ray Chen055c9862010-02-23 10:45:42 +08003209 remove(KEY_GPS_PROCESSING_METHOD);
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003210 }
3211
3212 /**
3213 * Gets the current white balance setting.
3214 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08003215 * @return current white balance. null if white balance setting is not
3216 * supported.
3217 * @see #WHITE_BALANCE_AUTO
3218 * @see #WHITE_BALANCE_INCANDESCENT
3219 * @see #WHITE_BALANCE_FLUORESCENT
3220 * @see #WHITE_BALANCE_WARM_FLUORESCENT
3221 * @see #WHITE_BALANCE_DAYLIGHT
3222 * @see #WHITE_BALANCE_CLOUDY_DAYLIGHT
3223 * @see #WHITE_BALANCE_TWILIGHT
3224 * @see #WHITE_BALANCE_SHADE
3225 *
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003226 */
3227 public String getWhiteBalance() {
3228 return get(KEY_WHITE_BALANCE);
3229 }
3230
3231 /**
Eino-Ville Talvala16b67132011-08-18 13:57:49 -07003232 * Sets the white balance. Changing the setting will release the
Wu-cheng Lib838d8d2011-11-17 20:12:23 +08003233 * auto-white balance lock. It is recommended not to change white
3234 * balance and AWB lock at the same time.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003235 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08003236 * @param value new white balance.
3237 * @see #getWhiteBalance()
Eino-Ville Talvala037abb82011-10-11 12:41:58 -07003238 * @see #setAutoWhiteBalanceLock(boolean)
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003239 */
3240 public void setWhiteBalance(String value) {
Wu-cheng Lib838d8d2011-11-17 20:12:23 +08003241 String oldValue = get(KEY_WHITE_BALANCE);
3242 if (same(value, oldValue)) return;
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003243 set(KEY_WHITE_BALANCE, value);
Eino-Ville Talvala16b67132011-08-18 13:57:49 -07003244 set(KEY_AUTO_WHITEBALANCE_LOCK, FALSE);
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003245 }
3246
3247 /**
3248 * Gets the supported white balance.
3249 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08003250 * @return a list of supported white balance. null if white balance
3251 * setting is not supported.
3252 * @see #getWhiteBalance()
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003253 */
3254 public List<String> getSupportedWhiteBalance() {
3255 String str = get(KEY_WHITE_BALANCE + SUPPORTED_VALUES_SUFFIX);
3256 return split(str);
3257 }
3258
3259 /**
3260 * Gets the current color effect setting.
3261 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08003262 * @return current color effect. null if color effect
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003263 * setting is not supported.
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08003264 * @see #EFFECT_NONE
3265 * @see #EFFECT_MONO
3266 * @see #EFFECT_NEGATIVE
3267 * @see #EFFECT_SOLARIZE
3268 * @see #EFFECT_SEPIA
3269 * @see #EFFECT_POSTERIZE
3270 * @see #EFFECT_WHITEBOARD
3271 * @see #EFFECT_BLACKBOARD
3272 * @see #EFFECT_AQUA
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003273 */
3274 public String getColorEffect() {
3275 return get(KEY_EFFECT);
3276 }
3277
3278 /**
3279 * Sets the current color effect setting.
3280 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08003281 * @param value new color effect.
3282 * @see #getColorEffect()
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003283 */
3284 public void setColorEffect(String value) {
3285 set(KEY_EFFECT, value);
3286 }
3287
3288 /**
3289 * Gets the supported color effects.
3290 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08003291 * @return a list of supported color effects. null if color effect
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003292 * setting is not supported.
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08003293 * @see #getColorEffect()
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003294 */
3295 public List<String> getSupportedColorEffects() {
3296 String str = get(KEY_EFFECT + SUPPORTED_VALUES_SUFFIX);
3297 return split(str);
3298 }
3299
3300
3301 /**
3302 * Gets the current antibanding setting.
3303 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08003304 * @return current antibanding. null if antibanding setting is not
3305 * supported.
3306 * @see #ANTIBANDING_AUTO
3307 * @see #ANTIBANDING_50HZ
3308 * @see #ANTIBANDING_60HZ
3309 * @see #ANTIBANDING_OFF
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003310 */
3311 public String getAntibanding() {
3312 return get(KEY_ANTIBANDING);
3313 }
3314
3315 /**
3316 * Sets the antibanding.
3317 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08003318 * @param antibanding new antibanding value.
3319 * @see #getAntibanding()
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003320 */
3321 public void setAntibanding(String antibanding) {
3322 set(KEY_ANTIBANDING, antibanding);
3323 }
3324
3325 /**
3326 * Gets the supported antibanding values.
3327 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08003328 * @return a list of supported antibanding values. null if antibanding
3329 * setting is not supported.
3330 * @see #getAntibanding()
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003331 */
3332 public List<String> getSupportedAntibanding() {
3333 String str = get(KEY_ANTIBANDING + SUPPORTED_VALUES_SUFFIX);
3334 return split(str);
3335 }
3336
3337 /**
3338 * Gets the current scene mode setting.
3339 *
3340 * @return one of SCENE_MODE_XXX string constant. null if scene mode
3341 * setting is not supported.
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08003342 * @see #SCENE_MODE_AUTO
3343 * @see #SCENE_MODE_ACTION
3344 * @see #SCENE_MODE_PORTRAIT
3345 * @see #SCENE_MODE_LANDSCAPE
3346 * @see #SCENE_MODE_NIGHT
3347 * @see #SCENE_MODE_NIGHT_PORTRAIT
3348 * @see #SCENE_MODE_THEATRE
3349 * @see #SCENE_MODE_BEACH
3350 * @see #SCENE_MODE_SNOW
3351 * @see #SCENE_MODE_SUNSET
3352 * @see #SCENE_MODE_STEADYPHOTO
3353 * @see #SCENE_MODE_FIREWORKS
3354 * @see #SCENE_MODE_SPORTS
3355 * @see #SCENE_MODE_PARTY
3356 * @see #SCENE_MODE_CANDLELIGHT
Eino-Ville Talvalada2f0ea2012-09-10 12:03:35 -07003357 * @see #SCENE_MODE_BARCODE
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003358 */
3359 public String getSceneMode() {
3360 return get(KEY_SCENE_MODE);
3361 }
3362
3363 /**
Wu-cheng Lic58b4232010-03-29 17:21:28 +08003364 * Sets the scene mode. Changing scene mode may override other
3365 * parameters (such as flash mode, focus mode, white balance). For
3366 * example, suppose originally flash mode is on and supported flash
3367 * modes are on/off. In night scene mode, both flash mode and supported
3368 * flash mode may be changed to off. After setting scene mode,
Wu-cheng Li2988ab72009-09-30 17:08:19 -07003369 * applications should call getParameters to know if some parameters are
3370 * changed.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003371 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08003372 * @param value scene mode.
3373 * @see #getSceneMode()
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003374 */
3375 public void setSceneMode(String value) {
3376 set(KEY_SCENE_MODE, value);
3377 }
3378
3379 /**
3380 * Gets the supported scene modes.
3381 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08003382 * @return a list of supported scene modes. null if scene mode setting
3383 * is not supported.
3384 * @see #getSceneMode()
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003385 */
3386 public List<String> getSupportedSceneModes() {
3387 String str = get(KEY_SCENE_MODE + SUPPORTED_VALUES_SUFFIX);
3388 return split(str);
3389 }
3390
3391 /**
3392 * Gets the current flash mode setting.
3393 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08003394 * @return current flash mode. null if flash mode setting is not
3395 * supported.
3396 * @see #FLASH_MODE_OFF
3397 * @see #FLASH_MODE_AUTO
3398 * @see #FLASH_MODE_ON
3399 * @see #FLASH_MODE_RED_EYE
3400 * @see #FLASH_MODE_TORCH
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003401 */
3402 public String getFlashMode() {
3403 return get(KEY_FLASH_MODE);
3404 }
3405
3406 /**
3407 * Sets the flash mode.
3408 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08003409 * @param value flash mode.
3410 * @see #getFlashMode()
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003411 */
3412 public void setFlashMode(String value) {
3413 set(KEY_FLASH_MODE, value);
3414 }
3415
3416 /**
3417 * Gets the supported flash modes.
3418 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08003419 * @return a list of supported flash modes. null if flash mode setting
3420 * is not supported.
3421 * @see #getFlashMode()
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003422 */
3423 public List<String> getSupportedFlashModes() {
3424 String str = get(KEY_FLASH_MODE + SUPPORTED_VALUES_SUFFIX);
3425 return split(str);
3426 }
3427
Wu-cheng Li36322db2009-09-18 18:59:21 +08003428 /**
3429 * Gets the current focus mode setting.
3430 *
Wu-cheng Li699fe932010-08-05 11:50:25 -07003431 * @return current focus mode. This method will always return a non-null
3432 * value. Applications should call {@link
3433 * #autoFocus(AutoFocusCallback)} to start the focus if focus
3434 * mode is FOCUS_MODE_AUTO or FOCUS_MODE_MACRO.
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08003435 * @see #FOCUS_MODE_AUTO
3436 * @see #FOCUS_MODE_INFINITY
3437 * @see #FOCUS_MODE_MACRO
3438 * @see #FOCUS_MODE_FIXED
Wu-cheng Lif008f3e2010-08-17 13:44:35 -07003439 * @see #FOCUS_MODE_EDOF
Wu-cheng Lid45cb722010-09-20 16:15:32 -07003440 * @see #FOCUS_MODE_CONTINUOUS_VIDEO
Wu-cheng Li36322db2009-09-18 18:59:21 +08003441 */
3442 public String getFocusMode() {
3443 return get(KEY_FOCUS_MODE);
3444 }
3445
3446 /**
3447 * Sets the focus mode.
3448 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08003449 * @param value focus mode.
3450 * @see #getFocusMode()
Wu-cheng Li36322db2009-09-18 18:59:21 +08003451 */
3452 public void setFocusMode(String value) {
3453 set(KEY_FOCUS_MODE, value);
3454 }
3455
3456 /**
3457 * Gets the supported focus modes.
3458 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08003459 * @return a list of supported focus modes. This method will always
3460 * return a list with at least one element.
3461 * @see #getFocusMode()
Wu-cheng Li36322db2009-09-18 18:59:21 +08003462 */
3463 public List<String> getSupportedFocusModes() {
3464 String str = get(KEY_FOCUS_MODE + SUPPORTED_VALUES_SUFFIX);
3465 return split(str);
3466 }
3467
Wu-cheng Li36f68b82009-09-28 16:14:58 -07003468 /**
Wu-cheng Li6c8d2762010-01-27 22:55:14 +08003469 * Gets the focal length (in millimeter) of the camera.
3470 *
3471 * @return the focal length. This method will always return a valid
3472 * value.
3473 */
3474 public float getFocalLength() {
3475 return Float.parseFloat(get(KEY_FOCAL_LENGTH));
3476 }
3477
3478 /**
3479 * Gets the horizontal angle of view in degrees.
3480 *
3481 * @return horizontal angle of view. This method will always return a
3482 * valid value.
3483 */
3484 public float getHorizontalViewAngle() {
3485 return Float.parseFloat(get(KEY_HORIZONTAL_VIEW_ANGLE));
3486 }
3487
3488 /**
3489 * Gets the vertical angle of view in degrees.
3490 *
3491 * @return vertical angle of view. This method will always return a
3492 * valid value.
3493 */
3494 public float getVerticalViewAngle() {
3495 return Float.parseFloat(get(KEY_VERTICAL_VIEW_ANGLE));
3496 }
3497
3498 /**
Wu-cheng Li24b326a2010-02-20 17:47:04 +08003499 * Gets the current exposure compensation index.
Wu-cheng Liff723b62010-02-09 13:38:19 +08003500 *
Wu-cheng Li24b326a2010-02-20 17:47:04 +08003501 * @return current exposure compensation index. The range is {@link
3502 * #getMinExposureCompensation} to {@link
3503 * #getMaxExposureCompensation}. 0 means exposure is not
3504 * adjusted.
Wu-cheng Liff723b62010-02-09 13:38:19 +08003505 */
3506 public int getExposureCompensation() {
Wu-cheng Li24b326a2010-02-20 17:47:04 +08003507 return getInt(KEY_EXPOSURE_COMPENSATION, 0);
Wu-cheng Liff723b62010-02-09 13:38:19 +08003508 }
3509
3510 /**
Wu-cheng Li24b326a2010-02-20 17:47:04 +08003511 * Sets the exposure compensation index.
Wu-cheng Liff723b62010-02-09 13:38:19 +08003512 *
Wu-cheng Li0402e7d2010-02-26 15:04:55 +08003513 * @param value exposure compensation index. The valid value range is
3514 * from {@link #getMinExposureCompensation} (inclusive) to {@link
Wu-cheng Li24b326a2010-02-20 17:47:04 +08003515 * #getMaxExposureCompensation} (inclusive). 0 means exposure is
3516 * not adjusted. Application should call
3517 * getMinExposureCompensation and getMaxExposureCompensation to
3518 * know if exposure compensation is supported.
Wu-cheng Liff723b62010-02-09 13:38:19 +08003519 */
3520 public void setExposureCompensation(int value) {
3521 set(KEY_EXPOSURE_COMPENSATION, value);
3522 }
3523
3524 /**
Wu-cheng Li24b326a2010-02-20 17:47:04 +08003525 * Gets the maximum exposure compensation index.
Wu-cheng Liff723b62010-02-09 13:38:19 +08003526 *
Wu-cheng Li24b326a2010-02-20 17:47:04 +08003527 * @return maximum exposure compensation index (>=0). If both this
3528 * method and {@link #getMinExposureCompensation} return 0,
3529 * exposure compensation is not supported.
Wu-cheng Liff723b62010-02-09 13:38:19 +08003530 */
Wu-cheng Li24b326a2010-02-20 17:47:04 +08003531 public int getMaxExposureCompensation() {
3532 return getInt(KEY_MAX_EXPOSURE_COMPENSATION, 0);
3533 }
3534
3535 /**
3536 * Gets the minimum exposure compensation index.
3537 *
3538 * @return minimum exposure compensation index (<=0). If both this
3539 * method and {@link #getMaxExposureCompensation} return 0,
3540 * exposure compensation is not supported.
3541 */
3542 public int getMinExposureCompensation() {
3543 return getInt(KEY_MIN_EXPOSURE_COMPENSATION, 0);
3544 }
3545
3546 /**
3547 * Gets the exposure compensation step.
3548 *
3549 * @return exposure compensation step. Applications can get EV by
3550 * multiplying the exposure compensation index and step. Ex: if
3551 * exposure compensation index is -6 and step is 0.333333333, EV
3552 * is -2.
3553 */
3554 public float getExposureCompensationStep() {
3555 return getFloat(KEY_EXPOSURE_COMPENSATION_STEP, 0);
Wu-cheng Liff723b62010-02-09 13:38:19 +08003556 }
3557
3558 /**
Eino-Ville Talvalad9c2601a2011-05-13 10:19:59 -07003559 * <p>Sets the auto-exposure lock state. Applications should check
3560 * {@link #isAutoExposureLockSupported} before using this method.</p>
Eino-Ville Talvala3773eef2011-04-15 13:51:42 -07003561 *
Eino-Ville Talvalad9c2601a2011-05-13 10:19:59 -07003562 * <p>If set to true, the camera auto-exposure routine will immediately
3563 * pause until the lock is set to false. Exposure compensation settings
3564 * changes will still take effect while auto-exposure is locked.</p>
3565 *
3566 * <p>If auto-exposure is already locked, setting this to true again has
3567 * no effect (the driver will not recalculate exposure values).</p>
3568 *
3569 * <p>Stopping preview with {@link #stopPreview()}, or triggering still
3570 * image capture with {@link #takePicture(Camera.ShutterCallback,
Wu-cheng Lib4f95be2011-09-22 11:43:28 +08003571 * Camera.PictureCallback, Camera.PictureCallback)}, will not change the
3572 * lock.</p>
Eino-Ville Talvalad9c2601a2011-05-13 10:19:59 -07003573 *
Wu-cheng Lib4f95be2011-09-22 11:43:28 +08003574 * <p>Exposure compensation, auto-exposure lock, and auto-white balance
3575 * lock can be used to capture an exposure-bracketed burst of images,
3576 * for example.</p>
Eino-Ville Talvalad9c2601a2011-05-13 10:19:59 -07003577 *
3578 * <p>Auto-exposure state, including the lock state, will not be
Eino-Ville Talvala3773eef2011-04-15 13:51:42 -07003579 * maintained after camera {@link #release()} is called. Locking
3580 * auto-exposure after {@link #open()} but before the first call to
3581 * {@link #startPreview()} will not allow the auto-exposure routine to
Eino-Ville Talvalad9c2601a2011-05-13 10:19:59 -07003582 * run at all, and may result in severely over- or under-exposed
3583 * images.</p>
Eino-Ville Talvala3773eef2011-04-15 13:51:42 -07003584 *
Eino-Ville Talvala3773eef2011-04-15 13:51:42 -07003585 * @param toggle new state of the auto-exposure lock. True means that
3586 * auto-exposure is locked, false means that the auto-exposure
3587 * routine is free to run normally.
3588 *
Eino-Ville Talvalad9c2601a2011-05-13 10:19:59 -07003589 * @see #getAutoExposureLock()
Eino-Ville Talvala3773eef2011-04-15 13:51:42 -07003590 */
3591 public void setAutoExposureLock(boolean toggle) {
3592 set(KEY_AUTO_EXPOSURE_LOCK, toggle ? TRUE : FALSE);
3593 }
3594
3595 /**
3596 * Gets the state of the auto-exposure lock. Applications should check
3597 * {@link #isAutoExposureLockSupported} before using this method. See
3598 * {@link #setAutoExposureLock} for details about the lock.
3599 *
3600 * @return State of the auto-exposure lock. Returns true if
Wu-cheng Lib4f95be2011-09-22 11:43:28 +08003601 * auto-exposure is currently locked, and false otherwise.
Eino-Ville Talvala3773eef2011-04-15 13:51:42 -07003602 *
3603 * @see #setAutoExposureLock(boolean)
3604 *
Eino-Ville Talvala3773eef2011-04-15 13:51:42 -07003605 */
3606 public boolean getAutoExposureLock() {
3607 String str = get(KEY_AUTO_EXPOSURE_LOCK);
3608 return TRUE.equals(str);
3609 }
3610
3611 /**
3612 * Returns true if auto-exposure locking is supported. Applications
3613 * should call this before trying to lock auto-exposure. See
3614 * {@link #setAutoExposureLock} for details about the lock.
3615 *
3616 * @return true if auto-exposure lock is supported.
3617 * @see #setAutoExposureLock(boolean)
3618 *
Eino-Ville Talvala3773eef2011-04-15 13:51:42 -07003619 */
3620 public boolean isAutoExposureLockSupported() {
3621 String str = get(KEY_AUTO_EXPOSURE_LOCK_SUPPORTED);
3622 return TRUE.equals(str);
3623 }
3624
3625 /**
Eino-Ville Talvalad9c2601a2011-05-13 10:19:59 -07003626 * <p>Sets the auto-white balance lock state. Applications should check
3627 * {@link #isAutoWhiteBalanceLockSupported} before using this
3628 * method.</p>
3629 *
3630 * <p>If set to true, the camera auto-white balance routine will
3631 * immediately pause until the lock is set to false.</p>
3632 *
3633 * <p>If auto-white balance is already locked, setting this to true
3634 * again has no effect (the driver will not recalculate white balance
3635 * values).</p>
3636 *
3637 * <p>Stopping preview with {@link #stopPreview()}, or triggering still
3638 * image capture with {@link #takePicture(Camera.ShutterCallback,
Wu-cheng Lib4f95be2011-09-22 11:43:28 +08003639 * Camera.PictureCallback, Camera.PictureCallback)}, will not change the
3640 * the lock.</p>
Eino-Ville Talvalad9c2601a2011-05-13 10:19:59 -07003641 *
Eino-Ville Talvala16b67132011-08-18 13:57:49 -07003642 * <p> Changing the white balance mode with {@link #setWhiteBalance}
3643 * will release the auto-white balance lock if it is set.</p>
3644 *
Wu-cheng Lib4f95be2011-09-22 11:43:28 +08003645 * <p>Exposure compensation, AE lock, and AWB lock can be used to
3646 * capture an exposure-bracketed burst of images, for example.
3647 * Auto-white balance state, including the lock state, will not be
3648 * maintained after camera {@link #release()} is called. Locking
3649 * auto-white balance after {@link #open()} but before the first call to
3650 * {@link #startPreview()} will not allow the auto-white balance routine
3651 * to run at all, and may result in severely incorrect color in captured
3652 * images.</p>
Eino-Ville Talvalad9c2601a2011-05-13 10:19:59 -07003653 *
3654 * @param toggle new state of the auto-white balance lock. True means
3655 * that auto-white balance is locked, false means that the
3656 * auto-white balance routine is free to run normally.
3657 *
3658 * @see #getAutoWhiteBalanceLock()
Eino-Ville Talvala16b67132011-08-18 13:57:49 -07003659 * @see #setWhiteBalance(String)
Eino-Ville Talvalad9c2601a2011-05-13 10:19:59 -07003660 */
3661 public void setAutoWhiteBalanceLock(boolean toggle) {
3662 set(KEY_AUTO_WHITEBALANCE_LOCK, toggle ? TRUE : FALSE);
3663 }
3664
3665 /**
3666 * Gets the state of the auto-white balance lock. Applications should
3667 * check {@link #isAutoWhiteBalanceLockSupported} before using this
3668 * method. See {@link #setAutoWhiteBalanceLock} for details about the
3669 * lock.
3670 *
3671 * @return State of the auto-white balance lock. Returns true if
3672 * auto-white balance is currently locked, and false
Wu-cheng Lib4f95be2011-09-22 11:43:28 +08003673 * otherwise.
Eino-Ville Talvalad9c2601a2011-05-13 10:19:59 -07003674 *
3675 * @see #setAutoWhiteBalanceLock(boolean)
3676 *
Eino-Ville Talvalad9c2601a2011-05-13 10:19:59 -07003677 */
3678 public boolean getAutoWhiteBalanceLock() {
3679 String str = get(KEY_AUTO_WHITEBALANCE_LOCK);
3680 return TRUE.equals(str);
3681 }
3682
3683 /**
3684 * Returns true if auto-white balance locking is supported. Applications
3685 * should call this before trying to lock auto-white balance. See
3686 * {@link #setAutoWhiteBalanceLock} for details about the lock.
3687 *
3688 * @return true if auto-white balance lock is supported.
3689 * @see #setAutoWhiteBalanceLock(boolean)
3690 *
Eino-Ville Talvalad9c2601a2011-05-13 10:19:59 -07003691 */
3692 public boolean isAutoWhiteBalanceLockSupported() {
3693 String str = get(KEY_AUTO_WHITEBALANCE_LOCK_SUPPORTED);
3694 return TRUE.equals(str);
3695 }
3696
3697 /**
Wu-cheng Li36f68b82009-09-28 16:14:58 -07003698 * Gets current zoom value. This also works when smooth zoom is in
Wu-cheng Li8cbb8f52010-02-28 23:19:55 -08003699 * progress. Applications should check {@link #isZoomSupported} before
3700 * using this method.
Wu-cheng Li36f68b82009-09-28 16:14:58 -07003701 *
3702 * @return the current zoom value. The range is 0 to {@link
Wu-cheng Li8cbb8f52010-02-28 23:19:55 -08003703 * #getMaxZoom}. 0 means the camera is not zoomed.
Wu-cheng Li36f68b82009-09-28 16:14:58 -07003704 */
3705 public int getZoom() {
Wu-cheng Li8cbb8f52010-02-28 23:19:55 -08003706 return getInt(KEY_ZOOM, 0);
Wu-cheng Li36f68b82009-09-28 16:14:58 -07003707 }
3708
3709 /**
Wu-cheng Li8cbb8f52010-02-28 23:19:55 -08003710 * Sets current zoom value. If the camera is zoomed (value > 0), the
3711 * actual picture size may be smaller than picture size setting.
3712 * Applications can check the actual picture size after picture is
3713 * returned from {@link PictureCallback}. The preview size remains the
3714 * same in zoom. Applications should check {@link #isZoomSupported}
3715 * before using this method.
Wu-cheng Li36f68b82009-09-28 16:14:58 -07003716 *
3717 * @param value zoom value. The valid range is 0 to {@link #getMaxZoom}.
Wu-cheng Li36f68b82009-09-28 16:14:58 -07003718 */
3719 public void setZoom(int value) {
Wu-cheng Li8cbb8f52010-02-28 23:19:55 -08003720 set(KEY_ZOOM, value);
Wu-cheng Li36f68b82009-09-28 16:14:58 -07003721 }
3722
3723 /**
3724 * Returns true if zoom is supported. Applications should call this
3725 * before using other zoom methods.
3726 *
3727 * @return true if zoom is supported.
Wu-cheng Li36f68b82009-09-28 16:14:58 -07003728 */
3729 public boolean isZoomSupported() {
Wu-cheng Li8cbb8f52010-02-28 23:19:55 -08003730 String str = get(KEY_ZOOM_SUPPORTED);
3731 return TRUE.equals(str);
Wu-cheng Li36f68b82009-09-28 16:14:58 -07003732 }
3733
3734 /**
3735 * Gets the maximum zoom value allowed for snapshot. This is the maximum
3736 * value that applications can set to {@link #setZoom(int)}.
Wu-cheng Li8cbb8f52010-02-28 23:19:55 -08003737 * Applications should call {@link #isZoomSupported} before using this
3738 * method. This value may change in different preview size. Applications
3739 * should call this again after setting preview size.
Wu-cheng Li36f68b82009-09-28 16:14:58 -07003740 *
3741 * @return the maximum zoom value supported by the camera.
Wu-cheng Li36f68b82009-09-28 16:14:58 -07003742 */
3743 public int getMaxZoom() {
Wu-cheng Li8cbb8f52010-02-28 23:19:55 -08003744 return getInt(KEY_MAX_ZOOM, 0);
Wu-cheng Li36f68b82009-09-28 16:14:58 -07003745 }
3746
3747 /**
Wu-cheng Li8cbb8f52010-02-28 23:19:55 -08003748 * Gets the zoom ratios of all zoom values. Applications should check
3749 * {@link #isZoomSupported} before using this method.
Wu-cheng Li36f68b82009-09-28 16:14:58 -07003750 *
Wu-cheng Li8cbb8f52010-02-28 23:19:55 -08003751 * @return the zoom ratios in 1/100 increments. Ex: a zoom of 3.2x is
3752 * returned as 320. The number of elements is {@link
3753 * #getMaxZoom} + 1. The list is sorted from small to large. The
3754 * first element is always 100. The last element is the zoom
3755 * ratio of the maximum zoom value.
Wu-cheng Li36f68b82009-09-28 16:14:58 -07003756 */
Wu-cheng Li8cbb8f52010-02-28 23:19:55 -08003757 public List<Integer> getZoomRatios() {
3758 return splitInt(get(KEY_ZOOM_RATIOS));
Wu-cheng Li36f68b82009-09-28 16:14:58 -07003759 }
3760
3761 /**
3762 * Returns true if smooth zoom is supported. Applications should call
3763 * this before using other smooth zoom methods.
3764 *
3765 * @return true if smooth zoom is supported.
Wu-cheng Li36f68b82009-09-28 16:14:58 -07003766 */
3767 public boolean isSmoothZoomSupported() {
Wu-cheng Li8cbb8f52010-02-28 23:19:55 -08003768 String str = get(KEY_SMOOTH_ZOOM_SUPPORTED);
3769 return TRUE.equals(str);
Wu-cheng Li36f68b82009-09-28 16:14:58 -07003770 }
3771
Wu-cheng Lie339c5e2010-05-13 19:31:02 +08003772 /**
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07003773 * <p>Gets the distances from the camera to where an object appears to be
Wu-cheng Lie339c5e2010-05-13 19:31:02 +08003774 * in focus. The object is sharpest at the optimal focus distance. The
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07003775 * depth of field is the far focus distance minus near focus distance.</p>
Wu-cheng Lie339c5e2010-05-13 19:31:02 +08003776 *
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07003777 * <p>Focus distances may change after calling {@link
Wu-cheng Lie339c5e2010-05-13 19:31:02 +08003778 * #autoFocus(AutoFocusCallback)}, {@link #cancelAutoFocus}, or {@link
3779 * #startPreview()}. Applications can call {@link #getParameters()}
3780 * and this method anytime to get the latest focus distances. If the
Wu-cheng Lid45cb722010-09-20 16:15:32 -07003781 * focus mode is FOCUS_MODE_CONTINUOUS_VIDEO, focus distances may change
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07003782 * from time to time.</p>
Wu-cheng Li699fe932010-08-05 11:50:25 -07003783 *
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07003784 * <p>This method is intended to estimate the distance between the camera
Wu-cheng Li699fe932010-08-05 11:50:25 -07003785 * and the subject. After autofocus, the subject distance may be within
3786 * near and far focus distance. However, the precision depends on the
3787 * camera hardware, autofocus algorithm, the focus area, and the scene.
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07003788 * The error can be large and it should be only used as a reference.</p>
Wu-cheng Lie339c5e2010-05-13 19:31:02 +08003789 *
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07003790 * <p>Far focus distance >= optimal focus distance >= near focus distance.
Wu-cheng Li185cc452010-05-20 15:36:13 +08003791 * If the focus distance is infinity, the value will be
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07003792 * {@code Float.POSITIVE_INFINITY}.</p>
Wu-cheng Lie339c5e2010-05-13 19:31:02 +08003793 *
3794 * @param output focus distances in meters. output must be a float
3795 * array with three elements. Near focus distance, optimal focus
3796 * distance, and far focus distance will be filled in the array.
Wu-cheng Li185cc452010-05-20 15:36:13 +08003797 * @see #FOCUS_DISTANCE_NEAR_INDEX
3798 * @see #FOCUS_DISTANCE_OPTIMAL_INDEX
3799 * @see #FOCUS_DISTANCE_FAR_INDEX
Wu-cheng Lie339c5e2010-05-13 19:31:02 +08003800 */
3801 public void getFocusDistances(float[] output) {
3802 if (output == null || output.length != 3) {
3803 throw new IllegalArgumentException(
Ken Wakasaf76a50c2012-03-09 19:56:35 +09003804 "output must be a float array with three elements.");
Wu-cheng Lie339c5e2010-05-13 19:31:02 +08003805 }
Wu-cheng Li454630f2010-08-11 16:48:05 -07003806 splitFloat(get(KEY_FOCUS_DISTANCES), output);
Wu-cheng Lie339c5e2010-05-13 19:31:02 +08003807 }
3808
Wu-cheng Li30771b72011-04-02 06:19:46 +08003809 /**
3810 * Gets the maximum number of focus areas supported. This is the maximum
Wu-cheng Li7b1c5c82011-04-15 19:16:52 +08003811 * length of the list in {@link #setFocusAreas(List)} and
3812 * {@link #getFocusAreas()}.
Wu-cheng Li30771b72011-04-02 06:19:46 +08003813 *
3814 * @return the maximum number of focus areas supported by the camera.
3815 * @see #getFocusAreas()
Wu-cheng Li30771b72011-04-02 06:19:46 +08003816 */
3817 public int getMaxNumFocusAreas() {
3818 return getInt(KEY_MAX_NUM_FOCUS_AREAS, 0);
3819 }
3820
3821 /**
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07003822 * <p>Gets the current focus areas. Camera driver uses the areas to decide
3823 * focus.</p>
Wu-cheng Li30771b72011-04-02 06:19:46 +08003824 *
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07003825 * <p>Before using this API or {@link #setFocusAreas(List)}, apps should
Wu-cheng Li7b1c5c82011-04-15 19:16:52 +08003826 * call {@link #getMaxNumFocusAreas()} to know the maximum number of
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07003827 * focus areas first. If the value is 0, focus area is not supported.</p>
Wu-cheng Li30771b72011-04-02 06:19:46 +08003828 *
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07003829 * <p>Each focus area is a rectangle with specified weight. The direction
Wu-cheng Li30771b72011-04-02 06:19:46 +08003830 * is relative to the sensor orientation, that is, what the sensor sees.
3831 * The direction is not affected by the rotation or mirroring of
3832 * {@link #setDisplayOrientation(int)}. Coordinates of the rectangle
3833 * range from -1000 to 1000. (-1000, -1000) is the upper left point.
Wu-cheng Libde61a52011-06-07 18:23:14 +08003834 * (1000, 1000) is the lower right point. The width and height of focus
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07003835 * areas cannot be 0 or negative.</p>
Wu-cheng Li30771b72011-04-02 06:19:46 +08003836 *
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07003837 * <p>The weight must range from 1 to 1000. The weight should be
Eino-Ville Talvala4e396e02011-04-21 09:23:15 -07003838 * interpreted as a per-pixel weight - all pixels in the area have the
3839 * specified weight. This means a small area with the same weight as a
3840 * larger area will have less influence on the focusing than the larger
3841 * area. Focus areas can partially overlap and the driver will add the
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07003842 * weights in the overlap region.</p>
Wu-cheng Li30771b72011-04-02 06:19:46 +08003843 *
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07003844 * <p>A special case of a {@code null} focus area list means the driver is
3845 * free to select focus targets as it wants. For example, the driver may
3846 * use more signals to select focus areas and change them
3847 * dynamically. Apps can set the focus area list to {@code null} if they
3848 * want the driver to completely control focusing.</p>
Wu-cheng Li30771b72011-04-02 06:19:46 +08003849 *
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07003850 * <p>Focus areas are relative to the current field of view
Wu-cheng Li30771b72011-04-02 06:19:46 +08003851 * ({@link #getZoom()}). No matter what the zoom level is, (-1000,-1000)
3852 * represents the top of the currently visible camera frame. The focus
3853 * area cannot be set to be outside the current field of view, even
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07003854 * when using zoom.</p>
Wu-cheng Li30771b72011-04-02 06:19:46 +08003855 *
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07003856 * <p>Focus area only has effect if the current focus mode is
Wu-cheng Li53b30912011-10-12 19:43:51 +08003857 * {@link #FOCUS_MODE_AUTO}, {@link #FOCUS_MODE_MACRO},
3858 * {@link #FOCUS_MODE_CONTINUOUS_VIDEO}, or
3859 * {@link #FOCUS_MODE_CONTINUOUS_PICTURE}.</p>
Wu-cheng Li30771b72011-04-02 06:19:46 +08003860 *
3861 * @return a list of current focus areas
Wu-cheng Li30771b72011-04-02 06:19:46 +08003862 */
3863 public List<Area> getFocusAreas() {
Wu-cheng Lif715bf92011-04-14 14:04:18 +08003864 return splitArea(get(KEY_FOCUS_AREAS));
Wu-cheng Li30771b72011-04-02 06:19:46 +08003865 }
3866
3867 /**
3868 * Sets focus areas. See {@link #getFocusAreas()} for documentation.
3869 *
Wu-cheng Li7b1c5c82011-04-15 19:16:52 +08003870 * @param focusAreas the focus areas
Wu-cheng Li30771b72011-04-02 06:19:46 +08003871 * @see #getFocusAreas()
Wu-cheng Li30771b72011-04-02 06:19:46 +08003872 */
Wu-cheng Lie98e4c82011-04-12 19:34:29 +08003873 public void setFocusAreas(List<Area> focusAreas) {
3874 set(KEY_FOCUS_AREAS, focusAreas);
3875 }
3876
3877 /**
3878 * Gets the maximum number of metering areas supported. This is the
Wu-cheng Li7b1c5c82011-04-15 19:16:52 +08003879 * maximum length of the list in {@link #setMeteringAreas(List)} and
3880 * {@link #getMeteringAreas()}.
Wu-cheng Lie98e4c82011-04-12 19:34:29 +08003881 *
3882 * @return the maximum number of metering areas supported by the camera.
3883 * @see #getMeteringAreas()
Wu-cheng Lie98e4c82011-04-12 19:34:29 +08003884 */
3885 public int getMaxNumMeteringAreas() {
3886 return getInt(KEY_MAX_NUM_METERING_AREAS, 0);
3887 }
3888
3889 /**
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07003890 * <p>Gets the current metering areas. Camera driver uses these areas to
3891 * decide exposure.</p>
Wu-cheng Lie98e4c82011-04-12 19:34:29 +08003892 *
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07003893 * <p>Before using this API or {@link #setMeteringAreas(List)}, apps should
Wu-cheng Li7b1c5c82011-04-15 19:16:52 +08003894 * call {@link #getMaxNumMeteringAreas()} to know the maximum number of
3895 * metering areas first. If the value is 0, metering area is not
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07003896 * supported.</p>
Wu-cheng Lie98e4c82011-04-12 19:34:29 +08003897 *
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07003898 * <p>Each metering area is a rectangle with specified weight. The
Wu-cheng Lie98e4c82011-04-12 19:34:29 +08003899 * direction is relative to the sensor orientation, that is, what the
3900 * sensor sees. The direction is not affected by the rotation or
3901 * mirroring of {@link #setDisplayOrientation(int)}. Coordinates of the
3902 * rectangle range from -1000 to 1000. (-1000, -1000) is the upper left
Wu-cheng Libde61a52011-06-07 18:23:14 +08003903 * point. (1000, 1000) is the lower right point. The width and height of
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07003904 * metering areas cannot be 0 or negative.</p>
Wu-cheng Lie98e4c82011-04-12 19:34:29 +08003905 *
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07003906 * <p>The weight must range from 1 to 1000, and represents a weight for
Eino-Ville Talvala4e396e02011-04-21 09:23:15 -07003907 * every pixel in the area. This means that a large metering area with
3908 * the same weight as a smaller area will have more effect in the
3909 * metering result. Metering areas can partially overlap and the driver
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07003910 * will add the weights in the overlap region.</p>
Wu-cheng Lie98e4c82011-04-12 19:34:29 +08003911 *
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07003912 * <p>A special case of a {@code null} metering area list means the driver
3913 * is free to meter as it chooses. For example, the driver may use more
3914 * signals to select metering areas and change them dynamically. Apps
3915 * can set the metering area list to {@code null} if they want the
3916 * driver to completely control metering.</p>
Wu-cheng Lie98e4c82011-04-12 19:34:29 +08003917 *
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07003918 * <p>Metering areas are relative to the current field of view
Wu-cheng Lie98e4c82011-04-12 19:34:29 +08003919 * ({@link #getZoom()}). No matter what the zoom level is, (-1000,-1000)
3920 * represents the top of the currently visible camera frame. The
3921 * metering area cannot be set to be outside the current field of view,
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07003922 * even when using zoom.</p>
Wu-cheng Lie98e4c82011-04-12 19:34:29 +08003923 *
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07003924 * <p>No matter what metering areas are, the final exposure are compensated
3925 * by {@link #setExposureCompensation(int)}.</p>
Wu-cheng Lie98e4c82011-04-12 19:34:29 +08003926 *
3927 * @return a list of current metering areas
Wu-cheng Lie98e4c82011-04-12 19:34:29 +08003928 */
3929 public List<Area> getMeteringAreas() {
Wu-cheng Lid8aab932011-06-21 11:50:43 +08003930 return splitArea(get(KEY_METERING_AREAS));
Wu-cheng Lie98e4c82011-04-12 19:34:29 +08003931 }
3932
3933 /**
3934 * Sets metering areas. See {@link #getMeteringAreas()} for
3935 * documentation.
3936 *
Wu-cheng Li7b1c5c82011-04-15 19:16:52 +08003937 * @param meteringAreas the metering areas
Wu-cheng Lie98e4c82011-04-12 19:34:29 +08003938 * @see #getMeteringAreas()
Wu-cheng Lie98e4c82011-04-12 19:34:29 +08003939 */
3940 public void setMeteringAreas(List<Area> meteringAreas) {
3941 set(KEY_METERING_AREAS, meteringAreas);
Wu-cheng Li30771b72011-04-02 06:19:46 +08003942 }
3943
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08003944 /**
3945 * Gets the maximum number of detected faces supported. This is the
3946 * maximum length of the list returned from {@link FaceDetectionListener}.
3947 * If the return value is 0, face detection of the specified type is not
3948 * supported.
3949 *
3950 * @return the maximum number of detected face supported by the camera.
Joe Fernandez464cb212011-10-04 16:56:47 -07003951 * @see #startFaceDetection()
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08003952 */
Wu-cheng Lic0c683b2011-08-04 00:11:00 +08003953 public int getMaxNumDetectedFaces() {
3954 return getInt(KEY_MAX_NUM_DETECTED_FACES_HW, 0);
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08003955 }
3956
Wu-cheng Li25d8fb52011-08-02 13:20:36 +08003957 /**
Wu-cheng Li9c53f1c2011-08-02 17:26:58 +08003958 * Sets recording mode hint. This tells the camera that the intent of
3959 * the application is to record videos {@link
3960 * android.media.MediaRecorder#start()}, not to take still pictures
3961 * {@link #takePicture(Camera.ShutterCallback, Camera.PictureCallback,
3962 * Camera.PictureCallback, Camera.PictureCallback)}. Using this hint can
3963 * allow MediaRecorder.start() to start faster or with fewer glitches on
3964 * output. This should be called before starting preview for the best
3965 * result, but can be changed while the preview is active. The default
3966 * value is false.
Wu-cheng Li25d8fb52011-08-02 13:20:36 +08003967 *
Wu-cheng Li9c53f1c2011-08-02 17:26:58 +08003968 * The app can still call takePicture() when the hint is true or call
3969 * MediaRecorder.start() when the hint is false. But the performance may
3970 * be worse.
Wu-cheng Li25d8fb52011-08-02 13:20:36 +08003971 *
Wu-cheng Li9c53f1c2011-08-02 17:26:58 +08003972 * @param hint true if the apps intend to record videos using
Wu-cheng Li25d8fb52011-08-02 13:20:36 +08003973 * {@link android.media.MediaRecorder}.
Wu-cheng Li25d8fb52011-08-02 13:20:36 +08003974 */
3975 public void setRecordingHint(boolean hint) {
3976 set(KEY_RECORDING_HINT, hint ? TRUE : FALSE);
3977 }
3978
Wu-cheng Li98bb2512011-08-30 21:33:10 +08003979 /**
Eino-Ville Talvala1cab31a2012-11-05 10:33:55 -08003980 * <p>Returns true if video snapshot is supported. That is, applications
Wu-cheng Li98bb2512011-08-30 21:33:10 +08003981 * can call {@link #takePicture(Camera.ShutterCallback,
Eino-Ville Talvala1cab31a2012-11-05 10:33:55 -08003982 * Camera.PictureCallback, Camera.PictureCallback,
3983 * Camera.PictureCallback)} during recording. Applications do not need
3984 * to call {@link #startPreview()} after taking a picture. The preview
3985 * will be still active. Other than that, taking a picture during
3986 * recording is identical to taking a picture normally. All settings and
3987 * methods related to takePicture work identically. Ex:
3988 * {@link #getPictureSize()}, {@link #getSupportedPictureSizes()},
3989 * {@link #setJpegQuality(int)}, {@link #setRotation(int)}, and etc. The
3990 * picture will have an EXIF header. {@link #FLASH_MODE_AUTO} and
3991 * {@link #FLASH_MODE_ON} also still work, but the video will record the
3992 * flash.</p>
Wu-cheng Li98bb2512011-08-30 21:33:10 +08003993 *
Eino-Ville Talvala1cab31a2012-11-05 10:33:55 -08003994 * <p>Applications can set shutter callback as null to avoid the shutter
Wu-cheng Li98bb2512011-08-30 21:33:10 +08003995 * sound. It is also recommended to set raw picture and post view
Eino-Ville Talvala1cab31a2012-11-05 10:33:55 -08003996 * callbacks to null to avoid the interrupt of preview display.</p>
Wu-cheng Li98bb2512011-08-30 21:33:10 +08003997 *
Eino-Ville Talvala1cab31a2012-11-05 10:33:55 -08003998 * <p>Field-of-view of the recorded video may be different from that of the
3999 * captured pictures. The maximum size of a video snapshot may be
4000 * smaller than that for regular still captures. If the current picture
4001 * size is set higher than can be supported by video snapshot, the
4002 * picture will be captured at the maximum supported size instead.</p>
Wu-cheng Li98bb2512011-08-30 21:33:10 +08004003 *
4004 * @return true if video snapshot is supported.
Wu-cheng Li98bb2512011-08-30 21:33:10 +08004005 */
4006 public boolean isVideoSnapshotSupported() {
4007 String str = get(KEY_VIDEO_SNAPSHOT_SUPPORTED);
4008 return TRUE.equals(str);
4009 }
4010
Eino-Ville Talvala037abb82011-10-11 12:41:58 -07004011 /**
4012 * <p>Enables and disables video stabilization. Use
4013 * {@link #isVideoStabilizationSupported} to determine if calling this
4014 * method is valid.</p>
4015 *
4016 * <p>Video stabilization reduces the shaking due to the motion of the
4017 * camera in both the preview stream and in recorded videos, including
4018 * data received from the preview callback. It does not reduce motion
4019 * blur in images captured with
4020 * {@link Camera#takePicture takePicture}.</p>
4021 *
4022 * <p>Video stabilization can be enabled and disabled while preview or
4023 * recording is active, but toggling it may cause a jump in the video
4024 * stream that may be undesirable in a recorded video.</p>
4025 *
4026 * @param toggle Set to true to enable video stabilization, and false to
4027 * disable video stabilization.
4028 * @see #isVideoStabilizationSupported()
4029 * @see #getVideoStabilization()
Eino-Ville Talvala037abb82011-10-11 12:41:58 -07004030 */
4031 public void setVideoStabilization(boolean toggle) {
4032 set(KEY_VIDEO_STABILIZATION, toggle ? TRUE : FALSE);
4033 }
4034
4035 /**
4036 * Get the current state of video stabilization. See
4037 * {@link #setVideoStabilization} for details of video stabilization.
4038 *
4039 * @return true if video stabilization is enabled
4040 * @see #isVideoStabilizationSupported()
4041 * @see #setVideoStabilization(boolean)
Eino-Ville Talvala037abb82011-10-11 12:41:58 -07004042 */
4043 public boolean getVideoStabilization() {
4044 String str = get(KEY_VIDEO_STABILIZATION);
4045 return TRUE.equals(str);
4046 }
4047
4048 /**
4049 * Returns true if video stabilization is supported. See
4050 * {@link #setVideoStabilization} for details of video stabilization.
4051 *
4052 * @return true if video stabilization is supported
4053 * @see #setVideoStabilization(boolean)
4054 * @see #getVideoStabilization()
Eino-Ville Talvala037abb82011-10-11 12:41:58 -07004055 */
4056 public boolean isVideoStabilizationSupported() {
4057 String str = get(KEY_VIDEO_STABILIZATION_SUPPORTED);
4058 return TRUE.equals(str);
4059 }
4060
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08004061 // Splits a comma delimited string to an ArrayList of String.
4062 // Return null if the passing string is null or the size is 0.
4063 private ArrayList<String> split(String str) {
4064 if (str == null) return null;
4065
Ali Utku Selen0a120182011-02-09 14:11:22 +01004066 TextUtils.StringSplitter splitter = new TextUtils.SimpleStringSplitter(',');
4067 splitter.setString(str);
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08004068 ArrayList<String> substrings = new ArrayList<String>();
Ali Utku Selen0a120182011-02-09 14:11:22 +01004069 for (String s : splitter) {
4070 substrings.add(s);
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08004071 }
4072 return substrings;
4073 }
4074
4075 // Splits a comma delimited string to an ArrayList of Integer.
4076 // Return null if the passing string is null or the size is 0.
4077 private ArrayList<Integer> splitInt(String str) {
4078 if (str == null) return null;
4079
Ali Utku Selen0a120182011-02-09 14:11:22 +01004080 TextUtils.StringSplitter splitter = new TextUtils.SimpleStringSplitter(',');
4081 splitter.setString(str);
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08004082 ArrayList<Integer> substrings = new ArrayList<Integer>();
Ali Utku Selen0a120182011-02-09 14:11:22 +01004083 for (String s : splitter) {
4084 substrings.add(Integer.parseInt(s));
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08004085 }
4086 if (substrings.size() == 0) return null;
4087 return substrings;
4088 }
4089
Wu-cheng Li454630f2010-08-11 16:48:05 -07004090 private void splitInt(String str, int[] output) {
4091 if (str == null) return;
Wu-cheng Lie339c5e2010-05-13 19:31:02 +08004092
Ali Utku Selen0a120182011-02-09 14:11:22 +01004093 TextUtils.StringSplitter splitter = new TextUtils.SimpleStringSplitter(',');
4094 splitter.setString(str);
Wu-cheng Li454630f2010-08-11 16:48:05 -07004095 int index = 0;
Ali Utku Selen0a120182011-02-09 14:11:22 +01004096 for (String s : splitter) {
4097 output[index++] = Integer.parseInt(s);
Wu-cheng Lie339c5e2010-05-13 19:31:02 +08004098 }
Wu-cheng Li454630f2010-08-11 16:48:05 -07004099 }
4100
4101 // Splits a comma delimited string to an ArrayList of Float.
4102 private void splitFloat(String str, float[] output) {
4103 if (str == null) return;
4104
Ali Utku Selen0a120182011-02-09 14:11:22 +01004105 TextUtils.StringSplitter splitter = new TextUtils.SimpleStringSplitter(',');
4106 splitter.setString(str);
Wu-cheng Li454630f2010-08-11 16:48:05 -07004107 int index = 0;
Ali Utku Selen0a120182011-02-09 14:11:22 +01004108 for (String s : splitter) {
4109 output[index++] = Float.parseFloat(s);
Wu-cheng Li454630f2010-08-11 16:48:05 -07004110 }
Wu-cheng Lie339c5e2010-05-13 19:31:02 +08004111 }
4112
Wu-cheng Li24b326a2010-02-20 17:47:04 +08004113 // Returns the value of a float parameter.
4114 private float getFloat(String key, float defaultValue) {
4115 try {
4116 return Float.parseFloat(mMap.get(key));
4117 } catch (NumberFormatException ex) {
4118 return defaultValue;
4119 }
4120 }
4121
4122 // Returns the value of a integer parameter.
4123 private int getInt(String key, int defaultValue) {
4124 try {
4125 return Integer.parseInt(mMap.get(key));
4126 } catch (NumberFormatException ex) {
4127 return defaultValue;
4128 }
4129 }
4130
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08004131 // Splits a comma delimited string to an ArrayList of Size.
4132 // Return null if the passing string is null or the size is 0.
4133 private ArrayList<Size> splitSize(String str) {
4134 if (str == null) return null;
4135
Ali Utku Selen0a120182011-02-09 14:11:22 +01004136 TextUtils.StringSplitter splitter = new TextUtils.SimpleStringSplitter(',');
4137 splitter.setString(str);
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08004138 ArrayList<Size> sizeList = new ArrayList<Size>();
Ali Utku Selen0a120182011-02-09 14:11:22 +01004139 for (String s : splitter) {
4140 Size size = strToSize(s);
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08004141 if (size != null) sizeList.add(size);
4142 }
4143 if (sizeList.size() == 0) return null;
4144 return sizeList;
4145 }
4146
4147 // Parses a string (ex: "480x320") to Size object.
4148 // Return null if the passing string is null.
4149 private Size strToSize(String str) {
4150 if (str == null) return null;
4151
4152 int pos = str.indexOf('x');
4153 if (pos != -1) {
4154 String width = str.substring(0, pos);
4155 String height = str.substring(pos + 1);
4156 return new Size(Integer.parseInt(width),
4157 Integer.parseInt(height));
4158 }
4159 Log.e(TAG, "Invalid size parameter string=" + str);
4160 return null;
4161 }
Wu-cheng Li454630f2010-08-11 16:48:05 -07004162
4163 // Splits a comma delimited string to an ArrayList of int array.
4164 // Example string: "(10000,26623),(10000,30000)". Return null if the
4165 // passing string is null or the size is 0.
4166 private ArrayList<int[]> splitRange(String str) {
4167 if (str == null || str.charAt(0) != '('
4168 || str.charAt(str.length() - 1) != ')') {
4169 Log.e(TAG, "Invalid range list string=" + str);
4170 return null;
4171 }
4172
4173 ArrayList<int[]> rangeList = new ArrayList<int[]>();
4174 int endIndex, fromIndex = 1;
4175 do {
4176 int[] range = new int[2];
4177 endIndex = str.indexOf("),(", fromIndex);
4178 if (endIndex == -1) endIndex = str.length() - 1;
4179 splitInt(str.substring(fromIndex, endIndex), range);
4180 rangeList.add(range);
4181 fromIndex = endIndex + 3;
4182 } while (endIndex != str.length() - 1);
4183
4184 if (rangeList.size() == 0) return null;
4185 return rangeList;
4186 }
Wu-cheng Li30771b72011-04-02 06:19:46 +08004187
4188 // Splits a comma delimited string to an ArrayList of Area objects.
4189 // Example string: "(-10,-10,0,0,300),(0,0,10,10,700)". Return null if
Wu-cheng Lif715bf92011-04-14 14:04:18 +08004190 // the passing string is null or the size is 0 or (0,0,0,0,0).
Wu-cheng Li30771b72011-04-02 06:19:46 +08004191 private ArrayList<Area> splitArea(String str) {
4192 if (str == null || str.charAt(0) != '('
4193 || str.charAt(str.length() - 1) != ')') {
4194 Log.e(TAG, "Invalid area string=" + str);
4195 return null;
4196 }
4197
4198 ArrayList<Area> result = new ArrayList<Area>();
4199 int endIndex, fromIndex = 1;
4200 int[] array = new int[5];
4201 do {
4202 endIndex = str.indexOf("),(", fromIndex);
4203 if (endIndex == -1) endIndex = str.length() - 1;
4204 splitInt(str.substring(fromIndex, endIndex), array);
4205 Rect rect = new Rect(array[0], array[1], array[2], array[3]);
4206 result.add(new Area(rect, array[4]));
4207 fromIndex = endIndex + 3;
4208 } while (endIndex != str.length() - 1);
4209
4210 if (result.size() == 0) return null;
Wu-cheng Lif715bf92011-04-14 14:04:18 +08004211
4212 if (result.size() == 1) {
Wu-cheng Libde61a52011-06-07 18:23:14 +08004213 Area area = result.get(0);
Wu-cheng Lif715bf92011-04-14 14:04:18 +08004214 Rect rect = area.rect;
4215 if (rect.left == 0 && rect.top == 0 && rect.right == 0
4216 && rect.bottom == 0 && area.weight == 0) {
4217 return null;
4218 }
4219 }
4220
Wu-cheng Li30771b72011-04-02 06:19:46 +08004221 return result;
4222 }
Wu-cheng Lib838d8d2011-11-17 20:12:23 +08004223
4224 private boolean same(String s1, String s2) {
4225 if (s1 == null && s2 == null) return true;
4226 if (s1 != null && s1.equals(s2)) return true;
4227 return false;
4228 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004229 };
4230}