blob: 4e510809bf5e403751326793e5ff4715a36d5b7d [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2008 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.hardware;
18
Eino-Ville Talvala788717c2013-02-15 18:30:15 -080019import android.app.ActivityThread;
Wu-cheng Li10e09c62011-07-18 09:09:41 +080020import android.annotation.SdkConstant;
21import android.annotation.SdkConstant.SdkConstantType;
Eino-Ville Talvala4f8e5ce2012-10-08 18:16:35 -070022import android.content.Context;
Mathias Agopiana696f5d2010-02-17 17:53:09 -080023import android.graphics.ImageFormat;
Wu-cheng Li4c2292e2011-07-22 02:37:11 +080024import android.graphics.Point;
Wu-cheng Li30771b72011-04-02 06:19:46 +080025import android.graphics.Rect;
Jamie Gennisfd6f39e2010-12-20 12:15:00 -080026import android.graphics.SurfaceTexture;
Eino-Ville Talvala4f8e5ce2012-10-08 18:16:35 -070027import android.media.IAudioService;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080028import android.os.Handler;
Eino-Ville Talvala4f8e5ce2012-10-08 18:16:35 -070029import android.os.IBinder;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080030import android.os.Looper;
31import android.os.Message;
Eino-Ville Talvala4f8e5ce2012-10-08 18:16:35 -070032import android.os.RemoteException;
33import android.os.ServiceManager;
Wu-cheng Libde61a52011-06-07 18:23:14 +080034import android.util.Log;
Ali Utku Selen0a120182011-02-09 14:11:22 +010035import android.text.TextUtils;
Wu-cheng Libde61a52011-06-07 18:23:14 +080036import android.view.Surface;
37import android.view.SurfaceHolder;
38
39import java.io.IOException;
40import java.lang.ref.WeakReference;
41import java.util.ArrayList;
42import java.util.HashMap;
43import java.util.List;
James Dong248ba232012-04-28 21:30:46 -070044import java.util.concurrent.locks.ReentrantLock;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080045
46/**
Dan Egnorbfcbeff2010-07-12 15:12:54 -070047 * The Camera class is used to set image capture settings, start/stop preview,
48 * snap pictures, and retrieve frames for encoding for video. This class is a
49 * client for the Camera service, which manages the actual camera hardware.
Scott Maindf4578e2009-09-10 12:22:07 -070050 *
Dan Egnorbfcbeff2010-07-12 15:12:54 -070051 * <p>To access the device camera, you must declare the
Wu-cheng Li7478ea62009-09-16 18:52:55 +080052 * {@link android.Manifest.permission#CAMERA} permission in your Android
Scott Maindf4578e2009-09-10 12:22:07 -070053 * Manifest. Also be sure to include the
54 * <a href="{@docRoot}guide/topics/manifest/uses-feature-element.html">&lt;uses-feature></a>
Dan Egnorbfcbeff2010-07-12 15:12:54 -070055 * manifest element to declare camera features used by your application.
Wu-cheng Li7478ea62009-09-16 18:52:55 +080056 * For example, if you use the camera and auto-focus feature, your Manifest
Scott Maindf4578e2009-09-10 12:22:07 -070057 * should include the following:</p>
58 * <pre> &lt;uses-permission android:name="android.permission.CAMERA" />
59 * &lt;uses-feature android:name="android.hardware.camera" />
60 * &lt;uses-feature android:name="android.hardware.camera.autofocus" /></pre>
61 *
Dan Egnorbfcbeff2010-07-12 15:12:54 -070062 * <p>To take pictures with this class, use the following steps:</p>
63 *
64 * <ol>
Dan Egnor341ff132010-07-20 11:30:17 -070065 * <li>Obtain an instance of Camera from {@link #open(int)}.
Dan Egnorbfcbeff2010-07-12 15:12:54 -070066 *
67 * <li>Get existing (default) settings with {@link #getParameters()}.
68 *
69 * <li>If necessary, modify the returned {@link Camera.Parameters} object and call
70 * {@link #setParameters(Camera.Parameters)}.
71 *
72 * <li>If desired, call {@link #setDisplayOrientation(int)}.
73 *
74 * <li><b>Important</b>: Pass a fully initialized {@link SurfaceHolder} to
75 * {@link #setPreviewDisplay(SurfaceHolder)}. Without a surface, the camera
76 * will be unable to start the preview.
77 *
78 * <li><b>Important</b>: Call {@link #startPreview()} to start updating the
79 * preview surface. Preview must be started before you can take a picture.
80 *
81 * <li>When you want, call {@link #takePicture(Camera.ShutterCallback,
82 * Camera.PictureCallback, Camera.PictureCallback, Camera.PictureCallback)} to
83 * capture a photo. Wait for the callbacks to provide the actual image data.
84 *
85 * <li>After taking a picture, preview display will have stopped. To take more
86 * photos, call {@link #startPreview()} again first.
87 *
88 * <li>Call {@link #stopPreview()} to stop updating the preview surface.
89 *
90 * <li><b>Important:</b> Call {@link #release()} to release the camera for
91 * use by other applications. Applications should release the camera
92 * immediately in {@link android.app.Activity#onPause()} (and re-{@link #open()}
93 * it in {@link android.app.Activity#onResume()}).
94 * </ol>
95 *
96 * <p>To quickly switch to video recording mode, use these steps:</p>
97 *
98 * <ol>
99 * <li>Obtain and initialize a Camera and start preview as described above.
100 *
101 * <li>Call {@link #unlock()} to allow the media process to access the camera.
102 *
103 * <li>Pass the camera to {@link android.media.MediaRecorder#setCamera(Camera)}.
104 * See {@link android.media.MediaRecorder} information about video recording.
105 *
106 * <li>When finished recording, call {@link #reconnect()} to re-acquire
107 * and re-lock the camera.
108 *
109 * <li>If desired, restart preview and take more photos or videos.
110 *
111 * <li>Call {@link #stopPreview()} and {@link #release()} as described above.
112 * </ol>
113 *
114 * <p>This class is not thread-safe, and is meant for use from one event thread.
115 * Most long-running operations (preview, focus, photo capture, etc) happen
116 * asynchronously and invoke callbacks as necessary. Callbacks will be invoked
Dan Egnor341ff132010-07-20 11:30:17 -0700117 * on the event thread {@link #open(int)} was called from. This class's methods
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700118 * must never be called from multiple threads at once.</p>
119 *
Scott Maindf4578e2009-09-10 12:22:07 -0700120 * <p class="caution"><strong>Caution:</strong> Different Android-powered devices
121 * may have different hardware specifications, such as megapixel ratings and
122 * auto-focus capabilities. In order for your application to be compatible with
Wu-cheng Li7478ea62009-09-16 18:52:55 +0800123 * more devices, you should not make assumptions about the device camera
Scott Maindf4578e2009-09-10 12:22:07 -0700124 * specifications.</p>
Joe Fernandez6c5c3c32011-10-18 14:57:05 -0700125 *
126 * <div class="special reference">
127 * <h3>Developer Guides</h3>
128 * <p>For more information about using cameras, read the
129 * <a href="{@docRoot}guide/topics/media/camera.html">Camera</a> developer guide.</p>
130 * </div>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800131 */
132public class Camera {
133 private static final String TAG = "Camera";
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800134
Wu-cheng Lid2c29292010-05-28 17:32:41 +0800135 // These match the enums in frameworks/base/include/camera/Camera.h
Benny Wongda83f462009-08-12 12:01:27 -0500136 private static final int CAMERA_MSG_ERROR = 0x001;
137 private static final int CAMERA_MSG_SHUTTER = 0x002;
138 private static final int CAMERA_MSG_FOCUS = 0x004;
139 private static final int CAMERA_MSG_ZOOM = 0x008;
140 private static final int CAMERA_MSG_PREVIEW_FRAME = 0x010;
141 private static final int CAMERA_MSG_VIDEO_FRAME = 0x020;
142 private static final int CAMERA_MSG_POSTVIEW_FRAME = 0x040;
143 private static final int CAMERA_MSG_RAW_IMAGE = 0x080;
144 private static final int CAMERA_MSG_COMPRESSED_IMAGE = 0x100;
Wu-cheng Li4c2292e2011-07-22 02:37:11 +0800145 private static final int CAMERA_MSG_RAW_IMAGE_NOTIFY = 0x200;
Wu-cheng Libb1e2752011-07-30 05:00:37 +0800146 private static final int CAMERA_MSG_PREVIEW_METADATA = 0x400;
Wu-cheng Li9d062cf2011-11-14 20:30:14 +0800147 private static final int CAMERA_MSG_FOCUS_MOVE = 0x800;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800148
149 private int mNativeContext; // accessed by native methods
150 private EventHandler mEventHandler;
151 private ShutterCallback mShutterCallback;
152 private PictureCallback mRawImageCallback;
153 private PictureCallback mJpegCallback;
154 private PreviewCallback mPreviewCallback;
Dave Sparkse8b26e12009-07-14 10:35:40 -0700155 private PictureCallback mPostviewCallback;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800156 private AutoFocusCallback mAutoFocusCallback;
Wu-cheng Li9d062cf2011-11-14 20:30:14 +0800157 private AutoFocusMoveCallback mAutoFocusMoveCallback;
Wu-cheng Li3f4639a2010-04-04 15:05:41 +0800158 private OnZoomChangeListener mZoomListener;
Wu-cheng Li4c2292e2011-07-22 02:37:11 +0800159 private FaceDetectionListener mFaceListener;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800160 private ErrorCallback mErrorCallback;
161 private boolean mOneShot;
Andrew Harp94927df2009-10-20 01:47:05 -0400162 private boolean mWithBuffer;
Wu-cheng Li4c2292e2011-07-22 02:37:11 +0800163 private boolean mFaceDetectionRunning = false;
Wu-cheng Lif05c1d62012-05-02 23:29:47 +0800164 private Object mAutoFocusCallbackLock = new Object();
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800165
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800166 /**
Wu-cheng Li10e09c62011-07-18 09:09:41 +0800167 * Broadcast Action: A new picture is taken by the camera, and the entry of
168 * the picture has been added to the media store.
169 * {@link android.content.Intent#getData} is URI of the picture.
170 */
171 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
172 public static final String ACTION_NEW_PICTURE = "android.hardware.action.NEW_PICTURE";
173
174 /**
175 * Broadcast Action: A new video is recorded by the camera, and the entry
176 * of the video has been added to the media store.
177 * {@link android.content.Intent#getData} is URI of the video.
178 */
179 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
180 public static final String ACTION_NEW_VIDEO = "android.hardware.action.NEW_VIDEO";
181
182 /**
Wu-cheng Li4c2292e2011-07-22 02:37:11 +0800183 * Hardware face detection. It does not use much CPU.
Wu-cheng Li4c2292e2011-07-22 02:37:11 +0800184 */
Wu-cheng Lic0c683b2011-08-04 00:11:00 +0800185 private static final int CAMERA_FACE_DETECTION_HW = 0;
Wu-cheng Li4c2292e2011-07-22 02:37:11 +0800186
187 /**
Wu-cheng Lic0c683b2011-08-04 00:11:00 +0800188 * Software face detection. It uses some CPU.
Wu-cheng Li4c2292e2011-07-22 02:37:11 +0800189 */
Wu-cheng Lic0c683b2011-08-04 00:11:00 +0800190 private static final int CAMERA_FACE_DETECTION_SW = 1;
Wu-cheng Li4c2292e2011-07-22 02:37:11 +0800191
192 /**
Dan Egnor341ff132010-07-20 11:30:17 -0700193 * Returns the number of physical cameras available on this device.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800194 */
Chih-Chung Change25cc652010-05-06 16:36:58 +0800195 public native static int getNumberOfCameras();
196
197 /**
Dan Egnor341ff132010-07-20 11:30:17 -0700198 * Returns the information about a particular camera.
Chih-Chung Changb8bb78f2010-06-10 13:32:16 +0800199 * If {@link #getNumberOfCameras()} returns N, the valid id is 0 to N-1.
Chih-Chung Changb8bb78f2010-06-10 13:32:16 +0800200 */
Eino-Ville Talvala4f8e5ce2012-10-08 18:16:35 -0700201 public static void getCameraInfo(int cameraId, CameraInfo cameraInfo) {
202 _getCameraInfo(cameraId, cameraInfo);
203 IBinder b = ServiceManager.getService(Context.AUDIO_SERVICE);
204 IAudioService audioService = IAudioService.Stub.asInterface(b);
205 try {
206 if (audioService.isCameraSoundForced()) {
207 // Only set this when sound is forced; otherwise let native code
208 // decide.
209 cameraInfo.canDisableShutterSound = false;
210 }
211 } catch (RemoteException e) {
212 Log.e(TAG, "Audio service is unavailable for queries");
213 }
214 }
215 private native static void _getCameraInfo(int cameraId, CameraInfo cameraInfo);
Chih-Chung Changb8bb78f2010-06-10 13:32:16 +0800216
217 /**
218 * Information about a camera
Chih-Chung Changb8bb78f2010-06-10 13:32:16 +0800219 */
220 public static class CameraInfo {
Wu-cheng Li78366602010-09-15 14:08:15 -0700221 /**
222 * The facing of the camera is opposite to that of the screen.
223 */
Chih-Chung Changb8bb78f2010-06-10 13:32:16 +0800224 public static final int CAMERA_FACING_BACK = 0;
Wu-cheng Li78366602010-09-15 14:08:15 -0700225
226 /**
227 * The facing of the camera is the same as that of the screen.
228 */
Chih-Chung Changb8bb78f2010-06-10 13:32:16 +0800229 public static final int CAMERA_FACING_FRONT = 1;
230
231 /**
Joe Fernandez464cb212011-10-04 16:56:47 -0700232 * The direction that the camera faces. It should be
Chih-Chung Changb8bb78f2010-06-10 13:32:16 +0800233 * CAMERA_FACING_BACK or CAMERA_FACING_FRONT.
234 */
Wu-cheng Li78366602010-09-15 14:08:15 -0700235 public int facing;
Chih-Chung Changb8bb78f2010-06-10 13:32:16 +0800236
237 /**
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -0700238 * <p>The orientation of the camera image. The value is the angle that the
Chih-Chung Changb8bb78f2010-06-10 13:32:16 +0800239 * camera image needs to be rotated clockwise so it shows correctly on
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -0700240 * the display in its natural orientation. It should be 0, 90, 180, or 270.</p>
Chih-Chung Changb8bb78f2010-06-10 13:32:16 +0800241 *
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -0700242 * <p>For example, suppose a device has a naturally tall screen. The
Wu-cheng Li2fe6fca2010-10-15 14:42:23 +0800243 * back-facing camera sensor is mounted in landscape. You are looking at
244 * the screen. If the top side of the camera sensor is aligned with the
245 * right edge of the screen in natural orientation, the value should be
246 * 90. If the top side of a front-facing camera sensor is aligned with
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -0700247 * the right of the screen, the value should be 270.</p>
Chih-Chung Changb8bb78f2010-06-10 13:32:16 +0800248 *
249 * @see #setDisplayOrientation(int)
Brad Fitzpatrick69ea4e12011-01-05 11:13:40 -0800250 * @see Parameters#setRotation(int)
251 * @see Parameters#setPreviewSize(int, int)
252 * @see Parameters#setPictureSize(int, int)
253 * @see Parameters#setJpegThumbnailSize(int, int)
Chih-Chung Changb8bb78f2010-06-10 13:32:16 +0800254 */
Wu-cheng Li78366602010-09-15 14:08:15 -0700255 public int orientation;
Eino-Ville Talvalaf7c6c5a2012-09-19 11:46:11 -0700256
257 /**
258 * <p>Whether the shutter sound can be disabled.</p>
259 *
260 * <p>On some devices, the camera shutter sound cannot be turned off
261 * through {@link #enableShutterSound enableShutterSound}. This field
262 * can be used to determine whether a call to disable the shutter sound
263 * will succeed.</p>
264 *
265 * <p>If this field is set to true, then a call of
266 * {@code enableShutterSound(false)} will be successful. If set to
267 * false, then that call will fail, and the shutter sound will be played
268 * when {@link Camera#takePicture takePicture} is called.</p>
269 */
270 public boolean canDisableShutterSound;
Chih-Chung Changb8bb78f2010-06-10 13:32:16 +0800271 };
272
273 /**
Wu-cheng Lia1c41e12012-02-23 19:01:00 -0800274 * Creates a new Camera object to access a particular hardware camera. If
275 * the same camera is opened by other applications, this will throw a
276 * RuntimeException.
277 *
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700278 * <p>You must call {@link #release()} when you are done using the camera,
279 * otherwise it will remain locked and be unavailable to other applications.
280 *
Dan Egnor341ff132010-07-20 11:30:17 -0700281 * <p>Your application should only have one Camera object active at a time
282 * for a particular hardware camera.
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700283 *
284 * <p>Callbacks from other methods are delivered to the event loop of the
285 * thread which called open(). If this thread has no event loop, then
286 * callbacks are delivered to the main application event loop. If there
287 * is no main application event loop, callbacks are not delivered.
288 *
289 * <p class="caution"><b>Caution:</b> On some devices, this method may
290 * take a long time to complete. It is best to call this method from a
291 * worker thread (possibly using {@link android.os.AsyncTask}) to avoid
292 * blocking the main application UI thread.
293 *
Dan Egnor341ff132010-07-20 11:30:17 -0700294 * @param cameraId the hardware camera to access, between 0 and
Wu-cheng Lia48b70f2010-11-09 01:55:44 +0800295 * {@link #getNumberOfCameras()}-1.
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700296 * @return a new Camera object, connected, locked and ready for use.
Wu-cheng Lia1c41e12012-02-23 19:01:00 -0800297 * @throws RuntimeException if opening the camera fails (for example, if the
298 * camera is in use by another process or device policy manager has
299 * disabled the camera).
Wu-cheng Lifacc8ce2011-06-17 13:09:40 +0800300 * @see android.app.admin.DevicePolicyManager#getCameraDisabled(android.content.ComponentName)
Chih-Chung Change25cc652010-05-06 16:36:58 +0800301 */
302 public static Camera open(int cameraId) {
Wu-cheng Li7bc1b212012-04-19 12:23:31 +0800303 return new Camera(cameraId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800304 }
305
Chih-Chung Change25cc652010-05-06 16:36:58 +0800306 /**
Wu-cheng Lia48b70f2010-11-09 01:55:44 +0800307 * Creates a new Camera object to access the first back-facing camera on the
308 * device. If the device does not have a back-facing camera, this returns
309 * null.
Wu-cheng Li78366602010-09-15 14:08:15 -0700310 * @see #open(int)
Chih-Chung Change25cc652010-05-06 16:36:58 +0800311 */
312 public static Camera open() {
Wu-cheng Lia48b70f2010-11-09 01:55:44 +0800313 int numberOfCameras = getNumberOfCameras();
314 CameraInfo cameraInfo = new CameraInfo();
315 for (int i = 0; i < numberOfCameras; i++) {
316 getCameraInfo(i, cameraInfo);
317 if (cameraInfo.facing == CameraInfo.CAMERA_FACING_BACK) {
Wu-cheng Li7bc1b212012-04-19 12:23:31 +0800318 return new Camera(i);
Wu-cheng Lia48b70f2010-11-09 01:55:44 +0800319 }
320 }
321 return null;
Chih-Chung Change25cc652010-05-06 16:36:58 +0800322 }
323
Wu-cheng Li7bc1b212012-04-19 12:23:31 +0800324 Camera(int cameraId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800325 mShutterCallback = null;
326 mRawImageCallback = null;
327 mJpegCallback = null;
328 mPreviewCallback = null;
Dave Sparkse8b26e12009-07-14 10:35:40 -0700329 mPostviewCallback = null;
Wu-cheng Li3f4639a2010-04-04 15:05:41 +0800330 mZoomListener = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800331
332 Looper looper;
333 if ((looper = Looper.myLooper()) != null) {
334 mEventHandler = new EventHandler(this, looper);
335 } else if ((looper = Looper.getMainLooper()) != null) {
336 mEventHandler = new EventHandler(this, looper);
337 } else {
338 mEventHandler = null;
339 }
340
Eino-Ville Talvala788717c2013-02-15 18:30:15 -0800341 String packageName = ActivityThread.currentPackageName();
342
343 native_setup(new WeakReference<Camera>(this), cameraId, packageName);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800344 }
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800345
Wu-cheng Li1c04a332011-11-22 18:21:18 +0800346 /**
347 * An empty Camera for testing purpose.
348 */
349 Camera() {
350 }
351
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800352 protected void finalize() {
Eino-Ville Talvalae0cc55a2011-11-08 10:12:09 -0800353 release();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800354 }
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800355
Eino-Ville Talvala788717c2013-02-15 18:30:15 -0800356 private native final void native_setup(Object camera_this, int cameraId,
357 String packageName);
358
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800359 private native final void native_release();
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800360
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800361
362 /**
363 * Disconnects and releases the Camera object resources.
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700364 *
365 * <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 -0800366 */
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800367 public final void release() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800368 native_release();
Wu-cheng Li4c2292e2011-07-22 02:37:11 +0800369 mFaceDetectionRunning = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800370 }
371
372 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700373 * Unlocks the camera to allow another process to access it.
374 * Normally, the camera is locked to the process with an active Camera
375 * object until {@link #release()} is called. To allow rapid handoff
376 * between processes, you can call this method to release the camera
377 * temporarily for another process to use; once the other process is done
378 * you can call {@link #reconnect()} to reclaim the camera.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800379 *
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700380 * <p>This must be done before calling
Wu-cheng Li42419ce2011-06-01 17:22:24 +0800381 * {@link android.media.MediaRecorder#setCamera(Camera)}. This cannot be
382 * called after recording starts.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800383 *
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700384 * <p>If you are not recording video, you probably do not need this method.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800385 *
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700386 * @throws RuntimeException if the camera cannot be unlocked.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800387 */
Wu-cheng Liffe1cf22009-09-10 16:49:17 +0800388 public native final void unlock();
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800389
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800390 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700391 * Re-locks the camera to prevent other processes from accessing it.
392 * Camera objects are locked by default unless {@link #unlock()} is
393 * called. Normally {@link #reconnect()} is used instead.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800394 *
Wu-cheng Li53b30912011-10-12 19:43:51 +0800395 * <p>Since API level 14, camera is automatically locked for applications in
Wu-cheng Li42419ce2011-06-01 17:22:24 +0800396 * {@link android.media.MediaRecorder#start()}. Applications can use the
397 * camera (ex: zoom) after recording starts. There is no need to call this
398 * after recording starts or stops.
399 *
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700400 * <p>If you are not recording video, you probably do not need this method.
401 *
402 * @throws RuntimeException if the camera cannot be re-locked (for
403 * example, if the camera is still in use by another process).
404 */
405 public native final void lock();
406
407 /**
408 * Reconnects to the camera service after another process used it.
409 * After {@link #unlock()} is called, another process may use the
410 * camera; when the process is done, you must reconnect to the camera,
411 * which will re-acquire the lock and allow you to continue using the
412 * camera.
413 *
Wu-cheng Li53b30912011-10-12 19:43:51 +0800414 * <p>Since API level 14, camera is automatically locked for applications in
Wu-cheng Li42419ce2011-06-01 17:22:24 +0800415 * {@link android.media.MediaRecorder#start()}. Applications can use the
416 * camera (ex: zoom) after recording starts. There is no need to call this
417 * after recording starts or stops.
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700418 *
419 * <p>If you are not recording video, you probably do not need this method.
420 *
421 * @throws IOException if a connection cannot be re-established (for
422 * example, if the camera is still in use by another process).
423 */
424 public native final void reconnect() throws IOException;
425
426 /**
427 * Sets the {@link Surface} to be used for live preview.
Jamie Gennisfd6f39e2010-12-20 12:15:00 -0800428 * Either a surface or surface texture is necessary for preview, and
429 * preview is necessary to take pictures. The same surface can be re-set
430 * without harm. Setting a preview surface will un-set any preview surface
431 * texture that was set via {@link #setPreviewTexture}.
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700432 *
433 * <p>The {@link SurfaceHolder} must already contain a surface when this
434 * method is called. If you are using {@link android.view.SurfaceView},
435 * you will need to register a {@link SurfaceHolder.Callback} with
436 * {@link SurfaceHolder#addCallback(SurfaceHolder.Callback)} and wait for
437 * {@link SurfaceHolder.Callback#surfaceCreated(SurfaceHolder)} before
438 * calling setPreviewDisplay() or starting preview.
439 *
440 * <p>This method must be called before {@link #startPreview()}. The
441 * one exception is that if the preview surface is not set (or set to null)
442 * before startPreview() is called, then this method may be called once
443 * with a non-null parameter to set the preview surface. (This allows
444 * camera setup and surface creation to happen in parallel, saving time.)
445 * The preview surface may not otherwise change while preview is running.
446 *
447 * @param holder containing the Surface on which to place the preview,
448 * or null to remove the preview surface
449 * @throws IOException if the method fails (for example, if the surface
450 * is unavailable or unsuitable).
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800451 */
452 public final void setPreviewDisplay(SurfaceHolder holder) throws IOException {
Wu-cheng Lib8a10fe2009-06-23 23:37:36 +0800453 if (holder != null) {
454 setPreviewDisplay(holder.getSurface());
455 } else {
456 setPreviewDisplay((Surface)null);
457 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800458 }
459
Glenn Kastendbc289d2011-02-09 10:15:44 -0800460 private native final void setPreviewDisplay(Surface surface) throws IOException;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800461
462 /**
Jamie Gennisfd6f39e2010-12-20 12:15:00 -0800463 * Sets the {@link SurfaceTexture} to be used for live preview.
464 * Either a surface or surface texture is necessary for preview, and
465 * preview is necessary to take pictures. The same surface texture can be
466 * re-set without harm. Setting a preview surface texture will un-set any
467 * preview surface that was set via {@link #setPreviewDisplay}.
468 *
469 * <p>This method must be called before {@link #startPreview()}. The
470 * one exception is that if the preview surface texture is not set (or set
471 * to null) before startPreview() is called, then this method may be called
472 * once with a non-null parameter to set the preview surface. (This allows
473 * camera setup and surface creation to happen in parallel, saving time.)
474 * The preview surface texture may not otherwise change while preview is
475 * running.
476 *
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -0700477 * <p>The timestamps provided by {@link SurfaceTexture#getTimestamp()} for a
Eino-Ville Talvalae309a0f2011-03-21 11:04:34 -0700478 * SurfaceTexture set as the preview texture have an unspecified zero point,
479 * and cannot be directly compared between different cameras or different
480 * instances of the same camera, or across multiple runs of the same
481 * program.
482 *
Eino-Ville Talvala108708b2012-03-05 11:00:43 -0800483 * <p>If you are using the preview data to create video or still images,
484 * strongly consider using {@link android.media.MediaActionSound} to
485 * properly indicate image capture or recording start/stop to the user.</p>
486 *
487 * @see android.media.MediaActionSound
488 * @see android.graphics.SurfaceTexture
489 * @see android.view.TextureView
Jamie Gennisfd6f39e2010-12-20 12:15:00 -0800490 * @param surfaceTexture the {@link SurfaceTexture} to which the preview
491 * images are to be sent or null to remove the current preview surface
492 * texture
493 * @throws IOException if the method fails (for example, if the surface
494 * texture is unavailable or unsuitable).
495 */
Glenn Kastendbc289d2011-02-09 10:15:44 -0800496 public native final void setPreviewTexture(SurfaceTexture surfaceTexture) throws IOException;
Jamie Gennisfd6f39e2010-12-20 12:15:00 -0800497
498 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700499 * Callback interface used to deliver copies of preview frames as
500 * they are displayed.
501 *
502 * @see #setPreviewCallback(Camera.PreviewCallback)
503 * @see #setOneShotPreviewCallback(Camera.PreviewCallback)
504 * @see #setPreviewCallbackWithBuffer(Camera.PreviewCallback)
505 * @see #startPreview()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800506 */
507 public interface PreviewCallback
508 {
509 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700510 * Called as preview frames are displayed. This callback is invoked
Dan Egnor341ff132010-07-20 11:30:17 -0700511 * on the event thread {@link #open(int)} was called from.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800512 *
Eino-Ville Talvala95151632012-05-02 16:21:18 -0700513 * <p>If using the {@link android.graphics.ImageFormat#YV12} format,
514 * refer to the equations in {@link Camera.Parameters#setPreviewFormat}
515 * for the arrangement of the pixel data in the preview callback
516 * buffers.
517 *
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700518 * @param data the contents of the preview frame in the format defined
Mathias Agopiana696f5d2010-02-17 17:53:09 -0800519 * by {@link android.graphics.ImageFormat}, which can be queried
Scott Maindf4578e2009-09-10 12:22:07 -0700520 * with {@link android.hardware.Camera.Parameters#getPreviewFormat()}.
Scott Mainda0a56d2009-09-10 18:08:37 -0700521 * If {@link android.hardware.Camera.Parameters#setPreviewFormat(int)}
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800522 * is never called, the default will be the YCbCr_420_SP
523 * (NV21) format.
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700524 * @param camera the Camera service object.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800525 */
526 void onPreviewFrame(byte[] data, Camera camera);
527 };
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800528
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800529 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700530 * Starts capturing and drawing preview frames to the screen.
Eino-Ville Talvalac5f94d82011-02-18 11:02:42 -0800531 * Preview will not actually start until a surface is supplied
532 * with {@link #setPreviewDisplay(SurfaceHolder)} or
533 * {@link #setPreviewTexture(SurfaceTexture)}.
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700534 *
535 * <p>If {@link #setPreviewCallback(Camera.PreviewCallback)},
536 * {@link #setOneShotPreviewCallback(Camera.PreviewCallback)}, or
537 * {@link #setPreviewCallbackWithBuffer(Camera.PreviewCallback)} were
538 * called, {@link Camera.PreviewCallback#onPreviewFrame(byte[], Camera)}
539 * will be called when preview data becomes available.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800540 */
541 public native final void startPreview();
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800542
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800543 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700544 * Stops capturing and drawing preview frames to the surface, and
545 * resets the camera for a future call to {@link #startPreview()}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800546 */
Wu-cheng Li4c2292e2011-07-22 02:37:11 +0800547 public final void stopPreview() {
548 _stopPreview();
549 mFaceDetectionRunning = false;
Chih-yu Huang664d72e2011-09-23 18:59:38 +0800550
551 mShutterCallback = null;
552 mRawImageCallback = null;
553 mPostviewCallback = null;
554 mJpegCallback = null;
Wu-cheng Lif05c1d62012-05-02 23:29:47 +0800555 synchronized (mAutoFocusCallbackLock) {
556 mAutoFocusCallback = null;
557 }
Wu-cheng Li9d062cf2011-11-14 20:30:14 +0800558 mAutoFocusMoveCallback = null;
Wu-cheng Li4c2292e2011-07-22 02:37:11 +0800559 }
560
561 private native final void _stopPreview();
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800562
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800563 /**
564 * Return current preview state.
565 *
566 * FIXME: Unhide before release
567 * @hide
568 */
569 public native final boolean previewEnabled();
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800570
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800571 /**
Eino-Ville Talvala108708b2012-03-05 11:00:43 -0800572 * <p>Installs a callback to be invoked for every preview frame in addition
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700573 * to displaying them on the screen. The callback will be repeatedly called
574 * for as long as preview is active. This method can be called at any time,
Eino-Ville Talvala108708b2012-03-05 11:00:43 -0800575 * even while preview is live. Any other preview callbacks are
576 * overridden.</p>
577 *
578 * <p>If you are using the preview data to create video or still images,
579 * strongly consider using {@link android.media.MediaActionSound} to
580 * properly indicate image capture or recording start/stop to the user.</p>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800581 *
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700582 * @param cb a callback object that receives a copy of each preview frame,
583 * or null to stop receiving callbacks.
Eino-Ville Talvala108708b2012-03-05 11:00:43 -0800584 * @see android.media.MediaActionSound
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800585 */
586 public final void setPreviewCallback(PreviewCallback cb) {
587 mPreviewCallback = cb;
588 mOneShot = false;
Andrew Harp94927df2009-10-20 01:47:05 -0400589 mWithBuffer = false;
Dave Sparksa6118c62009-10-13 02:28:54 -0700590 // Always use one-shot mode. We fake camera preview mode by
591 // doing one-shot preview continuously.
Andrew Harp94927df2009-10-20 01:47:05 -0400592 setHasPreviewCallback(cb != null, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800593 }
594
595 /**
Eino-Ville Talvala108708b2012-03-05 11:00:43 -0800596 * <p>Installs a callback to be invoked for the next preview frame in
597 * addition to displaying it on the screen. After one invocation, the
598 * callback is cleared. This method can be called any time, even when
599 * preview is live. Any other preview callbacks are overridden.</p>
600 *
601 * <p>If you are using the preview data to create video or still images,
602 * strongly consider using {@link android.media.MediaActionSound} to
603 * properly indicate image capture or recording start/stop to the user.</p>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800604 *
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700605 * @param cb a callback object that receives a copy of the next preview frame,
606 * or null to stop receiving callbacks.
Eino-Ville Talvala108708b2012-03-05 11:00:43 -0800607 * @see android.media.MediaActionSound
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800608 */
609 public final void setOneShotPreviewCallback(PreviewCallback cb) {
Andrew Harp94927df2009-10-20 01:47:05 -0400610 mPreviewCallback = cb;
611 mOneShot = true;
612 mWithBuffer = false;
613 setHasPreviewCallback(cb != null, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800614 }
615
Andrew Harp94927df2009-10-20 01:47:05 -0400616 private native final void setHasPreviewCallback(boolean installed, boolean manualBuffer);
617
618 /**
Eino-Ville Talvala108708b2012-03-05 11:00:43 -0800619 * <p>Installs a callback to be invoked for every preview frame, using
620 * buffers supplied with {@link #addCallbackBuffer(byte[])}, in addition to
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700621 * displaying them on the screen. The callback will be repeatedly called
Eino-Ville Talvala108708b2012-03-05 11:00:43 -0800622 * for as long as preview is active and buffers are available. Any other
623 * preview callbacks are overridden.</p>
Andrew Harp94927df2009-10-20 01:47:05 -0400624 *
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700625 * <p>The purpose of this method is to improve preview efficiency and frame
626 * rate by allowing preview frame memory reuse. You must call
627 * {@link #addCallbackBuffer(byte[])} at some point -- before or after
Eino-Ville Talvala108708b2012-03-05 11:00:43 -0800628 * calling this method -- or no callbacks will received.</p>
Andrew Harp94927df2009-10-20 01:47:05 -0400629 *
Eino-Ville Talvala108708b2012-03-05 11:00:43 -0800630 * <p>The buffer queue will be cleared if this method is called with a null
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700631 * callback, {@link #setPreviewCallback(Camera.PreviewCallback)} is called,
Eino-Ville Talvala108708b2012-03-05 11:00:43 -0800632 * or {@link #setOneShotPreviewCallback(Camera.PreviewCallback)} is
633 * called.</p>
634 *
635 * <p>If you are using the preview data to create video or still images,
636 * strongly consider using {@link android.media.MediaActionSound} to
637 * properly indicate image capture or recording start/stop to the user.</p>
Andrew Harp94927df2009-10-20 01:47:05 -0400638 *
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700639 * @param cb a callback object that receives a copy of the preview frame,
640 * or null to stop receiving callbacks and clear the buffer queue.
641 * @see #addCallbackBuffer(byte[])
Eino-Ville Talvala108708b2012-03-05 11:00:43 -0800642 * @see android.media.MediaActionSound
Andrew Harp94927df2009-10-20 01:47:05 -0400643 */
644 public final void setPreviewCallbackWithBuffer(PreviewCallback cb) {
645 mPreviewCallback = cb;
646 mOneShot = false;
647 mWithBuffer = true;
648 setHasPreviewCallback(cb != null, true);
649 }
650
651 /**
Wu-cheng Li3f4639a2010-04-04 15:05:41 +0800652 * Adds a pre-allocated buffer to the preview callback buffer queue.
653 * Applications can add one or more buffers to the queue. When a preview
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700654 * frame arrives and there is still at least one available buffer, the
655 * buffer will be used and removed from the queue. Then preview callback is
656 * invoked with the buffer. If a frame arrives and there is no buffer left,
657 * the frame is discarded. Applications should add buffers back when they
658 * finish processing the data in them.
Wu-cheng Lic10275a2010-03-09 13:49:21 -0800659 *
Eino-Ville Talvala95151632012-05-02 16:21:18 -0700660 * <p>For formats besides YV12, the size of the buffer is determined by
661 * multiplying the preview image width, height, and bytes per pixel. The
662 * width and height can be read from
663 * {@link Camera.Parameters#getPreviewSize()}. Bytes per pixel can be
664 * computed from {@link android.graphics.ImageFormat#getBitsPerPixel(int)} /
665 * 8, using the image format from
666 * {@link Camera.Parameters#getPreviewFormat()}.
667 *
668 * <p>If using the {@link android.graphics.ImageFormat#YV12} format, the
669 * size can be calculated using the equations listed in
670 * {@link Camera.Parameters#setPreviewFormat}.
Andrew Harp94927df2009-10-20 01:47:05 -0400671 *
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700672 * <p>This method is only necessary when
James Donge00cab72011-02-17 16:38:06 -0800673 * {@link #setPreviewCallbackWithBuffer(PreviewCallback)} is used. When
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700674 * {@link #setPreviewCallback(PreviewCallback)} or
675 * {@link #setOneShotPreviewCallback(PreviewCallback)} are used, buffers
James Donge00cab72011-02-17 16:38:06 -0800676 * are automatically allocated. When a supplied buffer is too small to
677 * hold the preview frame data, preview callback will return null and
678 * the buffer will be removed from the buffer queue.
Andrew Harp94927df2009-10-20 01:47:05 -0400679 *
Eino-Ville Talvala95151632012-05-02 16:21:18 -0700680 * @param callbackBuffer the buffer to add to the queue. The size of the
681 * buffer must match the values described above.
Wu-cheng Li5b9bcda2010-03-07 14:59:28 -0800682 * @see #setPreviewCallbackWithBuffer(PreviewCallback)
Andrew Harp94927df2009-10-20 01:47:05 -0400683 */
James Donge00cab72011-02-17 16:38:06 -0800684 public final void addCallbackBuffer(byte[] callbackBuffer)
685 {
686 _addCallbackBuffer(callbackBuffer, CAMERA_MSG_PREVIEW_FRAME);
687 }
688
689 /**
690 * Adds a pre-allocated buffer to the raw image callback buffer queue.
691 * Applications can add one or more buffers to the queue. When a raw image
692 * frame arrives and there is still at least one available buffer, the
693 * buffer will be used to hold the raw image data and removed from the
694 * queue. Then raw image callback is invoked with the buffer. If a raw
695 * image frame arrives but there is no buffer left, the frame is
696 * discarded. Applications should add buffers back when they finish
697 * processing the data in them by calling this method again in order
698 * to avoid running out of raw image callback buffers.
699 *
700 * <p>The size of the buffer is determined by multiplying the raw image
701 * width, height, and bytes per pixel. The width and height can be
702 * read from {@link Camera.Parameters#getPictureSize()}. Bytes per pixel
703 * can be computed from
704 * {@link android.graphics.ImageFormat#getBitsPerPixel(int)} / 8,
705 * using the image format from {@link Camera.Parameters#getPreviewFormat()}.
706 *
707 * <p>This method is only necessary when the PictureCallbck for raw image
708 * is used while calling {@link #takePicture(Camera.ShutterCallback,
709 * Camera.PictureCallback, Camera.PictureCallback, Camera.PictureCallback)}.
710 *
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -0700711 * <p>Please note that by calling this method, the mode for
712 * application-managed callback buffers is triggered. If this method has
713 * never been called, null will be returned by the raw image callback since
714 * there is no image callback buffer available. Furthermore, When a supplied
715 * buffer is too small to hold the raw image data, raw image callback will
716 * return null and the buffer will be removed from the buffer queue.
James Donge00cab72011-02-17 16:38:06 -0800717 *
718 * @param callbackBuffer the buffer to add to the raw image callback buffer
719 * queue. The size should be width * height * (bits per pixel) / 8. An
720 * null callbackBuffer will be ignored and won't be added to the queue.
721 *
722 * @see #takePicture(Camera.ShutterCallback,
723 * Camera.PictureCallback, Camera.PictureCallback, Camera.PictureCallback)}.
724 *
725 * {@hide}
726 */
727 public final void addRawImageCallbackBuffer(byte[] callbackBuffer)
728 {
729 addCallbackBuffer(callbackBuffer, CAMERA_MSG_RAW_IMAGE);
730 }
731
732 private final void addCallbackBuffer(byte[] callbackBuffer, int msgType)
733 {
734 // CAMERA_MSG_VIDEO_FRAME may be allowed in the future.
735 if (msgType != CAMERA_MSG_PREVIEW_FRAME &&
736 msgType != CAMERA_MSG_RAW_IMAGE) {
737 throw new IllegalArgumentException(
738 "Unsupported message type: " + msgType);
739 }
740
741 _addCallbackBuffer(callbackBuffer, msgType);
742 }
743
744 private native final void _addCallbackBuffer(
745 byte[] callbackBuffer, int msgType);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800746
747 private class EventHandler extends Handler
748 {
749 private Camera mCamera;
750
751 public EventHandler(Camera c, Looper looper) {
752 super(looper);
753 mCamera = c;
754 }
755
756 @Override
757 public void handleMessage(Message msg) {
758 switch(msg.what) {
Dave Sparksc62f9bd2009-06-26 13:33:32 -0700759 case CAMERA_MSG_SHUTTER:
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800760 if (mShutterCallback != null) {
761 mShutterCallback.onShutter();
762 }
763 return;
Dave Sparksc62f9bd2009-06-26 13:33:32 -0700764
765 case CAMERA_MSG_RAW_IMAGE:
Dave Sparkse8b26e12009-07-14 10:35:40 -0700766 if (mRawImageCallback != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800767 mRawImageCallback.onPictureTaken((byte[])msg.obj, mCamera);
Dave Sparkse8b26e12009-07-14 10:35:40 -0700768 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800769 return;
770
Dave Sparksc62f9bd2009-06-26 13:33:32 -0700771 case CAMERA_MSG_COMPRESSED_IMAGE:
Dave Sparkse8b26e12009-07-14 10:35:40 -0700772 if (mJpegCallback != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800773 mJpegCallback.onPictureTaken((byte[])msg.obj, mCamera);
Dave Sparkse8b26e12009-07-14 10:35:40 -0700774 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800775 return;
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800776
Dave Sparksc62f9bd2009-06-26 13:33:32 -0700777 case CAMERA_MSG_PREVIEW_FRAME:
Eino-Ville Talvalaca367b72012-05-30 16:01:33 -0700778 PreviewCallback pCb = mPreviewCallback;
779 if (pCb != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800780 if (mOneShot) {
Dave Sparksa6118c62009-10-13 02:28:54 -0700781 // Clear the callback variable before the callback
782 // in case the app calls setPreviewCallback from
783 // the callback function
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800784 mPreviewCallback = null;
Andrew Harp94927df2009-10-20 01:47:05 -0400785 } else if (!mWithBuffer) {
Dave Sparksa6118c62009-10-13 02:28:54 -0700786 // We're faking the camera preview mode to prevent
787 // the app from being flooded with preview frames.
788 // Set to oneshot mode again.
Andrew Harp94927df2009-10-20 01:47:05 -0400789 setHasPreviewCallback(true, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800790 }
Eino-Ville Talvalaca367b72012-05-30 16:01:33 -0700791 pCb.onPreviewFrame((byte[])msg.obj, mCamera);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800792 }
793 return;
794
Dave Sparkse8b26e12009-07-14 10:35:40 -0700795 case CAMERA_MSG_POSTVIEW_FRAME:
796 if (mPostviewCallback != null) {
797 mPostviewCallback.onPictureTaken((byte[])msg.obj, mCamera);
798 }
799 return;
800
Dave Sparksc62f9bd2009-06-26 13:33:32 -0700801 case CAMERA_MSG_FOCUS:
Wu-cheng Lif05c1d62012-05-02 23:29:47 +0800802 AutoFocusCallback cb = null;
803 synchronized (mAutoFocusCallbackLock) {
804 cb = mAutoFocusCallback;
805 }
806 if (cb != null) {
807 boolean success = msg.arg1 == 0 ? false : true;
808 cb.onAutoFocus(success, mCamera);
Dave Sparkse8b26e12009-07-14 10:35:40 -0700809 }
810 return;
811
812 case CAMERA_MSG_ZOOM:
Wu-cheng Li3f4639a2010-04-04 15:05:41 +0800813 if (mZoomListener != null) {
814 mZoomListener.onZoomChange(msg.arg1, msg.arg2 != 0, mCamera);
Dave Sparkse8b26e12009-07-14 10:35:40 -0700815 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800816 return;
817
Wu-cheng Libb1e2752011-07-30 05:00:37 +0800818 case CAMERA_MSG_PREVIEW_METADATA:
Wu-cheng Li4c2292e2011-07-22 02:37:11 +0800819 if (mFaceListener != null) {
Wu-cheng Lif0d6a482011-07-28 05:30:59 +0800820 mFaceListener.onFaceDetection((Face[])msg.obj, mCamera);
Wu-cheng Li4c2292e2011-07-22 02:37:11 +0800821 }
822 return;
823
Dave Sparksc62f9bd2009-06-26 13:33:32 -0700824 case CAMERA_MSG_ERROR :
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800825 Log.e(TAG, "Error " + msg.arg1);
Dave Sparkse8b26e12009-07-14 10:35:40 -0700826 if (mErrorCallback != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800827 mErrorCallback.onError(msg.arg1, mCamera);
Dave Sparkse8b26e12009-07-14 10:35:40 -0700828 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800829 return;
830
Wu-cheng Li9d062cf2011-11-14 20:30:14 +0800831 case CAMERA_MSG_FOCUS_MOVE:
832 if (mAutoFocusMoveCallback != null) {
833 mAutoFocusMoveCallback.onAutoFocusMoving(msg.arg1 == 0 ? false : true, mCamera);
834 }
835 return;
836
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800837 default:
838 Log.e(TAG, "Unknown message type " + msg.what);
839 return;
840 }
841 }
842 }
843
844 private static void postEventFromNative(Object camera_ref,
845 int what, int arg1, int arg2, Object obj)
846 {
847 Camera c = (Camera)((WeakReference)camera_ref).get();
848 if (c == null)
849 return;
850
851 if (c.mEventHandler != null) {
852 Message m = c.mEventHandler.obtainMessage(what, arg1, arg2, obj);
853 c.mEventHandler.sendMessage(m);
854 }
855 }
856
857 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700858 * Callback interface used to notify on completion of camera auto focus.
859 *
Wu-cheng Li7478ea62009-09-16 18:52:55 +0800860 * <p>Devices that do not support auto-focus will receive a "fake"
861 * callback to this interface. If your application needs auto-focus and
Scott Maindf4578e2009-09-10 12:22:07 -0700862 * should not be installed on devices <em>without</em> auto-focus, you must
863 * declare that your app uses the
Wu-cheng Li7478ea62009-09-16 18:52:55 +0800864 * {@code android.hardware.camera.autofocus} feature, in the
Scott Maindf4578e2009-09-10 12:22:07 -0700865 * <a href="{@docRoot}guide/topics/manifest/uses-feature-element.html">&lt;uses-feature></a>
866 * manifest element.</p>
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700867 *
868 * @see #autoFocus(AutoFocusCallback)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800869 */
870 public interface AutoFocusCallback
871 {
872 /**
Brad Fitzpatrick69ea4e12011-01-05 11:13:40 -0800873 * Called when the camera auto focus completes. If the camera
874 * does not support auto-focus and autoFocus is called,
875 * onAutoFocus will be called immediately with a fake value of
876 * <code>success</code> set to <code>true</code>.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800877 *
Wu-cheng Lib4f95be2011-09-22 11:43:28 +0800878 * The auto-focus routine does not lock auto-exposure and auto-white
879 * balance after it completes.
Eino-Ville Talvala83d33522011-05-13 10:25:00 -0700880 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800881 * @param success true if focus was successful, false if otherwise
882 * @param camera the Camera service object
Eino-Ville Talvala83d33522011-05-13 10:25:00 -0700883 * @see android.hardware.Camera.Parameters#setAutoExposureLock(boolean)
884 * @see android.hardware.Camera.Parameters#setAutoWhiteBalanceLock(boolean)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800885 */
886 void onAutoFocus(boolean success, Camera camera);
Wu-cheng Li53b30912011-10-12 19:43:51 +0800887 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800888
889 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700890 * Starts camera auto-focus and registers a callback function to run when
891 * the camera is focused. This method is only valid when preview is active
892 * (between {@link #startPreview()} and before {@link #stopPreview()}).
893 *
894 * <p>Callers should check
895 * {@link android.hardware.Camera.Parameters#getFocusMode()} to determine if
896 * this method should be called. If the camera does not support auto-focus,
897 * it is a no-op and {@link AutoFocusCallback#onAutoFocus(boolean, Camera)}
Wu-cheng Li36322db2009-09-18 18:59:21 +0800898 * callback will be called immediately.
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700899 *
Scott Mainda0a56d2009-09-10 18:08:37 -0700900 * <p>If your application should not be installed
Wu-cheng Li7478ea62009-09-16 18:52:55 +0800901 * on devices without auto-focus, you must declare that your application
902 * uses auto-focus with the
Scott Maindf4578e2009-09-10 12:22:07 -0700903 * <a href="{@docRoot}guide/topics/manifest/uses-feature-element.html">&lt;uses-feature></a>
904 * manifest element.</p>
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700905 *
Wu-cheng Li068ef422009-09-27 13:19:36 -0700906 * <p>If the current flash mode is not
907 * {@link android.hardware.Camera.Parameters#FLASH_MODE_OFF}, flash may be
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700908 * fired during auto-focus, depending on the driver and camera hardware.<p>
Wu-cheng Li7478ea62009-09-16 18:52:55 +0800909 *
Wu-cheng Li53b30912011-10-12 19:43:51 +0800910 * <p>Auto-exposure lock {@link android.hardware.Camera.Parameters#getAutoExposureLock()}
Wu-cheng Lib4f95be2011-09-22 11:43:28 +0800911 * and auto-white balance locks {@link android.hardware.Camera.Parameters#getAutoWhiteBalanceLock()}
912 * do not change during and after autofocus. But auto-focus routine may stop
913 * auto-exposure and auto-white balance transiently during focusing.
Eino-Ville Talvala83d33522011-05-13 10:25:00 -0700914 *
Wu-cheng Li53b30912011-10-12 19:43:51 +0800915 * <p>Stopping preview with {@link #stopPreview()}, or triggering still
916 * image capture with {@link #takePicture(Camera.ShutterCallback,
917 * Camera.PictureCallback, Camera.PictureCallback)}, will not change the
918 * the focus position. Applications must call cancelAutoFocus to reset the
919 * focus.</p>
920 *
Eino-Ville Talvala108708b2012-03-05 11:00:43 -0800921 * <p>If autofocus is successful, consider using
922 * {@link android.media.MediaActionSound} to properly play back an autofocus
923 * success sound to the user.</p>
924 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800925 * @param cb the callback to run
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700926 * @see #cancelAutoFocus()
Eino-Ville Talvala83d33522011-05-13 10:25:00 -0700927 * @see android.hardware.Camera.Parameters#setAutoExposureLock(boolean)
928 * @see android.hardware.Camera.Parameters#setAutoWhiteBalanceLock(boolean)
Eino-Ville Talvala108708b2012-03-05 11:00:43 -0800929 * @see android.media.MediaActionSound
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800930 */
931 public final void autoFocus(AutoFocusCallback cb)
932 {
Wu-cheng Lif05c1d62012-05-02 23:29:47 +0800933 synchronized (mAutoFocusCallbackLock) {
James Dong248ba232012-04-28 21:30:46 -0700934 mAutoFocusCallback = cb;
James Dong248ba232012-04-28 21:30:46 -0700935 }
Wu-cheng Lif05c1d62012-05-02 23:29:47 +0800936 native_autoFocus();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800937 }
938 private native final void native_autoFocus();
939
940 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700941 * Cancels any auto-focus function in progress.
942 * Whether or not auto-focus is currently in progress,
943 * this function will return the focus position to the default.
Chih-Chung Chang244f8c22009-09-15 14:51:56 +0800944 * If the camera does not support auto-focus, this is a no-op.
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700945 *
946 * @see #autoFocus(Camera.AutoFocusCallback)
Chih-Chung Chang244f8c22009-09-15 14:51:56 +0800947 */
948 public final void cancelAutoFocus()
949 {
Wu-cheng Lif05c1d62012-05-02 23:29:47 +0800950 synchronized (mAutoFocusCallbackLock) {
James Dong248ba232012-04-28 21:30:46 -0700951 mAutoFocusCallback = null;
James Dong248ba232012-04-28 21:30:46 -0700952 }
Wu-cheng Lif05c1d62012-05-02 23:29:47 +0800953 native_cancelAutoFocus();
954 // CAMERA_MSG_FOCUS should be removed here because the following
955 // scenario can happen:
956 // - An application uses the same thread for autoFocus, cancelAutoFocus
957 // and looper thread.
958 // - The application calls autoFocus.
959 // - HAL sends CAMERA_MSG_FOCUS, which enters the looper message queue.
960 // Before event handler's handleMessage() is invoked, the application
961 // calls cancelAutoFocus and autoFocus.
962 // - The application gets the old CAMERA_MSG_FOCUS and thinks autofocus
963 // has been completed. But in fact it is not.
964 //
965 // As documented in the beginning of the file, apps should not use
966 // multiple threads to call autoFocus and cancelAutoFocus at the same
967 // time. It is HAL's responsibility not to send a CAMERA_MSG_FOCUS
968 // message after native_cancelAutoFocus is called.
969 mEventHandler.removeMessages(CAMERA_MSG_FOCUS);
Chih-Chung Chang244f8c22009-09-15 14:51:56 +0800970 }
971 private native final void native_cancelAutoFocus();
972
973 /**
Wu-cheng Li9d062cf2011-11-14 20:30:14 +0800974 * Callback interface used to notify on auto focus start and stop.
975 *
Wu-cheng Li65745392012-04-12 18:07:16 +0800976 * <p>This is only supported in continuous autofocus modes -- {@link
977 * Parameters#FOCUS_MODE_CONTINUOUS_VIDEO} and {@link
978 * Parameters#FOCUS_MODE_CONTINUOUS_PICTURE}. Applications can show
979 * autofocus animation based on this.</p>
Wu-cheng Li9d062cf2011-11-14 20:30:14 +0800980 */
981 public interface AutoFocusMoveCallback
982 {
983 /**
984 * Called when the camera auto focus starts or stops.
985 *
986 * @param start true if focus starts to move, false if focus stops to move
Wu-cheng Li65745392012-04-12 18:07:16 +0800987 * @param camera the Camera service object
Wu-cheng Li9d062cf2011-11-14 20:30:14 +0800988 */
989 void onAutoFocusMoving(boolean start, Camera camera);
990 }
991
992 /**
993 * Sets camera auto-focus move callback.
994 *
995 * @param cb the callback to run
Wu-cheng Li9d062cf2011-11-14 20:30:14 +0800996 */
997 public void setAutoFocusMoveCallback(AutoFocusMoveCallback cb) {
998 mAutoFocusMoveCallback = cb;
999 enableFocusMoveCallback((mAutoFocusMoveCallback != null) ? 1 : 0);
1000 }
1001
1002 private native void enableFocusMoveCallback(int enable);
1003
1004 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -07001005 * Callback interface used to signal the moment of actual image capture.
1006 *
1007 * @see #takePicture(ShutterCallback, PictureCallback, PictureCallback, PictureCallback)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001008 */
1009 public interface ShutterCallback
1010 {
1011 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -07001012 * Called as near as possible to the moment when a photo is captured
1013 * from the sensor. This is a good opportunity to play a shutter sound
1014 * or give other feedback of camera operation. This may be some time
1015 * after the photo was triggered, but some time before the actual data
1016 * is available.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001017 */
1018 void onShutter();
1019 }
1020
1021 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -07001022 * Callback interface used to supply image data from a photo capture.
1023 *
1024 * @see #takePicture(ShutterCallback, PictureCallback, PictureCallback, PictureCallback)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001025 */
1026 public interface PictureCallback {
1027 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -07001028 * Called when image data is available after a picture is taken.
1029 * The format of the data depends on the context of the callback
1030 * and {@link Camera.Parameters} settings.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001031 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001032 * @param data a byte array of the picture data
1033 * @param camera the Camera service object
1034 */
1035 void onPictureTaken(byte[] data, Camera camera);
1036 };
1037
1038 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -07001039 * Equivalent to takePicture(shutter, raw, null, jpeg).
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001040 *
Dan Egnorbfcbeff2010-07-12 15:12:54 -07001041 * @see #takePicture(ShutterCallback, PictureCallback, PictureCallback, PictureCallback)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001042 */
1043 public final void takePicture(ShutterCallback shutter, PictureCallback raw,
1044 PictureCallback jpeg) {
Dave Sparkse8b26e12009-07-14 10:35:40 -07001045 takePicture(shutter, raw, null, jpeg);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001046 }
James Donge00cab72011-02-17 16:38:06 -08001047 private native final void native_takePicture(int msgType);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001048
Dave Sparkse8b26e12009-07-14 10:35:40 -07001049 /**
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001050 * Triggers an asynchronous image capture. The camera service will initiate
1051 * a series of callbacks to the application as the image capture progresses.
1052 * The shutter callback occurs after the image is captured. This can be used
1053 * to trigger a sound to let the user know that image has been captured. The
1054 * raw callback occurs when the raw image data is available (NOTE: the data
James Donge00cab72011-02-17 16:38:06 -08001055 * will be null if there is no raw image callback buffer available or the
1056 * raw image callback buffer is not large enough to hold the raw image).
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001057 * The postview callback occurs when a scaled, fully processed postview
1058 * image is available (NOTE: not all hardware supports this). The jpeg
1059 * callback occurs when the compressed image is available. If the
1060 * application does not need a particular callback, a null can be passed
1061 * instead of a callback method.
Dave Sparkse8b26e12009-07-14 10:35:40 -07001062 *
Dan Egnorbfcbeff2010-07-12 15:12:54 -07001063 * <p>This method is only valid when preview is active (after
1064 * {@link #startPreview()}). Preview will be stopped after the image is
1065 * taken; callers must call {@link #startPreview()} again if they want to
Wu-cheng Li42419ce2011-06-01 17:22:24 +08001066 * re-start preview or take more pictures. This should not be called between
1067 * {@link android.media.MediaRecorder#start()} and
1068 * {@link android.media.MediaRecorder#stop()}.
Wu-cheng Li40057ce2009-12-02 18:57:29 +08001069 *
Dan Egnorbfcbeff2010-07-12 15:12:54 -07001070 * <p>After calling this method, you must not call {@link #startPreview()}
1071 * or take another picture until the JPEG callback has returned.
1072 *
1073 * @param shutter the callback for image capture moment, or null
1074 * @param raw the callback for raw (uncompressed) image data, or null
Dave Sparkse8b26e12009-07-14 10:35:40 -07001075 * @param postview callback with postview image data, may be null
Dan Egnorbfcbeff2010-07-12 15:12:54 -07001076 * @param jpeg the callback for JPEG image data, or null
Dave Sparkse8b26e12009-07-14 10:35:40 -07001077 */
1078 public final void takePicture(ShutterCallback shutter, PictureCallback raw,
1079 PictureCallback postview, PictureCallback jpeg) {
1080 mShutterCallback = shutter;
1081 mRawImageCallback = raw;
1082 mPostviewCallback = postview;
1083 mJpegCallback = jpeg;
James Donge00cab72011-02-17 16:38:06 -08001084
1085 // If callback is not set, do not send me callbacks.
1086 int msgType = 0;
1087 if (mShutterCallback != null) {
1088 msgType |= CAMERA_MSG_SHUTTER;
1089 }
1090 if (mRawImageCallback != null) {
1091 msgType |= CAMERA_MSG_RAW_IMAGE;
1092 }
1093 if (mPostviewCallback != null) {
1094 msgType |= CAMERA_MSG_POSTVIEW_FRAME;
1095 }
1096 if (mJpegCallback != null) {
1097 msgType |= CAMERA_MSG_COMPRESSED_IMAGE;
1098 }
1099
1100 native_takePicture(msgType);
Wu-cheng Lie9c6c9c2012-05-29 16:47:44 +08001101 mFaceDetectionRunning = false;
Dave Sparkse8b26e12009-07-14 10:35:40 -07001102 }
1103
1104 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -07001105 * Zooms to the requested value smoothly. The driver will notify {@link
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08001106 * OnZoomChangeListener} of the zoom value and whether zoom is stopped at
1107 * the time. For example, suppose the current zoom is 0 and startSmoothZoom
Dan Egnorbfcbeff2010-07-12 15:12:54 -07001108 * is called with value 3. The
1109 * {@link Camera.OnZoomChangeListener#onZoomChange(int, boolean, Camera)}
1110 * method will be called three times with zoom values 1, 2, and 3.
1111 * Applications can call {@link #stopSmoothZoom} to stop the zoom earlier.
1112 * Applications should not call startSmoothZoom again or change the zoom
1113 * value before zoom stops. If the supplied zoom value equals to the current
1114 * zoom value, no zoom callback will be generated. This method is supported
1115 * if {@link android.hardware.Camera.Parameters#isSmoothZoomSupported}
1116 * returns true.
Wu-cheng Li36f68b82009-09-28 16:14:58 -07001117 *
1118 * @param value zoom value. The valid range is 0 to {@link
1119 * android.hardware.Camera.Parameters#getMaxZoom}.
Wu-cheng Li0ca25192010-03-29 16:21:12 +08001120 * @throws IllegalArgumentException if the zoom value is invalid.
1121 * @throws RuntimeException if the method fails.
Dan Egnorbfcbeff2010-07-12 15:12:54 -07001122 * @see #setZoomChangeListener(OnZoomChangeListener)
Wu-cheng Li36f68b82009-09-28 16:14:58 -07001123 */
1124 public native final void startSmoothZoom(int value);
1125
1126 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -07001127 * Stops the smooth zoom. Applications should wait for the {@link
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08001128 * OnZoomChangeListener} to know when the zoom is actually stopped. This
1129 * method is supported if {@link
Wu-cheng Li8cbb8f52010-02-28 23:19:55 -08001130 * android.hardware.Camera.Parameters#isSmoothZoomSupported} is true.
Wu-cheng Li0ca25192010-03-29 16:21:12 +08001131 *
1132 * @throws RuntimeException if the method fails.
Wu-cheng Li36f68b82009-09-28 16:14:58 -07001133 */
1134 public native final void stopSmoothZoom();
1135
1136 /**
Wu-cheng Li2fe6fca2010-10-15 14:42:23 +08001137 * Set the clockwise rotation of preview display in degrees. This affects
1138 * the preview frames and the picture displayed after snapshot. This method
1139 * is useful for portrait mode applications. Note that preview display of
Wu-cheng Lib982fb42010-10-19 17:19:09 +08001140 * front-facing cameras is flipped horizontally before the rotation, that
1141 * is, the image is reflected along the central vertical axis of the camera
1142 * sensor. So the users can see themselves as looking into a mirror.
Chih-Chung Changd1d77062010-01-22 17:49:48 -08001143 *
Brad Fitzpatrick69ea4e12011-01-05 11:13:40 -08001144 * <p>This does not affect the order of byte array passed in {@link
Wu-cheng Li2fe6fca2010-10-15 14:42:23 +08001145 * PreviewCallback#onPreviewFrame}, JPEG pictures, or recorded videos. This
1146 * method is not allowed to be called during preview.
Chih-Chung Changd1d77062010-01-22 17:49:48 -08001147 *
Brad Fitzpatrick69ea4e12011-01-05 11:13:40 -08001148 * <p>If you want to make the camera image show in the same orientation as
1149 * the display, you can use the following code.
Chih-Chung Changb8bb78f2010-06-10 13:32:16 +08001150 * <pre>
Chih-Chung Chang724c5222010-06-14 18:57:15 +08001151 * public static void setCameraDisplayOrientation(Activity activity,
1152 * int cameraId, android.hardware.Camera camera) {
1153 * android.hardware.Camera.CameraInfo info =
1154 * new android.hardware.Camera.CameraInfo();
1155 * android.hardware.Camera.getCameraInfo(cameraId, info);
1156 * int rotation = activity.getWindowManager().getDefaultDisplay()
1157 * .getRotation();
1158 * int degrees = 0;
1159 * switch (rotation) {
1160 * case Surface.ROTATION_0: degrees = 0; break;
1161 * case Surface.ROTATION_90: degrees = 90; break;
1162 * case Surface.ROTATION_180: degrees = 180; break;
1163 * case Surface.ROTATION_270: degrees = 270; break;
1164 * }
Chih-Chung Changb8bb78f2010-06-10 13:32:16 +08001165 *
Wu-cheng Li2fe6fca2010-10-15 14:42:23 +08001166 * int result;
1167 * if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
1168 * result = (info.orientation + degrees) % 360;
1169 * result = (360 - result) % 360; // compensate the mirror
1170 * } else { // back-facing
1171 * result = (info.orientation - degrees + 360) % 360;
1172 * }
Chih-Chung Chang724c5222010-06-14 18:57:15 +08001173 * camera.setDisplayOrientation(result);
1174 * }
Chih-Chung Changb8bb78f2010-06-10 13:32:16 +08001175 * </pre>
Wu-cheng Lid3033622011-10-07 13:13:54 +08001176 *
1177 * <p>Starting from API level 14, this method can be called when preview is
1178 * active.
1179 *
Chih-Chung Changd1d77062010-01-22 17:49:48 -08001180 * @param degrees the angle that the picture will be rotated clockwise.
Chih-Chung Change7bd22a2010-01-27 10:24:42 -08001181 * Valid values are 0, 90, 180, and 270. The starting
1182 * position is 0 (landscape).
Wu-cheng Li2fe6fca2010-10-15 14:42:23 +08001183 * @see #setPreviewDisplay(SurfaceHolder)
Chih-Chung Changd1d77062010-01-22 17:49:48 -08001184 */
1185 public native final void setDisplayOrientation(int degrees);
1186
1187 /**
Eino-Ville Talvala487acdf2012-09-24 11:30:24 -07001188 * <p>Enable or disable the default shutter sound when taking a picture.</p>
Eino-Ville Talvala69fe5272012-09-07 12:26:40 -07001189 *
Eino-Ville Talvala487acdf2012-09-24 11:30:24 -07001190 * <p>By default, the camera plays the system-defined camera shutter sound
1191 * when {@link #takePicture} is called. Using this method, the shutter sound
1192 * can be disabled. It is strongly recommended that an alternative shutter
1193 * sound is played in the {@link ShutterCallback} when the system shutter
1194 * sound is disabled.</p>
Eino-Ville Talvala69fe5272012-09-07 12:26:40 -07001195 *
Eino-Ville Talvala487acdf2012-09-24 11:30:24 -07001196 * <p>Note that devices may not always allow disabling the camera shutter
1197 * sound. If the shutter sound state cannot be set to the desired value,
1198 * this method will return false. {@link CameraInfo#canDisableShutterSound}
1199 * can be used to determine whether the device will allow the shutter sound
1200 * to be disabled.</p>
Eino-Ville Talvala69fe5272012-09-07 12:26:40 -07001201 *
1202 * @param enabled whether the camera should play the system shutter sound
1203 * when {@link #takePicture takePicture} is called.
Eino-Ville Talvala487acdf2012-09-24 11:30:24 -07001204 * @return {@code true} if the shutter sound state was successfully
1205 * changed. {@code false} if the shutter sound state could not be
1206 * changed. {@code true} is also returned if shutter sound playback
1207 * is already set to the requested state.
Eino-Ville Talvala69fe5272012-09-07 12:26:40 -07001208 * @see #takePicture
Eino-Ville Talvala487acdf2012-09-24 11:30:24 -07001209 * @see CameraInfo#canDisableShutterSound
Eino-Ville Talvala69fe5272012-09-07 12:26:40 -07001210 * @see ShutterCallback
Eino-Ville Talvala69fe5272012-09-07 12:26:40 -07001211 */
Eino-Ville Talvala4f8e5ce2012-10-08 18:16:35 -07001212 public final boolean enableShutterSound(boolean enabled) {
1213 if (!enabled) {
1214 IBinder b = ServiceManager.getService(Context.AUDIO_SERVICE);
1215 IAudioService audioService = IAudioService.Stub.asInterface(b);
1216 try {
1217 if (audioService.isCameraSoundForced()) return false;
1218 } catch (RemoteException e) {
1219 Log.e(TAG, "Audio service is unavailable for queries");
1220 }
1221 }
1222 return _enableShutterSound(enabled);
1223 }
1224
1225 private native final boolean _enableShutterSound(boolean enabled);
Eino-Ville Talvala69fe5272012-09-07 12:26:40 -07001226
1227 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -07001228 * Callback interface for zoom changes during a smooth zoom operation.
1229 *
1230 * @see #setZoomChangeListener(OnZoomChangeListener)
1231 * @see #startSmoothZoom(int)
Dave Sparkse8b26e12009-07-14 10:35:40 -07001232 */
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08001233 public interface OnZoomChangeListener
Dave Sparkse8b26e12009-07-14 10:35:40 -07001234 {
1235 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -07001236 * Called when the zoom value has changed during a smooth zoom.
Wu-cheng Li36f68b82009-09-28 16:14:58 -07001237 *
1238 * @param zoomValue the current zoom value. In smooth zoom mode, camera
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08001239 * calls this for every new zoom value.
Wu-cheng Li36f68b82009-09-28 16:14:58 -07001240 * @param stopped whether smooth zoom is stopped. If the value is true,
1241 * this is the last zoom update for the application.
Dave Sparkse8b26e12009-07-14 10:35:40 -07001242 * @param camera the Camera service object
1243 */
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08001244 void onZoomChange(int zoomValue, boolean stopped, Camera camera);
Dave Sparkse8b26e12009-07-14 10:35:40 -07001245 };
1246
1247 /**
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08001248 * Registers a listener to be notified when the zoom value is updated by the
Wu-cheng Li36f68b82009-09-28 16:14:58 -07001249 * camera driver during smooth zoom.
Wu-cheng Li8cbb8f52010-02-28 23:19:55 -08001250 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08001251 * @param listener the listener to notify
Wu-cheng Li8cbb8f52010-02-28 23:19:55 -08001252 * @see #startSmoothZoom(int)
Dave Sparkse8b26e12009-07-14 10:35:40 -07001253 */
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08001254 public final void setZoomChangeListener(OnZoomChangeListener listener)
Dave Sparkse8b26e12009-07-14 10:35:40 -07001255 {
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08001256 mZoomListener = listener;
Dave Sparkse8b26e12009-07-14 10:35:40 -07001257 }
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001258
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08001259 /**
1260 * Callback interface for face detected in the preview frame.
1261 *
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08001262 */
1263 public interface FaceDetectionListener
1264 {
1265 /**
1266 * Notify the listener of the detected faces in the preview frame.
1267 *
Wu-cheng Li53b30912011-10-12 19:43:51 +08001268 * @param faces The detected faces in a list
Joe Fernandez464cb212011-10-04 16:56:47 -07001269 * @param camera The {@link Camera} service object
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08001270 */
Wu-cheng Lif0d6a482011-07-28 05:30:59 +08001271 void onFaceDetection(Face[] faces, Camera camera);
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08001272 }
1273
1274 /**
Wu-cheng Lic0c683b2011-08-04 00:11:00 +08001275 * Registers a listener to be notified about the faces detected in the
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08001276 * preview frame.
1277 *
1278 * @param listener the listener to notify
Wu-cheng Lic0c683b2011-08-04 00:11:00 +08001279 * @see #startFaceDetection()
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08001280 */
1281 public final void setFaceDetectionListener(FaceDetectionListener listener)
1282 {
1283 mFaceListener = listener;
1284 }
1285
1286 /**
Wu-cheng Lic0c683b2011-08-04 00:11:00 +08001287 * Starts the face detection. This should be called after preview is started.
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08001288 * The camera will notify {@link FaceDetectionListener} of the detected
1289 * faces in the preview frame. The detected faces may be the same as the
1290 * previous ones. Applications should call {@link #stopFaceDetection} to
1291 * stop the face detection. This method is supported if {@link
Wu-cheng Lic0c683b2011-08-04 00:11:00 +08001292 * Parameters#getMaxNumDetectedFaces()} returns a number larger than 0.
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08001293 * If the face detection has started, apps should not call this again.
1294 *
Wu-cheng Li8c136702011-08-12 20:25:00 +08001295 * <p>When the face detection is running, {@link Parameters#setWhiteBalance(String)},
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08001296 * {@link Parameters#setFocusAreas(List)}, and {@link Parameters#setMeteringAreas(List)}
Wu-cheng Li8c136702011-08-12 20:25:00 +08001297 * have no effect. The camera uses the detected faces to do auto-white balance,
1298 * auto exposure, and autofocus.
1299 *
1300 * <p>If the apps call {@link #autoFocus(AutoFocusCallback)}, the camera
1301 * will stop sending face callbacks. The last face callback indicates the
1302 * areas used to do autofocus. After focus completes, face detection will
1303 * resume sending face callbacks. If the apps call {@link
1304 * #cancelAutoFocus()}, the face callbacks will also resume.</p>
1305 *
1306 * <p>After calling {@link #takePicture(Camera.ShutterCallback, Camera.PictureCallback,
1307 * Camera.PictureCallback)} or {@link #stopPreview()}, and then resuming
1308 * preview with {@link #startPreview()}, the apps should call this method
1309 * again to resume face detection.</p>
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08001310 *
Wu-cheng Lic0c683b2011-08-04 00:11:00 +08001311 * @throws IllegalArgumentException if the face detection is unsupported.
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08001312 * @throws RuntimeException if the method fails or the face detection is
1313 * already running.
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08001314 * @see FaceDetectionListener
1315 * @see #stopFaceDetection()
Wu-cheng Lic0c683b2011-08-04 00:11:00 +08001316 * @see Parameters#getMaxNumDetectedFaces()
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08001317 */
Wu-cheng Lic0c683b2011-08-04 00:11:00 +08001318 public final void startFaceDetection() {
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08001319 if (mFaceDetectionRunning) {
1320 throw new RuntimeException("Face detection is already running");
1321 }
Wu-cheng Lic0c683b2011-08-04 00:11:00 +08001322 _startFaceDetection(CAMERA_FACE_DETECTION_HW);
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08001323 mFaceDetectionRunning = true;
1324 }
1325
1326 /**
Wu-cheng Lic0c683b2011-08-04 00:11:00 +08001327 * Stops the face detection.
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08001328 *
Joe Fernandez464cb212011-10-04 16:56:47 -07001329 * @see #startFaceDetection()
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08001330 */
1331 public final void stopFaceDetection() {
1332 _stopFaceDetection();
1333 mFaceDetectionRunning = false;
1334 }
1335
1336 private native final void _startFaceDetection(int type);
1337 private native final void _stopFaceDetection();
1338
1339 /**
Joe Fernandez464cb212011-10-04 16:56:47 -07001340 * Information about a face identified through camera face detection.
Wu-cheng Li53b30912011-10-12 19:43:51 +08001341 *
Joe Fernandez464cb212011-10-04 16:56:47 -07001342 * <p>When face detection is used with a camera, the {@link FaceDetectionListener} returns a
1343 * list of face objects for use in focusing and metering.</p>
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08001344 *
Joe Fernandez464cb212011-10-04 16:56:47 -07001345 * @see FaceDetectionListener
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08001346 */
Wu-cheng Lif0d6a482011-07-28 05:30:59 +08001347 public static class Face {
Wu-cheng Lic0c683b2011-08-04 00:11:00 +08001348 /**
1349 * Create an empty face.
1350 */
Wu-cheng Libb1e2752011-07-30 05:00:37 +08001351 public Face() {
1352 }
1353
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08001354 /**
1355 * Bounds of the face. (-1000, -1000) represents the top-left of the
1356 * camera field of view, and (1000, 1000) represents the bottom-right of
Wu-cheng Lic0c683b2011-08-04 00:11:00 +08001357 * the field of view. For example, suppose the size of the viewfinder UI
1358 * is 800x480. The rect passed from the driver is (-1000, -1000, 0, 0).
Wu-cheng Li8c136702011-08-12 20:25:00 +08001359 * The corresponding viewfinder rect should be (0, 0, 400, 240). It is
1360 * guaranteed left < right and top < bottom. The coordinates can be
1361 * smaller than -1000 or bigger than 1000. But at least one vertex will
1362 * be within (-1000, -1000) and (1000, 1000).
Wu-cheng Lif0d6a482011-07-28 05:30:59 +08001363 *
1364 * <p>The direction is relative to the sensor orientation, that is, what
1365 * the sensor sees. The direction is not affected by the rotation or
Wu-cheng Li8c136702011-08-12 20:25:00 +08001366 * mirroring of {@link #setDisplayOrientation(int)}. The face bounding
1367 * rectangle does not provide any information about face orientation.</p>
1368 *
1369 * <p>Here is the matrix to convert driver coordinates to View coordinates
1370 * in pixels.</p>
1371 * <pre>
1372 * Matrix matrix = new Matrix();
1373 * CameraInfo info = CameraHolder.instance().getCameraInfo()[cameraId];
1374 * // Need mirror for front camera.
1375 * boolean mirror = (info.facing == CameraInfo.CAMERA_FACING_FRONT);
1376 * matrix.setScale(mirror ? -1 : 1, 1);
1377 * // This is the value for android.hardware.Camera.setDisplayOrientation.
1378 * matrix.postRotate(displayOrientation);
1379 * // Camera driver coordinates range from (-1000, -1000) to (1000, 1000).
1380 * // UI coordinates range from (0, 0) to (width, height).
1381 * matrix.postScale(view.getWidth() / 2000f, view.getHeight() / 2000f);
1382 * matrix.postTranslate(view.getWidth() / 2f, view.getHeight() / 2f);
1383 * </pre>
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08001384 *
Joe Fernandez464cb212011-10-04 16:56:47 -07001385 * @see #startFaceDetection()
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08001386 */
Wu-cheng Libb1e2752011-07-30 05:00:37 +08001387 public Rect rect;
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08001388
1389 /**
Eino-Ville Talvala8df3b2b2012-09-15 14:30:12 -07001390 * <p>The confidence level for the detection of the face. The range is 1 to
1391 * 100. 100 is the highest confidence.</p>
1392 *
1393 * <p>Depending on the device, even very low-confidence faces may be
1394 * listed, so applications should filter out faces with low confidence,
1395 * depending on the use case. For a typical point-and-shoot camera
1396 * application that wishes to display rectangles around detected faces,
1397 * filtering out faces with confidence less than 50 is recommended.</p>
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08001398 *
Joe Fernandez464cb212011-10-04 16:56:47 -07001399 * @see #startFaceDetection()
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08001400 */
Wu-cheng Libb1e2752011-07-30 05:00:37 +08001401 public int score;
Wei Huad52b3082011-08-19 13:01:51 -07001402
1403 /**
1404 * An unique id per face while the face is visible to the tracker. If
1405 * the face leaves the field-of-view and comes back, it will get a new
1406 * id. This is an optional field, may not be supported on all devices.
1407 * If not supported, id will always be set to -1. The optional fields
1408 * are supported as a set. Either they are all valid, or none of them
1409 * are.
1410 */
1411 public int id = -1;
1412
1413 /**
1414 * The coordinates of the center of the left eye. The coordinates are in
1415 * the same space as the ones for {@link #rect}. This is an optional
1416 * field, may not be supported on all devices. If not supported, the
1417 * value will always be set to null. The optional fields are supported
1418 * as a set. Either they are all valid, or none of them are.
1419 */
1420 public Point leftEye = null;
1421
1422 /**
1423 * The coordinates of the center of the right eye. The coordinates are
1424 * in the same space as the ones for {@link #rect}.This is an optional
1425 * field, may not be supported on all devices. If not supported, the
1426 * value will always be set to null. The optional fields are supported
1427 * as a set. Either they are all valid, or none of them are.
1428 */
1429 public Point rightEye = null;
1430
1431 /**
1432 * The coordinates of the center of the mouth. The coordinates are in
1433 * the same space as the ones for {@link #rect}. This is an optional
1434 * field, may not be supported on all devices. If not supported, the
1435 * value will always be set to null. The optional fields are supported
1436 * as a set. Either they are all valid, or none of them are.
1437 */
1438 public Point mouth = null;
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08001439 }
1440
Dan Egnorbfcbeff2010-07-12 15:12:54 -07001441 // Error codes match the enum in include/ui/Camera.h
1442
1443 /**
1444 * Unspecified camera error.
1445 * @see Camera.ErrorCallback
1446 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001447 public static final int CAMERA_ERROR_UNKNOWN = 1;
Dan Egnorbfcbeff2010-07-12 15:12:54 -07001448
1449 /**
1450 * Media server died. In this case, the application must release the
1451 * Camera object and instantiate a new one.
1452 * @see Camera.ErrorCallback
1453 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001454 public static final int CAMERA_ERROR_SERVER_DIED = 100;
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001455
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001456 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -07001457 * Callback interface for camera error notification.
1458 *
1459 * @see #setErrorCallback(ErrorCallback)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001460 */
1461 public interface ErrorCallback
1462 {
1463 /**
1464 * Callback for camera errors.
1465 * @param error error code:
1466 * <ul>
1467 * <li>{@link #CAMERA_ERROR_UNKNOWN}
1468 * <li>{@link #CAMERA_ERROR_SERVER_DIED}
1469 * </ul>
1470 * @param camera the Camera service object
1471 */
1472 void onError(int error, Camera camera);
1473 };
1474
1475 /**
1476 * Registers a callback to be invoked when an error occurs.
Dan Egnorbfcbeff2010-07-12 15:12:54 -07001477 * @param cb The callback to run
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001478 */
1479 public final void setErrorCallback(ErrorCallback cb)
1480 {
1481 mErrorCallback = cb;
1482 }
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001483
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001484 private native final void native_setParameters(String params);
1485 private native final String native_getParameters();
1486
1487 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -07001488 * Changes the settings for this Camera service.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001489 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001490 * @param params the Parameters to use for this Camera service
Wu-cheng Li99a3f3e2010-11-19 15:56:16 +08001491 * @throws RuntimeException if any parameter is invalid or not supported.
Dan Egnorbfcbeff2010-07-12 15:12:54 -07001492 * @see #getParameters()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001493 */
1494 public void setParameters(Parameters params) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001495 native_setParameters(params.flatten());
1496 }
1497
1498 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -07001499 * Returns the current settings for this Camera service.
1500 * If modifications are made to the returned Parameters, they must be passed
1501 * to {@link #setParameters(Camera.Parameters)} to take effect.
1502 *
1503 * @see #setParameters(Camera.Parameters)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001504 */
1505 public Parameters getParameters() {
1506 Parameters p = new Parameters();
1507 String s = native_getParameters();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001508 p.unflatten(s);
1509 return p;
1510 }
1511
1512 /**
Wu-cheng Li1c04a332011-11-22 18:21:18 +08001513 * Returns an empty {@link Parameters} for testing purpose.
1514 *
Ken Wakasaf76a50c2012-03-09 19:56:35 +09001515 * @return a Parameter object.
Wu-cheng Li1c04a332011-11-22 18:21:18 +08001516 *
1517 * @hide
1518 */
1519 public static Parameters getEmptyParameters() {
1520 Camera camera = new Camera();
1521 return camera.new Parameters();
1522 }
1523
1524 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -07001525 * Image size (width and height dimensions).
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001526 */
1527 public class Size {
1528 /**
1529 * Sets the dimensions for pictures.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001530 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001531 * @param w the photo width (pixels)
1532 * @param h the photo height (pixels)
1533 */
1534 public Size(int w, int h) {
1535 width = w;
1536 height = h;
1537 }
Wu-cheng Li4c4300c2010-01-23 15:45:39 +08001538 /**
1539 * Compares {@code obj} to this size.
1540 *
1541 * @param obj the object to compare this size with.
1542 * @return {@code true} if the width and height of {@code obj} is the
1543 * same as those of this size. {@code false} otherwise.
1544 */
1545 @Override
1546 public boolean equals(Object obj) {
1547 if (!(obj instanceof Size)) {
1548 return false;
1549 }
1550 Size s = (Size) obj;
1551 return width == s.width && height == s.height;
1552 }
1553 @Override
1554 public int hashCode() {
1555 return width * 32713 + height;
1556 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001557 /** width of the picture */
1558 public int width;
1559 /** height of the picture */
1560 public int height;
1561 };
1562
1563 /**
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07001564 * <p>The Area class is used for choosing specific metering and focus areas for
1565 * the camera to use when calculating auto-exposure, auto-white balance, and
1566 * auto-focus.</p>
1567 *
1568 * <p>To find out how many simultaneous areas a given camera supports, use
1569 * {@link Parameters#getMaxNumMeteringAreas()} and
1570 * {@link Parameters#getMaxNumFocusAreas()}. If metering or focusing area
1571 * selection is unsupported, these methods will return 0.</p>
1572 *
1573 * <p>Each Area consists of a rectangle specifying its bounds, and a weight
1574 * that determines its importance. The bounds are relative to the camera's
1575 * current field of view. The coordinates are mapped so that (-1000, -1000)
1576 * is always the top-left corner of the current field of view, and (1000,
1577 * 1000) is always the bottom-right corner of the current field of
1578 * view. Setting Areas with bounds outside that range is not allowed. Areas
1579 * with zero or negative width or height are not allowed.</p>
1580 *
1581 * <p>The weight must range from 1 to 1000, and represents a weight for
1582 * every pixel in the area. This means that a large metering area with
1583 * the same weight as a smaller area will have more effect in the
1584 * metering result. Metering areas can overlap and the driver
1585 * will add the weights in the overlap region.</p>
Wu-cheng Li30771b72011-04-02 06:19:46 +08001586 *
Wu-cheng Libde61a52011-06-07 18:23:14 +08001587 * @see Parameters#setFocusAreas(List)
1588 * @see Parameters#getFocusAreas()
1589 * @see Parameters#getMaxNumFocusAreas()
1590 * @see Parameters#setMeteringAreas(List)
1591 * @see Parameters#getMeteringAreas()
1592 * @see Parameters#getMaxNumMeteringAreas()
Wu-cheng Li30771b72011-04-02 06:19:46 +08001593 */
1594 public static class Area {
1595 /**
1596 * Create an area with specified rectangle and weight.
1597 *
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07001598 * @param rect the bounds of the area.
1599 * @param weight the weight of the area.
Wu-cheng Li30771b72011-04-02 06:19:46 +08001600 */
1601 public Area(Rect rect, int weight) {
1602 this.rect = rect;
1603 this.weight = weight;
1604 }
1605 /**
1606 * Compares {@code obj} to this area.
1607 *
1608 * @param obj the object to compare this area with.
1609 * @return {@code true} if the rectangle and weight of {@code obj} is
1610 * the same as those of this area. {@code false} otherwise.
1611 */
1612 @Override
1613 public boolean equals(Object obj) {
1614 if (!(obj instanceof Area)) {
1615 return false;
1616 }
1617 Area a = (Area) obj;
1618 if (rect == null) {
1619 if (a.rect != null) return false;
1620 } else {
1621 if (!rect.equals(a.rect)) return false;
1622 }
1623 return weight == a.weight;
1624 }
1625
Wu-cheng Libde61a52011-06-07 18:23:14 +08001626 /**
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07001627 * Bounds of the area. (-1000, -1000) represents the top-left of the
1628 * camera field of view, and (1000, 1000) represents the bottom-right of
1629 * the field of view. Setting bounds outside that range is not
1630 * allowed. Bounds with zero or negative width or height are not
1631 * allowed.
Wu-cheng Libde61a52011-06-07 18:23:14 +08001632 *
1633 * @see Parameters#getFocusAreas()
1634 * @see Parameters#getMeteringAreas()
1635 */
Wu-cheng Li30771b72011-04-02 06:19:46 +08001636 public Rect rect;
1637
Wu-cheng Libde61a52011-06-07 18:23:14 +08001638 /**
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07001639 * Weight of the area. The weight must range from 1 to 1000, and
1640 * represents a weight for every pixel in the area. This means that a
1641 * large metering area with the same weight as a smaller area will have
1642 * more effect in the metering result. Metering areas can overlap and
1643 * the driver will add the weights in the overlap region.
Wu-cheng Libde61a52011-06-07 18:23:14 +08001644 *
1645 * @see Parameters#getFocusAreas()
1646 * @see Parameters#getMeteringAreas()
1647 */
Wu-cheng Li30771b72011-04-02 06:19:46 +08001648 public int weight;
Wu-cheng Libde61a52011-06-07 18:23:14 +08001649 }
Wu-cheng Li30771b72011-04-02 06:19:46 +08001650
1651 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -07001652 * Camera service settings.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001653 *
1654 * <p>To make camera parameters take effect, applications have to call
Dan Egnorbfcbeff2010-07-12 15:12:54 -07001655 * {@link Camera#setParameters(Camera.Parameters)}. For example, after
1656 * {@link Camera.Parameters#setWhiteBalance} is called, white balance is not
1657 * actually changed until {@link Camera#setParameters(Camera.Parameters)}
1658 * is called with the changed parameters object.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001659 *
1660 * <p>Different devices may have different camera capabilities, such as
1661 * picture size or flash modes. The application should query the camera
1662 * capabilities before setting parameters. For example, the application
Dan Egnorbfcbeff2010-07-12 15:12:54 -07001663 * should call {@link Camera.Parameters#getSupportedColorEffects()} before
1664 * calling {@link Camera.Parameters#setColorEffect(String)}. If the
1665 * camera does not support color effects,
1666 * {@link Camera.Parameters#getSupportedColorEffects()} will return null.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001667 */
1668 public class Parameters {
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001669 // Parameter keys to communicate with the camera driver.
1670 private static final String KEY_PREVIEW_SIZE = "preview-size";
1671 private static final String KEY_PREVIEW_FORMAT = "preview-format";
1672 private static final String KEY_PREVIEW_FRAME_RATE = "preview-frame-rate";
Wu-cheng Li454630f2010-08-11 16:48:05 -07001673 private static final String KEY_PREVIEW_FPS_RANGE = "preview-fps-range";
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001674 private static final String KEY_PICTURE_SIZE = "picture-size";
1675 private static final String KEY_PICTURE_FORMAT = "picture-format";
Wu-cheng Li4c4300c2010-01-23 15:45:39 +08001676 private static final String KEY_JPEG_THUMBNAIL_SIZE = "jpeg-thumbnail-size";
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001677 private static final String KEY_JPEG_THUMBNAIL_WIDTH = "jpeg-thumbnail-width";
1678 private static final String KEY_JPEG_THUMBNAIL_HEIGHT = "jpeg-thumbnail-height";
1679 private static final String KEY_JPEG_THUMBNAIL_QUALITY = "jpeg-thumbnail-quality";
1680 private static final String KEY_JPEG_QUALITY = "jpeg-quality";
1681 private static final String KEY_ROTATION = "rotation";
1682 private static final String KEY_GPS_LATITUDE = "gps-latitude";
1683 private static final String KEY_GPS_LONGITUDE = "gps-longitude";
1684 private static final String KEY_GPS_ALTITUDE = "gps-altitude";
1685 private static final String KEY_GPS_TIMESTAMP = "gps-timestamp";
Ray Chen055c9862010-02-23 10:45:42 +08001686 private static final String KEY_GPS_PROCESSING_METHOD = "gps-processing-method";
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001687 private static final String KEY_WHITE_BALANCE = "whitebalance";
1688 private static final String KEY_EFFECT = "effect";
1689 private static final String KEY_ANTIBANDING = "antibanding";
1690 private static final String KEY_SCENE_MODE = "scene-mode";
1691 private static final String KEY_FLASH_MODE = "flash-mode";
Wu-cheng Li36322db2009-09-18 18:59:21 +08001692 private static final String KEY_FOCUS_MODE = "focus-mode";
Wu-cheng Li30771b72011-04-02 06:19:46 +08001693 private static final String KEY_FOCUS_AREAS = "focus-areas";
1694 private static final String KEY_MAX_NUM_FOCUS_AREAS = "max-num-focus-areas";
Wu-cheng Li6c8d2762010-01-27 22:55:14 +08001695 private static final String KEY_FOCAL_LENGTH = "focal-length";
1696 private static final String KEY_HORIZONTAL_VIEW_ANGLE = "horizontal-view-angle";
1697 private static final String KEY_VERTICAL_VIEW_ANGLE = "vertical-view-angle";
Wu-cheng Liff723b62010-02-09 13:38:19 +08001698 private static final String KEY_EXPOSURE_COMPENSATION = "exposure-compensation";
Wu-cheng Li24b326a2010-02-20 17:47:04 +08001699 private static final String KEY_MAX_EXPOSURE_COMPENSATION = "max-exposure-compensation";
1700 private static final String KEY_MIN_EXPOSURE_COMPENSATION = "min-exposure-compensation";
1701 private static final String KEY_EXPOSURE_COMPENSATION_STEP = "exposure-compensation-step";
Eino-Ville Talvala3773eef2011-04-15 13:51:42 -07001702 private static final String KEY_AUTO_EXPOSURE_LOCK = "auto-exposure-lock";
1703 private static final String KEY_AUTO_EXPOSURE_LOCK_SUPPORTED = "auto-exposure-lock-supported";
Eino-Ville Talvalad9c2601a2011-05-13 10:19:59 -07001704 private static final String KEY_AUTO_WHITEBALANCE_LOCK = "auto-whitebalance-lock";
1705 private static final String KEY_AUTO_WHITEBALANCE_LOCK_SUPPORTED = "auto-whitebalance-lock-supported";
Wu-cheng Lie98e4c82011-04-12 19:34:29 +08001706 private static final String KEY_METERING_AREAS = "metering-areas";
1707 private static final String KEY_MAX_NUM_METERING_AREAS = "max-num-metering-areas";
Wu-cheng Li8cbb8f52010-02-28 23:19:55 -08001708 private static final String KEY_ZOOM = "zoom";
1709 private static final String KEY_MAX_ZOOM = "max-zoom";
1710 private static final String KEY_ZOOM_RATIOS = "zoom-ratios";
1711 private static final String KEY_ZOOM_SUPPORTED = "zoom-supported";
1712 private static final String KEY_SMOOTH_ZOOM_SUPPORTED = "smooth-zoom-supported";
Wu-cheng Lie339c5e2010-05-13 19:31:02 +08001713 private static final String KEY_FOCUS_DISTANCES = "focus-distances";
James Dongdd0b16c2010-09-21 16:23:48 -07001714 private static final String KEY_VIDEO_SIZE = "video-size";
1715 private static final String KEY_PREFERRED_PREVIEW_SIZE_FOR_VIDEO =
1716 "preferred-preview-size-for-video";
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08001717 private static final String KEY_MAX_NUM_DETECTED_FACES_HW = "max-num-detected-faces-hw";
1718 private static final String KEY_MAX_NUM_DETECTED_FACES_SW = "max-num-detected-faces-sw";
Wu-cheng Li25d8fb52011-08-02 13:20:36 +08001719 private static final String KEY_RECORDING_HINT = "recording-hint";
Wu-cheng Li98bb2512011-08-30 21:33:10 +08001720 private static final String KEY_VIDEO_SNAPSHOT_SUPPORTED = "video-snapshot-supported";
Eino-Ville Talvala037abb82011-10-11 12:41:58 -07001721 private static final String KEY_VIDEO_STABILIZATION = "video-stabilization";
1722 private static final String KEY_VIDEO_STABILIZATION_SUPPORTED = "video-stabilization-supported";
Wu-cheng Lie339c5e2010-05-13 19:31:02 +08001723
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001724 // Parameter key suffix for supported values.
1725 private static final String SUPPORTED_VALUES_SUFFIX = "-values";
1726
Wu-cheng Li8cbb8f52010-02-28 23:19:55 -08001727 private static final String TRUE = "true";
Eino-Ville Talvala3773eef2011-04-15 13:51:42 -07001728 private static final String FALSE = "false";
Wu-cheng Li8cbb8f52010-02-28 23:19:55 -08001729
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001730 // Values for white balance settings.
1731 public static final String WHITE_BALANCE_AUTO = "auto";
1732 public static final String WHITE_BALANCE_INCANDESCENT = "incandescent";
1733 public static final String WHITE_BALANCE_FLUORESCENT = "fluorescent";
1734 public static final String WHITE_BALANCE_WARM_FLUORESCENT = "warm-fluorescent";
1735 public static final String WHITE_BALANCE_DAYLIGHT = "daylight";
1736 public static final String WHITE_BALANCE_CLOUDY_DAYLIGHT = "cloudy-daylight";
1737 public static final String WHITE_BALANCE_TWILIGHT = "twilight";
1738 public static final String WHITE_BALANCE_SHADE = "shade";
1739
1740 // Values for color effect settings.
1741 public static final String EFFECT_NONE = "none";
1742 public static final String EFFECT_MONO = "mono";
1743 public static final String EFFECT_NEGATIVE = "negative";
1744 public static final String EFFECT_SOLARIZE = "solarize";
1745 public static final String EFFECT_SEPIA = "sepia";
1746 public static final String EFFECT_POSTERIZE = "posterize";
1747 public static final String EFFECT_WHITEBOARD = "whiteboard";
1748 public static final String EFFECT_BLACKBOARD = "blackboard";
1749 public static final String EFFECT_AQUA = "aqua";
1750
1751 // Values for antibanding settings.
1752 public static final String ANTIBANDING_AUTO = "auto";
1753 public static final String ANTIBANDING_50HZ = "50hz";
1754 public static final String ANTIBANDING_60HZ = "60hz";
1755 public static final String ANTIBANDING_OFF = "off";
1756
1757 // Values for flash mode settings.
1758 /**
1759 * Flash will not be fired.
1760 */
1761 public static final String FLASH_MODE_OFF = "off";
Wu-cheng Li36f68b82009-09-28 16:14:58 -07001762
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001763 /**
Wu-cheng Li068ef422009-09-27 13:19:36 -07001764 * Flash will be fired automatically when required. The flash may be fired
1765 * during preview, auto-focus, or snapshot depending on the driver.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001766 */
1767 public static final String FLASH_MODE_AUTO = "auto";
Wu-cheng Li36f68b82009-09-28 16:14:58 -07001768
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001769 /**
Wu-cheng Li068ef422009-09-27 13:19:36 -07001770 * Flash will always be fired during snapshot. The flash may also be
1771 * fired during preview or auto-focus depending on the driver.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001772 */
1773 public static final String FLASH_MODE_ON = "on";
Wu-cheng Li36f68b82009-09-28 16:14:58 -07001774
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001775 /**
1776 * Flash will be fired in red-eye reduction mode.
1777 */
1778 public static final String FLASH_MODE_RED_EYE = "red-eye";
Wu-cheng Li36f68b82009-09-28 16:14:58 -07001779
Wu-cheng Li36322db2009-09-18 18:59:21 +08001780 /**
Wu-cheng Li068ef422009-09-27 13:19:36 -07001781 * Constant emission of light during preview, auto-focus and snapshot.
1782 * This can also be used for video recording.
Wu-cheng Li36322db2009-09-18 18:59:21 +08001783 */
Wu-cheng Li068ef422009-09-27 13:19:36 -07001784 public static final String FLASH_MODE_TORCH = "torch";
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001785
Wu-cheng Li00e21f82010-05-28 16:43:38 +08001786 /**
1787 * Scene mode is off.
1788 */
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001789 public static final String SCENE_MODE_AUTO = "auto";
Wu-cheng Li00e21f82010-05-28 16:43:38 +08001790
1791 /**
1792 * Take photos of fast moving objects. Same as {@link
1793 * #SCENE_MODE_SPORTS}.
1794 */
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001795 public static final String SCENE_MODE_ACTION = "action";
Wu-cheng Li00e21f82010-05-28 16:43:38 +08001796
1797 /**
1798 * Take people pictures.
1799 */
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001800 public static final String SCENE_MODE_PORTRAIT = "portrait";
Wu-cheng Li00e21f82010-05-28 16:43:38 +08001801
1802 /**
1803 * Take pictures on distant objects.
1804 */
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001805 public static final String SCENE_MODE_LANDSCAPE = "landscape";
Wu-cheng Li00e21f82010-05-28 16:43:38 +08001806
1807 /**
1808 * Take photos at night.
1809 */
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001810 public static final String SCENE_MODE_NIGHT = "night";
Wu-cheng Li00e21f82010-05-28 16:43:38 +08001811
1812 /**
1813 * Take people pictures at night.
1814 */
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001815 public static final String SCENE_MODE_NIGHT_PORTRAIT = "night-portrait";
Wu-cheng Li00e21f82010-05-28 16:43:38 +08001816
1817 /**
1818 * Take photos in a theater. Flash light is off.
1819 */
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001820 public static final String SCENE_MODE_THEATRE = "theatre";
Wu-cheng Li00e21f82010-05-28 16:43:38 +08001821
1822 /**
1823 * Take pictures on the beach.
1824 */
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001825 public static final String SCENE_MODE_BEACH = "beach";
Wu-cheng Li00e21f82010-05-28 16:43:38 +08001826
1827 /**
1828 * Take pictures on the snow.
1829 */
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001830 public static final String SCENE_MODE_SNOW = "snow";
Wu-cheng Li00e21f82010-05-28 16:43:38 +08001831
1832 /**
1833 * Take sunset photos.
1834 */
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001835 public static final String SCENE_MODE_SUNSET = "sunset";
Wu-cheng Li00e21f82010-05-28 16:43:38 +08001836
1837 /**
1838 * Avoid blurry pictures (for example, due to hand shake).
1839 */
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001840 public static final String SCENE_MODE_STEADYPHOTO = "steadyphoto";
Wu-cheng Li00e21f82010-05-28 16:43:38 +08001841
1842 /**
1843 * For shooting firework displays.
1844 */
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001845 public static final String SCENE_MODE_FIREWORKS = "fireworks";
Wu-cheng Li00e21f82010-05-28 16:43:38 +08001846
1847 /**
1848 * Take photos of fast moving objects. Same as {@link
1849 * #SCENE_MODE_ACTION}.
1850 */
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001851 public static final String SCENE_MODE_SPORTS = "sports";
Wu-cheng Li00e21f82010-05-28 16:43:38 +08001852
1853 /**
1854 * Take indoor low-light shot.
1855 */
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001856 public static final String SCENE_MODE_PARTY = "party";
Wu-cheng Li00e21f82010-05-28 16:43:38 +08001857
1858 /**
1859 * Capture the naturally warm color of scenes lit by candles.
1860 */
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001861 public static final String SCENE_MODE_CANDLELIGHT = "candlelight";
1862
Wu-cheng Lic58b4232010-03-29 17:21:28 +08001863 /**
1864 * Applications are looking for a barcode. Camera driver will be
1865 * optimized for barcode reading.
1866 */
1867 public static final String SCENE_MODE_BARCODE = "barcode";
1868
Wu-cheng Li36322db2009-09-18 18:59:21 +08001869 /**
Eino-Ville Talvalada2f0ea2012-09-10 12:03:35 -07001870 * Capture a scene using high dynamic range imaging techniques. The
1871 * camera will return an image that has an extended dynamic range
1872 * compared to a regular capture. Capturing such an image may take
1873 * longer than a regular capture.
Eino-Ville Talvalada2f0ea2012-09-10 12:03:35 -07001874 */
1875 public static final String SCENE_MODE_HDR = "hdr";
1876
1877 /**
Wu-cheng Lif008f3e2010-08-17 13:44:35 -07001878 * Auto-focus mode. Applications should call {@link
1879 * #autoFocus(AutoFocusCallback)} to start the focus in this mode.
Wu-cheng Li36322db2009-09-18 18:59:21 +08001880 */
1881 public static final String FOCUS_MODE_AUTO = "auto";
Wu-cheng Li36f68b82009-09-28 16:14:58 -07001882
Wu-cheng Li36322db2009-09-18 18:59:21 +08001883 /**
1884 * Focus is set at infinity. Applications should not call
1885 * {@link #autoFocus(AutoFocusCallback)} in this mode.
1886 */
1887 public static final String FOCUS_MODE_INFINITY = "infinity";
Wu-cheng Lif008f3e2010-08-17 13:44:35 -07001888
1889 /**
1890 * Macro (close-up) focus mode. Applications should call
1891 * {@link #autoFocus(AutoFocusCallback)} to start the focus in this
1892 * mode.
1893 */
Wu-cheng Li36322db2009-09-18 18:59:21 +08001894 public static final String FOCUS_MODE_MACRO = "macro";
Wu-cheng Li36f68b82009-09-28 16:14:58 -07001895
Wu-cheng Li36322db2009-09-18 18:59:21 +08001896 /**
1897 * Focus is fixed. The camera is always in this mode if the focus is not
1898 * adjustable. If the camera has auto-focus, this mode can fix the
1899 * focus, which is usually at hyperfocal distance. Applications should
1900 * not call {@link #autoFocus(AutoFocusCallback)} in this mode.
1901 */
1902 public static final String FOCUS_MODE_FIXED = "fixed";
1903
Wu-cheng Lic58b4232010-03-29 17:21:28 +08001904 /**
1905 * Extended depth of field (EDOF). Focusing is done digitally and
1906 * continuously. Applications should not call {@link
1907 * #autoFocus(AutoFocusCallback)} in this mode.
1908 */
1909 public static final String FOCUS_MODE_EDOF = "edof";
1910
Wu-cheng Li699fe932010-08-05 11:50:25 -07001911 /**
Wu-cheng Lid45cb722010-09-20 16:15:32 -07001912 * Continuous auto focus mode intended for video recording. The camera
Wu-cheng Lib9ac75d2011-08-16 21:14:16 +08001913 * continuously tries to focus. This is the best choice for video
1914 * recording because the focus changes smoothly . Applications still can
1915 * call {@link #takePicture(Camera.ShutterCallback,
1916 * Camera.PictureCallback, Camera.PictureCallback)} in this mode but the
1917 * subject may not be in focus. Auto focus starts when the parameter is
Wu-cheng Li53b30912011-10-12 19:43:51 +08001918 * set.
1919 *
1920 * <p>Since API level 14, applications can call {@link
1921 * #autoFocus(AutoFocusCallback)} in this mode. The focus callback will
1922 * immediately return with a boolean that indicates whether the focus is
1923 * sharp or not. The focus position is locked after autoFocus call. If
1924 * applications want to resume the continuous focus, cancelAutoFocus
1925 * must be called. Restarting the preview will not resume the continuous
1926 * autofocus. To stop continuous focus, applications should change the
1927 * focus mode to other modes.
1928 *
1929 * @see #FOCUS_MODE_CONTINUOUS_PICTURE
Wu-cheng Li699fe932010-08-05 11:50:25 -07001930 */
Wu-cheng Lid45cb722010-09-20 16:15:32 -07001931 public static final String FOCUS_MODE_CONTINUOUS_VIDEO = "continuous-video";
Wu-cheng Li699fe932010-08-05 11:50:25 -07001932
Wu-cheng Lib9ac75d2011-08-16 21:14:16 +08001933 /**
1934 * Continuous auto focus mode intended for taking pictures. The camera
1935 * continuously tries to focus. The speed of focus change is more
1936 * aggressive than {@link #FOCUS_MODE_CONTINUOUS_VIDEO}. Auto focus
Wu-cheng Li53b30912011-10-12 19:43:51 +08001937 * starts when the parameter is set.
1938 *
Wu-cheng Li0f4f97b2011-10-27 18:07:01 +08001939 * <p>Applications can call {@link #autoFocus(AutoFocusCallback)} in
1940 * this mode. If the autofocus is in the middle of scanning, the focus
1941 * callback will return when it completes. If the autofocus is not
1942 * scanning, the focus callback will immediately return with a boolean
1943 * that indicates whether the focus is sharp or not. The apps can then
1944 * decide if they want to take a picture immediately or to change the
1945 * focus mode to auto, and run a full autofocus cycle. The focus
1946 * position is locked after autoFocus call. If applications want to
1947 * resume the continuous focus, cancelAutoFocus must be called.
1948 * Restarting the preview will not resume the continuous autofocus. To
1949 * stop continuous focus, applications should change the focus mode to
1950 * other modes.
Wu-cheng Lib9ac75d2011-08-16 21:14:16 +08001951 *
1952 * @see #FOCUS_MODE_CONTINUOUS_VIDEO
Wu-cheng Lib9ac75d2011-08-16 21:14:16 +08001953 */
1954 public static final String FOCUS_MODE_CONTINUOUS_PICTURE = "continuous-picture";
1955
Wu-cheng Lie339c5e2010-05-13 19:31:02 +08001956 // Indices for focus distance array.
1957 /**
1958 * The array index of near focus distance for use with
1959 * {@link #getFocusDistances(float[])}.
1960 */
1961 public static final int FOCUS_DISTANCE_NEAR_INDEX = 0;
1962
1963 /**
1964 * The array index of optimal focus distance for use with
1965 * {@link #getFocusDistances(float[])}.
1966 */
1967 public static final int FOCUS_DISTANCE_OPTIMAL_INDEX = 1;
1968
1969 /**
1970 * The array index of far focus distance for use with
1971 * {@link #getFocusDistances(float[])}.
1972 */
1973 public static final int FOCUS_DISTANCE_FAR_INDEX = 2;
1974
Wu-cheng Lica099612010-05-06 16:47:30 +08001975 /**
Wu-cheng Li454630f2010-08-11 16:48:05 -07001976 * The array index of minimum preview fps for use with {@link
1977 * #getPreviewFpsRange(int[])} or {@link
1978 * #getSupportedPreviewFpsRange()}.
Wu-cheng Li454630f2010-08-11 16:48:05 -07001979 */
1980 public static final int PREVIEW_FPS_MIN_INDEX = 0;
1981
1982 /**
1983 * The array index of maximum preview fps for use with {@link
1984 * #getPreviewFpsRange(int[])} or {@link
1985 * #getSupportedPreviewFpsRange()}.
Wu-cheng Li454630f2010-08-11 16:48:05 -07001986 */
1987 public static final int PREVIEW_FPS_MAX_INDEX = 1;
1988
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001989 // Formats for setPreviewFormat and setPictureFormat.
1990 private static final String PIXEL_FORMAT_YUV422SP = "yuv422sp";
1991 private static final String PIXEL_FORMAT_YUV420SP = "yuv420sp";
Chih-Chung Changeb68c462009-09-18 18:37:44 +08001992 private static final String PIXEL_FORMAT_YUV422I = "yuv422i-yuyv";
Wu-cheng Li10a1b302011-02-22 15:49:25 +08001993 private static final String PIXEL_FORMAT_YUV420P = "yuv420p";
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001994 private static final String PIXEL_FORMAT_RGB565 = "rgb565";
1995 private static final String PIXEL_FORMAT_JPEG = "jpeg";
Wu-cheng Li70fb9082011-08-02 17:49:50 +08001996 private static final String PIXEL_FORMAT_BAYER_RGGB = "bayer-rggb";
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001997
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001998 private HashMap<String, String> mMap;
1999
2000 private Parameters() {
Ali Utku Selen0a120182011-02-09 14:11:22 +01002001 mMap = new HashMap<String, String>(64);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002002 }
2003
2004 /**
2005 * Writes the current Parameters to the log.
2006 * @hide
2007 * @deprecated
2008 */
2009 public void dump() {
2010 Log.e(TAG, "dump: size=" + mMap.size());
2011 for (String k : mMap.keySet()) {
2012 Log.e(TAG, "dump: " + k + "=" + mMap.get(k));
2013 }
2014 }
2015
2016 /**
2017 * Creates a single string with all the parameters set in
2018 * this Parameters object.
2019 * <p>The {@link #unflatten(String)} method does the reverse.</p>
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002020 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002021 * @return a String with all values from this Parameters object, in
2022 * semi-colon delimited key-value pairs
2023 */
2024 public String flatten() {
Ali Utku Selen0a120182011-02-09 14:11:22 +01002025 StringBuilder flattened = new StringBuilder(128);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002026 for (String k : mMap.keySet()) {
2027 flattened.append(k);
2028 flattened.append("=");
2029 flattened.append(mMap.get(k));
2030 flattened.append(";");
2031 }
2032 // chop off the extra semicolon at the end
2033 flattened.deleteCharAt(flattened.length()-1);
2034 return flattened.toString();
2035 }
2036
2037 /**
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002038 * Takes a flattened string of parameters and adds each one to
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002039 * this Parameters object.
2040 * <p>The {@link #flatten()} method does the reverse.</p>
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002041 *
2042 * @param flattened a String of parameters (key-value paired) that
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002043 * are semi-colon delimited
2044 */
2045 public void unflatten(String flattened) {
2046 mMap.clear();
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002047
Ali Utku Selen0a120182011-02-09 14:11:22 +01002048 TextUtils.StringSplitter splitter = new TextUtils.SimpleStringSplitter(';');
2049 splitter.setString(flattened);
2050 for (String kv : splitter) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002051 int pos = kv.indexOf('=');
2052 if (pos == -1) {
2053 continue;
2054 }
2055 String k = kv.substring(0, pos);
2056 String v = kv.substring(pos + 1);
2057 mMap.put(k, v);
2058 }
2059 }
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002060
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002061 public void remove(String key) {
2062 mMap.remove(key);
2063 }
2064
2065 /**
2066 * Sets a String parameter.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002067 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002068 * @param key the key name for the parameter
2069 * @param value the String value of the parameter
2070 */
2071 public void set(String key, String value) {
Eino-Ville Talvalacb569232012-03-12 11:36:58 -07002072 if (key.indexOf('=') != -1 || key.indexOf(';') != -1 || key.indexOf(0) != -1) {
2073 Log.e(TAG, "Key \"" + key + "\" contains invalid character (= or ; or \\0)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002074 return;
2075 }
Eino-Ville Talvalacb569232012-03-12 11:36:58 -07002076 if (value.indexOf('=') != -1 || value.indexOf(';') != -1 || value.indexOf(0) != -1) {
2077 Log.e(TAG, "Value \"" + value + "\" contains invalid character (= or ; or \\0)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002078 return;
2079 }
2080
2081 mMap.put(key, value);
2082 }
2083
2084 /**
2085 * Sets an integer parameter.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002086 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002087 * @param key the key name for the parameter
2088 * @param value the int value of the parameter
2089 */
2090 public void set(String key, int value) {
2091 mMap.put(key, Integer.toString(value));
2092 }
2093
Wu-cheng Lie98e4c82011-04-12 19:34:29 +08002094 private void set(String key, List<Area> areas) {
Wu-cheng Lif715bf92011-04-14 14:04:18 +08002095 if (areas == null) {
2096 set(key, "(0,0,0,0,0)");
2097 } else {
2098 StringBuilder buffer = new StringBuilder();
2099 for (int i = 0; i < areas.size(); i++) {
2100 Area area = areas.get(i);
2101 Rect rect = area.rect;
2102 buffer.append('(');
2103 buffer.append(rect.left);
2104 buffer.append(',');
2105 buffer.append(rect.top);
2106 buffer.append(',');
2107 buffer.append(rect.right);
2108 buffer.append(',');
2109 buffer.append(rect.bottom);
2110 buffer.append(',');
2111 buffer.append(area.weight);
2112 buffer.append(')');
2113 if (i != areas.size() - 1) buffer.append(',');
2114 }
2115 set(key, buffer.toString());
Wu-cheng Lie98e4c82011-04-12 19:34:29 +08002116 }
Wu-cheng Lie98e4c82011-04-12 19:34:29 +08002117 }
2118
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002119 /**
2120 * Returns the value of a String parameter.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002121 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002122 * @param key the key name for the parameter
2123 * @return the String value of the parameter
2124 */
2125 public String get(String key) {
2126 return mMap.get(key);
2127 }
2128
2129 /**
2130 * Returns the value of an integer parameter.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002131 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002132 * @param key the key name for the parameter
2133 * @return the int value of the parameter
2134 */
2135 public int getInt(String key) {
2136 return Integer.parseInt(mMap.get(key));
2137 }
2138
2139 /**
Wu-cheng Li26274fa2011-05-05 14:36:28 +08002140 * Sets the dimensions for preview pictures. If the preview has already
2141 * started, applications should stop the preview first before changing
2142 * preview size.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002143 *
Wu-cheng Lic157e0c2010-10-07 18:36:07 +08002144 * The sides of width and height are based on camera orientation. That
2145 * is, the preview size is the size before it is rotated by display
2146 * orientation. So applications need to consider the display orientation
2147 * while setting preview size. For example, suppose the camera supports
2148 * both 480x320 and 320x480 preview sizes. The application wants a 3:2
2149 * preview ratio. If the display orientation is set to 0 or 180, preview
2150 * size should be set to 480x320. If the display orientation is set to
2151 * 90 or 270, preview size should be set to 320x480. The display
2152 * orientation should also be considered while setting picture size and
2153 * thumbnail size.
2154 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002155 * @param width the width of the pictures, in pixels
2156 * @param height the height of the pictures, in pixels
Wu-cheng Lic157e0c2010-10-07 18:36:07 +08002157 * @see #setDisplayOrientation(int)
2158 * @see #getCameraInfo(int, CameraInfo)
2159 * @see #setPictureSize(int, int)
2160 * @see #setJpegThumbnailSize(int, int)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002161 */
2162 public void setPreviewSize(int width, int height) {
2163 String v = Integer.toString(width) + "x" + Integer.toString(height);
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002164 set(KEY_PREVIEW_SIZE, v);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002165 }
2166
2167 /**
2168 * Returns the dimensions setting for preview pictures.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002169 *
James Dongdd0b16c2010-09-21 16:23:48 -07002170 * @return a Size object with the width and height setting
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002171 * for the preview picture
2172 */
2173 public Size getPreviewSize() {
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002174 String pair = get(KEY_PREVIEW_SIZE);
2175 return strToSize(pair);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002176 }
2177
2178 /**
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002179 * Gets the supported preview sizes.
2180 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08002181 * @return a list of Size object. This method will always return a list
Wu-cheng Li9c799382009-12-04 19:59:18 +08002182 * with at least one element.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002183 */
2184 public List<Size> getSupportedPreviewSizes() {
2185 String str = get(KEY_PREVIEW_SIZE + SUPPORTED_VALUES_SUFFIX);
2186 return splitSize(str);
2187 }
2188
2189 /**
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07002190 * <p>Gets the supported video frame sizes that can be used by
2191 * MediaRecorder.</p>
James Dongdd0b16c2010-09-21 16:23:48 -07002192 *
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07002193 * <p>If the returned list is not null, the returned list will contain at
James Dongdd0b16c2010-09-21 16:23:48 -07002194 * least one Size and one of the sizes in the returned list must be
2195 * passed to MediaRecorder.setVideoSize() for camcorder application if
2196 * camera is used as the video source. In this case, the size of the
2197 * preview can be different from the resolution of the recorded video
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07002198 * during video recording.</p>
James Dongdd0b16c2010-09-21 16:23:48 -07002199 *
2200 * @return a list of Size object if camera has separate preview and
2201 * video output; otherwise, null is returned.
2202 * @see #getPreferredPreviewSizeForVideo()
2203 */
2204 public List<Size> getSupportedVideoSizes() {
2205 String str = get(KEY_VIDEO_SIZE + SUPPORTED_VALUES_SUFFIX);
2206 return splitSize(str);
2207 }
2208
2209 /**
2210 * Returns the preferred or recommended preview size (width and height)
2211 * in pixels for video recording. Camcorder applications should
2212 * set the preview size to a value that is not larger than the
2213 * preferred preview size. In other words, the product of the width
2214 * and height of the preview size should not be larger than that of
2215 * the preferred preview size. In addition, we recommend to choose a
2216 * preview size that has the same aspect ratio as the resolution of
2217 * video to be recorded.
2218 *
2219 * @return the preferred preview size (width and height) in pixels for
2220 * video recording if getSupportedVideoSizes() does not return
2221 * null; otherwise, null is returned.
2222 * @see #getSupportedVideoSizes()
2223 */
2224 public Size getPreferredPreviewSizeForVideo() {
2225 String pair = get(KEY_PREFERRED_PREVIEW_SIZE_FOR_VIDEO);
2226 return strToSize(pair);
2227 }
2228
2229 /**
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07002230 * <p>Sets the dimensions for EXIF thumbnail in Jpeg picture. If
Wu-cheng Li4c4300c2010-01-23 15:45:39 +08002231 * applications set both width and height to 0, EXIF will not contain
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07002232 * thumbnail.</p>
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002233 *
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07002234 * <p>Applications need to consider the display orientation. See {@link
2235 * #setPreviewSize(int,int)} for reference.</p>
Wu-cheng Lic157e0c2010-10-07 18:36:07 +08002236 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002237 * @param width the width of the thumbnail, in pixels
2238 * @param height the height of the thumbnail, in pixels
Wu-cheng Lic157e0c2010-10-07 18:36:07 +08002239 * @see #setPreviewSize(int,int)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002240 */
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002241 public void setJpegThumbnailSize(int width, int height) {
2242 set(KEY_JPEG_THUMBNAIL_WIDTH, width);
2243 set(KEY_JPEG_THUMBNAIL_HEIGHT, height);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002244 }
2245
2246 /**
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002247 * Returns the dimensions for EXIF thumbnail in Jpeg picture.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002248 *
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002249 * @return a Size object with the height and width setting for the EXIF
2250 * thumbnails
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002251 */
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002252 public Size getJpegThumbnailSize() {
2253 return new Size(getInt(KEY_JPEG_THUMBNAIL_WIDTH),
2254 getInt(KEY_JPEG_THUMBNAIL_HEIGHT));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002255 }
2256
2257 /**
Wu-cheng Li4c4300c2010-01-23 15:45:39 +08002258 * Gets the supported jpeg thumbnail sizes.
2259 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08002260 * @return a list of Size object. This method will always return a list
Wu-cheng Li4c4300c2010-01-23 15:45:39 +08002261 * with at least two elements. Size 0,0 (no thumbnail) is always
2262 * supported.
2263 */
2264 public List<Size> getSupportedJpegThumbnailSizes() {
2265 String str = get(KEY_JPEG_THUMBNAIL_SIZE + SUPPORTED_VALUES_SUFFIX);
2266 return splitSize(str);
2267 }
2268
2269 /**
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002270 * Sets the quality of the EXIF thumbnail in Jpeg picture.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002271 *
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002272 * @param quality the JPEG quality of the EXIF thumbnail. The range is 1
2273 * to 100, with 100 being the best.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002274 */
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002275 public void setJpegThumbnailQuality(int quality) {
2276 set(KEY_JPEG_THUMBNAIL_QUALITY, quality);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002277 }
2278
2279 /**
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002280 * Returns the quality setting for the EXIF thumbnail in Jpeg picture.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002281 *
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002282 * @return the JPEG quality setting of the EXIF thumbnail.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002283 */
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002284 public int getJpegThumbnailQuality() {
2285 return getInt(KEY_JPEG_THUMBNAIL_QUALITY);
2286 }
2287
2288 /**
2289 * Sets Jpeg quality of captured picture.
2290 *
2291 * @param quality the JPEG quality of captured picture. The range is 1
2292 * to 100, with 100 being the best.
2293 */
2294 public void setJpegQuality(int quality) {
2295 set(KEY_JPEG_QUALITY, quality);
2296 }
2297
2298 /**
2299 * Returns the quality setting for the JPEG picture.
2300 *
2301 * @return the JPEG picture quality setting.
2302 */
2303 public int getJpegQuality() {
2304 return getInt(KEY_JPEG_QUALITY);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002305 }
2306
2307 /**
Wu-cheng Lia18e9012010-02-10 13:05:29 +08002308 * Sets the rate at which preview frames are received. This is the
2309 * target frame rate. The actual frame rate depends on the driver.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002310 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002311 * @param fps the frame rate (frames per second)
Wu-cheng Li5f1e69c2010-08-18 11:39:12 -07002312 * @deprecated replaced by {@link #setPreviewFpsRange(int,int)}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002313 */
Wu-cheng Li5f1e69c2010-08-18 11:39:12 -07002314 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002315 public void setPreviewFrameRate(int fps) {
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002316 set(KEY_PREVIEW_FRAME_RATE, fps);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002317 }
2318
2319 /**
Wu-cheng Lia18e9012010-02-10 13:05:29 +08002320 * Returns the setting for the rate at which preview frames are
2321 * received. This is the target frame rate. The actual frame rate
2322 * depends on the driver.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002323 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002324 * @return the frame rate setting (frames per second)
Wu-cheng Li5f1e69c2010-08-18 11:39:12 -07002325 * @deprecated replaced by {@link #getPreviewFpsRange(int[])}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002326 */
Wu-cheng Li5f1e69c2010-08-18 11:39:12 -07002327 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002328 public int getPreviewFrameRate() {
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002329 return getInt(KEY_PREVIEW_FRAME_RATE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002330 }
2331
2332 /**
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002333 * Gets the supported preview frame rates.
2334 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08002335 * @return a list of supported preview frame rates. null if preview
2336 * frame rate setting is not supported.
Wu-cheng Li5f1e69c2010-08-18 11:39:12 -07002337 * @deprecated replaced by {@link #getSupportedPreviewFpsRange()}
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002338 */
Wu-cheng Li5f1e69c2010-08-18 11:39:12 -07002339 @Deprecated
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002340 public List<Integer> getSupportedPreviewFrameRates() {
2341 String str = get(KEY_PREVIEW_FRAME_RATE + SUPPORTED_VALUES_SUFFIX);
2342 return splitInt(str);
2343 }
2344
2345 /**
Hai Guo4a68e3c2012-12-05 21:50:28 +08002346 * Sets the minimum and maximum preview fps. This controls the rate of
Wu-cheng Li1620d112010-08-27 15:09:20 -07002347 * preview frames received in {@link PreviewCallback}. The minimum and
Wu-cheng Li454630f2010-08-11 16:48:05 -07002348 * maximum preview fps must be one of the elements from {@link
2349 * #getSupportedPreviewFpsRange}.
2350 *
2351 * @param min the minimum preview fps (scaled by 1000).
2352 * @param max the maximum preview fps (scaled by 1000).
2353 * @throws RuntimeException if fps range is invalid.
2354 * @see #setPreviewCallbackWithBuffer(Camera.PreviewCallback)
2355 * @see #getSupportedPreviewFpsRange()
Wu-cheng Li454630f2010-08-11 16:48:05 -07002356 */
2357 public void setPreviewFpsRange(int min, int max) {
2358 set(KEY_PREVIEW_FPS_RANGE, "" + min + "," + max);
2359 }
2360
2361 /**
2362 * Returns the current minimum and maximum preview fps. The values are
2363 * one of the elements returned by {@link #getSupportedPreviewFpsRange}.
2364 *
2365 * @return range the minimum and maximum preview fps (scaled by 1000).
2366 * @see #PREVIEW_FPS_MIN_INDEX
2367 * @see #PREVIEW_FPS_MAX_INDEX
2368 * @see #getSupportedPreviewFpsRange()
Wu-cheng Li454630f2010-08-11 16:48:05 -07002369 */
2370 public void getPreviewFpsRange(int[] range) {
2371 if (range == null || range.length != 2) {
2372 throw new IllegalArgumentException(
Wu-cheng Li5f1e69c2010-08-18 11:39:12 -07002373 "range must be an array with two elements.");
Wu-cheng Li454630f2010-08-11 16:48:05 -07002374 }
2375 splitInt(get(KEY_PREVIEW_FPS_RANGE), range);
2376 }
2377
2378 /**
2379 * Gets the supported preview fps (frame-per-second) ranges. Each range
2380 * contains a minimum fps and maximum fps. If minimum fps equals to
2381 * maximum fps, the camera outputs frames in fixed frame rate. If not,
2382 * the camera outputs frames in auto frame rate. The actual frame rate
2383 * fluctuates between the minimum and the maximum. The values are
2384 * multiplied by 1000 and represented in integers. For example, if frame
2385 * rate is 26.623 frames per second, the value is 26623.
2386 *
2387 * @return a list of supported preview fps ranges. This method returns a
2388 * list with at least one element. Every element is an int array
2389 * of two values - minimum fps and maximum fps. The list is
2390 * sorted from small to large (first by maximum fps and then
2391 * minimum fps).
2392 * @see #PREVIEW_FPS_MIN_INDEX
2393 * @see #PREVIEW_FPS_MAX_INDEX
Wu-cheng Li454630f2010-08-11 16:48:05 -07002394 */
2395 public List<int[]> getSupportedPreviewFpsRange() {
2396 String str = get(KEY_PREVIEW_FPS_RANGE + SUPPORTED_VALUES_SUFFIX);
2397 return splitRange(str);
2398 }
2399
2400 /**
Wu-cheng Li7478ea62009-09-16 18:52:55 +08002401 * Sets the image format for preview pictures.
Scott Mainda0a56d2009-09-10 18:08:37 -07002402 * <p>If this is never called, the default format will be
Mathias Agopiana696f5d2010-02-17 17:53:09 -08002403 * {@link android.graphics.ImageFormat#NV21}, which
Scott Maindf4578e2009-09-10 12:22:07 -07002404 * uses the NV21 encoding format.</p>
Wu-cheng Li7478ea62009-09-16 18:52:55 +08002405 *
Eino-Ville Talvala95151632012-05-02 16:21:18 -07002406 * <p>Use {@link Parameters#getSupportedPreviewFormats} to get a list of
2407 * the available preview formats.
2408 *
2409 * <p>It is strongly recommended that either
2410 * {@link android.graphics.ImageFormat#NV21} or
2411 * {@link android.graphics.ImageFormat#YV12} is used, since
2412 * they are supported by all camera devices.</p>
2413 *
2414 * <p>For YV12, the image buffer that is received is not necessarily
2415 * tightly packed, as there may be padding at the end of each row of
2416 * pixel data, as described in
2417 * {@link android.graphics.ImageFormat#YV12}. For camera callback data,
2418 * it can be assumed that the stride of the Y and UV data is the
2419 * smallest possible that meets the alignment requirements. That is, if
2420 * the preview size is <var>width x height</var>, then the following
2421 * equations describe the buffer index for the beginning of row
2422 * <var>y</var> for the Y plane and row <var>c</var> for the U and V
2423 * planes:
2424 *
2425 * {@code
2426 * <pre>
2427 * yStride = (int) ceil(width / 16.0) * 16;
2428 * uvStride = (int) ceil( (yStride / 2) / 16.0) * 16;
2429 * ySize = yStride * height;
2430 * uvSize = uvStride * height / 2;
2431 * yRowIndex = yStride * y;
2432 * uRowIndex = ySize + uvSize + uvStride * c;
2433 * vRowIndex = ySize + uvStride * c;
2434 * size = ySize + uvSize * 2;</pre>
2435 * }
2436 *
2437 * @param pixel_format the desired preview picture format, defined by
2438 * one of the {@link android.graphics.ImageFormat} constants. (E.g.,
2439 * <var>ImageFormat.NV21</var> (default), or
2440 * <var>ImageFormat.YV12</var>)
2441 *
Mathias Agopiana696f5d2010-02-17 17:53:09 -08002442 * @see android.graphics.ImageFormat
Eino-Ville Talvala95151632012-05-02 16:21:18 -07002443 * @see android.hardware.Camera.Parameters#getSupportedPreviewFormats
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002444 */
2445 public void setPreviewFormat(int pixel_format) {
2446 String s = cameraFormatForPixelFormat(pixel_format);
2447 if (s == null) {
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002448 throw new IllegalArgumentException(
2449 "Invalid pixel_format=" + pixel_format);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002450 }
2451
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002452 set(KEY_PREVIEW_FORMAT, s);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002453 }
2454
2455 /**
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08002456 * Returns the image format for preview frames got from
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002457 * {@link PreviewCallback}.
Wu-cheng Li7478ea62009-09-16 18:52:55 +08002458 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08002459 * @return the preview format.
2460 * @see android.graphics.ImageFormat
Eino-Ville Talvala95151632012-05-02 16:21:18 -07002461 * @see #setPreviewFormat
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002462 */
2463 public int getPreviewFormat() {
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002464 return pixelFormatForCameraFormat(get(KEY_PREVIEW_FORMAT));
2465 }
2466
2467 /**
Wu-cheng Lif9293e72011-02-25 13:35:10 +08002468 * Gets the supported preview formats. {@link android.graphics.ImageFormat#NV21}
2469 * is always supported. {@link android.graphics.ImageFormat#YV12}
2470 * is always supported since API level 12.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002471 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08002472 * @return a list of supported preview formats. This method will always
2473 * return a list with at least one element.
2474 * @see android.graphics.ImageFormat
Eino-Ville Talvala95151632012-05-02 16:21:18 -07002475 * @see #setPreviewFormat
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002476 */
2477 public List<Integer> getSupportedPreviewFormats() {
2478 String str = get(KEY_PREVIEW_FORMAT + SUPPORTED_VALUES_SUFFIX);
Chih-Chung Changeb68c462009-09-18 18:37:44 +08002479 ArrayList<Integer> formats = new ArrayList<Integer>();
2480 for (String s : split(str)) {
2481 int f = pixelFormatForCameraFormat(s);
Mathias Agopiana696f5d2010-02-17 17:53:09 -08002482 if (f == ImageFormat.UNKNOWN) continue;
Chih-Chung Changeb68c462009-09-18 18:37:44 +08002483 formats.add(f);
2484 }
2485 return formats;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002486 }
2487
2488 /**
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07002489 * <p>Sets the dimensions for pictures.</p>
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002490 *
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07002491 * <p>Applications need to consider the display orientation. See {@link
2492 * #setPreviewSize(int,int)} for reference.</p>
Wu-cheng Lic157e0c2010-10-07 18:36:07 +08002493 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002494 * @param width the width for pictures, in pixels
2495 * @param height the height for pictures, in pixels
Wu-cheng Lic157e0c2010-10-07 18:36:07 +08002496 * @see #setPreviewSize(int,int)
2497 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002498 */
2499 public void setPictureSize(int width, int height) {
2500 String v = Integer.toString(width) + "x" + Integer.toString(height);
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002501 set(KEY_PICTURE_SIZE, v);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002502 }
2503
2504 /**
2505 * Returns the dimension setting for pictures.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002506 *
2507 * @return a Size object with the height and width setting
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002508 * for pictures
2509 */
2510 public Size getPictureSize() {
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002511 String pair = get(KEY_PICTURE_SIZE);
2512 return strToSize(pair);
2513 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002514
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002515 /**
2516 * Gets the supported picture sizes.
2517 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08002518 * @return a list of supported picture sizes. This method will always
2519 * return a list with at least one element.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002520 */
2521 public List<Size> getSupportedPictureSizes() {
2522 String str = get(KEY_PICTURE_SIZE + SUPPORTED_VALUES_SUFFIX);
2523 return splitSize(str);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002524 }
2525
2526 /**
2527 * Sets the image format for pictures.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002528 *
2529 * @param pixel_format the desired picture format
Mathias Agopiana696f5d2010-02-17 17:53:09 -08002530 * (<var>ImageFormat.NV21</var>,
2531 * <var>ImageFormat.RGB_565</var>, or
2532 * <var>ImageFormat.JPEG</var>)
2533 * @see android.graphics.ImageFormat
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002534 */
2535 public void setPictureFormat(int pixel_format) {
2536 String s = cameraFormatForPixelFormat(pixel_format);
2537 if (s == null) {
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002538 throw new IllegalArgumentException(
2539 "Invalid pixel_format=" + pixel_format);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002540 }
2541
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002542 set(KEY_PICTURE_FORMAT, s);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002543 }
2544
2545 /**
2546 * Returns the image format for pictures.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002547 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08002548 * @return the picture format
2549 * @see android.graphics.ImageFormat
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002550 */
2551 public int getPictureFormat() {
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002552 return pixelFormatForCameraFormat(get(KEY_PICTURE_FORMAT));
2553 }
2554
2555 /**
2556 * Gets the supported picture formats.
2557 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08002558 * @return supported picture formats. This method will always return a
2559 * list with at least one element.
2560 * @see android.graphics.ImageFormat
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002561 */
2562 public List<Integer> getSupportedPictureFormats() {
Wu-cheng Li9c799382009-12-04 19:59:18 +08002563 String str = get(KEY_PICTURE_FORMAT + SUPPORTED_VALUES_SUFFIX);
2564 ArrayList<Integer> formats = new ArrayList<Integer>();
2565 for (String s : split(str)) {
2566 int f = pixelFormatForCameraFormat(s);
Mathias Agopiana696f5d2010-02-17 17:53:09 -08002567 if (f == ImageFormat.UNKNOWN) continue;
Wu-cheng Li9c799382009-12-04 19:59:18 +08002568 formats.add(f);
2569 }
2570 return formats;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002571 }
2572
2573 private String cameraFormatForPixelFormat(int pixel_format) {
2574 switch(pixel_format) {
Mathias Agopiana696f5d2010-02-17 17:53:09 -08002575 case ImageFormat.NV16: return PIXEL_FORMAT_YUV422SP;
2576 case ImageFormat.NV21: return PIXEL_FORMAT_YUV420SP;
2577 case ImageFormat.YUY2: return PIXEL_FORMAT_YUV422I;
Wu-cheng Li10a1b302011-02-22 15:49:25 +08002578 case ImageFormat.YV12: return PIXEL_FORMAT_YUV420P;
Mathias Agopiana696f5d2010-02-17 17:53:09 -08002579 case ImageFormat.RGB_565: return PIXEL_FORMAT_RGB565;
2580 case ImageFormat.JPEG: return PIXEL_FORMAT_JPEG;
Wu-cheng Li70fb9082011-08-02 17:49:50 +08002581 case ImageFormat.BAYER_RGGB: return PIXEL_FORMAT_BAYER_RGGB;
Mathias Agopiana696f5d2010-02-17 17:53:09 -08002582 default: return null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002583 }
2584 }
2585
2586 private int pixelFormatForCameraFormat(String format) {
2587 if (format == null)
Mathias Agopiana696f5d2010-02-17 17:53:09 -08002588 return ImageFormat.UNKNOWN;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002589
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002590 if (format.equals(PIXEL_FORMAT_YUV422SP))
Mathias Agopiana696f5d2010-02-17 17:53:09 -08002591 return ImageFormat.NV16;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002592
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002593 if (format.equals(PIXEL_FORMAT_YUV420SP))
Mathias Agopiana696f5d2010-02-17 17:53:09 -08002594 return ImageFormat.NV21;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002595
Chih-Chung Changeb68c462009-09-18 18:37:44 +08002596 if (format.equals(PIXEL_FORMAT_YUV422I))
Mathias Agopiana696f5d2010-02-17 17:53:09 -08002597 return ImageFormat.YUY2;
Chih-Chung Changeb68c462009-09-18 18:37:44 +08002598
Wu-cheng Li10a1b302011-02-22 15:49:25 +08002599 if (format.equals(PIXEL_FORMAT_YUV420P))
2600 return ImageFormat.YV12;
2601
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002602 if (format.equals(PIXEL_FORMAT_RGB565))
Mathias Agopiana696f5d2010-02-17 17:53:09 -08002603 return ImageFormat.RGB_565;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002604
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002605 if (format.equals(PIXEL_FORMAT_JPEG))
Mathias Agopiana696f5d2010-02-17 17:53:09 -08002606 return ImageFormat.JPEG;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002607
Mathias Agopiana696f5d2010-02-17 17:53:09 -08002608 return ImageFormat.UNKNOWN;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002609 }
2610
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002611 /**
Wu-cheng Li8969ea12012-04-20 17:38:09 +08002612 * Sets the clockwise rotation angle in degrees relative to the
2613 * orientation of the camera. This affects the pictures returned from
2614 * JPEG {@link PictureCallback}. The camera driver may set orientation
2615 * in the EXIF header without rotating the picture. Or the driver may
2616 * rotate the picture and the EXIF thumbnail. If the Jpeg picture is
2617 * rotated, the orientation in the EXIF header will be missing or 1
2618 * (row #0 is top and column #0 is left side).
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002619 *
Brad Fitzpatrick69ea4e12011-01-05 11:13:40 -08002620 * <p>If applications want to rotate the picture to match the orientation
Wu-cheng Li2fe6fca2010-10-15 14:42:23 +08002621 * of what users see, apps should use {@link
Wu-cheng Li2fb818c2010-09-13 20:02:01 -07002622 * android.view.OrientationEventListener} and {@link CameraInfo}.
2623 * The value from OrientationEventListener is relative to the natural
Wu-cheng Li2fe6fca2010-10-15 14:42:23 +08002624 * orientation of the device. CameraInfo.orientation is the angle
Brad Fitzpatrick69ea4e12011-01-05 11:13:40 -08002625 * between camera orientation and natural device orientation. The sum
Wu-cheng Li2fe6fca2010-10-15 14:42:23 +08002626 * of the two is the rotation angle for back-facing camera. The
2627 * difference of the two is the rotation angle for front-facing camera.
2628 * Note that the JPEG pictures of front-facing cameras are not mirrored
2629 * as in preview display.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002630 *
Brad Fitzpatrick69ea4e12011-01-05 11:13:40 -08002631 * <p>For example, suppose the natural orientation of the device is
Wu-cheng Li2fb818c2010-09-13 20:02:01 -07002632 * portrait. The device is rotated 270 degrees clockwise, so the device
Wu-cheng Li2fe6fca2010-10-15 14:42:23 +08002633 * orientation is 270. Suppose a back-facing camera sensor is mounted in
2634 * landscape and the top side of the camera sensor is aligned with the
2635 * right edge of the display in natural orientation. So the camera
2636 * orientation is 90. The rotation should be set to 0 (270 + 90).
Wu-cheng Li2fb818c2010-09-13 20:02:01 -07002637 *
Brad Fitzpatrick69ea4e12011-01-05 11:13:40 -08002638 * <p>The reference code is as follows.
Wu-cheng Li2fb818c2010-09-13 20:02:01 -07002639 *
Eino-Ville Talvalae0cc55a2011-11-08 10:12:09 -08002640 * <pre>
Scott Main9a10bf02011-08-24 19:09:48 -07002641 * public void onOrientationChanged(int orientation) {
Wu-cheng Li2fb818c2010-09-13 20:02:01 -07002642 * if (orientation == ORIENTATION_UNKNOWN) return;
2643 * android.hardware.Camera.CameraInfo info =
2644 * new android.hardware.Camera.CameraInfo();
2645 * android.hardware.Camera.getCameraInfo(cameraId, info);
2646 * orientation = (orientation + 45) / 90 * 90;
Wu-cheng Li2fe6fca2010-10-15 14:42:23 +08002647 * int rotation = 0;
2648 * if (info.facing == CameraInfo.CAMERA_FACING_FRONT) {
2649 * rotation = (info.orientation - orientation + 360) % 360;
2650 * } else { // back-facing camera
2651 * rotation = (info.orientation + orientation) % 360;
2652 * }
2653 * mParameters.setRotation(rotation);
Wu-cheng Li2fb818c2010-09-13 20:02:01 -07002654 * }
Eino-Ville Talvalae0cc55a2011-11-08 10:12:09 -08002655 * </pre>
Wu-cheng Li2fb818c2010-09-13 20:02:01 -07002656 *
2657 * @param rotation The rotation angle in degrees relative to the
2658 * orientation of the camera. Rotation can only be 0,
2659 * 90, 180 or 270.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002660 * @throws IllegalArgumentException if rotation value is invalid.
2661 * @see android.view.OrientationEventListener
Wu-cheng Li2fb818c2010-09-13 20:02:01 -07002662 * @see #getCameraInfo(int, CameraInfo)
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002663 */
2664 public void setRotation(int rotation) {
2665 if (rotation == 0 || rotation == 90 || rotation == 180
2666 || rotation == 270) {
2667 set(KEY_ROTATION, Integer.toString(rotation));
2668 } else {
2669 throw new IllegalArgumentException(
2670 "Invalid rotation=" + rotation);
2671 }
2672 }
2673
2674 /**
2675 * Sets GPS latitude coordinate. This will be stored in JPEG EXIF
2676 * header.
2677 *
2678 * @param latitude GPS latitude coordinate.
2679 */
2680 public void setGpsLatitude(double latitude) {
2681 set(KEY_GPS_LATITUDE, Double.toString(latitude));
2682 }
2683
2684 /**
2685 * Sets GPS longitude coordinate. This will be stored in JPEG EXIF
2686 * header.
2687 *
2688 * @param longitude GPS longitude coordinate.
2689 */
2690 public void setGpsLongitude(double longitude) {
2691 set(KEY_GPS_LONGITUDE, Double.toString(longitude));
2692 }
2693
2694 /**
2695 * Sets GPS altitude. This will be stored in JPEG EXIF header.
2696 *
2697 * @param altitude GPS altitude in meters.
2698 */
2699 public void setGpsAltitude(double altitude) {
2700 set(KEY_GPS_ALTITUDE, Double.toString(altitude));
2701 }
2702
2703 /**
2704 * Sets GPS timestamp. This will be stored in JPEG EXIF header.
2705 *
2706 * @param timestamp GPS timestamp (UTC in seconds since January 1,
2707 * 1970).
2708 */
2709 public void setGpsTimestamp(long timestamp) {
2710 set(KEY_GPS_TIMESTAMP, Long.toString(timestamp));
2711 }
2712
2713 /**
Ray Chene2083772010-03-10 15:02:49 -08002714 * Sets GPS processing method. It will store up to 32 characters
Ray Chen055c9862010-02-23 10:45:42 +08002715 * in JPEG EXIF header.
2716 *
2717 * @param processing_method The processing method to get this location.
2718 */
2719 public void setGpsProcessingMethod(String processing_method) {
2720 set(KEY_GPS_PROCESSING_METHOD, processing_method);
2721 }
2722
2723 /**
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002724 * Removes GPS latitude, longitude, altitude, and timestamp from the
2725 * parameters.
2726 */
2727 public void removeGpsData() {
2728 remove(KEY_GPS_LATITUDE);
2729 remove(KEY_GPS_LONGITUDE);
2730 remove(KEY_GPS_ALTITUDE);
2731 remove(KEY_GPS_TIMESTAMP);
Ray Chen055c9862010-02-23 10:45:42 +08002732 remove(KEY_GPS_PROCESSING_METHOD);
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002733 }
2734
2735 /**
2736 * Gets the current white balance setting.
2737 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08002738 * @return current white balance. null if white balance setting is not
2739 * supported.
2740 * @see #WHITE_BALANCE_AUTO
2741 * @see #WHITE_BALANCE_INCANDESCENT
2742 * @see #WHITE_BALANCE_FLUORESCENT
2743 * @see #WHITE_BALANCE_WARM_FLUORESCENT
2744 * @see #WHITE_BALANCE_DAYLIGHT
2745 * @see #WHITE_BALANCE_CLOUDY_DAYLIGHT
2746 * @see #WHITE_BALANCE_TWILIGHT
2747 * @see #WHITE_BALANCE_SHADE
2748 *
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002749 */
2750 public String getWhiteBalance() {
2751 return get(KEY_WHITE_BALANCE);
2752 }
2753
2754 /**
Eino-Ville Talvala16b67132011-08-18 13:57:49 -07002755 * Sets the white balance. Changing the setting will release the
Wu-cheng Lib838d8d2011-11-17 20:12:23 +08002756 * auto-white balance lock. It is recommended not to change white
2757 * balance and AWB lock at the same time.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002758 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08002759 * @param value new white balance.
2760 * @see #getWhiteBalance()
Eino-Ville Talvala037abb82011-10-11 12:41:58 -07002761 * @see #setAutoWhiteBalanceLock(boolean)
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002762 */
2763 public void setWhiteBalance(String value) {
Wu-cheng Lib838d8d2011-11-17 20:12:23 +08002764 String oldValue = get(KEY_WHITE_BALANCE);
2765 if (same(value, oldValue)) return;
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002766 set(KEY_WHITE_BALANCE, value);
Eino-Ville Talvala16b67132011-08-18 13:57:49 -07002767 set(KEY_AUTO_WHITEBALANCE_LOCK, FALSE);
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002768 }
2769
2770 /**
2771 * Gets the supported white balance.
2772 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08002773 * @return a list of supported white balance. null if white balance
2774 * setting is not supported.
2775 * @see #getWhiteBalance()
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002776 */
2777 public List<String> getSupportedWhiteBalance() {
2778 String str = get(KEY_WHITE_BALANCE + SUPPORTED_VALUES_SUFFIX);
2779 return split(str);
2780 }
2781
2782 /**
2783 * Gets the current color effect setting.
2784 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08002785 * @return current color effect. null if color effect
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002786 * setting is not supported.
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08002787 * @see #EFFECT_NONE
2788 * @see #EFFECT_MONO
2789 * @see #EFFECT_NEGATIVE
2790 * @see #EFFECT_SOLARIZE
2791 * @see #EFFECT_SEPIA
2792 * @see #EFFECT_POSTERIZE
2793 * @see #EFFECT_WHITEBOARD
2794 * @see #EFFECT_BLACKBOARD
2795 * @see #EFFECT_AQUA
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002796 */
2797 public String getColorEffect() {
2798 return get(KEY_EFFECT);
2799 }
2800
2801 /**
2802 * Sets the current color effect setting.
2803 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08002804 * @param value new color effect.
2805 * @see #getColorEffect()
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002806 */
2807 public void setColorEffect(String value) {
2808 set(KEY_EFFECT, value);
2809 }
2810
2811 /**
2812 * Gets the supported color effects.
2813 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08002814 * @return a list of supported color effects. null if color effect
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002815 * setting is not supported.
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08002816 * @see #getColorEffect()
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002817 */
2818 public List<String> getSupportedColorEffects() {
2819 String str = get(KEY_EFFECT + SUPPORTED_VALUES_SUFFIX);
2820 return split(str);
2821 }
2822
2823
2824 /**
2825 * Gets the current antibanding setting.
2826 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08002827 * @return current antibanding. null if antibanding setting is not
2828 * supported.
2829 * @see #ANTIBANDING_AUTO
2830 * @see #ANTIBANDING_50HZ
2831 * @see #ANTIBANDING_60HZ
2832 * @see #ANTIBANDING_OFF
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002833 */
2834 public String getAntibanding() {
2835 return get(KEY_ANTIBANDING);
2836 }
2837
2838 /**
2839 * Sets the antibanding.
2840 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08002841 * @param antibanding new antibanding value.
2842 * @see #getAntibanding()
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002843 */
2844 public void setAntibanding(String antibanding) {
2845 set(KEY_ANTIBANDING, antibanding);
2846 }
2847
2848 /**
2849 * Gets the supported antibanding values.
2850 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08002851 * @return a list of supported antibanding values. null if antibanding
2852 * setting is not supported.
2853 * @see #getAntibanding()
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002854 */
2855 public List<String> getSupportedAntibanding() {
2856 String str = get(KEY_ANTIBANDING + SUPPORTED_VALUES_SUFFIX);
2857 return split(str);
2858 }
2859
2860 /**
2861 * Gets the current scene mode setting.
2862 *
2863 * @return one of SCENE_MODE_XXX string constant. null if scene mode
2864 * setting is not supported.
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08002865 * @see #SCENE_MODE_AUTO
2866 * @see #SCENE_MODE_ACTION
2867 * @see #SCENE_MODE_PORTRAIT
2868 * @see #SCENE_MODE_LANDSCAPE
2869 * @see #SCENE_MODE_NIGHT
2870 * @see #SCENE_MODE_NIGHT_PORTRAIT
2871 * @see #SCENE_MODE_THEATRE
2872 * @see #SCENE_MODE_BEACH
2873 * @see #SCENE_MODE_SNOW
2874 * @see #SCENE_MODE_SUNSET
2875 * @see #SCENE_MODE_STEADYPHOTO
2876 * @see #SCENE_MODE_FIREWORKS
2877 * @see #SCENE_MODE_SPORTS
2878 * @see #SCENE_MODE_PARTY
2879 * @see #SCENE_MODE_CANDLELIGHT
Eino-Ville Talvalada2f0ea2012-09-10 12:03:35 -07002880 * @see #SCENE_MODE_BARCODE
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002881 */
2882 public String getSceneMode() {
2883 return get(KEY_SCENE_MODE);
2884 }
2885
2886 /**
Wu-cheng Lic58b4232010-03-29 17:21:28 +08002887 * Sets the scene mode. Changing scene mode may override other
2888 * parameters (such as flash mode, focus mode, white balance). For
2889 * example, suppose originally flash mode is on and supported flash
2890 * modes are on/off. In night scene mode, both flash mode and supported
2891 * flash mode may be changed to off. After setting scene mode,
Wu-cheng Li2988ab72009-09-30 17:08:19 -07002892 * applications should call getParameters to know if some parameters are
2893 * changed.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002894 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08002895 * @param value scene mode.
2896 * @see #getSceneMode()
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002897 */
2898 public void setSceneMode(String value) {
2899 set(KEY_SCENE_MODE, value);
2900 }
2901
2902 /**
2903 * Gets the supported scene modes.
2904 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08002905 * @return a list of supported scene modes. null if scene mode setting
2906 * is not supported.
2907 * @see #getSceneMode()
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002908 */
2909 public List<String> getSupportedSceneModes() {
2910 String str = get(KEY_SCENE_MODE + SUPPORTED_VALUES_SUFFIX);
2911 return split(str);
2912 }
2913
2914 /**
2915 * Gets the current flash mode setting.
2916 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08002917 * @return current flash mode. null if flash mode setting is not
2918 * supported.
2919 * @see #FLASH_MODE_OFF
2920 * @see #FLASH_MODE_AUTO
2921 * @see #FLASH_MODE_ON
2922 * @see #FLASH_MODE_RED_EYE
2923 * @see #FLASH_MODE_TORCH
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002924 */
2925 public String getFlashMode() {
2926 return get(KEY_FLASH_MODE);
2927 }
2928
2929 /**
2930 * Sets the flash mode.
2931 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08002932 * @param value flash mode.
2933 * @see #getFlashMode()
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002934 */
2935 public void setFlashMode(String value) {
2936 set(KEY_FLASH_MODE, value);
2937 }
2938
2939 /**
2940 * Gets the supported flash modes.
2941 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08002942 * @return a list of supported flash modes. null if flash mode setting
2943 * is not supported.
2944 * @see #getFlashMode()
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002945 */
2946 public List<String> getSupportedFlashModes() {
2947 String str = get(KEY_FLASH_MODE + SUPPORTED_VALUES_SUFFIX);
2948 return split(str);
2949 }
2950
Wu-cheng Li36322db2009-09-18 18:59:21 +08002951 /**
2952 * Gets the current focus mode setting.
2953 *
Wu-cheng Li699fe932010-08-05 11:50:25 -07002954 * @return current focus mode. This method will always return a non-null
2955 * value. Applications should call {@link
2956 * #autoFocus(AutoFocusCallback)} to start the focus if focus
2957 * mode is FOCUS_MODE_AUTO or FOCUS_MODE_MACRO.
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08002958 * @see #FOCUS_MODE_AUTO
2959 * @see #FOCUS_MODE_INFINITY
2960 * @see #FOCUS_MODE_MACRO
2961 * @see #FOCUS_MODE_FIXED
Wu-cheng Lif008f3e2010-08-17 13:44:35 -07002962 * @see #FOCUS_MODE_EDOF
Wu-cheng Lid45cb722010-09-20 16:15:32 -07002963 * @see #FOCUS_MODE_CONTINUOUS_VIDEO
Wu-cheng Li36322db2009-09-18 18:59:21 +08002964 */
2965 public String getFocusMode() {
2966 return get(KEY_FOCUS_MODE);
2967 }
2968
2969 /**
2970 * Sets the focus mode.
2971 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08002972 * @param value focus mode.
2973 * @see #getFocusMode()
Wu-cheng Li36322db2009-09-18 18:59:21 +08002974 */
2975 public void setFocusMode(String value) {
2976 set(KEY_FOCUS_MODE, value);
2977 }
2978
2979 /**
2980 * Gets the supported focus modes.
2981 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08002982 * @return a list of supported focus modes. This method will always
2983 * return a list with at least one element.
2984 * @see #getFocusMode()
Wu-cheng Li36322db2009-09-18 18:59:21 +08002985 */
2986 public List<String> getSupportedFocusModes() {
2987 String str = get(KEY_FOCUS_MODE + SUPPORTED_VALUES_SUFFIX);
2988 return split(str);
2989 }
2990
Wu-cheng Li36f68b82009-09-28 16:14:58 -07002991 /**
Wu-cheng Li6c8d2762010-01-27 22:55:14 +08002992 * Gets the focal length (in millimeter) of the camera.
2993 *
2994 * @return the focal length. This method will always return a valid
2995 * value.
2996 */
2997 public float getFocalLength() {
2998 return Float.parseFloat(get(KEY_FOCAL_LENGTH));
2999 }
3000
3001 /**
3002 * Gets the horizontal angle of view in degrees.
3003 *
3004 * @return horizontal angle of view. This method will always return a
3005 * valid value.
3006 */
3007 public float getHorizontalViewAngle() {
3008 return Float.parseFloat(get(KEY_HORIZONTAL_VIEW_ANGLE));
3009 }
3010
3011 /**
3012 * Gets the vertical angle of view in degrees.
3013 *
3014 * @return vertical angle of view. This method will always return a
3015 * valid value.
3016 */
3017 public float getVerticalViewAngle() {
3018 return Float.parseFloat(get(KEY_VERTICAL_VIEW_ANGLE));
3019 }
3020
3021 /**
Wu-cheng Li24b326a2010-02-20 17:47:04 +08003022 * Gets the current exposure compensation index.
Wu-cheng Liff723b62010-02-09 13:38:19 +08003023 *
Wu-cheng Li24b326a2010-02-20 17:47:04 +08003024 * @return current exposure compensation index. The range is {@link
3025 * #getMinExposureCompensation} to {@link
3026 * #getMaxExposureCompensation}. 0 means exposure is not
3027 * adjusted.
Wu-cheng Liff723b62010-02-09 13:38:19 +08003028 */
3029 public int getExposureCompensation() {
Wu-cheng Li24b326a2010-02-20 17:47:04 +08003030 return getInt(KEY_EXPOSURE_COMPENSATION, 0);
Wu-cheng Liff723b62010-02-09 13:38:19 +08003031 }
3032
3033 /**
Wu-cheng Li24b326a2010-02-20 17:47:04 +08003034 * Sets the exposure compensation index.
Wu-cheng Liff723b62010-02-09 13:38:19 +08003035 *
Wu-cheng Li0402e7d2010-02-26 15:04:55 +08003036 * @param value exposure compensation index. The valid value range is
3037 * from {@link #getMinExposureCompensation} (inclusive) to {@link
Wu-cheng Li24b326a2010-02-20 17:47:04 +08003038 * #getMaxExposureCompensation} (inclusive). 0 means exposure is
3039 * not adjusted. Application should call
3040 * getMinExposureCompensation and getMaxExposureCompensation to
3041 * know if exposure compensation is supported.
Wu-cheng Liff723b62010-02-09 13:38:19 +08003042 */
3043 public void setExposureCompensation(int value) {
3044 set(KEY_EXPOSURE_COMPENSATION, value);
3045 }
3046
3047 /**
Wu-cheng Li24b326a2010-02-20 17:47:04 +08003048 * Gets the maximum exposure compensation index.
Wu-cheng Liff723b62010-02-09 13:38:19 +08003049 *
Wu-cheng Li24b326a2010-02-20 17:47:04 +08003050 * @return maximum exposure compensation index (>=0). If both this
3051 * method and {@link #getMinExposureCompensation} return 0,
3052 * exposure compensation is not supported.
Wu-cheng Liff723b62010-02-09 13:38:19 +08003053 */
Wu-cheng Li24b326a2010-02-20 17:47:04 +08003054 public int getMaxExposureCompensation() {
3055 return getInt(KEY_MAX_EXPOSURE_COMPENSATION, 0);
3056 }
3057
3058 /**
3059 * Gets the minimum exposure compensation index.
3060 *
3061 * @return minimum exposure compensation index (<=0). If both this
3062 * method and {@link #getMaxExposureCompensation} return 0,
3063 * exposure compensation is not supported.
3064 */
3065 public int getMinExposureCompensation() {
3066 return getInt(KEY_MIN_EXPOSURE_COMPENSATION, 0);
3067 }
3068
3069 /**
3070 * Gets the exposure compensation step.
3071 *
3072 * @return exposure compensation step. Applications can get EV by
3073 * multiplying the exposure compensation index and step. Ex: if
3074 * exposure compensation index is -6 and step is 0.333333333, EV
3075 * is -2.
3076 */
3077 public float getExposureCompensationStep() {
3078 return getFloat(KEY_EXPOSURE_COMPENSATION_STEP, 0);
Wu-cheng Liff723b62010-02-09 13:38:19 +08003079 }
3080
3081 /**
Eino-Ville Talvalad9c2601a2011-05-13 10:19:59 -07003082 * <p>Sets the auto-exposure lock state. Applications should check
3083 * {@link #isAutoExposureLockSupported} before using this method.</p>
Eino-Ville Talvala3773eef2011-04-15 13:51:42 -07003084 *
Eino-Ville Talvalad9c2601a2011-05-13 10:19:59 -07003085 * <p>If set to true, the camera auto-exposure routine will immediately
3086 * pause until the lock is set to false. Exposure compensation settings
3087 * changes will still take effect while auto-exposure is locked.</p>
3088 *
3089 * <p>If auto-exposure is already locked, setting this to true again has
3090 * no effect (the driver will not recalculate exposure values).</p>
3091 *
3092 * <p>Stopping preview with {@link #stopPreview()}, or triggering still
3093 * image capture with {@link #takePicture(Camera.ShutterCallback,
Wu-cheng Lib4f95be2011-09-22 11:43:28 +08003094 * Camera.PictureCallback, Camera.PictureCallback)}, will not change the
3095 * lock.</p>
Eino-Ville Talvalad9c2601a2011-05-13 10:19:59 -07003096 *
Wu-cheng Lib4f95be2011-09-22 11:43:28 +08003097 * <p>Exposure compensation, auto-exposure lock, and auto-white balance
3098 * lock can be used to capture an exposure-bracketed burst of images,
3099 * for example.</p>
Eino-Ville Talvalad9c2601a2011-05-13 10:19:59 -07003100 *
3101 * <p>Auto-exposure state, including the lock state, will not be
Eino-Ville Talvala3773eef2011-04-15 13:51:42 -07003102 * maintained after camera {@link #release()} is called. Locking
3103 * auto-exposure after {@link #open()} but before the first call to
3104 * {@link #startPreview()} will not allow the auto-exposure routine to
Eino-Ville Talvalad9c2601a2011-05-13 10:19:59 -07003105 * run at all, and may result in severely over- or under-exposed
3106 * images.</p>
Eino-Ville Talvala3773eef2011-04-15 13:51:42 -07003107 *
Eino-Ville Talvala3773eef2011-04-15 13:51:42 -07003108 * @param toggle new state of the auto-exposure lock. True means that
3109 * auto-exposure is locked, false means that the auto-exposure
3110 * routine is free to run normally.
3111 *
Eino-Ville Talvalad9c2601a2011-05-13 10:19:59 -07003112 * @see #getAutoExposureLock()
Eino-Ville Talvala3773eef2011-04-15 13:51:42 -07003113 */
3114 public void setAutoExposureLock(boolean toggle) {
3115 set(KEY_AUTO_EXPOSURE_LOCK, toggle ? TRUE : FALSE);
3116 }
3117
3118 /**
3119 * Gets the state of the auto-exposure lock. Applications should check
3120 * {@link #isAutoExposureLockSupported} before using this method. See
3121 * {@link #setAutoExposureLock} for details about the lock.
3122 *
3123 * @return State of the auto-exposure lock. Returns true if
Wu-cheng Lib4f95be2011-09-22 11:43:28 +08003124 * auto-exposure is currently locked, and false otherwise.
Eino-Ville Talvala3773eef2011-04-15 13:51:42 -07003125 *
3126 * @see #setAutoExposureLock(boolean)
3127 *
Eino-Ville Talvala3773eef2011-04-15 13:51:42 -07003128 */
3129 public boolean getAutoExposureLock() {
3130 String str = get(KEY_AUTO_EXPOSURE_LOCK);
3131 return TRUE.equals(str);
3132 }
3133
3134 /**
3135 * Returns true if auto-exposure locking is supported. Applications
3136 * should call this before trying to lock auto-exposure. See
3137 * {@link #setAutoExposureLock} for details about the lock.
3138 *
3139 * @return true if auto-exposure lock is supported.
3140 * @see #setAutoExposureLock(boolean)
3141 *
Eino-Ville Talvala3773eef2011-04-15 13:51:42 -07003142 */
3143 public boolean isAutoExposureLockSupported() {
3144 String str = get(KEY_AUTO_EXPOSURE_LOCK_SUPPORTED);
3145 return TRUE.equals(str);
3146 }
3147
3148 /**
Eino-Ville Talvalad9c2601a2011-05-13 10:19:59 -07003149 * <p>Sets the auto-white balance lock state. Applications should check
3150 * {@link #isAutoWhiteBalanceLockSupported} before using this
3151 * method.</p>
3152 *
3153 * <p>If set to true, the camera auto-white balance routine will
3154 * immediately pause until the lock is set to false.</p>
3155 *
3156 * <p>If auto-white balance is already locked, setting this to true
3157 * again has no effect (the driver will not recalculate white balance
3158 * values).</p>
3159 *
3160 * <p>Stopping preview with {@link #stopPreview()}, or triggering still
3161 * image capture with {@link #takePicture(Camera.ShutterCallback,
Wu-cheng Lib4f95be2011-09-22 11:43:28 +08003162 * Camera.PictureCallback, Camera.PictureCallback)}, will not change the
3163 * the lock.</p>
Eino-Ville Talvalad9c2601a2011-05-13 10:19:59 -07003164 *
Eino-Ville Talvala16b67132011-08-18 13:57:49 -07003165 * <p> Changing the white balance mode with {@link #setWhiteBalance}
3166 * will release the auto-white balance lock if it is set.</p>
3167 *
Wu-cheng Lib4f95be2011-09-22 11:43:28 +08003168 * <p>Exposure compensation, AE lock, and AWB lock can be used to
3169 * capture an exposure-bracketed burst of images, for example.
3170 * Auto-white balance state, including the lock state, will not be
3171 * maintained after camera {@link #release()} is called. Locking
3172 * auto-white balance after {@link #open()} but before the first call to
3173 * {@link #startPreview()} will not allow the auto-white balance routine
3174 * to run at all, and may result in severely incorrect color in captured
3175 * images.</p>
Eino-Ville Talvalad9c2601a2011-05-13 10:19:59 -07003176 *
3177 * @param toggle new state of the auto-white balance lock. True means
3178 * that auto-white balance is locked, false means that the
3179 * auto-white balance routine is free to run normally.
3180 *
3181 * @see #getAutoWhiteBalanceLock()
Eino-Ville Talvala16b67132011-08-18 13:57:49 -07003182 * @see #setWhiteBalance(String)
Eino-Ville Talvalad9c2601a2011-05-13 10:19:59 -07003183 */
3184 public void setAutoWhiteBalanceLock(boolean toggle) {
3185 set(KEY_AUTO_WHITEBALANCE_LOCK, toggle ? TRUE : FALSE);
3186 }
3187
3188 /**
3189 * Gets the state of the auto-white balance lock. Applications should
3190 * check {@link #isAutoWhiteBalanceLockSupported} before using this
3191 * method. See {@link #setAutoWhiteBalanceLock} for details about the
3192 * lock.
3193 *
3194 * @return State of the auto-white balance lock. Returns true if
3195 * auto-white balance is currently locked, and false
Wu-cheng Lib4f95be2011-09-22 11:43:28 +08003196 * otherwise.
Eino-Ville Talvalad9c2601a2011-05-13 10:19:59 -07003197 *
3198 * @see #setAutoWhiteBalanceLock(boolean)
3199 *
Eino-Ville Talvalad9c2601a2011-05-13 10:19:59 -07003200 */
3201 public boolean getAutoWhiteBalanceLock() {
3202 String str = get(KEY_AUTO_WHITEBALANCE_LOCK);
3203 return TRUE.equals(str);
3204 }
3205
3206 /**
3207 * Returns true if auto-white balance locking is supported. Applications
3208 * should call this before trying to lock auto-white balance. See
3209 * {@link #setAutoWhiteBalanceLock} for details about the lock.
3210 *
3211 * @return true if auto-white balance lock is supported.
3212 * @see #setAutoWhiteBalanceLock(boolean)
3213 *
Eino-Ville Talvalad9c2601a2011-05-13 10:19:59 -07003214 */
3215 public boolean isAutoWhiteBalanceLockSupported() {
3216 String str = get(KEY_AUTO_WHITEBALANCE_LOCK_SUPPORTED);
3217 return TRUE.equals(str);
3218 }
3219
3220 /**
Wu-cheng Li36f68b82009-09-28 16:14:58 -07003221 * Gets current zoom value. This also works when smooth zoom is in
Wu-cheng Li8cbb8f52010-02-28 23:19:55 -08003222 * progress. Applications should check {@link #isZoomSupported} before
3223 * using this method.
Wu-cheng Li36f68b82009-09-28 16:14:58 -07003224 *
3225 * @return the current zoom value. The range is 0 to {@link
Wu-cheng Li8cbb8f52010-02-28 23:19:55 -08003226 * #getMaxZoom}. 0 means the camera is not zoomed.
Wu-cheng Li36f68b82009-09-28 16:14:58 -07003227 */
3228 public int getZoom() {
Wu-cheng Li8cbb8f52010-02-28 23:19:55 -08003229 return getInt(KEY_ZOOM, 0);
Wu-cheng Li36f68b82009-09-28 16:14:58 -07003230 }
3231
3232 /**
Wu-cheng Li8cbb8f52010-02-28 23:19:55 -08003233 * Sets current zoom value. If the camera is zoomed (value > 0), the
3234 * actual picture size may be smaller than picture size setting.
3235 * Applications can check the actual picture size after picture is
3236 * returned from {@link PictureCallback}. The preview size remains the
3237 * same in zoom. Applications should check {@link #isZoomSupported}
3238 * before using this method.
Wu-cheng Li36f68b82009-09-28 16:14:58 -07003239 *
3240 * @param value zoom value. The valid range is 0 to {@link #getMaxZoom}.
Wu-cheng Li36f68b82009-09-28 16:14:58 -07003241 */
3242 public void setZoom(int value) {
Wu-cheng Li8cbb8f52010-02-28 23:19:55 -08003243 set(KEY_ZOOM, value);
Wu-cheng Li36f68b82009-09-28 16:14:58 -07003244 }
3245
3246 /**
3247 * Returns true if zoom is supported. Applications should call this
3248 * before using other zoom methods.
3249 *
3250 * @return true if zoom is supported.
Wu-cheng Li36f68b82009-09-28 16:14:58 -07003251 */
3252 public boolean isZoomSupported() {
Wu-cheng Li8cbb8f52010-02-28 23:19:55 -08003253 String str = get(KEY_ZOOM_SUPPORTED);
3254 return TRUE.equals(str);
Wu-cheng Li36f68b82009-09-28 16:14:58 -07003255 }
3256
3257 /**
3258 * Gets the maximum zoom value allowed for snapshot. This is the maximum
3259 * value that applications can set to {@link #setZoom(int)}.
Wu-cheng Li8cbb8f52010-02-28 23:19:55 -08003260 * Applications should call {@link #isZoomSupported} before using this
3261 * method. This value may change in different preview size. Applications
3262 * should call this again after setting preview size.
Wu-cheng Li36f68b82009-09-28 16:14:58 -07003263 *
3264 * @return the maximum zoom value supported by the camera.
Wu-cheng Li36f68b82009-09-28 16:14:58 -07003265 */
3266 public int getMaxZoom() {
Wu-cheng Li8cbb8f52010-02-28 23:19:55 -08003267 return getInt(KEY_MAX_ZOOM, 0);
Wu-cheng Li36f68b82009-09-28 16:14:58 -07003268 }
3269
3270 /**
Wu-cheng Li8cbb8f52010-02-28 23:19:55 -08003271 * Gets the zoom ratios of all zoom values. Applications should check
3272 * {@link #isZoomSupported} before using this method.
Wu-cheng Li36f68b82009-09-28 16:14:58 -07003273 *
Wu-cheng Li8cbb8f52010-02-28 23:19:55 -08003274 * @return the zoom ratios in 1/100 increments. Ex: a zoom of 3.2x is
3275 * returned as 320. The number of elements is {@link
3276 * #getMaxZoom} + 1. The list is sorted from small to large. The
3277 * first element is always 100. The last element is the zoom
3278 * ratio of the maximum zoom value.
Wu-cheng Li36f68b82009-09-28 16:14:58 -07003279 */
Wu-cheng Li8cbb8f52010-02-28 23:19:55 -08003280 public List<Integer> getZoomRatios() {
3281 return splitInt(get(KEY_ZOOM_RATIOS));
Wu-cheng Li36f68b82009-09-28 16:14:58 -07003282 }
3283
3284 /**
3285 * Returns true if smooth zoom is supported. Applications should call
3286 * this before using other smooth zoom methods.
3287 *
3288 * @return true if smooth zoom is supported.
Wu-cheng Li36f68b82009-09-28 16:14:58 -07003289 */
3290 public boolean isSmoothZoomSupported() {
Wu-cheng Li8cbb8f52010-02-28 23:19:55 -08003291 String str = get(KEY_SMOOTH_ZOOM_SUPPORTED);
3292 return TRUE.equals(str);
Wu-cheng Li36f68b82009-09-28 16:14:58 -07003293 }
3294
Wu-cheng Lie339c5e2010-05-13 19:31:02 +08003295 /**
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07003296 * <p>Gets the distances from the camera to where an object appears to be
Wu-cheng Lie339c5e2010-05-13 19:31:02 +08003297 * in focus. The object is sharpest at the optimal focus distance. The
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07003298 * depth of field is the far focus distance minus near focus distance.</p>
Wu-cheng Lie339c5e2010-05-13 19:31:02 +08003299 *
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07003300 * <p>Focus distances may change after calling {@link
Wu-cheng Lie339c5e2010-05-13 19:31:02 +08003301 * #autoFocus(AutoFocusCallback)}, {@link #cancelAutoFocus}, or {@link
3302 * #startPreview()}. Applications can call {@link #getParameters()}
3303 * and this method anytime to get the latest focus distances. If the
Wu-cheng Lid45cb722010-09-20 16:15:32 -07003304 * focus mode is FOCUS_MODE_CONTINUOUS_VIDEO, focus distances may change
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07003305 * from time to time.</p>
Wu-cheng Li699fe932010-08-05 11:50:25 -07003306 *
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07003307 * <p>This method is intended to estimate the distance between the camera
Wu-cheng Li699fe932010-08-05 11:50:25 -07003308 * and the subject. After autofocus, the subject distance may be within
3309 * near and far focus distance. However, the precision depends on the
3310 * camera hardware, autofocus algorithm, the focus area, and the scene.
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07003311 * The error can be large and it should be only used as a reference.</p>
Wu-cheng Lie339c5e2010-05-13 19:31:02 +08003312 *
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07003313 * <p>Far focus distance >= optimal focus distance >= near focus distance.
Wu-cheng Li185cc452010-05-20 15:36:13 +08003314 * If the focus distance is infinity, the value will be
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07003315 * {@code Float.POSITIVE_INFINITY}.</p>
Wu-cheng Lie339c5e2010-05-13 19:31:02 +08003316 *
3317 * @param output focus distances in meters. output must be a float
3318 * array with three elements. Near focus distance, optimal focus
3319 * distance, and far focus distance will be filled in the array.
Wu-cheng Li185cc452010-05-20 15:36:13 +08003320 * @see #FOCUS_DISTANCE_NEAR_INDEX
3321 * @see #FOCUS_DISTANCE_OPTIMAL_INDEX
3322 * @see #FOCUS_DISTANCE_FAR_INDEX
Wu-cheng Lie339c5e2010-05-13 19:31:02 +08003323 */
3324 public void getFocusDistances(float[] output) {
3325 if (output == null || output.length != 3) {
3326 throw new IllegalArgumentException(
Ken Wakasaf76a50c2012-03-09 19:56:35 +09003327 "output must be a float array with three elements.");
Wu-cheng Lie339c5e2010-05-13 19:31:02 +08003328 }
Wu-cheng Li454630f2010-08-11 16:48:05 -07003329 splitFloat(get(KEY_FOCUS_DISTANCES), output);
Wu-cheng Lie339c5e2010-05-13 19:31:02 +08003330 }
3331
Wu-cheng Li30771b72011-04-02 06:19:46 +08003332 /**
3333 * Gets the maximum number of focus areas supported. This is the maximum
Wu-cheng Li7b1c5c82011-04-15 19:16:52 +08003334 * length of the list in {@link #setFocusAreas(List)} and
3335 * {@link #getFocusAreas()}.
Wu-cheng Li30771b72011-04-02 06:19:46 +08003336 *
3337 * @return the maximum number of focus areas supported by the camera.
3338 * @see #getFocusAreas()
Wu-cheng Li30771b72011-04-02 06:19:46 +08003339 */
3340 public int getMaxNumFocusAreas() {
3341 return getInt(KEY_MAX_NUM_FOCUS_AREAS, 0);
3342 }
3343
3344 /**
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07003345 * <p>Gets the current focus areas. Camera driver uses the areas to decide
3346 * focus.</p>
Wu-cheng Li30771b72011-04-02 06:19:46 +08003347 *
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07003348 * <p>Before using this API or {@link #setFocusAreas(List)}, apps should
Wu-cheng Li7b1c5c82011-04-15 19:16:52 +08003349 * call {@link #getMaxNumFocusAreas()} to know the maximum number of
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07003350 * focus areas first. If the value is 0, focus area is not supported.</p>
Wu-cheng Li30771b72011-04-02 06:19:46 +08003351 *
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07003352 * <p>Each focus area is a rectangle with specified weight. The direction
Wu-cheng Li30771b72011-04-02 06:19:46 +08003353 * is relative to the sensor orientation, that is, what the sensor sees.
3354 * The direction is not affected by the rotation or mirroring of
3355 * {@link #setDisplayOrientation(int)}. Coordinates of the rectangle
3356 * range from -1000 to 1000. (-1000, -1000) is the upper left point.
Wu-cheng Libde61a52011-06-07 18:23:14 +08003357 * (1000, 1000) is the lower right point. The width and height of focus
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07003358 * areas cannot be 0 or negative.</p>
Wu-cheng Li30771b72011-04-02 06:19:46 +08003359 *
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07003360 * <p>The weight must range from 1 to 1000. The weight should be
Eino-Ville Talvala4e396e02011-04-21 09:23:15 -07003361 * interpreted as a per-pixel weight - all pixels in the area have the
3362 * specified weight. This means a small area with the same weight as a
3363 * larger area will have less influence on the focusing than the larger
3364 * area. Focus areas can partially overlap and the driver will add the
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07003365 * weights in the overlap region.</p>
Wu-cheng Li30771b72011-04-02 06:19:46 +08003366 *
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07003367 * <p>A special case of a {@code null} focus area list means the driver is
3368 * free to select focus targets as it wants. For example, the driver may
3369 * use more signals to select focus areas and change them
3370 * dynamically. Apps can set the focus area list to {@code null} if they
3371 * want the driver to completely control focusing.</p>
Wu-cheng Li30771b72011-04-02 06:19:46 +08003372 *
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07003373 * <p>Focus areas are relative to the current field of view
Wu-cheng Li30771b72011-04-02 06:19:46 +08003374 * ({@link #getZoom()}). No matter what the zoom level is, (-1000,-1000)
3375 * represents the top of the currently visible camera frame. The focus
3376 * area cannot be set to be outside the current field of view, even
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07003377 * when using zoom.</p>
Wu-cheng Li30771b72011-04-02 06:19:46 +08003378 *
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07003379 * <p>Focus area only has effect if the current focus mode is
Wu-cheng Li53b30912011-10-12 19:43:51 +08003380 * {@link #FOCUS_MODE_AUTO}, {@link #FOCUS_MODE_MACRO},
3381 * {@link #FOCUS_MODE_CONTINUOUS_VIDEO}, or
3382 * {@link #FOCUS_MODE_CONTINUOUS_PICTURE}.</p>
Wu-cheng Li30771b72011-04-02 06:19:46 +08003383 *
3384 * @return a list of current focus areas
Wu-cheng Li30771b72011-04-02 06:19:46 +08003385 */
3386 public List<Area> getFocusAreas() {
Wu-cheng Lif715bf92011-04-14 14:04:18 +08003387 return splitArea(get(KEY_FOCUS_AREAS));
Wu-cheng Li30771b72011-04-02 06:19:46 +08003388 }
3389
3390 /**
3391 * Sets focus areas. See {@link #getFocusAreas()} for documentation.
3392 *
Wu-cheng Li7b1c5c82011-04-15 19:16:52 +08003393 * @param focusAreas the focus areas
Wu-cheng Li30771b72011-04-02 06:19:46 +08003394 * @see #getFocusAreas()
Wu-cheng Li30771b72011-04-02 06:19:46 +08003395 */
Wu-cheng Lie98e4c82011-04-12 19:34:29 +08003396 public void setFocusAreas(List<Area> focusAreas) {
3397 set(KEY_FOCUS_AREAS, focusAreas);
3398 }
3399
3400 /**
3401 * Gets the maximum number of metering areas supported. This is the
Wu-cheng Li7b1c5c82011-04-15 19:16:52 +08003402 * maximum length of the list in {@link #setMeteringAreas(List)} and
3403 * {@link #getMeteringAreas()}.
Wu-cheng Lie98e4c82011-04-12 19:34:29 +08003404 *
3405 * @return the maximum number of metering areas supported by the camera.
3406 * @see #getMeteringAreas()
Wu-cheng Lie98e4c82011-04-12 19:34:29 +08003407 */
3408 public int getMaxNumMeteringAreas() {
3409 return getInt(KEY_MAX_NUM_METERING_AREAS, 0);
3410 }
3411
3412 /**
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07003413 * <p>Gets the current metering areas. Camera driver uses these areas to
3414 * decide exposure.</p>
Wu-cheng Lie98e4c82011-04-12 19:34:29 +08003415 *
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07003416 * <p>Before using this API or {@link #setMeteringAreas(List)}, apps should
Wu-cheng Li7b1c5c82011-04-15 19:16:52 +08003417 * call {@link #getMaxNumMeteringAreas()} to know the maximum number of
3418 * metering areas first. If the value is 0, metering area is not
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07003419 * supported.</p>
Wu-cheng Lie98e4c82011-04-12 19:34:29 +08003420 *
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07003421 * <p>Each metering area is a rectangle with specified weight. The
Wu-cheng Lie98e4c82011-04-12 19:34:29 +08003422 * direction is relative to the sensor orientation, that is, what the
3423 * sensor sees. The direction is not affected by the rotation or
3424 * mirroring of {@link #setDisplayOrientation(int)}. Coordinates of the
3425 * rectangle range from -1000 to 1000. (-1000, -1000) is the upper left
Wu-cheng Libde61a52011-06-07 18:23:14 +08003426 * point. (1000, 1000) is the lower right point. The width and height of
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07003427 * metering areas cannot be 0 or negative.</p>
Wu-cheng Lie98e4c82011-04-12 19:34:29 +08003428 *
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07003429 * <p>The weight must range from 1 to 1000, and represents a weight for
Eino-Ville Talvala4e396e02011-04-21 09:23:15 -07003430 * every pixel in the area. This means that a large metering area with
3431 * the same weight as a smaller area will have more effect in the
3432 * metering result. Metering areas can partially overlap and the driver
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07003433 * will add the weights in the overlap region.</p>
Wu-cheng Lie98e4c82011-04-12 19:34:29 +08003434 *
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07003435 * <p>A special case of a {@code null} metering area list means the driver
3436 * is free to meter as it chooses. For example, the driver may use more
3437 * signals to select metering areas and change them dynamically. Apps
3438 * can set the metering area list to {@code null} if they want the
3439 * driver to completely control metering.</p>
Wu-cheng Lie98e4c82011-04-12 19:34:29 +08003440 *
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07003441 * <p>Metering areas are relative to the current field of view
Wu-cheng Lie98e4c82011-04-12 19:34:29 +08003442 * ({@link #getZoom()}). No matter what the zoom level is, (-1000,-1000)
3443 * represents the top of the currently visible camera frame. The
3444 * metering area cannot be set to be outside the current field of view,
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07003445 * even when using zoom.</p>
Wu-cheng Lie98e4c82011-04-12 19:34:29 +08003446 *
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07003447 * <p>No matter what metering areas are, the final exposure are compensated
3448 * by {@link #setExposureCompensation(int)}.</p>
Wu-cheng Lie98e4c82011-04-12 19:34:29 +08003449 *
3450 * @return a list of current metering areas
Wu-cheng Lie98e4c82011-04-12 19:34:29 +08003451 */
3452 public List<Area> getMeteringAreas() {
Wu-cheng Lid8aab932011-06-21 11:50:43 +08003453 return splitArea(get(KEY_METERING_AREAS));
Wu-cheng Lie98e4c82011-04-12 19:34:29 +08003454 }
3455
3456 /**
3457 * Sets metering areas. See {@link #getMeteringAreas()} for
3458 * documentation.
3459 *
Wu-cheng Li7b1c5c82011-04-15 19:16:52 +08003460 * @param meteringAreas the metering areas
Wu-cheng Lie98e4c82011-04-12 19:34:29 +08003461 * @see #getMeteringAreas()
Wu-cheng Lie98e4c82011-04-12 19:34:29 +08003462 */
3463 public void setMeteringAreas(List<Area> meteringAreas) {
3464 set(KEY_METERING_AREAS, meteringAreas);
Wu-cheng Li30771b72011-04-02 06:19:46 +08003465 }
3466
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08003467 /**
3468 * Gets the maximum number of detected faces supported. This is the
3469 * maximum length of the list returned from {@link FaceDetectionListener}.
3470 * If the return value is 0, face detection of the specified type is not
3471 * supported.
3472 *
3473 * @return the maximum number of detected face supported by the camera.
Joe Fernandez464cb212011-10-04 16:56:47 -07003474 * @see #startFaceDetection()
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08003475 */
Wu-cheng Lic0c683b2011-08-04 00:11:00 +08003476 public int getMaxNumDetectedFaces() {
3477 return getInt(KEY_MAX_NUM_DETECTED_FACES_HW, 0);
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08003478 }
3479
Wu-cheng Li25d8fb52011-08-02 13:20:36 +08003480 /**
Wu-cheng Li9c53f1c2011-08-02 17:26:58 +08003481 * Sets recording mode hint. This tells the camera that the intent of
3482 * the application is to record videos {@link
3483 * android.media.MediaRecorder#start()}, not to take still pictures
3484 * {@link #takePicture(Camera.ShutterCallback, Camera.PictureCallback,
3485 * Camera.PictureCallback, Camera.PictureCallback)}. Using this hint can
3486 * allow MediaRecorder.start() to start faster or with fewer glitches on
3487 * output. This should be called before starting preview for the best
3488 * result, but can be changed while the preview is active. The default
3489 * value is false.
Wu-cheng Li25d8fb52011-08-02 13:20:36 +08003490 *
Wu-cheng Li9c53f1c2011-08-02 17:26:58 +08003491 * The app can still call takePicture() when the hint is true or call
3492 * MediaRecorder.start() when the hint is false. But the performance may
3493 * be worse.
Wu-cheng Li25d8fb52011-08-02 13:20:36 +08003494 *
Wu-cheng Li9c53f1c2011-08-02 17:26:58 +08003495 * @param hint true if the apps intend to record videos using
Wu-cheng Li25d8fb52011-08-02 13:20:36 +08003496 * {@link android.media.MediaRecorder}.
Wu-cheng Li25d8fb52011-08-02 13:20:36 +08003497 */
3498 public void setRecordingHint(boolean hint) {
3499 set(KEY_RECORDING_HINT, hint ? TRUE : FALSE);
3500 }
3501
Wu-cheng Li98bb2512011-08-30 21:33:10 +08003502 /**
Eino-Ville Talvala1cab31a2012-11-05 10:33:55 -08003503 * <p>Returns true if video snapshot is supported. That is, applications
Wu-cheng Li98bb2512011-08-30 21:33:10 +08003504 * can call {@link #takePicture(Camera.ShutterCallback,
Eino-Ville Talvala1cab31a2012-11-05 10:33:55 -08003505 * Camera.PictureCallback, Camera.PictureCallback,
3506 * Camera.PictureCallback)} during recording. Applications do not need
3507 * to call {@link #startPreview()} after taking a picture. The preview
3508 * will be still active. Other than that, taking a picture during
3509 * recording is identical to taking a picture normally. All settings and
3510 * methods related to takePicture work identically. Ex:
3511 * {@link #getPictureSize()}, {@link #getSupportedPictureSizes()},
3512 * {@link #setJpegQuality(int)}, {@link #setRotation(int)}, and etc. The
3513 * picture will have an EXIF header. {@link #FLASH_MODE_AUTO} and
3514 * {@link #FLASH_MODE_ON} also still work, but the video will record the
3515 * flash.</p>
Wu-cheng Li98bb2512011-08-30 21:33:10 +08003516 *
Eino-Ville Talvala1cab31a2012-11-05 10:33:55 -08003517 * <p>Applications can set shutter callback as null to avoid the shutter
Wu-cheng Li98bb2512011-08-30 21:33:10 +08003518 * sound. It is also recommended to set raw picture and post view
Eino-Ville Talvala1cab31a2012-11-05 10:33:55 -08003519 * callbacks to null to avoid the interrupt of preview display.</p>
Wu-cheng Li98bb2512011-08-30 21:33:10 +08003520 *
Eino-Ville Talvala1cab31a2012-11-05 10:33:55 -08003521 * <p>Field-of-view of the recorded video may be different from that of the
3522 * captured pictures. The maximum size of a video snapshot may be
3523 * smaller than that for regular still captures. If the current picture
3524 * size is set higher than can be supported by video snapshot, the
3525 * picture will be captured at the maximum supported size instead.</p>
Wu-cheng Li98bb2512011-08-30 21:33:10 +08003526 *
3527 * @return true if video snapshot is supported.
Wu-cheng Li98bb2512011-08-30 21:33:10 +08003528 */
3529 public boolean isVideoSnapshotSupported() {
3530 String str = get(KEY_VIDEO_SNAPSHOT_SUPPORTED);
3531 return TRUE.equals(str);
3532 }
3533
Eino-Ville Talvala037abb82011-10-11 12:41:58 -07003534 /**
3535 * <p>Enables and disables video stabilization. Use
3536 * {@link #isVideoStabilizationSupported} to determine if calling this
3537 * method is valid.</p>
3538 *
3539 * <p>Video stabilization reduces the shaking due to the motion of the
3540 * camera in both the preview stream and in recorded videos, including
3541 * data received from the preview callback. It does not reduce motion
3542 * blur in images captured with
3543 * {@link Camera#takePicture takePicture}.</p>
3544 *
3545 * <p>Video stabilization can be enabled and disabled while preview or
3546 * recording is active, but toggling it may cause a jump in the video
3547 * stream that may be undesirable in a recorded video.</p>
3548 *
3549 * @param toggle Set to true to enable video stabilization, and false to
3550 * disable video stabilization.
3551 * @see #isVideoStabilizationSupported()
3552 * @see #getVideoStabilization()
Eino-Ville Talvala037abb82011-10-11 12:41:58 -07003553 */
3554 public void setVideoStabilization(boolean toggle) {
3555 set(KEY_VIDEO_STABILIZATION, toggle ? TRUE : FALSE);
3556 }
3557
3558 /**
3559 * Get the current state of video stabilization. See
3560 * {@link #setVideoStabilization} for details of video stabilization.
3561 *
3562 * @return true if video stabilization is enabled
3563 * @see #isVideoStabilizationSupported()
3564 * @see #setVideoStabilization(boolean)
Eino-Ville Talvala037abb82011-10-11 12:41:58 -07003565 */
3566 public boolean getVideoStabilization() {
3567 String str = get(KEY_VIDEO_STABILIZATION);
3568 return TRUE.equals(str);
3569 }
3570
3571 /**
3572 * Returns true if video stabilization is supported. See
3573 * {@link #setVideoStabilization} for details of video stabilization.
3574 *
3575 * @return true if video stabilization is supported
3576 * @see #setVideoStabilization(boolean)
3577 * @see #getVideoStabilization()
Eino-Ville Talvala037abb82011-10-11 12:41:58 -07003578 */
3579 public boolean isVideoStabilizationSupported() {
3580 String str = get(KEY_VIDEO_STABILIZATION_SUPPORTED);
3581 return TRUE.equals(str);
3582 }
3583
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003584 // Splits a comma delimited string to an ArrayList of String.
3585 // Return null if the passing string is null or the size is 0.
3586 private ArrayList<String> split(String str) {
3587 if (str == null) return null;
3588
Ali Utku Selen0a120182011-02-09 14:11:22 +01003589 TextUtils.StringSplitter splitter = new TextUtils.SimpleStringSplitter(',');
3590 splitter.setString(str);
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003591 ArrayList<String> substrings = new ArrayList<String>();
Ali Utku Selen0a120182011-02-09 14:11:22 +01003592 for (String s : splitter) {
3593 substrings.add(s);
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003594 }
3595 return substrings;
3596 }
3597
3598 // Splits a comma delimited string to an ArrayList of Integer.
3599 // Return null if the passing string is null or the size is 0.
3600 private ArrayList<Integer> splitInt(String str) {
3601 if (str == null) return null;
3602
Ali Utku Selen0a120182011-02-09 14:11:22 +01003603 TextUtils.StringSplitter splitter = new TextUtils.SimpleStringSplitter(',');
3604 splitter.setString(str);
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003605 ArrayList<Integer> substrings = new ArrayList<Integer>();
Ali Utku Selen0a120182011-02-09 14:11:22 +01003606 for (String s : splitter) {
3607 substrings.add(Integer.parseInt(s));
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003608 }
3609 if (substrings.size() == 0) return null;
3610 return substrings;
3611 }
3612
Wu-cheng Li454630f2010-08-11 16:48:05 -07003613 private void splitInt(String str, int[] output) {
3614 if (str == null) return;
Wu-cheng Lie339c5e2010-05-13 19:31:02 +08003615
Ali Utku Selen0a120182011-02-09 14:11:22 +01003616 TextUtils.StringSplitter splitter = new TextUtils.SimpleStringSplitter(',');
3617 splitter.setString(str);
Wu-cheng Li454630f2010-08-11 16:48:05 -07003618 int index = 0;
Ali Utku Selen0a120182011-02-09 14:11:22 +01003619 for (String s : splitter) {
3620 output[index++] = Integer.parseInt(s);
Wu-cheng Lie339c5e2010-05-13 19:31:02 +08003621 }
Wu-cheng Li454630f2010-08-11 16:48:05 -07003622 }
3623
3624 // Splits a comma delimited string to an ArrayList of Float.
3625 private void splitFloat(String str, float[] output) {
3626 if (str == null) return;
3627
Ali Utku Selen0a120182011-02-09 14:11:22 +01003628 TextUtils.StringSplitter splitter = new TextUtils.SimpleStringSplitter(',');
3629 splitter.setString(str);
Wu-cheng Li454630f2010-08-11 16:48:05 -07003630 int index = 0;
Ali Utku Selen0a120182011-02-09 14:11:22 +01003631 for (String s : splitter) {
3632 output[index++] = Float.parseFloat(s);
Wu-cheng Li454630f2010-08-11 16:48:05 -07003633 }
Wu-cheng Lie339c5e2010-05-13 19:31:02 +08003634 }
3635
Wu-cheng Li24b326a2010-02-20 17:47:04 +08003636 // Returns the value of a float parameter.
3637 private float getFloat(String key, float defaultValue) {
3638 try {
3639 return Float.parseFloat(mMap.get(key));
3640 } catch (NumberFormatException ex) {
3641 return defaultValue;
3642 }
3643 }
3644
3645 // Returns the value of a integer parameter.
3646 private int getInt(String key, int defaultValue) {
3647 try {
3648 return Integer.parseInt(mMap.get(key));
3649 } catch (NumberFormatException ex) {
3650 return defaultValue;
3651 }
3652 }
3653
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003654 // Splits a comma delimited string to an ArrayList of Size.
3655 // Return null if the passing string is null or the size is 0.
3656 private ArrayList<Size> splitSize(String str) {
3657 if (str == null) return null;
3658
Ali Utku Selen0a120182011-02-09 14:11:22 +01003659 TextUtils.StringSplitter splitter = new TextUtils.SimpleStringSplitter(',');
3660 splitter.setString(str);
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003661 ArrayList<Size> sizeList = new ArrayList<Size>();
Ali Utku Selen0a120182011-02-09 14:11:22 +01003662 for (String s : splitter) {
3663 Size size = strToSize(s);
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003664 if (size != null) sizeList.add(size);
3665 }
3666 if (sizeList.size() == 0) return null;
3667 return sizeList;
3668 }
3669
3670 // Parses a string (ex: "480x320") to Size object.
3671 // Return null if the passing string is null.
3672 private Size strToSize(String str) {
3673 if (str == null) return null;
3674
3675 int pos = str.indexOf('x');
3676 if (pos != -1) {
3677 String width = str.substring(0, pos);
3678 String height = str.substring(pos + 1);
3679 return new Size(Integer.parseInt(width),
3680 Integer.parseInt(height));
3681 }
3682 Log.e(TAG, "Invalid size parameter string=" + str);
3683 return null;
3684 }
Wu-cheng Li454630f2010-08-11 16:48:05 -07003685
3686 // Splits a comma delimited string to an ArrayList of int array.
3687 // Example string: "(10000,26623),(10000,30000)". Return null if the
3688 // passing string is null or the size is 0.
3689 private ArrayList<int[]> splitRange(String str) {
3690 if (str == null || str.charAt(0) != '('
3691 || str.charAt(str.length() - 1) != ')') {
3692 Log.e(TAG, "Invalid range list string=" + str);
3693 return null;
3694 }
3695
3696 ArrayList<int[]> rangeList = new ArrayList<int[]>();
3697 int endIndex, fromIndex = 1;
3698 do {
3699 int[] range = new int[2];
3700 endIndex = str.indexOf("),(", fromIndex);
3701 if (endIndex == -1) endIndex = str.length() - 1;
3702 splitInt(str.substring(fromIndex, endIndex), range);
3703 rangeList.add(range);
3704 fromIndex = endIndex + 3;
3705 } while (endIndex != str.length() - 1);
3706
3707 if (rangeList.size() == 0) return null;
3708 return rangeList;
3709 }
Wu-cheng Li30771b72011-04-02 06:19:46 +08003710
3711 // Splits a comma delimited string to an ArrayList of Area objects.
3712 // Example string: "(-10,-10,0,0,300),(0,0,10,10,700)". Return null if
Wu-cheng Lif715bf92011-04-14 14:04:18 +08003713 // the passing string is null or the size is 0 or (0,0,0,0,0).
Wu-cheng Li30771b72011-04-02 06:19:46 +08003714 private ArrayList<Area> splitArea(String str) {
3715 if (str == null || str.charAt(0) != '('
3716 || str.charAt(str.length() - 1) != ')') {
3717 Log.e(TAG, "Invalid area string=" + str);
3718 return null;
3719 }
3720
3721 ArrayList<Area> result = new ArrayList<Area>();
3722 int endIndex, fromIndex = 1;
3723 int[] array = new int[5];
3724 do {
3725 endIndex = str.indexOf("),(", fromIndex);
3726 if (endIndex == -1) endIndex = str.length() - 1;
3727 splitInt(str.substring(fromIndex, endIndex), array);
3728 Rect rect = new Rect(array[0], array[1], array[2], array[3]);
3729 result.add(new Area(rect, array[4]));
3730 fromIndex = endIndex + 3;
3731 } while (endIndex != str.length() - 1);
3732
3733 if (result.size() == 0) return null;
Wu-cheng Lif715bf92011-04-14 14:04:18 +08003734
3735 if (result.size() == 1) {
Wu-cheng Libde61a52011-06-07 18:23:14 +08003736 Area area = result.get(0);
Wu-cheng Lif715bf92011-04-14 14:04:18 +08003737 Rect rect = area.rect;
3738 if (rect.left == 0 && rect.top == 0 && rect.right == 0
3739 && rect.bottom == 0 && area.weight == 0) {
3740 return null;
3741 }
3742 }
3743
Wu-cheng Li30771b72011-04-02 06:19:46 +08003744 return result;
3745 }
Wu-cheng Lib838d8d2011-11-17 20:12:23 +08003746
3747 private boolean same(String s1, String s2) {
3748 if (s1 == null && s2 == null) return true;
3749 if (s1 != null && s1.equals(s2)) return true;
3750 return false;
3751 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003752 };
3753}