blob: 2e9e786225fe9af218701e3c5dffc6050f18f751 [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
Wu-cheng Li10e09c62011-07-18 09:09:41 +080019import android.annotation.SdkConstant;
20import android.annotation.SdkConstant.SdkConstantType;
Mathias Agopiana696f5d2010-02-17 17:53:09 -080021import android.graphics.ImageFormat;
Wu-cheng Li4c2292e2011-07-22 02:37:11 +080022import android.graphics.Point;
Wu-cheng Li30771b72011-04-02 06:19:46 +080023import android.graphics.Rect;
Jamie Gennisfd6f39e2010-12-20 12:15:00 -080024import android.graphics.SurfaceTexture;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080025import android.os.Handler;
26import android.os.Looper;
27import android.os.Message;
Wu-cheng Libde61a52011-06-07 18:23:14 +080028import android.util.Log;
29import android.view.Surface;
30import android.view.SurfaceHolder;
31
32import java.io.IOException;
33import java.lang.ref.WeakReference;
34import java.util.ArrayList;
35import java.util.HashMap;
36import java.util.List;
37import java.util.StringTokenizer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080038
Wu-cheng Li4c2292e2011-07-22 02:37:11 +080039
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080040/**
Dan Egnorbfcbeff2010-07-12 15:12:54 -070041 * The Camera class is used to set image capture settings, start/stop preview,
42 * snap pictures, and retrieve frames for encoding for video. This class is a
43 * client for the Camera service, which manages the actual camera hardware.
Scott Maindf4578e2009-09-10 12:22:07 -070044 *
Dan Egnorbfcbeff2010-07-12 15:12:54 -070045 * <p>To access the device camera, you must declare the
Wu-cheng Li7478ea62009-09-16 18:52:55 +080046 * {@link android.Manifest.permission#CAMERA} permission in your Android
Scott Maindf4578e2009-09-10 12:22:07 -070047 * Manifest. Also be sure to include the
48 * <a href="{@docRoot}guide/topics/manifest/uses-feature-element.html">&lt;uses-feature></a>
Dan Egnorbfcbeff2010-07-12 15:12:54 -070049 * manifest element to declare camera features used by your application.
Wu-cheng Li7478ea62009-09-16 18:52:55 +080050 * For example, if you use the camera and auto-focus feature, your Manifest
Scott Maindf4578e2009-09-10 12:22:07 -070051 * should include the following:</p>
52 * <pre> &lt;uses-permission android:name="android.permission.CAMERA" />
53 * &lt;uses-feature android:name="android.hardware.camera" />
54 * &lt;uses-feature android:name="android.hardware.camera.autofocus" /></pre>
55 *
Dan Egnorbfcbeff2010-07-12 15:12:54 -070056 * <p>To take pictures with this class, use the following steps:</p>
57 *
58 * <ol>
Dan Egnor341ff132010-07-20 11:30:17 -070059 * <li>Obtain an instance of Camera from {@link #open(int)}.
Dan Egnorbfcbeff2010-07-12 15:12:54 -070060 *
61 * <li>Get existing (default) settings with {@link #getParameters()}.
62 *
63 * <li>If necessary, modify the returned {@link Camera.Parameters} object and call
64 * {@link #setParameters(Camera.Parameters)}.
65 *
66 * <li>If desired, call {@link #setDisplayOrientation(int)}.
67 *
68 * <li><b>Important</b>: Pass a fully initialized {@link SurfaceHolder} to
69 * {@link #setPreviewDisplay(SurfaceHolder)}. Without a surface, the camera
70 * will be unable to start the preview.
71 *
72 * <li><b>Important</b>: Call {@link #startPreview()} to start updating the
73 * preview surface. Preview must be started before you can take a picture.
74 *
75 * <li>When you want, call {@link #takePicture(Camera.ShutterCallback,
76 * Camera.PictureCallback, Camera.PictureCallback, Camera.PictureCallback)} to
77 * capture a photo. Wait for the callbacks to provide the actual image data.
78 *
79 * <li>After taking a picture, preview display will have stopped. To take more
80 * photos, call {@link #startPreview()} again first.
81 *
82 * <li>Call {@link #stopPreview()} to stop updating the preview surface.
83 *
84 * <li><b>Important:</b> Call {@link #release()} to release the camera for
85 * use by other applications. Applications should release the camera
86 * immediately in {@link android.app.Activity#onPause()} (and re-{@link #open()}
87 * it in {@link android.app.Activity#onResume()}).
88 * </ol>
89 *
90 * <p>To quickly switch to video recording mode, use these steps:</p>
91 *
92 * <ol>
93 * <li>Obtain and initialize a Camera and start preview as described above.
94 *
95 * <li>Call {@link #unlock()} to allow the media process to access the camera.
96 *
97 * <li>Pass the camera to {@link android.media.MediaRecorder#setCamera(Camera)}.
98 * See {@link android.media.MediaRecorder} information about video recording.
99 *
100 * <li>When finished recording, call {@link #reconnect()} to re-acquire
101 * and re-lock the camera.
102 *
103 * <li>If desired, restart preview and take more photos or videos.
104 *
105 * <li>Call {@link #stopPreview()} and {@link #release()} as described above.
106 * </ol>
107 *
108 * <p>This class is not thread-safe, and is meant for use from one event thread.
109 * Most long-running operations (preview, focus, photo capture, etc) happen
110 * asynchronously and invoke callbacks as necessary. Callbacks will be invoked
Dan Egnor341ff132010-07-20 11:30:17 -0700111 * on the event thread {@link #open(int)} was called from. This class's methods
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700112 * must never be called from multiple threads at once.</p>
113 *
Scott Maindf4578e2009-09-10 12:22:07 -0700114 * <p class="caution"><strong>Caution:</strong> Different Android-powered devices
115 * may have different hardware specifications, such as megapixel ratings and
116 * auto-focus capabilities. In order for your application to be compatible with
Wu-cheng Li7478ea62009-09-16 18:52:55 +0800117 * more devices, you should not make assumptions about the device camera
Scott Maindf4578e2009-09-10 12:22:07 -0700118 * specifications.</p>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800119 */
120public class Camera {
121 private static final String TAG = "Camera";
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800122
Wu-cheng Lid2c29292010-05-28 17:32:41 +0800123 // These match the enums in frameworks/base/include/camera/Camera.h
Benny Wongda83f462009-08-12 12:01:27 -0500124 private static final int CAMERA_MSG_ERROR = 0x001;
125 private static final int CAMERA_MSG_SHUTTER = 0x002;
126 private static final int CAMERA_MSG_FOCUS = 0x004;
127 private static final int CAMERA_MSG_ZOOM = 0x008;
128 private static final int CAMERA_MSG_PREVIEW_FRAME = 0x010;
129 private static final int CAMERA_MSG_VIDEO_FRAME = 0x020;
130 private static final int CAMERA_MSG_POSTVIEW_FRAME = 0x040;
131 private static final int CAMERA_MSG_RAW_IMAGE = 0x080;
132 private static final int CAMERA_MSG_COMPRESSED_IMAGE = 0x100;
Wu-cheng Li4c2292e2011-07-22 02:37:11 +0800133 private static final int CAMERA_MSG_RAW_IMAGE_NOTIFY = 0x200;
Wu-cheng Libb1e2752011-07-30 05:00:37 +0800134 private static final int CAMERA_MSG_PREVIEW_METADATA = 0x400;
Wu-cheng Li4c2292e2011-07-22 02:37:11 +0800135 private static final int CAMERA_MSG_ALL_MSGS = 0x4FF;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800136
137 private int mNativeContext; // accessed by native methods
138 private EventHandler mEventHandler;
139 private ShutterCallback mShutterCallback;
140 private PictureCallback mRawImageCallback;
141 private PictureCallback mJpegCallback;
142 private PreviewCallback mPreviewCallback;
Dave Sparkse8b26e12009-07-14 10:35:40 -0700143 private PictureCallback mPostviewCallback;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800144 private AutoFocusCallback mAutoFocusCallback;
Wu-cheng Li3f4639a2010-04-04 15:05:41 +0800145 private OnZoomChangeListener mZoomListener;
Wu-cheng Li4c2292e2011-07-22 02:37:11 +0800146 private FaceDetectionListener mFaceListener;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800147 private ErrorCallback mErrorCallback;
148 private boolean mOneShot;
Andrew Harp94927df2009-10-20 01:47:05 -0400149 private boolean mWithBuffer;
Wu-cheng Li4c2292e2011-07-22 02:37:11 +0800150 private boolean mFaceDetectionRunning = false;
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800151
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800152 /**
Wu-cheng Li10e09c62011-07-18 09:09:41 +0800153 * Broadcast Action: A new picture is taken by the camera, and the entry of
154 * the picture has been added to the media store.
155 * {@link android.content.Intent#getData} is URI of the picture.
156 */
157 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
158 public static final String ACTION_NEW_PICTURE = "android.hardware.action.NEW_PICTURE";
159
160 /**
161 * Broadcast Action: A new video is recorded by the camera, and the entry
162 * of the video has been added to the media store.
163 * {@link android.content.Intent#getData} is URI of the video.
164 */
165 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
166 public static final String ACTION_NEW_VIDEO = "android.hardware.action.NEW_VIDEO";
167
168 /**
Wu-cheng Li4c2292e2011-07-22 02:37:11 +0800169 * Hardware face detection. It does not use much CPU.
170 *
171 * @see #startFaceDetection(int)
172 * @see Parameters#getMaxNumDetectedFaces(int)
173 * @see #CAMERA_FACE_DETECTION_SW
174 * @hide
175 */
176 public static final int CAMERA_FACE_DETECTION_HW = 0;
177
178 /**
179 * Software face detection. It uses some CPU. Applications must use
180 * {@link #setPreviewTexture(SurfaceTexture)} for preview in this mode.
181 *
182 * @see #CAMERA_FACE_DETECTION_HW
183 * @hide
184 */
185 public static final int CAMERA_FACE_DETECTION_SW = 1;
186
187 /**
Dan Egnor341ff132010-07-20 11:30:17 -0700188 * Returns the number of physical cameras available on this device.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800189 */
Chih-Chung Change25cc652010-05-06 16:36:58 +0800190 public native static int getNumberOfCameras();
191
192 /**
Dan Egnor341ff132010-07-20 11:30:17 -0700193 * Returns the information about a particular camera.
Chih-Chung Changb8bb78f2010-06-10 13:32:16 +0800194 * If {@link #getNumberOfCameras()} returns N, the valid id is 0 to N-1.
Chih-Chung Changb8bb78f2010-06-10 13:32:16 +0800195 */
196 public native static void getCameraInfo(int cameraId, CameraInfo cameraInfo);
197
198 /**
199 * Information about a camera
Chih-Chung Changb8bb78f2010-06-10 13:32:16 +0800200 */
201 public static class CameraInfo {
Wu-cheng Li78366602010-09-15 14:08:15 -0700202 /**
203 * The facing of the camera is opposite to that of the screen.
204 */
Chih-Chung Changb8bb78f2010-06-10 13:32:16 +0800205 public static final int CAMERA_FACING_BACK = 0;
Wu-cheng Li78366602010-09-15 14:08:15 -0700206
207 /**
208 * The facing of the camera is the same as that of the screen.
209 */
Chih-Chung Changb8bb78f2010-06-10 13:32:16 +0800210 public static final int CAMERA_FACING_FRONT = 1;
211
212 /**
213 * The direction that the camera faces to. It should be
214 * CAMERA_FACING_BACK or CAMERA_FACING_FRONT.
215 */
Wu-cheng Li78366602010-09-15 14:08:15 -0700216 public int facing;
Chih-Chung Changb8bb78f2010-06-10 13:32:16 +0800217
218 /**
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -0700219 * <p>The orientation of the camera image. The value is the angle that the
Chih-Chung Changb8bb78f2010-06-10 13:32:16 +0800220 * camera image needs to be rotated clockwise so it shows correctly on
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -0700221 * the display in its natural orientation. It should be 0, 90, 180, or 270.</p>
Chih-Chung Changb8bb78f2010-06-10 13:32:16 +0800222 *
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -0700223 * <p>For example, suppose a device has a naturally tall screen. The
Wu-cheng Li2fe6fca2010-10-15 14:42:23 +0800224 * back-facing camera sensor is mounted in landscape. You are looking at
225 * the screen. If the top side of the camera sensor is aligned with the
226 * right edge of the screen in natural orientation, the value should be
227 * 90. If the top side of a front-facing camera sensor is aligned with
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -0700228 * the right of the screen, the value should be 270.</p>
Chih-Chung Changb8bb78f2010-06-10 13:32:16 +0800229 *
230 * @see #setDisplayOrientation(int)
Brad Fitzpatrick69ea4e12011-01-05 11:13:40 -0800231 * @see Parameters#setRotation(int)
232 * @see Parameters#setPreviewSize(int, int)
233 * @see Parameters#setPictureSize(int, int)
234 * @see Parameters#setJpegThumbnailSize(int, int)
Chih-Chung Changb8bb78f2010-06-10 13:32:16 +0800235 */
Wu-cheng Li78366602010-09-15 14:08:15 -0700236 public int orientation;
Chih-Chung Changb8bb78f2010-06-10 13:32:16 +0800237 };
238
239 /**
Dan Egnor341ff132010-07-20 11:30:17 -0700240 * Creates a new Camera object to access a particular hardware camera.
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700241 *
242 * <p>You must call {@link #release()} when you are done using the camera,
243 * otherwise it will remain locked and be unavailable to other applications.
244 *
Dan Egnor341ff132010-07-20 11:30:17 -0700245 * <p>Your application should only have one Camera object active at a time
246 * for a particular hardware camera.
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700247 *
248 * <p>Callbacks from other methods are delivered to the event loop of the
249 * thread which called open(). If this thread has no event loop, then
250 * callbacks are delivered to the main application event loop. If there
251 * is no main application event loop, callbacks are not delivered.
252 *
253 * <p class="caution"><b>Caution:</b> On some devices, this method may
254 * take a long time to complete. It is best to call this method from a
255 * worker thread (possibly using {@link android.os.AsyncTask}) to avoid
256 * blocking the main application UI thread.
257 *
Dan Egnor341ff132010-07-20 11:30:17 -0700258 * @param cameraId the hardware camera to access, between 0 and
Wu-cheng Lia48b70f2010-11-09 01:55:44 +0800259 * {@link #getNumberOfCameras()}-1.
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700260 * @return a new Camera object, connected, locked and ready for use.
261 * @throws RuntimeException if connection to the camera service fails (for
Wu-cheng Lifacc8ce2011-06-17 13:09:40 +0800262 * example, if the camera is in use by another process or device policy
263 * manager has disabled the camera).
264 * @see android.app.admin.DevicePolicyManager#getCameraDisabled(android.content.ComponentName)
Chih-Chung Change25cc652010-05-06 16:36:58 +0800265 */
266 public static Camera open(int cameraId) {
267 return new Camera(cameraId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800268 }
269
Chih-Chung Change25cc652010-05-06 16:36:58 +0800270 /**
Wu-cheng Lia48b70f2010-11-09 01:55:44 +0800271 * Creates a new Camera object to access the first back-facing camera on the
272 * device. If the device does not have a back-facing camera, this returns
273 * null.
Wu-cheng Li78366602010-09-15 14:08:15 -0700274 * @see #open(int)
Chih-Chung Change25cc652010-05-06 16:36:58 +0800275 */
276 public static Camera open() {
Wu-cheng Lia48b70f2010-11-09 01:55:44 +0800277 int numberOfCameras = getNumberOfCameras();
278 CameraInfo cameraInfo = new CameraInfo();
279 for (int i = 0; i < numberOfCameras; i++) {
280 getCameraInfo(i, cameraInfo);
281 if (cameraInfo.facing == CameraInfo.CAMERA_FACING_BACK) {
282 return new Camera(i);
283 }
284 }
285 return null;
Chih-Chung Change25cc652010-05-06 16:36:58 +0800286 }
287
288 Camera(int cameraId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800289 mShutterCallback = null;
290 mRawImageCallback = null;
291 mJpegCallback = null;
292 mPreviewCallback = null;
Dave Sparkse8b26e12009-07-14 10:35:40 -0700293 mPostviewCallback = null;
Wu-cheng Li3f4639a2010-04-04 15:05:41 +0800294 mZoomListener = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800295
296 Looper looper;
297 if ((looper = Looper.myLooper()) != null) {
298 mEventHandler = new EventHandler(this, looper);
299 } else if ((looper = Looper.getMainLooper()) != null) {
300 mEventHandler = new EventHandler(this, looper);
301 } else {
302 mEventHandler = null;
303 }
304
Chih-Chung Change25cc652010-05-06 16:36:58 +0800305 native_setup(new WeakReference<Camera>(this), cameraId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800306 }
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800307
308 protected void finalize() {
309 native_release();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800310 }
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800311
Chih-Chung Change25cc652010-05-06 16:36:58 +0800312 private native final void native_setup(Object camera_this, int cameraId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800313 private native final void native_release();
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800314
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800315
316 /**
317 * Disconnects and releases the Camera object resources.
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700318 *
319 * <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 -0800320 */
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800321 public final void release() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800322 native_release();
Wu-cheng Li4c2292e2011-07-22 02:37:11 +0800323 mFaceDetectionRunning = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800324 }
325
326 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700327 * Unlocks the camera to allow another process to access it.
328 * Normally, the camera is locked to the process with an active Camera
329 * object until {@link #release()} is called. To allow rapid handoff
330 * between processes, you can call this method to release the camera
331 * temporarily for another process to use; once the other process is done
332 * you can call {@link #reconnect()} to reclaim the camera.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800333 *
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700334 * <p>This must be done before calling
Wu-cheng Li42419ce2011-06-01 17:22:24 +0800335 * {@link android.media.MediaRecorder#setCamera(Camera)}. This cannot be
336 * called after recording starts.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800337 *
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700338 * <p>If you are not recording video, you probably do not need this method.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800339 *
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700340 * @throws RuntimeException if the camera cannot be unlocked.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800341 */
Wu-cheng Liffe1cf22009-09-10 16:49:17 +0800342 public native final void unlock();
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800343
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800344 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700345 * Re-locks the camera to prevent other processes from accessing it.
346 * Camera objects are locked by default unless {@link #unlock()} is
347 * called. Normally {@link #reconnect()} is used instead.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800348 *
Wu-cheng Li42419ce2011-06-01 17:22:24 +0800349 * <p>Since API level 13, camera is automatically locked for applications in
350 * {@link android.media.MediaRecorder#start()}. Applications can use the
351 * camera (ex: zoom) after recording starts. There is no need to call this
352 * after recording starts or stops.
353 *
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700354 * <p>If you are not recording video, you probably do not need this method.
355 *
356 * @throws RuntimeException if the camera cannot be re-locked (for
357 * example, if the camera is still in use by another process).
358 */
359 public native final void lock();
360
361 /**
362 * Reconnects to the camera service after another process used it.
363 * After {@link #unlock()} is called, another process may use the
364 * camera; when the process is done, you must reconnect to the camera,
365 * which will re-acquire the lock and allow you to continue using the
366 * camera.
367 *
Wu-cheng Li42419ce2011-06-01 17:22:24 +0800368 * <p>Since API level 13, camera is automatically locked for applications in
369 * {@link android.media.MediaRecorder#start()}. Applications can use the
370 * camera (ex: zoom) after recording starts. There is no need to call this
371 * after recording starts or stops.
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700372 *
373 * <p>If you are not recording video, you probably do not need this method.
374 *
375 * @throws IOException if a connection cannot be re-established (for
376 * example, if the camera is still in use by another process).
377 */
378 public native final void reconnect() throws IOException;
379
380 /**
381 * Sets the {@link Surface} to be used for live preview.
Jamie Gennisfd6f39e2010-12-20 12:15:00 -0800382 * Either a surface or surface texture is necessary for preview, and
383 * preview is necessary to take pictures. The same surface can be re-set
384 * without harm. Setting a preview surface will un-set any preview surface
385 * texture that was set via {@link #setPreviewTexture}.
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700386 *
387 * <p>The {@link SurfaceHolder} must already contain a surface when this
388 * method is called. If you are using {@link android.view.SurfaceView},
389 * you will need to register a {@link SurfaceHolder.Callback} with
390 * {@link SurfaceHolder#addCallback(SurfaceHolder.Callback)} and wait for
391 * {@link SurfaceHolder.Callback#surfaceCreated(SurfaceHolder)} before
392 * calling setPreviewDisplay() or starting preview.
393 *
394 * <p>This method must be called before {@link #startPreview()}. The
395 * one exception is that if the preview surface is not set (or set to null)
396 * before startPreview() is called, then this method may be called once
397 * with a non-null parameter to set the preview surface. (This allows
398 * camera setup and surface creation to happen in parallel, saving time.)
399 * The preview surface may not otherwise change while preview is running.
400 *
401 * @param holder containing the Surface on which to place the preview,
402 * or null to remove the preview surface
403 * @throws IOException if the method fails (for example, if the surface
404 * is unavailable or unsuitable).
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800405 */
406 public final void setPreviewDisplay(SurfaceHolder holder) throws IOException {
Wu-cheng Lib8a10fe2009-06-23 23:37:36 +0800407 if (holder != null) {
408 setPreviewDisplay(holder.getSurface());
409 } else {
410 setPreviewDisplay((Surface)null);
411 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800412 }
413
Glenn Kastendbc289d2011-02-09 10:15:44 -0800414 private native final void setPreviewDisplay(Surface surface) throws IOException;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800415
416 /**
Jamie Gennisfd6f39e2010-12-20 12:15:00 -0800417 * Sets the {@link SurfaceTexture} to be used for live preview.
418 * Either a surface or surface texture is necessary for preview, and
419 * preview is necessary to take pictures. The same surface texture can be
420 * re-set without harm. Setting a preview surface texture will un-set any
421 * preview surface that was set via {@link #setPreviewDisplay}.
422 *
423 * <p>This method must be called before {@link #startPreview()}. The
424 * one exception is that if the preview surface texture is not set (or set
425 * to null) before startPreview() is called, then this method may be called
426 * once with a non-null parameter to set the preview surface. (This allows
427 * camera setup and surface creation to happen in parallel, saving time.)
428 * The preview surface texture may not otherwise change while preview is
429 * running.
430 *
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -0700431 * <p>The timestamps provided by {@link SurfaceTexture#getTimestamp()} for a
Eino-Ville Talvalae309a0f2011-03-21 11:04:34 -0700432 * SurfaceTexture set as the preview texture have an unspecified zero point,
433 * and cannot be directly compared between different cameras or different
434 * instances of the same camera, or across multiple runs of the same
435 * program.
436 *
Jamie Gennisfd6f39e2010-12-20 12:15:00 -0800437 * @param surfaceTexture the {@link SurfaceTexture} to which the preview
438 * images are to be sent or null to remove the current preview surface
439 * texture
440 * @throws IOException if the method fails (for example, if the surface
441 * texture is unavailable or unsuitable).
442 */
Glenn Kastendbc289d2011-02-09 10:15:44 -0800443 public native final void setPreviewTexture(SurfaceTexture surfaceTexture) throws IOException;
Jamie Gennisfd6f39e2010-12-20 12:15:00 -0800444
445 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700446 * Callback interface used to deliver copies of preview frames as
447 * they are displayed.
448 *
449 * @see #setPreviewCallback(Camera.PreviewCallback)
450 * @see #setOneShotPreviewCallback(Camera.PreviewCallback)
451 * @see #setPreviewCallbackWithBuffer(Camera.PreviewCallback)
452 * @see #startPreview()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800453 */
454 public interface PreviewCallback
455 {
456 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700457 * Called as preview frames are displayed. This callback is invoked
Dan Egnor341ff132010-07-20 11:30:17 -0700458 * on the event thread {@link #open(int)} was called from.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800459 *
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700460 * @param data the contents of the preview frame in the format defined
Mathias Agopiana696f5d2010-02-17 17:53:09 -0800461 * by {@link android.graphics.ImageFormat}, which can be queried
Scott Maindf4578e2009-09-10 12:22:07 -0700462 * with {@link android.hardware.Camera.Parameters#getPreviewFormat()}.
Scott Mainda0a56d2009-09-10 18:08:37 -0700463 * If {@link android.hardware.Camera.Parameters#setPreviewFormat(int)}
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800464 * is never called, the default will be the YCbCr_420_SP
465 * (NV21) format.
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700466 * @param camera the Camera service object.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800467 */
468 void onPreviewFrame(byte[] data, Camera camera);
469 };
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800470
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800471 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700472 * Starts capturing and drawing preview frames to the screen.
Eino-Ville Talvalac5f94d82011-02-18 11:02:42 -0800473 * Preview will not actually start until a surface is supplied
474 * with {@link #setPreviewDisplay(SurfaceHolder)} or
475 * {@link #setPreviewTexture(SurfaceTexture)}.
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700476 *
477 * <p>If {@link #setPreviewCallback(Camera.PreviewCallback)},
478 * {@link #setOneShotPreviewCallback(Camera.PreviewCallback)}, or
479 * {@link #setPreviewCallbackWithBuffer(Camera.PreviewCallback)} were
480 * called, {@link Camera.PreviewCallback#onPreviewFrame(byte[], Camera)}
481 * will be called when preview data becomes available.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800482 */
483 public native final void startPreview();
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800484
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800485 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700486 * Stops capturing and drawing preview frames to the surface, and
487 * resets the camera for a future call to {@link #startPreview()}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800488 */
Wu-cheng Li4c2292e2011-07-22 02:37:11 +0800489 public final void stopPreview() {
490 _stopPreview();
491 mFaceDetectionRunning = false;
492 }
493
494 private native final void _stopPreview();
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800495
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800496 /**
497 * Return current preview state.
498 *
499 * FIXME: Unhide before release
500 * @hide
501 */
502 public native final boolean previewEnabled();
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800503
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800504 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700505 * Installs a callback to be invoked for every preview frame in addition
506 * to displaying them on the screen. The callback will be repeatedly called
507 * for as long as preview is active. This method can be called at any time,
508 * even while preview is live. Any other preview callbacks are overridden.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800509 *
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700510 * @param cb a callback object that receives a copy of each preview frame,
511 * or null to stop receiving callbacks.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800512 */
513 public final void setPreviewCallback(PreviewCallback cb) {
514 mPreviewCallback = cb;
515 mOneShot = false;
Andrew Harp94927df2009-10-20 01:47:05 -0400516 mWithBuffer = false;
Dave Sparksa6118c62009-10-13 02:28:54 -0700517 // Always use one-shot mode. We fake camera preview mode by
518 // doing one-shot preview continuously.
Andrew Harp94927df2009-10-20 01:47:05 -0400519 setHasPreviewCallback(cb != null, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800520 }
521
522 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700523 * Installs a callback to be invoked for the next preview frame in addition
524 * to displaying it on the screen. After one invocation, the callback is
525 * cleared. This method can be called any time, even when preview is live.
526 * Any other preview callbacks are overridden.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800527 *
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700528 * @param cb a callback object that receives a copy of the next preview frame,
529 * or null to stop receiving callbacks.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800530 */
531 public final void setOneShotPreviewCallback(PreviewCallback cb) {
Andrew Harp94927df2009-10-20 01:47:05 -0400532 mPreviewCallback = cb;
533 mOneShot = true;
534 mWithBuffer = false;
535 setHasPreviewCallback(cb != null, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800536 }
537
Andrew Harp94927df2009-10-20 01:47:05 -0400538 private native final void setHasPreviewCallback(boolean installed, boolean manualBuffer);
539
540 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700541 * Installs a callback to be invoked for every preview frame, using buffers
542 * supplied with {@link #addCallbackBuffer(byte[])}, in addition to
543 * displaying them on the screen. The callback will be repeatedly called
544 * for as long as preview is active and buffers are available.
545 * Any other preview callbacks are overridden.
Andrew Harp94927df2009-10-20 01:47:05 -0400546 *
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700547 * <p>The purpose of this method is to improve preview efficiency and frame
548 * rate by allowing preview frame memory reuse. You must call
549 * {@link #addCallbackBuffer(byte[])} at some point -- before or after
550 * calling this method -- or no callbacks will received.
Andrew Harp94927df2009-10-20 01:47:05 -0400551 *
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700552 * The buffer queue will be cleared if this method is called with a null
553 * callback, {@link #setPreviewCallback(Camera.PreviewCallback)} is called,
554 * or {@link #setOneShotPreviewCallback(Camera.PreviewCallback)} is called.
Andrew Harp94927df2009-10-20 01:47:05 -0400555 *
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700556 * @param cb a callback object that receives a copy of the preview frame,
557 * or null to stop receiving callbacks and clear the buffer queue.
558 * @see #addCallbackBuffer(byte[])
Andrew Harp94927df2009-10-20 01:47:05 -0400559 */
560 public final void setPreviewCallbackWithBuffer(PreviewCallback cb) {
561 mPreviewCallback = cb;
562 mOneShot = false;
563 mWithBuffer = true;
564 setHasPreviewCallback(cb != null, true);
565 }
566
567 /**
Wu-cheng Li3f4639a2010-04-04 15:05:41 +0800568 * Adds a pre-allocated buffer to the preview callback buffer queue.
569 * Applications can add one or more buffers to the queue. When a preview
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700570 * frame arrives and there is still at least one available buffer, the
571 * buffer will be used and removed from the queue. Then preview callback is
572 * invoked with the buffer. If a frame arrives and there is no buffer left,
573 * the frame is discarded. Applications should add buffers back when they
574 * finish processing the data in them.
Wu-cheng Lic10275a2010-03-09 13:49:21 -0800575 *
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700576 * <p>The size of the buffer is determined by multiplying the preview
James Donge00cab72011-02-17 16:38:06 -0800577 * image width, height, and bytes per pixel. The width and height can be
578 * read from {@link Camera.Parameters#getPreviewSize()}. Bytes per pixel
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700579 * can be computed from
580 * {@link android.graphics.ImageFormat#getBitsPerPixel(int)} / 8,
581 * using the image format from {@link Camera.Parameters#getPreviewFormat()}.
Andrew Harp94927df2009-10-20 01:47:05 -0400582 *
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700583 * <p>This method is only necessary when
James Donge00cab72011-02-17 16:38:06 -0800584 * {@link #setPreviewCallbackWithBuffer(PreviewCallback)} is used. When
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700585 * {@link #setPreviewCallback(PreviewCallback)} or
586 * {@link #setOneShotPreviewCallback(PreviewCallback)} are used, buffers
James Donge00cab72011-02-17 16:38:06 -0800587 * are automatically allocated. When a supplied buffer is too small to
588 * hold the preview frame data, preview callback will return null and
589 * the buffer will be removed from the buffer queue.
Andrew Harp94927df2009-10-20 01:47:05 -0400590 *
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700591 * @param callbackBuffer the buffer to add to the queue.
592 * The size should be width * height * bits_per_pixel / 8.
Wu-cheng Li5b9bcda2010-03-07 14:59:28 -0800593 * @see #setPreviewCallbackWithBuffer(PreviewCallback)
Andrew Harp94927df2009-10-20 01:47:05 -0400594 */
James Donge00cab72011-02-17 16:38:06 -0800595 public final void addCallbackBuffer(byte[] callbackBuffer)
596 {
597 _addCallbackBuffer(callbackBuffer, CAMERA_MSG_PREVIEW_FRAME);
598 }
599
600 /**
601 * Adds a pre-allocated buffer to the raw image callback buffer queue.
602 * Applications can add one or more buffers to the queue. When a raw image
603 * frame arrives and there is still at least one available buffer, the
604 * buffer will be used to hold the raw image data and removed from the
605 * queue. Then raw image callback is invoked with the buffer. If a raw
606 * image frame arrives but there is no buffer left, the frame is
607 * discarded. Applications should add buffers back when they finish
608 * processing the data in them by calling this method again in order
609 * to avoid running out of raw image callback buffers.
610 *
611 * <p>The size of the buffer is determined by multiplying the raw image
612 * width, height, and bytes per pixel. The width and height can be
613 * read from {@link Camera.Parameters#getPictureSize()}. Bytes per pixel
614 * can be computed from
615 * {@link android.graphics.ImageFormat#getBitsPerPixel(int)} / 8,
616 * using the image format from {@link Camera.Parameters#getPreviewFormat()}.
617 *
618 * <p>This method is only necessary when the PictureCallbck for raw image
619 * is used while calling {@link #takePicture(Camera.ShutterCallback,
620 * Camera.PictureCallback, Camera.PictureCallback, Camera.PictureCallback)}.
621 *
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -0700622 * <p>Please note that by calling this method, the mode for
623 * application-managed callback buffers is triggered. If this method has
624 * never been called, null will be returned by the raw image callback since
625 * there is no image callback buffer available. Furthermore, When a supplied
626 * buffer is too small to hold the raw image data, raw image callback will
627 * return null and the buffer will be removed from the buffer queue.
James Donge00cab72011-02-17 16:38:06 -0800628 *
629 * @param callbackBuffer the buffer to add to the raw image callback buffer
630 * queue. The size should be width * height * (bits per pixel) / 8. An
631 * null callbackBuffer will be ignored and won't be added to the queue.
632 *
633 * @see #takePicture(Camera.ShutterCallback,
634 * Camera.PictureCallback, Camera.PictureCallback, Camera.PictureCallback)}.
635 *
636 * {@hide}
637 */
638 public final void addRawImageCallbackBuffer(byte[] callbackBuffer)
639 {
640 addCallbackBuffer(callbackBuffer, CAMERA_MSG_RAW_IMAGE);
641 }
642
643 private final void addCallbackBuffer(byte[] callbackBuffer, int msgType)
644 {
645 // CAMERA_MSG_VIDEO_FRAME may be allowed in the future.
646 if (msgType != CAMERA_MSG_PREVIEW_FRAME &&
647 msgType != CAMERA_MSG_RAW_IMAGE) {
648 throw new IllegalArgumentException(
649 "Unsupported message type: " + msgType);
650 }
651
652 _addCallbackBuffer(callbackBuffer, msgType);
653 }
654
655 private native final void _addCallbackBuffer(
656 byte[] callbackBuffer, int msgType);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800657
658 private class EventHandler extends Handler
659 {
660 private Camera mCamera;
661
662 public EventHandler(Camera c, Looper looper) {
663 super(looper);
664 mCamera = c;
665 }
666
667 @Override
668 public void handleMessage(Message msg) {
669 switch(msg.what) {
Dave Sparksc62f9bd2009-06-26 13:33:32 -0700670 case CAMERA_MSG_SHUTTER:
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800671 if (mShutterCallback != null) {
672 mShutterCallback.onShutter();
673 }
674 return;
Dave Sparksc62f9bd2009-06-26 13:33:32 -0700675
676 case CAMERA_MSG_RAW_IMAGE:
Dave Sparkse8b26e12009-07-14 10:35:40 -0700677 if (mRawImageCallback != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800678 mRawImageCallback.onPictureTaken((byte[])msg.obj, mCamera);
Dave Sparkse8b26e12009-07-14 10:35:40 -0700679 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800680 return;
681
Dave Sparksc62f9bd2009-06-26 13:33:32 -0700682 case CAMERA_MSG_COMPRESSED_IMAGE:
Dave Sparkse8b26e12009-07-14 10:35:40 -0700683 if (mJpegCallback != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800684 mJpegCallback.onPictureTaken((byte[])msg.obj, mCamera);
Dave Sparkse8b26e12009-07-14 10:35:40 -0700685 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800686 return;
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800687
Dave Sparksc62f9bd2009-06-26 13:33:32 -0700688 case CAMERA_MSG_PREVIEW_FRAME:
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800689 if (mPreviewCallback != null) {
Dave Sparksa6118c62009-10-13 02:28:54 -0700690 PreviewCallback cb = mPreviewCallback;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800691 if (mOneShot) {
Dave Sparksa6118c62009-10-13 02:28:54 -0700692 // Clear the callback variable before the callback
693 // in case the app calls setPreviewCallback from
694 // the callback function
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800695 mPreviewCallback = null;
Andrew Harp94927df2009-10-20 01:47:05 -0400696 } else if (!mWithBuffer) {
Dave Sparksa6118c62009-10-13 02:28:54 -0700697 // We're faking the camera preview mode to prevent
698 // the app from being flooded with preview frames.
699 // Set to oneshot mode again.
Andrew Harp94927df2009-10-20 01:47:05 -0400700 setHasPreviewCallback(true, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800701 }
Dave Sparksa6118c62009-10-13 02:28:54 -0700702 cb.onPreviewFrame((byte[])msg.obj, mCamera);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800703 }
704 return;
705
Dave Sparkse8b26e12009-07-14 10:35:40 -0700706 case CAMERA_MSG_POSTVIEW_FRAME:
707 if (mPostviewCallback != null) {
708 mPostviewCallback.onPictureTaken((byte[])msg.obj, mCamera);
709 }
710 return;
711
Dave Sparksc62f9bd2009-06-26 13:33:32 -0700712 case CAMERA_MSG_FOCUS:
Dave Sparkse8b26e12009-07-14 10:35:40 -0700713 if (mAutoFocusCallback != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800714 mAutoFocusCallback.onAutoFocus(msg.arg1 == 0 ? false : true, mCamera);
Dave Sparkse8b26e12009-07-14 10:35:40 -0700715 }
716 return;
717
718 case CAMERA_MSG_ZOOM:
Wu-cheng Li3f4639a2010-04-04 15:05:41 +0800719 if (mZoomListener != null) {
720 mZoomListener.onZoomChange(msg.arg1, msg.arg2 != 0, mCamera);
Dave Sparkse8b26e12009-07-14 10:35:40 -0700721 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800722 return;
723
Wu-cheng Libb1e2752011-07-30 05:00:37 +0800724 case CAMERA_MSG_PREVIEW_METADATA:
Wu-cheng Li4c2292e2011-07-22 02:37:11 +0800725 if (mFaceListener != null) {
Wu-cheng Lif0d6a482011-07-28 05:30:59 +0800726 mFaceListener.onFaceDetection((Face[])msg.obj, mCamera);
Wu-cheng Li4c2292e2011-07-22 02:37:11 +0800727 }
728 return;
729
Dave Sparksc62f9bd2009-06-26 13:33:32 -0700730 case CAMERA_MSG_ERROR :
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800731 Log.e(TAG, "Error " + msg.arg1);
Dave Sparkse8b26e12009-07-14 10:35:40 -0700732 if (mErrorCallback != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800733 mErrorCallback.onError(msg.arg1, mCamera);
Dave Sparkse8b26e12009-07-14 10:35:40 -0700734 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800735 return;
736
737 default:
738 Log.e(TAG, "Unknown message type " + msg.what);
739 return;
740 }
741 }
742 }
743
744 private static void postEventFromNative(Object camera_ref,
745 int what, int arg1, int arg2, Object obj)
746 {
747 Camera c = (Camera)((WeakReference)camera_ref).get();
748 if (c == null)
749 return;
750
751 if (c.mEventHandler != null) {
752 Message m = c.mEventHandler.obtainMessage(what, arg1, arg2, obj);
753 c.mEventHandler.sendMessage(m);
754 }
755 }
756
757 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700758 * Callback interface used to notify on completion of camera auto focus.
759 *
Wu-cheng Li7478ea62009-09-16 18:52:55 +0800760 * <p>Devices that do not support auto-focus will receive a "fake"
761 * callback to this interface. If your application needs auto-focus and
Scott Maindf4578e2009-09-10 12:22:07 -0700762 * should not be installed on devices <em>without</em> auto-focus, you must
763 * declare that your app uses the
Wu-cheng Li7478ea62009-09-16 18:52:55 +0800764 * {@code android.hardware.camera.autofocus} feature, in the
Scott Maindf4578e2009-09-10 12:22:07 -0700765 * <a href="{@docRoot}guide/topics/manifest/uses-feature-element.html">&lt;uses-feature></a>
766 * manifest element.</p>
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700767 *
768 * @see #autoFocus(AutoFocusCallback)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800769 */
770 public interface AutoFocusCallback
771 {
772 /**
Brad Fitzpatrick69ea4e12011-01-05 11:13:40 -0800773 * Called when the camera auto focus completes. If the camera
774 * does not support auto-focus and autoFocus is called,
775 * onAutoFocus will be called immediately with a fake value of
776 * <code>success</code> set to <code>true</code>.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800777 *
Eino-Ville Talvala83d33522011-05-13 10:25:00 -0700778 * The auto-focus routine may lock auto-exposure and auto-white balance
779 * after it completes. To check for the state of these locks, use the
780 * {@link android.hardware.Camera.Parameters#getAutoExposureLock()} and
781 * {@link android.hardware.Camera.Parameters#getAutoWhiteBalanceLock()}
782 * methods. If such locking is undesirable, use
783 * {@link android.hardware.Camera.Parameters#setAutoExposureLock(boolean)}
784 * and
785 * {@link android.hardware.Camera.Parameters#setAutoWhiteBalanceLock(boolean)}
786 * to release the locks.
787 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800788 * @param success true if focus was successful, false if otherwise
789 * @param camera the Camera service object
Eino-Ville Talvala83d33522011-05-13 10:25:00 -0700790 * @see android.hardware.Camera.Parameters#setAutoExposureLock(boolean)
791 * @see android.hardware.Camera.Parameters#setAutoWhiteBalanceLock(boolean)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800792 */
793 void onAutoFocus(boolean success, Camera camera);
794 };
795
796 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700797 * Starts camera auto-focus and registers a callback function to run when
798 * the camera is focused. This method is only valid when preview is active
799 * (between {@link #startPreview()} and before {@link #stopPreview()}).
800 *
801 * <p>Callers should check
802 * {@link android.hardware.Camera.Parameters#getFocusMode()} to determine if
803 * this method should be called. If the camera does not support auto-focus,
804 * it is a no-op and {@link AutoFocusCallback#onAutoFocus(boolean, Camera)}
Wu-cheng Li36322db2009-09-18 18:59:21 +0800805 * callback will be called immediately.
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700806 *
Scott Mainda0a56d2009-09-10 18:08:37 -0700807 * <p>If your application should not be installed
Wu-cheng Li7478ea62009-09-16 18:52:55 +0800808 * on devices without auto-focus, you must declare that your application
809 * uses auto-focus with the
Scott Maindf4578e2009-09-10 12:22:07 -0700810 * <a href="{@docRoot}guide/topics/manifest/uses-feature-element.html">&lt;uses-feature></a>
811 * manifest element.</p>
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700812 *
Wu-cheng Li068ef422009-09-27 13:19:36 -0700813 * <p>If the current flash mode is not
814 * {@link android.hardware.Camera.Parameters#FLASH_MODE_OFF}, flash may be
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700815 * fired during auto-focus, depending on the driver and camera hardware.<p>
Wu-cheng Li7478ea62009-09-16 18:52:55 +0800816 *
Eino-Ville Talvala83d33522011-05-13 10:25:00 -0700817 * The auto-focus routine may lock auto-exposure and auto-white balance
818 * after it completes. To check for the state of these locks, use the
819 * {@link android.hardware.Camera.Parameters#getAutoExposureLock()} and
820 * {@link android.hardware.Camera.Parameters#getAutoWhiteBalanceLock()}
821 * methods after the {@link AutoFocusCallback#onAutoFocus(boolean, Camera)}
822 * callback is invoked. If such locking is undesirable, use
823 * {@link android.hardware.Camera.Parameters#setAutoExposureLock(boolean)}
824 * and
825 * {@link android.hardware.Camera.Parameters#setAutoWhiteBalanceLock(boolean)}
826 * to release the locks.
827 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800828 * @param cb the callback to run
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700829 * @see #cancelAutoFocus()
Eino-Ville Talvala83d33522011-05-13 10:25:00 -0700830 * @see android.hardware.Camera.Parameters#setAutoExposureLock(boolean)
831 * @see android.hardware.Camera.Parameters#setAutoWhiteBalanceLock(boolean)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800832 */
833 public final void autoFocus(AutoFocusCallback cb)
834 {
835 mAutoFocusCallback = cb;
836 native_autoFocus();
837 }
838 private native final void native_autoFocus();
839
840 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700841 * Cancels any auto-focus function in progress.
842 * Whether or not auto-focus is currently in progress,
843 * this function will return the focus position to the default.
Chih-Chung Chang244f8c22009-09-15 14:51:56 +0800844 * If the camera does not support auto-focus, this is a no-op.
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700845 *
Eino-Ville Talvala83d33522011-05-13 10:25:00 -0700846 * Canceling auto-focus will return the auto-exposure lock and auto-white
847 * balance lock to their state before {@link #autoFocus(AutoFocusCallback)}
848 * was called.
849 *
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700850 * @see #autoFocus(Camera.AutoFocusCallback)
Eino-Ville Talvala83d33522011-05-13 10:25:00 -0700851 * @see android.hardware.Camera.Parameters#setAutoExposureLock(boolean)
852 * @see android.hardware.Camera.Parameters#setAutoWhiteBalanceLock(boolean)
Chih-Chung Chang244f8c22009-09-15 14:51:56 +0800853 */
854 public final void cancelAutoFocus()
855 {
856 mAutoFocusCallback = null;
857 native_cancelAutoFocus();
858 }
859 private native final void native_cancelAutoFocus();
860
861 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700862 * Callback interface used to signal the moment of actual image capture.
863 *
864 * @see #takePicture(ShutterCallback, PictureCallback, PictureCallback, PictureCallback)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800865 */
866 public interface ShutterCallback
867 {
868 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700869 * Called as near as possible to the moment when a photo is captured
870 * from the sensor. This is a good opportunity to play a shutter sound
871 * or give other feedback of camera operation. This may be some time
872 * after the photo was triggered, but some time before the actual data
873 * is available.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800874 */
875 void onShutter();
876 }
877
878 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700879 * Callback interface used to supply image data from a photo capture.
880 *
881 * @see #takePicture(ShutterCallback, PictureCallback, PictureCallback, PictureCallback)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800882 */
883 public interface PictureCallback {
884 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700885 * Called when image data is available after a picture is taken.
886 * The format of the data depends on the context of the callback
887 * and {@link Camera.Parameters} settings.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800888 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800889 * @param data a byte array of the picture data
890 * @param camera the Camera service object
891 */
892 void onPictureTaken(byte[] data, Camera camera);
893 };
894
895 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700896 * Equivalent to takePicture(shutter, raw, null, jpeg).
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800897 *
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700898 * @see #takePicture(ShutterCallback, PictureCallback, PictureCallback, PictureCallback)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800899 */
900 public final void takePicture(ShutterCallback shutter, PictureCallback raw,
901 PictureCallback jpeg) {
Dave Sparkse8b26e12009-07-14 10:35:40 -0700902 takePicture(shutter, raw, null, jpeg);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800903 }
James Donge00cab72011-02-17 16:38:06 -0800904 private native final void native_takePicture(int msgType);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800905
Dave Sparkse8b26e12009-07-14 10:35:40 -0700906 /**
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800907 * Triggers an asynchronous image capture. The camera service will initiate
908 * a series of callbacks to the application as the image capture progresses.
909 * The shutter callback occurs after the image is captured. This can be used
910 * to trigger a sound to let the user know that image has been captured. The
911 * raw callback occurs when the raw image data is available (NOTE: the data
James Donge00cab72011-02-17 16:38:06 -0800912 * will be null if there is no raw image callback buffer available or the
913 * raw image callback buffer is not large enough to hold the raw image).
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800914 * The postview callback occurs when a scaled, fully processed postview
915 * image is available (NOTE: not all hardware supports this). The jpeg
916 * callback occurs when the compressed image is available. If the
917 * application does not need a particular callback, a null can be passed
918 * instead of a callback method.
Dave Sparkse8b26e12009-07-14 10:35:40 -0700919 *
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700920 * <p>This method is only valid when preview is active (after
921 * {@link #startPreview()}). Preview will be stopped after the image is
922 * taken; callers must call {@link #startPreview()} again if they want to
Wu-cheng Li42419ce2011-06-01 17:22:24 +0800923 * re-start preview or take more pictures. This should not be called between
924 * {@link android.media.MediaRecorder#start()} and
925 * {@link android.media.MediaRecorder#stop()}.
Wu-cheng Li40057ce2009-12-02 18:57:29 +0800926 *
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700927 * <p>After calling this method, you must not call {@link #startPreview()}
928 * or take another picture until the JPEG callback has returned.
929 *
930 * @param shutter the callback for image capture moment, or null
931 * @param raw the callback for raw (uncompressed) image data, or null
Dave Sparkse8b26e12009-07-14 10:35:40 -0700932 * @param postview callback with postview image data, may be null
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700933 * @param jpeg the callback for JPEG image data, or null
Dave Sparkse8b26e12009-07-14 10:35:40 -0700934 */
935 public final void takePicture(ShutterCallback shutter, PictureCallback raw,
936 PictureCallback postview, PictureCallback jpeg) {
937 mShutterCallback = shutter;
938 mRawImageCallback = raw;
939 mPostviewCallback = postview;
940 mJpegCallback = jpeg;
James Donge00cab72011-02-17 16:38:06 -0800941
942 // If callback is not set, do not send me callbacks.
943 int msgType = 0;
944 if (mShutterCallback != null) {
945 msgType |= CAMERA_MSG_SHUTTER;
946 }
947 if (mRawImageCallback != null) {
948 msgType |= CAMERA_MSG_RAW_IMAGE;
949 }
950 if (mPostviewCallback != null) {
951 msgType |= CAMERA_MSG_POSTVIEW_FRAME;
952 }
953 if (mJpegCallback != null) {
954 msgType |= CAMERA_MSG_COMPRESSED_IMAGE;
955 }
956
957 native_takePicture(msgType);
Dave Sparkse8b26e12009-07-14 10:35:40 -0700958 }
959
960 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700961 * Zooms to the requested value smoothly. The driver will notify {@link
Wu-cheng Li3f4639a2010-04-04 15:05:41 +0800962 * OnZoomChangeListener} of the zoom value and whether zoom is stopped at
963 * the time. For example, suppose the current zoom is 0 and startSmoothZoom
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700964 * is called with value 3. The
965 * {@link Camera.OnZoomChangeListener#onZoomChange(int, boolean, Camera)}
966 * method will be called three times with zoom values 1, 2, and 3.
967 * Applications can call {@link #stopSmoothZoom} to stop the zoom earlier.
968 * Applications should not call startSmoothZoom again or change the zoom
969 * value before zoom stops. If the supplied zoom value equals to the current
970 * zoom value, no zoom callback will be generated. This method is supported
971 * if {@link android.hardware.Camera.Parameters#isSmoothZoomSupported}
972 * returns true.
Wu-cheng Li36f68b82009-09-28 16:14:58 -0700973 *
974 * @param value zoom value. The valid range is 0 to {@link
975 * android.hardware.Camera.Parameters#getMaxZoom}.
Wu-cheng Li0ca25192010-03-29 16:21:12 +0800976 * @throws IllegalArgumentException if the zoom value is invalid.
977 * @throws RuntimeException if the method fails.
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700978 * @see #setZoomChangeListener(OnZoomChangeListener)
Wu-cheng Li36f68b82009-09-28 16:14:58 -0700979 */
980 public native final void startSmoothZoom(int value);
981
982 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700983 * Stops the smooth zoom. Applications should wait for the {@link
Wu-cheng Li3f4639a2010-04-04 15:05:41 +0800984 * OnZoomChangeListener} to know when the zoom is actually stopped. This
985 * method is supported if {@link
Wu-cheng Li8cbb8f52010-02-28 23:19:55 -0800986 * android.hardware.Camera.Parameters#isSmoothZoomSupported} is true.
Wu-cheng Li0ca25192010-03-29 16:21:12 +0800987 *
988 * @throws RuntimeException if the method fails.
Wu-cheng Li36f68b82009-09-28 16:14:58 -0700989 */
990 public native final void stopSmoothZoom();
991
992 /**
Wu-cheng Li2fe6fca2010-10-15 14:42:23 +0800993 * Set the clockwise rotation of preview display in degrees. This affects
994 * the preview frames and the picture displayed after snapshot. This method
995 * is useful for portrait mode applications. Note that preview display of
Wu-cheng Lib982fb42010-10-19 17:19:09 +0800996 * front-facing cameras is flipped horizontally before the rotation, that
997 * is, the image is reflected along the central vertical axis of the camera
998 * sensor. So the users can see themselves as looking into a mirror.
Chih-Chung Changd1d77062010-01-22 17:49:48 -0800999 *
Brad Fitzpatrick69ea4e12011-01-05 11:13:40 -08001000 * <p>This does not affect the order of byte array passed in {@link
Wu-cheng Li2fe6fca2010-10-15 14:42:23 +08001001 * PreviewCallback#onPreviewFrame}, JPEG pictures, or recorded videos. This
1002 * method is not allowed to be called during preview.
Chih-Chung Changd1d77062010-01-22 17:49:48 -08001003 *
Brad Fitzpatrick69ea4e12011-01-05 11:13:40 -08001004 * <p>If you want to make the camera image show in the same orientation as
1005 * the display, you can use the following code.
Chih-Chung Changb8bb78f2010-06-10 13:32:16 +08001006 * <pre>
Chih-Chung Chang724c5222010-06-14 18:57:15 +08001007 * public static void setCameraDisplayOrientation(Activity activity,
1008 * int cameraId, android.hardware.Camera camera) {
1009 * android.hardware.Camera.CameraInfo info =
1010 * new android.hardware.Camera.CameraInfo();
1011 * android.hardware.Camera.getCameraInfo(cameraId, info);
1012 * int rotation = activity.getWindowManager().getDefaultDisplay()
1013 * .getRotation();
1014 * int degrees = 0;
1015 * switch (rotation) {
1016 * case Surface.ROTATION_0: degrees = 0; break;
1017 * case Surface.ROTATION_90: degrees = 90; break;
1018 * case Surface.ROTATION_180: degrees = 180; break;
1019 * case Surface.ROTATION_270: degrees = 270; break;
1020 * }
Chih-Chung Changb8bb78f2010-06-10 13:32:16 +08001021 *
Wu-cheng Li2fe6fca2010-10-15 14:42:23 +08001022 * int result;
1023 * if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
1024 * result = (info.orientation + degrees) % 360;
1025 * result = (360 - result) % 360; // compensate the mirror
1026 * } else { // back-facing
1027 * result = (info.orientation - degrees + 360) % 360;
1028 * }
Chih-Chung Chang724c5222010-06-14 18:57:15 +08001029 * camera.setDisplayOrientation(result);
1030 * }
Chih-Chung Changb8bb78f2010-06-10 13:32:16 +08001031 * </pre>
Chih-Chung Changd1d77062010-01-22 17:49:48 -08001032 * @param degrees the angle that the picture will be rotated clockwise.
Chih-Chung Change7bd22a2010-01-27 10:24:42 -08001033 * Valid values are 0, 90, 180, and 270. The starting
1034 * position is 0 (landscape).
Wu-cheng Li2fe6fca2010-10-15 14:42:23 +08001035 * @see #setPreviewDisplay(SurfaceHolder)
Chih-Chung Changd1d77062010-01-22 17:49:48 -08001036 */
1037 public native final void setDisplayOrientation(int degrees);
1038
1039 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -07001040 * Callback interface for zoom changes during a smooth zoom operation.
1041 *
1042 * @see #setZoomChangeListener(OnZoomChangeListener)
1043 * @see #startSmoothZoom(int)
Dave Sparkse8b26e12009-07-14 10:35:40 -07001044 */
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08001045 public interface OnZoomChangeListener
Dave Sparkse8b26e12009-07-14 10:35:40 -07001046 {
1047 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -07001048 * Called when the zoom value has changed during a smooth zoom.
Wu-cheng Li36f68b82009-09-28 16:14:58 -07001049 *
1050 * @param zoomValue the current zoom value. In smooth zoom mode, camera
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08001051 * calls this for every new zoom value.
Wu-cheng Li36f68b82009-09-28 16:14:58 -07001052 * @param stopped whether smooth zoom is stopped. If the value is true,
1053 * this is the last zoom update for the application.
Dave Sparkse8b26e12009-07-14 10:35:40 -07001054 * @param camera the Camera service object
1055 */
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08001056 void onZoomChange(int zoomValue, boolean stopped, Camera camera);
Dave Sparkse8b26e12009-07-14 10:35:40 -07001057 };
1058
1059 /**
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08001060 * Registers a listener to be notified when the zoom value is updated by the
Wu-cheng Li36f68b82009-09-28 16:14:58 -07001061 * camera driver during smooth zoom.
Wu-cheng Li8cbb8f52010-02-28 23:19:55 -08001062 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08001063 * @param listener the listener to notify
Wu-cheng Li8cbb8f52010-02-28 23:19:55 -08001064 * @see #startSmoothZoom(int)
Dave Sparkse8b26e12009-07-14 10:35:40 -07001065 */
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08001066 public final void setZoomChangeListener(OnZoomChangeListener listener)
Dave Sparkse8b26e12009-07-14 10:35:40 -07001067 {
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08001068 mZoomListener = listener;
Dave Sparkse8b26e12009-07-14 10:35:40 -07001069 }
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001070
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08001071 /**
1072 * Callback interface for face detected in the preview frame.
1073 *
1074 * @hide
1075 */
1076 public interface FaceDetectionListener
1077 {
1078 /**
1079 * Notify the listener of the detected faces in the preview frame.
1080 *
Wu-cheng Lif0d6a482011-07-28 05:30:59 +08001081 * @param faces the detected faces. The list is sorted by the score.
1082 * The highest score is the first element.
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08001083 * @param camera the Camera service object
1084 */
Wu-cheng Lif0d6a482011-07-28 05:30:59 +08001085 void onFaceDetection(Face[] faces, Camera camera);
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08001086 }
1087
1088 /**
1089 * Registers a listener to be notified about the face detected of the
1090 * preview frame.
1091 *
1092 * @param listener the listener to notify
1093 * @see #startFaceDetection(int)
1094 * @hide
1095 */
1096 public final void setFaceDetectionListener(FaceDetectionListener listener)
1097 {
1098 mFaceListener = listener;
1099 }
1100
1101 /**
1102 * Start the face detection. This should be called after preview is started.
1103 * The camera will notify {@link FaceDetectionListener} of the detected
1104 * faces in the preview frame. The detected faces may be the same as the
1105 * previous ones. Applications should call {@link #stopFaceDetection} to
1106 * stop the face detection. This method is supported if {@link
1107 * Parameters#getMaxNumDetectedFaces(int)} returns a number larger than 0.
1108 * Hardware and software face detection cannot be used at the same time.
1109 * If the face detection has started, apps should not call this again.
1110 *
1111 * In hardware face detection mode, {@link Parameters#setWhiteBalance(String)},
1112 * {@link Parameters#setFocusAreas(List)}, and {@link Parameters#setMeteringAreas(List)}
1113 * have no effect.
1114 *
1115 * @param type face detection type. This can be either {@link
1116 * #CAMERA_FACE_DETECTION_HW} or {@link #CAMERA_FACE_DETECTION_SW}
1117 * @throws IllegalArgumentException if the face detection type is
1118 * unsupported or invalid.
1119 * @throws RuntimeException if the method fails or the face detection is
1120 * already running.
1121 * @see #CAMERA_FACE_DETECTION_HW
1122 * @see #CAMERA_FACE_DETECTION_SW
1123 * @see FaceDetectionListener
1124 * @see #stopFaceDetection()
1125 * @see Parameters#getMaxNumDetectedFaces(int)
1126 * @hide
1127 */
1128 public final void startFaceDetection(int type) {
1129 if (type != CAMERA_FACE_DETECTION_HW && type != CAMERA_FACE_DETECTION_SW) {
1130 throw new IllegalArgumentException("Invalid face detection type " + type);
1131 }
1132 if (mFaceDetectionRunning) {
1133 throw new RuntimeException("Face detection is already running");
1134 }
1135 _startFaceDetection(type);
1136 mFaceDetectionRunning = true;
1137 }
1138
1139 /**
1140 * Stop the face detection.
1141 *
1142 * @see #startFaceDetection(int)
1143 * @hide
1144 */
1145 public final void stopFaceDetection() {
1146 _stopFaceDetection();
1147 mFaceDetectionRunning = false;
1148 }
1149
1150 private native final void _startFaceDetection(int type);
1151 private native final void _stopFaceDetection();
1152
1153 /**
Wu-cheng Lif0d6a482011-07-28 05:30:59 +08001154 * The information of a face from camera face detection.
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08001155 *
1156 * @hide
1157 */
Wu-cheng Lif0d6a482011-07-28 05:30:59 +08001158 public static class Face {
Wu-cheng Libb1e2752011-07-30 05:00:37 +08001159 public Face() {
1160 }
1161
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08001162 /**
1163 * Bounds of the face. (-1000, -1000) represents the top-left of the
1164 * camera field of view, and (1000, 1000) represents the bottom-right of
Wu-cheng Lif0d6a482011-07-28 05:30:59 +08001165 * the field of view. The width and height cannot be 0 or negative. This
1166 * is supported by both hardware and software face detection.
1167 *
1168 * <p>The direction is relative to the sensor orientation, that is, what
1169 * the sensor sees. The direction is not affected by the rotation or
1170 * mirroring of {@link #setDisplayOrientation(int)}.</p>
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08001171 *
1172 * @see #startFaceDetection(int)
1173 */
Wu-cheng Libb1e2752011-07-30 05:00:37 +08001174 public Rect rect;
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08001175
1176 /**
1177 * The confidence level of the face. The range is 1 to 100. 100 is the
1178 * highest confidence. This is supported by both hardware and software
1179 * face detction.
1180 *
1181 * @see #startFaceDetection(int)
1182 */
Wu-cheng Libb1e2752011-07-30 05:00:37 +08001183 public int score;
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08001184
1185 /**
1186 * An unique id per face while the face is visible to the tracker. If
1187 * the face leaves the field-of-view and comes back, it will get a new
1188 * id. If the value is 0, id is not supported.
1189 */
Wu-cheng Libb1e2752011-07-30 05:00:37 +08001190 public int id;
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08001191
1192 /**
Wu-cheng Lif0d6a482011-07-28 05:30:59 +08001193 * The coordinates of the center of the left eye. The range is -1000 to
1194 * 1000. null if this is not supported.
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08001195 */
Wu-cheng Libb1e2752011-07-30 05:00:37 +08001196 public Point leftEye;
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08001197
1198 /**
Wu-cheng Lif0d6a482011-07-28 05:30:59 +08001199 * The coordinates of the center of the right eye. The range is -1000 to
1200 * 1000. null if this is not supported.
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08001201 */
Wu-cheng Libb1e2752011-07-30 05:00:37 +08001202 public Point rightEye;
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08001203
1204 /**
Wu-cheng Lif0d6a482011-07-28 05:30:59 +08001205 * The coordinates of the center of the mouth. The range is -1000 to
1206 * 1000. null if this is not supported.
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08001207 */
Wu-cheng Libb1e2752011-07-30 05:00:37 +08001208 public Point mouth;
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08001209 }
1210
Dan Egnorbfcbeff2010-07-12 15:12:54 -07001211 // Error codes match the enum in include/ui/Camera.h
1212
1213 /**
1214 * Unspecified camera error.
1215 * @see Camera.ErrorCallback
1216 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001217 public static final int CAMERA_ERROR_UNKNOWN = 1;
Dan Egnorbfcbeff2010-07-12 15:12:54 -07001218
1219 /**
1220 * Media server died. In this case, the application must release the
1221 * Camera object and instantiate a new one.
1222 * @see Camera.ErrorCallback
1223 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001224 public static final int CAMERA_ERROR_SERVER_DIED = 100;
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001225
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001226 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -07001227 * Callback interface for camera error notification.
1228 *
1229 * @see #setErrorCallback(ErrorCallback)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001230 */
1231 public interface ErrorCallback
1232 {
1233 /**
1234 * Callback for camera errors.
1235 * @param error error code:
1236 * <ul>
1237 * <li>{@link #CAMERA_ERROR_UNKNOWN}
1238 * <li>{@link #CAMERA_ERROR_SERVER_DIED}
1239 * </ul>
1240 * @param camera the Camera service object
1241 */
1242 void onError(int error, Camera camera);
1243 };
1244
1245 /**
1246 * Registers a callback to be invoked when an error occurs.
Dan Egnorbfcbeff2010-07-12 15:12:54 -07001247 * @param cb The callback to run
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001248 */
1249 public final void setErrorCallback(ErrorCallback cb)
1250 {
1251 mErrorCallback = cb;
1252 }
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001253
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001254 private native final void native_setParameters(String params);
1255 private native final String native_getParameters();
1256
1257 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -07001258 * Changes the settings for this Camera service.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001259 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001260 * @param params the Parameters to use for this Camera service
Wu-cheng Li99a3f3e2010-11-19 15:56:16 +08001261 * @throws RuntimeException if any parameter is invalid or not supported.
Dan Egnorbfcbeff2010-07-12 15:12:54 -07001262 * @see #getParameters()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001263 */
1264 public void setParameters(Parameters params) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001265 native_setParameters(params.flatten());
1266 }
1267
1268 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -07001269 * Returns the current settings for this Camera service.
1270 * If modifications are made to the returned Parameters, they must be passed
1271 * to {@link #setParameters(Camera.Parameters)} to take effect.
1272 *
1273 * @see #setParameters(Camera.Parameters)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001274 */
1275 public Parameters getParameters() {
1276 Parameters p = new Parameters();
1277 String s = native_getParameters();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001278 p.unflatten(s);
1279 return p;
1280 }
1281
1282 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -07001283 * Image size (width and height dimensions).
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001284 */
1285 public class Size {
1286 /**
1287 * Sets the dimensions for pictures.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001288 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001289 * @param w the photo width (pixels)
1290 * @param h the photo height (pixels)
1291 */
1292 public Size(int w, int h) {
1293 width = w;
1294 height = h;
1295 }
Wu-cheng Li4c4300c2010-01-23 15:45:39 +08001296 /**
1297 * Compares {@code obj} to this size.
1298 *
1299 * @param obj the object to compare this size with.
1300 * @return {@code true} if the width and height of {@code obj} is the
1301 * same as those of this size. {@code false} otherwise.
1302 */
1303 @Override
1304 public boolean equals(Object obj) {
1305 if (!(obj instanceof Size)) {
1306 return false;
1307 }
1308 Size s = (Size) obj;
1309 return width == s.width && height == s.height;
1310 }
1311 @Override
1312 public int hashCode() {
1313 return width * 32713 + height;
1314 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001315 /** width of the picture */
1316 public int width;
1317 /** height of the picture */
1318 public int height;
1319 };
1320
1321 /**
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07001322 * <p>The Area class is used for choosing specific metering and focus areas for
1323 * the camera to use when calculating auto-exposure, auto-white balance, and
1324 * auto-focus.</p>
1325 *
1326 * <p>To find out how many simultaneous areas a given camera supports, use
1327 * {@link Parameters#getMaxNumMeteringAreas()} and
1328 * {@link Parameters#getMaxNumFocusAreas()}. If metering or focusing area
1329 * selection is unsupported, these methods will return 0.</p>
1330 *
1331 * <p>Each Area consists of a rectangle specifying its bounds, and a weight
1332 * that determines its importance. The bounds are relative to the camera's
1333 * current field of view. The coordinates are mapped so that (-1000, -1000)
1334 * is always the top-left corner of the current field of view, and (1000,
1335 * 1000) is always the bottom-right corner of the current field of
1336 * view. Setting Areas with bounds outside that range is not allowed. Areas
1337 * with zero or negative width or height are not allowed.</p>
1338 *
1339 * <p>The weight must range from 1 to 1000, and represents a weight for
1340 * every pixel in the area. This means that a large metering area with
1341 * the same weight as a smaller area will have more effect in the
1342 * metering result. Metering areas can overlap and the driver
1343 * will add the weights in the overlap region.</p>
Wu-cheng Li30771b72011-04-02 06:19:46 +08001344 *
Wu-cheng Libde61a52011-06-07 18:23:14 +08001345 * @see Parameters#setFocusAreas(List)
1346 * @see Parameters#getFocusAreas()
1347 * @see Parameters#getMaxNumFocusAreas()
1348 * @see Parameters#setMeteringAreas(List)
1349 * @see Parameters#getMeteringAreas()
1350 * @see Parameters#getMaxNumMeteringAreas()
Wu-cheng Li30771b72011-04-02 06:19:46 +08001351 */
1352 public static class Area {
1353 /**
1354 * Create an area with specified rectangle and weight.
1355 *
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07001356 * @param rect the bounds of the area.
1357 * @param weight the weight of the area.
Wu-cheng Li30771b72011-04-02 06:19:46 +08001358 */
1359 public Area(Rect rect, int weight) {
1360 this.rect = rect;
1361 this.weight = weight;
1362 }
1363 /**
1364 * Compares {@code obj} to this area.
1365 *
1366 * @param obj the object to compare this area with.
1367 * @return {@code true} if the rectangle and weight of {@code obj} is
1368 * the same as those of this area. {@code false} otherwise.
1369 */
1370 @Override
1371 public boolean equals(Object obj) {
1372 if (!(obj instanceof Area)) {
1373 return false;
1374 }
1375 Area a = (Area) obj;
1376 if (rect == null) {
1377 if (a.rect != null) return false;
1378 } else {
1379 if (!rect.equals(a.rect)) return false;
1380 }
1381 return weight == a.weight;
1382 }
1383
Wu-cheng Libde61a52011-06-07 18:23:14 +08001384 /**
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07001385 * Bounds of the area. (-1000, -1000) represents the top-left of the
1386 * camera field of view, and (1000, 1000) represents the bottom-right of
1387 * the field of view. Setting bounds outside that range is not
1388 * allowed. Bounds with zero or negative width or height are not
1389 * allowed.
Wu-cheng Libde61a52011-06-07 18:23:14 +08001390 *
1391 * @see Parameters#getFocusAreas()
1392 * @see Parameters#getMeteringAreas()
1393 */
Wu-cheng Li30771b72011-04-02 06:19:46 +08001394 public Rect rect;
1395
Wu-cheng Libde61a52011-06-07 18:23:14 +08001396 /**
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07001397 * Weight of the area. The weight must range from 1 to 1000, and
1398 * represents a weight for every pixel in the area. This means that a
1399 * large metering area with the same weight as a smaller area will have
1400 * more effect in the metering result. Metering areas can overlap and
1401 * the driver will add the weights in the overlap region.
Wu-cheng Libde61a52011-06-07 18:23:14 +08001402 *
1403 * @see Parameters#getFocusAreas()
1404 * @see Parameters#getMeteringAreas()
1405 */
Wu-cheng Li30771b72011-04-02 06:19:46 +08001406 public int weight;
Wu-cheng Libde61a52011-06-07 18:23:14 +08001407 }
Wu-cheng Li30771b72011-04-02 06:19:46 +08001408
1409 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -07001410 * Camera service settings.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001411 *
1412 * <p>To make camera parameters take effect, applications have to call
Dan Egnorbfcbeff2010-07-12 15:12:54 -07001413 * {@link Camera#setParameters(Camera.Parameters)}. For example, after
1414 * {@link Camera.Parameters#setWhiteBalance} is called, white balance is not
1415 * actually changed until {@link Camera#setParameters(Camera.Parameters)}
1416 * is called with the changed parameters object.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001417 *
1418 * <p>Different devices may have different camera capabilities, such as
1419 * picture size or flash modes. The application should query the camera
1420 * capabilities before setting parameters. For example, the application
Dan Egnorbfcbeff2010-07-12 15:12:54 -07001421 * should call {@link Camera.Parameters#getSupportedColorEffects()} before
1422 * calling {@link Camera.Parameters#setColorEffect(String)}. If the
1423 * camera does not support color effects,
1424 * {@link Camera.Parameters#getSupportedColorEffects()} will return null.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001425 */
1426 public class Parameters {
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001427 // Parameter keys to communicate with the camera driver.
1428 private static final String KEY_PREVIEW_SIZE = "preview-size";
1429 private static final String KEY_PREVIEW_FORMAT = "preview-format";
1430 private static final String KEY_PREVIEW_FRAME_RATE = "preview-frame-rate";
Wu-cheng Li454630f2010-08-11 16:48:05 -07001431 private static final String KEY_PREVIEW_FPS_RANGE = "preview-fps-range";
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001432 private static final String KEY_PICTURE_SIZE = "picture-size";
1433 private static final String KEY_PICTURE_FORMAT = "picture-format";
Wu-cheng Li4c4300c2010-01-23 15:45:39 +08001434 private static final String KEY_JPEG_THUMBNAIL_SIZE = "jpeg-thumbnail-size";
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001435 private static final String KEY_JPEG_THUMBNAIL_WIDTH = "jpeg-thumbnail-width";
1436 private static final String KEY_JPEG_THUMBNAIL_HEIGHT = "jpeg-thumbnail-height";
1437 private static final String KEY_JPEG_THUMBNAIL_QUALITY = "jpeg-thumbnail-quality";
1438 private static final String KEY_JPEG_QUALITY = "jpeg-quality";
1439 private static final String KEY_ROTATION = "rotation";
1440 private static final String KEY_GPS_LATITUDE = "gps-latitude";
1441 private static final String KEY_GPS_LONGITUDE = "gps-longitude";
1442 private static final String KEY_GPS_ALTITUDE = "gps-altitude";
1443 private static final String KEY_GPS_TIMESTAMP = "gps-timestamp";
Ray Chen055c9862010-02-23 10:45:42 +08001444 private static final String KEY_GPS_PROCESSING_METHOD = "gps-processing-method";
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001445 private static final String KEY_WHITE_BALANCE = "whitebalance";
1446 private static final String KEY_EFFECT = "effect";
1447 private static final String KEY_ANTIBANDING = "antibanding";
1448 private static final String KEY_SCENE_MODE = "scene-mode";
1449 private static final String KEY_FLASH_MODE = "flash-mode";
Wu-cheng Li36322db2009-09-18 18:59:21 +08001450 private static final String KEY_FOCUS_MODE = "focus-mode";
Wu-cheng Li30771b72011-04-02 06:19:46 +08001451 private static final String KEY_FOCUS_AREAS = "focus-areas";
1452 private static final String KEY_MAX_NUM_FOCUS_AREAS = "max-num-focus-areas";
Wu-cheng Li6c8d2762010-01-27 22:55:14 +08001453 private static final String KEY_FOCAL_LENGTH = "focal-length";
1454 private static final String KEY_HORIZONTAL_VIEW_ANGLE = "horizontal-view-angle";
1455 private static final String KEY_VERTICAL_VIEW_ANGLE = "vertical-view-angle";
Wu-cheng Liff723b62010-02-09 13:38:19 +08001456 private static final String KEY_EXPOSURE_COMPENSATION = "exposure-compensation";
Wu-cheng Li24b326a2010-02-20 17:47:04 +08001457 private static final String KEY_MAX_EXPOSURE_COMPENSATION = "max-exposure-compensation";
1458 private static final String KEY_MIN_EXPOSURE_COMPENSATION = "min-exposure-compensation";
1459 private static final String KEY_EXPOSURE_COMPENSATION_STEP = "exposure-compensation-step";
Eino-Ville Talvala3773eef2011-04-15 13:51:42 -07001460 private static final String KEY_AUTO_EXPOSURE_LOCK = "auto-exposure-lock";
1461 private static final String KEY_AUTO_EXPOSURE_LOCK_SUPPORTED = "auto-exposure-lock-supported";
Eino-Ville Talvalad9c2601a2011-05-13 10:19:59 -07001462 private static final String KEY_AUTO_WHITEBALANCE_LOCK = "auto-whitebalance-lock";
1463 private static final String KEY_AUTO_WHITEBALANCE_LOCK_SUPPORTED = "auto-whitebalance-lock-supported";
Wu-cheng Lie98e4c82011-04-12 19:34:29 +08001464 private static final String KEY_METERING_AREAS = "metering-areas";
1465 private static final String KEY_MAX_NUM_METERING_AREAS = "max-num-metering-areas";
Wu-cheng Li8cbb8f52010-02-28 23:19:55 -08001466 private static final String KEY_ZOOM = "zoom";
1467 private static final String KEY_MAX_ZOOM = "max-zoom";
1468 private static final String KEY_ZOOM_RATIOS = "zoom-ratios";
1469 private static final String KEY_ZOOM_SUPPORTED = "zoom-supported";
1470 private static final String KEY_SMOOTH_ZOOM_SUPPORTED = "smooth-zoom-supported";
Wu-cheng Lie339c5e2010-05-13 19:31:02 +08001471 private static final String KEY_FOCUS_DISTANCES = "focus-distances";
James Dongdd0b16c2010-09-21 16:23:48 -07001472 private static final String KEY_VIDEO_SIZE = "video-size";
1473 private static final String KEY_PREFERRED_PREVIEW_SIZE_FOR_VIDEO =
1474 "preferred-preview-size-for-video";
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08001475 private static final String KEY_MAX_NUM_DETECTED_FACES_HW = "max-num-detected-faces-hw";
1476 private static final String KEY_MAX_NUM_DETECTED_FACES_SW = "max-num-detected-faces-sw";
Wu-cheng Li25d8fb52011-08-02 13:20:36 +08001477 private static final String KEY_RECORDING_HINT = "recording-hint";
Wu-cheng Lie339c5e2010-05-13 19:31:02 +08001478
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001479 // Parameter key suffix for supported values.
1480 private static final String SUPPORTED_VALUES_SUFFIX = "-values";
1481
Wu-cheng Li8cbb8f52010-02-28 23:19:55 -08001482 private static final String TRUE = "true";
Eino-Ville Talvala3773eef2011-04-15 13:51:42 -07001483 private static final String FALSE = "false";
Wu-cheng Li8cbb8f52010-02-28 23:19:55 -08001484
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001485 // Values for white balance settings.
1486 public static final String WHITE_BALANCE_AUTO = "auto";
1487 public static final String WHITE_BALANCE_INCANDESCENT = "incandescent";
1488 public static final String WHITE_BALANCE_FLUORESCENT = "fluorescent";
1489 public static final String WHITE_BALANCE_WARM_FLUORESCENT = "warm-fluorescent";
1490 public static final String WHITE_BALANCE_DAYLIGHT = "daylight";
1491 public static final String WHITE_BALANCE_CLOUDY_DAYLIGHT = "cloudy-daylight";
1492 public static final String WHITE_BALANCE_TWILIGHT = "twilight";
1493 public static final String WHITE_BALANCE_SHADE = "shade";
1494
1495 // Values for color effect settings.
1496 public static final String EFFECT_NONE = "none";
1497 public static final String EFFECT_MONO = "mono";
1498 public static final String EFFECT_NEGATIVE = "negative";
1499 public static final String EFFECT_SOLARIZE = "solarize";
1500 public static final String EFFECT_SEPIA = "sepia";
1501 public static final String EFFECT_POSTERIZE = "posterize";
1502 public static final String EFFECT_WHITEBOARD = "whiteboard";
1503 public static final String EFFECT_BLACKBOARD = "blackboard";
1504 public static final String EFFECT_AQUA = "aqua";
1505
1506 // Values for antibanding settings.
1507 public static final String ANTIBANDING_AUTO = "auto";
1508 public static final String ANTIBANDING_50HZ = "50hz";
1509 public static final String ANTIBANDING_60HZ = "60hz";
1510 public static final String ANTIBANDING_OFF = "off";
1511
1512 // Values for flash mode settings.
1513 /**
1514 * Flash will not be fired.
1515 */
1516 public static final String FLASH_MODE_OFF = "off";
Wu-cheng Li36f68b82009-09-28 16:14:58 -07001517
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001518 /**
Wu-cheng Li068ef422009-09-27 13:19:36 -07001519 * Flash will be fired automatically when required. The flash may be fired
1520 * during preview, auto-focus, or snapshot depending on the driver.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001521 */
1522 public static final String FLASH_MODE_AUTO = "auto";
Wu-cheng Li36f68b82009-09-28 16:14:58 -07001523
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001524 /**
Wu-cheng Li068ef422009-09-27 13:19:36 -07001525 * Flash will always be fired during snapshot. The flash may also be
1526 * fired during preview or auto-focus depending on the driver.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001527 */
1528 public static final String FLASH_MODE_ON = "on";
Wu-cheng Li36f68b82009-09-28 16:14:58 -07001529
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001530 /**
1531 * Flash will be fired in red-eye reduction mode.
1532 */
1533 public static final String FLASH_MODE_RED_EYE = "red-eye";
Wu-cheng Li36f68b82009-09-28 16:14:58 -07001534
Wu-cheng Li36322db2009-09-18 18:59:21 +08001535 /**
Wu-cheng Li068ef422009-09-27 13:19:36 -07001536 * Constant emission of light during preview, auto-focus and snapshot.
1537 * This can also be used for video recording.
Wu-cheng Li36322db2009-09-18 18:59:21 +08001538 */
Wu-cheng Li068ef422009-09-27 13:19:36 -07001539 public static final String FLASH_MODE_TORCH = "torch";
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001540
Wu-cheng Li00e21f82010-05-28 16:43:38 +08001541 /**
1542 * Scene mode is off.
1543 */
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001544 public static final String SCENE_MODE_AUTO = "auto";
Wu-cheng Li00e21f82010-05-28 16:43:38 +08001545
1546 /**
1547 * Take photos of fast moving objects. Same as {@link
1548 * #SCENE_MODE_SPORTS}.
1549 */
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001550 public static final String SCENE_MODE_ACTION = "action";
Wu-cheng Li00e21f82010-05-28 16:43:38 +08001551
1552 /**
1553 * Take people pictures.
1554 */
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001555 public static final String SCENE_MODE_PORTRAIT = "portrait";
Wu-cheng Li00e21f82010-05-28 16:43:38 +08001556
1557 /**
1558 * Take pictures on distant objects.
1559 */
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001560 public static final String SCENE_MODE_LANDSCAPE = "landscape";
Wu-cheng Li00e21f82010-05-28 16:43:38 +08001561
1562 /**
1563 * Take photos at night.
1564 */
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001565 public static final String SCENE_MODE_NIGHT = "night";
Wu-cheng Li00e21f82010-05-28 16:43:38 +08001566
1567 /**
1568 * Take people pictures at night.
1569 */
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001570 public static final String SCENE_MODE_NIGHT_PORTRAIT = "night-portrait";
Wu-cheng Li00e21f82010-05-28 16:43:38 +08001571
1572 /**
1573 * Take photos in a theater. Flash light is off.
1574 */
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001575 public static final String SCENE_MODE_THEATRE = "theatre";
Wu-cheng Li00e21f82010-05-28 16:43:38 +08001576
1577 /**
1578 * Take pictures on the beach.
1579 */
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001580 public static final String SCENE_MODE_BEACH = "beach";
Wu-cheng Li00e21f82010-05-28 16:43:38 +08001581
1582 /**
1583 * Take pictures on the snow.
1584 */
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001585 public static final String SCENE_MODE_SNOW = "snow";
Wu-cheng Li00e21f82010-05-28 16:43:38 +08001586
1587 /**
1588 * Take sunset photos.
1589 */
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001590 public static final String SCENE_MODE_SUNSET = "sunset";
Wu-cheng Li00e21f82010-05-28 16:43:38 +08001591
1592 /**
1593 * Avoid blurry pictures (for example, due to hand shake).
1594 */
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001595 public static final String SCENE_MODE_STEADYPHOTO = "steadyphoto";
Wu-cheng Li00e21f82010-05-28 16:43:38 +08001596
1597 /**
1598 * For shooting firework displays.
1599 */
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001600 public static final String SCENE_MODE_FIREWORKS = "fireworks";
Wu-cheng Li00e21f82010-05-28 16:43:38 +08001601
1602 /**
1603 * Take photos of fast moving objects. Same as {@link
1604 * #SCENE_MODE_ACTION}.
1605 */
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001606 public static final String SCENE_MODE_SPORTS = "sports";
Wu-cheng Li00e21f82010-05-28 16:43:38 +08001607
1608 /**
1609 * Take indoor low-light shot.
1610 */
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001611 public static final String SCENE_MODE_PARTY = "party";
Wu-cheng Li00e21f82010-05-28 16:43:38 +08001612
1613 /**
1614 * Capture the naturally warm color of scenes lit by candles.
1615 */
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001616 public static final String SCENE_MODE_CANDLELIGHT = "candlelight";
1617
Wu-cheng Lic58b4232010-03-29 17:21:28 +08001618 /**
1619 * Applications are looking for a barcode. Camera driver will be
1620 * optimized for barcode reading.
1621 */
1622 public static final String SCENE_MODE_BARCODE = "barcode";
1623
Wu-cheng Li36322db2009-09-18 18:59:21 +08001624 /**
Wu-cheng Lif008f3e2010-08-17 13:44:35 -07001625 * Auto-focus mode. Applications should call {@link
1626 * #autoFocus(AutoFocusCallback)} to start the focus in this mode.
Wu-cheng Li36322db2009-09-18 18:59:21 +08001627 */
1628 public static final String FOCUS_MODE_AUTO = "auto";
Wu-cheng Li36f68b82009-09-28 16:14:58 -07001629
Wu-cheng Li36322db2009-09-18 18:59:21 +08001630 /**
1631 * Focus is set at infinity. Applications should not call
1632 * {@link #autoFocus(AutoFocusCallback)} in this mode.
1633 */
1634 public static final String FOCUS_MODE_INFINITY = "infinity";
Wu-cheng Lif008f3e2010-08-17 13:44:35 -07001635
1636 /**
1637 * Macro (close-up) focus mode. Applications should call
1638 * {@link #autoFocus(AutoFocusCallback)} to start the focus in this
1639 * mode.
1640 */
Wu-cheng Li36322db2009-09-18 18:59:21 +08001641 public static final String FOCUS_MODE_MACRO = "macro";
Wu-cheng Li36f68b82009-09-28 16:14:58 -07001642
Wu-cheng Li36322db2009-09-18 18:59:21 +08001643 /**
1644 * Focus is fixed. The camera is always in this mode if the focus is not
1645 * adjustable. If the camera has auto-focus, this mode can fix the
1646 * focus, which is usually at hyperfocal distance. Applications should
1647 * not call {@link #autoFocus(AutoFocusCallback)} in this mode.
1648 */
1649 public static final String FOCUS_MODE_FIXED = "fixed";
1650
Wu-cheng Lic58b4232010-03-29 17:21:28 +08001651 /**
1652 * Extended depth of field (EDOF). Focusing is done digitally and
1653 * continuously. Applications should not call {@link
1654 * #autoFocus(AutoFocusCallback)} in this mode.
1655 */
1656 public static final String FOCUS_MODE_EDOF = "edof";
1657
Wu-cheng Li699fe932010-08-05 11:50:25 -07001658 /**
Wu-cheng Lid45cb722010-09-20 16:15:32 -07001659 * Continuous auto focus mode intended for video recording. The camera
1660 * continuously tries to focus. This is ideal for shooting video.
1661 * Applications still can call {@link
1662 * #takePicture(Camera.ShutterCallback, Camera.PictureCallback,
1663 * Camera.PictureCallback)} in this mode but the subject may not be in
1664 * focus. Auto focus starts when the parameter is set. Applications
1665 * should not call {@link #autoFocus(AutoFocusCallback)} in this mode.
1666 * To stop continuous focus, applications should change the focus mode
1667 * to other modes.
Wu-cheng Li699fe932010-08-05 11:50:25 -07001668 */
Wu-cheng Lid45cb722010-09-20 16:15:32 -07001669 public static final String FOCUS_MODE_CONTINUOUS_VIDEO = "continuous-video";
Wu-cheng Li699fe932010-08-05 11:50:25 -07001670
Wu-cheng Lie339c5e2010-05-13 19:31:02 +08001671 // Indices for focus distance array.
1672 /**
1673 * The array index of near focus distance for use with
1674 * {@link #getFocusDistances(float[])}.
1675 */
1676 public static final int FOCUS_DISTANCE_NEAR_INDEX = 0;
1677
1678 /**
1679 * The array index of optimal focus distance for use with
1680 * {@link #getFocusDistances(float[])}.
1681 */
1682 public static final int FOCUS_DISTANCE_OPTIMAL_INDEX = 1;
1683
1684 /**
1685 * The array index of far focus distance for use with
1686 * {@link #getFocusDistances(float[])}.
1687 */
1688 public static final int FOCUS_DISTANCE_FAR_INDEX = 2;
1689
Wu-cheng Lica099612010-05-06 16:47:30 +08001690 /**
Wu-cheng Li454630f2010-08-11 16:48:05 -07001691 * The array index of minimum preview fps for use with {@link
1692 * #getPreviewFpsRange(int[])} or {@link
1693 * #getSupportedPreviewFpsRange()}.
Wu-cheng Li454630f2010-08-11 16:48:05 -07001694 */
1695 public static final int PREVIEW_FPS_MIN_INDEX = 0;
1696
1697 /**
1698 * The array index of maximum preview fps for use with {@link
1699 * #getPreviewFpsRange(int[])} or {@link
1700 * #getSupportedPreviewFpsRange()}.
Wu-cheng Li454630f2010-08-11 16:48:05 -07001701 */
1702 public static final int PREVIEW_FPS_MAX_INDEX = 1;
1703
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001704 // Formats for setPreviewFormat and setPictureFormat.
1705 private static final String PIXEL_FORMAT_YUV422SP = "yuv422sp";
1706 private static final String PIXEL_FORMAT_YUV420SP = "yuv420sp";
Chih-Chung Changeb68c462009-09-18 18:37:44 +08001707 private static final String PIXEL_FORMAT_YUV422I = "yuv422i-yuyv";
Wu-cheng Li10a1b302011-02-22 15:49:25 +08001708 private static final String PIXEL_FORMAT_YUV420P = "yuv420p";
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001709 private static final String PIXEL_FORMAT_RGB565 = "rgb565";
1710 private static final String PIXEL_FORMAT_JPEG = "jpeg";
1711
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001712 private HashMap<String, String> mMap;
1713
1714 private Parameters() {
1715 mMap = new HashMap<String, String>();
1716 }
1717
1718 /**
1719 * Writes the current Parameters to the log.
1720 * @hide
1721 * @deprecated
1722 */
1723 public void dump() {
1724 Log.e(TAG, "dump: size=" + mMap.size());
1725 for (String k : mMap.keySet()) {
1726 Log.e(TAG, "dump: " + k + "=" + mMap.get(k));
1727 }
1728 }
1729
1730 /**
1731 * Creates a single string with all the parameters set in
1732 * this Parameters object.
1733 * <p>The {@link #unflatten(String)} method does the reverse.</p>
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001734 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001735 * @return a String with all values from this Parameters object, in
1736 * semi-colon delimited key-value pairs
1737 */
1738 public String flatten() {
1739 StringBuilder flattened = new StringBuilder();
1740 for (String k : mMap.keySet()) {
1741 flattened.append(k);
1742 flattened.append("=");
1743 flattened.append(mMap.get(k));
1744 flattened.append(";");
1745 }
1746 // chop off the extra semicolon at the end
1747 flattened.deleteCharAt(flattened.length()-1);
1748 return flattened.toString();
1749 }
1750
1751 /**
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001752 * Takes a flattened string of parameters and adds each one to
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001753 * this Parameters object.
1754 * <p>The {@link #flatten()} method does the reverse.</p>
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001755 *
1756 * @param flattened a String of parameters (key-value paired) that
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001757 * are semi-colon delimited
1758 */
1759 public void unflatten(String flattened) {
1760 mMap.clear();
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001761
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001762 StringTokenizer tokenizer = new StringTokenizer(flattened, ";");
1763 while (tokenizer.hasMoreElements()) {
1764 String kv = tokenizer.nextToken();
1765 int pos = kv.indexOf('=');
1766 if (pos == -1) {
1767 continue;
1768 }
1769 String k = kv.substring(0, pos);
1770 String v = kv.substring(pos + 1);
1771 mMap.put(k, v);
1772 }
1773 }
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001774
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001775 public void remove(String key) {
1776 mMap.remove(key);
1777 }
1778
1779 /**
1780 * Sets a String parameter.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001781 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001782 * @param key the key name for the parameter
1783 * @param value the String value of the parameter
1784 */
1785 public void set(String key, String value) {
1786 if (key.indexOf('=') != -1 || key.indexOf(';') != -1) {
1787 Log.e(TAG, "Key \"" + key + "\" contains invalid character (= or ;)");
1788 return;
1789 }
1790 if (value.indexOf('=') != -1 || value.indexOf(';') != -1) {
1791 Log.e(TAG, "Value \"" + value + "\" contains invalid character (= or ;)");
1792 return;
1793 }
1794
1795 mMap.put(key, value);
1796 }
1797
1798 /**
1799 * Sets an integer parameter.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001800 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001801 * @param key the key name for the parameter
1802 * @param value the int value of the parameter
1803 */
1804 public void set(String key, int value) {
1805 mMap.put(key, Integer.toString(value));
1806 }
1807
Wu-cheng Lie98e4c82011-04-12 19:34:29 +08001808 private void set(String key, List<Area> areas) {
Wu-cheng Lif715bf92011-04-14 14:04:18 +08001809 if (areas == null) {
1810 set(key, "(0,0,0,0,0)");
1811 } else {
1812 StringBuilder buffer = new StringBuilder();
1813 for (int i = 0; i < areas.size(); i++) {
1814 Area area = areas.get(i);
1815 Rect rect = area.rect;
1816 buffer.append('(');
1817 buffer.append(rect.left);
1818 buffer.append(',');
1819 buffer.append(rect.top);
1820 buffer.append(',');
1821 buffer.append(rect.right);
1822 buffer.append(',');
1823 buffer.append(rect.bottom);
1824 buffer.append(',');
1825 buffer.append(area.weight);
1826 buffer.append(')');
1827 if (i != areas.size() - 1) buffer.append(',');
1828 }
1829 set(key, buffer.toString());
Wu-cheng Lie98e4c82011-04-12 19:34:29 +08001830 }
Wu-cheng Lie98e4c82011-04-12 19:34:29 +08001831 }
1832
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001833 /**
1834 * Returns the value of a String parameter.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001835 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001836 * @param key the key name for the parameter
1837 * @return the String value of the parameter
1838 */
1839 public String get(String key) {
1840 return mMap.get(key);
1841 }
1842
1843 /**
1844 * Returns the value of an integer parameter.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001845 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001846 * @param key the key name for the parameter
1847 * @return the int value of the parameter
1848 */
1849 public int getInt(String key) {
1850 return Integer.parseInt(mMap.get(key));
1851 }
1852
1853 /**
Wu-cheng Li26274fa2011-05-05 14:36:28 +08001854 * Sets the dimensions for preview pictures. If the preview has already
1855 * started, applications should stop the preview first before changing
1856 * preview size.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001857 *
Wu-cheng Lic157e0c2010-10-07 18:36:07 +08001858 * The sides of width and height are based on camera orientation. That
1859 * is, the preview size is the size before it is rotated by display
1860 * orientation. So applications need to consider the display orientation
1861 * while setting preview size. For example, suppose the camera supports
1862 * both 480x320 and 320x480 preview sizes. The application wants a 3:2
1863 * preview ratio. If the display orientation is set to 0 or 180, preview
1864 * size should be set to 480x320. If the display orientation is set to
1865 * 90 or 270, preview size should be set to 320x480. The display
1866 * orientation should also be considered while setting picture size and
1867 * thumbnail size.
1868 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001869 * @param width the width of the pictures, in pixels
1870 * @param height the height of the pictures, in pixels
Wu-cheng Lic157e0c2010-10-07 18:36:07 +08001871 * @see #setDisplayOrientation(int)
1872 * @see #getCameraInfo(int, CameraInfo)
1873 * @see #setPictureSize(int, int)
1874 * @see #setJpegThumbnailSize(int, int)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001875 */
1876 public void setPreviewSize(int width, int height) {
1877 String v = Integer.toString(width) + "x" + Integer.toString(height);
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001878 set(KEY_PREVIEW_SIZE, v);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001879 }
1880
1881 /**
1882 * Returns the dimensions setting for preview pictures.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001883 *
James Dongdd0b16c2010-09-21 16:23:48 -07001884 * @return a Size object with the width and height setting
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001885 * for the preview picture
1886 */
1887 public Size getPreviewSize() {
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001888 String pair = get(KEY_PREVIEW_SIZE);
1889 return strToSize(pair);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001890 }
1891
1892 /**
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001893 * Gets the supported preview sizes.
1894 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08001895 * @return a list of Size object. This method will always return a list
Wu-cheng Li9c799382009-12-04 19:59:18 +08001896 * with at least one element.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001897 */
1898 public List<Size> getSupportedPreviewSizes() {
1899 String str = get(KEY_PREVIEW_SIZE + SUPPORTED_VALUES_SUFFIX);
1900 return splitSize(str);
1901 }
1902
1903 /**
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07001904 * <p>Gets the supported video frame sizes that can be used by
1905 * MediaRecorder.</p>
James Dongdd0b16c2010-09-21 16:23:48 -07001906 *
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07001907 * <p>If the returned list is not null, the returned list will contain at
James Dongdd0b16c2010-09-21 16:23:48 -07001908 * least one Size and one of the sizes in the returned list must be
1909 * passed to MediaRecorder.setVideoSize() for camcorder application if
1910 * camera is used as the video source. In this case, the size of the
1911 * preview can be different from the resolution of the recorded video
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07001912 * during video recording.</p>
James Dongdd0b16c2010-09-21 16:23:48 -07001913 *
1914 * @return a list of Size object if camera has separate preview and
1915 * video output; otherwise, null is returned.
1916 * @see #getPreferredPreviewSizeForVideo()
1917 */
1918 public List<Size> getSupportedVideoSizes() {
1919 String str = get(KEY_VIDEO_SIZE + SUPPORTED_VALUES_SUFFIX);
1920 return splitSize(str);
1921 }
1922
1923 /**
1924 * Returns the preferred or recommended preview size (width and height)
1925 * in pixels for video recording. Camcorder applications should
1926 * set the preview size to a value that is not larger than the
1927 * preferred preview size. In other words, the product of the width
1928 * and height of the preview size should not be larger than that of
1929 * the preferred preview size. In addition, we recommend to choose a
1930 * preview size that has the same aspect ratio as the resolution of
1931 * video to be recorded.
1932 *
1933 * @return the preferred preview size (width and height) in pixels for
1934 * video recording if getSupportedVideoSizes() does not return
1935 * null; otherwise, null is returned.
1936 * @see #getSupportedVideoSizes()
1937 */
1938 public Size getPreferredPreviewSizeForVideo() {
1939 String pair = get(KEY_PREFERRED_PREVIEW_SIZE_FOR_VIDEO);
1940 return strToSize(pair);
1941 }
1942
1943 /**
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07001944 * <p>Sets the dimensions for EXIF thumbnail in Jpeg picture. If
Wu-cheng Li4c4300c2010-01-23 15:45:39 +08001945 * applications set both width and height to 0, EXIF will not contain
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07001946 * thumbnail.</p>
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001947 *
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07001948 * <p>Applications need to consider the display orientation. See {@link
1949 * #setPreviewSize(int,int)} for reference.</p>
Wu-cheng Lic157e0c2010-10-07 18:36:07 +08001950 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001951 * @param width the width of the thumbnail, in pixels
1952 * @param height the height of the thumbnail, in pixels
Wu-cheng Lic157e0c2010-10-07 18:36:07 +08001953 * @see #setPreviewSize(int,int)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001954 */
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001955 public void setJpegThumbnailSize(int width, int height) {
1956 set(KEY_JPEG_THUMBNAIL_WIDTH, width);
1957 set(KEY_JPEG_THUMBNAIL_HEIGHT, height);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001958 }
1959
1960 /**
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001961 * Returns the dimensions for EXIF thumbnail in Jpeg picture.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001962 *
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001963 * @return a Size object with the height and width setting for the EXIF
1964 * thumbnails
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001965 */
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001966 public Size getJpegThumbnailSize() {
1967 return new Size(getInt(KEY_JPEG_THUMBNAIL_WIDTH),
1968 getInt(KEY_JPEG_THUMBNAIL_HEIGHT));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001969 }
1970
1971 /**
Wu-cheng Li4c4300c2010-01-23 15:45:39 +08001972 * Gets the supported jpeg thumbnail sizes.
1973 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08001974 * @return a list of Size object. This method will always return a list
Wu-cheng Li4c4300c2010-01-23 15:45:39 +08001975 * with at least two elements. Size 0,0 (no thumbnail) is always
1976 * supported.
1977 */
1978 public List<Size> getSupportedJpegThumbnailSizes() {
1979 String str = get(KEY_JPEG_THUMBNAIL_SIZE + SUPPORTED_VALUES_SUFFIX);
1980 return splitSize(str);
1981 }
1982
1983 /**
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001984 * Sets the quality of the EXIF thumbnail in Jpeg picture.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001985 *
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001986 * @param quality the JPEG quality of the EXIF thumbnail. The range is 1
1987 * to 100, with 100 being the best.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001988 */
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001989 public void setJpegThumbnailQuality(int quality) {
1990 set(KEY_JPEG_THUMBNAIL_QUALITY, quality);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001991 }
1992
1993 /**
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001994 * Returns the quality setting for the EXIF thumbnail in Jpeg picture.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001995 *
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001996 * @return the JPEG quality setting of the EXIF thumbnail.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001997 */
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001998 public int getJpegThumbnailQuality() {
1999 return getInt(KEY_JPEG_THUMBNAIL_QUALITY);
2000 }
2001
2002 /**
2003 * Sets Jpeg quality of captured picture.
2004 *
2005 * @param quality the JPEG quality of captured picture. The range is 1
2006 * to 100, with 100 being the best.
2007 */
2008 public void setJpegQuality(int quality) {
2009 set(KEY_JPEG_QUALITY, quality);
2010 }
2011
2012 /**
2013 * Returns the quality setting for the JPEG picture.
2014 *
2015 * @return the JPEG picture quality setting.
2016 */
2017 public int getJpegQuality() {
2018 return getInt(KEY_JPEG_QUALITY);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002019 }
2020
2021 /**
Wu-cheng Lia18e9012010-02-10 13:05:29 +08002022 * Sets the rate at which preview frames are received. This is the
2023 * target frame rate. The actual frame rate depends on the driver.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002024 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002025 * @param fps the frame rate (frames per second)
Wu-cheng Li5f1e69c2010-08-18 11:39:12 -07002026 * @deprecated replaced by {@link #setPreviewFpsRange(int,int)}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002027 */
Wu-cheng Li5f1e69c2010-08-18 11:39:12 -07002028 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002029 public void setPreviewFrameRate(int fps) {
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002030 set(KEY_PREVIEW_FRAME_RATE, fps);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002031 }
2032
2033 /**
Wu-cheng Lia18e9012010-02-10 13:05:29 +08002034 * Returns the setting for the rate at which preview frames are
2035 * received. This is the target frame rate. The actual frame rate
2036 * depends on the driver.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002037 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002038 * @return the frame rate setting (frames per second)
Wu-cheng Li5f1e69c2010-08-18 11:39:12 -07002039 * @deprecated replaced by {@link #getPreviewFpsRange(int[])}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002040 */
Wu-cheng Li5f1e69c2010-08-18 11:39:12 -07002041 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002042 public int getPreviewFrameRate() {
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002043 return getInt(KEY_PREVIEW_FRAME_RATE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002044 }
2045
2046 /**
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002047 * Gets the supported preview frame rates.
2048 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08002049 * @return a list of supported preview frame rates. null if preview
2050 * frame rate setting is not supported.
Wu-cheng Li5f1e69c2010-08-18 11:39:12 -07002051 * @deprecated replaced by {@link #getSupportedPreviewFpsRange()}
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002052 */
Wu-cheng Li5f1e69c2010-08-18 11:39:12 -07002053 @Deprecated
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002054 public List<Integer> getSupportedPreviewFrameRates() {
2055 String str = get(KEY_PREVIEW_FRAME_RATE + SUPPORTED_VALUES_SUFFIX);
2056 return splitInt(str);
2057 }
2058
2059 /**
Wu-cheng Li454630f2010-08-11 16:48:05 -07002060 * Sets the maximum and maximum preview fps. This controls the rate of
Wu-cheng Li1620d112010-08-27 15:09:20 -07002061 * preview frames received in {@link PreviewCallback}. The minimum and
Wu-cheng Li454630f2010-08-11 16:48:05 -07002062 * maximum preview fps must be one of the elements from {@link
2063 * #getSupportedPreviewFpsRange}.
2064 *
2065 * @param min the minimum preview fps (scaled by 1000).
2066 * @param max the maximum preview fps (scaled by 1000).
2067 * @throws RuntimeException if fps range is invalid.
2068 * @see #setPreviewCallbackWithBuffer(Camera.PreviewCallback)
2069 * @see #getSupportedPreviewFpsRange()
Wu-cheng Li454630f2010-08-11 16:48:05 -07002070 */
2071 public void setPreviewFpsRange(int min, int max) {
2072 set(KEY_PREVIEW_FPS_RANGE, "" + min + "," + max);
2073 }
2074
2075 /**
2076 * Returns the current minimum and maximum preview fps. The values are
2077 * one of the elements returned by {@link #getSupportedPreviewFpsRange}.
2078 *
2079 * @return range the minimum and maximum preview fps (scaled by 1000).
2080 * @see #PREVIEW_FPS_MIN_INDEX
2081 * @see #PREVIEW_FPS_MAX_INDEX
2082 * @see #getSupportedPreviewFpsRange()
Wu-cheng Li454630f2010-08-11 16:48:05 -07002083 */
2084 public void getPreviewFpsRange(int[] range) {
2085 if (range == null || range.length != 2) {
2086 throw new IllegalArgumentException(
Wu-cheng Li5f1e69c2010-08-18 11:39:12 -07002087 "range must be an array with two elements.");
Wu-cheng Li454630f2010-08-11 16:48:05 -07002088 }
2089 splitInt(get(KEY_PREVIEW_FPS_RANGE), range);
2090 }
2091
2092 /**
2093 * Gets the supported preview fps (frame-per-second) ranges. Each range
2094 * contains a minimum fps and maximum fps. If minimum fps equals to
2095 * maximum fps, the camera outputs frames in fixed frame rate. If not,
2096 * the camera outputs frames in auto frame rate. The actual frame rate
2097 * fluctuates between the minimum and the maximum. The values are
2098 * multiplied by 1000 and represented in integers. For example, if frame
2099 * rate is 26.623 frames per second, the value is 26623.
2100 *
2101 * @return a list of supported preview fps ranges. This method returns a
2102 * list with at least one element. Every element is an int array
2103 * of two values - minimum fps and maximum fps. The list is
2104 * sorted from small to large (first by maximum fps and then
2105 * minimum fps).
2106 * @see #PREVIEW_FPS_MIN_INDEX
2107 * @see #PREVIEW_FPS_MAX_INDEX
Wu-cheng Li454630f2010-08-11 16:48:05 -07002108 */
2109 public List<int[]> getSupportedPreviewFpsRange() {
2110 String str = get(KEY_PREVIEW_FPS_RANGE + SUPPORTED_VALUES_SUFFIX);
2111 return splitRange(str);
2112 }
2113
2114 /**
Wu-cheng Li7478ea62009-09-16 18:52:55 +08002115 * Sets the image format for preview pictures.
Scott Mainda0a56d2009-09-10 18:08:37 -07002116 * <p>If this is never called, the default format will be
Mathias Agopiana696f5d2010-02-17 17:53:09 -08002117 * {@link android.graphics.ImageFormat#NV21}, which
Scott Maindf4578e2009-09-10 12:22:07 -07002118 * uses the NV21 encoding format.</p>
Wu-cheng Li7478ea62009-09-16 18:52:55 +08002119 *
Scott Maindf4578e2009-09-10 12:22:07 -07002120 * @param pixel_format the desired preview picture format, defined
Mathias Agopiana696f5d2010-02-17 17:53:09 -08002121 * by one of the {@link android.graphics.ImageFormat} constants.
2122 * (E.g., <var>ImageFormat.NV21</var> (default),
2123 * <var>ImageFormat.RGB_565</var>, or
2124 * <var>ImageFormat.JPEG</var>)
2125 * @see android.graphics.ImageFormat
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002126 */
2127 public void setPreviewFormat(int pixel_format) {
2128 String s = cameraFormatForPixelFormat(pixel_format);
2129 if (s == null) {
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002130 throw new IllegalArgumentException(
2131 "Invalid pixel_format=" + pixel_format);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002132 }
2133
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002134 set(KEY_PREVIEW_FORMAT, s);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002135 }
2136
2137 /**
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08002138 * Returns the image format for preview frames got from
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002139 * {@link PreviewCallback}.
Wu-cheng Li7478ea62009-09-16 18:52:55 +08002140 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08002141 * @return the preview format.
2142 * @see android.graphics.ImageFormat
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002143 */
2144 public int getPreviewFormat() {
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002145 return pixelFormatForCameraFormat(get(KEY_PREVIEW_FORMAT));
2146 }
2147
2148 /**
Wu-cheng Lif9293e72011-02-25 13:35:10 +08002149 * Gets the supported preview formats. {@link android.graphics.ImageFormat#NV21}
2150 * is always supported. {@link android.graphics.ImageFormat#YV12}
2151 * is always supported since API level 12.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002152 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08002153 * @return a list of supported preview formats. This method will always
2154 * return a list with at least one element.
2155 * @see android.graphics.ImageFormat
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002156 */
2157 public List<Integer> getSupportedPreviewFormats() {
2158 String str = get(KEY_PREVIEW_FORMAT + SUPPORTED_VALUES_SUFFIX);
Chih-Chung Changeb68c462009-09-18 18:37:44 +08002159 ArrayList<Integer> formats = new ArrayList<Integer>();
2160 for (String s : split(str)) {
2161 int f = pixelFormatForCameraFormat(s);
Mathias Agopiana696f5d2010-02-17 17:53:09 -08002162 if (f == ImageFormat.UNKNOWN) continue;
Chih-Chung Changeb68c462009-09-18 18:37:44 +08002163 formats.add(f);
2164 }
2165 return formats;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002166 }
2167
2168 /**
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07002169 * <p>Sets the dimensions for pictures.</p>
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002170 *
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07002171 * <p>Applications need to consider the display orientation. See {@link
2172 * #setPreviewSize(int,int)} for reference.</p>
Wu-cheng Lic157e0c2010-10-07 18:36:07 +08002173 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002174 * @param width the width for pictures, in pixels
2175 * @param height the height for pictures, in pixels
Wu-cheng Lic157e0c2010-10-07 18:36:07 +08002176 * @see #setPreviewSize(int,int)
2177 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002178 */
2179 public void setPictureSize(int width, int height) {
2180 String v = Integer.toString(width) + "x" + Integer.toString(height);
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002181 set(KEY_PICTURE_SIZE, v);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002182 }
2183
2184 /**
2185 * Returns the dimension setting for pictures.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002186 *
2187 * @return a Size object with the height and width setting
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002188 * for pictures
2189 */
2190 public Size getPictureSize() {
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002191 String pair = get(KEY_PICTURE_SIZE);
2192 return strToSize(pair);
2193 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002194
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002195 /**
2196 * Gets the supported picture sizes.
2197 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08002198 * @return a list of supported picture sizes. This method will always
2199 * return a list with at least one element.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002200 */
2201 public List<Size> getSupportedPictureSizes() {
2202 String str = get(KEY_PICTURE_SIZE + SUPPORTED_VALUES_SUFFIX);
2203 return splitSize(str);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002204 }
2205
2206 /**
2207 * Sets the image format for pictures.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002208 *
2209 * @param pixel_format the desired picture format
Mathias Agopiana696f5d2010-02-17 17:53:09 -08002210 * (<var>ImageFormat.NV21</var>,
2211 * <var>ImageFormat.RGB_565</var>, or
2212 * <var>ImageFormat.JPEG</var>)
2213 * @see android.graphics.ImageFormat
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002214 */
2215 public void setPictureFormat(int pixel_format) {
2216 String s = cameraFormatForPixelFormat(pixel_format);
2217 if (s == null) {
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002218 throw new IllegalArgumentException(
2219 "Invalid pixel_format=" + pixel_format);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002220 }
2221
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002222 set(KEY_PICTURE_FORMAT, s);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002223 }
2224
2225 /**
2226 * Returns the image format for pictures.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002227 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08002228 * @return the picture format
2229 * @see android.graphics.ImageFormat
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002230 */
2231 public int getPictureFormat() {
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002232 return pixelFormatForCameraFormat(get(KEY_PICTURE_FORMAT));
2233 }
2234
2235 /**
2236 * Gets the supported picture formats.
2237 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08002238 * @return supported picture formats. This method will always return a
2239 * list with at least one element.
2240 * @see android.graphics.ImageFormat
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002241 */
2242 public List<Integer> getSupportedPictureFormats() {
Wu-cheng Li9c799382009-12-04 19:59:18 +08002243 String str = get(KEY_PICTURE_FORMAT + SUPPORTED_VALUES_SUFFIX);
2244 ArrayList<Integer> formats = new ArrayList<Integer>();
2245 for (String s : split(str)) {
2246 int f = pixelFormatForCameraFormat(s);
Mathias Agopiana696f5d2010-02-17 17:53:09 -08002247 if (f == ImageFormat.UNKNOWN) continue;
Wu-cheng Li9c799382009-12-04 19:59:18 +08002248 formats.add(f);
2249 }
2250 return formats;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002251 }
2252
2253 private String cameraFormatForPixelFormat(int pixel_format) {
2254 switch(pixel_format) {
Mathias Agopiana696f5d2010-02-17 17:53:09 -08002255 case ImageFormat.NV16: return PIXEL_FORMAT_YUV422SP;
2256 case ImageFormat.NV21: return PIXEL_FORMAT_YUV420SP;
2257 case ImageFormat.YUY2: return PIXEL_FORMAT_YUV422I;
Wu-cheng Li10a1b302011-02-22 15:49:25 +08002258 case ImageFormat.YV12: return PIXEL_FORMAT_YUV420P;
Mathias Agopiana696f5d2010-02-17 17:53:09 -08002259 case ImageFormat.RGB_565: return PIXEL_FORMAT_RGB565;
2260 case ImageFormat.JPEG: return PIXEL_FORMAT_JPEG;
2261 default: return null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002262 }
2263 }
2264
2265 private int pixelFormatForCameraFormat(String format) {
2266 if (format == null)
Mathias Agopiana696f5d2010-02-17 17:53:09 -08002267 return ImageFormat.UNKNOWN;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002268
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002269 if (format.equals(PIXEL_FORMAT_YUV422SP))
Mathias Agopiana696f5d2010-02-17 17:53:09 -08002270 return ImageFormat.NV16;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002271
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002272 if (format.equals(PIXEL_FORMAT_YUV420SP))
Mathias Agopiana696f5d2010-02-17 17:53:09 -08002273 return ImageFormat.NV21;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002274
Chih-Chung Changeb68c462009-09-18 18:37:44 +08002275 if (format.equals(PIXEL_FORMAT_YUV422I))
Mathias Agopiana696f5d2010-02-17 17:53:09 -08002276 return ImageFormat.YUY2;
Chih-Chung Changeb68c462009-09-18 18:37:44 +08002277
Wu-cheng Li10a1b302011-02-22 15:49:25 +08002278 if (format.equals(PIXEL_FORMAT_YUV420P))
2279 return ImageFormat.YV12;
2280
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002281 if (format.equals(PIXEL_FORMAT_RGB565))
Mathias Agopiana696f5d2010-02-17 17:53:09 -08002282 return ImageFormat.RGB_565;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002283
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002284 if (format.equals(PIXEL_FORMAT_JPEG))
Mathias Agopiana696f5d2010-02-17 17:53:09 -08002285 return ImageFormat.JPEG;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002286
Mathias Agopiana696f5d2010-02-17 17:53:09 -08002287 return ImageFormat.UNKNOWN;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002288 }
2289
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002290 /**
Wu-cheng Li2fb818c2010-09-13 20:02:01 -07002291 * Sets the rotation angle in degrees relative to the orientation of
2292 * the camera. This affects the pictures returned from JPEG {@link
2293 * PictureCallback}. The camera driver may set orientation in the
2294 * EXIF header without rotating the picture. Or the driver may rotate
2295 * the picture and the EXIF thumbnail. If the Jpeg picture is rotated,
2296 * the orientation in the EXIF header will be missing or 1 (row #0 is
2297 * top and column #0 is left side).
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002298 *
Brad Fitzpatrick69ea4e12011-01-05 11:13:40 -08002299 * <p>If applications want to rotate the picture to match the orientation
Wu-cheng Li2fe6fca2010-10-15 14:42:23 +08002300 * of what users see, apps should use {@link
Wu-cheng Li2fb818c2010-09-13 20:02:01 -07002301 * android.view.OrientationEventListener} and {@link CameraInfo}.
2302 * The value from OrientationEventListener is relative to the natural
Wu-cheng Li2fe6fca2010-10-15 14:42:23 +08002303 * orientation of the device. CameraInfo.orientation is the angle
Brad Fitzpatrick69ea4e12011-01-05 11:13:40 -08002304 * between camera orientation and natural device orientation. The sum
Wu-cheng Li2fe6fca2010-10-15 14:42:23 +08002305 * of the two is the rotation angle for back-facing camera. The
2306 * difference of the two is the rotation angle for front-facing camera.
2307 * Note that the JPEG pictures of front-facing cameras are not mirrored
2308 * as in preview display.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002309 *
Brad Fitzpatrick69ea4e12011-01-05 11:13:40 -08002310 * <p>For example, suppose the natural orientation of the device is
Wu-cheng Li2fb818c2010-09-13 20:02:01 -07002311 * portrait. The device is rotated 270 degrees clockwise, so the device
Wu-cheng Li2fe6fca2010-10-15 14:42:23 +08002312 * orientation is 270. Suppose a back-facing camera sensor is mounted in
2313 * landscape and the top side of the camera sensor is aligned with the
2314 * right edge of the display in natural orientation. So the camera
2315 * orientation is 90. The rotation should be set to 0 (270 + 90).
Wu-cheng Li2fb818c2010-09-13 20:02:01 -07002316 *
Brad Fitzpatrick69ea4e12011-01-05 11:13:40 -08002317 * <p>The reference code is as follows.
Wu-cheng Li2fb818c2010-09-13 20:02:01 -07002318 *
Brad Fitzpatrick69ea4e12011-01-05 11:13:40 -08002319 * <pre>
Wu-cheng Li2fb818c2010-09-13 20:02:01 -07002320 * public void public void onOrientationChanged(int orientation) {
2321 * if (orientation == ORIENTATION_UNKNOWN) return;
2322 * android.hardware.Camera.CameraInfo info =
2323 * new android.hardware.Camera.CameraInfo();
2324 * android.hardware.Camera.getCameraInfo(cameraId, info);
2325 * orientation = (orientation + 45) / 90 * 90;
Wu-cheng Li2fe6fca2010-10-15 14:42:23 +08002326 * int rotation = 0;
2327 * if (info.facing == CameraInfo.CAMERA_FACING_FRONT) {
2328 * rotation = (info.orientation - orientation + 360) % 360;
2329 * } else { // back-facing camera
2330 * rotation = (info.orientation + orientation) % 360;
2331 * }
2332 * mParameters.setRotation(rotation);
Wu-cheng Li2fb818c2010-09-13 20:02:01 -07002333 * }
Brad Fitzpatrick69ea4e12011-01-05 11:13:40 -08002334 * </pre>
Wu-cheng Li2fb818c2010-09-13 20:02:01 -07002335 *
2336 * @param rotation The rotation angle in degrees relative to the
2337 * orientation of the camera. Rotation can only be 0,
2338 * 90, 180 or 270.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002339 * @throws IllegalArgumentException if rotation value is invalid.
2340 * @see android.view.OrientationEventListener
Wu-cheng Li2fb818c2010-09-13 20:02:01 -07002341 * @see #getCameraInfo(int, CameraInfo)
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002342 */
2343 public void setRotation(int rotation) {
2344 if (rotation == 0 || rotation == 90 || rotation == 180
2345 || rotation == 270) {
2346 set(KEY_ROTATION, Integer.toString(rotation));
2347 } else {
2348 throw new IllegalArgumentException(
2349 "Invalid rotation=" + rotation);
2350 }
2351 }
2352
2353 /**
2354 * Sets GPS latitude coordinate. This will be stored in JPEG EXIF
2355 * header.
2356 *
2357 * @param latitude GPS latitude coordinate.
2358 */
2359 public void setGpsLatitude(double latitude) {
2360 set(KEY_GPS_LATITUDE, Double.toString(latitude));
2361 }
2362
2363 /**
2364 * Sets GPS longitude coordinate. This will be stored in JPEG EXIF
2365 * header.
2366 *
2367 * @param longitude GPS longitude coordinate.
2368 */
2369 public void setGpsLongitude(double longitude) {
2370 set(KEY_GPS_LONGITUDE, Double.toString(longitude));
2371 }
2372
2373 /**
2374 * Sets GPS altitude. This will be stored in JPEG EXIF header.
2375 *
2376 * @param altitude GPS altitude in meters.
2377 */
2378 public void setGpsAltitude(double altitude) {
2379 set(KEY_GPS_ALTITUDE, Double.toString(altitude));
2380 }
2381
2382 /**
2383 * Sets GPS timestamp. This will be stored in JPEG EXIF header.
2384 *
2385 * @param timestamp GPS timestamp (UTC in seconds since January 1,
2386 * 1970).
2387 */
2388 public void setGpsTimestamp(long timestamp) {
2389 set(KEY_GPS_TIMESTAMP, Long.toString(timestamp));
2390 }
2391
2392 /**
Ray Chene2083772010-03-10 15:02:49 -08002393 * Sets GPS processing method. It will store up to 32 characters
Ray Chen055c9862010-02-23 10:45:42 +08002394 * in JPEG EXIF header.
2395 *
2396 * @param processing_method The processing method to get this location.
2397 */
2398 public void setGpsProcessingMethod(String processing_method) {
2399 set(KEY_GPS_PROCESSING_METHOD, processing_method);
2400 }
2401
2402 /**
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002403 * Removes GPS latitude, longitude, altitude, and timestamp from the
2404 * parameters.
2405 */
2406 public void removeGpsData() {
2407 remove(KEY_GPS_LATITUDE);
2408 remove(KEY_GPS_LONGITUDE);
2409 remove(KEY_GPS_ALTITUDE);
2410 remove(KEY_GPS_TIMESTAMP);
Ray Chen055c9862010-02-23 10:45:42 +08002411 remove(KEY_GPS_PROCESSING_METHOD);
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002412 }
2413
2414 /**
2415 * Gets the current white balance setting.
2416 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08002417 * @return current white balance. null if white balance setting is not
2418 * supported.
2419 * @see #WHITE_BALANCE_AUTO
2420 * @see #WHITE_BALANCE_INCANDESCENT
2421 * @see #WHITE_BALANCE_FLUORESCENT
2422 * @see #WHITE_BALANCE_WARM_FLUORESCENT
2423 * @see #WHITE_BALANCE_DAYLIGHT
2424 * @see #WHITE_BALANCE_CLOUDY_DAYLIGHT
2425 * @see #WHITE_BALANCE_TWILIGHT
2426 * @see #WHITE_BALANCE_SHADE
2427 *
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002428 */
2429 public String getWhiteBalance() {
2430 return get(KEY_WHITE_BALANCE);
2431 }
2432
2433 /**
2434 * Sets the white balance.
2435 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08002436 * @param value new white balance.
2437 * @see #getWhiteBalance()
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002438 */
2439 public void setWhiteBalance(String value) {
2440 set(KEY_WHITE_BALANCE, value);
2441 }
2442
2443 /**
2444 * Gets the supported white balance.
2445 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08002446 * @return a list of supported white balance. null if white balance
2447 * setting is not supported.
2448 * @see #getWhiteBalance()
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002449 */
2450 public List<String> getSupportedWhiteBalance() {
2451 String str = get(KEY_WHITE_BALANCE + SUPPORTED_VALUES_SUFFIX);
2452 return split(str);
2453 }
2454
2455 /**
2456 * Gets the current color effect setting.
2457 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08002458 * @return current color effect. null if color effect
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002459 * setting is not supported.
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08002460 * @see #EFFECT_NONE
2461 * @see #EFFECT_MONO
2462 * @see #EFFECT_NEGATIVE
2463 * @see #EFFECT_SOLARIZE
2464 * @see #EFFECT_SEPIA
2465 * @see #EFFECT_POSTERIZE
2466 * @see #EFFECT_WHITEBOARD
2467 * @see #EFFECT_BLACKBOARD
2468 * @see #EFFECT_AQUA
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002469 */
2470 public String getColorEffect() {
2471 return get(KEY_EFFECT);
2472 }
2473
2474 /**
2475 * Sets the current color effect setting.
2476 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08002477 * @param value new color effect.
2478 * @see #getColorEffect()
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002479 */
2480 public void setColorEffect(String value) {
2481 set(KEY_EFFECT, value);
2482 }
2483
2484 /**
2485 * Gets the supported color effects.
2486 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08002487 * @return a list of supported color effects. null if color effect
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002488 * setting is not supported.
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08002489 * @see #getColorEffect()
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002490 */
2491 public List<String> getSupportedColorEffects() {
2492 String str = get(KEY_EFFECT + SUPPORTED_VALUES_SUFFIX);
2493 return split(str);
2494 }
2495
2496
2497 /**
2498 * Gets the current antibanding setting.
2499 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08002500 * @return current antibanding. null if antibanding setting is not
2501 * supported.
2502 * @see #ANTIBANDING_AUTO
2503 * @see #ANTIBANDING_50HZ
2504 * @see #ANTIBANDING_60HZ
2505 * @see #ANTIBANDING_OFF
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002506 */
2507 public String getAntibanding() {
2508 return get(KEY_ANTIBANDING);
2509 }
2510
2511 /**
2512 * Sets the antibanding.
2513 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08002514 * @param antibanding new antibanding value.
2515 * @see #getAntibanding()
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002516 */
2517 public void setAntibanding(String antibanding) {
2518 set(KEY_ANTIBANDING, antibanding);
2519 }
2520
2521 /**
2522 * Gets the supported antibanding values.
2523 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08002524 * @return a list of supported antibanding values. null if antibanding
2525 * setting is not supported.
2526 * @see #getAntibanding()
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002527 */
2528 public List<String> getSupportedAntibanding() {
2529 String str = get(KEY_ANTIBANDING + SUPPORTED_VALUES_SUFFIX);
2530 return split(str);
2531 }
2532
2533 /**
2534 * Gets the current scene mode setting.
2535 *
2536 * @return one of SCENE_MODE_XXX string constant. null if scene mode
2537 * setting is not supported.
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08002538 * @see #SCENE_MODE_AUTO
2539 * @see #SCENE_MODE_ACTION
2540 * @see #SCENE_MODE_PORTRAIT
2541 * @see #SCENE_MODE_LANDSCAPE
2542 * @see #SCENE_MODE_NIGHT
2543 * @see #SCENE_MODE_NIGHT_PORTRAIT
2544 * @see #SCENE_MODE_THEATRE
2545 * @see #SCENE_MODE_BEACH
2546 * @see #SCENE_MODE_SNOW
2547 * @see #SCENE_MODE_SUNSET
2548 * @see #SCENE_MODE_STEADYPHOTO
2549 * @see #SCENE_MODE_FIREWORKS
2550 * @see #SCENE_MODE_SPORTS
2551 * @see #SCENE_MODE_PARTY
2552 * @see #SCENE_MODE_CANDLELIGHT
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002553 */
2554 public String getSceneMode() {
2555 return get(KEY_SCENE_MODE);
2556 }
2557
2558 /**
Wu-cheng Lic58b4232010-03-29 17:21:28 +08002559 * Sets the scene mode. Changing scene mode may override other
2560 * parameters (such as flash mode, focus mode, white balance). For
2561 * example, suppose originally flash mode is on and supported flash
2562 * modes are on/off. In night scene mode, both flash mode and supported
2563 * flash mode may be changed to off. After setting scene mode,
Wu-cheng Li2988ab72009-09-30 17:08:19 -07002564 * applications should call getParameters to know if some parameters are
2565 * changed.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002566 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08002567 * @param value scene mode.
2568 * @see #getSceneMode()
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002569 */
2570 public void setSceneMode(String value) {
2571 set(KEY_SCENE_MODE, value);
2572 }
2573
2574 /**
2575 * Gets the supported scene modes.
2576 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08002577 * @return a list of supported scene modes. null if scene mode setting
2578 * is not supported.
2579 * @see #getSceneMode()
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002580 */
2581 public List<String> getSupportedSceneModes() {
2582 String str = get(KEY_SCENE_MODE + SUPPORTED_VALUES_SUFFIX);
2583 return split(str);
2584 }
2585
2586 /**
2587 * Gets the current flash mode setting.
2588 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08002589 * @return current flash mode. null if flash mode setting is not
2590 * supported.
2591 * @see #FLASH_MODE_OFF
2592 * @see #FLASH_MODE_AUTO
2593 * @see #FLASH_MODE_ON
2594 * @see #FLASH_MODE_RED_EYE
2595 * @see #FLASH_MODE_TORCH
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002596 */
2597 public String getFlashMode() {
2598 return get(KEY_FLASH_MODE);
2599 }
2600
2601 /**
2602 * Sets the flash mode.
2603 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08002604 * @param value flash mode.
2605 * @see #getFlashMode()
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002606 */
2607 public void setFlashMode(String value) {
2608 set(KEY_FLASH_MODE, value);
2609 }
2610
2611 /**
2612 * Gets the supported flash modes.
2613 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08002614 * @return a list of supported flash modes. null if flash mode setting
2615 * is not supported.
2616 * @see #getFlashMode()
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002617 */
2618 public List<String> getSupportedFlashModes() {
2619 String str = get(KEY_FLASH_MODE + SUPPORTED_VALUES_SUFFIX);
2620 return split(str);
2621 }
2622
Wu-cheng Li36322db2009-09-18 18:59:21 +08002623 /**
2624 * Gets the current focus mode setting.
2625 *
Wu-cheng Li699fe932010-08-05 11:50:25 -07002626 * @return current focus mode. This method will always return a non-null
2627 * value. Applications should call {@link
2628 * #autoFocus(AutoFocusCallback)} to start the focus if focus
2629 * mode is FOCUS_MODE_AUTO or FOCUS_MODE_MACRO.
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08002630 * @see #FOCUS_MODE_AUTO
2631 * @see #FOCUS_MODE_INFINITY
2632 * @see #FOCUS_MODE_MACRO
2633 * @see #FOCUS_MODE_FIXED
Wu-cheng Lif008f3e2010-08-17 13:44:35 -07002634 * @see #FOCUS_MODE_EDOF
Wu-cheng Lid45cb722010-09-20 16:15:32 -07002635 * @see #FOCUS_MODE_CONTINUOUS_VIDEO
Wu-cheng Li36322db2009-09-18 18:59:21 +08002636 */
2637 public String getFocusMode() {
2638 return get(KEY_FOCUS_MODE);
2639 }
2640
2641 /**
2642 * Sets the focus mode.
2643 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08002644 * @param value focus mode.
2645 * @see #getFocusMode()
Wu-cheng Li36322db2009-09-18 18:59:21 +08002646 */
2647 public void setFocusMode(String value) {
2648 set(KEY_FOCUS_MODE, value);
2649 }
2650
2651 /**
2652 * Gets the supported focus modes.
2653 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08002654 * @return a list of supported focus modes. This method will always
2655 * return a list with at least one element.
2656 * @see #getFocusMode()
Wu-cheng Li36322db2009-09-18 18:59:21 +08002657 */
2658 public List<String> getSupportedFocusModes() {
2659 String str = get(KEY_FOCUS_MODE + SUPPORTED_VALUES_SUFFIX);
2660 return split(str);
2661 }
2662
Wu-cheng Li36f68b82009-09-28 16:14:58 -07002663 /**
Wu-cheng Li6c8d2762010-01-27 22:55:14 +08002664 * Gets the focal length (in millimeter) of the camera.
2665 *
2666 * @return the focal length. This method will always return a valid
2667 * value.
2668 */
2669 public float getFocalLength() {
2670 return Float.parseFloat(get(KEY_FOCAL_LENGTH));
2671 }
2672
2673 /**
2674 * Gets the horizontal angle of view in degrees.
2675 *
2676 * @return horizontal angle of view. This method will always return a
2677 * valid value.
2678 */
2679 public float getHorizontalViewAngle() {
2680 return Float.parseFloat(get(KEY_HORIZONTAL_VIEW_ANGLE));
2681 }
2682
2683 /**
2684 * Gets the vertical angle of view in degrees.
2685 *
2686 * @return vertical angle of view. This method will always return a
2687 * valid value.
2688 */
2689 public float getVerticalViewAngle() {
2690 return Float.parseFloat(get(KEY_VERTICAL_VIEW_ANGLE));
2691 }
2692
2693 /**
Wu-cheng Li24b326a2010-02-20 17:47:04 +08002694 * Gets the current exposure compensation index.
Wu-cheng Liff723b62010-02-09 13:38:19 +08002695 *
Wu-cheng Li24b326a2010-02-20 17:47:04 +08002696 * @return current exposure compensation index. The range is {@link
2697 * #getMinExposureCompensation} to {@link
2698 * #getMaxExposureCompensation}. 0 means exposure is not
2699 * adjusted.
Wu-cheng Liff723b62010-02-09 13:38:19 +08002700 */
2701 public int getExposureCompensation() {
Wu-cheng Li24b326a2010-02-20 17:47:04 +08002702 return getInt(KEY_EXPOSURE_COMPENSATION, 0);
Wu-cheng Liff723b62010-02-09 13:38:19 +08002703 }
2704
2705 /**
Wu-cheng Li24b326a2010-02-20 17:47:04 +08002706 * Sets the exposure compensation index.
Wu-cheng Liff723b62010-02-09 13:38:19 +08002707 *
Wu-cheng Li0402e7d2010-02-26 15:04:55 +08002708 * @param value exposure compensation index. The valid value range is
2709 * from {@link #getMinExposureCompensation} (inclusive) to {@link
Wu-cheng Li24b326a2010-02-20 17:47:04 +08002710 * #getMaxExposureCompensation} (inclusive). 0 means exposure is
2711 * not adjusted. Application should call
2712 * getMinExposureCompensation and getMaxExposureCompensation to
2713 * know if exposure compensation is supported.
Wu-cheng Liff723b62010-02-09 13:38:19 +08002714 */
2715 public void setExposureCompensation(int value) {
2716 set(KEY_EXPOSURE_COMPENSATION, value);
2717 }
2718
2719 /**
Wu-cheng Li24b326a2010-02-20 17:47:04 +08002720 * Gets the maximum exposure compensation index.
Wu-cheng Liff723b62010-02-09 13:38:19 +08002721 *
Wu-cheng Li24b326a2010-02-20 17:47:04 +08002722 * @return maximum exposure compensation index (>=0). If both this
2723 * method and {@link #getMinExposureCompensation} return 0,
2724 * exposure compensation is not supported.
Wu-cheng Liff723b62010-02-09 13:38:19 +08002725 */
Wu-cheng Li24b326a2010-02-20 17:47:04 +08002726 public int getMaxExposureCompensation() {
2727 return getInt(KEY_MAX_EXPOSURE_COMPENSATION, 0);
2728 }
2729
2730 /**
2731 * Gets the minimum exposure compensation index.
2732 *
2733 * @return minimum exposure compensation index (<=0). If both this
2734 * method and {@link #getMaxExposureCompensation} return 0,
2735 * exposure compensation is not supported.
2736 */
2737 public int getMinExposureCompensation() {
2738 return getInt(KEY_MIN_EXPOSURE_COMPENSATION, 0);
2739 }
2740
2741 /**
2742 * Gets the exposure compensation step.
2743 *
2744 * @return exposure compensation step. Applications can get EV by
2745 * multiplying the exposure compensation index and step. Ex: if
2746 * exposure compensation index is -6 and step is 0.333333333, EV
2747 * is -2.
2748 */
2749 public float getExposureCompensationStep() {
2750 return getFloat(KEY_EXPOSURE_COMPENSATION_STEP, 0);
Wu-cheng Liff723b62010-02-09 13:38:19 +08002751 }
2752
2753 /**
Eino-Ville Talvalad9c2601a2011-05-13 10:19:59 -07002754 * <p>Sets the auto-exposure lock state. Applications should check
2755 * {@link #isAutoExposureLockSupported} before using this method.</p>
Eino-Ville Talvala3773eef2011-04-15 13:51:42 -07002756 *
Eino-Ville Talvalad9c2601a2011-05-13 10:19:59 -07002757 * <p>If set to true, the camera auto-exposure routine will immediately
2758 * pause until the lock is set to false. Exposure compensation settings
2759 * changes will still take effect while auto-exposure is locked.</p>
2760 *
2761 * <p>If auto-exposure is already locked, setting this to true again has
2762 * no effect (the driver will not recalculate exposure values).</p>
2763 *
2764 * <p>Stopping preview with {@link #stopPreview()}, or triggering still
2765 * image capture with {@link #takePicture(Camera.ShutterCallback,
2766 * Camera.PictureCallback, Camera.PictureCallback)}, will automatically
2767 * set the lock to false. However, the lock can be re-enabled before
2768 * preview is re-started to keep the same AE parameters.</p>
2769 *
2770 * <p>Exposure compensation, in conjunction with re-enabling the AE and
2771 * AWB locks after each still capture, can be used to capture an
2772 * exposure-bracketed burst of images, for example.</p>
2773 *
2774 * <p>Auto-exposure state, including the lock state, will not be
Eino-Ville Talvala3773eef2011-04-15 13:51:42 -07002775 * maintained after camera {@link #release()} is called. Locking
2776 * auto-exposure after {@link #open()} but before the first call to
2777 * {@link #startPreview()} will not allow the auto-exposure routine to
Eino-Ville Talvalad9c2601a2011-05-13 10:19:59 -07002778 * run at all, and may result in severely over- or under-exposed
2779 * images.</p>
Eino-Ville Talvala3773eef2011-04-15 13:51:42 -07002780 *
Eino-Ville Talvalad9c2601a2011-05-13 10:19:59 -07002781 * <p>The driver may also independently lock auto-exposure after
2782 * auto-focus completes. If this is undesirable, be sure to always set
2783 * the auto-exposure lock to false after the
Eino-Ville Talvala3773eef2011-04-15 13:51:42 -07002784 * {@link AutoFocusCallback#onAutoFocus(boolean, Camera)} callback is
2785 * received. The {@link #getAutoExposureLock()} method can be used after
2786 * the callback to determine if the camera has locked auto-exposure
Eino-Ville Talvalad9c2601a2011-05-13 10:19:59 -07002787 * independently.</p>
Eino-Ville Talvala3773eef2011-04-15 13:51:42 -07002788 *
2789 * @param toggle new state of the auto-exposure lock. True means that
2790 * auto-exposure is locked, false means that the auto-exposure
2791 * routine is free to run normally.
2792 *
Eino-Ville Talvalad9c2601a2011-05-13 10:19:59 -07002793 * @see #getAutoExposureLock()
Eino-Ville Talvala3773eef2011-04-15 13:51:42 -07002794 */
2795 public void setAutoExposureLock(boolean toggle) {
2796 set(KEY_AUTO_EXPOSURE_LOCK, toggle ? TRUE : FALSE);
2797 }
2798
2799 /**
2800 * Gets the state of the auto-exposure lock. Applications should check
2801 * {@link #isAutoExposureLockSupported} before using this method. See
2802 * {@link #setAutoExposureLock} for details about the lock.
2803 *
2804 * @return State of the auto-exposure lock. Returns true if
2805 * auto-exposure is currently locked, and false otherwise. The
2806 * auto-exposure lock may be independently enabled by the camera
2807 * subsystem when auto-focus has completed. This method can be
2808 * used after the {@link AutoFocusCallback#onAutoFocus(boolean,
2809 * Camera)} callback to determine if the camera has locked AE.
2810 *
2811 * @see #setAutoExposureLock(boolean)
2812 *
Eino-Ville Talvala3773eef2011-04-15 13:51:42 -07002813 */
2814 public boolean getAutoExposureLock() {
2815 String str = get(KEY_AUTO_EXPOSURE_LOCK);
2816 return TRUE.equals(str);
2817 }
2818
2819 /**
2820 * Returns true if auto-exposure locking is supported. Applications
2821 * should call this before trying to lock auto-exposure. See
2822 * {@link #setAutoExposureLock} for details about the lock.
2823 *
2824 * @return true if auto-exposure lock is supported.
2825 * @see #setAutoExposureLock(boolean)
2826 *
Eino-Ville Talvala3773eef2011-04-15 13:51:42 -07002827 */
2828 public boolean isAutoExposureLockSupported() {
2829 String str = get(KEY_AUTO_EXPOSURE_LOCK_SUPPORTED);
2830 return TRUE.equals(str);
2831 }
2832
2833 /**
Eino-Ville Talvalad9c2601a2011-05-13 10:19:59 -07002834 * <p>Sets the auto-white balance lock state. Applications should check
2835 * {@link #isAutoWhiteBalanceLockSupported} before using this
2836 * method.</p>
2837 *
2838 * <p>If set to true, the camera auto-white balance routine will
2839 * immediately pause until the lock is set to false.</p>
2840 *
2841 * <p>If auto-white balance is already locked, setting this to true
2842 * again has no effect (the driver will not recalculate white balance
2843 * values).</p>
2844 *
2845 * <p>Stopping preview with {@link #stopPreview()}, or triggering still
2846 * image capture with {@link #takePicture(Camera.ShutterCallback,
2847 * Camera.PictureCallback, Camera.PictureCallback)}, will automatically
2848 * set the lock to false. However, the lock can be re-enabled before
2849 * preview is re-started to keep the same white balance parameters.</p>
2850 *
2851 * <p>Exposure compensation, in conjunction with re-enabling the AE and
2852 * AWB locks after each still capture, can be used to capture an
2853 * exposure-bracketed burst of images, for example. Auto-white balance
2854 * state, including the lock state, will not be maintained after camera
2855 * {@link #release()} is called. Locking auto-white balance after
2856 * {@link #open()} but before the first call to {@link #startPreview()}
2857 * will not allow the auto-white balance routine to run at all, and may
2858 * result in severely incorrect color in captured images.</p>
2859 *
2860 * <p>The driver may also independently lock auto-white balance after
2861 * auto-focus completes. If this is undesirable, be sure to always set
2862 * the auto-white balance lock to false after the
2863 * {@link AutoFocusCallback#onAutoFocus(boolean, Camera)} callback is
2864 * received. The {@link #getAutoWhiteBalanceLock()} method can be used
2865 * after the callback to determine if the camera has locked auto-white
2866 * balance independently.</p>
2867 *
2868 * @param toggle new state of the auto-white balance lock. True means
2869 * that auto-white balance is locked, false means that the
2870 * auto-white balance routine is free to run normally.
2871 *
2872 * @see #getAutoWhiteBalanceLock()
Eino-Ville Talvalad9c2601a2011-05-13 10:19:59 -07002873 */
2874 public void setAutoWhiteBalanceLock(boolean toggle) {
2875 set(KEY_AUTO_WHITEBALANCE_LOCK, toggle ? TRUE : FALSE);
2876 }
2877
2878 /**
2879 * Gets the state of the auto-white balance lock. Applications should
2880 * check {@link #isAutoWhiteBalanceLockSupported} before using this
2881 * method. See {@link #setAutoWhiteBalanceLock} for details about the
2882 * lock.
2883 *
2884 * @return State of the auto-white balance lock. Returns true if
2885 * auto-white balance is currently locked, and false
2886 * otherwise. The auto-white balance lock may be independently
2887 * enabled by the camera subsystem when auto-focus has
2888 * completed. This method can be used after the
2889 * {@link AutoFocusCallback#onAutoFocus(boolean, Camera)}
2890 * callback to determine if the camera has locked AWB.
2891 *
2892 * @see #setAutoWhiteBalanceLock(boolean)
2893 *
Eino-Ville Talvalad9c2601a2011-05-13 10:19:59 -07002894 */
2895 public boolean getAutoWhiteBalanceLock() {
2896 String str = get(KEY_AUTO_WHITEBALANCE_LOCK);
2897 return TRUE.equals(str);
2898 }
2899
2900 /**
2901 * Returns true if auto-white balance locking is supported. Applications
2902 * should call this before trying to lock auto-white balance. See
2903 * {@link #setAutoWhiteBalanceLock} for details about the lock.
2904 *
2905 * @return true if auto-white balance lock is supported.
2906 * @see #setAutoWhiteBalanceLock(boolean)
2907 *
Eino-Ville Talvalad9c2601a2011-05-13 10:19:59 -07002908 */
2909 public boolean isAutoWhiteBalanceLockSupported() {
2910 String str = get(KEY_AUTO_WHITEBALANCE_LOCK_SUPPORTED);
2911 return TRUE.equals(str);
2912 }
2913
2914 /**
Wu-cheng Li36f68b82009-09-28 16:14:58 -07002915 * Gets current zoom value. This also works when smooth zoom is in
Wu-cheng Li8cbb8f52010-02-28 23:19:55 -08002916 * progress. Applications should check {@link #isZoomSupported} before
2917 * using this method.
Wu-cheng Li36f68b82009-09-28 16:14:58 -07002918 *
2919 * @return the current zoom value. The range is 0 to {@link
Wu-cheng Li8cbb8f52010-02-28 23:19:55 -08002920 * #getMaxZoom}. 0 means the camera is not zoomed.
Wu-cheng Li36f68b82009-09-28 16:14:58 -07002921 */
2922 public int getZoom() {
Wu-cheng Li8cbb8f52010-02-28 23:19:55 -08002923 return getInt(KEY_ZOOM, 0);
Wu-cheng Li36f68b82009-09-28 16:14:58 -07002924 }
2925
2926 /**
Wu-cheng Li8cbb8f52010-02-28 23:19:55 -08002927 * Sets current zoom value. If the camera is zoomed (value > 0), the
2928 * actual picture size may be smaller than picture size setting.
2929 * Applications can check the actual picture size after picture is
2930 * returned from {@link PictureCallback}. The preview size remains the
2931 * same in zoom. Applications should check {@link #isZoomSupported}
2932 * before using this method.
Wu-cheng Li36f68b82009-09-28 16:14:58 -07002933 *
2934 * @param value zoom value. The valid range is 0 to {@link #getMaxZoom}.
Wu-cheng Li36f68b82009-09-28 16:14:58 -07002935 */
2936 public void setZoom(int value) {
Wu-cheng Li8cbb8f52010-02-28 23:19:55 -08002937 set(KEY_ZOOM, value);
Wu-cheng Li36f68b82009-09-28 16:14:58 -07002938 }
2939
2940 /**
2941 * Returns true if zoom is supported. Applications should call this
2942 * before using other zoom methods.
2943 *
2944 * @return true if zoom is supported.
Wu-cheng Li36f68b82009-09-28 16:14:58 -07002945 */
2946 public boolean isZoomSupported() {
Wu-cheng Li8cbb8f52010-02-28 23:19:55 -08002947 String str = get(KEY_ZOOM_SUPPORTED);
2948 return TRUE.equals(str);
Wu-cheng Li36f68b82009-09-28 16:14:58 -07002949 }
2950
2951 /**
2952 * Gets the maximum zoom value allowed for snapshot. This is the maximum
2953 * value that applications can set to {@link #setZoom(int)}.
Wu-cheng Li8cbb8f52010-02-28 23:19:55 -08002954 * Applications should call {@link #isZoomSupported} before using this
2955 * method. This value may change in different preview size. Applications
2956 * should call this again after setting preview size.
Wu-cheng Li36f68b82009-09-28 16:14:58 -07002957 *
2958 * @return the maximum zoom value supported by the camera.
Wu-cheng Li36f68b82009-09-28 16:14:58 -07002959 */
2960 public int getMaxZoom() {
Wu-cheng Li8cbb8f52010-02-28 23:19:55 -08002961 return getInt(KEY_MAX_ZOOM, 0);
Wu-cheng Li36f68b82009-09-28 16:14:58 -07002962 }
2963
2964 /**
Wu-cheng Li8cbb8f52010-02-28 23:19:55 -08002965 * Gets the zoom ratios of all zoom values. Applications should check
2966 * {@link #isZoomSupported} before using this method.
Wu-cheng Li36f68b82009-09-28 16:14:58 -07002967 *
Wu-cheng Li8cbb8f52010-02-28 23:19:55 -08002968 * @return the zoom ratios in 1/100 increments. Ex: a zoom of 3.2x is
2969 * returned as 320. The number of elements is {@link
2970 * #getMaxZoom} + 1. The list is sorted from small to large. The
2971 * first element is always 100. The last element is the zoom
2972 * ratio of the maximum zoom value.
Wu-cheng Li36f68b82009-09-28 16:14:58 -07002973 */
Wu-cheng Li8cbb8f52010-02-28 23:19:55 -08002974 public List<Integer> getZoomRatios() {
2975 return splitInt(get(KEY_ZOOM_RATIOS));
Wu-cheng Li36f68b82009-09-28 16:14:58 -07002976 }
2977
2978 /**
2979 * Returns true if smooth zoom is supported. Applications should call
2980 * this before using other smooth zoom methods.
2981 *
2982 * @return true if smooth zoom is supported.
Wu-cheng Li36f68b82009-09-28 16:14:58 -07002983 */
2984 public boolean isSmoothZoomSupported() {
Wu-cheng Li8cbb8f52010-02-28 23:19:55 -08002985 String str = get(KEY_SMOOTH_ZOOM_SUPPORTED);
2986 return TRUE.equals(str);
Wu-cheng Li36f68b82009-09-28 16:14:58 -07002987 }
2988
Wu-cheng Lie339c5e2010-05-13 19:31:02 +08002989 /**
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07002990 * <p>Gets the distances from the camera to where an object appears to be
Wu-cheng Lie339c5e2010-05-13 19:31:02 +08002991 * in focus. The object is sharpest at the optimal focus distance. The
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07002992 * depth of field is the far focus distance minus near focus distance.</p>
Wu-cheng Lie339c5e2010-05-13 19:31:02 +08002993 *
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07002994 * <p>Focus distances may change after calling {@link
Wu-cheng Lie339c5e2010-05-13 19:31:02 +08002995 * #autoFocus(AutoFocusCallback)}, {@link #cancelAutoFocus}, or {@link
2996 * #startPreview()}. Applications can call {@link #getParameters()}
2997 * and this method anytime to get the latest focus distances. If the
Wu-cheng Lid45cb722010-09-20 16:15:32 -07002998 * focus mode is FOCUS_MODE_CONTINUOUS_VIDEO, focus distances may change
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07002999 * from time to time.</p>
Wu-cheng Li699fe932010-08-05 11:50:25 -07003000 *
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07003001 * <p>This method is intended to estimate the distance between the camera
Wu-cheng Li699fe932010-08-05 11:50:25 -07003002 * and the subject. After autofocus, the subject distance may be within
3003 * near and far focus distance. However, the precision depends on the
3004 * camera hardware, autofocus algorithm, the focus area, and the scene.
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07003005 * The error can be large and it should be only used as a reference.</p>
Wu-cheng Lie339c5e2010-05-13 19:31:02 +08003006 *
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07003007 * <p>Far focus distance >= optimal focus distance >= near focus distance.
Wu-cheng Li185cc452010-05-20 15:36:13 +08003008 * If the focus distance is infinity, the value will be
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07003009 * {@code Float.POSITIVE_INFINITY}.</p>
Wu-cheng Lie339c5e2010-05-13 19:31:02 +08003010 *
3011 * @param output focus distances in meters. output must be a float
3012 * array with three elements. Near focus distance, optimal focus
3013 * distance, and far focus distance will be filled in the array.
Wu-cheng Li185cc452010-05-20 15:36:13 +08003014 * @see #FOCUS_DISTANCE_NEAR_INDEX
3015 * @see #FOCUS_DISTANCE_OPTIMAL_INDEX
3016 * @see #FOCUS_DISTANCE_FAR_INDEX
Wu-cheng Lie339c5e2010-05-13 19:31:02 +08003017 */
3018 public void getFocusDistances(float[] output) {
3019 if (output == null || output.length != 3) {
3020 throw new IllegalArgumentException(
3021 "output must be an float array with three elements.");
3022 }
Wu-cheng Li454630f2010-08-11 16:48:05 -07003023 splitFloat(get(KEY_FOCUS_DISTANCES), output);
Wu-cheng Lie339c5e2010-05-13 19:31:02 +08003024 }
3025
Wu-cheng Li30771b72011-04-02 06:19:46 +08003026 /**
3027 * Gets the maximum number of focus areas supported. This is the maximum
Wu-cheng Li7b1c5c82011-04-15 19:16:52 +08003028 * length of the list in {@link #setFocusAreas(List)} and
3029 * {@link #getFocusAreas()}.
Wu-cheng Li30771b72011-04-02 06:19:46 +08003030 *
3031 * @return the maximum number of focus areas supported by the camera.
3032 * @see #getFocusAreas()
Wu-cheng Li30771b72011-04-02 06:19:46 +08003033 */
3034 public int getMaxNumFocusAreas() {
3035 return getInt(KEY_MAX_NUM_FOCUS_AREAS, 0);
3036 }
3037
3038 /**
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07003039 * <p>Gets the current focus areas. Camera driver uses the areas to decide
3040 * focus.</p>
Wu-cheng Li30771b72011-04-02 06:19:46 +08003041 *
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07003042 * <p>Before using this API or {@link #setFocusAreas(List)}, apps should
Wu-cheng Li7b1c5c82011-04-15 19:16:52 +08003043 * call {@link #getMaxNumFocusAreas()} to know the maximum number of
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07003044 * focus areas first. If the value is 0, focus area is not supported.</p>
Wu-cheng Li30771b72011-04-02 06:19:46 +08003045 *
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07003046 * <p>Each focus area is a rectangle with specified weight. The direction
Wu-cheng Li30771b72011-04-02 06:19:46 +08003047 * is relative to the sensor orientation, that is, what the sensor sees.
3048 * The direction is not affected by the rotation or mirroring of
3049 * {@link #setDisplayOrientation(int)}. Coordinates of the rectangle
3050 * range from -1000 to 1000. (-1000, -1000) is the upper left point.
Wu-cheng Libde61a52011-06-07 18:23:14 +08003051 * (1000, 1000) is the lower right point. The width and height of focus
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07003052 * areas cannot be 0 or negative.</p>
Wu-cheng Li30771b72011-04-02 06:19:46 +08003053 *
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07003054 * <p>The weight must range from 1 to 1000. The weight should be
Eino-Ville Talvala4e396e02011-04-21 09:23:15 -07003055 * interpreted as a per-pixel weight - all pixels in the area have the
3056 * specified weight. This means a small area with the same weight as a
3057 * larger area will have less influence on the focusing than the larger
3058 * area. Focus areas can partially overlap and the driver will add the
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07003059 * weights in the overlap region.</p>
Wu-cheng Li30771b72011-04-02 06:19:46 +08003060 *
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07003061 * <p>A special case of a {@code null} focus area list means the driver is
3062 * free to select focus targets as it wants. For example, the driver may
3063 * use more signals to select focus areas and change them
3064 * dynamically. Apps can set the focus area list to {@code null} if they
3065 * want the driver to completely control focusing.</p>
Wu-cheng Li30771b72011-04-02 06:19:46 +08003066 *
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07003067 * <p>Focus areas are relative to the current field of view
Wu-cheng Li30771b72011-04-02 06:19:46 +08003068 * ({@link #getZoom()}). No matter what the zoom level is, (-1000,-1000)
3069 * represents the top of the currently visible camera frame. The focus
3070 * area cannot be set to be outside the current field of view, even
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07003071 * when using zoom.</p>
Wu-cheng Li30771b72011-04-02 06:19:46 +08003072 *
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07003073 * <p>Focus area only has effect if the current focus mode is
Wu-cheng Li30771b72011-04-02 06:19:46 +08003074 * {@link #FOCUS_MODE_AUTO}, {@link #FOCUS_MODE_MACRO}, or
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07003075 * {@link #FOCUS_MODE_CONTINUOUS_VIDEO}.</p>
Wu-cheng Li30771b72011-04-02 06:19:46 +08003076 *
3077 * @return a list of current focus areas
Wu-cheng Li30771b72011-04-02 06:19:46 +08003078 */
3079 public List<Area> getFocusAreas() {
Wu-cheng Lif715bf92011-04-14 14:04:18 +08003080 return splitArea(get(KEY_FOCUS_AREAS));
Wu-cheng Li30771b72011-04-02 06:19:46 +08003081 }
3082
3083 /**
3084 * Sets focus areas. See {@link #getFocusAreas()} for documentation.
3085 *
Wu-cheng Li7b1c5c82011-04-15 19:16:52 +08003086 * @param focusAreas the focus areas
Wu-cheng Li30771b72011-04-02 06:19:46 +08003087 * @see #getFocusAreas()
Wu-cheng Li30771b72011-04-02 06:19:46 +08003088 */
Wu-cheng Lie98e4c82011-04-12 19:34:29 +08003089 public void setFocusAreas(List<Area> focusAreas) {
3090 set(KEY_FOCUS_AREAS, focusAreas);
3091 }
3092
3093 /**
3094 * Gets the maximum number of metering areas supported. This is the
Wu-cheng Li7b1c5c82011-04-15 19:16:52 +08003095 * maximum length of the list in {@link #setMeteringAreas(List)} and
3096 * {@link #getMeteringAreas()}.
Wu-cheng Lie98e4c82011-04-12 19:34:29 +08003097 *
3098 * @return the maximum number of metering areas supported by the camera.
3099 * @see #getMeteringAreas()
Wu-cheng Lie98e4c82011-04-12 19:34:29 +08003100 */
3101 public int getMaxNumMeteringAreas() {
3102 return getInt(KEY_MAX_NUM_METERING_AREAS, 0);
3103 }
3104
3105 /**
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07003106 * <p>Gets the current metering areas. Camera driver uses these areas to
3107 * decide exposure.</p>
Wu-cheng Lie98e4c82011-04-12 19:34:29 +08003108 *
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07003109 * <p>Before using this API or {@link #setMeteringAreas(List)}, apps should
Wu-cheng Li7b1c5c82011-04-15 19:16:52 +08003110 * call {@link #getMaxNumMeteringAreas()} to know the maximum number of
3111 * metering areas first. If the value is 0, metering area is not
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07003112 * supported.</p>
Wu-cheng Lie98e4c82011-04-12 19:34:29 +08003113 *
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07003114 * <p>Each metering area is a rectangle with specified weight. The
Wu-cheng Lie98e4c82011-04-12 19:34:29 +08003115 * direction is relative to the sensor orientation, that is, what the
3116 * sensor sees. The direction is not affected by the rotation or
3117 * mirroring of {@link #setDisplayOrientation(int)}. Coordinates of the
3118 * rectangle range from -1000 to 1000. (-1000, -1000) is the upper left
Wu-cheng Libde61a52011-06-07 18:23:14 +08003119 * point. (1000, 1000) is the lower right point. The width and height of
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07003120 * metering areas cannot be 0 or negative.</p>
Wu-cheng Lie98e4c82011-04-12 19:34:29 +08003121 *
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07003122 * <p>The weight must range from 1 to 1000, and represents a weight for
Eino-Ville Talvala4e396e02011-04-21 09:23:15 -07003123 * every pixel in the area. This means that a large metering area with
3124 * the same weight as a smaller area will have more effect in the
3125 * metering result. Metering areas can partially overlap and the driver
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07003126 * will add the weights in the overlap region.</p>
Wu-cheng Lie98e4c82011-04-12 19:34:29 +08003127 *
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07003128 * <p>A special case of a {@code null} metering area list means the driver
3129 * is free to meter as it chooses. For example, the driver may use more
3130 * signals to select metering areas and change them dynamically. Apps
3131 * can set the metering area list to {@code null} if they want the
3132 * driver to completely control metering.</p>
Wu-cheng Lie98e4c82011-04-12 19:34:29 +08003133 *
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07003134 * <p>Metering areas are relative to the current field of view
Wu-cheng Lie98e4c82011-04-12 19:34:29 +08003135 * ({@link #getZoom()}). No matter what the zoom level is, (-1000,-1000)
3136 * represents the top of the currently visible camera frame. The
3137 * metering area cannot be set to be outside the current field of view,
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07003138 * even when using zoom.</p>
Wu-cheng Lie98e4c82011-04-12 19:34:29 +08003139 *
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07003140 * <p>No matter what metering areas are, the final exposure are compensated
3141 * by {@link #setExposureCompensation(int)}.</p>
Wu-cheng Lie98e4c82011-04-12 19:34:29 +08003142 *
3143 * @return a list of current metering areas
Wu-cheng Lie98e4c82011-04-12 19:34:29 +08003144 */
3145 public List<Area> getMeteringAreas() {
Wu-cheng Lid8aab932011-06-21 11:50:43 +08003146 return splitArea(get(KEY_METERING_AREAS));
Wu-cheng Lie98e4c82011-04-12 19:34:29 +08003147 }
3148
3149 /**
3150 * Sets metering areas. See {@link #getMeteringAreas()} for
3151 * documentation.
3152 *
Wu-cheng Li7b1c5c82011-04-15 19:16:52 +08003153 * @param meteringAreas the metering areas
Wu-cheng Lie98e4c82011-04-12 19:34:29 +08003154 * @see #getMeteringAreas()
Wu-cheng Lie98e4c82011-04-12 19:34:29 +08003155 */
3156 public void setMeteringAreas(List<Area> meteringAreas) {
3157 set(KEY_METERING_AREAS, meteringAreas);
Wu-cheng Li30771b72011-04-02 06:19:46 +08003158 }
3159
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08003160 /**
3161 * Gets the maximum number of detected faces supported. This is the
3162 * maximum length of the list returned from {@link FaceDetectionListener}.
3163 * If the return value is 0, face detection of the specified type is not
3164 * supported.
3165 *
3166 * @return the maximum number of detected face supported by the camera.
3167 * @see #startFaceDetection(int)
3168 * @hide
3169 */
3170 public int getMaxNumDetectedFaces(int type) {
3171 if (type == CAMERA_FACE_DETECTION_HW) {
3172 return getInt(KEY_MAX_NUM_DETECTED_FACES_HW, 0);
3173 } else if (type == CAMERA_FACE_DETECTION_SW){
3174 return getInt(KEY_MAX_NUM_DETECTED_FACES_SW, 0);
3175 }
3176 throw new IllegalArgumentException("Invalid face detection type " + type);
3177 }
3178
Wu-cheng Li25d8fb52011-08-02 13:20:36 +08003179 /**
Wu-cheng Li9c53f1c2011-08-02 17:26:58 +08003180 * Sets recording mode hint. This tells the camera that the intent of
3181 * the application is to record videos {@link
3182 * android.media.MediaRecorder#start()}, not to take still pictures
3183 * {@link #takePicture(Camera.ShutterCallback, Camera.PictureCallback,
3184 * Camera.PictureCallback, Camera.PictureCallback)}. Using this hint can
3185 * allow MediaRecorder.start() to start faster or with fewer glitches on
3186 * output. This should be called before starting preview for the best
3187 * result, but can be changed while the preview is active. The default
3188 * value is false.
Wu-cheng Li25d8fb52011-08-02 13:20:36 +08003189 *
Wu-cheng Li9c53f1c2011-08-02 17:26:58 +08003190 * The app can still call takePicture() when the hint is true or call
3191 * MediaRecorder.start() when the hint is false. But the performance may
3192 * be worse.
Wu-cheng Li25d8fb52011-08-02 13:20:36 +08003193 *
Wu-cheng Li9c53f1c2011-08-02 17:26:58 +08003194 * @param hint true if the apps intend to record videos using
Wu-cheng Li25d8fb52011-08-02 13:20:36 +08003195 * {@link android.media.MediaRecorder}.
Wu-cheng Li25d8fb52011-08-02 13:20:36 +08003196 */
3197 public void setRecordingHint(boolean hint) {
3198 set(KEY_RECORDING_HINT, hint ? TRUE : FALSE);
3199 }
3200
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003201 // Splits a comma delimited string to an ArrayList of String.
3202 // Return null if the passing string is null or the size is 0.
3203 private ArrayList<String> split(String str) {
3204 if (str == null) return null;
3205
3206 // Use StringTokenizer because it is faster than split.
3207 StringTokenizer tokenizer = new StringTokenizer(str, ",");
3208 ArrayList<String> substrings = new ArrayList<String>();
3209 while (tokenizer.hasMoreElements()) {
3210 substrings.add(tokenizer.nextToken());
3211 }
3212 return substrings;
3213 }
3214
3215 // Splits a comma delimited string to an ArrayList of Integer.
3216 // Return null if the passing string is null or the size is 0.
3217 private ArrayList<Integer> splitInt(String str) {
3218 if (str == null) return null;
3219
3220 StringTokenizer tokenizer = new StringTokenizer(str, ",");
3221 ArrayList<Integer> substrings = new ArrayList<Integer>();
3222 while (tokenizer.hasMoreElements()) {
3223 String token = tokenizer.nextToken();
3224 substrings.add(Integer.parseInt(token));
3225 }
3226 if (substrings.size() == 0) return null;
3227 return substrings;
3228 }
3229
Wu-cheng Li454630f2010-08-11 16:48:05 -07003230 private void splitInt(String str, int[] output) {
3231 if (str == null) return;
Wu-cheng Lie339c5e2010-05-13 19:31:02 +08003232
3233 StringTokenizer tokenizer = new StringTokenizer(str, ",");
Wu-cheng Li454630f2010-08-11 16:48:05 -07003234 int index = 0;
Wu-cheng Lie339c5e2010-05-13 19:31:02 +08003235 while (tokenizer.hasMoreElements()) {
3236 String token = tokenizer.nextToken();
Wu-cheng Li454630f2010-08-11 16:48:05 -07003237 output[index++] = Integer.parseInt(token);
Wu-cheng Lie339c5e2010-05-13 19:31:02 +08003238 }
Wu-cheng Li454630f2010-08-11 16:48:05 -07003239 }
3240
3241 // Splits a comma delimited string to an ArrayList of Float.
3242 private void splitFloat(String str, float[] output) {
3243 if (str == null) return;
3244
3245 StringTokenizer tokenizer = new StringTokenizer(str, ",");
3246 int index = 0;
3247 while (tokenizer.hasMoreElements()) {
3248 String token = tokenizer.nextToken();
3249 output[index++] = Float.parseFloat(token);
3250 }
Wu-cheng Lie339c5e2010-05-13 19:31:02 +08003251 }
3252
Wu-cheng Li24b326a2010-02-20 17:47:04 +08003253 // Returns the value of a float parameter.
3254 private float getFloat(String key, float defaultValue) {
3255 try {
3256 return Float.parseFloat(mMap.get(key));
3257 } catch (NumberFormatException ex) {
3258 return defaultValue;
3259 }
3260 }
3261
3262 // Returns the value of a integer parameter.
3263 private int getInt(String key, int defaultValue) {
3264 try {
3265 return Integer.parseInt(mMap.get(key));
3266 } catch (NumberFormatException ex) {
3267 return defaultValue;
3268 }
3269 }
3270
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003271 // Splits a comma delimited string to an ArrayList of Size.
3272 // Return null if the passing string is null or the size is 0.
3273 private ArrayList<Size> splitSize(String str) {
3274 if (str == null) return null;
3275
3276 StringTokenizer tokenizer = new StringTokenizer(str, ",");
3277 ArrayList<Size> sizeList = new ArrayList<Size>();
3278 while (tokenizer.hasMoreElements()) {
3279 Size size = strToSize(tokenizer.nextToken());
3280 if (size != null) sizeList.add(size);
3281 }
3282 if (sizeList.size() == 0) return null;
3283 return sizeList;
3284 }
3285
3286 // Parses a string (ex: "480x320") to Size object.
3287 // Return null if the passing string is null.
3288 private Size strToSize(String str) {
3289 if (str == null) return null;
3290
3291 int pos = str.indexOf('x');
3292 if (pos != -1) {
3293 String width = str.substring(0, pos);
3294 String height = str.substring(pos + 1);
3295 return new Size(Integer.parseInt(width),
3296 Integer.parseInt(height));
3297 }
3298 Log.e(TAG, "Invalid size parameter string=" + str);
3299 return null;
3300 }
Wu-cheng Li454630f2010-08-11 16:48:05 -07003301
3302 // Splits a comma delimited string to an ArrayList of int array.
3303 // Example string: "(10000,26623),(10000,30000)". Return null if the
3304 // passing string is null or the size is 0.
3305 private ArrayList<int[]> splitRange(String str) {
3306 if (str == null || str.charAt(0) != '('
3307 || str.charAt(str.length() - 1) != ')') {
3308 Log.e(TAG, "Invalid range list string=" + str);
3309 return null;
3310 }
3311
3312 ArrayList<int[]> rangeList = new ArrayList<int[]>();
3313 int endIndex, fromIndex = 1;
3314 do {
3315 int[] range = new int[2];
3316 endIndex = str.indexOf("),(", fromIndex);
3317 if (endIndex == -1) endIndex = str.length() - 1;
3318 splitInt(str.substring(fromIndex, endIndex), range);
3319 rangeList.add(range);
3320 fromIndex = endIndex + 3;
3321 } while (endIndex != str.length() - 1);
3322
3323 if (rangeList.size() == 0) return null;
3324 return rangeList;
3325 }
Wu-cheng Li30771b72011-04-02 06:19:46 +08003326
3327 // Splits a comma delimited string to an ArrayList of Area objects.
3328 // Example string: "(-10,-10,0,0,300),(0,0,10,10,700)". Return null if
Wu-cheng Lif715bf92011-04-14 14:04:18 +08003329 // the passing string is null or the size is 0 or (0,0,0,0,0).
Wu-cheng Li30771b72011-04-02 06:19:46 +08003330 private ArrayList<Area> splitArea(String str) {
3331 if (str == null || str.charAt(0) != '('
3332 || str.charAt(str.length() - 1) != ')') {
3333 Log.e(TAG, "Invalid area string=" + str);
3334 return null;
3335 }
3336
3337 ArrayList<Area> result = new ArrayList<Area>();
3338 int endIndex, fromIndex = 1;
3339 int[] array = new int[5];
3340 do {
3341 endIndex = str.indexOf("),(", fromIndex);
3342 if (endIndex == -1) endIndex = str.length() - 1;
3343 splitInt(str.substring(fromIndex, endIndex), array);
3344 Rect rect = new Rect(array[0], array[1], array[2], array[3]);
3345 result.add(new Area(rect, array[4]));
3346 fromIndex = endIndex + 3;
3347 } while (endIndex != str.length() - 1);
3348
3349 if (result.size() == 0) return null;
Wu-cheng Lif715bf92011-04-14 14:04:18 +08003350
3351 if (result.size() == 1) {
Wu-cheng Libde61a52011-06-07 18:23:14 +08003352 Area area = result.get(0);
Wu-cheng Lif715bf92011-04-14 14:04:18 +08003353 Rect rect = area.rect;
3354 if (rect.left == 0 && rect.top == 0 && rect.right == 0
3355 && rect.bottom == 0 && area.weight == 0) {
3356 return null;
3357 }
3358 }
3359
Wu-cheng Li30771b72011-04-02 06:19:46 +08003360 return result;
3361 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003362 };
3363}