blob: 4c73e6ad47520d8f2e0f42b246a12b9f8052c123 [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;
Eino-Ville Talvala4f8e5ce2012-10-08 18:16:35 -070022import android.content.Context;
Mathias Agopiana696f5d2010-02-17 17:53:09 -080023import android.graphics.ImageFormat;
Wu-cheng Li4c2292e2011-07-22 02:37:11 +080024import android.graphics.Point;
Wu-cheng Li30771b72011-04-02 06:19:46 +080025import android.graphics.Rect;
Jamie Gennisfd6f39e2010-12-20 12:15:00 -080026import android.graphics.SurfaceTexture;
Eino-Ville Talvala4f8e5ce2012-10-08 18:16:35 -070027import android.media.IAudioService;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080028import android.os.Handler;
Eino-Ville Talvala4f8e5ce2012-10-08 18:16:35 -070029import android.os.IBinder;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080030import android.os.Looper;
31import android.os.Message;
Eino-Ville Talvala4f8e5ce2012-10-08 18:16:35 -070032import android.os.RemoteException;
33import android.os.ServiceManager;
Eino-Ville Talvala7005b672013-04-02 15:46:38 -070034import android.renderscript.Allocation;
35import android.renderscript.Element;
36import android.renderscript.RenderScript;
37import android.renderscript.RSIllegalArgumentException;
38import android.renderscript.Type;
Wu-cheng Libde61a52011-06-07 18:23:14 +080039import android.util.Log;
Ali Utku Selen0a120182011-02-09 14:11:22 +010040import android.text.TextUtils;
Wu-cheng Libde61a52011-06-07 18:23:14 +080041import android.view.Surface;
42import android.view.SurfaceHolder;
43
44import java.io.IOException;
45import java.lang.ref.WeakReference;
46import java.util.ArrayList;
47import java.util.HashMap;
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
51/**
Dan Egnorbfcbeff2010-07-12 15:12:54 -070052 * The Camera class is used to set image capture settings, start/stop preview,
53 * snap pictures, and retrieve frames for encoding for video. This class is a
54 * client for the Camera service, which manages the actual camera hardware.
Scott Maindf4578e2009-09-10 12:22:07 -070055 *
Dan Egnorbfcbeff2010-07-12 15:12:54 -070056 * <p>To access the device camera, you must declare the
Wu-cheng Li7478ea62009-09-16 18:52:55 +080057 * {@link android.Manifest.permission#CAMERA} permission in your Android
Scott Maindf4578e2009-09-10 12:22:07 -070058 * Manifest. Also be sure to include the
59 * <a href="{@docRoot}guide/topics/manifest/uses-feature-element.html">&lt;uses-feature></a>
Dan Egnorbfcbeff2010-07-12 15:12:54 -070060 * manifest element to declare camera features used by your application.
Wu-cheng Li7478ea62009-09-16 18:52:55 +080061 * For example, if you use the camera and auto-focus feature, your Manifest
Scott Maindf4578e2009-09-10 12:22:07 -070062 * should include the following:</p>
63 * <pre> &lt;uses-permission android:name="android.permission.CAMERA" />
64 * &lt;uses-feature android:name="android.hardware.camera" />
65 * &lt;uses-feature android:name="android.hardware.camera.autofocus" /></pre>
66 *
Dan Egnorbfcbeff2010-07-12 15:12:54 -070067 * <p>To take pictures with this class, use the following steps:</p>
68 *
69 * <ol>
Dan Egnor341ff132010-07-20 11:30:17 -070070 * <li>Obtain an instance of Camera from {@link #open(int)}.
Dan Egnorbfcbeff2010-07-12 15:12:54 -070071 *
72 * <li>Get existing (default) settings with {@link #getParameters()}.
73 *
74 * <li>If necessary, modify the returned {@link Camera.Parameters} object and call
75 * {@link #setParameters(Camera.Parameters)}.
76 *
77 * <li>If desired, call {@link #setDisplayOrientation(int)}.
78 *
79 * <li><b>Important</b>: Pass a fully initialized {@link SurfaceHolder} to
80 * {@link #setPreviewDisplay(SurfaceHolder)}. Without a surface, the camera
81 * will be unable to start the preview.
82 *
83 * <li><b>Important</b>: Call {@link #startPreview()} to start updating the
84 * preview surface. Preview must be started before you can take a picture.
85 *
86 * <li>When you want, call {@link #takePicture(Camera.ShutterCallback,
87 * Camera.PictureCallback, Camera.PictureCallback, Camera.PictureCallback)} to
88 * capture a photo. Wait for the callbacks to provide the actual image data.
89 *
90 * <li>After taking a picture, preview display will have stopped. To take more
91 * photos, call {@link #startPreview()} again first.
92 *
93 * <li>Call {@link #stopPreview()} to stop updating the preview surface.
94 *
95 * <li><b>Important:</b> Call {@link #release()} to release the camera for
96 * use by other applications. Applications should release the camera
97 * immediately in {@link android.app.Activity#onPause()} (and re-{@link #open()}
98 * it in {@link android.app.Activity#onResume()}).
99 * </ol>
100 *
101 * <p>To quickly switch to video recording mode, use these steps:</p>
102 *
103 * <ol>
104 * <li>Obtain and initialize a Camera and start preview as described above.
105 *
106 * <li>Call {@link #unlock()} to allow the media process to access the camera.
107 *
108 * <li>Pass the camera to {@link android.media.MediaRecorder#setCamera(Camera)}.
109 * See {@link android.media.MediaRecorder} information about video recording.
110 *
111 * <li>When finished recording, call {@link #reconnect()} to re-acquire
112 * and re-lock the camera.
113 *
114 * <li>If desired, restart preview and take more photos or videos.
115 *
116 * <li>Call {@link #stopPreview()} and {@link #release()} as described above.
117 * </ol>
118 *
119 * <p>This class is not thread-safe, and is meant for use from one event thread.
120 * Most long-running operations (preview, focus, photo capture, etc) happen
121 * asynchronously and invoke callbacks as necessary. Callbacks will be invoked
Dan Egnor341ff132010-07-20 11:30:17 -0700122 * on the event thread {@link #open(int)} was called from. This class's methods
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700123 * must never be called from multiple threads at once.</p>
124 *
Scott Maindf4578e2009-09-10 12:22:07 -0700125 * <p class="caution"><strong>Caution:</strong> Different Android-powered devices
126 * may have different hardware specifications, such as megapixel ratings and
127 * auto-focus capabilities. In order for your application to be compatible with
Wu-cheng Li7478ea62009-09-16 18:52:55 +0800128 * more devices, you should not make assumptions about the device camera
Scott Maindf4578e2009-09-10 12:22:07 -0700129 * specifications.</p>
Joe Fernandez6c5c3c32011-10-18 14:57:05 -0700130 *
131 * <div class="special reference">
132 * <h3>Developer Guides</h3>
133 * <p>For more information about using cameras, read the
134 * <a href="{@docRoot}guide/topics/media/camera.html">Camera</a> developer guide.</p>
135 * </div>
Eino-Ville Talvalab942b052014-07-10 17:45:03 -0700136 *
137 * @deprecated We recommend using the new {@link android.hardware.camera2} API for new
138 * applications.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800139 */
Eino-Ville Talvalab942b052014-07-10 17:45:03 -0700140@Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800141public class Camera {
142 private static final String TAG = "Camera";
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800143
Wu-cheng Lid2c29292010-05-28 17:32:41 +0800144 // These match the enums in frameworks/base/include/camera/Camera.h
Benny Wongda83f462009-08-12 12:01:27 -0500145 private static final int CAMERA_MSG_ERROR = 0x001;
146 private static final int CAMERA_MSG_SHUTTER = 0x002;
147 private static final int CAMERA_MSG_FOCUS = 0x004;
148 private static final int CAMERA_MSG_ZOOM = 0x008;
149 private static final int CAMERA_MSG_PREVIEW_FRAME = 0x010;
150 private static final int CAMERA_MSG_VIDEO_FRAME = 0x020;
151 private static final int CAMERA_MSG_POSTVIEW_FRAME = 0x040;
152 private static final int CAMERA_MSG_RAW_IMAGE = 0x080;
153 private static final int CAMERA_MSG_COMPRESSED_IMAGE = 0x100;
Wu-cheng Li4c2292e2011-07-22 02:37:11 +0800154 private static final int CAMERA_MSG_RAW_IMAGE_NOTIFY = 0x200;
Wu-cheng Libb1e2752011-07-30 05:00:37 +0800155 private static final int CAMERA_MSG_PREVIEW_METADATA = 0x400;
Wu-cheng Li9d062cf2011-11-14 20:30:14 +0800156 private static final int CAMERA_MSG_FOCUS_MOVE = 0x800;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800157
Ashok Bhat4838e332014-01-03 14:37:19 +0000158 private long mNativeContext; // accessed by native methods
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800159 private EventHandler mEventHandler;
160 private ShutterCallback mShutterCallback;
161 private PictureCallback mRawImageCallback;
162 private PictureCallback mJpegCallback;
163 private PreviewCallback mPreviewCallback;
Eino-Ville Talvala7005b672013-04-02 15:46:38 -0700164 private boolean mUsingPreviewAllocation;
Dave Sparkse8b26e12009-07-14 10:35:40 -0700165 private PictureCallback mPostviewCallback;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800166 private AutoFocusCallback mAutoFocusCallback;
Wu-cheng Li9d062cf2011-11-14 20:30:14 +0800167 private AutoFocusMoveCallback mAutoFocusMoveCallback;
Wu-cheng Li3f4639a2010-04-04 15:05:41 +0800168 private OnZoomChangeListener mZoomListener;
Wu-cheng Li4c2292e2011-07-22 02:37:11 +0800169 private FaceDetectionListener mFaceListener;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800170 private ErrorCallback mErrorCallback;
171 private boolean mOneShot;
Andrew Harp94927df2009-10-20 01:47:05 -0400172 private boolean mWithBuffer;
Wu-cheng Li4c2292e2011-07-22 02:37:11 +0800173 private boolean mFaceDetectionRunning = false;
Igor Murashkina1d66272014-06-20 11:22:11 -0700174 private final Object mAutoFocusCallbackLock = new Object();
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800175
Ruben Brunkfeb50af2014-05-09 19:58:49 -0700176 private static final int NO_ERROR = 0;
177 private static final int EACCESS = -13;
178 private static final int ENODEV = -19;
Zhijun He4c913802014-06-16 16:42:35 -0700179 private static final int EBUSY = -16;
180 private static final int EINVAL = -22;
181 private static final int ENOSYS = -38;
182 private static final int EUSERS = -87;
183 private static final int EOPNOTSUPP = -95;
Ruben Brunkfeb50af2014-05-09 19:58:49 -0700184
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800185 /**
Wu-cheng Li10e09c62011-07-18 09:09:41 +0800186 * Broadcast Action: A new picture is taken by the camera, and the entry of
187 * the picture has been added to the media store.
188 * {@link android.content.Intent#getData} is URI of the picture.
189 */
190 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
191 public static final String ACTION_NEW_PICTURE = "android.hardware.action.NEW_PICTURE";
192
193 /**
194 * Broadcast Action: A new video is recorded by the camera, and the entry
195 * of the video has been added to the media store.
196 * {@link android.content.Intent#getData} is URI of the video.
197 */
198 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
199 public static final String ACTION_NEW_VIDEO = "android.hardware.action.NEW_VIDEO";
200
201 /**
Zhijun He4c913802014-06-16 16:42:35 -0700202 * Camera HAL device API version 1.0
203 * @hide
204 */
205 public static final int CAMERA_HAL_API_VERSION_1_0 = 0x100;
206
207 /**
208 * A constant meaning the normal camera connect/open will be used.
Zhijun He4c913802014-06-16 16:42:35 -0700209 */
Igor Murashkina1d66272014-06-20 11:22:11 -0700210 private static final int CAMERA_HAL_API_VERSION_NORMAL_CONNECT = -2;
Zhijun He4c913802014-06-16 16:42:35 -0700211
212 /**
213 * Used to indicate HAL version un-specified.
214 */
215 private static final int CAMERA_HAL_API_VERSION_UNSPECIFIED = -1;
Igor Murashkina1d66272014-06-20 11:22:11 -0700216
Zhijun He4c913802014-06-16 16:42:35 -0700217 /**
Wu-cheng Li4c2292e2011-07-22 02:37:11 +0800218 * Hardware face detection. It does not use much CPU.
Wu-cheng Li4c2292e2011-07-22 02:37:11 +0800219 */
Wu-cheng Lic0c683b2011-08-04 00:11:00 +0800220 private static final int CAMERA_FACE_DETECTION_HW = 0;
Wu-cheng Li4c2292e2011-07-22 02:37:11 +0800221
222 /**
Wu-cheng Lic0c683b2011-08-04 00:11:00 +0800223 * Software face detection. It uses some CPU.
Wu-cheng Li4c2292e2011-07-22 02:37:11 +0800224 */
Wu-cheng Lic0c683b2011-08-04 00:11:00 +0800225 private static final int CAMERA_FACE_DETECTION_SW = 1;
Wu-cheng Li4c2292e2011-07-22 02:37:11 +0800226
227 /**
Dan Egnor341ff132010-07-20 11:30:17 -0700228 * Returns the number of physical cameras available on this device.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800229 */
Chih-Chung Change25cc652010-05-06 16:36:58 +0800230 public native static int getNumberOfCameras();
231
232 /**
Dan Egnor341ff132010-07-20 11:30:17 -0700233 * Returns the information about a particular camera.
Chih-Chung Changb8bb78f2010-06-10 13:32:16 +0800234 * If {@link #getNumberOfCameras()} returns N, the valid id is 0 to N-1.
Chih-Chung Changb8bb78f2010-06-10 13:32:16 +0800235 */
Eino-Ville Talvala4f8e5ce2012-10-08 18:16:35 -0700236 public static void getCameraInfo(int cameraId, CameraInfo cameraInfo) {
237 _getCameraInfo(cameraId, cameraInfo);
238 IBinder b = ServiceManager.getService(Context.AUDIO_SERVICE);
239 IAudioService audioService = IAudioService.Stub.asInterface(b);
240 try {
241 if (audioService.isCameraSoundForced()) {
242 // Only set this when sound is forced; otherwise let native code
243 // decide.
244 cameraInfo.canDisableShutterSound = false;
245 }
246 } catch (RemoteException e) {
247 Log.e(TAG, "Audio service is unavailable for queries");
248 }
249 }
250 private native static void _getCameraInfo(int cameraId, CameraInfo cameraInfo);
Chih-Chung Changb8bb78f2010-06-10 13:32:16 +0800251
252 /**
253 * Information about a camera
Eino-Ville Talvalab942b052014-07-10 17:45:03 -0700254 *
255 * @deprecated We recommend using the new {@link android.hardware.camera2} API for new
256 * applications.
Chih-Chung Changb8bb78f2010-06-10 13:32:16 +0800257 */
Eino-Ville Talvalab942b052014-07-10 17:45:03 -0700258 @Deprecated
Chih-Chung Changb8bb78f2010-06-10 13:32:16 +0800259 public static class CameraInfo {
Wu-cheng Li78366602010-09-15 14:08:15 -0700260 /**
261 * The facing of the camera is opposite to that of the screen.
262 */
Chih-Chung Changb8bb78f2010-06-10 13:32:16 +0800263 public static final int CAMERA_FACING_BACK = 0;
Wu-cheng Li78366602010-09-15 14:08:15 -0700264
265 /**
266 * The facing of the camera is the same as that of the screen.
267 */
Chih-Chung Changb8bb78f2010-06-10 13:32:16 +0800268 public static final int CAMERA_FACING_FRONT = 1;
269
270 /**
Joe Fernandez464cb212011-10-04 16:56:47 -0700271 * The direction that the camera faces. It should be
Chih-Chung Changb8bb78f2010-06-10 13:32:16 +0800272 * CAMERA_FACING_BACK or CAMERA_FACING_FRONT.
273 */
Wu-cheng Li78366602010-09-15 14:08:15 -0700274 public int facing;
Chih-Chung Changb8bb78f2010-06-10 13:32:16 +0800275
276 /**
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -0700277 * <p>The orientation of the camera image. The value is the angle that the
Chih-Chung Changb8bb78f2010-06-10 13:32:16 +0800278 * camera image needs to be rotated clockwise so it shows correctly on
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -0700279 * the display in its natural orientation. It should be 0, 90, 180, or 270.</p>
Chih-Chung Changb8bb78f2010-06-10 13:32:16 +0800280 *
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -0700281 * <p>For example, suppose a device has a naturally tall screen. The
Wu-cheng Li2fe6fca2010-10-15 14:42:23 +0800282 * back-facing camera sensor is mounted in landscape. You are looking at
283 * the screen. If the top side of the camera sensor is aligned with the
284 * right edge of the screen in natural orientation, the value should be
285 * 90. If the top side of a front-facing camera sensor is aligned with
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -0700286 * the right of the screen, the value should be 270.</p>
Chih-Chung Changb8bb78f2010-06-10 13:32:16 +0800287 *
288 * @see #setDisplayOrientation(int)
Brad Fitzpatrick69ea4e12011-01-05 11:13:40 -0800289 * @see Parameters#setRotation(int)
290 * @see Parameters#setPreviewSize(int, int)
291 * @see Parameters#setPictureSize(int, int)
292 * @see Parameters#setJpegThumbnailSize(int, int)
Chih-Chung Changb8bb78f2010-06-10 13:32:16 +0800293 */
Wu-cheng Li78366602010-09-15 14:08:15 -0700294 public int orientation;
Eino-Ville Talvalaf7c6c5a2012-09-19 11:46:11 -0700295
296 /**
297 * <p>Whether the shutter sound can be disabled.</p>
298 *
299 * <p>On some devices, the camera shutter sound cannot be turned off
300 * through {@link #enableShutterSound enableShutterSound}. This field
301 * can be used to determine whether a call to disable the shutter sound
302 * will succeed.</p>
303 *
304 * <p>If this field is set to true, then a call of
305 * {@code enableShutterSound(false)} will be successful. If set to
306 * false, then that call will fail, and the shutter sound will be played
307 * when {@link Camera#takePicture takePicture} is called.</p>
308 */
309 public boolean canDisableShutterSound;
Chih-Chung Changb8bb78f2010-06-10 13:32:16 +0800310 };
311
312 /**
Wu-cheng Lia1c41e12012-02-23 19:01:00 -0800313 * Creates a new Camera object to access a particular hardware camera. If
314 * the same camera is opened by other applications, this will throw a
315 * RuntimeException.
316 *
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700317 * <p>You must call {@link #release()} when you are done using the camera,
318 * otherwise it will remain locked and be unavailable to other applications.
319 *
Dan Egnor341ff132010-07-20 11:30:17 -0700320 * <p>Your application should only have one Camera object active at a time
321 * for a particular hardware camera.
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700322 *
323 * <p>Callbacks from other methods are delivered to the event loop of the
324 * thread which called open(). If this thread has no event loop, then
325 * callbacks are delivered to the main application event loop. If there
326 * is no main application event loop, callbacks are not delivered.
327 *
328 * <p class="caution"><b>Caution:</b> On some devices, this method may
329 * take a long time to complete. It is best to call this method from a
330 * worker thread (possibly using {@link android.os.AsyncTask}) to avoid
331 * blocking the main application UI thread.
332 *
Dan Egnor341ff132010-07-20 11:30:17 -0700333 * @param cameraId the hardware camera to access, between 0 and
Wu-cheng Lia48b70f2010-11-09 01:55:44 +0800334 * {@link #getNumberOfCameras()}-1.
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700335 * @return a new Camera object, connected, locked and ready for use.
Wu-cheng Lia1c41e12012-02-23 19:01:00 -0800336 * @throws RuntimeException if opening the camera fails (for example, if the
337 * camera is in use by another process or device policy manager has
338 * disabled the camera).
Wu-cheng Lifacc8ce2011-06-17 13:09:40 +0800339 * @see android.app.admin.DevicePolicyManager#getCameraDisabled(android.content.ComponentName)
Chih-Chung Change25cc652010-05-06 16:36:58 +0800340 */
341 public static Camera open(int cameraId) {
Wu-cheng Li7bc1b212012-04-19 12:23:31 +0800342 return new Camera(cameraId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800343 }
344
Chih-Chung Change25cc652010-05-06 16:36:58 +0800345 /**
Wu-cheng Lia48b70f2010-11-09 01:55:44 +0800346 * Creates a new Camera object to access the first back-facing camera on the
347 * device. If the device does not have a back-facing camera, this returns
348 * null.
Wu-cheng Li78366602010-09-15 14:08:15 -0700349 * @see #open(int)
Chih-Chung Change25cc652010-05-06 16:36:58 +0800350 */
351 public static Camera open() {
Wu-cheng Lia48b70f2010-11-09 01:55:44 +0800352 int numberOfCameras = getNumberOfCameras();
353 CameraInfo cameraInfo = new CameraInfo();
354 for (int i = 0; i < numberOfCameras; i++) {
355 getCameraInfo(i, cameraInfo);
356 if (cameraInfo.facing == CameraInfo.CAMERA_FACING_BACK) {
Wu-cheng Li7bc1b212012-04-19 12:23:31 +0800357 return new Camera(i);
Wu-cheng Lia48b70f2010-11-09 01:55:44 +0800358 }
359 }
360 return null;
Chih-Chung Change25cc652010-05-06 16:36:58 +0800361 }
362
Zhijun He4c913802014-06-16 16:42:35 -0700363 /**
364 * Creates a new Camera object to access a particular hardware camera with
365 * given hal API version. If the same camera is opened by other applications
366 * or the hal API version is not supported by this device, this will throw a
367 * RuntimeException.
368 * <p>
369 * You must call {@link #release()} when you are done using the camera,
370 * otherwise it will remain locked and be unavailable to other applications.
371 * <p>
372 * Your application should only have one Camera object active at a time for
373 * a particular hardware camera.
374 * <p>
375 * Callbacks from other methods are delivered to the event loop of the
376 * thread which called open(). If this thread has no event loop, then
377 * callbacks are delivered to the main application event loop. If there is
378 * no main application event loop, callbacks are not delivered.
379 * <p class="caution">
380 * <b>Caution:</b> On some devices, this method may take a long time to
381 * complete. It is best to call this method from a worker thread (possibly
382 * using {@link android.os.AsyncTask}) to avoid blocking the main
383 * application UI thread.
384 *
385 * @param cameraId The hardware camera to access, between 0 and
386 * {@link #getNumberOfCameras()}-1.
Igor Murashkina1d66272014-06-20 11:22:11 -0700387 * @param halVersion The HAL API version this camera device to be opened as.
Zhijun He4c913802014-06-16 16:42:35 -0700388 * @return a new Camera object, connected, locked and ready for use.
Igor Murashkina1d66272014-06-20 11:22:11 -0700389 *
390 * @throws IllegalArgumentException if the {@code halVersion} is invalid
391 *
Zhijun He4c913802014-06-16 16:42:35 -0700392 * @throws RuntimeException if opening the camera fails (for example, if the
393 * camera is in use by another process or device policy manager has disabled
394 * the camera).
Igor Murashkina1d66272014-06-20 11:22:11 -0700395 *
Zhijun He4c913802014-06-16 16:42:35 -0700396 * @see android.app.admin.DevicePolicyManager#getCameraDisabled(android.content.ComponentName)
Igor Murashkina1d66272014-06-20 11:22:11 -0700397 * @see #CAMERA_HAL_API_VERSION_1_0
Zhijun He4c913802014-06-16 16:42:35 -0700398 *
399 * @hide
400 */
401 public static Camera openLegacy(int cameraId, int halVersion) {
Igor Murashkina1d66272014-06-20 11:22:11 -0700402 if (halVersion < CAMERA_HAL_API_VERSION_1_0) {
403 throw new IllegalArgumentException("Invalid HAL version " + halVersion);
404 }
405
Zhijun He4c913802014-06-16 16:42:35 -0700406 return new Camera(cameraId, halVersion);
407 }
408
409 /**
410 * Create a legacy camera object.
411 *
412 * @param cameraId The hardware camera to access, between 0 and
413 * {@link #getNumberOfCameras()}-1.
414 * @param halVersion The HAL API version this camera device to be opened as.
415 */
416 private Camera(int cameraId, int halVersion) {
Igor Murashkina1d66272014-06-20 11:22:11 -0700417 int err = cameraInitVersion(cameraId, halVersion);
Zhijun He4c913802014-06-16 16:42:35 -0700418 if (checkInitErrors(err)) {
419 switch(err) {
420 case EACCESS:
421 throw new RuntimeException("Fail to connect to camera service");
422 case ENODEV:
423 throw new RuntimeException("Camera initialization failed");
424 case ENOSYS:
425 throw new RuntimeException("Camera initialization failed because some methods"
426 + " are not implemented");
427 case EOPNOTSUPP:
428 throw new RuntimeException("Camera initialization failed because the hal"
429 + " version is not supported by this device");
430 case EINVAL:
431 throw new RuntimeException("Camera initialization failed because the input"
432 + " arugments are invalid");
433 case EBUSY:
434 throw new RuntimeException("Camera initialization failed because the camera"
435 + " device was already opened");
436 case EUSERS:
437 throw new RuntimeException("Camera initialization failed because the max"
438 + " number of camera devices were already opened");
439 default:
440 // Should never hit this.
441 throw new RuntimeException("Unknown camera error");
442 }
443 }
444 }
445
Igor Murashkina1d66272014-06-20 11:22:11 -0700446 private int cameraInitVersion(int cameraId, int halVersion) {
Zhijun He4c913802014-06-16 16:42:35 -0700447 mShutterCallback = null;
448 mRawImageCallback = null;
449 mJpegCallback = null;
450 mPreviewCallback = null;
451 mPostviewCallback = null;
452 mUsingPreviewAllocation = false;
453 mZoomListener = null;
454
455 Looper looper;
456 if ((looper = Looper.myLooper()) != null) {
457 mEventHandler = new EventHandler(this, looper);
458 } else if ((looper = Looper.getMainLooper()) != null) {
459 mEventHandler = new EventHandler(this, looper);
460 } else {
461 mEventHandler = null;
462 }
463
464 String packageName = ActivityThread.currentPackageName();
465
466 return native_setup(new WeakReference<Camera>(this), cameraId, halVersion, packageName);
467 }
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)) {
495 switch(err) {
496 case EACCESS:
497 throw new RuntimeException("Fail to connect to camera service");
498 case ENODEV:
499 throw new RuntimeException("Camera initialization failed");
500 default:
501 // Should never hit this.
502 throw new RuntimeException("Unknown camera error");
503 }
504 }
505 }
506
Ruben Brunkfeb50af2014-05-09 19:58:49 -0700507
508 /**
509 * @hide
510 */
511 public static boolean checkInitErrors(int err) {
512 return err != NO_ERROR;
513 }
514
515 /**
516 * @hide
517 */
518 public static Camera openUninitialized() {
519 return new Camera();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800520 }
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800521
Wu-cheng Li1c04a332011-11-22 18:21:18 +0800522 /**
523 * An empty Camera for testing purpose.
524 */
525 Camera() {
526 }
527
Igor Murashkina1d66272014-06-20 11:22:11 -0700528 @Override
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800529 protected void finalize() {
Eino-Ville Talvalae0cc55a2011-11-08 10:12:09 -0800530 release();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800531 }
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800532
Zhijun He4c913802014-06-16 16:42:35 -0700533 private native final int native_setup(Object camera_this, int cameraId, int halVersion,
Eino-Ville Talvala788717c2013-02-15 18:30:15 -0800534 String packageName);
535
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800536 private native final void native_release();
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800537
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800538
539 /**
540 * Disconnects and releases the Camera object resources.
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700541 *
542 * <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 -0800543 */
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800544 public final void release() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800545 native_release();
Wu-cheng Li4c2292e2011-07-22 02:37:11 +0800546 mFaceDetectionRunning = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800547 }
548
549 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700550 * Unlocks the camera to allow another process to access it.
551 * Normally, the camera is locked to the process with an active Camera
552 * object until {@link #release()} is called. To allow rapid handoff
553 * between processes, you can call this method to release the camera
554 * temporarily for another process to use; once the other process is done
555 * you can call {@link #reconnect()} to reclaim the camera.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800556 *
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700557 * <p>This must be done before calling
Wu-cheng Li42419ce2011-06-01 17:22:24 +0800558 * {@link android.media.MediaRecorder#setCamera(Camera)}. This cannot be
559 * called after recording starts.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800560 *
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700561 * <p>If you are not recording video, you probably do not need this method.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800562 *
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700563 * @throws RuntimeException if the camera cannot be unlocked.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800564 */
Wu-cheng Liffe1cf22009-09-10 16:49:17 +0800565 public native final void unlock();
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800566
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800567 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700568 * Re-locks the camera to prevent other processes from accessing it.
569 * Camera objects are locked by default unless {@link #unlock()} is
570 * called. Normally {@link #reconnect()} is used instead.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800571 *
Wu-cheng Li53b30912011-10-12 19:43:51 +0800572 * <p>Since API level 14, camera is automatically locked for applications in
Wu-cheng Li42419ce2011-06-01 17:22:24 +0800573 * {@link android.media.MediaRecorder#start()}. Applications can use the
574 * camera (ex: zoom) after recording starts. There is no need to call this
575 * after recording starts or stops.
576 *
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700577 * <p>If you are not recording video, you probably do not need this method.
578 *
579 * @throws RuntimeException if the camera cannot be re-locked (for
580 * example, if the camera is still in use by another process).
581 */
582 public native final void lock();
583
584 /**
585 * Reconnects to the camera service after another process used it.
586 * After {@link #unlock()} is called, another process may use the
587 * camera; when the process is done, you must reconnect to the camera,
588 * which will re-acquire the lock and allow you to continue using the
589 * camera.
590 *
Wu-cheng Li53b30912011-10-12 19:43:51 +0800591 * <p>Since API level 14, camera is automatically locked for applications in
Wu-cheng Li42419ce2011-06-01 17:22:24 +0800592 * {@link android.media.MediaRecorder#start()}. Applications can use the
593 * camera (ex: zoom) after recording starts. There is no need to call this
594 * after recording starts or stops.
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700595 *
596 * <p>If you are not recording video, you probably do not need this method.
597 *
598 * @throws IOException if a connection cannot be re-established (for
599 * example, if the camera is still in use by another process).
600 */
601 public native final void reconnect() throws IOException;
602
603 /**
604 * Sets the {@link Surface} to be used for live preview.
Jamie Gennisfd6f39e2010-12-20 12:15:00 -0800605 * Either a surface or surface texture is necessary for preview, and
606 * preview is necessary to take pictures. The same surface can be re-set
607 * without harm. Setting a preview surface will un-set any preview surface
608 * texture that was set via {@link #setPreviewTexture}.
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700609 *
610 * <p>The {@link SurfaceHolder} must already contain a surface when this
611 * method is called. If you are using {@link android.view.SurfaceView},
612 * you will need to register a {@link SurfaceHolder.Callback} with
613 * {@link SurfaceHolder#addCallback(SurfaceHolder.Callback)} and wait for
614 * {@link SurfaceHolder.Callback#surfaceCreated(SurfaceHolder)} before
615 * calling setPreviewDisplay() or starting preview.
616 *
617 * <p>This method must be called before {@link #startPreview()}. The
618 * one exception is that if the preview surface is not set (or set to null)
619 * before startPreview() is called, then this method may be called once
620 * with a non-null parameter to set the preview surface. (This allows
621 * camera setup and surface creation to happen in parallel, saving time.)
622 * The preview surface may not otherwise change while preview is running.
623 *
624 * @param holder containing the Surface on which to place the preview,
625 * or null to remove the preview surface
626 * @throws IOException if the method fails (for example, if the surface
627 * is unavailable or unsuitable).
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800628 */
629 public final void setPreviewDisplay(SurfaceHolder holder) throws IOException {
Wu-cheng Lib8a10fe2009-06-23 23:37:36 +0800630 if (holder != null) {
Ruben Brunkfeb50af2014-05-09 19:58:49 -0700631 setPreviewSurface(holder.getSurface());
Wu-cheng Lib8a10fe2009-06-23 23:37:36 +0800632 } else {
Ruben Brunkfeb50af2014-05-09 19:58:49 -0700633 setPreviewSurface((Surface)null);
Wu-cheng Lib8a10fe2009-06-23 23:37:36 +0800634 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800635 }
636
Ruben Brunkfeb50af2014-05-09 19:58:49 -0700637 /**
638 * @hide
639 */
640 public native final void setPreviewSurface(Surface surface) throws IOException;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800641
642 /**
Jamie Gennisfd6f39e2010-12-20 12:15:00 -0800643 * Sets the {@link SurfaceTexture} to be used for live preview.
644 * Either a surface or surface texture is necessary for preview, and
645 * preview is necessary to take pictures. The same surface texture can be
646 * re-set without harm. Setting a preview surface texture will un-set any
647 * preview surface that was set via {@link #setPreviewDisplay}.
648 *
649 * <p>This method must be called before {@link #startPreview()}. The
650 * one exception is that if the preview surface texture is not set (or set
651 * to null) before startPreview() is called, then this method may be called
652 * once with a non-null parameter to set the preview surface. (This allows
653 * camera setup and surface creation to happen in parallel, saving time.)
654 * The preview surface texture may not otherwise change while preview is
655 * running.
656 *
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -0700657 * <p>The timestamps provided by {@link SurfaceTexture#getTimestamp()} for a
Eino-Ville Talvalae309a0f2011-03-21 11:04:34 -0700658 * SurfaceTexture set as the preview texture have an unspecified zero point,
659 * and cannot be directly compared between different cameras or different
660 * instances of the same camera, or across multiple runs of the same
661 * program.
662 *
Eino-Ville Talvala108708b2012-03-05 11:00:43 -0800663 * <p>If you are using the preview data to create video or still images,
664 * strongly consider using {@link android.media.MediaActionSound} to
665 * properly indicate image capture or recording start/stop to the user.</p>
666 *
667 * @see android.media.MediaActionSound
668 * @see android.graphics.SurfaceTexture
669 * @see android.view.TextureView
Jamie Gennisfd6f39e2010-12-20 12:15:00 -0800670 * @param surfaceTexture the {@link SurfaceTexture} to which the preview
671 * images are to be sent or null to remove the current preview surface
672 * texture
673 * @throws IOException if the method fails (for example, if the surface
674 * texture is unavailable or unsuitable).
675 */
Glenn Kastendbc289d2011-02-09 10:15:44 -0800676 public native final void setPreviewTexture(SurfaceTexture surfaceTexture) throws IOException;
Jamie Gennisfd6f39e2010-12-20 12:15:00 -0800677
678 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700679 * Callback interface used to deliver copies of preview frames as
680 * they are displayed.
681 *
682 * @see #setPreviewCallback(Camera.PreviewCallback)
683 * @see #setOneShotPreviewCallback(Camera.PreviewCallback)
684 * @see #setPreviewCallbackWithBuffer(Camera.PreviewCallback)
685 * @see #startPreview()
Eino-Ville Talvalab942b052014-07-10 17:45:03 -0700686 *
687 * @deprecated We recommend using the new {@link android.hardware.camera2} API for new
688 * applications.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800689 */
Eino-Ville Talvalab942b052014-07-10 17:45:03 -0700690 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800691 public interface PreviewCallback
692 {
693 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700694 * Called as preview frames are displayed. This callback is invoked
Dan Egnor341ff132010-07-20 11:30:17 -0700695 * on the event thread {@link #open(int)} was called from.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800696 *
Eino-Ville Talvala95151632012-05-02 16:21:18 -0700697 * <p>If using the {@link android.graphics.ImageFormat#YV12} format,
698 * refer to the equations in {@link Camera.Parameters#setPreviewFormat}
699 * for the arrangement of the pixel data in the preview callback
700 * buffers.
701 *
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700702 * @param data the contents of the preview frame in the format defined
Mathias Agopiana696f5d2010-02-17 17:53:09 -0800703 * by {@link android.graphics.ImageFormat}, which can be queried
Scott Maindf4578e2009-09-10 12:22:07 -0700704 * with {@link android.hardware.Camera.Parameters#getPreviewFormat()}.
Scott Mainda0a56d2009-09-10 18:08:37 -0700705 * If {@link android.hardware.Camera.Parameters#setPreviewFormat(int)}
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800706 * is never called, the default will be the YCbCr_420_SP
707 * (NV21) format.
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700708 * @param camera the Camera service object.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800709 */
710 void onPreviewFrame(byte[] data, Camera camera);
711 };
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800712
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800713 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700714 * Starts capturing and drawing preview frames to the screen.
Eino-Ville Talvalac5f94d82011-02-18 11:02:42 -0800715 * Preview will not actually start until a surface is supplied
716 * with {@link #setPreviewDisplay(SurfaceHolder)} or
717 * {@link #setPreviewTexture(SurfaceTexture)}.
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700718 *
719 * <p>If {@link #setPreviewCallback(Camera.PreviewCallback)},
720 * {@link #setOneShotPreviewCallback(Camera.PreviewCallback)}, or
721 * {@link #setPreviewCallbackWithBuffer(Camera.PreviewCallback)} were
722 * called, {@link Camera.PreviewCallback#onPreviewFrame(byte[], Camera)}
723 * will be called when preview data becomes available.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800724 */
725 public native final void startPreview();
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800726
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800727 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700728 * Stops capturing and drawing preview frames to the surface, and
729 * resets the camera for a future call to {@link #startPreview()}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800730 */
Wu-cheng Li4c2292e2011-07-22 02:37:11 +0800731 public final void stopPreview() {
732 _stopPreview();
733 mFaceDetectionRunning = false;
Chih-yu Huang664d72e2011-09-23 18:59:38 +0800734
735 mShutterCallback = null;
736 mRawImageCallback = null;
737 mPostviewCallback = null;
738 mJpegCallback = null;
Wu-cheng Lif05c1d62012-05-02 23:29:47 +0800739 synchronized (mAutoFocusCallbackLock) {
740 mAutoFocusCallback = null;
741 }
Wu-cheng Li9d062cf2011-11-14 20:30:14 +0800742 mAutoFocusMoveCallback = null;
Wu-cheng Li4c2292e2011-07-22 02:37:11 +0800743 }
744
745 private native final void _stopPreview();
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800746
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800747 /**
748 * Return current preview state.
749 *
750 * FIXME: Unhide before release
751 * @hide
752 */
753 public native final boolean previewEnabled();
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800754
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800755 /**
Eino-Ville Talvala108708b2012-03-05 11:00:43 -0800756 * <p>Installs a callback to be invoked for every preview frame in addition
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700757 * to displaying them on the screen. The callback will be repeatedly called
758 * for as long as preview is active. This method can be called at any time,
Eino-Ville Talvala108708b2012-03-05 11:00:43 -0800759 * even while preview is live. Any other preview callbacks are
760 * overridden.</p>
761 *
762 * <p>If you are using the preview data to create video or still images,
763 * strongly consider using {@link android.media.MediaActionSound} to
764 * properly indicate image capture or recording start/stop to the user.</p>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800765 *
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700766 * @param cb a callback object that receives a copy of each preview frame,
767 * or null to stop receiving callbacks.
Eino-Ville Talvala108708b2012-03-05 11:00:43 -0800768 * @see android.media.MediaActionSound
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800769 */
770 public final void setPreviewCallback(PreviewCallback cb) {
771 mPreviewCallback = cb;
772 mOneShot = false;
Andrew Harp94927df2009-10-20 01:47:05 -0400773 mWithBuffer = false;
Eino-Ville Talvala7005b672013-04-02 15:46:38 -0700774 if (cb != null) {
775 mUsingPreviewAllocation = false;
776 }
Dave Sparksa6118c62009-10-13 02:28:54 -0700777 // Always use one-shot mode. We fake camera preview mode by
778 // doing one-shot preview continuously.
Andrew Harp94927df2009-10-20 01:47:05 -0400779 setHasPreviewCallback(cb != null, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800780 }
781
782 /**
Eino-Ville Talvala108708b2012-03-05 11:00:43 -0800783 * <p>Installs a callback to be invoked for the next preview frame in
784 * addition to displaying it on the screen. After one invocation, the
785 * callback is cleared. This method can be called any time, even when
786 * preview is live. Any other preview callbacks are overridden.</p>
787 *
788 * <p>If you are using the preview data to create video or still images,
789 * strongly consider using {@link android.media.MediaActionSound} to
790 * properly indicate image capture or recording start/stop to the user.</p>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800791 *
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700792 * @param cb a callback object that receives a copy of the next preview frame,
793 * or null to stop receiving callbacks.
Eino-Ville Talvala108708b2012-03-05 11:00:43 -0800794 * @see android.media.MediaActionSound
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800795 */
796 public final void setOneShotPreviewCallback(PreviewCallback cb) {
Andrew Harp94927df2009-10-20 01:47:05 -0400797 mPreviewCallback = cb;
798 mOneShot = true;
799 mWithBuffer = false;
Eino-Ville Talvala7005b672013-04-02 15:46:38 -0700800 if (cb != null) {
801 mUsingPreviewAllocation = false;
802 }
Andrew Harp94927df2009-10-20 01:47:05 -0400803 setHasPreviewCallback(cb != null, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800804 }
805
Andrew Harp94927df2009-10-20 01:47:05 -0400806 private native final void setHasPreviewCallback(boolean installed, boolean manualBuffer);
807
808 /**
Eino-Ville Talvala108708b2012-03-05 11:00:43 -0800809 * <p>Installs a callback to be invoked for every preview frame, using
810 * buffers supplied with {@link #addCallbackBuffer(byte[])}, in addition to
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700811 * displaying them on the screen. The callback will be repeatedly called
Eino-Ville Talvala108708b2012-03-05 11:00:43 -0800812 * for as long as preview is active and buffers are available. Any other
813 * preview callbacks are overridden.</p>
Andrew Harp94927df2009-10-20 01:47:05 -0400814 *
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700815 * <p>The purpose of this method is to improve preview efficiency and frame
816 * rate by allowing preview frame memory reuse. You must call
817 * {@link #addCallbackBuffer(byte[])} at some point -- before or after
Eino-Ville Talvala108708b2012-03-05 11:00:43 -0800818 * calling this method -- or no callbacks will received.</p>
Andrew Harp94927df2009-10-20 01:47:05 -0400819 *
Eino-Ville Talvala108708b2012-03-05 11:00:43 -0800820 * <p>The buffer queue will be cleared if this method is called with a null
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700821 * callback, {@link #setPreviewCallback(Camera.PreviewCallback)} is called,
Eino-Ville Talvala108708b2012-03-05 11:00:43 -0800822 * or {@link #setOneShotPreviewCallback(Camera.PreviewCallback)} is
823 * called.</p>
824 *
825 * <p>If you are using the preview data to create video or still images,
826 * strongly consider using {@link android.media.MediaActionSound} to
827 * properly indicate image capture or recording start/stop to the user.</p>
Andrew Harp94927df2009-10-20 01:47:05 -0400828 *
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700829 * @param cb a callback object that receives a copy of the preview frame,
830 * or null to stop receiving callbacks and clear the buffer queue.
831 * @see #addCallbackBuffer(byte[])
Eino-Ville Talvala108708b2012-03-05 11:00:43 -0800832 * @see android.media.MediaActionSound
Andrew Harp94927df2009-10-20 01:47:05 -0400833 */
834 public final void setPreviewCallbackWithBuffer(PreviewCallback cb) {
835 mPreviewCallback = cb;
836 mOneShot = false;
837 mWithBuffer = true;
Eino-Ville Talvala7005b672013-04-02 15:46:38 -0700838 if (cb != null) {
839 mUsingPreviewAllocation = false;
840 }
Andrew Harp94927df2009-10-20 01:47:05 -0400841 setHasPreviewCallback(cb != null, true);
842 }
843
844 /**
Wu-cheng Li3f4639a2010-04-04 15:05:41 +0800845 * Adds a pre-allocated buffer to the preview callback buffer queue.
846 * Applications can add one or more buffers to the queue. When a preview
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700847 * frame arrives and there is still at least one available buffer, the
848 * buffer will be used and removed from the queue. Then preview callback is
849 * invoked with the buffer. If a frame arrives and there is no buffer left,
850 * the frame is discarded. Applications should add buffers back when they
851 * finish processing the data in them.
Wu-cheng Lic10275a2010-03-09 13:49:21 -0800852 *
Eino-Ville Talvala95151632012-05-02 16:21:18 -0700853 * <p>For formats besides YV12, the size of the buffer is determined by
854 * multiplying the preview image width, height, and bytes per pixel. The
855 * width and height can be read from
856 * {@link Camera.Parameters#getPreviewSize()}. Bytes per pixel can be
857 * computed from {@link android.graphics.ImageFormat#getBitsPerPixel(int)} /
858 * 8, using the image format from
859 * {@link Camera.Parameters#getPreviewFormat()}.
860 *
861 * <p>If using the {@link android.graphics.ImageFormat#YV12} format, the
862 * size can be calculated using the equations listed in
863 * {@link Camera.Parameters#setPreviewFormat}.
Andrew Harp94927df2009-10-20 01:47:05 -0400864 *
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700865 * <p>This method is only necessary when
James Donge00cab72011-02-17 16:38:06 -0800866 * {@link #setPreviewCallbackWithBuffer(PreviewCallback)} is used. When
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700867 * {@link #setPreviewCallback(PreviewCallback)} or
868 * {@link #setOneShotPreviewCallback(PreviewCallback)} are used, buffers
James Donge00cab72011-02-17 16:38:06 -0800869 * are automatically allocated. When a supplied buffer is too small to
870 * hold the preview frame data, preview callback will return null and
871 * the buffer will be removed from the buffer queue.
Andrew Harp94927df2009-10-20 01:47:05 -0400872 *
Eino-Ville Talvala95151632012-05-02 16:21:18 -0700873 * @param callbackBuffer the buffer to add to the queue. The size of the
874 * buffer must match the values described above.
Wu-cheng Li5b9bcda2010-03-07 14:59:28 -0800875 * @see #setPreviewCallbackWithBuffer(PreviewCallback)
Andrew Harp94927df2009-10-20 01:47:05 -0400876 */
James Donge00cab72011-02-17 16:38:06 -0800877 public final void addCallbackBuffer(byte[] callbackBuffer)
878 {
879 _addCallbackBuffer(callbackBuffer, CAMERA_MSG_PREVIEW_FRAME);
880 }
881
882 /**
883 * Adds a pre-allocated buffer to the raw image callback buffer queue.
884 * Applications can add one or more buffers to the queue. When a raw image
885 * frame arrives and there is still at least one available buffer, the
886 * buffer will be used to hold the raw image data and removed from the
887 * queue. Then raw image callback is invoked with the buffer. If a raw
888 * image frame arrives but there is no buffer left, the frame is
889 * discarded. Applications should add buffers back when they finish
890 * processing the data in them by calling this method again in order
891 * to avoid running out of raw image callback buffers.
892 *
893 * <p>The size of the buffer is determined by multiplying the raw image
894 * width, height, and bytes per pixel. The width and height can be
895 * read from {@link Camera.Parameters#getPictureSize()}. Bytes per pixel
896 * can be computed from
897 * {@link android.graphics.ImageFormat#getBitsPerPixel(int)} / 8,
898 * using the image format from {@link Camera.Parameters#getPreviewFormat()}.
899 *
900 * <p>This method is only necessary when the PictureCallbck for raw image
901 * is used while calling {@link #takePicture(Camera.ShutterCallback,
902 * Camera.PictureCallback, Camera.PictureCallback, Camera.PictureCallback)}.
903 *
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -0700904 * <p>Please note that by calling this method, the mode for
905 * application-managed callback buffers is triggered. If this method has
906 * never been called, null will be returned by the raw image callback since
907 * there is no image callback buffer available. Furthermore, When a supplied
908 * buffer is too small to hold the raw image data, raw image callback will
909 * return null and the buffer will be removed from the buffer queue.
James Donge00cab72011-02-17 16:38:06 -0800910 *
911 * @param callbackBuffer the buffer to add to the raw image callback buffer
912 * queue. The size should be width * height * (bits per pixel) / 8. An
913 * null callbackBuffer will be ignored and won't be added to the queue.
914 *
915 * @see #takePicture(Camera.ShutterCallback,
916 * Camera.PictureCallback, Camera.PictureCallback, Camera.PictureCallback)}.
917 *
918 * {@hide}
919 */
920 public final void addRawImageCallbackBuffer(byte[] callbackBuffer)
921 {
922 addCallbackBuffer(callbackBuffer, CAMERA_MSG_RAW_IMAGE);
923 }
924
925 private final void addCallbackBuffer(byte[] callbackBuffer, int msgType)
926 {
927 // CAMERA_MSG_VIDEO_FRAME may be allowed in the future.
928 if (msgType != CAMERA_MSG_PREVIEW_FRAME &&
929 msgType != CAMERA_MSG_RAW_IMAGE) {
930 throw new IllegalArgumentException(
931 "Unsupported message type: " + msgType);
932 }
933
934 _addCallbackBuffer(callbackBuffer, msgType);
935 }
936
937 private native final void _addCallbackBuffer(
938 byte[] callbackBuffer, int msgType);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800939
Eino-Ville Talvala7005b672013-04-02 15:46:38 -0700940 /**
941 * <p>Create a {@link android.renderscript RenderScript}
942 * {@link android.renderscript.Allocation Allocation} to use as a
943 * destination of preview callback frames. Use
944 * {@link #setPreviewCallbackAllocation setPreviewCallbackAllocation} to use
945 * the created Allocation as a destination for camera preview frames.</p>
946 *
947 * <p>The Allocation will be created with a YUV type, and its contents must
948 * be accessed within Renderscript with the {@code rsGetElementAtYuv_*}
949 * accessor methods. Its size will be based on the current
950 * {@link Parameters#getPreviewSize preview size} configured for this
951 * camera.</p>
952 *
953 * @param rs the RenderScript context for this Allocation.
954 * @param usage additional usage flags to set for the Allocation. The usage
955 * flag {@link android.renderscript.Allocation#USAGE_IO_INPUT} will always
956 * be set on the created Allocation, but additional flags may be provided
957 * here.
958 * @return a new YUV-type Allocation with dimensions equal to the current
959 * preview size.
960 * @throws RSIllegalArgumentException if the usage flags are not compatible
961 * with an YUV Allocation.
962 * @see #setPreviewCallbackAllocation
963 * @hide
964 */
965 public final Allocation createPreviewAllocation(RenderScript rs, int usage)
966 throws RSIllegalArgumentException {
967 Parameters p = getParameters();
968 Size previewSize = p.getPreviewSize();
969 Type.Builder yuvBuilder = new Type.Builder(rs,
970 Element.createPixel(rs,
971 Element.DataType.UNSIGNED_8,
972 Element.DataKind.PIXEL_YUV));
973 // Use YV12 for wide compatibility. Changing this requires also
974 // adjusting camera service's format selection.
975 yuvBuilder.setYuvFormat(ImageFormat.YV12);
976 yuvBuilder.setX(previewSize.width);
977 yuvBuilder.setY(previewSize.height);
978
979 Allocation a = Allocation.createTyped(rs, yuvBuilder.create(),
980 usage | Allocation.USAGE_IO_INPUT);
981
982 return a;
983 }
984
985 /**
986 * <p>Set an {@link android.renderscript.Allocation Allocation} as the
987 * target of preview callback data. Use this method for efficient processing
988 * of camera preview data with RenderScript. The Allocation must be created
989 * with the {@link #createPreviewAllocation createPreviewAllocation }
990 * method.</p>
991 *
992 * <p>Setting a preview allocation will disable any active preview callbacks
993 * set by {@link #setPreviewCallback setPreviewCallback} or
994 * {@link #setPreviewCallbackWithBuffer setPreviewCallbackWithBuffer}, and
995 * vice versa. Using a preview allocation still requires an active standard
996 * preview target to be set, either with
997 * {@link #setPreviewTexture setPreviewTexture} or
998 * {@link #setPreviewDisplay setPreviewDisplay}.</p>
999 *
1000 * <p>To be notified when new frames are available to the Allocation, use
1001 * {@link android.renderscript.Allocation#setIoInputNotificationHandler Allocation.setIoInputNotificationHandler}. To
1002 * update the frame currently accessible from the Allocation to the latest
1003 * preview frame, call
1004 * {@link android.renderscript.Allocation#ioReceive Allocation.ioReceive}.</p>
1005 *
1006 * <p>To disable preview into the Allocation, call this method with a
1007 * {@code null} parameter.</p>
1008 *
1009 * <p>Once a preview allocation is set, the preview size set by
1010 * {@link Parameters#setPreviewSize setPreviewSize} cannot be changed. If
1011 * you wish to change the preview size, first remove the preview allocation
1012 * by calling {@code setPreviewCallbackAllocation(null)}, then change the
1013 * preview size, create a new preview Allocation with
1014 * {@link #createPreviewAllocation createPreviewAllocation}, and set it as
1015 * the new preview callback allocation target.</p>
1016 *
1017 * <p>If you are using the preview data to create video or still images,
1018 * strongly consider using {@link android.media.MediaActionSound} to
1019 * properly indicate image capture or recording start/stop to the user.</p>
1020 *
1021 * @param previewAllocation the allocation to use as destination for preview
1022 * @throws IOException if configuring the camera to use the Allocation for
1023 * preview fails.
1024 * @throws IllegalArgumentException if the Allocation's dimensions or other
1025 * parameters don't meet the requirements.
1026 * @see #createPreviewAllocation
1027 * @see #setPreviewCallback
1028 * @see #setPreviewCallbackWithBuffer
1029 * @hide
1030 */
1031 public final void setPreviewCallbackAllocation(Allocation previewAllocation)
1032 throws IOException {
1033 Surface previewSurface = null;
1034 if (previewAllocation != null) {
1035 Parameters p = getParameters();
1036 Size previewSize = p.getPreviewSize();
1037 if (previewSize.width != previewAllocation.getType().getX() ||
1038 previewSize.height != previewAllocation.getType().getY()) {
1039 throw new IllegalArgumentException(
1040 "Allocation dimensions don't match preview dimensions: " +
1041 "Allocation is " +
1042 previewAllocation.getType().getX() +
1043 ", " +
1044 previewAllocation.getType().getY() +
1045 ". Preview is " + previewSize.width + ", " +
1046 previewSize.height);
1047 }
1048 if ((previewAllocation.getUsage() &
1049 Allocation.USAGE_IO_INPUT) == 0) {
1050 throw new IllegalArgumentException(
1051 "Allocation usage does not include USAGE_IO_INPUT");
1052 }
1053 if (previewAllocation.getType().getElement().getDataKind() !=
1054 Element.DataKind.PIXEL_YUV) {
1055 throw new IllegalArgumentException(
1056 "Allocation is not of a YUV type");
1057 }
1058 previewSurface = previewAllocation.getSurface();
1059 mUsingPreviewAllocation = true;
1060 } else {
1061 mUsingPreviewAllocation = false;
1062 }
1063 setPreviewCallbackSurface(previewSurface);
1064 }
1065
1066 private native final void setPreviewCallbackSurface(Surface s);
1067
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001068 private class EventHandler extends Handler
1069 {
Igor Murashkina1d66272014-06-20 11:22:11 -07001070 private final Camera mCamera;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001071
1072 public EventHandler(Camera c, Looper looper) {
1073 super(looper);
1074 mCamera = c;
1075 }
1076
1077 @Override
1078 public void handleMessage(Message msg) {
1079 switch(msg.what) {
Dave Sparksc62f9bd2009-06-26 13:33:32 -07001080 case CAMERA_MSG_SHUTTER:
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001081 if (mShutterCallback != null) {
1082 mShutterCallback.onShutter();
1083 }
1084 return;
Dave Sparksc62f9bd2009-06-26 13:33:32 -07001085
1086 case CAMERA_MSG_RAW_IMAGE:
Dave Sparkse8b26e12009-07-14 10:35:40 -07001087 if (mRawImageCallback != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001088 mRawImageCallback.onPictureTaken((byte[])msg.obj, mCamera);
Dave Sparkse8b26e12009-07-14 10:35:40 -07001089 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001090 return;
1091
Dave Sparksc62f9bd2009-06-26 13:33:32 -07001092 case CAMERA_MSG_COMPRESSED_IMAGE:
Dave Sparkse8b26e12009-07-14 10:35:40 -07001093 if (mJpegCallback != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001094 mJpegCallback.onPictureTaken((byte[])msg.obj, mCamera);
Dave Sparkse8b26e12009-07-14 10:35:40 -07001095 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001096 return;
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001097
Dave Sparksc62f9bd2009-06-26 13:33:32 -07001098 case CAMERA_MSG_PREVIEW_FRAME:
Eino-Ville Talvalaca367b72012-05-30 16:01:33 -07001099 PreviewCallback pCb = mPreviewCallback;
1100 if (pCb != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001101 if (mOneShot) {
Dave Sparksa6118c62009-10-13 02:28:54 -07001102 // Clear the callback variable before the callback
1103 // in case the app calls setPreviewCallback from
1104 // the callback function
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001105 mPreviewCallback = null;
Andrew Harp94927df2009-10-20 01:47:05 -04001106 } else if (!mWithBuffer) {
Dave Sparksa6118c62009-10-13 02:28:54 -07001107 // We're faking the camera preview mode to prevent
1108 // the app from being flooded with preview frames.
1109 // Set to oneshot mode again.
Andrew Harp94927df2009-10-20 01:47:05 -04001110 setHasPreviewCallback(true, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001111 }
Eino-Ville Talvalaca367b72012-05-30 16:01:33 -07001112 pCb.onPreviewFrame((byte[])msg.obj, mCamera);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001113 }
1114 return;
1115
Dave Sparkse8b26e12009-07-14 10:35:40 -07001116 case CAMERA_MSG_POSTVIEW_FRAME:
1117 if (mPostviewCallback != null) {
1118 mPostviewCallback.onPictureTaken((byte[])msg.obj, mCamera);
1119 }
1120 return;
1121
Dave Sparksc62f9bd2009-06-26 13:33:32 -07001122 case CAMERA_MSG_FOCUS:
Wu-cheng Lif05c1d62012-05-02 23:29:47 +08001123 AutoFocusCallback cb = null;
1124 synchronized (mAutoFocusCallbackLock) {
1125 cb = mAutoFocusCallback;
1126 }
1127 if (cb != null) {
1128 boolean success = msg.arg1 == 0 ? false : true;
1129 cb.onAutoFocus(success, mCamera);
Dave Sparkse8b26e12009-07-14 10:35:40 -07001130 }
1131 return;
1132
1133 case CAMERA_MSG_ZOOM:
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08001134 if (mZoomListener != null) {
1135 mZoomListener.onZoomChange(msg.arg1, msg.arg2 != 0, mCamera);
Dave Sparkse8b26e12009-07-14 10:35:40 -07001136 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001137 return;
1138
Wu-cheng Libb1e2752011-07-30 05:00:37 +08001139 case CAMERA_MSG_PREVIEW_METADATA:
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08001140 if (mFaceListener != null) {
Wu-cheng Lif0d6a482011-07-28 05:30:59 +08001141 mFaceListener.onFaceDetection((Face[])msg.obj, mCamera);
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08001142 }
1143 return;
1144
Dave Sparksc62f9bd2009-06-26 13:33:32 -07001145 case CAMERA_MSG_ERROR :
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001146 Log.e(TAG, "Error " + msg.arg1);
Dave Sparkse8b26e12009-07-14 10:35:40 -07001147 if (mErrorCallback != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001148 mErrorCallback.onError(msg.arg1, mCamera);
Dave Sparkse8b26e12009-07-14 10:35:40 -07001149 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001150 return;
1151
Wu-cheng Li9d062cf2011-11-14 20:30:14 +08001152 case CAMERA_MSG_FOCUS_MOVE:
1153 if (mAutoFocusMoveCallback != null) {
1154 mAutoFocusMoveCallback.onAutoFocusMoving(msg.arg1 == 0 ? false : true, mCamera);
1155 }
1156 return;
1157
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001158 default:
1159 Log.e(TAG, "Unknown message type " + msg.what);
1160 return;
1161 }
1162 }
1163 }
1164
1165 private static void postEventFromNative(Object camera_ref,
1166 int what, int arg1, int arg2, Object obj)
1167 {
1168 Camera c = (Camera)((WeakReference)camera_ref).get();
1169 if (c == null)
1170 return;
1171
1172 if (c.mEventHandler != null) {
1173 Message m = c.mEventHandler.obtainMessage(what, arg1, arg2, obj);
1174 c.mEventHandler.sendMessage(m);
1175 }
1176 }
1177
1178 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -07001179 * Callback interface used to notify on completion of camera auto focus.
1180 *
Wu-cheng Li7478ea62009-09-16 18:52:55 +08001181 * <p>Devices that do not support auto-focus will receive a "fake"
1182 * callback to this interface. If your application needs auto-focus and
Scott Maindf4578e2009-09-10 12:22:07 -07001183 * should not be installed on devices <em>without</em> auto-focus, you must
1184 * declare that your app uses the
Wu-cheng Li7478ea62009-09-16 18:52:55 +08001185 * {@code android.hardware.camera.autofocus} feature, in the
Scott Maindf4578e2009-09-10 12:22:07 -07001186 * <a href="{@docRoot}guide/topics/manifest/uses-feature-element.html">&lt;uses-feature></a>
1187 * manifest element.</p>
Dan Egnorbfcbeff2010-07-12 15:12:54 -07001188 *
1189 * @see #autoFocus(AutoFocusCallback)
Eino-Ville Talvalab942b052014-07-10 17:45:03 -07001190 * @deprecated We recommend using the new {@link android.hardware.camera2} API for new
1191 * applications.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001192 */
Eino-Ville Talvalab942b052014-07-10 17:45:03 -07001193 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001194 public interface AutoFocusCallback
1195 {
1196 /**
Brad Fitzpatrick69ea4e12011-01-05 11:13:40 -08001197 * Called when the camera auto focus completes. If the camera
1198 * does not support auto-focus and autoFocus is called,
1199 * onAutoFocus will be called immediately with a fake value of
1200 * <code>success</code> set to <code>true</code>.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001201 *
Wu-cheng Lib4f95be2011-09-22 11:43:28 +08001202 * The auto-focus routine does not lock auto-exposure and auto-white
1203 * balance after it completes.
Eino-Ville Talvala83d33522011-05-13 10:25:00 -07001204 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001205 * @param success true if focus was successful, false if otherwise
1206 * @param camera the Camera service object
Eino-Ville Talvala83d33522011-05-13 10:25:00 -07001207 * @see android.hardware.Camera.Parameters#setAutoExposureLock(boolean)
1208 * @see android.hardware.Camera.Parameters#setAutoWhiteBalanceLock(boolean)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001209 */
1210 void onAutoFocus(boolean success, Camera camera);
Wu-cheng Li53b30912011-10-12 19:43:51 +08001211 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001212
1213 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -07001214 * Starts camera auto-focus and registers a callback function to run when
1215 * the camera is focused. This method is only valid when preview is active
1216 * (between {@link #startPreview()} and before {@link #stopPreview()}).
1217 *
1218 * <p>Callers should check
1219 * {@link android.hardware.Camera.Parameters#getFocusMode()} to determine if
1220 * this method should be called. If the camera does not support auto-focus,
1221 * it is a no-op and {@link AutoFocusCallback#onAutoFocus(boolean, Camera)}
Wu-cheng Li36322db2009-09-18 18:59:21 +08001222 * callback will be called immediately.
Dan Egnorbfcbeff2010-07-12 15:12:54 -07001223 *
Scott Mainda0a56d2009-09-10 18:08:37 -07001224 * <p>If your application should not be installed
Wu-cheng Li7478ea62009-09-16 18:52:55 +08001225 * on devices without auto-focus, you must declare that your application
1226 * uses auto-focus with the
Scott Maindf4578e2009-09-10 12:22:07 -07001227 * <a href="{@docRoot}guide/topics/manifest/uses-feature-element.html">&lt;uses-feature></a>
1228 * manifest element.</p>
Dan Egnorbfcbeff2010-07-12 15:12:54 -07001229 *
Wu-cheng Li068ef422009-09-27 13:19:36 -07001230 * <p>If the current flash mode is not
1231 * {@link android.hardware.Camera.Parameters#FLASH_MODE_OFF}, flash may be
Dan Egnorbfcbeff2010-07-12 15:12:54 -07001232 * fired during auto-focus, depending on the driver and camera hardware.<p>
Wu-cheng Li7478ea62009-09-16 18:52:55 +08001233 *
Wu-cheng Li53b30912011-10-12 19:43:51 +08001234 * <p>Auto-exposure lock {@link android.hardware.Camera.Parameters#getAutoExposureLock()}
Wu-cheng Lib4f95be2011-09-22 11:43:28 +08001235 * and auto-white balance locks {@link android.hardware.Camera.Parameters#getAutoWhiteBalanceLock()}
1236 * do not change during and after autofocus. But auto-focus routine may stop
1237 * auto-exposure and auto-white balance transiently during focusing.
Eino-Ville Talvala83d33522011-05-13 10:25:00 -07001238 *
Wu-cheng Li53b30912011-10-12 19:43:51 +08001239 * <p>Stopping preview with {@link #stopPreview()}, or triggering still
1240 * image capture with {@link #takePicture(Camera.ShutterCallback,
1241 * Camera.PictureCallback, Camera.PictureCallback)}, will not change the
1242 * the focus position. Applications must call cancelAutoFocus to reset the
1243 * focus.</p>
1244 *
Eino-Ville Talvala108708b2012-03-05 11:00:43 -08001245 * <p>If autofocus is successful, consider using
1246 * {@link android.media.MediaActionSound} to properly play back an autofocus
1247 * success sound to the user.</p>
1248 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001249 * @param cb the callback to run
Dan Egnorbfcbeff2010-07-12 15:12:54 -07001250 * @see #cancelAutoFocus()
Eino-Ville Talvala83d33522011-05-13 10:25:00 -07001251 * @see android.hardware.Camera.Parameters#setAutoExposureLock(boolean)
1252 * @see android.hardware.Camera.Parameters#setAutoWhiteBalanceLock(boolean)
Eino-Ville Talvala108708b2012-03-05 11:00:43 -08001253 * @see android.media.MediaActionSound
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001254 */
1255 public final void autoFocus(AutoFocusCallback cb)
1256 {
Wu-cheng Lif05c1d62012-05-02 23:29:47 +08001257 synchronized (mAutoFocusCallbackLock) {
James Dong248ba232012-04-28 21:30:46 -07001258 mAutoFocusCallback = cb;
James Dong248ba232012-04-28 21:30:46 -07001259 }
Wu-cheng Lif05c1d62012-05-02 23:29:47 +08001260 native_autoFocus();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001261 }
1262 private native final void native_autoFocus();
1263
1264 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -07001265 * Cancels any auto-focus function in progress.
1266 * Whether or not auto-focus is currently in progress,
1267 * this function will return the focus position to the default.
Chih-Chung Chang244f8c22009-09-15 14:51:56 +08001268 * If the camera does not support auto-focus, this is a no-op.
Dan Egnorbfcbeff2010-07-12 15:12:54 -07001269 *
1270 * @see #autoFocus(Camera.AutoFocusCallback)
Chih-Chung Chang244f8c22009-09-15 14:51:56 +08001271 */
1272 public final void cancelAutoFocus()
1273 {
Wu-cheng Lif05c1d62012-05-02 23:29:47 +08001274 synchronized (mAutoFocusCallbackLock) {
James Dong248ba232012-04-28 21:30:46 -07001275 mAutoFocusCallback = null;
James Dong248ba232012-04-28 21:30:46 -07001276 }
Wu-cheng Lif05c1d62012-05-02 23:29:47 +08001277 native_cancelAutoFocus();
1278 // CAMERA_MSG_FOCUS should be removed here because the following
1279 // scenario can happen:
1280 // - An application uses the same thread for autoFocus, cancelAutoFocus
1281 // and looper thread.
1282 // - The application calls autoFocus.
1283 // - HAL sends CAMERA_MSG_FOCUS, which enters the looper message queue.
1284 // Before event handler's handleMessage() is invoked, the application
1285 // calls cancelAutoFocus and autoFocus.
1286 // - The application gets the old CAMERA_MSG_FOCUS and thinks autofocus
1287 // has been completed. But in fact it is not.
1288 //
1289 // As documented in the beginning of the file, apps should not use
1290 // multiple threads to call autoFocus and cancelAutoFocus at the same
1291 // time. It is HAL's responsibility not to send a CAMERA_MSG_FOCUS
1292 // message after native_cancelAutoFocus is called.
1293 mEventHandler.removeMessages(CAMERA_MSG_FOCUS);
Chih-Chung Chang244f8c22009-09-15 14:51:56 +08001294 }
1295 private native final void native_cancelAutoFocus();
1296
1297 /**
Wu-cheng Li9d062cf2011-11-14 20:30:14 +08001298 * Callback interface used to notify on auto focus start and stop.
1299 *
Wu-cheng Li65745392012-04-12 18:07:16 +08001300 * <p>This is only supported in continuous autofocus modes -- {@link
1301 * Parameters#FOCUS_MODE_CONTINUOUS_VIDEO} and {@link
1302 * Parameters#FOCUS_MODE_CONTINUOUS_PICTURE}. Applications can show
1303 * autofocus animation based on this.</p>
Eino-Ville Talvalab942b052014-07-10 17:45:03 -07001304 *
1305 * @deprecated We recommend using the new {@link android.hardware.camera2} API for new
1306 * applications.
Wu-cheng Li9d062cf2011-11-14 20:30:14 +08001307 */
Eino-Ville Talvalab942b052014-07-10 17:45:03 -07001308 @Deprecated
Wu-cheng Li9d062cf2011-11-14 20:30:14 +08001309 public interface AutoFocusMoveCallback
1310 {
1311 /**
1312 * Called when the camera auto focus starts or stops.
1313 *
1314 * @param start true if focus starts to move, false if focus stops to move
Wu-cheng Li65745392012-04-12 18:07:16 +08001315 * @param camera the Camera service object
Wu-cheng Li9d062cf2011-11-14 20:30:14 +08001316 */
1317 void onAutoFocusMoving(boolean start, Camera camera);
1318 }
1319
1320 /**
1321 * Sets camera auto-focus move callback.
1322 *
1323 * @param cb the callback to run
Wu-cheng Li9d062cf2011-11-14 20:30:14 +08001324 */
1325 public void setAutoFocusMoveCallback(AutoFocusMoveCallback cb) {
1326 mAutoFocusMoveCallback = cb;
1327 enableFocusMoveCallback((mAutoFocusMoveCallback != null) ? 1 : 0);
1328 }
1329
1330 private native void enableFocusMoveCallback(int enable);
1331
1332 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -07001333 * Callback interface used to signal the moment of actual image capture.
1334 *
1335 * @see #takePicture(ShutterCallback, PictureCallback, PictureCallback, PictureCallback)
Eino-Ville Talvalab942b052014-07-10 17:45:03 -07001336 *
1337 * @deprecated We recommend using the new {@link android.hardware.camera2} API for new
1338 * applications.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001339 */
Eino-Ville Talvalab942b052014-07-10 17:45:03 -07001340 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001341 public interface ShutterCallback
1342 {
1343 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -07001344 * Called as near as possible to the moment when a photo is captured
1345 * from the sensor. This is a good opportunity to play a shutter sound
1346 * or give other feedback of camera operation. This may be some time
1347 * after the photo was triggered, but some time before the actual data
1348 * is available.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001349 */
1350 void onShutter();
1351 }
1352
1353 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -07001354 * Callback interface used to supply image data from a photo capture.
1355 *
1356 * @see #takePicture(ShutterCallback, PictureCallback, PictureCallback, PictureCallback)
Eino-Ville Talvalab942b052014-07-10 17:45:03 -07001357 *
1358 * @deprecated We recommend using the new {@link android.hardware.camera2} API for new
1359 * applications.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001360 */
Eino-Ville Talvalab942b052014-07-10 17:45:03 -07001361 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001362 public interface PictureCallback {
1363 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -07001364 * Called when image data is available after a picture is taken.
1365 * The format of the data depends on the context of the callback
1366 * and {@link Camera.Parameters} settings.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001367 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001368 * @param data a byte array of the picture data
1369 * @param camera the Camera service object
1370 */
1371 void onPictureTaken(byte[] data, Camera camera);
1372 };
1373
1374 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -07001375 * Equivalent to takePicture(shutter, raw, null, jpeg).
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001376 *
Dan Egnorbfcbeff2010-07-12 15:12:54 -07001377 * @see #takePicture(ShutterCallback, PictureCallback, PictureCallback, PictureCallback)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001378 */
1379 public final void takePicture(ShutterCallback shutter, PictureCallback raw,
1380 PictureCallback jpeg) {
Dave Sparkse8b26e12009-07-14 10:35:40 -07001381 takePicture(shutter, raw, null, jpeg);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001382 }
James Donge00cab72011-02-17 16:38:06 -08001383 private native final void native_takePicture(int msgType);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001384
Dave Sparkse8b26e12009-07-14 10:35:40 -07001385 /**
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001386 * Triggers an asynchronous image capture. The camera service will initiate
1387 * a series of callbacks to the application as the image capture progresses.
1388 * The shutter callback occurs after the image is captured. This can be used
1389 * to trigger a sound to let the user know that image has been captured. The
1390 * raw callback occurs when the raw image data is available (NOTE: the data
James Donge00cab72011-02-17 16:38:06 -08001391 * will be null if there is no raw image callback buffer available or the
1392 * raw image callback buffer is not large enough to hold the raw image).
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001393 * The postview callback occurs when a scaled, fully processed postview
1394 * image is available (NOTE: not all hardware supports this). The jpeg
1395 * callback occurs when the compressed image is available. If the
1396 * application does not need a particular callback, a null can be passed
1397 * instead of a callback method.
Dave Sparkse8b26e12009-07-14 10:35:40 -07001398 *
Dan Egnorbfcbeff2010-07-12 15:12:54 -07001399 * <p>This method is only valid when preview is active (after
1400 * {@link #startPreview()}). Preview will be stopped after the image is
1401 * taken; callers must call {@link #startPreview()} again if they want to
Wu-cheng Li42419ce2011-06-01 17:22:24 +08001402 * re-start preview or take more pictures. This should not be called between
1403 * {@link android.media.MediaRecorder#start()} and
1404 * {@link android.media.MediaRecorder#stop()}.
Wu-cheng Li40057ce2009-12-02 18:57:29 +08001405 *
Dan Egnorbfcbeff2010-07-12 15:12:54 -07001406 * <p>After calling this method, you must not call {@link #startPreview()}
1407 * or take another picture until the JPEG callback has returned.
1408 *
1409 * @param shutter the callback for image capture moment, or null
1410 * @param raw the callback for raw (uncompressed) image data, or null
Dave Sparkse8b26e12009-07-14 10:35:40 -07001411 * @param postview callback with postview image data, may be null
Dan Egnorbfcbeff2010-07-12 15:12:54 -07001412 * @param jpeg the callback for JPEG image data, or null
Dave Sparkse8b26e12009-07-14 10:35:40 -07001413 */
1414 public final void takePicture(ShutterCallback shutter, PictureCallback raw,
1415 PictureCallback postview, PictureCallback jpeg) {
1416 mShutterCallback = shutter;
1417 mRawImageCallback = raw;
1418 mPostviewCallback = postview;
1419 mJpegCallback = jpeg;
James Donge00cab72011-02-17 16:38:06 -08001420
1421 // If callback is not set, do not send me callbacks.
1422 int msgType = 0;
1423 if (mShutterCallback != null) {
1424 msgType |= CAMERA_MSG_SHUTTER;
1425 }
1426 if (mRawImageCallback != null) {
1427 msgType |= CAMERA_MSG_RAW_IMAGE;
1428 }
1429 if (mPostviewCallback != null) {
1430 msgType |= CAMERA_MSG_POSTVIEW_FRAME;
1431 }
1432 if (mJpegCallback != null) {
1433 msgType |= CAMERA_MSG_COMPRESSED_IMAGE;
1434 }
1435
1436 native_takePicture(msgType);
Wu-cheng Lie9c6c9c2012-05-29 16:47:44 +08001437 mFaceDetectionRunning = false;
Dave Sparkse8b26e12009-07-14 10:35:40 -07001438 }
1439
1440 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -07001441 * Zooms to the requested value smoothly. The driver will notify {@link
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08001442 * OnZoomChangeListener} of the zoom value and whether zoom is stopped at
1443 * the time. For example, suppose the current zoom is 0 and startSmoothZoom
Dan Egnorbfcbeff2010-07-12 15:12:54 -07001444 * is called with value 3. The
1445 * {@link Camera.OnZoomChangeListener#onZoomChange(int, boolean, Camera)}
1446 * method will be called three times with zoom values 1, 2, and 3.
1447 * Applications can call {@link #stopSmoothZoom} to stop the zoom earlier.
1448 * Applications should not call startSmoothZoom again or change the zoom
1449 * value before zoom stops. If the supplied zoom value equals to the current
1450 * zoom value, no zoom callback will be generated. This method is supported
1451 * if {@link android.hardware.Camera.Parameters#isSmoothZoomSupported}
1452 * returns true.
Wu-cheng Li36f68b82009-09-28 16:14:58 -07001453 *
1454 * @param value zoom value. The valid range is 0 to {@link
1455 * android.hardware.Camera.Parameters#getMaxZoom}.
Wu-cheng Li0ca25192010-03-29 16:21:12 +08001456 * @throws IllegalArgumentException if the zoom value is invalid.
1457 * @throws RuntimeException if the method fails.
Dan Egnorbfcbeff2010-07-12 15:12:54 -07001458 * @see #setZoomChangeListener(OnZoomChangeListener)
Wu-cheng Li36f68b82009-09-28 16:14:58 -07001459 */
1460 public native final void startSmoothZoom(int value);
1461
1462 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -07001463 * Stops the smooth zoom. Applications should wait for the {@link
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08001464 * OnZoomChangeListener} to know when the zoom is actually stopped. This
1465 * method is supported if {@link
Wu-cheng Li8cbb8f52010-02-28 23:19:55 -08001466 * android.hardware.Camera.Parameters#isSmoothZoomSupported} is true.
Wu-cheng Li0ca25192010-03-29 16:21:12 +08001467 *
1468 * @throws RuntimeException if the method fails.
Wu-cheng Li36f68b82009-09-28 16:14:58 -07001469 */
1470 public native final void stopSmoothZoom();
1471
1472 /**
Wu-cheng Li2fe6fca2010-10-15 14:42:23 +08001473 * Set the clockwise rotation of preview display in degrees. This affects
1474 * the preview frames and the picture displayed after snapshot. This method
1475 * is useful for portrait mode applications. Note that preview display of
Wu-cheng Lib982fb42010-10-19 17:19:09 +08001476 * front-facing cameras is flipped horizontally before the rotation, that
1477 * is, the image is reflected along the central vertical axis of the camera
1478 * sensor. So the users can see themselves as looking into a mirror.
Chih-Chung Changd1d77062010-01-22 17:49:48 -08001479 *
Brad Fitzpatrick69ea4e12011-01-05 11:13:40 -08001480 * <p>This does not affect the order of byte array passed in {@link
Wu-cheng Li2fe6fca2010-10-15 14:42:23 +08001481 * PreviewCallback#onPreviewFrame}, JPEG pictures, or recorded videos. This
1482 * method is not allowed to be called during preview.
Chih-Chung Changd1d77062010-01-22 17:49:48 -08001483 *
Brad Fitzpatrick69ea4e12011-01-05 11:13:40 -08001484 * <p>If you want to make the camera image show in the same orientation as
1485 * the display, you can use the following code.
Chih-Chung Changb8bb78f2010-06-10 13:32:16 +08001486 * <pre>
Chih-Chung Chang724c5222010-06-14 18:57:15 +08001487 * public static void setCameraDisplayOrientation(Activity activity,
1488 * int cameraId, android.hardware.Camera camera) {
1489 * android.hardware.Camera.CameraInfo info =
1490 * new android.hardware.Camera.CameraInfo();
1491 * android.hardware.Camera.getCameraInfo(cameraId, info);
1492 * int rotation = activity.getWindowManager().getDefaultDisplay()
1493 * .getRotation();
1494 * int degrees = 0;
1495 * switch (rotation) {
1496 * case Surface.ROTATION_0: degrees = 0; break;
1497 * case Surface.ROTATION_90: degrees = 90; break;
1498 * case Surface.ROTATION_180: degrees = 180; break;
1499 * case Surface.ROTATION_270: degrees = 270; break;
1500 * }
Chih-Chung Changb8bb78f2010-06-10 13:32:16 +08001501 *
Wu-cheng Li2fe6fca2010-10-15 14:42:23 +08001502 * int result;
1503 * if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
1504 * result = (info.orientation + degrees) % 360;
1505 * result = (360 - result) % 360; // compensate the mirror
1506 * } else { // back-facing
1507 * result = (info.orientation - degrees + 360) % 360;
1508 * }
Chih-Chung Chang724c5222010-06-14 18:57:15 +08001509 * camera.setDisplayOrientation(result);
1510 * }
Chih-Chung Changb8bb78f2010-06-10 13:32:16 +08001511 * </pre>
Wu-cheng Lid3033622011-10-07 13:13:54 +08001512 *
1513 * <p>Starting from API level 14, this method can be called when preview is
1514 * active.
1515 *
Chih-Chung Changd1d77062010-01-22 17:49:48 -08001516 * @param degrees the angle that the picture will be rotated clockwise.
Chih-Chung Change7bd22a2010-01-27 10:24:42 -08001517 * Valid values are 0, 90, 180, and 270. The starting
1518 * position is 0 (landscape).
Wu-cheng Li2fe6fca2010-10-15 14:42:23 +08001519 * @see #setPreviewDisplay(SurfaceHolder)
Chih-Chung Changd1d77062010-01-22 17:49:48 -08001520 */
1521 public native final void setDisplayOrientation(int degrees);
1522
1523 /**
Eino-Ville Talvala487acdf2012-09-24 11:30:24 -07001524 * <p>Enable or disable the default shutter sound when taking a picture.</p>
Eino-Ville Talvala69fe5272012-09-07 12:26:40 -07001525 *
Eino-Ville Talvala487acdf2012-09-24 11:30:24 -07001526 * <p>By default, the camera plays the system-defined camera shutter sound
1527 * when {@link #takePicture} is called. Using this method, the shutter sound
1528 * can be disabled. It is strongly recommended that an alternative shutter
1529 * sound is played in the {@link ShutterCallback} when the system shutter
1530 * sound is disabled.</p>
Eino-Ville Talvala69fe5272012-09-07 12:26:40 -07001531 *
Eino-Ville Talvala487acdf2012-09-24 11:30:24 -07001532 * <p>Note that devices may not always allow disabling the camera shutter
1533 * sound. If the shutter sound state cannot be set to the desired value,
1534 * this method will return false. {@link CameraInfo#canDisableShutterSound}
1535 * can be used to determine whether the device will allow the shutter sound
1536 * to be disabled.</p>
Eino-Ville Talvala69fe5272012-09-07 12:26:40 -07001537 *
1538 * @param enabled whether the camera should play the system shutter sound
1539 * when {@link #takePicture takePicture} is called.
Eino-Ville Talvala487acdf2012-09-24 11:30:24 -07001540 * @return {@code true} if the shutter sound state was successfully
1541 * changed. {@code false} if the shutter sound state could not be
1542 * changed. {@code true} is also returned if shutter sound playback
1543 * is already set to the requested state.
Eino-Ville Talvala69fe5272012-09-07 12:26:40 -07001544 * @see #takePicture
Eino-Ville Talvala487acdf2012-09-24 11:30:24 -07001545 * @see CameraInfo#canDisableShutterSound
Eino-Ville Talvala69fe5272012-09-07 12:26:40 -07001546 * @see ShutterCallback
Eino-Ville Talvala69fe5272012-09-07 12:26:40 -07001547 */
Eino-Ville Talvala4f8e5ce2012-10-08 18:16:35 -07001548 public final boolean enableShutterSound(boolean enabled) {
1549 if (!enabled) {
1550 IBinder b = ServiceManager.getService(Context.AUDIO_SERVICE);
1551 IAudioService audioService = IAudioService.Stub.asInterface(b);
1552 try {
1553 if (audioService.isCameraSoundForced()) return false;
1554 } catch (RemoteException e) {
1555 Log.e(TAG, "Audio service is unavailable for queries");
1556 }
1557 }
1558 return _enableShutterSound(enabled);
1559 }
1560
1561 private native final boolean _enableShutterSound(boolean enabled);
Eino-Ville Talvala69fe5272012-09-07 12:26:40 -07001562
1563 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -07001564 * Callback interface for zoom changes during a smooth zoom operation.
1565 *
1566 * @see #setZoomChangeListener(OnZoomChangeListener)
1567 * @see #startSmoothZoom(int)
Eino-Ville Talvalab942b052014-07-10 17:45:03 -07001568 *
1569 * @deprecated We recommend using the new {@link android.hardware.camera2} API for new
1570 * applications.
Dave Sparkse8b26e12009-07-14 10:35:40 -07001571 */
Eino-Ville Talvalab942b052014-07-10 17:45:03 -07001572 @Deprecated
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08001573 public interface OnZoomChangeListener
Dave Sparkse8b26e12009-07-14 10:35:40 -07001574 {
1575 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -07001576 * Called when the zoom value has changed during a smooth zoom.
Wu-cheng Li36f68b82009-09-28 16:14:58 -07001577 *
1578 * @param zoomValue the current zoom value. In smooth zoom mode, camera
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08001579 * calls this for every new zoom value.
Wu-cheng Li36f68b82009-09-28 16:14:58 -07001580 * @param stopped whether smooth zoom is stopped. If the value is true,
1581 * this is the last zoom update for the application.
Dave Sparkse8b26e12009-07-14 10:35:40 -07001582 * @param camera the Camera service object
1583 */
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08001584 void onZoomChange(int zoomValue, boolean stopped, Camera camera);
Dave Sparkse8b26e12009-07-14 10:35:40 -07001585 };
1586
1587 /**
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08001588 * Registers a listener to be notified when the zoom value is updated by the
Wu-cheng Li36f68b82009-09-28 16:14:58 -07001589 * camera driver during smooth zoom.
Wu-cheng Li8cbb8f52010-02-28 23:19:55 -08001590 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08001591 * @param listener the listener to notify
Wu-cheng Li8cbb8f52010-02-28 23:19:55 -08001592 * @see #startSmoothZoom(int)
Dave Sparkse8b26e12009-07-14 10:35:40 -07001593 */
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08001594 public final void setZoomChangeListener(OnZoomChangeListener listener)
Dave Sparkse8b26e12009-07-14 10:35:40 -07001595 {
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08001596 mZoomListener = listener;
Dave Sparkse8b26e12009-07-14 10:35:40 -07001597 }
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001598
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08001599 /**
1600 * Callback interface for face detected in the preview frame.
1601 *
Eino-Ville Talvalab942b052014-07-10 17:45:03 -07001602 * @deprecated We recommend using the new {@link android.hardware.camera2} API for new
1603 * applications.
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08001604 */
Eino-Ville Talvalab942b052014-07-10 17:45:03 -07001605 @Deprecated
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08001606 public interface FaceDetectionListener
1607 {
1608 /**
1609 * Notify the listener of the detected faces in the preview frame.
1610 *
Wu-cheng Li53b30912011-10-12 19:43:51 +08001611 * @param faces The detected faces in a list
Joe Fernandez464cb212011-10-04 16:56:47 -07001612 * @param camera The {@link Camera} service object
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08001613 */
Wu-cheng Lif0d6a482011-07-28 05:30:59 +08001614 void onFaceDetection(Face[] faces, Camera camera);
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08001615 }
1616
1617 /**
Wu-cheng Lic0c683b2011-08-04 00:11:00 +08001618 * Registers a listener to be notified about the faces detected in the
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08001619 * preview frame.
1620 *
1621 * @param listener the listener to notify
Wu-cheng Lic0c683b2011-08-04 00:11:00 +08001622 * @see #startFaceDetection()
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08001623 */
1624 public final void setFaceDetectionListener(FaceDetectionListener listener)
1625 {
1626 mFaceListener = listener;
1627 }
1628
1629 /**
Wu-cheng Lic0c683b2011-08-04 00:11:00 +08001630 * Starts the face detection. This should be called after preview is started.
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08001631 * The camera will notify {@link FaceDetectionListener} of the detected
1632 * faces in the preview frame. The detected faces may be the same as the
1633 * previous ones. Applications should call {@link #stopFaceDetection} to
1634 * stop the face detection. This method is supported if {@link
Wu-cheng Lic0c683b2011-08-04 00:11:00 +08001635 * Parameters#getMaxNumDetectedFaces()} returns a number larger than 0.
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08001636 * If the face detection has started, apps should not call this again.
1637 *
Wu-cheng Li8c136702011-08-12 20:25:00 +08001638 * <p>When the face detection is running, {@link Parameters#setWhiteBalance(String)},
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08001639 * {@link Parameters#setFocusAreas(List)}, and {@link Parameters#setMeteringAreas(List)}
Wu-cheng Li8c136702011-08-12 20:25:00 +08001640 * have no effect. The camera uses the detected faces to do auto-white balance,
1641 * auto exposure, and autofocus.
1642 *
1643 * <p>If the apps call {@link #autoFocus(AutoFocusCallback)}, the camera
1644 * will stop sending face callbacks. The last face callback indicates the
1645 * areas used to do autofocus. After focus completes, face detection will
1646 * resume sending face callbacks. If the apps call {@link
1647 * #cancelAutoFocus()}, the face callbacks will also resume.</p>
1648 *
1649 * <p>After calling {@link #takePicture(Camera.ShutterCallback, Camera.PictureCallback,
1650 * Camera.PictureCallback)} or {@link #stopPreview()}, and then resuming
1651 * preview with {@link #startPreview()}, the apps should call this method
1652 * again to resume face detection.</p>
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08001653 *
Wu-cheng Lic0c683b2011-08-04 00:11:00 +08001654 * @throws IllegalArgumentException if the face detection is unsupported.
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08001655 * @throws RuntimeException if the method fails or the face detection is
1656 * already running.
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08001657 * @see FaceDetectionListener
1658 * @see #stopFaceDetection()
Wu-cheng Lic0c683b2011-08-04 00:11:00 +08001659 * @see Parameters#getMaxNumDetectedFaces()
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08001660 */
Wu-cheng Lic0c683b2011-08-04 00:11:00 +08001661 public final void startFaceDetection() {
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08001662 if (mFaceDetectionRunning) {
1663 throw new RuntimeException("Face detection is already running");
1664 }
Wu-cheng Lic0c683b2011-08-04 00:11:00 +08001665 _startFaceDetection(CAMERA_FACE_DETECTION_HW);
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08001666 mFaceDetectionRunning = true;
1667 }
1668
1669 /**
Wu-cheng Lic0c683b2011-08-04 00:11:00 +08001670 * Stops the face detection.
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08001671 *
Joe Fernandez464cb212011-10-04 16:56:47 -07001672 * @see #startFaceDetection()
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08001673 */
1674 public final void stopFaceDetection() {
1675 _stopFaceDetection();
1676 mFaceDetectionRunning = false;
1677 }
1678
1679 private native final void _startFaceDetection(int type);
1680 private native final void _stopFaceDetection();
1681
1682 /**
Joe Fernandez464cb212011-10-04 16:56:47 -07001683 * Information about a face identified through camera face detection.
Wu-cheng Li53b30912011-10-12 19:43:51 +08001684 *
Joe Fernandez464cb212011-10-04 16:56:47 -07001685 * <p>When face detection is used with a camera, the {@link FaceDetectionListener} returns a
1686 * list of face objects for use in focusing and metering.</p>
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08001687 *
Joe Fernandez464cb212011-10-04 16:56:47 -07001688 * @see FaceDetectionListener
Eino-Ville Talvalab942b052014-07-10 17:45:03 -07001689 * @deprecated We recommend using the new {@link android.hardware.camera2} API for new
1690 * applications.
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08001691 */
Eino-Ville Talvalab942b052014-07-10 17:45:03 -07001692 @Deprecated
Wu-cheng Lif0d6a482011-07-28 05:30:59 +08001693 public static class Face {
Wu-cheng Lic0c683b2011-08-04 00:11:00 +08001694 /**
1695 * Create an empty face.
1696 */
Wu-cheng Libb1e2752011-07-30 05:00:37 +08001697 public Face() {
1698 }
1699
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08001700 /**
1701 * Bounds of the face. (-1000, -1000) represents the top-left of the
1702 * camera field of view, and (1000, 1000) represents the bottom-right of
Wu-cheng Lic0c683b2011-08-04 00:11:00 +08001703 * the field of view. For example, suppose the size of the viewfinder UI
1704 * is 800x480. The rect passed from the driver is (-1000, -1000, 0, 0).
Wu-cheng Li8c136702011-08-12 20:25:00 +08001705 * The corresponding viewfinder rect should be (0, 0, 400, 240). It is
1706 * guaranteed left < right and top < bottom. The coordinates can be
1707 * smaller than -1000 or bigger than 1000. But at least one vertex will
1708 * be within (-1000, -1000) and (1000, 1000).
Wu-cheng Lif0d6a482011-07-28 05:30:59 +08001709 *
1710 * <p>The direction is relative to the sensor orientation, that is, what
1711 * the sensor sees. The direction is not affected by the rotation or
Wu-cheng Li8c136702011-08-12 20:25:00 +08001712 * mirroring of {@link #setDisplayOrientation(int)}. The face bounding
1713 * rectangle does not provide any information about face orientation.</p>
1714 *
1715 * <p>Here is the matrix to convert driver coordinates to View coordinates
1716 * in pixels.</p>
1717 * <pre>
1718 * Matrix matrix = new Matrix();
1719 * CameraInfo info = CameraHolder.instance().getCameraInfo()[cameraId];
1720 * // Need mirror for front camera.
1721 * boolean mirror = (info.facing == CameraInfo.CAMERA_FACING_FRONT);
1722 * matrix.setScale(mirror ? -1 : 1, 1);
1723 * // This is the value for android.hardware.Camera.setDisplayOrientation.
1724 * matrix.postRotate(displayOrientation);
1725 * // Camera driver coordinates range from (-1000, -1000) to (1000, 1000).
1726 * // UI coordinates range from (0, 0) to (width, height).
1727 * matrix.postScale(view.getWidth() / 2000f, view.getHeight() / 2000f);
1728 * matrix.postTranslate(view.getWidth() / 2f, view.getHeight() / 2f);
1729 * </pre>
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08001730 *
Joe Fernandez464cb212011-10-04 16:56:47 -07001731 * @see #startFaceDetection()
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08001732 */
Wu-cheng Libb1e2752011-07-30 05:00:37 +08001733 public Rect rect;
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08001734
1735 /**
Eino-Ville Talvala8df3b2b2012-09-15 14:30:12 -07001736 * <p>The confidence level for the detection of the face. The range is 1 to
1737 * 100. 100 is the highest confidence.</p>
1738 *
1739 * <p>Depending on the device, even very low-confidence faces may be
1740 * listed, so applications should filter out faces with low confidence,
1741 * depending on the use case. For a typical point-and-shoot camera
1742 * application that wishes to display rectangles around detected faces,
1743 * filtering out faces with confidence less than 50 is recommended.</p>
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08001744 *
Joe Fernandez464cb212011-10-04 16:56:47 -07001745 * @see #startFaceDetection()
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08001746 */
Wu-cheng Libb1e2752011-07-30 05:00:37 +08001747 public int score;
Wei Huad52b3082011-08-19 13:01:51 -07001748
1749 /**
1750 * An unique id per face while the face is visible to the tracker. If
1751 * the face leaves the field-of-view and comes back, it will get a new
1752 * id. This is an optional field, may not be supported on all devices.
1753 * If not supported, id will always be set to -1. The optional fields
1754 * are supported as a set. Either they are all valid, or none of them
1755 * are.
1756 */
1757 public int id = -1;
1758
1759 /**
1760 * The coordinates of the center of the left eye. The coordinates are in
1761 * the same space as the ones for {@link #rect}. This is an optional
1762 * field, may not be supported on all devices. If not supported, the
1763 * value will always be set to null. The optional fields are supported
1764 * as a set. Either they are all valid, or none of them are.
1765 */
1766 public Point leftEye = null;
1767
1768 /**
1769 * The coordinates of the center of the right eye. The coordinates are
1770 * in the same space as the ones for {@link #rect}.This is an optional
1771 * field, may not be supported on all devices. If not supported, the
1772 * value will always be set to null. The optional fields are supported
1773 * as a set. Either they are all valid, or none of them are.
1774 */
1775 public Point rightEye = null;
1776
1777 /**
1778 * The coordinates of the center of the mouth. The coordinates are in
1779 * the same space as the ones for {@link #rect}. This is an optional
1780 * field, may not be supported on all devices. If not supported, the
1781 * value will always be set to null. The optional fields are supported
1782 * as a set. Either they are all valid, or none of them are.
1783 */
1784 public Point mouth = null;
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08001785 }
1786
Dan Egnorbfcbeff2010-07-12 15:12:54 -07001787 // Error codes match the enum in include/ui/Camera.h
1788
1789 /**
1790 * Unspecified camera error.
1791 * @see Camera.ErrorCallback
1792 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001793 public static final int CAMERA_ERROR_UNKNOWN = 1;
Dan Egnorbfcbeff2010-07-12 15:12:54 -07001794
1795 /**
1796 * Media server died. In this case, the application must release the
1797 * Camera object and instantiate a new one.
1798 * @see Camera.ErrorCallback
1799 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001800 public static final int CAMERA_ERROR_SERVER_DIED = 100;
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001801
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001802 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -07001803 * Callback interface for camera error notification.
1804 *
1805 * @see #setErrorCallback(ErrorCallback)
Eino-Ville Talvalab942b052014-07-10 17:45:03 -07001806 *
1807 * @deprecated We recommend using the new {@link android.hardware.camera2} API for new
1808 * applications.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001809 */
Eino-Ville Talvalab942b052014-07-10 17:45:03 -07001810 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001811 public interface ErrorCallback
1812 {
1813 /**
1814 * Callback for camera errors.
1815 * @param error error code:
1816 * <ul>
1817 * <li>{@link #CAMERA_ERROR_UNKNOWN}
1818 * <li>{@link #CAMERA_ERROR_SERVER_DIED}
1819 * </ul>
1820 * @param camera the Camera service object
1821 */
1822 void onError(int error, Camera camera);
1823 };
1824
1825 /**
1826 * Registers a callback to be invoked when an error occurs.
Dan Egnorbfcbeff2010-07-12 15:12:54 -07001827 * @param cb The callback to run
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001828 */
1829 public final void setErrorCallback(ErrorCallback cb)
1830 {
1831 mErrorCallback = cb;
1832 }
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001833
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001834 private native final void native_setParameters(String params);
1835 private native final String native_getParameters();
1836
1837 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -07001838 * Changes the settings for this Camera service.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001839 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001840 * @param params the Parameters to use for this Camera service
Wu-cheng Li99a3f3e2010-11-19 15:56:16 +08001841 * @throws RuntimeException if any parameter is invalid or not supported.
Dan Egnorbfcbeff2010-07-12 15:12:54 -07001842 * @see #getParameters()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001843 */
1844 public void setParameters(Parameters params) {
Eino-Ville Talvala7005b672013-04-02 15:46:38 -07001845 // If using preview allocations, don't allow preview size changes
1846 if (mUsingPreviewAllocation) {
1847 Size newPreviewSize = params.getPreviewSize();
1848 Size currentPreviewSize = getParameters().getPreviewSize();
1849 if (newPreviewSize.width != currentPreviewSize.width ||
1850 newPreviewSize.height != currentPreviewSize.height) {
1851 throw new IllegalStateException("Cannot change preview size" +
1852 " while a preview allocation is configured.");
1853 }
1854 }
1855
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001856 native_setParameters(params.flatten());
1857 }
1858
1859 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -07001860 * Returns the current settings for this Camera service.
1861 * If modifications are made to the returned Parameters, they must be passed
1862 * to {@link #setParameters(Camera.Parameters)} to take effect.
1863 *
1864 * @see #setParameters(Camera.Parameters)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001865 */
1866 public Parameters getParameters() {
1867 Parameters p = new Parameters();
1868 String s = native_getParameters();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001869 p.unflatten(s);
1870 return p;
1871 }
1872
1873 /**
Wu-cheng Li1c04a332011-11-22 18:21:18 +08001874 * Returns an empty {@link Parameters} for testing purpose.
1875 *
Ken Wakasaf76a50c2012-03-09 19:56:35 +09001876 * @return a Parameter object.
Wu-cheng Li1c04a332011-11-22 18:21:18 +08001877 *
1878 * @hide
1879 */
1880 public static Parameters getEmptyParameters() {
1881 Camera camera = new Camera();
1882 return camera.new Parameters();
1883 }
1884
1885 /**
Igor Murashkindf6242e2014-07-01 18:06:13 -07001886 * Returns a copied {@link Parameters}; for shim use only.
1887 *
1888 * @param parameters a non-{@code null} parameters
1889 * @return a Parameter object, with all the parameters copied from {@code parameters}.
1890 *
1891 * @throws NullPointerException if {@code parameters} was {@code null}
1892 * @hide
1893 */
1894 public static Parameters getParametersCopy(Camera.Parameters parameters) {
1895 if (parameters == null) {
1896 throw new NullPointerException("parameters must not be null");
1897 }
1898
1899 Camera camera = parameters.getOuter();
1900 Parameters p = camera.new Parameters();
1901 p.copyFrom(parameters);
1902
1903 return p;
1904 }
1905
1906 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -07001907 * Image size (width and height dimensions).
Eino-Ville Talvalab942b052014-07-10 17:45:03 -07001908 * @deprecated We recommend using the new {@link android.hardware.camera2} API for new
1909 * applications.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001910 */
Eino-Ville Talvalab942b052014-07-10 17:45:03 -07001911 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001912 public class Size {
1913 /**
1914 * Sets the dimensions for pictures.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001915 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001916 * @param w the photo width (pixels)
1917 * @param h the photo height (pixels)
1918 */
1919 public Size(int w, int h) {
1920 width = w;
1921 height = h;
1922 }
Wu-cheng Li4c4300c2010-01-23 15:45:39 +08001923 /**
1924 * Compares {@code obj} to this size.
1925 *
1926 * @param obj the object to compare this size with.
1927 * @return {@code true} if the width and height of {@code obj} is the
1928 * same as those of this size. {@code false} otherwise.
1929 */
1930 @Override
1931 public boolean equals(Object obj) {
1932 if (!(obj instanceof Size)) {
1933 return false;
1934 }
1935 Size s = (Size) obj;
1936 return width == s.width && height == s.height;
1937 }
1938 @Override
1939 public int hashCode() {
1940 return width * 32713 + height;
1941 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001942 /** width of the picture */
1943 public int width;
1944 /** height of the picture */
1945 public int height;
1946 };
1947
1948 /**
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07001949 * <p>The Area class is used for choosing specific metering and focus areas for
1950 * the camera to use when calculating auto-exposure, auto-white balance, and
1951 * auto-focus.</p>
1952 *
1953 * <p>To find out how many simultaneous areas a given camera supports, use
1954 * {@link Parameters#getMaxNumMeteringAreas()} and
1955 * {@link Parameters#getMaxNumFocusAreas()}. If metering or focusing area
1956 * selection is unsupported, these methods will return 0.</p>
1957 *
1958 * <p>Each Area consists of a rectangle specifying its bounds, and a weight
1959 * that determines its importance. The bounds are relative to the camera's
1960 * current field of view. The coordinates are mapped so that (-1000, -1000)
1961 * is always the top-left corner of the current field of view, and (1000,
1962 * 1000) is always the bottom-right corner of the current field of
1963 * view. Setting Areas with bounds outside that range is not allowed. Areas
1964 * with zero or negative width or height are not allowed.</p>
1965 *
1966 * <p>The weight must range from 1 to 1000, and represents a weight for
1967 * every pixel in the area. This means that a large metering area with
1968 * the same weight as a smaller area will have more effect in the
1969 * metering result. Metering areas can overlap and the driver
1970 * will add the weights in the overlap region.</p>
Wu-cheng Li30771b72011-04-02 06:19:46 +08001971 *
Wu-cheng Libde61a52011-06-07 18:23:14 +08001972 * @see Parameters#setFocusAreas(List)
1973 * @see Parameters#getFocusAreas()
1974 * @see Parameters#getMaxNumFocusAreas()
1975 * @see Parameters#setMeteringAreas(List)
1976 * @see Parameters#getMeteringAreas()
1977 * @see Parameters#getMaxNumMeteringAreas()
Eino-Ville Talvalab942b052014-07-10 17:45:03 -07001978 *
1979 * @deprecated We recommend using the new {@link android.hardware.camera2} API for new
1980 * applications.
Wu-cheng Li30771b72011-04-02 06:19:46 +08001981 */
Eino-Ville Talvalab942b052014-07-10 17:45:03 -07001982 @Deprecated
Wu-cheng Li30771b72011-04-02 06:19:46 +08001983 public static class Area {
1984 /**
1985 * Create an area with specified rectangle and weight.
1986 *
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07001987 * @param rect the bounds of the area.
1988 * @param weight the weight of the area.
Wu-cheng Li30771b72011-04-02 06:19:46 +08001989 */
1990 public Area(Rect rect, int weight) {
1991 this.rect = rect;
1992 this.weight = weight;
1993 }
1994 /**
1995 * Compares {@code obj} to this area.
1996 *
1997 * @param obj the object to compare this area with.
1998 * @return {@code true} if the rectangle and weight of {@code obj} is
1999 * the same as those of this area. {@code false} otherwise.
2000 */
2001 @Override
2002 public boolean equals(Object obj) {
2003 if (!(obj instanceof Area)) {
2004 return false;
2005 }
2006 Area a = (Area) obj;
2007 if (rect == null) {
2008 if (a.rect != null) return false;
2009 } else {
2010 if (!rect.equals(a.rect)) return false;
2011 }
2012 return weight == a.weight;
2013 }
2014
Wu-cheng Libde61a52011-06-07 18:23:14 +08002015 /**
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07002016 * Bounds of the area. (-1000, -1000) represents the top-left of the
2017 * camera field of view, and (1000, 1000) represents the bottom-right of
2018 * the field of view. Setting bounds outside that range is not
2019 * allowed. Bounds with zero or negative width or height are not
2020 * allowed.
Wu-cheng Libde61a52011-06-07 18:23:14 +08002021 *
2022 * @see Parameters#getFocusAreas()
2023 * @see Parameters#getMeteringAreas()
2024 */
Wu-cheng Li30771b72011-04-02 06:19:46 +08002025 public Rect rect;
2026
Wu-cheng Libde61a52011-06-07 18:23:14 +08002027 /**
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07002028 * Weight of the area. The weight must range from 1 to 1000, and
2029 * represents a weight for every pixel in the area. This means that a
2030 * large metering area with the same weight as a smaller area will have
2031 * more effect in the metering result. Metering areas can overlap and
2032 * the driver will add the weights in the overlap region.
Wu-cheng Libde61a52011-06-07 18:23:14 +08002033 *
2034 * @see Parameters#getFocusAreas()
2035 * @see Parameters#getMeteringAreas()
2036 */
Wu-cheng Li30771b72011-04-02 06:19:46 +08002037 public int weight;
Wu-cheng Libde61a52011-06-07 18:23:14 +08002038 }
Wu-cheng Li30771b72011-04-02 06:19:46 +08002039
2040 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -07002041 * Camera service settings.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002042 *
2043 * <p>To make camera parameters take effect, applications have to call
Dan Egnorbfcbeff2010-07-12 15:12:54 -07002044 * {@link Camera#setParameters(Camera.Parameters)}. For example, after
2045 * {@link Camera.Parameters#setWhiteBalance} is called, white balance is not
2046 * actually changed until {@link Camera#setParameters(Camera.Parameters)}
2047 * is called with the changed parameters object.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002048 *
2049 * <p>Different devices may have different camera capabilities, such as
2050 * picture size or flash modes. The application should query the camera
2051 * capabilities before setting parameters. For example, the application
Dan Egnorbfcbeff2010-07-12 15:12:54 -07002052 * should call {@link Camera.Parameters#getSupportedColorEffects()} before
2053 * calling {@link Camera.Parameters#setColorEffect(String)}. If the
2054 * camera does not support color effects,
2055 * {@link Camera.Parameters#getSupportedColorEffects()} will return null.
Eino-Ville Talvalab942b052014-07-10 17:45:03 -07002056 *
2057 * @deprecated We recommend using the new {@link android.hardware.camera2} API for new
2058 * applications.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002059 */
Eino-Ville Talvalab942b052014-07-10 17:45:03 -07002060 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002061 public class Parameters {
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002062 // Parameter keys to communicate with the camera driver.
2063 private static final String KEY_PREVIEW_SIZE = "preview-size";
2064 private static final String KEY_PREVIEW_FORMAT = "preview-format";
2065 private static final String KEY_PREVIEW_FRAME_RATE = "preview-frame-rate";
Wu-cheng Li454630f2010-08-11 16:48:05 -07002066 private static final String KEY_PREVIEW_FPS_RANGE = "preview-fps-range";
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002067 private static final String KEY_PICTURE_SIZE = "picture-size";
2068 private static final String KEY_PICTURE_FORMAT = "picture-format";
Wu-cheng Li4c4300c2010-01-23 15:45:39 +08002069 private static final String KEY_JPEG_THUMBNAIL_SIZE = "jpeg-thumbnail-size";
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002070 private static final String KEY_JPEG_THUMBNAIL_WIDTH = "jpeg-thumbnail-width";
2071 private static final String KEY_JPEG_THUMBNAIL_HEIGHT = "jpeg-thumbnail-height";
2072 private static final String KEY_JPEG_THUMBNAIL_QUALITY = "jpeg-thumbnail-quality";
2073 private static final String KEY_JPEG_QUALITY = "jpeg-quality";
2074 private static final String KEY_ROTATION = "rotation";
2075 private static final String KEY_GPS_LATITUDE = "gps-latitude";
2076 private static final String KEY_GPS_LONGITUDE = "gps-longitude";
2077 private static final String KEY_GPS_ALTITUDE = "gps-altitude";
2078 private static final String KEY_GPS_TIMESTAMP = "gps-timestamp";
Ray Chen055c9862010-02-23 10:45:42 +08002079 private static final String KEY_GPS_PROCESSING_METHOD = "gps-processing-method";
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002080 private static final String KEY_WHITE_BALANCE = "whitebalance";
2081 private static final String KEY_EFFECT = "effect";
2082 private static final String KEY_ANTIBANDING = "antibanding";
2083 private static final String KEY_SCENE_MODE = "scene-mode";
2084 private static final String KEY_FLASH_MODE = "flash-mode";
Wu-cheng Li36322db2009-09-18 18:59:21 +08002085 private static final String KEY_FOCUS_MODE = "focus-mode";
Wu-cheng Li30771b72011-04-02 06:19:46 +08002086 private static final String KEY_FOCUS_AREAS = "focus-areas";
2087 private static final String KEY_MAX_NUM_FOCUS_AREAS = "max-num-focus-areas";
Wu-cheng Li6c8d2762010-01-27 22:55:14 +08002088 private static final String KEY_FOCAL_LENGTH = "focal-length";
2089 private static final String KEY_HORIZONTAL_VIEW_ANGLE = "horizontal-view-angle";
2090 private static final String KEY_VERTICAL_VIEW_ANGLE = "vertical-view-angle";
Wu-cheng Liff723b62010-02-09 13:38:19 +08002091 private static final String KEY_EXPOSURE_COMPENSATION = "exposure-compensation";
Wu-cheng Li24b326a2010-02-20 17:47:04 +08002092 private static final String KEY_MAX_EXPOSURE_COMPENSATION = "max-exposure-compensation";
2093 private static final String KEY_MIN_EXPOSURE_COMPENSATION = "min-exposure-compensation";
2094 private static final String KEY_EXPOSURE_COMPENSATION_STEP = "exposure-compensation-step";
Eino-Ville Talvala3773eef2011-04-15 13:51:42 -07002095 private static final String KEY_AUTO_EXPOSURE_LOCK = "auto-exposure-lock";
2096 private static final String KEY_AUTO_EXPOSURE_LOCK_SUPPORTED = "auto-exposure-lock-supported";
Eino-Ville Talvalad9c2601a2011-05-13 10:19:59 -07002097 private static final String KEY_AUTO_WHITEBALANCE_LOCK = "auto-whitebalance-lock";
2098 private static final String KEY_AUTO_WHITEBALANCE_LOCK_SUPPORTED = "auto-whitebalance-lock-supported";
Wu-cheng Lie98e4c82011-04-12 19:34:29 +08002099 private static final String KEY_METERING_AREAS = "metering-areas";
2100 private static final String KEY_MAX_NUM_METERING_AREAS = "max-num-metering-areas";
Wu-cheng Li8cbb8f52010-02-28 23:19:55 -08002101 private static final String KEY_ZOOM = "zoom";
2102 private static final String KEY_MAX_ZOOM = "max-zoom";
2103 private static final String KEY_ZOOM_RATIOS = "zoom-ratios";
2104 private static final String KEY_ZOOM_SUPPORTED = "zoom-supported";
2105 private static final String KEY_SMOOTH_ZOOM_SUPPORTED = "smooth-zoom-supported";
Wu-cheng Lie339c5e2010-05-13 19:31:02 +08002106 private static final String KEY_FOCUS_DISTANCES = "focus-distances";
James Dongdd0b16c2010-09-21 16:23:48 -07002107 private static final String KEY_VIDEO_SIZE = "video-size";
2108 private static final String KEY_PREFERRED_PREVIEW_SIZE_FOR_VIDEO =
2109 "preferred-preview-size-for-video";
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08002110 private static final String KEY_MAX_NUM_DETECTED_FACES_HW = "max-num-detected-faces-hw";
2111 private static final String KEY_MAX_NUM_DETECTED_FACES_SW = "max-num-detected-faces-sw";
Wu-cheng Li25d8fb52011-08-02 13:20:36 +08002112 private static final String KEY_RECORDING_HINT = "recording-hint";
Wu-cheng Li98bb2512011-08-30 21:33:10 +08002113 private static final String KEY_VIDEO_SNAPSHOT_SUPPORTED = "video-snapshot-supported";
Eino-Ville Talvala037abb82011-10-11 12:41:58 -07002114 private static final String KEY_VIDEO_STABILIZATION = "video-stabilization";
2115 private static final String KEY_VIDEO_STABILIZATION_SUPPORTED = "video-stabilization-supported";
Wu-cheng Lie339c5e2010-05-13 19:31:02 +08002116
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002117 // Parameter key suffix for supported values.
2118 private static final String SUPPORTED_VALUES_SUFFIX = "-values";
2119
Wu-cheng Li8cbb8f52010-02-28 23:19:55 -08002120 private static final String TRUE = "true";
Eino-Ville Talvala3773eef2011-04-15 13:51:42 -07002121 private static final String FALSE = "false";
Wu-cheng Li8cbb8f52010-02-28 23:19:55 -08002122
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002123 // Values for white balance settings.
2124 public static final String WHITE_BALANCE_AUTO = "auto";
2125 public static final String WHITE_BALANCE_INCANDESCENT = "incandescent";
2126 public static final String WHITE_BALANCE_FLUORESCENT = "fluorescent";
2127 public static final String WHITE_BALANCE_WARM_FLUORESCENT = "warm-fluorescent";
2128 public static final String WHITE_BALANCE_DAYLIGHT = "daylight";
2129 public static final String WHITE_BALANCE_CLOUDY_DAYLIGHT = "cloudy-daylight";
2130 public static final String WHITE_BALANCE_TWILIGHT = "twilight";
2131 public static final String WHITE_BALANCE_SHADE = "shade";
2132
2133 // Values for color effect settings.
2134 public static final String EFFECT_NONE = "none";
2135 public static final String EFFECT_MONO = "mono";
2136 public static final String EFFECT_NEGATIVE = "negative";
2137 public static final String EFFECT_SOLARIZE = "solarize";
2138 public static final String EFFECT_SEPIA = "sepia";
2139 public static final String EFFECT_POSTERIZE = "posterize";
2140 public static final String EFFECT_WHITEBOARD = "whiteboard";
2141 public static final String EFFECT_BLACKBOARD = "blackboard";
2142 public static final String EFFECT_AQUA = "aqua";
2143
2144 // Values for antibanding settings.
2145 public static final String ANTIBANDING_AUTO = "auto";
2146 public static final String ANTIBANDING_50HZ = "50hz";
2147 public static final String ANTIBANDING_60HZ = "60hz";
2148 public static final String ANTIBANDING_OFF = "off";
2149
2150 // Values for flash mode settings.
2151 /**
2152 * Flash will not be fired.
2153 */
2154 public static final String FLASH_MODE_OFF = "off";
Wu-cheng Li36f68b82009-09-28 16:14:58 -07002155
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002156 /**
Wu-cheng Li068ef422009-09-27 13:19:36 -07002157 * Flash will be fired automatically when required. The flash may be fired
2158 * during preview, auto-focus, or snapshot depending on the driver.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002159 */
2160 public static final String FLASH_MODE_AUTO = "auto";
Wu-cheng Li36f68b82009-09-28 16:14:58 -07002161
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002162 /**
Wu-cheng Li068ef422009-09-27 13:19:36 -07002163 * Flash will always be fired during snapshot. The flash may also be
2164 * fired during preview or auto-focus depending on the driver.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002165 */
2166 public static final String FLASH_MODE_ON = "on";
Wu-cheng Li36f68b82009-09-28 16:14:58 -07002167
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002168 /**
2169 * Flash will be fired in red-eye reduction mode.
2170 */
2171 public static final String FLASH_MODE_RED_EYE = "red-eye";
Wu-cheng Li36f68b82009-09-28 16:14:58 -07002172
Wu-cheng Li36322db2009-09-18 18:59:21 +08002173 /**
Wu-cheng Li068ef422009-09-27 13:19:36 -07002174 * Constant emission of light during preview, auto-focus and snapshot.
2175 * This can also be used for video recording.
Wu-cheng Li36322db2009-09-18 18:59:21 +08002176 */
Wu-cheng Li068ef422009-09-27 13:19:36 -07002177 public static final String FLASH_MODE_TORCH = "torch";
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002178
Wu-cheng Li00e21f82010-05-28 16:43:38 +08002179 /**
2180 * Scene mode is off.
2181 */
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002182 public static final String SCENE_MODE_AUTO = "auto";
Wu-cheng Li00e21f82010-05-28 16:43:38 +08002183
2184 /**
2185 * Take photos of fast moving objects. Same as {@link
2186 * #SCENE_MODE_SPORTS}.
2187 */
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002188 public static final String SCENE_MODE_ACTION = "action";
Wu-cheng Li00e21f82010-05-28 16:43:38 +08002189
2190 /**
2191 * Take people pictures.
2192 */
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002193 public static final String SCENE_MODE_PORTRAIT = "portrait";
Wu-cheng Li00e21f82010-05-28 16:43:38 +08002194
2195 /**
2196 * Take pictures on distant objects.
2197 */
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002198 public static final String SCENE_MODE_LANDSCAPE = "landscape";
Wu-cheng Li00e21f82010-05-28 16:43:38 +08002199
2200 /**
2201 * Take photos at night.
2202 */
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002203 public static final String SCENE_MODE_NIGHT = "night";
Wu-cheng Li00e21f82010-05-28 16:43:38 +08002204
2205 /**
2206 * Take people pictures at night.
2207 */
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002208 public static final String SCENE_MODE_NIGHT_PORTRAIT = "night-portrait";
Wu-cheng Li00e21f82010-05-28 16:43:38 +08002209
2210 /**
2211 * Take photos in a theater. Flash light is off.
2212 */
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002213 public static final String SCENE_MODE_THEATRE = "theatre";
Wu-cheng Li00e21f82010-05-28 16:43:38 +08002214
2215 /**
2216 * Take pictures on the beach.
2217 */
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002218 public static final String SCENE_MODE_BEACH = "beach";
Wu-cheng Li00e21f82010-05-28 16:43:38 +08002219
2220 /**
2221 * Take pictures on the snow.
2222 */
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002223 public static final String SCENE_MODE_SNOW = "snow";
Wu-cheng Li00e21f82010-05-28 16:43:38 +08002224
2225 /**
2226 * Take sunset photos.
2227 */
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002228 public static final String SCENE_MODE_SUNSET = "sunset";
Wu-cheng Li00e21f82010-05-28 16:43:38 +08002229
2230 /**
2231 * Avoid blurry pictures (for example, due to hand shake).
2232 */
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002233 public static final String SCENE_MODE_STEADYPHOTO = "steadyphoto";
Wu-cheng Li00e21f82010-05-28 16:43:38 +08002234
2235 /**
2236 * For shooting firework displays.
2237 */
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002238 public static final String SCENE_MODE_FIREWORKS = "fireworks";
Wu-cheng Li00e21f82010-05-28 16:43:38 +08002239
2240 /**
2241 * Take photos of fast moving objects. Same as {@link
2242 * #SCENE_MODE_ACTION}.
2243 */
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002244 public static final String SCENE_MODE_SPORTS = "sports";
Wu-cheng Li00e21f82010-05-28 16:43:38 +08002245
2246 /**
2247 * Take indoor low-light shot.
2248 */
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002249 public static final String SCENE_MODE_PARTY = "party";
Wu-cheng Li00e21f82010-05-28 16:43:38 +08002250
2251 /**
2252 * Capture the naturally warm color of scenes lit by candles.
2253 */
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002254 public static final String SCENE_MODE_CANDLELIGHT = "candlelight";
2255
Wu-cheng Lic58b4232010-03-29 17:21:28 +08002256 /**
2257 * Applications are looking for a barcode. Camera driver will be
2258 * optimized for barcode reading.
2259 */
2260 public static final String SCENE_MODE_BARCODE = "barcode";
2261
Wu-cheng Li36322db2009-09-18 18:59:21 +08002262 /**
Eino-Ville Talvalada2f0ea2012-09-10 12:03:35 -07002263 * Capture a scene using high dynamic range imaging techniques. The
2264 * camera will return an image that has an extended dynamic range
2265 * compared to a regular capture. Capturing such an image may take
2266 * longer than a regular capture.
Eino-Ville Talvalada2f0ea2012-09-10 12:03:35 -07002267 */
2268 public static final String SCENE_MODE_HDR = "hdr";
2269
2270 /**
Wu-cheng Lif008f3e2010-08-17 13:44:35 -07002271 * Auto-focus mode. Applications should call {@link
2272 * #autoFocus(AutoFocusCallback)} to start the focus in this mode.
Wu-cheng Li36322db2009-09-18 18:59:21 +08002273 */
2274 public static final String FOCUS_MODE_AUTO = "auto";
Wu-cheng Li36f68b82009-09-28 16:14:58 -07002275
Wu-cheng Li36322db2009-09-18 18:59:21 +08002276 /**
2277 * Focus is set at infinity. Applications should not call
2278 * {@link #autoFocus(AutoFocusCallback)} in this mode.
2279 */
2280 public static final String FOCUS_MODE_INFINITY = "infinity";
Wu-cheng Lif008f3e2010-08-17 13:44:35 -07002281
2282 /**
2283 * Macro (close-up) focus mode. Applications should call
2284 * {@link #autoFocus(AutoFocusCallback)} to start the focus in this
2285 * mode.
2286 */
Wu-cheng Li36322db2009-09-18 18:59:21 +08002287 public static final String FOCUS_MODE_MACRO = "macro";
Wu-cheng Li36f68b82009-09-28 16:14:58 -07002288
Wu-cheng Li36322db2009-09-18 18:59:21 +08002289 /**
2290 * Focus is fixed. The camera is always in this mode if the focus is not
2291 * adjustable. If the camera has auto-focus, this mode can fix the
2292 * focus, which is usually at hyperfocal distance. Applications should
2293 * not call {@link #autoFocus(AutoFocusCallback)} in this mode.
2294 */
2295 public static final String FOCUS_MODE_FIXED = "fixed";
2296
Wu-cheng Lic58b4232010-03-29 17:21:28 +08002297 /**
2298 * Extended depth of field (EDOF). Focusing is done digitally and
2299 * continuously. Applications should not call {@link
2300 * #autoFocus(AutoFocusCallback)} in this mode.
2301 */
2302 public static final String FOCUS_MODE_EDOF = "edof";
2303
Wu-cheng Li699fe932010-08-05 11:50:25 -07002304 /**
Wu-cheng Lid45cb722010-09-20 16:15:32 -07002305 * Continuous auto focus mode intended for video recording. The camera
Wu-cheng Lib9ac75d2011-08-16 21:14:16 +08002306 * continuously tries to focus. This is the best choice for video
2307 * recording because the focus changes smoothly . Applications still can
2308 * call {@link #takePicture(Camera.ShutterCallback,
2309 * Camera.PictureCallback, Camera.PictureCallback)} in this mode but the
2310 * subject may not be in focus. Auto focus starts when the parameter is
Wu-cheng Li53b30912011-10-12 19:43:51 +08002311 * set.
2312 *
2313 * <p>Since API level 14, applications can call {@link
2314 * #autoFocus(AutoFocusCallback)} in this mode. The focus callback will
2315 * immediately return with a boolean that indicates whether the focus is
2316 * sharp or not. The focus position is locked after autoFocus call. If
2317 * applications want to resume the continuous focus, cancelAutoFocus
2318 * must be called. Restarting the preview will not resume the continuous
2319 * autofocus. To stop continuous focus, applications should change the
2320 * focus mode to other modes.
2321 *
2322 * @see #FOCUS_MODE_CONTINUOUS_PICTURE
Wu-cheng Li699fe932010-08-05 11:50:25 -07002323 */
Wu-cheng Lid45cb722010-09-20 16:15:32 -07002324 public static final String FOCUS_MODE_CONTINUOUS_VIDEO = "continuous-video";
Wu-cheng Li699fe932010-08-05 11:50:25 -07002325
Wu-cheng Lib9ac75d2011-08-16 21:14:16 +08002326 /**
2327 * Continuous auto focus mode intended for taking pictures. The camera
2328 * continuously tries to focus. The speed of focus change is more
2329 * aggressive than {@link #FOCUS_MODE_CONTINUOUS_VIDEO}. Auto focus
Wu-cheng Li53b30912011-10-12 19:43:51 +08002330 * starts when the parameter is set.
2331 *
Wu-cheng Li0f4f97b2011-10-27 18:07:01 +08002332 * <p>Applications can call {@link #autoFocus(AutoFocusCallback)} in
2333 * this mode. If the autofocus is in the middle of scanning, the focus
2334 * callback will return when it completes. If the autofocus is not
2335 * scanning, the focus callback will immediately return with a boolean
2336 * that indicates whether the focus is sharp or not. The apps can then
2337 * decide if they want to take a picture immediately or to change the
2338 * focus mode to auto, and run a full autofocus cycle. The focus
2339 * position is locked after autoFocus call. If applications want to
2340 * resume the continuous focus, cancelAutoFocus must be called.
2341 * Restarting the preview will not resume the continuous autofocus. To
2342 * stop continuous focus, applications should change the focus mode to
2343 * other modes.
Wu-cheng Lib9ac75d2011-08-16 21:14:16 +08002344 *
2345 * @see #FOCUS_MODE_CONTINUOUS_VIDEO
Wu-cheng Lib9ac75d2011-08-16 21:14:16 +08002346 */
2347 public static final String FOCUS_MODE_CONTINUOUS_PICTURE = "continuous-picture";
2348
Wu-cheng Lie339c5e2010-05-13 19:31:02 +08002349 // Indices for focus distance array.
2350 /**
2351 * The array index of near focus distance for use with
2352 * {@link #getFocusDistances(float[])}.
2353 */
2354 public static final int FOCUS_DISTANCE_NEAR_INDEX = 0;
2355
2356 /**
2357 * The array index of optimal focus distance for use with
2358 * {@link #getFocusDistances(float[])}.
2359 */
2360 public static final int FOCUS_DISTANCE_OPTIMAL_INDEX = 1;
2361
2362 /**
2363 * The array index of far focus distance for use with
2364 * {@link #getFocusDistances(float[])}.
2365 */
2366 public static final int FOCUS_DISTANCE_FAR_INDEX = 2;
2367
Wu-cheng Lica099612010-05-06 16:47:30 +08002368 /**
Wu-cheng Li454630f2010-08-11 16:48:05 -07002369 * The array index of minimum preview fps for use with {@link
2370 * #getPreviewFpsRange(int[])} or {@link
2371 * #getSupportedPreviewFpsRange()}.
Wu-cheng Li454630f2010-08-11 16:48:05 -07002372 */
2373 public static final int PREVIEW_FPS_MIN_INDEX = 0;
2374
2375 /**
2376 * The array index of maximum preview fps for use with {@link
2377 * #getPreviewFpsRange(int[])} or {@link
2378 * #getSupportedPreviewFpsRange()}.
Wu-cheng Li454630f2010-08-11 16:48:05 -07002379 */
2380 public static final int PREVIEW_FPS_MAX_INDEX = 1;
2381
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002382 // Formats for setPreviewFormat and setPictureFormat.
2383 private static final String PIXEL_FORMAT_YUV422SP = "yuv422sp";
2384 private static final String PIXEL_FORMAT_YUV420SP = "yuv420sp";
Chih-Chung Changeb68c462009-09-18 18:37:44 +08002385 private static final String PIXEL_FORMAT_YUV422I = "yuv422i-yuyv";
Wu-cheng Li10a1b302011-02-22 15:49:25 +08002386 private static final String PIXEL_FORMAT_YUV420P = "yuv420p";
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002387 private static final String PIXEL_FORMAT_RGB565 = "rgb565";
2388 private static final String PIXEL_FORMAT_JPEG = "jpeg";
Wu-cheng Li70fb9082011-08-02 17:49:50 +08002389 private static final String PIXEL_FORMAT_BAYER_RGGB = "bayer-rggb";
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002390
Igor Murashkin7d9a8ff2014-03-18 18:14:41 -07002391 /**
2392 * Order matters: Keys that are {@link #set(String, String) set} later
2393 * will take precedence over keys that are set earlier (if the two keys
2394 * conflict with each other).
2395 *
2396 * <p>One example is {@link #setPreviewFpsRange(int, int)} , since it
2397 * conflicts with {@link #setPreviewFrameRate(int)} whichever key is set later
2398 * is the one that will take precedence.
2399 * </p>
2400 */
2401 private final LinkedHashMap<String, String> mMap;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002402
2403 private Parameters() {
Igor Murashkin7d9a8ff2014-03-18 18:14:41 -07002404 mMap = new LinkedHashMap<String, String>(/*initialCapacity*/64);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002405 }
2406
2407 /**
Igor Murashkindf6242e2014-07-01 18:06:13 -07002408 * Overwrite existing parameters with a copy of the ones from {@code other}.
2409 *
2410 * <b>For use by the legacy shim only.</b>
2411 *
2412 * @hide
2413 */
2414 public void copyFrom(Parameters other) {
2415 if (other == null) {
2416 throw new NullPointerException("other must not be null");
2417 }
2418
2419 mMap.putAll(other.mMap);
2420 }
2421
2422 private Camera getOuter() {
2423 return Camera.this;
2424 }
2425
2426 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002427 * Writes the current Parameters to the log.
2428 * @hide
2429 * @deprecated
2430 */
Igor Murashkina1d66272014-06-20 11:22:11 -07002431 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002432 public void dump() {
2433 Log.e(TAG, "dump: size=" + mMap.size());
2434 for (String k : mMap.keySet()) {
2435 Log.e(TAG, "dump: " + k + "=" + mMap.get(k));
2436 }
2437 }
2438
2439 /**
2440 * Creates a single string with all the parameters set in
2441 * this Parameters object.
2442 * <p>The {@link #unflatten(String)} method does the reverse.</p>
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002443 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002444 * @return a String with all values from this Parameters object, in
2445 * semi-colon delimited key-value pairs
2446 */
2447 public String flatten() {
Ali Utku Selen0a120182011-02-09 14:11:22 +01002448 StringBuilder flattened = new StringBuilder(128);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002449 for (String k : mMap.keySet()) {
2450 flattened.append(k);
2451 flattened.append("=");
2452 flattened.append(mMap.get(k));
2453 flattened.append(";");
2454 }
2455 // chop off the extra semicolon at the end
2456 flattened.deleteCharAt(flattened.length()-1);
2457 return flattened.toString();
2458 }
2459
2460 /**
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002461 * Takes a flattened string of parameters and adds each one to
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002462 * this Parameters object.
2463 * <p>The {@link #flatten()} method does the reverse.</p>
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002464 *
2465 * @param flattened a String of parameters (key-value paired) that
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002466 * are semi-colon delimited
2467 */
2468 public void unflatten(String flattened) {
2469 mMap.clear();
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002470
Ali Utku Selen0a120182011-02-09 14:11:22 +01002471 TextUtils.StringSplitter splitter = new TextUtils.SimpleStringSplitter(';');
2472 splitter.setString(flattened);
2473 for (String kv : splitter) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002474 int pos = kv.indexOf('=');
2475 if (pos == -1) {
2476 continue;
2477 }
2478 String k = kv.substring(0, pos);
2479 String v = kv.substring(pos + 1);
2480 mMap.put(k, v);
2481 }
2482 }
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002483
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002484 public void remove(String key) {
2485 mMap.remove(key);
2486 }
2487
2488 /**
2489 * Sets a String parameter.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002490 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002491 * @param key the key name for the parameter
2492 * @param value the String value of the parameter
2493 */
2494 public void set(String key, String value) {
Eino-Ville Talvalacb569232012-03-12 11:36:58 -07002495 if (key.indexOf('=') != -1 || key.indexOf(';') != -1 || key.indexOf(0) != -1) {
2496 Log.e(TAG, "Key \"" + key + "\" contains invalid character (= or ; or \\0)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002497 return;
2498 }
Eino-Ville Talvalacb569232012-03-12 11:36:58 -07002499 if (value.indexOf('=') != -1 || value.indexOf(';') != -1 || value.indexOf(0) != -1) {
2500 Log.e(TAG, "Value \"" + value + "\" contains invalid character (= or ; or \\0)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002501 return;
2502 }
2503
Igor Murashkin7d9a8ff2014-03-18 18:14:41 -07002504 put(key, value);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002505 }
2506
2507 /**
2508 * Sets an integer parameter.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002509 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002510 * @param key the key name for the parameter
2511 * @param value the int value of the parameter
2512 */
2513 public void set(String key, int value) {
Igor Murashkin7d9a8ff2014-03-18 18:14:41 -07002514 put(key, Integer.toString(value));
2515 }
2516
2517 private void put(String key, String value) {
2518 /*
2519 * Remove the key if it already exists.
2520 *
2521 * This way setting a new value for an already existing key will always move
2522 * that key to be ordered the latest in the map.
2523 */
2524 mMap.remove(key);
2525 mMap.put(key, value);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002526 }
2527
Wu-cheng Lie98e4c82011-04-12 19:34:29 +08002528 private void set(String key, List<Area> areas) {
Wu-cheng Lif715bf92011-04-14 14:04:18 +08002529 if (areas == null) {
2530 set(key, "(0,0,0,0,0)");
2531 } else {
2532 StringBuilder buffer = new StringBuilder();
2533 for (int i = 0; i < areas.size(); i++) {
2534 Area area = areas.get(i);
2535 Rect rect = area.rect;
2536 buffer.append('(');
2537 buffer.append(rect.left);
2538 buffer.append(',');
2539 buffer.append(rect.top);
2540 buffer.append(',');
2541 buffer.append(rect.right);
2542 buffer.append(',');
2543 buffer.append(rect.bottom);
2544 buffer.append(',');
2545 buffer.append(area.weight);
2546 buffer.append(')');
2547 if (i != areas.size() - 1) buffer.append(',');
2548 }
2549 set(key, buffer.toString());
Wu-cheng Lie98e4c82011-04-12 19:34:29 +08002550 }
Wu-cheng Lie98e4c82011-04-12 19:34:29 +08002551 }
2552
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002553 /**
2554 * Returns the value of a String parameter.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002555 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002556 * @param key the key name for the parameter
2557 * @return the String value of the parameter
2558 */
2559 public String get(String key) {
2560 return mMap.get(key);
2561 }
2562
2563 /**
2564 * Returns the value of an integer parameter.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002565 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002566 * @param key the key name for the parameter
2567 * @return the int value of the parameter
2568 */
2569 public int getInt(String key) {
2570 return Integer.parseInt(mMap.get(key));
2571 }
2572
2573 /**
Wu-cheng Li26274fa2011-05-05 14:36:28 +08002574 * Sets the dimensions for preview pictures. If the preview has already
2575 * started, applications should stop the preview first before changing
2576 * preview size.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002577 *
Wu-cheng Lic157e0c2010-10-07 18:36:07 +08002578 * The sides of width and height are based on camera orientation. That
2579 * is, the preview size is the size before it is rotated by display
2580 * orientation. So applications need to consider the display orientation
2581 * while setting preview size. For example, suppose the camera supports
2582 * both 480x320 and 320x480 preview sizes. The application wants a 3:2
2583 * preview ratio. If the display orientation is set to 0 or 180, preview
2584 * size should be set to 480x320. If the display orientation is set to
2585 * 90 or 270, preview size should be set to 320x480. The display
2586 * orientation should also be considered while setting picture size and
2587 * thumbnail size.
2588 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002589 * @param width the width of the pictures, in pixels
2590 * @param height the height of the pictures, in pixels
Wu-cheng Lic157e0c2010-10-07 18:36:07 +08002591 * @see #setDisplayOrientation(int)
2592 * @see #getCameraInfo(int, CameraInfo)
2593 * @see #setPictureSize(int, int)
2594 * @see #setJpegThumbnailSize(int, int)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002595 */
2596 public void setPreviewSize(int width, int height) {
2597 String v = Integer.toString(width) + "x" + Integer.toString(height);
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002598 set(KEY_PREVIEW_SIZE, v);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002599 }
2600
2601 /**
2602 * Returns the dimensions setting for preview pictures.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002603 *
James Dongdd0b16c2010-09-21 16:23:48 -07002604 * @return a Size object with the width and height setting
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002605 * for the preview picture
2606 */
2607 public Size getPreviewSize() {
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002608 String pair = get(KEY_PREVIEW_SIZE);
2609 return strToSize(pair);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002610 }
2611
2612 /**
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002613 * Gets the supported preview sizes.
2614 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08002615 * @return a list of Size object. This method will always return a list
Wu-cheng Li9c799382009-12-04 19:59:18 +08002616 * with at least one element.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002617 */
2618 public List<Size> getSupportedPreviewSizes() {
2619 String str = get(KEY_PREVIEW_SIZE + SUPPORTED_VALUES_SUFFIX);
2620 return splitSize(str);
2621 }
2622
2623 /**
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07002624 * <p>Gets the supported video frame sizes that can be used by
2625 * MediaRecorder.</p>
James Dongdd0b16c2010-09-21 16:23:48 -07002626 *
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07002627 * <p>If the returned list is not null, the returned list will contain at
James Dongdd0b16c2010-09-21 16:23:48 -07002628 * least one Size and one of the sizes in the returned list must be
2629 * passed to MediaRecorder.setVideoSize() for camcorder application if
2630 * camera is used as the video source. In this case, the size of the
2631 * preview can be different from the resolution of the recorded video
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07002632 * during video recording.</p>
James Dongdd0b16c2010-09-21 16:23:48 -07002633 *
2634 * @return a list of Size object if camera has separate preview and
2635 * video output; otherwise, null is returned.
2636 * @see #getPreferredPreviewSizeForVideo()
2637 */
2638 public List<Size> getSupportedVideoSizes() {
2639 String str = get(KEY_VIDEO_SIZE + SUPPORTED_VALUES_SUFFIX);
2640 return splitSize(str);
2641 }
2642
2643 /**
2644 * Returns the preferred or recommended preview size (width and height)
2645 * in pixels for video recording. Camcorder applications should
2646 * set the preview size to a value that is not larger than the
2647 * preferred preview size. In other words, the product of the width
2648 * and height of the preview size should not be larger than that of
2649 * the preferred preview size. In addition, we recommend to choose a
2650 * preview size that has the same aspect ratio as the resolution of
2651 * video to be recorded.
2652 *
2653 * @return the preferred preview size (width and height) in pixels for
2654 * video recording if getSupportedVideoSizes() does not return
2655 * null; otherwise, null is returned.
2656 * @see #getSupportedVideoSizes()
2657 */
2658 public Size getPreferredPreviewSizeForVideo() {
2659 String pair = get(KEY_PREFERRED_PREVIEW_SIZE_FOR_VIDEO);
2660 return strToSize(pair);
2661 }
2662
2663 /**
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07002664 * <p>Sets the dimensions for EXIF thumbnail in Jpeg picture. If
Wu-cheng Li4c4300c2010-01-23 15:45:39 +08002665 * applications set both width and height to 0, EXIF will not contain
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07002666 * thumbnail.</p>
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002667 *
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07002668 * <p>Applications need to consider the display orientation. See {@link
2669 * #setPreviewSize(int,int)} for reference.</p>
Wu-cheng Lic157e0c2010-10-07 18:36:07 +08002670 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002671 * @param width the width of the thumbnail, in pixels
2672 * @param height the height of the thumbnail, in pixels
Wu-cheng Lic157e0c2010-10-07 18:36:07 +08002673 * @see #setPreviewSize(int,int)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002674 */
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002675 public void setJpegThumbnailSize(int width, int height) {
2676 set(KEY_JPEG_THUMBNAIL_WIDTH, width);
2677 set(KEY_JPEG_THUMBNAIL_HEIGHT, height);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002678 }
2679
2680 /**
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002681 * Returns the dimensions for EXIF thumbnail in Jpeg picture.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002682 *
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002683 * @return a Size object with the height and width setting for the EXIF
2684 * thumbnails
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002685 */
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002686 public Size getJpegThumbnailSize() {
2687 return new Size(getInt(KEY_JPEG_THUMBNAIL_WIDTH),
2688 getInt(KEY_JPEG_THUMBNAIL_HEIGHT));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002689 }
2690
2691 /**
Wu-cheng Li4c4300c2010-01-23 15:45:39 +08002692 * Gets the supported jpeg thumbnail sizes.
2693 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08002694 * @return a list of Size object. This method will always return a list
Wu-cheng Li4c4300c2010-01-23 15:45:39 +08002695 * with at least two elements. Size 0,0 (no thumbnail) is always
2696 * supported.
2697 */
2698 public List<Size> getSupportedJpegThumbnailSizes() {
2699 String str = get(KEY_JPEG_THUMBNAIL_SIZE + SUPPORTED_VALUES_SUFFIX);
2700 return splitSize(str);
2701 }
2702
2703 /**
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002704 * Sets the quality of the EXIF thumbnail in Jpeg picture.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002705 *
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002706 * @param quality the JPEG quality of the EXIF thumbnail. The range is 1
2707 * to 100, with 100 being the best.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002708 */
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002709 public void setJpegThumbnailQuality(int quality) {
2710 set(KEY_JPEG_THUMBNAIL_QUALITY, quality);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002711 }
2712
2713 /**
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002714 * Returns the quality setting for the EXIF thumbnail in Jpeg picture.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002715 *
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002716 * @return the JPEG quality setting of the EXIF thumbnail.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002717 */
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002718 public int getJpegThumbnailQuality() {
2719 return getInt(KEY_JPEG_THUMBNAIL_QUALITY);
2720 }
2721
2722 /**
2723 * Sets Jpeg quality of captured picture.
2724 *
2725 * @param quality the JPEG quality of captured picture. The range is 1
2726 * to 100, with 100 being the best.
2727 */
2728 public void setJpegQuality(int quality) {
2729 set(KEY_JPEG_QUALITY, quality);
2730 }
2731
2732 /**
2733 * Returns the quality setting for the JPEG picture.
2734 *
2735 * @return the JPEG picture quality setting.
2736 */
2737 public int getJpegQuality() {
2738 return getInt(KEY_JPEG_QUALITY);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002739 }
2740
2741 /**
Wu-cheng Lia18e9012010-02-10 13:05:29 +08002742 * Sets the rate at which preview frames are received. This is the
2743 * target frame rate. The actual frame rate depends on the driver.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002744 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002745 * @param fps the frame rate (frames per second)
Wu-cheng Li5f1e69c2010-08-18 11:39:12 -07002746 * @deprecated replaced by {@link #setPreviewFpsRange(int,int)}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002747 */
Wu-cheng Li5f1e69c2010-08-18 11:39:12 -07002748 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002749 public void setPreviewFrameRate(int fps) {
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002750 set(KEY_PREVIEW_FRAME_RATE, fps);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002751 }
2752
2753 /**
Wu-cheng Lia18e9012010-02-10 13:05:29 +08002754 * Returns the setting for the rate at which preview frames are
2755 * received. This is the target frame rate. The actual frame rate
2756 * depends on the driver.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002757 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002758 * @return the frame rate setting (frames per second)
Wu-cheng Li5f1e69c2010-08-18 11:39:12 -07002759 * @deprecated replaced by {@link #getPreviewFpsRange(int[])}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002760 */
Wu-cheng Li5f1e69c2010-08-18 11:39:12 -07002761 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002762 public int getPreviewFrameRate() {
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002763 return getInt(KEY_PREVIEW_FRAME_RATE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002764 }
2765
2766 /**
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002767 * Gets the supported preview frame rates.
2768 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08002769 * @return a list of supported preview frame rates. null if preview
2770 * frame rate setting is not supported.
Wu-cheng Li5f1e69c2010-08-18 11:39:12 -07002771 * @deprecated replaced by {@link #getSupportedPreviewFpsRange()}
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002772 */
Wu-cheng Li5f1e69c2010-08-18 11:39:12 -07002773 @Deprecated
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002774 public List<Integer> getSupportedPreviewFrameRates() {
2775 String str = get(KEY_PREVIEW_FRAME_RATE + SUPPORTED_VALUES_SUFFIX);
2776 return splitInt(str);
2777 }
2778
2779 /**
Hai Guo4a68e3c2012-12-05 21:50:28 +08002780 * Sets the minimum and maximum preview fps. This controls the rate of
Wu-cheng Li1620d112010-08-27 15:09:20 -07002781 * preview frames received in {@link PreviewCallback}. The minimum and
Wu-cheng Li454630f2010-08-11 16:48:05 -07002782 * maximum preview fps must be one of the elements from {@link
2783 * #getSupportedPreviewFpsRange}.
2784 *
2785 * @param min the minimum preview fps (scaled by 1000).
2786 * @param max the maximum preview fps (scaled by 1000).
2787 * @throws RuntimeException if fps range is invalid.
2788 * @see #setPreviewCallbackWithBuffer(Camera.PreviewCallback)
2789 * @see #getSupportedPreviewFpsRange()
Wu-cheng Li454630f2010-08-11 16:48:05 -07002790 */
2791 public void setPreviewFpsRange(int min, int max) {
2792 set(KEY_PREVIEW_FPS_RANGE, "" + min + "," + max);
2793 }
2794
2795 /**
2796 * Returns the current minimum and maximum preview fps. The values are
2797 * one of the elements returned by {@link #getSupportedPreviewFpsRange}.
2798 *
2799 * @return range the minimum and maximum preview fps (scaled by 1000).
2800 * @see #PREVIEW_FPS_MIN_INDEX
2801 * @see #PREVIEW_FPS_MAX_INDEX
2802 * @see #getSupportedPreviewFpsRange()
Wu-cheng Li454630f2010-08-11 16:48:05 -07002803 */
2804 public void getPreviewFpsRange(int[] range) {
2805 if (range == null || range.length != 2) {
2806 throw new IllegalArgumentException(
Wu-cheng Li5f1e69c2010-08-18 11:39:12 -07002807 "range must be an array with two elements.");
Wu-cheng Li454630f2010-08-11 16:48:05 -07002808 }
2809 splitInt(get(KEY_PREVIEW_FPS_RANGE), range);
2810 }
2811
2812 /**
2813 * Gets the supported preview fps (frame-per-second) ranges. Each range
2814 * contains a minimum fps and maximum fps. If minimum fps equals to
2815 * maximum fps, the camera outputs frames in fixed frame rate. If not,
2816 * the camera outputs frames in auto frame rate. The actual frame rate
2817 * fluctuates between the minimum and the maximum. The values are
2818 * multiplied by 1000 and represented in integers. For example, if frame
2819 * rate is 26.623 frames per second, the value is 26623.
2820 *
2821 * @return a list of supported preview fps ranges. This method returns a
2822 * list with at least one element. Every element is an int array
2823 * of two values - minimum fps and maximum fps. The list is
2824 * sorted from small to large (first by maximum fps and then
2825 * minimum fps).
2826 * @see #PREVIEW_FPS_MIN_INDEX
2827 * @see #PREVIEW_FPS_MAX_INDEX
Wu-cheng Li454630f2010-08-11 16:48:05 -07002828 */
2829 public List<int[]> getSupportedPreviewFpsRange() {
2830 String str = get(KEY_PREVIEW_FPS_RANGE + SUPPORTED_VALUES_SUFFIX);
2831 return splitRange(str);
2832 }
2833
2834 /**
Wu-cheng Li7478ea62009-09-16 18:52:55 +08002835 * Sets the image format for preview pictures.
Scott Mainda0a56d2009-09-10 18:08:37 -07002836 * <p>If this is never called, the default format will be
Mathias Agopiana696f5d2010-02-17 17:53:09 -08002837 * {@link android.graphics.ImageFormat#NV21}, which
Scott Maindf4578e2009-09-10 12:22:07 -07002838 * uses the NV21 encoding format.</p>
Wu-cheng Li7478ea62009-09-16 18:52:55 +08002839 *
Eino-Ville Talvala95151632012-05-02 16:21:18 -07002840 * <p>Use {@link Parameters#getSupportedPreviewFormats} to get a list of
2841 * the available preview formats.
2842 *
2843 * <p>It is strongly recommended that either
2844 * {@link android.graphics.ImageFormat#NV21} or
2845 * {@link android.graphics.ImageFormat#YV12} is used, since
2846 * they are supported by all camera devices.</p>
2847 *
2848 * <p>For YV12, the image buffer that is received is not necessarily
2849 * tightly packed, as there may be padding at the end of each row of
2850 * pixel data, as described in
2851 * {@link android.graphics.ImageFormat#YV12}. For camera callback data,
2852 * it can be assumed that the stride of the Y and UV data is the
2853 * smallest possible that meets the alignment requirements. That is, if
2854 * the preview size is <var>width x height</var>, then the following
2855 * equations describe the buffer index for the beginning of row
2856 * <var>y</var> for the Y plane and row <var>c</var> for the U and V
2857 * planes:
2858 *
2859 * {@code
2860 * <pre>
2861 * yStride = (int) ceil(width / 16.0) * 16;
2862 * uvStride = (int) ceil( (yStride / 2) / 16.0) * 16;
2863 * ySize = yStride * height;
2864 * uvSize = uvStride * height / 2;
2865 * yRowIndex = yStride * y;
2866 * uRowIndex = ySize + uvSize + uvStride * c;
2867 * vRowIndex = ySize + uvStride * c;
2868 * size = ySize + uvSize * 2;</pre>
2869 * }
2870 *
2871 * @param pixel_format the desired preview picture format, defined by
2872 * one of the {@link android.graphics.ImageFormat} constants. (E.g.,
2873 * <var>ImageFormat.NV21</var> (default), or
2874 * <var>ImageFormat.YV12</var>)
2875 *
Mathias Agopiana696f5d2010-02-17 17:53:09 -08002876 * @see android.graphics.ImageFormat
Eino-Ville Talvala95151632012-05-02 16:21:18 -07002877 * @see android.hardware.Camera.Parameters#getSupportedPreviewFormats
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002878 */
2879 public void setPreviewFormat(int pixel_format) {
2880 String s = cameraFormatForPixelFormat(pixel_format);
2881 if (s == null) {
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002882 throw new IllegalArgumentException(
2883 "Invalid pixel_format=" + pixel_format);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002884 }
2885
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002886 set(KEY_PREVIEW_FORMAT, s);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002887 }
2888
2889 /**
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08002890 * Returns the image format for preview frames got from
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002891 * {@link PreviewCallback}.
Wu-cheng Li7478ea62009-09-16 18:52:55 +08002892 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08002893 * @return the preview format.
2894 * @see android.graphics.ImageFormat
Eino-Ville Talvala95151632012-05-02 16:21:18 -07002895 * @see #setPreviewFormat
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002896 */
2897 public int getPreviewFormat() {
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002898 return pixelFormatForCameraFormat(get(KEY_PREVIEW_FORMAT));
2899 }
2900
2901 /**
Wu-cheng Lif9293e72011-02-25 13:35:10 +08002902 * Gets the supported preview formats. {@link android.graphics.ImageFormat#NV21}
2903 * is always supported. {@link android.graphics.ImageFormat#YV12}
2904 * is always supported since API level 12.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002905 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08002906 * @return a list of supported preview formats. This method will always
2907 * return a list with at least one element.
2908 * @see android.graphics.ImageFormat
Eino-Ville Talvala95151632012-05-02 16:21:18 -07002909 * @see #setPreviewFormat
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002910 */
2911 public List<Integer> getSupportedPreviewFormats() {
2912 String str = get(KEY_PREVIEW_FORMAT + SUPPORTED_VALUES_SUFFIX);
Chih-Chung Changeb68c462009-09-18 18:37:44 +08002913 ArrayList<Integer> formats = new ArrayList<Integer>();
2914 for (String s : split(str)) {
2915 int f = pixelFormatForCameraFormat(s);
Mathias Agopiana696f5d2010-02-17 17:53:09 -08002916 if (f == ImageFormat.UNKNOWN) continue;
Chih-Chung Changeb68c462009-09-18 18:37:44 +08002917 formats.add(f);
2918 }
2919 return formats;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002920 }
2921
2922 /**
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07002923 * <p>Sets the dimensions for pictures.</p>
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002924 *
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07002925 * <p>Applications need to consider the display orientation. See {@link
2926 * #setPreviewSize(int,int)} for reference.</p>
Wu-cheng Lic157e0c2010-10-07 18:36:07 +08002927 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002928 * @param width the width for pictures, in pixels
2929 * @param height the height for pictures, in pixels
Wu-cheng Lic157e0c2010-10-07 18:36:07 +08002930 * @see #setPreviewSize(int,int)
2931 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002932 */
2933 public void setPictureSize(int width, int height) {
2934 String v = Integer.toString(width) + "x" + Integer.toString(height);
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002935 set(KEY_PICTURE_SIZE, v);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002936 }
2937
2938 /**
2939 * Returns the dimension setting for pictures.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002940 *
2941 * @return a Size object with the height and width setting
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002942 * for pictures
2943 */
2944 public Size getPictureSize() {
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002945 String pair = get(KEY_PICTURE_SIZE);
2946 return strToSize(pair);
2947 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002948
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002949 /**
2950 * Gets the supported picture sizes.
2951 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08002952 * @return a list of supported picture sizes. This method will always
2953 * return a list with at least one element.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002954 */
2955 public List<Size> getSupportedPictureSizes() {
2956 String str = get(KEY_PICTURE_SIZE + SUPPORTED_VALUES_SUFFIX);
2957 return splitSize(str);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002958 }
2959
2960 /**
2961 * Sets the image format for pictures.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002962 *
2963 * @param pixel_format the desired picture format
Mathias Agopiana696f5d2010-02-17 17:53:09 -08002964 * (<var>ImageFormat.NV21</var>,
2965 * <var>ImageFormat.RGB_565</var>, or
2966 * <var>ImageFormat.JPEG</var>)
2967 * @see android.graphics.ImageFormat
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002968 */
2969 public void setPictureFormat(int pixel_format) {
2970 String s = cameraFormatForPixelFormat(pixel_format);
2971 if (s == null) {
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002972 throw new IllegalArgumentException(
2973 "Invalid pixel_format=" + pixel_format);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002974 }
2975
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002976 set(KEY_PICTURE_FORMAT, s);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002977 }
2978
2979 /**
2980 * Returns the image format for pictures.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002981 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08002982 * @return the picture format
2983 * @see android.graphics.ImageFormat
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002984 */
2985 public int getPictureFormat() {
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002986 return pixelFormatForCameraFormat(get(KEY_PICTURE_FORMAT));
2987 }
2988
2989 /**
2990 * Gets the supported picture formats.
2991 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08002992 * @return supported picture formats. This method will always return a
2993 * list with at least one element.
2994 * @see android.graphics.ImageFormat
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002995 */
2996 public List<Integer> getSupportedPictureFormats() {
Wu-cheng Li9c799382009-12-04 19:59:18 +08002997 String str = get(KEY_PICTURE_FORMAT + SUPPORTED_VALUES_SUFFIX);
2998 ArrayList<Integer> formats = new ArrayList<Integer>();
2999 for (String s : split(str)) {
3000 int f = pixelFormatForCameraFormat(s);
Mathias Agopiana696f5d2010-02-17 17:53:09 -08003001 if (f == ImageFormat.UNKNOWN) continue;
Wu-cheng Li9c799382009-12-04 19:59:18 +08003002 formats.add(f);
3003 }
3004 return formats;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003005 }
3006
3007 private String cameraFormatForPixelFormat(int pixel_format) {
3008 switch(pixel_format) {
Mathias Agopiana696f5d2010-02-17 17:53:09 -08003009 case ImageFormat.NV16: return PIXEL_FORMAT_YUV422SP;
3010 case ImageFormat.NV21: return PIXEL_FORMAT_YUV420SP;
3011 case ImageFormat.YUY2: return PIXEL_FORMAT_YUV422I;
Wu-cheng Li10a1b302011-02-22 15:49:25 +08003012 case ImageFormat.YV12: return PIXEL_FORMAT_YUV420P;
Mathias Agopiana696f5d2010-02-17 17:53:09 -08003013 case ImageFormat.RGB_565: return PIXEL_FORMAT_RGB565;
3014 case ImageFormat.JPEG: return PIXEL_FORMAT_JPEG;
3015 default: return null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003016 }
3017 }
3018
3019 private int pixelFormatForCameraFormat(String format) {
3020 if (format == null)
Mathias Agopiana696f5d2010-02-17 17:53:09 -08003021 return ImageFormat.UNKNOWN;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003022
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003023 if (format.equals(PIXEL_FORMAT_YUV422SP))
Mathias Agopiana696f5d2010-02-17 17:53:09 -08003024 return ImageFormat.NV16;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003025
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003026 if (format.equals(PIXEL_FORMAT_YUV420SP))
Mathias Agopiana696f5d2010-02-17 17:53:09 -08003027 return ImageFormat.NV21;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003028
Chih-Chung Changeb68c462009-09-18 18:37:44 +08003029 if (format.equals(PIXEL_FORMAT_YUV422I))
Mathias Agopiana696f5d2010-02-17 17:53:09 -08003030 return ImageFormat.YUY2;
Chih-Chung Changeb68c462009-09-18 18:37:44 +08003031
Wu-cheng Li10a1b302011-02-22 15:49:25 +08003032 if (format.equals(PIXEL_FORMAT_YUV420P))
3033 return ImageFormat.YV12;
3034
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003035 if (format.equals(PIXEL_FORMAT_RGB565))
Mathias Agopiana696f5d2010-02-17 17:53:09 -08003036 return ImageFormat.RGB_565;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003037
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003038 if (format.equals(PIXEL_FORMAT_JPEG))
Mathias Agopiana696f5d2010-02-17 17:53:09 -08003039 return ImageFormat.JPEG;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003040
Mathias Agopiana696f5d2010-02-17 17:53:09 -08003041 return ImageFormat.UNKNOWN;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003042 }
3043
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003044 /**
Wu-cheng Li8969ea12012-04-20 17:38:09 +08003045 * Sets the clockwise rotation angle in degrees relative to the
3046 * orientation of the camera. This affects the pictures returned from
3047 * JPEG {@link PictureCallback}. The camera driver may set orientation
3048 * in the EXIF header without rotating the picture. Or the driver may
3049 * rotate the picture and the EXIF thumbnail. If the Jpeg picture is
Igor Murashkina1b02db2013-06-11 15:25:20 -07003050 * rotated, the orientation in the EXIF header will be missing or 1 (row
3051 * #0 is top and column #0 is left side).
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003052 *
Igor Murashkina1b02db2013-06-11 15:25:20 -07003053 * <p>
3054 * If applications want to rotate the picture to match the orientation
3055 * of what users see, apps should use
3056 * {@link android.view.OrientationEventListener} and
3057 * {@link android.hardware.Camera.CameraInfo}. The value from
3058 * OrientationEventListener is relative to the natural orientation of
3059 * the device. CameraInfo.orientation is the angle between camera
3060 * orientation and natural device orientation. The sum of the two is the
3061 * rotation angle for back-facing camera. The difference of the two is
3062 * the rotation angle for front-facing camera. Note that the JPEG
3063 * pictures of front-facing cameras are not mirrored as in preview
3064 * display.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003065 *
Igor Murashkina1b02db2013-06-11 15:25:20 -07003066 * <p>
3067 * For example, suppose the natural orientation of the device is
Wu-cheng Li2fb818c2010-09-13 20:02:01 -07003068 * portrait. The device is rotated 270 degrees clockwise, so the device
Wu-cheng Li2fe6fca2010-10-15 14:42:23 +08003069 * orientation is 270. Suppose a back-facing camera sensor is mounted in
3070 * landscape and the top side of the camera sensor is aligned with the
3071 * right edge of the display in natural orientation. So the camera
3072 * orientation is 90. The rotation should be set to 0 (270 + 90).
Wu-cheng Li2fb818c2010-09-13 20:02:01 -07003073 *
Brad Fitzpatrick69ea4e12011-01-05 11:13:40 -08003074 * <p>The reference code is as follows.
Wu-cheng Li2fb818c2010-09-13 20:02:01 -07003075 *
Eino-Ville Talvalae0cc55a2011-11-08 10:12:09 -08003076 * <pre>
Scott Main9a10bf02011-08-24 19:09:48 -07003077 * public void onOrientationChanged(int orientation) {
Wu-cheng Li2fb818c2010-09-13 20:02:01 -07003078 * if (orientation == ORIENTATION_UNKNOWN) return;
3079 * android.hardware.Camera.CameraInfo info =
3080 * new android.hardware.Camera.CameraInfo();
3081 * android.hardware.Camera.getCameraInfo(cameraId, info);
3082 * orientation = (orientation + 45) / 90 * 90;
Wu-cheng Li2fe6fca2010-10-15 14:42:23 +08003083 * int rotation = 0;
3084 * if (info.facing == CameraInfo.CAMERA_FACING_FRONT) {
3085 * rotation = (info.orientation - orientation + 360) % 360;
3086 * } else { // back-facing camera
3087 * rotation = (info.orientation + orientation) % 360;
3088 * }
3089 * mParameters.setRotation(rotation);
Wu-cheng Li2fb818c2010-09-13 20:02:01 -07003090 * }
Eino-Ville Talvalae0cc55a2011-11-08 10:12:09 -08003091 * </pre>
Wu-cheng Li2fb818c2010-09-13 20:02:01 -07003092 *
3093 * @param rotation The rotation angle in degrees relative to the
3094 * orientation of the camera. Rotation can only be 0,
3095 * 90, 180 or 270.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003096 * @throws IllegalArgumentException if rotation value is invalid.
3097 * @see android.view.OrientationEventListener
Wu-cheng Li2fb818c2010-09-13 20:02:01 -07003098 * @see #getCameraInfo(int, CameraInfo)
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003099 */
3100 public void setRotation(int rotation) {
3101 if (rotation == 0 || rotation == 90 || rotation == 180
3102 || rotation == 270) {
3103 set(KEY_ROTATION, Integer.toString(rotation));
3104 } else {
3105 throw new IllegalArgumentException(
3106 "Invalid rotation=" + rotation);
3107 }
3108 }
3109
3110 /**
3111 * Sets GPS latitude coordinate. This will be stored in JPEG EXIF
3112 * header.
3113 *
3114 * @param latitude GPS latitude coordinate.
3115 */
3116 public void setGpsLatitude(double latitude) {
3117 set(KEY_GPS_LATITUDE, Double.toString(latitude));
3118 }
3119
3120 /**
3121 * Sets GPS longitude coordinate. This will be stored in JPEG EXIF
3122 * header.
3123 *
3124 * @param longitude GPS longitude coordinate.
3125 */
3126 public void setGpsLongitude(double longitude) {
3127 set(KEY_GPS_LONGITUDE, Double.toString(longitude));
3128 }
3129
3130 /**
3131 * Sets GPS altitude. This will be stored in JPEG EXIF header.
3132 *
3133 * @param altitude GPS altitude in meters.
3134 */
3135 public void setGpsAltitude(double altitude) {
3136 set(KEY_GPS_ALTITUDE, Double.toString(altitude));
3137 }
3138
3139 /**
3140 * Sets GPS timestamp. This will be stored in JPEG EXIF header.
3141 *
3142 * @param timestamp GPS timestamp (UTC in seconds since January 1,
3143 * 1970).
3144 */
3145 public void setGpsTimestamp(long timestamp) {
3146 set(KEY_GPS_TIMESTAMP, Long.toString(timestamp));
3147 }
3148
3149 /**
Ray Chene2083772010-03-10 15:02:49 -08003150 * Sets GPS processing method. It will store up to 32 characters
Ray Chen055c9862010-02-23 10:45:42 +08003151 * in JPEG EXIF header.
3152 *
3153 * @param processing_method The processing method to get this location.
3154 */
3155 public void setGpsProcessingMethod(String processing_method) {
3156 set(KEY_GPS_PROCESSING_METHOD, processing_method);
3157 }
3158
3159 /**
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003160 * Removes GPS latitude, longitude, altitude, and timestamp from the
3161 * parameters.
3162 */
3163 public void removeGpsData() {
3164 remove(KEY_GPS_LATITUDE);
3165 remove(KEY_GPS_LONGITUDE);
3166 remove(KEY_GPS_ALTITUDE);
3167 remove(KEY_GPS_TIMESTAMP);
Ray Chen055c9862010-02-23 10:45:42 +08003168 remove(KEY_GPS_PROCESSING_METHOD);
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003169 }
3170
3171 /**
3172 * Gets the current white balance setting.
3173 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08003174 * @return current white balance. null if white balance setting is not
3175 * supported.
3176 * @see #WHITE_BALANCE_AUTO
3177 * @see #WHITE_BALANCE_INCANDESCENT
3178 * @see #WHITE_BALANCE_FLUORESCENT
3179 * @see #WHITE_BALANCE_WARM_FLUORESCENT
3180 * @see #WHITE_BALANCE_DAYLIGHT
3181 * @see #WHITE_BALANCE_CLOUDY_DAYLIGHT
3182 * @see #WHITE_BALANCE_TWILIGHT
3183 * @see #WHITE_BALANCE_SHADE
3184 *
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003185 */
3186 public String getWhiteBalance() {
3187 return get(KEY_WHITE_BALANCE);
3188 }
3189
3190 /**
Eino-Ville Talvala16b67132011-08-18 13:57:49 -07003191 * Sets the white balance. Changing the setting will release the
Wu-cheng Lib838d8d2011-11-17 20:12:23 +08003192 * auto-white balance lock. It is recommended not to change white
3193 * balance and AWB lock at the same time.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003194 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08003195 * @param value new white balance.
3196 * @see #getWhiteBalance()
Eino-Ville Talvala037abb82011-10-11 12:41:58 -07003197 * @see #setAutoWhiteBalanceLock(boolean)
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003198 */
3199 public void setWhiteBalance(String value) {
Wu-cheng Lib838d8d2011-11-17 20:12:23 +08003200 String oldValue = get(KEY_WHITE_BALANCE);
3201 if (same(value, oldValue)) return;
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003202 set(KEY_WHITE_BALANCE, value);
Eino-Ville Talvala16b67132011-08-18 13:57:49 -07003203 set(KEY_AUTO_WHITEBALANCE_LOCK, FALSE);
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003204 }
3205
3206 /**
3207 * Gets the supported white balance.
3208 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08003209 * @return a list of supported white balance. null if white balance
3210 * setting is not supported.
3211 * @see #getWhiteBalance()
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003212 */
3213 public List<String> getSupportedWhiteBalance() {
3214 String str = get(KEY_WHITE_BALANCE + SUPPORTED_VALUES_SUFFIX);
3215 return split(str);
3216 }
3217
3218 /**
3219 * Gets the current color effect setting.
3220 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08003221 * @return current color effect. null if color effect
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003222 * setting is not supported.
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08003223 * @see #EFFECT_NONE
3224 * @see #EFFECT_MONO
3225 * @see #EFFECT_NEGATIVE
3226 * @see #EFFECT_SOLARIZE
3227 * @see #EFFECT_SEPIA
3228 * @see #EFFECT_POSTERIZE
3229 * @see #EFFECT_WHITEBOARD
3230 * @see #EFFECT_BLACKBOARD
3231 * @see #EFFECT_AQUA
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003232 */
3233 public String getColorEffect() {
3234 return get(KEY_EFFECT);
3235 }
3236
3237 /**
3238 * Sets the current color effect setting.
3239 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08003240 * @param value new color effect.
3241 * @see #getColorEffect()
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003242 */
3243 public void setColorEffect(String value) {
3244 set(KEY_EFFECT, value);
3245 }
3246
3247 /**
3248 * Gets the supported color effects.
3249 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08003250 * @return a list of supported color effects. null if color effect
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003251 * setting is not supported.
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08003252 * @see #getColorEffect()
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003253 */
3254 public List<String> getSupportedColorEffects() {
3255 String str = get(KEY_EFFECT + SUPPORTED_VALUES_SUFFIX);
3256 return split(str);
3257 }
3258
3259
3260 /**
3261 * Gets the current antibanding setting.
3262 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08003263 * @return current antibanding. null if antibanding setting is not
3264 * supported.
3265 * @see #ANTIBANDING_AUTO
3266 * @see #ANTIBANDING_50HZ
3267 * @see #ANTIBANDING_60HZ
3268 * @see #ANTIBANDING_OFF
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003269 */
3270 public String getAntibanding() {
3271 return get(KEY_ANTIBANDING);
3272 }
3273
3274 /**
3275 * Sets the antibanding.
3276 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08003277 * @param antibanding new antibanding value.
3278 * @see #getAntibanding()
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003279 */
3280 public void setAntibanding(String antibanding) {
3281 set(KEY_ANTIBANDING, antibanding);
3282 }
3283
3284 /**
3285 * Gets the supported antibanding values.
3286 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08003287 * @return a list of supported antibanding values. null if antibanding
3288 * setting is not supported.
3289 * @see #getAntibanding()
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003290 */
3291 public List<String> getSupportedAntibanding() {
3292 String str = get(KEY_ANTIBANDING + SUPPORTED_VALUES_SUFFIX);
3293 return split(str);
3294 }
3295
3296 /**
3297 * Gets the current scene mode setting.
3298 *
3299 * @return one of SCENE_MODE_XXX string constant. null if scene mode
3300 * setting is not supported.
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08003301 * @see #SCENE_MODE_AUTO
3302 * @see #SCENE_MODE_ACTION
3303 * @see #SCENE_MODE_PORTRAIT
3304 * @see #SCENE_MODE_LANDSCAPE
3305 * @see #SCENE_MODE_NIGHT
3306 * @see #SCENE_MODE_NIGHT_PORTRAIT
3307 * @see #SCENE_MODE_THEATRE
3308 * @see #SCENE_MODE_BEACH
3309 * @see #SCENE_MODE_SNOW
3310 * @see #SCENE_MODE_SUNSET
3311 * @see #SCENE_MODE_STEADYPHOTO
3312 * @see #SCENE_MODE_FIREWORKS
3313 * @see #SCENE_MODE_SPORTS
3314 * @see #SCENE_MODE_PARTY
3315 * @see #SCENE_MODE_CANDLELIGHT
Eino-Ville Talvalada2f0ea2012-09-10 12:03:35 -07003316 * @see #SCENE_MODE_BARCODE
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003317 */
3318 public String getSceneMode() {
3319 return get(KEY_SCENE_MODE);
3320 }
3321
3322 /**
Wu-cheng Lic58b4232010-03-29 17:21:28 +08003323 * Sets the scene mode. Changing scene mode may override other
3324 * parameters (such as flash mode, focus mode, white balance). For
3325 * example, suppose originally flash mode is on and supported flash
3326 * modes are on/off. In night scene mode, both flash mode and supported
3327 * flash mode may be changed to off. After setting scene mode,
Wu-cheng Li2988ab72009-09-30 17:08:19 -07003328 * applications should call getParameters to know if some parameters are
3329 * changed.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003330 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08003331 * @param value scene mode.
3332 * @see #getSceneMode()
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003333 */
3334 public void setSceneMode(String value) {
3335 set(KEY_SCENE_MODE, value);
3336 }
3337
3338 /**
3339 * Gets the supported scene modes.
3340 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08003341 * @return a list of supported scene modes. null if scene mode setting
3342 * is not supported.
3343 * @see #getSceneMode()
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003344 */
3345 public List<String> getSupportedSceneModes() {
3346 String str = get(KEY_SCENE_MODE + SUPPORTED_VALUES_SUFFIX);
3347 return split(str);
3348 }
3349
3350 /**
3351 * Gets the current flash mode setting.
3352 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08003353 * @return current flash mode. null if flash mode setting is not
3354 * supported.
3355 * @see #FLASH_MODE_OFF
3356 * @see #FLASH_MODE_AUTO
3357 * @see #FLASH_MODE_ON
3358 * @see #FLASH_MODE_RED_EYE
3359 * @see #FLASH_MODE_TORCH
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003360 */
3361 public String getFlashMode() {
3362 return get(KEY_FLASH_MODE);
3363 }
3364
3365 /**
3366 * Sets the flash mode.
3367 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08003368 * @param value flash mode.
3369 * @see #getFlashMode()
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003370 */
3371 public void setFlashMode(String value) {
3372 set(KEY_FLASH_MODE, value);
3373 }
3374
3375 /**
3376 * Gets the supported flash modes.
3377 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08003378 * @return a list of supported flash modes. null if flash mode setting
3379 * is not supported.
3380 * @see #getFlashMode()
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003381 */
3382 public List<String> getSupportedFlashModes() {
3383 String str = get(KEY_FLASH_MODE + SUPPORTED_VALUES_SUFFIX);
3384 return split(str);
3385 }
3386
Wu-cheng Li36322db2009-09-18 18:59:21 +08003387 /**
3388 * Gets the current focus mode setting.
3389 *
Wu-cheng Li699fe932010-08-05 11:50:25 -07003390 * @return current focus mode. This method will always return a non-null
3391 * value. Applications should call {@link
3392 * #autoFocus(AutoFocusCallback)} to start the focus if focus
3393 * mode is FOCUS_MODE_AUTO or FOCUS_MODE_MACRO.
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08003394 * @see #FOCUS_MODE_AUTO
3395 * @see #FOCUS_MODE_INFINITY
3396 * @see #FOCUS_MODE_MACRO
3397 * @see #FOCUS_MODE_FIXED
Wu-cheng Lif008f3e2010-08-17 13:44:35 -07003398 * @see #FOCUS_MODE_EDOF
Wu-cheng Lid45cb722010-09-20 16:15:32 -07003399 * @see #FOCUS_MODE_CONTINUOUS_VIDEO
Wu-cheng Li36322db2009-09-18 18:59:21 +08003400 */
3401 public String getFocusMode() {
3402 return get(KEY_FOCUS_MODE);
3403 }
3404
3405 /**
3406 * Sets the focus mode.
3407 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08003408 * @param value focus mode.
3409 * @see #getFocusMode()
Wu-cheng Li36322db2009-09-18 18:59:21 +08003410 */
3411 public void setFocusMode(String value) {
3412 set(KEY_FOCUS_MODE, value);
3413 }
3414
3415 /**
3416 * Gets the supported focus modes.
3417 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08003418 * @return a list of supported focus modes. This method will always
3419 * return a list with at least one element.
3420 * @see #getFocusMode()
Wu-cheng Li36322db2009-09-18 18:59:21 +08003421 */
3422 public List<String> getSupportedFocusModes() {
3423 String str = get(KEY_FOCUS_MODE + SUPPORTED_VALUES_SUFFIX);
3424 return split(str);
3425 }
3426
Wu-cheng Li36f68b82009-09-28 16:14:58 -07003427 /**
Wu-cheng Li6c8d2762010-01-27 22:55:14 +08003428 * Gets the focal length (in millimeter) of the camera.
3429 *
3430 * @return the focal length. This method will always return a valid
3431 * value.
3432 */
3433 public float getFocalLength() {
3434 return Float.parseFloat(get(KEY_FOCAL_LENGTH));
3435 }
3436
3437 /**
3438 * Gets the horizontal angle of view in degrees.
3439 *
3440 * @return horizontal angle of view. This method will always return a
3441 * valid value.
3442 */
3443 public float getHorizontalViewAngle() {
3444 return Float.parseFloat(get(KEY_HORIZONTAL_VIEW_ANGLE));
3445 }
3446
3447 /**
3448 * Gets the vertical angle of view in degrees.
3449 *
3450 * @return vertical angle of view. This method will always return a
3451 * valid value.
3452 */
3453 public float getVerticalViewAngle() {
3454 return Float.parseFloat(get(KEY_VERTICAL_VIEW_ANGLE));
3455 }
3456
3457 /**
Wu-cheng Li24b326a2010-02-20 17:47:04 +08003458 * Gets the current exposure compensation index.
Wu-cheng Liff723b62010-02-09 13:38:19 +08003459 *
Wu-cheng Li24b326a2010-02-20 17:47:04 +08003460 * @return current exposure compensation index. The range is {@link
3461 * #getMinExposureCompensation} to {@link
3462 * #getMaxExposureCompensation}. 0 means exposure is not
3463 * adjusted.
Wu-cheng Liff723b62010-02-09 13:38:19 +08003464 */
3465 public int getExposureCompensation() {
Wu-cheng Li24b326a2010-02-20 17:47:04 +08003466 return getInt(KEY_EXPOSURE_COMPENSATION, 0);
Wu-cheng Liff723b62010-02-09 13:38:19 +08003467 }
3468
3469 /**
Wu-cheng Li24b326a2010-02-20 17:47:04 +08003470 * Sets the exposure compensation index.
Wu-cheng Liff723b62010-02-09 13:38:19 +08003471 *
Wu-cheng Li0402e7d2010-02-26 15:04:55 +08003472 * @param value exposure compensation index. The valid value range is
3473 * from {@link #getMinExposureCompensation} (inclusive) to {@link
Wu-cheng Li24b326a2010-02-20 17:47:04 +08003474 * #getMaxExposureCompensation} (inclusive). 0 means exposure is
3475 * not adjusted. Application should call
3476 * getMinExposureCompensation and getMaxExposureCompensation to
3477 * know if exposure compensation is supported.
Wu-cheng Liff723b62010-02-09 13:38:19 +08003478 */
3479 public void setExposureCompensation(int value) {
3480 set(KEY_EXPOSURE_COMPENSATION, value);
3481 }
3482
3483 /**
Wu-cheng Li24b326a2010-02-20 17:47:04 +08003484 * Gets the maximum exposure compensation index.
Wu-cheng Liff723b62010-02-09 13:38:19 +08003485 *
Wu-cheng Li24b326a2010-02-20 17:47:04 +08003486 * @return maximum exposure compensation index (>=0). If both this
3487 * method and {@link #getMinExposureCompensation} return 0,
3488 * exposure compensation is not supported.
Wu-cheng Liff723b62010-02-09 13:38:19 +08003489 */
Wu-cheng Li24b326a2010-02-20 17:47:04 +08003490 public int getMaxExposureCompensation() {
3491 return getInt(KEY_MAX_EXPOSURE_COMPENSATION, 0);
3492 }
3493
3494 /**
3495 * Gets the minimum exposure compensation index.
3496 *
3497 * @return minimum exposure compensation index (<=0). If both this
3498 * method and {@link #getMaxExposureCompensation} return 0,
3499 * exposure compensation is not supported.
3500 */
3501 public int getMinExposureCompensation() {
3502 return getInt(KEY_MIN_EXPOSURE_COMPENSATION, 0);
3503 }
3504
3505 /**
3506 * Gets the exposure compensation step.
3507 *
3508 * @return exposure compensation step. Applications can get EV by
3509 * multiplying the exposure compensation index and step. Ex: if
3510 * exposure compensation index is -6 and step is 0.333333333, EV
3511 * is -2.
3512 */
3513 public float getExposureCompensationStep() {
3514 return getFloat(KEY_EXPOSURE_COMPENSATION_STEP, 0);
Wu-cheng Liff723b62010-02-09 13:38:19 +08003515 }
3516
3517 /**
Eino-Ville Talvalad9c2601a2011-05-13 10:19:59 -07003518 * <p>Sets the auto-exposure lock state. Applications should check
3519 * {@link #isAutoExposureLockSupported} before using this method.</p>
Eino-Ville Talvala3773eef2011-04-15 13:51:42 -07003520 *
Eino-Ville Talvalad9c2601a2011-05-13 10:19:59 -07003521 * <p>If set to true, the camera auto-exposure routine will immediately
3522 * pause until the lock is set to false. Exposure compensation settings
3523 * changes will still take effect while auto-exposure is locked.</p>
3524 *
3525 * <p>If auto-exposure is already locked, setting this to true again has
3526 * no effect (the driver will not recalculate exposure values).</p>
3527 *
3528 * <p>Stopping preview with {@link #stopPreview()}, or triggering still
3529 * image capture with {@link #takePicture(Camera.ShutterCallback,
Wu-cheng Lib4f95be2011-09-22 11:43:28 +08003530 * Camera.PictureCallback, Camera.PictureCallback)}, will not change the
3531 * lock.</p>
Eino-Ville Talvalad9c2601a2011-05-13 10:19:59 -07003532 *
Wu-cheng Lib4f95be2011-09-22 11:43:28 +08003533 * <p>Exposure compensation, auto-exposure lock, and auto-white balance
3534 * lock can be used to capture an exposure-bracketed burst of images,
3535 * for example.</p>
Eino-Ville Talvalad9c2601a2011-05-13 10:19:59 -07003536 *
3537 * <p>Auto-exposure state, including the lock state, will not be
Eino-Ville Talvala3773eef2011-04-15 13:51:42 -07003538 * maintained after camera {@link #release()} is called. Locking
3539 * auto-exposure after {@link #open()} but before the first call to
3540 * {@link #startPreview()} will not allow the auto-exposure routine to
Eino-Ville Talvalad9c2601a2011-05-13 10:19:59 -07003541 * run at all, and may result in severely over- or under-exposed
3542 * images.</p>
Eino-Ville Talvala3773eef2011-04-15 13:51:42 -07003543 *
Eino-Ville Talvala3773eef2011-04-15 13:51:42 -07003544 * @param toggle new state of the auto-exposure lock. True means that
3545 * auto-exposure is locked, false means that the auto-exposure
3546 * routine is free to run normally.
3547 *
Eino-Ville Talvalad9c2601a2011-05-13 10:19:59 -07003548 * @see #getAutoExposureLock()
Eino-Ville Talvala3773eef2011-04-15 13:51:42 -07003549 */
3550 public void setAutoExposureLock(boolean toggle) {
3551 set(KEY_AUTO_EXPOSURE_LOCK, toggle ? TRUE : FALSE);
3552 }
3553
3554 /**
3555 * Gets the state of the auto-exposure lock. Applications should check
3556 * {@link #isAutoExposureLockSupported} before using this method. See
3557 * {@link #setAutoExposureLock} for details about the lock.
3558 *
3559 * @return State of the auto-exposure lock. Returns true if
Wu-cheng Lib4f95be2011-09-22 11:43:28 +08003560 * auto-exposure is currently locked, and false otherwise.
Eino-Ville Talvala3773eef2011-04-15 13:51:42 -07003561 *
3562 * @see #setAutoExposureLock(boolean)
3563 *
Eino-Ville Talvala3773eef2011-04-15 13:51:42 -07003564 */
3565 public boolean getAutoExposureLock() {
3566 String str = get(KEY_AUTO_EXPOSURE_LOCK);
3567 return TRUE.equals(str);
3568 }
3569
3570 /**
3571 * Returns true if auto-exposure locking is supported. Applications
3572 * should call this before trying to lock auto-exposure. See
3573 * {@link #setAutoExposureLock} for details about the lock.
3574 *
3575 * @return true if auto-exposure lock is supported.
3576 * @see #setAutoExposureLock(boolean)
3577 *
Eino-Ville Talvala3773eef2011-04-15 13:51:42 -07003578 */
3579 public boolean isAutoExposureLockSupported() {
3580 String str = get(KEY_AUTO_EXPOSURE_LOCK_SUPPORTED);
3581 return TRUE.equals(str);
3582 }
3583
3584 /**
Eino-Ville Talvalad9c2601a2011-05-13 10:19:59 -07003585 * <p>Sets the auto-white balance lock state. Applications should check
3586 * {@link #isAutoWhiteBalanceLockSupported} before using this
3587 * method.</p>
3588 *
3589 * <p>If set to true, the camera auto-white balance routine will
3590 * immediately pause until the lock is set to false.</p>
3591 *
3592 * <p>If auto-white balance is already locked, setting this to true
3593 * again has no effect (the driver will not recalculate white balance
3594 * values).</p>
3595 *
3596 * <p>Stopping preview with {@link #stopPreview()}, or triggering still
3597 * image capture with {@link #takePicture(Camera.ShutterCallback,
Wu-cheng Lib4f95be2011-09-22 11:43:28 +08003598 * Camera.PictureCallback, Camera.PictureCallback)}, will not change the
3599 * the lock.</p>
Eino-Ville Talvalad9c2601a2011-05-13 10:19:59 -07003600 *
Eino-Ville Talvala16b67132011-08-18 13:57:49 -07003601 * <p> Changing the white balance mode with {@link #setWhiteBalance}
3602 * will release the auto-white balance lock if it is set.</p>
3603 *
Wu-cheng Lib4f95be2011-09-22 11:43:28 +08003604 * <p>Exposure compensation, AE lock, and AWB lock can be used to
3605 * capture an exposure-bracketed burst of images, for example.
3606 * Auto-white balance state, including the lock state, will not be
3607 * maintained after camera {@link #release()} is called. Locking
3608 * auto-white balance after {@link #open()} but before the first call to
3609 * {@link #startPreview()} will not allow the auto-white balance routine
3610 * to run at all, and may result in severely incorrect color in captured
3611 * images.</p>
Eino-Ville Talvalad9c2601a2011-05-13 10:19:59 -07003612 *
3613 * @param toggle new state of the auto-white balance lock. True means
3614 * that auto-white balance is locked, false means that the
3615 * auto-white balance routine is free to run normally.
3616 *
3617 * @see #getAutoWhiteBalanceLock()
Eino-Ville Talvala16b67132011-08-18 13:57:49 -07003618 * @see #setWhiteBalance(String)
Eino-Ville Talvalad9c2601a2011-05-13 10:19:59 -07003619 */
3620 public void setAutoWhiteBalanceLock(boolean toggle) {
3621 set(KEY_AUTO_WHITEBALANCE_LOCK, toggle ? TRUE : FALSE);
3622 }
3623
3624 /**
3625 * Gets the state of the auto-white balance lock. Applications should
3626 * check {@link #isAutoWhiteBalanceLockSupported} before using this
3627 * method. See {@link #setAutoWhiteBalanceLock} for details about the
3628 * lock.
3629 *
3630 * @return State of the auto-white balance lock. Returns true if
3631 * auto-white balance is currently locked, and false
Wu-cheng Lib4f95be2011-09-22 11:43:28 +08003632 * otherwise.
Eino-Ville Talvalad9c2601a2011-05-13 10:19:59 -07003633 *
3634 * @see #setAutoWhiteBalanceLock(boolean)
3635 *
Eino-Ville Talvalad9c2601a2011-05-13 10:19:59 -07003636 */
3637 public boolean getAutoWhiteBalanceLock() {
3638 String str = get(KEY_AUTO_WHITEBALANCE_LOCK);
3639 return TRUE.equals(str);
3640 }
3641
3642 /**
3643 * Returns true if auto-white balance locking is supported. Applications
3644 * should call this before trying to lock auto-white balance. See
3645 * {@link #setAutoWhiteBalanceLock} for details about the lock.
3646 *
3647 * @return true if auto-white balance lock is supported.
3648 * @see #setAutoWhiteBalanceLock(boolean)
3649 *
Eino-Ville Talvalad9c2601a2011-05-13 10:19:59 -07003650 */
3651 public boolean isAutoWhiteBalanceLockSupported() {
3652 String str = get(KEY_AUTO_WHITEBALANCE_LOCK_SUPPORTED);
3653 return TRUE.equals(str);
3654 }
3655
3656 /**
Wu-cheng Li36f68b82009-09-28 16:14:58 -07003657 * Gets current zoom value. This also works when smooth zoom is in
Wu-cheng Li8cbb8f52010-02-28 23:19:55 -08003658 * progress. Applications should check {@link #isZoomSupported} before
3659 * using this method.
Wu-cheng Li36f68b82009-09-28 16:14:58 -07003660 *
3661 * @return the current zoom value. The range is 0 to {@link
Wu-cheng Li8cbb8f52010-02-28 23:19:55 -08003662 * #getMaxZoom}. 0 means the camera is not zoomed.
Wu-cheng Li36f68b82009-09-28 16:14:58 -07003663 */
3664 public int getZoom() {
Wu-cheng Li8cbb8f52010-02-28 23:19:55 -08003665 return getInt(KEY_ZOOM, 0);
Wu-cheng Li36f68b82009-09-28 16:14:58 -07003666 }
3667
3668 /**
Wu-cheng Li8cbb8f52010-02-28 23:19:55 -08003669 * Sets current zoom value. If the camera is zoomed (value > 0), the
3670 * actual picture size may be smaller than picture size setting.
3671 * Applications can check the actual picture size after picture is
3672 * returned from {@link PictureCallback}. The preview size remains the
3673 * same in zoom. Applications should check {@link #isZoomSupported}
3674 * before using this method.
Wu-cheng Li36f68b82009-09-28 16:14:58 -07003675 *
3676 * @param value zoom value. The valid range is 0 to {@link #getMaxZoom}.
Wu-cheng Li36f68b82009-09-28 16:14:58 -07003677 */
3678 public void setZoom(int value) {
Wu-cheng Li8cbb8f52010-02-28 23:19:55 -08003679 set(KEY_ZOOM, value);
Wu-cheng Li36f68b82009-09-28 16:14:58 -07003680 }
3681
3682 /**
3683 * Returns true if zoom is supported. Applications should call this
3684 * before using other zoom methods.
3685 *
3686 * @return true if zoom is supported.
Wu-cheng Li36f68b82009-09-28 16:14:58 -07003687 */
3688 public boolean isZoomSupported() {
Wu-cheng Li8cbb8f52010-02-28 23:19:55 -08003689 String str = get(KEY_ZOOM_SUPPORTED);
3690 return TRUE.equals(str);
Wu-cheng Li36f68b82009-09-28 16:14:58 -07003691 }
3692
3693 /**
3694 * Gets the maximum zoom value allowed for snapshot. This is the maximum
3695 * value that applications can set to {@link #setZoom(int)}.
Wu-cheng Li8cbb8f52010-02-28 23:19:55 -08003696 * Applications should call {@link #isZoomSupported} before using this
3697 * method. This value may change in different preview size. Applications
3698 * should call this again after setting preview size.
Wu-cheng Li36f68b82009-09-28 16:14:58 -07003699 *
3700 * @return the maximum zoom value supported by the camera.
Wu-cheng Li36f68b82009-09-28 16:14:58 -07003701 */
3702 public int getMaxZoom() {
Wu-cheng Li8cbb8f52010-02-28 23:19:55 -08003703 return getInt(KEY_MAX_ZOOM, 0);
Wu-cheng Li36f68b82009-09-28 16:14:58 -07003704 }
3705
3706 /**
Wu-cheng Li8cbb8f52010-02-28 23:19:55 -08003707 * Gets the zoom ratios of all zoom values. Applications should check
3708 * {@link #isZoomSupported} before using this method.
Wu-cheng Li36f68b82009-09-28 16:14:58 -07003709 *
Wu-cheng Li8cbb8f52010-02-28 23:19:55 -08003710 * @return the zoom ratios in 1/100 increments. Ex: a zoom of 3.2x is
3711 * returned as 320. The number of elements is {@link
3712 * #getMaxZoom} + 1. The list is sorted from small to large. The
3713 * first element is always 100. The last element is the zoom
3714 * ratio of the maximum zoom value.
Wu-cheng Li36f68b82009-09-28 16:14:58 -07003715 */
Wu-cheng Li8cbb8f52010-02-28 23:19:55 -08003716 public List<Integer> getZoomRatios() {
3717 return splitInt(get(KEY_ZOOM_RATIOS));
Wu-cheng Li36f68b82009-09-28 16:14:58 -07003718 }
3719
3720 /**
3721 * Returns true if smooth zoom is supported. Applications should call
3722 * this before using other smooth zoom methods.
3723 *
3724 * @return true if smooth zoom is supported.
Wu-cheng Li36f68b82009-09-28 16:14:58 -07003725 */
3726 public boolean isSmoothZoomSupported() {
Wu-cheng Li8cbb8f52010-02-28 23:19:55 -08003727 String str = get(KEY_SMOOTH_ZOOM_SUPPORTED);
3728 return TRUE.equals(str);
Wu-cheng Li36f68b82009-09-28 16:14:58 -07003729 }
3730
Wu-cheng Lie339c5e2010-05-13 19:31:02 +08003731 /**
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07003732 * <p>Gets the distances from the camera to where an object appears to be
Wu-cheng Lie339c5e2010-05-13 19:31:02 +08003733 * in focus. The object is sharpest at the optimal focus distance. The
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07003734 * depth of field is the far focus distance minus near focus distance.</p>
Wu-cheng Lie339c5e2010-05-13 19:31:02 +08003735 *
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07003736 * <p>Focus distances may change after calling {@link
Wu-cheng Lie339c5e2010-05-13 19:31:02 +08003737 * #autoFocus(AutoFocusCallback)}, {@link #cancelAutoFocus}, or {@link
3738 * #startPreview()}. Applications can call {@link #getParameters()}
3739 * and this method anytime to get the latest focus distances. If the
Wu-cheng Lid45cb722010-09-20 16:15:32 -07003740 * focus mode is FOCUS_MODE_CONTINUOUS_VIDEO, focus distances may change
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07003741 * from time to time.</p>
Wu-cheng Li699fe932010-08-05 11:50:25 -07003742 *
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07003743 * <p>This method is intended to estimate the distance between the camera
Wu-cheng Li699fe932010-08-05 11:50:25 -07003744 * and the subject. After autofocus, the subject distance may be within
3745 * near and far focus distance. However, the precision depends on the
3746 * camera hardware, autofocus algorithm, the focus area, and the scene.
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07003747 * The error can be large and it should be only used as a reference.</p>
Wu-cheng Lie339c5e2010-05-13 19:31:02 +08003748 *
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07003749 * <p>Far focus distance >= optimal focus distance >= near focus distance.
Wu-cheng Li185cc452010-05-20 15:36:13 +08003750 * If the focus distance is infinity, the value will be
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07003751 * {@code Float.POSITIVE_INFINITY}.</p>
Wu-cheng Lie339c5e2010-05-13 19:31:02 +08003752 *
3753 * @param output focus distances in meters. output must be a float
3754 * array with three elements. Near focus distance, optimal focus
3755 * distance, and far focus distance will be filled in the array.
Wu-cheng Li185cc452010-05-20 15:36:13 +08003756 * @see #FOCUS_DISTANCE_NEAR_INDEX
3757 * @see #FOCUS_DISTANCE_OPTIMAL_INDEX
3758 * @see #FOCUS_DISTANCE_FAR_INDEX
Wu-cheng Lie339c5e2010-05-13 19:31:02 +08003759 */
3760 public void getFocusDistances(float[] output) {
3761 if (output == null || output.length != 3) {
3762 throw new IllegalArgumentException(
Ken Wakasaf76a50c2012-03-09 19:56:35 +09003763 "output must be a float array with three elements.");
Wu-cheng Lie339c5e2010-05-13 19:31:02 +08003764 }
Wu-cheng Li454630f2010-08-11 16:48:05 -07003765 splitFloat(get(KEY_FOCUS_DISTANCES), output);
Wu-cheng Lie339c5e2010-05-13 19:31:02 +08003766 }
3767
Wu-cheng Li30771b72011-04-02 06:19:46 +08003768 /**
3769 * Gets the maximum number of focus areas supported. This is the maximum
Wu-cheng Li7b1c5c82011-04-15 19:16:52 +08003770 * length of the list in {@link #setFocusAreas(List)} and
3771 * {@link #getFocusAreas()}.
Wu-cheng Li30771b72011-04-02 06:19:46 +08003772 *
3773 * @return the maximum number of focus areas supported by the camera.
3774 * @see #getFocusAreas()
Wu-cheng Li30771b72011-04-02 06:19:46 +08003775 */
3776 public int getMaxNumFocusAreas() {
3777 return getInt(KEY_MAX_NUM_FOCUS_AREAS, 0);
3778 }
3779
3780 /**
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07003781 * <p>Gets the current focus areas. Camera driver uses the areas to decide
3782 * focus.</p>
Wu-cheng Li30771b72011-04-02 06:19:46 +08003783 *
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07003784 * <p>Before using this API or {@link #setFocusAreas(List)}, apps should
Wu-cheng Li7b1c5c82011-04-15 19:16:52 +08003785 * call {@link #getMaxNumFocusAreas()} to know the maximum number of
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07003786 * focus areas first. If the value is 0, focus area is not supported.</p>
Wu-cheng Li30771b72011-04-02 06:19:46 +08003787 *
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07003788 * <p>Each focus area is a rectangle with specified weight. The direction
Wu-cheng Li30771b72011-04-02 06:19:46 +08003789 * is relative to the sensor orientation, that is, what the sensor sees.
3790 * The direction is not affected by the rotation or mirroring of
3791 * {@link #setDisplayOrientation(int)}. Coordinates of the rectangle
3792 * range from -1000 to 1000. (-1000, -1000) is the upper left point.
Wu-cheng Libde61a52011-06-07 18:23:14 +08003793 * (1000, 1000) is the lower right point. The width and height of focus
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07003794 * areas cannot be 0 or negative.</p>
Wu-cheng Li30771b72011-04-02 06:19:46 +08003795 *
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07003796 * <p>The weight must range from 1 to 1000. The weight should be
Eino-Ville Talvala4e396e02011-04-21 09:23:15 -07003797 * interpreted as a per-pixel weight - all pixels in the area have the
3798 * specified weight. This means a small area with the same weight as a
3799 * larger area will have less influence on the focusing than the larger
3800 * area. Focus areas can partially overlap and the driver will add the
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07003801 * weights in the overlap region.</p>
Wu-cheng Li30771b72011-04-02 06:19:46 +08003802 *
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07003803 * <p>A special case of a {@code null} focus area list means the driver is
3804 * free to select focus targets as it wants. For example, the driver may
3805 * use more signals to select focus areas and change them
3806 * dynamically. Apps can set the focus area list to {@code null} if they
3807 * want the driver to completely control focusing.</p>
Wu-cheng Li30771b72011-04-02 06:19:46 +08003808 *
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07003809 * <p>Focus areas are relative to the current field of view
Wu-cheng Li30771b72011-04-02 06:19:46 +08003810 * ({@link #getZoom()}). No matter what the zoom level is, (-1000,-1000)
3811 * represents the top of the currently visible camera frame. The focus
3812 * area cannot be set to be outside the current field of view, even
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07003813 * when using zoom.</p>
Wu-cheng Li30771b72011-04-02 06:19:46 +08003814 *
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07003815 * <p>Focus area only has effect if the current focus mode is
Wu-cheng Li53b30912011-10-12 19:43:51 +08003816 * {@link #FOCUS_MODE_AUTO}, {@link #FOCUS_MODE_MACRO},
3817 * {@link #FOCUS_MODE_CONTINUOUS_VIDEO}, or
3818 * {@link #FOCUS_MODE_CONTINUOUS_PICTURE}.</p>
Wu-cheng Li30771b72011-04-02 06:19:46 +08003819 *
3820 * @return a list of current focus areas
Wu-cheng Li30771b72011-04-02 06:19:46 +08003821 */
3822 public List<Area> getFocusAreas() {
Wu-cheng Lif715bf92011-04-14 14:04:18 +08003823 return splitArea(get(KEY_FOCUS_AREAS));
Wu-cheng Li30771b72011-04-02 06:19:46 +08003824 }
3825
3826 /**
3827 * Sets focus areas. See {@link #getFocusAreas()} for documentation.
3828 *
Wu-cheng Li7b1c5c82011-04-15 19:16:52 +08003829 * @param focusAreas the focus areas
Wu-cheng Li30771b72011-04-02 06:19:46 +08003830 * @see #getFocusAreas()
Wu-cheng Li30771b72011-04-02 06:19:46 +08003831 */
Wu-cheng Lie98e4c82011-04-12 19:34:29 +08003832 public void setFocusAreas(List<Area> focusAreas) {
3833 set(KEY_FOCUS_AREAS, focusAreas);
3834 }
3835
3836 /**
3837 * Gets the maximum number of metering areas supported. This is the
Wu-cheng Li7b1c5c82011-04-15 19:16:52 +08003838 * maximum length of the list in {@link #setMeteringAreas(List)} and
3839 * {@link #getMeteringAreas()}.
Wu-cheng Lie98e4c82011-04-12 19:34:29 +08003840 *
3841 * @return the maximum number of metering areas supported by the camera.
3842 * @see #getMeteringAreas()
Wu-cheng Lie98e4c82011-04-12 19:34:29 +08003843 */
3844 public int getMaxNumMeteringAreas() {
3845 return getInt(KEY_MAX_NUM_METERING_AREAS, 0);
3846 }
3847
3848 /**
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07003849 * <p>Gets the current metering areas. Camera driver uses these areas to
3850 * decide exposure.</p>
Wu-cheng Lie98e4c82011-04-12 19:34:29 +08003851 *
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07003852 * <p>Before using this API or {@link #setMeteringAreas(List)}, apps should
Wu-cheng Li7b1c5c82011-04-15 19:16:52 +08003853 * call {@link #getMaxNumMeteringAreas()} to know the maximum number of
3854 * metering areas first. If the value is 0, metering area is not
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07003855 * supported.</p>
Wu-cheng Lie98e4c82011-04-12 19:34:29 +08003856 *
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07003857 * <p>Each metering area is a rectangle with specified weight. The
Wu-cheng Lie98e4c82011-04-12 19:34:29 +08003858 * direction is relative to the sensor orientation, that is, what the
3859 * sensor sees. The direction is not affected by the rotation or
3860 * mirroring of {@link #setDisplayOrientation(int)}. Coordinates of the
3861 * rectangle range from -1000 to 1000. (-1000, -1000) is the upper left
Wu-cheng Libde61a52011-06-07 18:23:14 +08003862 * point. (1000, 1000) is the lower right point. The width and height of
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07003863 * metering areas cannot be 0 or negative.</p>
Wu-cheng Lie98e4c82011-04-12 19:34:29 +08003864 *
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07003865 * <p>The weight must range from 1 to 1000, and represents a weight for
Eino-Ville Talvala4e396e02011-04-21 09:23:15 -07003866 * every pixel in the area. This means that a large metering area with
3867 * the same weight as a smaller area will have more effect in the
3868 * metering result. Metering areas can partially overlap and the driver
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07003869 * will add the weights in the overlap region.</p>
Wu-cheng Lie98e4c82011-04-12 19:34:29 +08003870 *
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07003871 * <p>A special case of a {@code null} metering area list means the driver
3872 * is free to meter as it chooses. For example, the driver may use more
3873 * signals to select metering areas and change them dynamically. Apps
3874 * can set the metering area list to {@code null} if they want the
3875 * driver to completely control metering.</p>
Wu-cheng Lie98e4c82011-04-12 19:34:29 +08003876 *
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07003877 * <p>Metering areas are relative to the current field of view
Wu-cheng Lie98e4c82011-04-12 19:34:29 +08003878 * ({@link #getZoom()}). No matter what the zoom level is, (-1000,-1000)
3879 * represents the top of the currently visible camera frame. The
3880 * metering area cannot be set to be outside the current field of view,
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07003881 * even when using zoom.</p>
Wu-cheng Lie98e4c82011-04-12 19:34:29 +08003882 *
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07003883 * <p>No matter what metering areas are, the final exposure are compensated
3884 * by {@link #setExposureCompensation(int)}.</p>
Wu-cheng Lie98e4c82011-04-12 19:34:29 +08003885 *
3886 * @return a list of current metering areas
Wu-cheng Lie98e4c82011-04-12 19:34:29 +08003887 */
3888 public List<Area> getMeteringAreas() {
Wu-cheng Lid8aab932011-06-21 11:50:43 +08003889 return splitArea(get(KEY_METERING_AREAS));
Wu-cheng Lie98e4c82011-04-12 19:34:29 +08003890 }
3891
3892 /**
3893 * Sets metering areas. See {@link #getMeteringAreas()} for
3894 * documentation.
3895 *
Wu-cheng Li7b1c5c82011-04-15 19:16:52 +08003896 * @param meteringAreas the metering areas
Wu-cheng Lie98e4c82011-04-12 19:34:29 +08003897 * @see #getMeteringAreas()
Wu-cheng Lie98e4c82011-04-12 19:34:29 +08003898 */
3899 public void setMeteringAreas(List<Area> meteringAreas) {
3900 set(KEY_METERING_AREAS, meteringAreas);
Wu-cheng Li30771b72011-04-02 06:19:46 +08003901 }
3902
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08003903 /**
3904 * Gets the maximum number of detected faces supported. This is the
3905 * maximum length of the list returned from {@link FaceDetectionListener}.
3906 * If the return value is 0, face detection of the specified type is not
3907 * supported.
3908 *
3909 * @return the maximum number of detected face supported by the camera.
Joe Fernandez464cb212011-10-04 16:56:47 -07003910 * @see #startFaceDetection()
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08003911 */
Wu-cheng Lic0c683b2011-08-04 00:11:00 +08003912 public int getMaxNumDetectedFaces() {
3913 return getInt(KEY_MAX_NUM_DETECTED_FACES_HW, 0);
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08003914 }
3915
Wu-cheng Li25d8fb52011-08-02 13:20:36 +08003916 /**
Wu-cheng Li9c53f1c2011-08-02 17:26:58 +08003917 * Sets recording mode hint. This tells the camera that the intent of
3918 * the application is to record videos {@link
3919 * android.media.MediaRecorder#start()}, not to take still pictures
3920 * {@link #takePicture(Camera.ShutterCallback, Camera.PictureCallback,
3921 * Camera.PictureCallback, Camera.PictureCallback)}. Using this hint can
3922 * allow MediaRecorder.start() to start faster or with fewer glitches on
3923 * output. This should be called before starting preview for the best
3924 * result, but can be changed while the preview is active. The default
3925 * value is false.
Wu-cheng Li25d8fb52011-08-02 13:20:36 +08003926 *
Wu-cheng Li9c53f1c2011-08-02 17:26:58 +08003927 * The app can still call takePicture() when the hint is true or call
3928 * MediaRecorder.start() when the hint is false. But the performance may
3929 * be worse.
Wu-cheng Li25d8fb52011-08-02 13:20:36 +08003930 *
Wu-cheng Li9c53f1c2011-08-02 17:26:58 +08003931 * @param hint true if the apps intend to record videos using
Wu-cheng Li25d8fb52011-08-02 13:20:36 +08003932 * {@link android.media.MediaRecorder}.
Wu-cheng Li25d8fb52011-08-02 13:20:36 +08003933 */
3934 public void setRecordingHint(boolean hint) {
3935 set(KEY_RECORDING_HINT, hint ? TRUE : FALSE);
3936 }
3937
Wu-cheng Li98bb2512011-08-30 21:33:10 +08003938 /**
Eino-Ville Talvala1cab31a2012-11-05 10:33:55 -08003939 * <p>Returns true if video snapshot is supported. That is, applications
Wu-cheng Li98bb2512011-08-30 21:33:10 +08003940 * can call {@link #takePicture(Camera.ShutterCallback,
Eino-Ville Talvala1cab31a2012-11-05 10:33:55 -08003941 * Camera.PictureCallback, Camera.PictureCallback,
3942 * Camera.PictureCallback)} during recording. Applications do not need
3943 * to call {@link #startPreview()} after taking a picture. The preview
3944 * will be still active. Other than that, taking a picture during
3945 * recording is identical to taking a picture normally. All settings and
3946 * methods related to takePicture work identically. Ex:
3947 * {@link #getPictureSize()}, {@link #getSupportedPictureSizes()},
3948 * {@link #setJpegQuality(int)}, {@link #setRotation(int)}, and etc. The
3949 * picture will have an EXIF header. {@link #FLASH_MODE_AUTO} and
3950 * {@link #FLASH_MODE_ON} also still work, but the video will record the
3951 * flash.</p>
Wu-cheng Li98bb2512011-08-30 21:33:10 +08003952 *
Eino-Ville Talvala1cab31a2012-11-05 10:33:55 -08003953 * <p>Applications can set shutter callback as null to avoid the shutter
Wu-cheng Li98bb2512011-08-30 21:33:10 +08003954 * sound. It is also recommended to set raw picture and post view
Eino-Ville Talvala1cab31a2012-11-05 10:33:55 -08003955 * callbacks to null to avoid the interrupt of preview display.</p>
Wu-cheng Li98bb2512011-08-30 21:33:10 +08003956 *
Eino-Ville Talvala1cab31a2012-11-05 10:33:55 -08003957 * <p>Field-of-view of the recorded video may be different from that of the
3958 * captured pictures. The maximum size of a video snapshot may be
3959 * smaller than that for regular still captures. If the current picture
3960 * size is set higher than can be supported by video snapshot, the
3961 * picture will be captured at the maximum supported size instead.</p>
Wu-cheng Li98bb2512011-08-30 21:33:10 +08003962 *
3963 * @return true if video snapshot is supported.
Wu-cheng Li98bb2512011-08-30 21:33:10 +08003964 */
3965 public boolean isVideoSnapshotSupported() {
3966 String str = get(KEY_VIDEO_SNAPSHOT_SUPPORTED);
3967 return TRUE.equals(str);
3968 }
3969
Eino-Ville Talvala037abb82011-10-11 12:41:58 -07003970 /**
3971 * <p>Enables and disables video stabilization. Use
3972 * {@link #isVideoStabilizationSupported} to determine if calling this
3973 * method is valid.</p>
3974 *
3975 * <p>Video stabilization reduces the shaking due to the motion of the
3976 * camera in both the preview stream and in recorded videos, including
3977 * data received from the preview callback. It does not reduce motion
3978 * blur in images captured with
3979 * {@link Camera#takePicture takePicture}.</p>
3980 *
3981 * <p>Video stabilization can be enabled and disabled while preview or
3982 * recording is active, but toggling it may cause a jump in the video
3983 * stream that may be undesirable in a recorded video.</p>
3984 *
3985 * @param toggle Set to true to enable video stabilization, and false to
3986 * disable video stabilization.
3987 * @see #isVideoStabilizationSupported()
3988 * @see #getVideoStabilization()
Eino-Ville Talvala037abb82011-10-11 12:41:58 -07003989 */
3990 public void setVideoStabilization(boolean toggle) {
3991 set(KEY_VIDEO_STABILIZATION, toggle ? TRUE : FALSE);
3992 }
3993
3994 /**
3995 * Get the current state of video stabilization. See
3996 * {@link #setVideoStabilization} for details of video stabilization.
3997 *
3998 * @return true if video stabilization is enabled
3999 * @see #isVideoStabilizationSupported()
4000 * @see #setVideoStabilization(boolean)
Eino-Ville Talvala037abb82011-10-11 12:41:58 -07004001 */
4002 public boolean getVideoStabilization() {
4003 String str = get(KEY_VIDEO_STABILIZATION);
4004 return TRUE.equals(str);
4005 }
4006
4007 /**
4008 * Returns true if video stabilization is supported. See
4009 * {@link #setVideoStabilization} for details of video stabilization.
4010 *
4011 * @return true if video stabilization is supported
4012 * @see #setVideoStabilization(boolean)
4013 * @see #getVideoStabilization()
Eino-Ville Talvala037abb82011-10-11 12:41:58 -07004014 */
4015 public boolean isVideoStabilizationSupported() {
4016 String str = get(KEY_VIDEO_STABILIZATION_SUPPORTED);
4017 return TRUE.equals(str);
4018 }
4019
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08004020 // Splits a comma delimited string to an ArrayList of String.
4021 // Return null if the passing string is null or the size is 0.
4022 private ArrayList<String> split(String str) {
4023 if (str == null) return null;
4024
Ali Utku Selen0a120182011-02-09 14:11:22 +01004025 TextUtils.StringSplitter splitter = new TextUtils.SimpleStringSplitter(',');
4026 splitter.setString(str);
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08004027 ArrayList<String> substrings = new ArrayList<String>();
Ali Utku Selen0a120182011-02-09 14:11:22 +01004028 for (String s : splitter) {
4029 substrings.add(s);
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08004030 }
4031 return substrings;
4032 }
4033
4034 // Splits a comma delimited string to an ArrayList of Integer.
4035 // Return null if the passing string is null or the size is 0.
4036 private ArrayList<Integer> splitInt(String str) {
4037 if (str == null) return null;
4038
Ali Utku Selen0a120182011-02-09 14:11:22 +01004039 TextUtils.StringSplitter splitter = new TextUtils.SimpleStringSplitter(',');
4040 splitter.setString(str);
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08004041 ArrayList<Integer> substrings = new ArrayList<Integer>();
Ali Utku Selen0a120182011-02-09 14:11:22 +01004042 for (String s : splitter) {
4043 substrings.add(Integer.parseInt(s));
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08004044 }
4045 if (substrings.size() == 0) return null;
4046 return substrings;
4047 }
4048
Wu-cheng Li454630f2010-08-11 16:48:05 -07004049 private void splitInt(String str, int[] output) {
4050 if (str == null) return;
Wu-cheng Lie339c5e2010-05-13 19:31:02 +08004051
Ali Utku Selen0a120182011-02-09 14:11:22 +01004052 TextUtils.StringSplitter splitter = new TextUtils.SimpleStringSplitter(',');
4053 splitter.setString(str);
Wu-cheng Li454630f2010-08-11 16:48:05 -07004054 int index = 0;
Ali Utku Selen0a120182011-02-09 14:11:22 +01004055 for (String s : splitter) {
4056 output[index++] = Integer.parseInt(s);
Wu-cheng Lie339c5e2010-05-13 19:31:02 +08004057 }
Wu-cheng Li454630f2010-08-11 16:48:05 -07004058 }
4059
4060 // Splits a comma delimited string to an ArrayList of Float.
4061 private void splitFloat(String str, float[] output) {
4062 if (str == null) return;
4063
Ali Utku Selen0a120182011-02-09 14:11:22 +01004064 TextUtils.StringSplitter splitter = new TextUtils.SimpleStringSplitter(',');
4065 splitter.setString(str);
Wu-cheng Li454630f2010-08-11 16:48:05 -07004066 int index = 0;
Ali Utku Selen0a120182011-02-09 14:11:22 +01004067 for (String s : splitter) {
4068 output[index++] = Float.parseFloat(s);
Wu-cheng Li454630f2010-08-11 16:48:05 -07004069 }
Wu-cheng Lie339c5e2010-05-13 19:31:02 +08004070 }
4071
Wu-cheng Li24b326a2010-02-20 17:47:04 +08004072 // Returns the value of a float parameter.
4073 private float getFloat(String key, float defaultValue) {
4074 try {
4075 return Float.parseFloat(mMap.get(key));
4076 } catch (NumberFormatException ex) {
4077 return defaultValue;
4078 }
4079 }
4080
4081 // Returns the value of a integer parameter.
4082 private int getInt(String key, int defaultValue) {
4083 try {
4084 return Integer.parseInt(mMap.get(key));
4085 } catch (NumberFormatException ex) {
4086 return defaultValue;
4087 }
4088 }
4089
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08004090 // Splits a comma delimited string to an ArrayList of Size.
4091 // Return null if the passing string is null or the size is 0.
4092 private ArrayList<Size> splitSize(String str) {
4093 if (str == null) return null;
4094
Ali Utku Selen0a120182011-02-09 14:11:22 +01004095 TextUtils.StringSplitter splitter = new TextUtils.SimpleStringSplitter(',');
4096 splitter.setString(str);
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08004097 ArrayList<Size> sizeList = new ArrayList<Size>();
Ali Utku Selen0a120182011-02-09 14:11:22 +01004098 for (String s : splitter) {
4099 Size size = strToSize(s);
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08004100 if (size != null) sizeList.add(size);
4101 }
4102 if (sizeList.size() == 0) return null;
4103 return sizeList;
4104 }
4105
4106 // Parses a string (ex: "480x320") to Size object.
4107 // Return null if the passing string is null.
4108 private Size strToSize(String str) {
4109 if (str == null) return null;
4110
4111 int pos = str.indexOf('x');
4112 if (pos != -1) {
4113 String width = str.substring(0, pos);
4114 String height = str.substring(pos + 1);
4115 return new Size(Integer.parseInt(width),
4116 Integer.parseInt(height));
4117 }
4118 Log.e(TAG, "Invalid size parameter string=" + str);
4119 return null;
4120 }
Wu-cheng Li454630f2010-08-11 16:48:05 -07004121
4122 // Splits a comma delimited string to an ArrayList of int array.
4123 // Example string: "(10000,26623),(10000,30000)". Return null if the
4124 // passing string is null or the size is 0.
4125 private ArrayList<int[]> splitRange(String str) {
4126 if (str == null || str.charAt(0) != '('
4127 || str.charAt(str.length() - 1) != ')') {
4128 Log.e(TAG, "Invalid range list string=" + str);
4129 return null;
4130 }
4131
4132 ArrayList<int[]> rangeList = new ArrayList<int[]>();
4133 int endIndex, fromIndex = 1;
4134 do {
4135 int[] range = new int[2];
4136 endIndex = str.indexOf("),(", fromIndex);
4137 if (endIndex == -1) endIndex = str.length() - 1;
4138 splitInt(str.substring(fromIndex, endIndex), range);
4139 rangeList.add(range);
4140 fromIndex = endIndex + 3;
4141 } while (endIndex != str.length() - 1);
4142
4143 if (rangeList.size() == 0) return null;
4144 return rangeList;
4145 }
Wu-cheng Li30771b72011-04-02 06:19:46 +08004146
4147 // Splits a comma delimited string to an ArrayList of Area objects.
4148 // Example string: "(-10,-10,0,0,300),(0,0,10,10,700)". Return null if
Wu-cheng Lif715bf92011-04-14 14:04:18 +08004149 // the passing string is null or the size is 0 or (0,0,0,0,0).
Wu-cheng Li30771b72011-04-02 06:19:46 +08004150 private ArrayList<Area> splitArea(String str) {
4151 if (str == null || str.charAt(0) != '('
4152 || str.charAt(str.length() - 1) != ')') {
4153 Log.e(TAG, "Invalid area string=" + str);
4154 return null;
4155 }
4156
4157 ArrayList<Area> result = new ArrayList<Area>();
4158 int endIndex, fromIndex = 1;
4159 int[] array = new int[5];
4160 do {
4161 endIndex = str.indexOf("),(", fromIndex);
4162 if (endIndex == -1) endIndex = str.length() - 1;
4163 splitInt(str.substring(fromIndex, endIndex), array);
4164 Rect rect = new Rect(array[0], array[1], array[2], array[3]);
4165 result.add(new Area(rect, array[4]));
4166 fromIndex = endIndex + 3;
4167 } while (endIndex != str.length() - 1);
4168
4169 if (result.size() == 0) return null;
Wu-cheng Lif715bf92011-04-14 14:04:18 +08004170
4171 if (result.size() == 1) {
Wu-cheng Libde61a52011-06-07 18:23:14 +08004172 Area area = result.get(0);
Wu-cheng Lif715bf92011-04-14 14:04:18 +08004173 Rect rect = area.rect;
4174 if (rect.left == 0 && rect.top == 0 && rect.right == 0
4175 && rect.bottom == 0 && area.weight == 0) {
4176 return null;
4177 }
4178 }
4179
Wu-cheng Li30771b72011-04-02 06:19:46 +08004180 return result;
4181 }
Wu-cheng Lib838d8d2011-11-17 20:12:23 +08004182
4183 private boolean same(String s1, String s2) {
4184 if (s1 == null && s2 == null) return true;
4185 if (s1 != null && s1.equals(s2)) return true;
4186 return false;
4187 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004188 };
4189}