blob: 0a13b4e649749eec76332b098e8ff6eb0eb84664 [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
19import java.lang.ref.WeakReference;
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +080020import java.util.ArrayList;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080021import java.util.HashMap;
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +080022import java.util.List;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080023import java.util.StringTokenizer;
24import java.io.IOException;
25
26import android.util.Log;
27import android.view.Surface;
28import android.view.SurfaceHolder;
Mathias Agopiana696f5d2010-02-17 17:53:09 -080029import android.graphics.ImageFormat;
Wu-cheng Li30771b72011-04-02 06:19:46 +080030import android.graphics.Rect;
Jamie Gennisfd6f39e2010-12-20 12:15:00 -080031import android.graphics.SurfaceTexture;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080032import android.os.Handler;
33import android.os.Looper;
34import android.os.Message;
35
36/**
Dan Egnorbfcbeff2010-07-12 15:12:54 -070037 * The Camera class is used to set image capture settings, start/stop preview,
38 * snap pictures, and retrieve frames for encoding for video. This class is a
39 * client for the Camera service, which manages the actual camera hardware.
Scott Maindf4578e2009-09-10 12:22:07 -070040 *
Dan Egnorbfcbeff2010-07-12 15:12:54 -070041 * <p>To access the device camera, you must declare the
Wu-cheng Li7478ea62009-09-16 18:52:55 +080042 * {@link android.Manifest.permission#CAMERA} permission in your Android
Scott Maindf4578e2009-09-10 12:22:07 -070043 * Manifest. Also be sure to include the
44 * <a href="{@docRoot}guide/topics/manifest/uses-feature-element.html">&lt;uses-feature></a>
Dan Egnorbfcbeff2010-07-12 15:12:54 -070045 * manifest element to declare camera features used by your application.
Wu-cheng Li7478ea62009-09-16 18:52:55 +080046 * For example, if you use the camera and auto-focus feature, your Manifest
Scott Maindf4578e2009-09-10 12:22:07 -070047 * should include the following:</p>
48 * <pre> &lt;uses-permission android:name="android.permission.CAMERA" />
49 * &lt;uses-feature android:name="android.hardware.camera" />
50 * &lt;uses-feature android:name="android.hardware.camera.autofocus" /></pre>
51 *
Dan Egnorbfcbeff2010-07-12 15:12:54 -070052 * <p>To take pictures with this class, use the following steps:</p>
53 *
54 * <ol>
Dan Egnor341ff132010-07-20 11:30:17 -070055 * <li>Obtain an instance of Camera from {@link #open(int)}.
Dan Egnorbfcbeff2010-07-12 15:12:54 -070056 *
57 * <li>Get existing (default) settings with {@link #getParameters()}.
58 *
59 * <li>If necessary, modify the returned {@link Camera.Parameters} object and call
60 * {@link #setParameters(Camera.Parameters)}.
61 *
62 * <li>If desired, call {@link #setDisplayOrientation(int)}.
63 *
64 * <li><b>Important</b>: Pass a fully initialized {@link SurfaceHolder} to
65 * {@link #setPreviewDisplay(SurfaceHolder)}. Without a surface, the camera
66 * will be unable to start the preview.
67 *
68 * <li><b>Important</b>: Call {@link #startPreview()} to start updating the
69 * preview surface. Preview must be started before you can take a picture.
70 *
71 * <li>When you want, call {@link #takePicture(Camera.ShutterCallback,
72 * Camera.PictureCallback, Camera.PictureCallback, Camera.PictureCallback)} to
73 * capture a photo. Wait for the callbacks to provide the actual image data.
74 *
75 * <li>After taking a picture, preview display will have stopped. To take more
76 * photos, call {@link #startPreview()} again first.
77 *
78 * <li>Call {@link #stopPreview()} to stop updating the preview surface.
79 *
80 * <li><b>Important:</b> Call {@link #release()} to release the camera for
81 * use by other applications. Applications should release the camera
82 * immediately in {@link android.app.Activity#onPause()} (and re-{@link #open()}
83 * it in {@link android.app.Activity#onResume()}).
84 * </ol>
85 *
86 * <p>To quickly switch to video recording mode, use these steps:</p>
87 *
88 * <ol>
89 * <li>Obtain and initialize a Camera and start preview as described above.
90 *
91 * <li>Call {@link #unlock()} to allow the media process to access the camera.
92 *
93 * <li>Pass the camera to {@link android.media.MediaRecorder#setCamera(Camera)}.
94 * See {@link android.media.MediaRecorder} information about video recording.
95 *
96 * <li>When finished recording, call {@link #reconnect()} to re-acquire
97 * and re-lock the camera.
98 *
99 * <li>If desired, restart preview and take more photos or videos.
100 *
101 * <li>Call {@link #stopPreview()} and {@link #release()} as described above.
102 * </ol>
103 *
104 * <p>This class is not thread-safe, and is meant for use from one event thread.
105 * Most long-running operations (preview, focus, photo capture, etc) happen
106 * asynchronously and invoke callbacks as necessary. Callbacks will be invoked
Dan Egnor341ff132010-07-20 11:30:17 -0700107 * on the event thread {@link #open(int)} was called from. This class's methods
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700108 * must never be called from multiple threads at once.</p>
109 *
Scott Maindf4578e2009-09-10 12:22:07 -0700110 * <p class="caution"><strong>Caution:</strong> Different Android-powered devices
111 * may have different hardware specifications, such as megapixel ratings and
112 * auto-focus capabilities. In order for your application to be compatible with
Wu-cheng Li7478ea62009-09-16 18:52:55 +0800113 * more devices, you should not make assumptions about the device camera
Scott Maindf4578e2009-09-10 12:22:07 -0700114 * specifications.</p>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800115 */
116public class Camera {
117 private static final String TAG = "Camera";
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800118
Wu-cheng Lid2c29292010-05-28 17:32:41 +0800119 // These match the enums in frameworks/base/include/camera/Camera.h
Benny Wongda83f462009-08-12 12:01:27 -0500120 private static final int CAMERA_MSG_ERROR = 0x001;
121 private static final int CAMERA_MSG_SHUTTER = 0x002;
122 private static final int CAMERA_MSG_FOCUS = 0x004;
123 private static final int CAMERA_MSG_ZOOM = 0x008;
124 private static final int CAMERA_MSG_PREVIEW_FRAME = 0x010;
125 private static final int CAMERA_MSG_VIDEO_FRAME = 0x020;
126 private static final int CAMERA_MSG_POSTVIEW_FRAME = 0x040;
127 private static final int CAMERA_MSG_RAW_IMAGE = 0x080;
128 private static final int CAMERA_MSG_COMPRESSED_IMAGE = 0x100;
129 private static final int CAMERA_MSG_ALL_MSGS = 0x1FF;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800130
131 private int mNativeContext; // accessed by native methods
132 private EventHandler mEventHandler;
133 private ShutterCallback mShutterCallback;
134 private PictureCallback mRawImageCallback;
135 private PictureCallback mJpegCallback;
136 private PreviewCallback mPreviewCallback;
Dave Sparkse8b26e12009-07-14 10:35:40 -0700137 private PictureCallback mPostviewCallback;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800138 private AutoFocusCallback mAutoFocusCallback;
Wu-cheng Li3f4639a2010-04-04 15:05:41 +0800139 private OnZoomChangeListener mZoomListener;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800140 private ErrorCallback mErrorCallback;
141 private boolean mOneShot;
Andrew Harp94927df2009-10-20 01:47:05 -0400142 private boolean mWithBuffer;
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800143
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800144 /**
Dan Egnor341ff132010-07-20 11:30:17 -0700145 * Returns the number of physical cameras available on this device.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800146 */
Chih-Chung Change25cc652010-05-06 16:36:58 +0800147 public native static int getNumberOfCameras();
148
149 /**
Dan Egnor341ff132010-07-20 11:30:17 -0700150 * Returns the information about a particular camera.
Chih-Chung Changb8bb78f2010-06-10 13:32:16 +0800151 * If {@link #getNumberOfCameras()} returns N, the valid id is 0 to N-1.
Chih-Chung Changb8bb78f2010-06-10 13:32:16 +0800152 */
153 public native static void getCameraInfo(int cameraId, CameraInfo cameraInfo);
154
155 /**
156 * Information about a camera
Chih-Chung Changb8bb78f2010-06-10 13:32:16 +0800157 */
158 public static class CameraInfo {
Wu-cheng Li78366602010-09-15 14:08:15 -0700159 /**
160 * The facing of the camera is opposite to that of the screen.
161 */
Chih-Chung Changb8bb78f2010-06-10 13:32:16 +0800162 public static final int CAMERA_FACING_BACK = 0;
Wu-cheng Li78366602010-09-15 14:08:15 -0700163
164 /**
165 * The facing of the camera is the same as that of the screen.
166 */
Chih-Chung Changb8bb78f2010-06-10 13:32:16 +0800167 public static final int CAMERA_FACING_FRONT = 1;
168
169 /**
170 * The direction that the camera faces to. It should be
171 * CAMERA_FACING_BACK or CAMERA_FACING_FRONT.
172 */
Wu-cheng Li78366602010-09-15 14:08:15 -0700173 public int facing;
Chih-Chung Changb8bb78f2010-06-10 13:32:16 +0800174
175 /**
176 * The orientation of the camera image. The value is the angle that the
177 * camera image needs to be rotated clockwise so it shows correctly on
178 * the display in its natural orientation. It should be 0, 90, 180, or 270.
179 *
Wu-cheng Li2fe6fca2010-10-15 14:42:23 +0800180 * For example, suppose a device has a naturally tall screen. The
181 * back-facing camera sensor is mounted in landscape. You are looking at
182 * the screen. If the top side of the camera sensor is aligned with the
183 * right edge of the screen in natural orientation, the value should be
184 * 90. If the top side of a front-facing camera sensor is aligned with
185 * the right of the screen, the value should be 270.
Chih-Chung Changb8bb78f2010-06-10 13:32:16 +0800186 *
187 * @see #setDisplayOrientation(int)
Brad Fitzpatrick69ea4e12011-01-05 11:13:40 -0800188 * @see Parameters#setRotation(int)
189 * @see Parameters#setPreviewSize(int, int)
190 * @see Parameters#setPictureSize(int, int)
191 * @see Parameters#setJpegThumbnailSize(int, int)
Chih-Chung Changb8bb78f2010-06-10 13:32:16 +0800192 */
Wu-cheng Li78366602010-09-15 14:08:15 -0700193 public int orientation;
Chih-Chung Changb8bb78f2010-06-10 13:32:16 +0800194 };
195
196 /**
Dan Egnor341ff132010-07-20 11:30:17 -0700197 * Creates a new Camera object to access a particular hardware camera.
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700198 *
199 * <p>You must call {@link #release()} when you are done using the camera,
200 * otherwise it will remain locked and be unavailable to other applications.
201 *
Dan Egnor341ff132010-07-20 11:30:17 -0700202 * <p>Your application should only have one Camera object active at a time
203 * for a particular hardware camera.
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700204 *
205 * <p>Callbacks from other methods are delivered to the event loop of the
206 * thread which called open(). If this thread has no event loop, then
207 * callbacks are delivered to the main application event loop. If there
208 * is no main application event loop, callbacks are not delivered.
209 *
210 * <p class="caution"><b>Caution:</b> On some devices, this method may
211 * take a long time to complete. It is best to call this method from a
212 * worker thread (possibly using {@link android.os.AsyncTask}) to avoid
213 * blocking the main application UI thread.
214 *
Dan Egnor341ff132010-07-20 11:30:17 -0700215 * @param cameraId the hardware camera to access, between 0 and
Wu-cheng Lia48b70f2010-11-09 01:55:44 +0800216 * {@link #getNumberOfCameras()}-1.
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700217 * @return a new Camera object, connected, locked and ready for use.
218 * @throws RuntimeException if connection to the camera service fails (for
219 * example, if the camera is in use by another process).
Chih-Chung Change25cc652010-05-06 16:36:58 +0800220 */
221 public static Camera open(int cameraId) {
222 return new Camera(cameraId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800223 }
224
Chih-Chung Change25cc652010-05-06 16:36:58 +0800225 /**
Wu-cheng Lia48b70f2010-11-09 01:55:44 +0800226 * Creates a new Camera object to access the first back-facing camera on the
227 * device. If the device does not have a back-facing camera, this returns
228 * null.
Wu-cheng Li78366602010-09-15 14:08:15 -0700229 * @see #open(int)
Chih-Chung Change25cc652010-05-06 16:36:58 +0800230 */
231 public static Camera open() {
Wu-cheng Lia48b70f2010-11-09 01:55:44 +0800232 int numberOfCameras = getNumberOfCameras();
233 CameraInfo cameraInfo = new CameraInfo();
234 for (int i = 0; i < numberOfCameras; i++) {
235 getCameraInfo(i, cameraInfo);
236 if (cameraInfo.facing == CameraInfo.CAMERA_FACING_BACK) {
237 return new Camera(i);
238 }
239 }
240 return null;
Chih-Chung Change25cc652010-05-06 16:36:58 +0800241 }
242
243 Camera(int cameraId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800244 mShutterCallback = null;
245 mRawImageCallback = null;
246 mJpegCallback = null;
247 mPreviewCallback = null;
Dave Sparkse8b26e12009-07-14 10:35:40 -0700248 mPostviewCallback = null;
Wu-cheng Li3f4639a2010-04-04 15:05:41 +0800249 mZoomListener = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800250
251 Looper looper;
252 if ((looper = Looper.myLooper()) != null) {
253 mEventHandler = new EventHandler(this, looper);
254 } else if ((looper = Looper.getMainLooper()) != null) {
255 mEventHandler = new EventHandler(this, looper);
256 } else {
257 mEventHandler = null;
258 }
259
Chih-Chung Change25cc652010-05-06 16:36:58 +0800260 native_setup(new WeakReference<Camera>(this), cameraId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800261 }
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800262
263 protected void finalize() {
264 native_release();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800265 }
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800266
Chih-Chung Change25cc652010-05-06 16:36:58 +0800267 private native final void native_setup(Object camera_this, int cameraId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800268 private native final void native_release();
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800269
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800270
271 /**
272 * Disconnects and releases the Camera object resources.
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700273 *
274 * <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 -0800275 */
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800276 public final void release() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800277 native_release();
278 }
279
280 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700281 * Unlocks the camera to allow another process to access it.
282 * Normally, the camera is locked to the process with an active Camera
283 * object until {@link #release()} is called. To allow rapid handoff
284 * between processes, you can call this method to release the camera
285 * temporarily for another process to use; once the other process is done
286 * you can call {@link #reconnect()} to reclaim the camera.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800287 *
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700288 * <p>This must be done before calling
289 * {@link android.media.MediaRecorder#setCamera(Camera)}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800290 *
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700291 * <p>If you are not recording video, you probably do not need this method.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800292 *
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700293 * @throws RuntimeException if the camera cannot be unlocked.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800294 */
Wu-cheng Liffe1cf22009-09-10 16:49:17 +0800295 public native final void unlock();
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800296
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800297 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700298 * Re-locks the camera to prevent other processes from accessing it.
299 * Camera objects are locked by default unless {@link #unlock()} is
300 * called. Normally {@link #reconnect()} is used instead.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800301 *
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700302 * <p>If you are not recording video, you probably do not need this method.
303 *
304 * @throws RuntimeException if the camera cannot be re-locked (for
305 * example, if the camera is still in use by another process).
306 */
307 public native final void lock();
308
309 /**
310 * Reconnects to the camera service after another process used it.
311 * After {@link #unlock()} is called, another process may use the
312 * camera; when the process is done, you must reconnect to the camera,
313 * which will re-acquire the lock and allow you to continue using the
314 * camera.
315 *
316 * <p>This must be done after {@link android.media.MediaRecorder} is
317 * done recording if {@link android.media.MediaRecorder#setCamera(Camera)}
318 * was used.
319 *
320 * <p>If you are not recording video, you probably do not need this method.
321 *
322 * @throws IOException if a connection cannot be re-established (for
323 * example, if the camera is still in use by another process).
324 */
325 public native final void reconnect() throws IOException;
326
327 /**
328 * Sets the {@link Surface} to be used for live preview.
Jamie Gennisfd6f39e2010-12-20 12:15:00 -0800329 * Either a surface or surface texture is necessary for preview, and
330 * preview is necessary to take pictures. The same surface can be re-set
331 * without harm. Setting a preview surface will un-set any preview surface
332 * texture that was set via {@link #setPreviewTexture}.
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700333 *
334 * <p>The {@link SurfaceHolder} must already contain a surface when this
335 * method is called. If you are using {@link android.view.SurfaceView},
336 * you will need to register a {@link SurfaceHolder.Callback} with
337 * {@link SurfaceHolder#addCallback(SurfaceHolder.Callback)} and wait for
338 * {@link SurfaceHolder.Callback#surfaceCreated(SurfaceHolder)} before
339 * calling setPreviewDisplay() or starting preview.
340 *
341 * <p>This method must be called before {@link #startPreview()}. The
342 * one exception is that if the preview surface is not set (or set to null)
343 * before startPreview() is called, then this method may be called once
344 * with a non-null parameter to set the preview surface. (This allows
345 * camera setup and surface creation to happen in parallel, saving time.)
346 * The preview surface may not otherwise change while preview is running.
347 *
348 * @param holder containing the Surface on which to place the preview,
349 * or null to remove the preview surface
350 * @throws IOException if the method fails (for example, if the surface
351 * is unavailable or unsuitable).
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800352 */
353 public final void setPreviewDisplay(SurfaceHolder holder) throws IOException {
Wu-cheng Lib8a10fe2009-06-23 23:37:36 +0800354 if (holder != null) {
355 setPreviewDisplay(holder.getSurface());
356 } else {
357 setPreviewDisplay((Surface)null);
358 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800359 }
360
Glenn Kastendbc289d2011-02-09 10:15:44 -0800361 private native final void setPreviewDisplay(Surface surface) throws IOException;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800362
363 /**
Jamie Gennisfd6f39e2010-12-20 12:15:00 -0800364 * Sets the {@link SurfaceTexture} to be used for live preview.
365 * Either a surface or surface texture is necessary for preview, and
366 * preview is necessary to take pictures. The same surface texture can be
367 * re-set without harm. Setting a preview surface texture will un-set any
368 * preview surface that was set via {@link #setPreviewDisplay}.
369 *
370 * <p>This method must be called before {@link #startPreview()}. The
371 * one exception is that if the preview surface texture is not set (or set
372 * to null) before startPreview() is called, then this method may be called
373 * once with a non-null parameter to set the preview surface. (This allows
374 * camera setup and surface creation to happen in parallel, saving time.)
375 * The preview surface texture may not otherwise change while preview is
376 * running.
377 *
Eino-Ville Talvalae309a0f2011-03-21 11:04:34 -0700378 * The timestamps provided by {@link SurfaceTexture#getTimestamp()} for a
379 * SurfaceTexture set as the preview texture have an unspecified zero point,
380 * and cannot be directly compared between different cameras or different
381 * instances of the same camera, or across multiple runs of the same
382 * program.
383 *
Jamie Gennisfd6f39e2010-12-20 12:15:00 -0800384 * @param surfaceTexture the {@link SurfaceTexture} to which the preview
385 * images are to be sent or null to remove the current preview surface
386 * texture
387 * @throws IOException if the method fails (for example, if the surface
388 * texture is unavailable or unsuitable).
389 */
Glenn Kastendbc289d2011-02-09 10:15:44 -0800390 public native final void setPreviewTexture(SurfaceTexture surfaceTexture) throws IOException;
Jamie Gennisfd6f39e2010-12-20 12:15:00 -0800391
392 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700393 * Callback interface used to deliver copies of preview frames as
394 * they are displayed.
395 *
396 * @see #setPreviewCallback(Camera.PreviewCallback)
397 * @see #setOneShotPreviewCallback(Camera.PreviewCallback)
398 * @see #setPreviewCallbackWithBuffer(Camera.PreviewCallback)
399 * @see #startPreview()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800400 */
401 public interface PreviewCallback
402 {
403 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700404 * Called as preview frames are displayed. This callback is invoked
Dan Egnor341ff132010-07-20 11:30:17 -0700405 * on the event thread {@link #open(int)} was called from.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800406 *
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700407 * @param data the contents of the preview frame in the format defined
Mathias Agopiana696f5d2010-02-17 17:53:09 -0800408 * by {@link android.graphics.ImageFormat}, which can be queried
Scott Maindf4578e2009-09-10 12:22:07 -0700409 * with {@link android.hardware.Camera.Parameters#getPreviewFormat()}.
Scott Mainda0a56d2009-09-10 18:08:37 -0700410 * If {@link android.hardware.Camera.Parameters#setPreviewFormat(int)}
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800411 * is never called, the default will be the YCbCr_420_SP
412 * (NV21) format.
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700413 * @param camera the Camera service object.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800414 */
415 void onPreviewFrame(byte[] data, Camera camera);
416 };
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800417
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800418 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700419 * Starts capturing and drawing preview frames to the screen.
Eino-Ville Talvalac5f94d82011-02-18 11:02:42 -0800420 * Preview will not actually start until a surface is supplied
421 * with {@link #setPreviewDisplay(SurfaceHolder)} or
422 * {@link #setPreviewTexture(SurfaceTexture)}.
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700423 *
424 * <p>If {@link #setPreviewCallback(Camera.PreviewCallback)},
425 * {@link #setOneShotPreviewCallback(Camera.PreviewCallback)}, or
426 * {@link #setPreviewCallbackWithBuffer(Camera.PreviewCallback)} were
427 * called, {@link Camera.PreviewCallback#onPreviewFrame(byte[], Camera)}
428 * will be called when preview data becomes available.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800429 */
430 public native final void startPreview();
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800431
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800432 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700433 * Stops capturing and drawing preview frames to the surface, and
434 * resets the camera for a future call to {@link #startPreview()}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800435 */
436 public native final void stopPreview();
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800437
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800438 /**
439 * Return current preview state.
440 *
441 * FIXME: Unhide before release
442 * @hide
443 */
444 public native final boolean previewEnabled();
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800445
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800446 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700447 * Installs a callback to be invoked for every preview frame in addition
448 * to displaying them on the screen. The callback will be repeatedly called
449 * for as long as preview is active. This method can be called at any time,
450 * even while preview is live. Any other preview callbacks are overridden.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800451 *
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700452 * @param cb a callback object that receives a copy of each preview frame,
453 * or null to stop receiving callbacks.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800454 */
455 public final void setPreviewCallback(PreviewCallback cb) {
456 mPreviewCallback = cb;
457 mOneShot = false;
Andrew Harp94927df2009-10-20 01:47:05 -0400458 mWithBuffer = false;
Dave Sparksa6118c62009-10-13 02:28:54 -0700459 // Always use one-shot mode. We fake camera preview mode by
460 // doing one-shot preview continuously.
Andrew Harp94927df2009-10-20 01:47:05 -0400461 setHasPreviewCallback(cb != null, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800462 }
463
464 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700465 * Installs a callback to be invoked for the next preview frame in addition
466 * to displaying it on the screen. After one invocation, the callback is
467 * cleared. This method can be called any time, even when preview is live.
468 * Any other preview callbacks are overridden.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800469 *
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700470 * @param cb a callback object that receives a copy of the next preview frame,
471 * or null to stop receiving callbacks.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800472 */
473 public final void setOneShotPreviewCallback(PreviewCallback cb) {
Andrew Harp94927df2009-10-20 01:47:05 -0400474 mPreviewCallback = cb;
475 mOneShot = true;
476 mWithBuffer = false;
477 setHasPreviewCallback(cb != null, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800478 }
479
Andrew Harp94927df2009-10-20 01:47:05 -0400480 private native final void setHasPreviewCallback(boolean installed, boolean manualBuffer);
481
482 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700483 * Installs a callback to be invoked for every preview frame, using buffers
484 * supplied with {@link #addCallbackBuffer(byte[])}, in addition to
485 * displaying them on the screen. The callback will be repeatedly called
486 * for as long as preview is active and buffers are available.
487 * Any other preview callbacks are overridden.
Andrew Harp94927df2009-10-20 01:47:05 -0400488 *
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700489 * <p>The purpose of this method is to improve preview efficiency and frame
490 * rate by allowing preview frame memory reuse. You must call
491 * {@link #addCallbackBuffer(byte[])} at some point -- before or after
492 * calling this method -- or no callbacks will received.
Andrew Harp94927df2009-10-20 01:47:05 -0400493 *
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700494 * The buffer queue will be cleared if this method is called with a null
495 * callback, {@link #setPreviewCallback(Camera.PreviewCallback)} is called,
496 * or {@link #setOneShotPreviewCallback(Camera.PreviewCallback)} is called.
Andrew Harp94927df2009-10-20 01:47:05 -0400497 *
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700498 * @param cb a callback object that receives a copy of the preview frame,
499 * or null to stop receiving callbacks and clear the buffer queue.
500 * @see #addCallbackBuffer(byte[])
Andrew Harp94927df2009-10-20 01:47:05 -0400501 */
502 public final void setPreviewCallbackWithBuffer(PreviewCallback cb) {
503 mPreviewCallback = cb;
504 mOneShot = false;
505 mWithBuffer = true;
506 setHasPreviewCallback(cb != null, true);
507 }
508
509 /**
Wu-cheng Li3f4639a2010-04-04 15:05:41 +0800510 * Adds a pre-allocated buffer to the preview callback buffer queue.
511 * Applications can add one or more buffers to the queue. When a preview
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700512 * frame arrives and there is still at least one available buffer, the
513 * buffer will be used and removed from the queue. Then preview callback is
514 * invoked with the buffer. If a frame arrives and there is no buffer left,
515 * the frame is discarded. Applications should add buffers back when they
516 * finish processing the data in them.
Wu-cheng Lic10275a2010-03-09 13:49:21 -0800517 *
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700518 * <p>The size of the buffer is determined by multiplying the preview
James Donge00cab72011-02-17 16:38:06 -0800519 * image width, height, and bytes per pixel. The width and height can be
520 * read from {@link Camera.Parameters#getPreviewSize()}. Bytes per pixel
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700521 * can be computed from
522 * {@link android.graphics.ImageFormat#getBitsPerPixel(int)} / 8,
523 * using the image format from {@link Camera.Parameters#getPreviewFormat()}.
Andrew Harp94927df2009-10-20 01:47:05 -0400524 *
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700525 * <p>This method is only necessary when
James Donge00cab72011-02-17 16:38:06 -0800526 * {@link #setPreviewCallbackWithBuffer(PreviewCallback)} is used. When
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700527 * {@link #setPreviewCallback(PreviewCallback)} or
528 * {@link #setOneShotPreviewCallback(PreviewCallback)} are used, buffers
James Donge00cab72011-02-17 16:38:06 -0800529 * are automatically allocated. When a supplied buffer is too small to
530 * hold the preview frame data, preview callback will return null and
531 * the buffer will be removed from the buffer queue.
Andrew Harp94927df2009-10-20 01:47:05 -0400532 *
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700533 * @param callbackBuffer the buffer to add to the queue.
534 * The size should be width * height * bits_per_pixel / 8.
Wu-cheng Li5b9bcda2010-03-07 14:59:28 -0800535 * @see #setPreviewCallbackWithBuffer(PreviewCallback)
Andrew Harp94927df2009-10-20 01:47:05 -0400536 */
James Donge00cab72011-02-17 16:38:06 -0800537 public final void addCallbackBuffer(byte[] callbackBuffer)
538 {
539 _addCallbackBuffer(callbackBuffer, CAMERA_MSG_PREVIEW_FRAME);
540 }
541
542 /**
543 * Adds a pre-allocated buffer to the raw image callback buffer queue.
544 * Applications can add one or more buffers to the queue. When a raw image
545 * frame arrives and there is still at least one available buffer, the
546 * buffer will be used to hold the raw image data and removed from the
547 * queue. Then raw image callback is invoked with the buffer. If a raw
548 * image frame arrives but there is no buffer left, the frame is
549 * discarded. Applications should add buffers back when they finish
550 * processing the data in them by calling this method again in order
551 * to avoid running out of raw image callback buffers.
552 *
553 * <p>The size of the buffer is determined by multiplying the raw image
554 * width, height, and bytes per pixel. The width and height can be
555 * read from {@link Camera.Parameters#getPictureSize()}. Bytes per pixel
556 * can be computed from
557 * {@link android.graphics.ImageFormat#getBitsPerPixel(int)} / 8,
558 * using the image format from {@link Camera.Parameters#getPreviewFormat()}.
559 *
560 * <p>This method is only necessary when the PictureCallbck for raw image
561 * is used while calling {@link #takePicture(Camera.ShutterCallback,
562 * Camera.PictureCallback, Camera.PictureCallback, Camera.PictureCallback)}.
563 *
564 * Please note that by calling this method, the mode for application-managed
565 * callback buffers is triggered. If this method has never been called,
566 * null will be returned by the raw image callback since there is
567 * no image callback buffer available. Furthermore, When a supplied buffer
568 * is too small to hold the raw image data, raw image callback will return
569 * null and the buffer will be removed from the buffer queue.
570 *
571 * @param callbackBuffer the buffer to add to the raw image callback buffer
572 * queue. The size should be width * height * (bits per pixel) / 8. An
573 * null callbackBuffer will be ignored and won't be added to the queue.
574 *
575 * @see #takePicture(Camera.ShutterCallback,
576 * Camera.PictureCallback, Camera.PictureCallback, Camera.PictureCallback)}.
577 *
578 * {@hide}
579 */
580 public final void addRawImageCallbackBuffer(byte[] callbackBuffer)
581 {
582 addCallbackBuffer(callbackBuffer, CAMERA_MSG_RAW_IMAGE);
583 }
584
585 private final void addCallbackBuffer(byte[] callbackBuffer, int msgType)
586 {
587 // CAMERA_MSG_VIDEO_FRAME may be allowed in the future.
588 if (msgType != CAMERA_MSG_PREVIEW_FRAME &&
589 msgType != CAMERA_MSG_RAW_IMAGE) {
590 throw new IllegalArgumentException(
591 "Unsupported message type: " + msgType);
592 }
593
594 _addCallbackBuffer(callbackBuffer, msgType);
595 }
596
597 private native final void _addCallbackBuffer(
598 byte[] callbackBuffer, int msgType);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800599
600 private class EventHandler extends Handler
601 {
602 private Camera mCamera;
603
604 public EventHandler(Camera c, Looper looper) {
605 super(looper);
606 mCamera = c;
607 }
608
609 @Override
610 public void handleMessage(Message msg) {
611 switch(msg.what) {
Dave Sparksc62f9bd2009-06-26 13:33:32 -0700612 case CAMERA_MSG_SHUTTER:
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800613 if (mShutterCallback != null) {
614 mShutterCallback.onShutter();
615 }
616 return;
Dave Sparksc62f9bd2009-06-26 13:33:32 -0700617
618 case CAMERA_MSG_RAW_IMAGE:
Dave Sparkse8b26e12009-07-14 10:35:40 -0700619 if (mRawImageCallback != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800620 mRawImageCallback.onPictureTaken((byte[])msg.obj, mCamera);
Dave Sparkse8b26e12009-07-14 10:35:40 -0700621 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800622 return;
623
Dave Sparksc62f9bd2009-06-26 13:33:32 -0700624 case CAMERA_MSG_COMPRESSED_IMAGE:
Dave Sparkse8b26e12009-07-14 10:35:40 -0700625 if (mJpegCallback != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800626 mJpegCallback.onPictureTaken((byte[])msg.obj, mCamera);
Dave Sparkse8b26e12009-07-14 10:35:40 -0700627 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800628 return;
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800629
Dave Sparksc62f9bd2009-06-26 13:33:32 -0700630 case CAMERA_MSG_PREVIEW_FRAME:
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800631 if (mPreviewCallback != null) {
Dave Sparksa6118c62009-10-13 02:28:54 -0700632 PreviewCallback cb = mPreviewCallback;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800633 if (mOneShot) {
Dave Sparksa6118c62009-10-13 02:28:54 -0700634 // Clear the callback variable before the callback
635 // in case the app calls setPreviewCallback from
636 // the callback function
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800637 mPreviewCallback = null;
Andrew Harp94927df2009-10-20 01:47:05 -0400638 } else if (!mWithBuffer) {
Dave Sparksa6118c62009-10-13 02:28:54 -0700639 // We're faking the camera preview mode to prevent
640 // the app from being flooded with preview frames.
641 // Set to oneshot mode again.
Andrew Harp94927df2009-10-20 01:47:05 -0400642 setHasPreviewCallback(true, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800643 }
Dave Sparksa6118c62009-10-13 02:28:54 -0700644 cb.onPreviewFrame((byte[])msg.obj, mCamera);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800645 }
646 return;
647
Dave Sparkse8b26e12009-07-14 10:35:40 -0700648 case CAMERA_MSG_POSTVIEW_FRAME:
649 if (mPostviewCallback != null) {
650 mPostviewCallback.onPictureTaken((byte[])msg.obj, mCamera);
651 }
652 return;
653
Dave Sparksc62f9bd2009-06-26 13:33:32 -0700654 case CAMERA_MSG_FOCUS:
Dave Sparkse8b26e12009-07-14 10:35:40 -0700655 if (mAutoFocusCallback != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800656 mAutoFocusCallback.onAutoFocus(msg.arg1 == 0 ? false : true, mCamera);
Dave Sparkse8b26e12009-07-14 10:35:40 -0700657 }
658 return;
659
660 case CAMERA_MSG_ZOOM:
Wu-cheng Li3f4639a2010-04-04 15:05:41 +0800661 if (mZoomListener != null) {
662 mZoomListener.onZoomChange(msg.arg1, msg.arg2 != 0, mCamera);
Dave Sparkse8b26e12009-07-14 10:35:40 -0700663 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800664 return;
665
Dave Sparksc62f9bd2009-06-26 13:33:32 -0700666 case CAMERA_MSG_ERROR :
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800667 Log.e(TAG, "Error " + msg.arg1);
Dave Sparkse8b26e12009-07-14 10:35:40 -0700668 if (mErrorCallback != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800669 mErrorCallback.onError(msg.arg1, mCamera);
Dave Sparkse8b26e12009-07-14 10:35:40 -0700670 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800671 return;
672
673 default:
674 Log.e(TAG, "Unknown message type " + msg.what);
675 return;
676 }
677 }
678 }
679
680 private static void postEventFromNative(Object camera_ref,
681 int what, int arg1, int arg2, Object obj)
682 {
683 Camera c = (Camera)((WeakReference)camera_ref).get();
684 if (c == null)
685 return;
686
687 if (c.mEventHandler != null) {
688 Message m = c.mEventHandler.obtainMessage(what, arg1, arg2, obj);
689 c.mEventHandler.sendMessage(m);
690 }
691 }
692
693 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700694 * Callback interface used to notify on completion of camera auto focus.
695 *
Wu-cheng Li7478ea62009-09-16 18:52:55 +0800696 * <p>Devices that do not support auto-focus will receive a "fake"
697 * callback to this interface. If your application needs auto-focus and
Scott Maindf4578e2009-09-10 12:22:07 -0700698 * should not be installed on devices <em>without</em> auto-focus, you must
699 * declare that your app uses the
Wu-cheng Li7478ea62009-09-16 18:52:55 +0800700 * {@code android.hardware.camera.autofocus} feature, in the
Scott Maindf4578e2009-09-10 12:22:07 -0700701 * <a href="{@docRoot}guide/topics/manifest/uses-feature-element.html">&lt;uses-feature></a>
702 * manifest element.</p>
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700703 *
704 * @see #autoFocus(AutoFocusCallback)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800705 */
706 public interface AutoFocusCallback
707 {
708 /**
Brad Fitzpatrick69ea4e12011-01-05 11:13:40 -0800709 * Called when the camera auto focus completes. If the camera
710 * does not support auto-focus and autoFocus is called,
711 * onAutoFocus will be called immediately with a fake value of
712 * <code>success</code> set to <code>true</code>.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800713 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800714 * @param success true if focus was successful, false if otherwise
715 * @param camera the Camera service object
716 */
717 void onAutoFocus(boolean success, Camera camera);
718 };
719
720 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700721 * Starts camera auto-focus and registers a callback function to run when
722 * the camera is focused. This method is only valid when preview is active
723 * (between {@link #startPreview()} and before {@link #stopPreview()}).
724 *
725 * <p>Callers should check
726 * {@link android.hardware.Camera.Parameters#getFocusMode()} to determine if
727 * this method should be called. If the camera does not support auto-focus,
728 * it is a no-op and {@link AutoFocusCallback#onAutoFocus(boolean, Camera)}
Wu-cheng Li36322db2009-09-18 18:59:21 +0800729 * callback will be called immediately.
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700730 *
Scott Mainda0a56d2009-09-10 18:08:37 -0700731 * <p>If your application should not be installed
Wu-cheng Li7478ea62009-09-16 18:52:55 +0800732 * on devices without auto-focus, you must declare that your application
733 * uses auto-focus with the
Scott Maindf4578e2009-09-10 12:22:07 -0700734 * <a href="{@docRoot}guide/topics/manifest/uses-feature-element.html">&lt;uses-feature></a>
735 * manifest element.</p>
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700736 *
Wu-cheng Li068ef422009-09-27 13:19:36 -0700737 * <p>If the current flash mode is not
738 * {@link android.hardware.Camera.Parameters#FLASH_MODE_OFF}, flash may be
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700739 * fired during auto-focus, depending on the driver and camera hardware.<p>
Wu-cheng Li7478ea62009-09-16 18:52:55 +0800740 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800741 * @param cb the callback to run
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700742 * @see #cancelAutoFocus()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800743 */
744 public final void autoFocus(AutoFocusCallback cb)
745 {
746 mAutoFocusCallback = cb;
747 native_autoFocus();
748 }
749 private native final void native_autoFocus();
750
751 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700752 * Cancels any auto-focus function in progress.
753 * Whether or not auto-focus is currently in progress,
754 * this function will return the focus position to the default.
Chih-Chung Chang244f8c22009-09-15 14:51:56 +0800755 * If the camera does not support auto-focus, this is a no-op.
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700756 *
757 * @see #autoFocus(Camera.AutoFocusCallback)
Chih-Chung Chang244f8c22009-09-15 14:51:56 +0800758 */
759 public final void cancelAutoFocus()
760 {
761 mAutoFocusCallback = null;
762 native_cancelAutoFocus();
763 }
764 private native final void native_cancelAutoFocus();
765
766 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700767 * Callback interface used to signal the moment of actual image capture.
768 *
769 * @see #takePicture(ShutterCallback, PictureCallback, PictureCallback, PictureCallback)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800770 */
771 public interface ShutterCallback
772 {
773 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700774 * Called as near as possible to the moment when a photo is captured
775 * from the sensor. This is a good opportunity to play a shutter sound
776 * or give other feedback of camera operation. This may be some time
777 * after the photo was triggered, but some time before the actual data
778 * is available.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800779 */
780 void onShutter();
781 }
782
783 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700784 * Callback interface used to supply image data from a photo capture.
785 *
786 * @see #takePicture(ShutterCallback, PictureCallback, PictureCallback, PictureCallback)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800787 */
788 public interface PictureCallback {
789 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700790 * Called when image data is available after a picture is taken.
791 * The format of the data depends on the context of the callback
792 * and {@link Camera.Parameters} settings.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800793 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800794 * @param data a byte array of the picture data
795 * @param camera the Camera service object
796 */
797 void onPictureTaken(byte[] data, Camera camera);
798 };
799
800 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700801 * Equivalent to takePicture(shutter, raw, null, jpeg).
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800802 *
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700803 * @see #takePicture(ShutterCallback, PictureCallback, PictureCallback, PictureCallback)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800804 */
805 public final void takePicture(ShutterCallback shutter, PictureCallback raw,
806 PictureCallback jpeg) {
Dave Sparkse8b26e12009-07-14 10:35:40 -0700807 takePicture(shutter, raw, null, jpeg);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800808 }
James Donge00cab72011-02-17 16:38:06 -0800809 private native final void native_takePicture(int msgType);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800810
Dave Sparkse8b26e12009-07-14 10:35:40 -0700811 /**
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800812 * Triggers an asynchronous image capture. The camera service will initiate
813 * a series of callbacks to the application as the image capture progresses.
814 * The shutter callback occurs after the image is captured. This can be used
815 * to trigger a sound to let the user know that image has been captured. The
816 * raw callback occurs when the raw image data is available (NOTE: the data
James Donge00cab72011-02-17 16:38:06 -0800817 * will be null if there is no raw image callback buffer available or the
818 * raw image callback buffer is not large enough to hold the raw image).
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800819 * The postview callback occurs when a scaled, fully processed postview
820 * image is available (NOTE: not all hardware supports this). The jpeg
821 * callback occurs when the compressed image is available. If the
822 * application does not need a particular callback, a null can be passed
823 * instead of a callback method.
Dave Sparkse8b26e12009-07-14 10:35:40 -0700824 *
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700825 * <p>This method is only valid when preview is active (after
826 * {@link #startPreview()}). Preview will be stopped after the image is
827 * taken; callers must call {@link #startPreview()} again if they want to
828 * re-start preview or take more pictures.
Wu-cheng Li40057ce2009-12-02 18:57:29 +0800829 *
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700830 * <p>After calling this method, you must not call {@link #startPreview()}
831 * or take another picture until the JPEG callback has returned.
832 *
833 * @param shutter the callback for image capture moment, or null
834 * @param raw the callback for raw (uncompressed) image data, or null
Dave Sparkse8b26e12009-07-14 10:35:40 -0700835 * @param postview callback with postview image data, may be null
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700836 * @param jpeg the callback for JPEG image data, or null
James Donge00cab72011-02-17 16:38:06 -0800837 *
838 * @see #addRawImageCallbackBuffer(byte[])
Dave Sparkse8b26e12009-07-14 10:35:40 -0700839 */
840 public final void takePicture(ShutterCallback shutter, PictureCallback raw,
841 PictureCallback postview, PictureCallback jpeg) {
842 mShutterCallback = shutter;
843 mRawImageCallback = raw;
844 mPostviewCallback = postview;
845 mJpegCallback = jpeg;
James Donge00cab72011-02-17 16:38:06 -0800846
847 // If callback is not set, do not send me callbacks.
848 int msgType = 0;
849 if (mShutterCallback != null) {
850 msgType |= CAMERA_MSG_SHUTTER;
851 }
852 if (mRawImageCallback != null) {
853 msgType |= CAMERA_MSG_RAW_IMAGE;
854 }
855 if (mPostviewCallback != null) {
856 msgType |= CAMERA_MSG_POSTVIEW_FRAME;
857 }
858 if (mJpegCallback != null) {
859 msgType |= CAMERA_MSG_COMPRESSED_IMAGE;
860 }
861
862 native_takePicture(msgType);
Dave Sparkse8b26e12009-07-14 10:35:40 -0700863 }
864
865 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700866 * Zooms to the requested value smoothly. The driver will notify {@link
Wu-cheng Li3f4639a2010-04-04 15:05:41 +0800867 * OnZoomChangeListener} of the zoom value and whether zoom is stopped at
868 * the time. For example, suppose the current zoom is 0 and startSmoothZoom
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700869 * is called with value 3. The
870 * {@link Camera.OnZoomChangeListener#onZoomChange(int, boolean, Camera)}
871 * method will be called three times with zoom values 1, 2, and 3.
872 * Applications can call {@link #stopSmoothZoom} to stop the zoom earlier.
873 * Applications should not call startSmoothZoom again or change the zoom
874 * value before zoom stops. If the supplied zoom value equals to the current
875 * zoom value, no zoom callback will be generated. This method is supported
876 * if {@link android.hardware.Camera.Parameters#isSmoothZoomSupported}
877 * returns true.
Wu-cheng Li36f68b82009-09-28 16:14:58 -0700878 *
879 * @param value zoom value. The valid range is 0 to {@link
880 * android.hardware.Camera.Parameters#getMaxZoom}.
Wu-cheng Li0ca25192010-03-29 16:21:12 +0800881 * @throws IllegalArgumentException if the zoom value is invalid.
882 * @throws RuntimeException if the method fails.
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700883 * @see #setZoomChangeListener(OnZoomChangeListener)
Wu-cheng Li36f68b82009-09-28 16:14:58 -0700884 */
885 public native final void startSmoothZoom(int value);
886
887 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700888 * Stops the smooth zoom. Applications should wait for the {@link
Wu-cheng Li3f4639a2010-04-04 15:05:41 +0800889 * OnZoomChangeListener} to know when the zoom is actually stopped. This
890 * method is supported if {@link
Wu-cheng Li8cbb8f52010-02-28 23:19:55 -0800891 * android.hardware.Camera.Parameters#isSmoothZoomSupported} is true.
Wu-cheng Li0ca25192010-03-29 16:21:12 +0800892 *
893 * @throws RuntimeException if the method fails.
Wu-cheng Li36f68b82009-09-28 16:14:58 -0700894 */
895 public native final void stopSmoothZoom();
896
897 /**
Wu-cheng Li2fe6fca2010-10-15 14:42:23 +0800898 * Set the clockwise rotation of preview display in degrees. This affects
899 * the preview frames and the picture displayed after snapshot. This method
900 * is useful for portrait mode applications. Note that preview display of
Wu-cheng Lib982fb42010-10-19 17:19:09 +0800901 * front-facing cameras is flipped horizontally before the rotation, that
902 * is, the image is reflected along the central vertical axis of the camera
903 * sensor. So the users can see themselves as looking into a mirror.
Chih-Chung Changd1d77062010-01-22 17:49:48 -0800904 *
Brad Fitzpatrick69ea4e12011-01-05 11:13:40 -0800905 * <p>This does not affect the order of byte array passed in {@link
Wu-cheng Li2fe6fca2010-10-15 14:42:23 +0800906 * PreviewCallback#onPreviewFrame}, JPEG pictures, or recorded videos. This
907 * method is not allowed to be called during preview.
Chih-Chung Changd1d77062010-01-22 17:49:48 -0800908 *
Brad Fitzpatrick69ea4e12011-01-05 11:13:40 -0800909 * <p>If you want to make the camera image show in the same orientation as
910 * the display, you can use the following code.
Chih-Chung Changb8bb78f2010-06-10 13:32:16 +0800911 * <pre>
Chih-Chung Chang724c5222010-06-14 18:57:15 +0800912 * public static void setCameraDisplayOrientation(Activity activity,
913 * int cameraId, android.hardware.Camera camera) {
914 * android.hardware.Camera.CameraInfo info =
915 * new android.hardware.Camera.CameraInfo();
916 * android.hardware.Camera.getCameraInfo(cameraId, info);
917 * int rotation = activity.getWindowManager().getDefaultDisplay()
918 * .getRotation();
919 * int degrees = 0;
920 * switch (rotation) {
921 * case Surface.ROTATION_0: degrees = 0; break;
922 * case Surface.ROTATION_90: degrees = 90; break;
923 * case Surface.ROTATION_180: degrees = 180; break;
924 * case Surface.ROTATION_270: degrees = 270; break;
925 * }
Chih-Chung Changb8bb78f2010-06-10 13:32:16 +0800926 *
Wu-cheng Li2fe6fca2010-10-15 14:42:23 +0800927 * int result;
928 * if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
929 * result = (info.orientation + degrees) % 360;
930 * result = (360 - result) % 360; // compensate the mirror
931 * } else { // back-facing
932 * result = (info.orientation - degrees + 360) % 360;
933 * }
Chih-Chung Chang724c5222010-06-14 18:57:15 +0800934 * camera.setDisplayOrientation(result);
935 * }
Chih-Chung Changb8bb78f2010-06-10 13:32:16 +0800936 * </pre>
Chih-Chung Changd1d77062010-01-22 17:49:48 -0800937 * @param degrees the angle that the picture will be rotated clockwise.
Chih-Chung Change7bd22a2010-01-27 10:24:42 -0800938 * Valid values are 0, 90, 180, and 270. The starting
939 * position is 0 (landscape).
Wu-cheng Li2fe6fca2010-10-15 14:42:23 +0800940 * @see #setPreviewDisplay(SurfaceHolder)
Chih-Chung Changd1d77062010-01-22 17:49:48 -0800941 */
942 public native final void setDisplayOrientation(int degrees);
943
944 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700945 * Callback interface for zoom changes during a smooth zoom operation.
946 *
947 * @see #setZoomChangeListener(OnZoomChangeListener)
948 * @see #startSmoothZoom(int)
Dave Sparkse8b26e12009-07-14 10:35:40 -0700949 */
Wu-cheng Li3f4639a2010-04-04 15:05:41 +0800950 public interface OnZoomChangeListener
Dave Sparkse8b26e12009-07-14 10:35:40 -0700951 {
952 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700953 * Called when the zoom value has changed during a smooth zoom.
Wu-cheng Li36f68b82009-09-28 16:14:58 -0700954 *
955 * @param zoomValue the current zoom value. In smooth zoom mode, camera
Wu-cheng Li3f4639a2010-04-04 15:05:41 +0800956 * calls this for every new zoom value.
Wu-cheng Li36f68b82009-09-28 16:14:58 -0700957 * @param stopped whether smooth zoom is stopped. If the value is true,
958 * this is the last zoom update for the application.
Dave Sparkse8b26e12009-07-14 10:35:40 -0700959 * @param camera the Camera service object
960 */
Wu-cheng Li3f4639a2010-04-04 15:05:41 +0800961 void onZoomChange(int zoomValue, boolean stopped, Camera camera);
Dave Sparkse8b26e12009-07-14 10:35:40 -0700962 };
963
964 /**
Wu-cheng Li3f4639a2010-04-04 15:05:41 +0800965 * Registers a listener to be notified when the zoom value is updated by the
Wu-cheng Li36f68b82009-09-28 16:14:58 -0700966 * camera driver during smooth zoom.
Wu-cheng Li8cbb8f52010-02-28 23:19:55 -0800967 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +0800968 * @param listener the listener to notify
Wu-cheng Li8cbb8f52010-02-28 23:19:55 -0800969 * @see #startSmoothZoom(int)
Dave Sparkse8b26e12009-07-14 10:35:40 -0700970 */
Wu-cheng Li3f4639a2010-04-04 15:05:41 +0800971 public final void setZoomChangeListener(OnZoomChangeListener listener)
Dave Sparkse8b26e12009-07-14 10:35:40 -0700972 {
Wu-cheng Li3f4639a2010-04-04 15:05:41 +0800973 mZoomListener = listener;
Dave Sparkse8b26e12009-07-14 10:35:40 -0700974 }
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800975
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700976 // Error codes match the enum in include/ui/Camera.h
977
978 /**
979 * Unspecified camera error.
980 * @see Camera.ErrorCallback
981 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800982 public static final int CAMERA_ERROR_UNKNOWN = 1;
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700983
984 /**
985 * Media server died. In this case, the application must release the
986 * Camera object and instantiate a new one.
987 * @see Camera.ErrorCallback
988 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800989 public static final int CAMERA_ERROR_SERVER_DIED = 100;
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800990
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800991 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700992 * Callback interface for camera error notification.
993 *
994 * @see #setErrorCallback(ErrorCallback)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800995 */
996 public interface ErrorCallback
997 {
998 /**
999 * Callback for camera errors.
1000 * @param error error code:
1001 * <ul>
1002 * <li>{@link #CAMERA_ERROR_UNKNOWN}
1003 * <li>{@link #CAMERA_ERROR_SERVER_DIED}
1004 * </ul>
1005 * @param camera the Camera service object
1006 */
1007 void onError(int error, Camera camera);
1008 };
1009
1010 /**
1011 * Registers a callback to be invoked when an error occurs.
Dan Egnorbfcbeff2010-07-12 15:12:54 -07001012 * @param cb The callback to run
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001013 */
1014 public final void setErrorCallback(ErrorCallback cb)
1015 {
1016 mErrorCallback = cb;
1017 }
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001018
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001019 private native final void native_setParameters(String params);
1020 private native final String native_getParameters();
1021
1022 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -07001023 * Changes the settings for this Camera service.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001024 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001025 * @param params the Parameters to use for this Camera service
Wu-cheng Li99a3f3e2010-11-19 15:56:16 +08001026 * @throws RuntimeException if any parameter is invalid or not supported.
Dan Egnorbfcbeff2010-07-12 15:12:54 -07001027 * @see #getParameters()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001028 */
1029 public void setParameters(Parameters params) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001030 native_setParameters(params.flatten());
1031 }
1032
1033 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -07001034 * Returns the current settings for this Camera service.
1035 * If modifications are made to the returned Parameters, they must be passed
1036 * to {@link #setParameters(Camera.Parameters)} to take effect.
1037 *
1038 * @see #setParameters(Camera.Parameters)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001039 */
1040 public Parameters getParameters() {
1041 Parameters p = new Parameters();
1042 String s = native_getParameters();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001043 p.unflatten(s);
1044 return p;
1045 }
1046
1047 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -07001048 * Image size (width and height dimensions).
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001049 */
1050 public class Size {
1051 /**
1052 * Sets the dimensions for pictures.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001053 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001054 * @param w the photo width (pixels)
1055 * @param h the photo height (pixels)
1056 */
1057 public Size(int w, int h) {
1058 width = w;
1059 height = h;
1060 }
Wu-cheng Li4c4300c2010-01-23 15:45:39 +08001061 /**
1062 * Compares {@code obj} to this size.
1063 *
1064 * @param obj the object to compare this size with.
1065 * @return {@code true} if the width and height of {@code obj} is the
1066 * same as those of this size. {@code false} otherwise.
1067 */
1068 @Override
1069 public boolean equals(Object obj) {
1070 if (!(obj instanceof Size)) {
1071 return false;
1072 }
1073 Size s = (Size) obj;
1074 return width == s.width && height == s.height;
1075 }
1076 @Override
1077 public int hashCode() {
1078 return width * 32713 + height;
1079 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001080 /** width of the picture */
1081 public int width;
1082 /** height of the picture */
1083 public int height;
1084 };
1085
1086 /**
Wu-cheng Li30771b72011-04-02 06:19:46 +08001087 * Area class for focus.
1088 *
1089 * @see #setFocusAreas(List<Area>)
1090 * @see #getFocusAreas()
1091 * @hide
1092 */
1093 public static class Area {
1094 /**
1095 * Create an area with specified rectangle and weight.
1096 *
1097 * @param rect the rectangle of the area
1098 * @param weight the weight of the area
1099 */
1100 public Area(Rect rect, int weight) {
1101 this.rect = rect;
1102 this.weight = weight;
1103 }
1104 /**
1105 * Compares {@code obj} to this area.
1106 *
1107 * @param obj the object to compare this area with.
1108 * @return {@code true} if the rectangle and weight of {@code obj} is
1109 * the same as those of this area. {@code false} otherwise.
1110 */
1111 @Override
1112 public boolean equals(Object obj) {
1113 if (!(obj instanceof Area)) {
1114 return false;
1115 }
1116 Area a = (Area) obj;
1117 if (rect == null) {
1118 if (a.rect != null) return false;
1119 } else {
1120 if (!rect.equals(a.rect)) return false;
1121 }
1122 return weight == a.weight;
1123 }
1124
1125 /** rectangle of the area */
1126 public Rect rect;
1127
1128 /** weight of the area */
1129 public int weight;
1130 };
1131
1132 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -07001133 * Camera service settings.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001134 *
1135 * <p>To make camera parameters take effect, applications have to call
Dan Egnorbfcbeff2010-07-12 15:12:54 -07001136 * {@link Camera#setParameters(Camera.Parameters)}. For example, after
1137 * {@link Camera.Parameters#setWhiteBalance} is called, white balance is not
1138 * actually changed until {@link Camera#setParameters(Camera.Parameters)}
1139 * is called with the changed parameters object.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001140 *
1141 * <p>Different devices may have different camera capabilities, such as
1142 * picture size or flash modes. The application should query the camera
1143 * capabilities before setting parameters. For example, the application
Dan Egnorbfcbeff2010-07-12 15:12:54 -07001144 * should call {@link Camera.Parameters#getSupportedColorEffects()} before
1145 * calling {@link Camera.Parameters#setColorEffect(String)}. If the
1146 * camera does not support color effects,
1147 * {@link Camera.Parameters#getSupportedColorEffects()} will return null.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001148 */
1149 public class Parameters {
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001150 // Parameter keys to communicate with the camera driver.
1151 private static final String KEY_PREVIEW_SIZE = "preview-size";
1152 private static final String KEY_PREVIEW_FORMAT = "preview-format";
1153 private static final String KEY_PREVIEW_FRAME_RATE = "preview-frame-rate";
Wu-cheng Li454630f2010-08-11 16:48:05 -07001154 private static final String KEY_PREVIEW_FPS_RANGE = "preview-fps-range";
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001155 private static final String KEY_PICTURE_SIZE = "picture-size";
1156 private static final String KEY_PICTURE_FORMAT = "picture-format";
Wu-cheng Li4c4300c2010-01-23 15:45:39 +08001157 private static final String KEY_JPEG_THUMBNAIL_SIZE = "jpeg-thumbnail-size";
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001158 private static final String KEY_JPEG_THUMBNAIL_WIDTH = "jpeg-thumbnail-width";
1159 private static final String KEY_JPEG_THUMBNAIL_HEIGHT = "jpeg-thumbnail-height";
1160 private static final String KEY_JPEG_THUMBNAIL_QUALITY = "jpeg-thumbnail-quality";
1161 private static final String KEY_JPEG_QUALITY = "jpeg-quality";
1162 private static final String KEY_ROTATION = "rotation";
1163 private static final String KEY_GPS_LATITUDE = "gps-latitude";
1164 private static final String KEY_GPS_LONGITUDE = "gps-longitude";
1165 private static final String KEY_GPS_ALTITUDE = "gps-altitude";
1166 private static final String KEY_GPS_TIMESTAMP = "gps-timestamp";
Ray Chen055c9862010-02-23 10:45:42 +08001167 private static final String KEY_GPS_PROCESSING_METHOD = "gps-processing-method";
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001168 private static final String KEY_WHITE_BALANCE = "whitebalance";
1169 private static final String KEY_EFFECT = "effect";
1170 private static final String KEY_ANTIBANDING = "antibanding";
1171 private static final String KEY_SCENE_MODE = "scene-mode";
1172 private static final String KEY_FLASH_MODE = "flash-mode";
Wu-cheng Li36322db2009-09-18 18:59:21 +08001173 private static final String KEY_FOCUS_MODE = "focus-mode";
Wu-cheng Li30771b72011-04-02 06:19:46 +08001174 private static final String KEY_FOCUS_AREAS = "focus-areas";
1175 private static final String KEY_MAX_NUM_FOCUS_AREAS = "max-num-focus-areas";
Wu-cheng Li6c8d2762010-01-27 22:55:14 +08001176 private static final String KEY_FOCAL_LENGTH = "focal-length";
1177 private static final String KEY_HORIZONTAL_VIEW_ANGLE = "horizontal-view-angle";
1178 private static final String KEY_VERTICAL_VIEW_ANGLE = "vertical-view-angle";
Wu-cheng Liff723b62010-02-09 13:38:19 +08001179 private static final String KEY_EXPOSURE_COMPENSATION = "exposure-compensation";
Wu-cheng Li24b326a2010-02-20 17:47:04 +08001180 private static final String KEY_MAX_EXPOSURE_COMPENSATION = "max-exposure-compensation";
1181 private static final String KEY_MIN_EXPOSURE_COMPENSATION = "min-exposure-compensation";
1182 private static final String KEY_EXPOSURE_COMPENSATION_STEP = "exposure-compensation-step";
Wu-cheng Li8cbb8f52010-02-28 23:19:55 -08001183 private static final String KEY_ZOOM = "zoom";
1184 private static final String KEY_MAX_ZOOM = "max-zoom";
1185 private static final String KEY_ZOOM_RATIOS = "zoom-ratios";
1186 private static final String KEY_ZOOM_SUPPORTED = "zoom-supported";
1187 private static final String KEY_SMOOTH_ZOOM_SUPPORTED = "smooth-zoom-supported";
Wu-cheng Lie339c5e2010-05-13 19:31:02 +08001188 private static final String KEY_FOCUS_DISTANCES = "focus-distances";
James Dongdd0b16c2010-09-21 16:23:48 -07001189 private static final String KEY_VIDEO_SIZE = "video-size";
1190 private static final String KEY_PREFERRED_PREVIEW_SIZE_FOR_VIDEO =
1191 "preferred-preview-size-for-video";
Wu-cheng Lie339c5e2010-05-13 19:31:02 +08001192
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001193 // Parameter key suffix for supported values.
1194 private static final String SUPPORTED_VALUES_SUFFIX = "-values";
1195
Wu-cheng Li8cbb8f52010-02-28 23:19:55 -08001196 private static final String TRUE = "true";
1197
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001198 // Values for white balance settings.
1199 public static final String WHITE_BALANCE_AUTO = "auto";
1200 public static final String WHITE_BALANCE_INCANDESCENT = "incandescent";
1201 public static final String WHITE_BALANCE_FLUORESCENT = "fluorescent";
1202 public static final String WHITE_BALANCE_WARM_FLUORESCENT = "warm-fluorescent";
1203 public static final String WHITE_BALANCE_DAYLIGHT = "daylight";
1204 public static final String WHITE_BALANCE_CLOUDY_DAYLIGHT = "cloudy-daylight";
1205 public static final String WHITE_BALANCE_TWILIGHT = "twilight";
1206 public static final String WHITE_BALANCE_SHADE = "shade";
1207
1208 // Values for color effect settings.
1209 public static final String EFFECT_NONE = "none";
1210 public static final String EFFECT_MONO = "mono";
1211 public static final String EFFECT_NEGATIVE = "negative";
1212 public static final String EFFECT_SOLARIZE = "solarize";
1213 public static final String EFFECT_SEPIA = "sepia";
1214 public static final String EFFECT_POSTERIZE = "posterize";
1215 public static final String EFFECT_WHITEBOARD = "whiteboard";
1216 public static final String EFFECT_BLACKBOARD = "blackboard";
1217 public static final String EFFECT_AQUA = "aqua";
1218
1219 // Values for antibanding settings.
1220 public static final String ANTIBANDING_AUTO = "auto";
1221 public static final String ANTIBANDING_50HZ = "50hz";
1222 public static final String ANTIBANDING_60HZ = "60hz";
1223 public static final String ANTIBANDING_OFF = "off";
1224
1225 // Values for flash mode settings.
1226 /**
1227 * Flash will not be fired.
1228 */
1229 public static final String FLASH_MODE_OFF = "off";
Wu-cheng Li36f68b82009-09-28 16:14:58 -07001230
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001231 /**
Wu-cheng Li068ef422009-09-27 13:19:36 -07001232 * Flash will be fired automatically when required. The flash may be fired
1233 * during preview, auto-focus, or snapshot depending on the driver.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001234 */
1235 public static final String FLASH_MODE_AUTO = "auto";
Wu-cheng Li36f68b82009-09-28 16:14:58 -07001236
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001237 /**
Wu-cheng Li068ef422009-09-27 13:19:36 -07001238 * Flash will always be fired during snapshot. The flash may also be
1239 * fired during preview or auto-focus depending on the driver.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001240 */
1241 public static final String FLASH_MODE_ON = "on";
Wu-cheng Li36f68b82009-09-28 16:14:58 -07001242
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001243 /**
1244 * Flash will be fired in red-eye reduction mode.
1245 */
1246 public static final String FLASH_MODE_RED_EYE = "red-eye";
Wu-cheng Li36f68b82009-09-28 16:14:58 -07001247
Wu-cheng Li36322db2009-09-18 18:59:21 +08001248 /**
Wu-cheng Li068ef422009-09-27 13:19:36 -07001249 * Constant emission of light during preview, auto-focus and snapshot.
1250 * This can also be used for video recording.
Wu-cheng Li36322db2009-09-18 18:59:21 +08001251 */
Wu-cheng Li068ef422009-09-27 13:19:36 -07001252 public static final String FLASH_MODE_TORCH = "torch";
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001253
Wu-cheng Li00e21f82010-05-28 16:43:38 +08001254 /**
1255 * Scene mode is off.
1256 */
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001257 public static final String SCENE_MODE_AUTO = "auto";
Wu-cheng Li00e21f82010-05-28 16:43:38 +08001258
1259 /**
1260 * Take photos of fast moving objects. Same as {@link
1261 * #SCENE_MODE_SPORTS}.
1262 */
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001263 public static final String SCENE_MODE_ACTION = "action";
Wu-cheng Li00e21f82010-05-28 16:43:38 +08001264
1265 /**
1266 * Take people pictures.
1267 */
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001268 public static final String SCENE_MODE_PORTRAIT = "portrait";
Wu-cheng Li00e21f82010-05-28 16:43:38 +08001269
1270 /**
1271 * Take pictures on distant objects.
1272 */
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001273 public static final String SCENE_MODE_LANDSCAPE = "landscape";
Wu-cheng Li00e21f82010-05-28 16:43:38 +08001274
1275 /**
1276 * Take photos at night.
1277 */
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001278 public static final String SCENE_MODE_NIGHT = "night";
Wu-cheng Li00e21f82010-05-28 16:43:38 +08001279
1280 /**
1281 * Take people pictures at night.
1282 */
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001283 public static final String SCENE_MODE_NIGHT_PORTRAIT = "night-portrait";
Wu-cheng Li00e21f82010-05-28 16:43:38 +08001284
1285 /**
1286 * Take photos in a theater. Flash light is off.
1287 */
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001288 public static final String SCENE_MODE_THEATRE = "theatre";
Wu-cheng Li00e21f82010-05-28 16:43:38 +08001289
1290 /**
1291 * Take pictures on the beach.
1292 */
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001293 public static final String SCENE_MODE_BEACH = "beach";
Wu-cheng Li00e21f82010-05-28 16:43:38 +08001294
1295 /**
1296 * Take pictures on the snow.
1297 */
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001298 public static final String SCENE_MODE_SNOW = "snow";
Wu-cheng Li00e21f82010-05-28 16:43:38 +08001299
1300 /**
1301 * Take sunset photos.
1302 */
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001303 public static final String SCENE_MODE_SUNSET = "sunset";
Wu-cheng Li00e21f82010-05-28 16:43:38 +08001304
1305 /**
1306 * Avoid blurry pictures (for example, due to hand shake).
1307 */
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001308 public static final String SCENE_MODE_STEADYPHOTO = "steadyphoto";
Wu-cheng Li00e21f82010-05-28 16:43:38 +08001309
1310 /**
1311 * For shooting firework displays.
1312 */
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001313 public static final String SCENE_MODE_FIREWORKS = "fireworks";
Wu-cheng Li00e21f82010-05-28 16:43:38 +08001314
1315 /**
1316 * Take photos of fast moving objects. Same as {@link
1317 * #SCENE_MODE_ACTION}.
1318 */
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001319 public static final String SCENE_MODE_SPORTS = "sports";
Wu-cheng Li00e21f82010-05-28 16:43:38 +08001320
1321 /**
1322 * Take indoor low-light shot.
1323 */
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001324 public static final String SCENE_MODE_PARTY = "party";
Wu-cheng Li00e21f82010-05-28 16:43:38 +08001325
1326 /**
1327 * Capture the naturally warm color of scenes lit by candles.
1328 */
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001329 public static final String SCENE_MODE_CANDLELIGHT = "candlelight";
1330
Wu-cheng Lic58b4232010-03-29 17:21:28 +08001331 /**
1332 * Applications are looking for a barcode. Camera driver will be
1333 * optimized for barcode reading.
1334 */
1335 public static final String SCENE_MODE_BARCODE = "barcode";
1336
Wu-cheng Li36322db2009-09-18 18:59:21 +08001337 /**
Wu-cheng Lif008f3e2010-08-17 13:44:35 -07001338 * Auto-focus mode. Applications should call {@link
1339 * #autoFocus(AutoFocusCallback)} to start the focus in this mode.
Wu-cheng Li36322db2009-09-18 18:59:21 +08001340 */
1341 public static final String FOCUS_MODE_AUTO = "auto";
Wu-cheng Li36f68b82009-09-28 16:14:58 -07001342
Wu-cheng Li36322db2009-09-18 18:59:21 +08001343 /**
1344 * Focus is set at infinity. Applications should not call
1345 * {@link #autoFocus(AutoFocusCallback)} in this mode.
1346 */
1347 public static final String FOCUS_MODE_INFINITY = "infinity";
Wu-cheng Lif008f3e2010-08-17 13:44:35 -07001348
1349 /**
1350 * Macro (close-up) focus mode. Applications should call
1351 * {@link #autoFocus(AutoFocusCallback)} to start the focus in this
1352 * mode.
1353 */
Wu-cheng Li36322db2009-09-18 18:59:21 +08001354 public static final String FOCUS_MODE_MACRO = "macro";
Wu-cheng Li36f68b82009-09-28 16:14:58 -07001355
Wu-cheng Li36322db2009-09-18 18:59:21 +08001356 /**
1357 * Focus is fixed. The camera is always in this mode if the focus is not
1358 * adjustable. If the camera has auto-focus, this mode can fix the
1359 * focus, which is usually at hyperfocal distance. Applications should
1360 * not call {@link #autoFocus(AutoFocusCallback)} in this mode.
1361 */
1362 public static final String FOCUS_MODE_FIXED = "fixed";
1363
Wu-cheng Lic58b4232010-03-29 17:21:28 +08001364 /**
1365 * Extended depth of field (EDOF). Focusing is done digitally and
1366 * continuously. Applications should not call {@link
1367 * #autoFocus(AutoFocusCallback)} in this mode.
1368 */
1369 public static final String FOCUS_MODE_EDOF = "edof";
1370
Wu-cheng Li699fe932010-08-05 11:50:25 -07001371 /**
Wu-cheng Lid45cb722010-09-20 16:15:32 -07001372 * Continuous auto focus mode intended for video recording. The camera
1373 * continuously tries to focus. This is ideal for shooting video.
1374 * Applications still can call {@link
1375 * #takePicture(Camera.ShutterCallback, Camera.PictureCallback,
1376 * Camera.PictureCallback)} in this mode but the subject may not be in
1377 * focus. Auto focus starts when the parameter is set. Applications
1378 * should not call {@link #autoFocus(AutoFocusCallback)} in this mode.
1379 * To stop continuous focus, applications should change the focus mode
1380 * to other modes.
Wu-cheng Li699fe932010-08-05 11:50:25 -07001381 */
Wu-cheng Lid45cb722010-09-20 16:15:32 -07001382 public static final String FOCUS_MODE_CONTINUOUS_VIDEO = "continuous-video";
Wu-cheng Li699fe932010-08-05 11:50:25 -07001383
Wu-cheng Lie339c5e2010-05-13 19:31:02 +08001384 // Indices for focus distance array.
1385 /**
1386 * The array index of near focus distance for use with
1387 * {@link #getFocusDistances(float[])}.
1388 */
1389 public static final int FOCUS_DISTANCE_NEAR_INDEX = 0;
1390
1391 /**
1392 * The array index of optimal focus distance for use with
1393 * {@link #getFocusDistances(float[])}.
1394 */
1395 public static final int FOCUS_DISTANCE_OPTIMAL_INDEX = 1;
1396
1397 /**
1398 * The array index of far focus distance for use with
1399 * {@link #getFocusDistances(float[])}.
1400 */
1401 public static final int FOCUS_DISTANCE_FAR_INDEX = 2;
1402
Wu-cheng Lica099612010-05-06 16:47:30 +08001403 /**
Wu-cheng Li454630f2010-08-11 16:48:05 -07001404 * The array index of minimum preview fps for use with {@link
1405 * #getPreviewFpsRange(int[])} or {@link
1406 * #getSupportedPreviewFpsRange()}.
Wu-cheng Li454630f2010-08-11 16:48:05 -07001407 */
1408 public static final int PREVIEW_FPS_MIN_INDEX = 0;
1409
1410 /**
1411 * The array index of maximum preview fps for use with {@link
1412 * #getPreviewFpsRange(int[])} or {@link
1413 * #getSupportedPreviewFpsRange()}.
Wu-cheng Li454630f2010-08-11 16:48:05 -07001414 */
1415 public static final int PREVIEW_FPS_MAX_INDEX = 1;
1416
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001417 // Formats for setPreviewFormat and setPictureFormat.
1418 private static final String PIXEL_FORMAT_YUV422SP = "yuv422sp";
1419 private static final String PIXEL_FORMAT_YUV420SP = "yuv420sp";
Chih-Chung Changeb68c462009-09-18 18:37:44 +08001420 private static final String PIXEL_FORMAT_YUV422I = "yuv422i-yuyv";
Wu-cheng Li10a1b302011-02-22 15:49:25 +08001421 private static final String PIXEL_FORMAT_YUV420P = "yuv420p";
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001422 private static final String PIXEL_FORMAT_RGB565 = "rgb565";
1423 private static final String PIXEL_FORMAT_JPEG = "jpeg";
1424
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001425 private HashMap<String, String> mMap;
1426
1427 private Parameters() {
1428 mMap = new HashMap<String, String>();
1429 }
1430
1431 /**
1432 * Writes the current Parameters to the log.
1433 * @hide
1434 * @deprecated
1435 */
1436 public void dump() {
1437 Log.e(TAG, "dump: size=" + mMap.size());
1438 for (String k : mMap.keySet()) {
1439 Log.e(TAG, "dump: " + k + "=" + mMap.get(k));
1440 }
1441 }
1442
1443 /**
1444 * Creates a single string with all the parameters set in
1445 * this Parameters object.
1446 * <p>The {@link #unflatten(String)} method does the reverse.</p>
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001447 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001448 * @return a String with all values from this Parameters object, in
1449 * semi-colon delimited key-value pairs
1450 */
1451 public String flatten() {
1452 StringBuilder flattened = new StringBuilder();
1453 for (String k : mMap.keySet()) {
1454 flattened.append(k);
1455 flattened.append("=");
1456 flattened.append(mMap.get(k));
1457 flattened.append(";");
1458 }
1459 // chop off the extra semicolon at the end
1460 flattened.deleteCharAt(flattened.length()-1);
1461 return flattened.toString();
1462 }
1463
1464 /**
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001465 * Takes a flattened string of parameters and adds each one to
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001466 * this Parameters object.
1467 * <p>The {@link #flatten()} method does the reverse.</p>
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001468 *
1469 * @param flattened a String of parameters (key-value paired) that
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001470 * are semi-colon delimited
1471 */
1472 public void unflatten(String flattened) {
1473 mMap.clear();
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001474
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001475 StringTokenizer tokenizer = new StringTokenizer(flattened, ";");
1476 while (tokenizer.hasMoreElements()) {
1477 String kv = tokenizer.nextToken();
1478 int pos = kv.indexOf('=');
1479 if (pos == -1) {
1480 continue;
1481 }
1482 String k = kv.substring(0, pos);
1483 String v = kv.substring(pos + 1);
1484 mMap.put(k, v);
1485 }
1486 }
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001487
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001488 public void remove(String key) {
1489 mMap.remove(key);
1490 }
1491
1492 /**
1493 * Sets a String parameter.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001494 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001495 * @param key the key name for the parameter
1496 * @param value the String value of the parameter
1497 */
1498 public void set(String key, String value) {
1499 if (key.indexOf('=') != -1 || key.indexOf(';') != -1) {
1500 Log.e(TAG, "Key \"" + key + "\" contains invalid character (= or ;)");
1501 return;
1502 }
1503 if (value.indexOf('=') != -1 || value.indexOf(';') != -1) {
1504 Log.e(TAG, "Value \"" + value + "\" contains invalid character (= or ;)");
1505 return;
1506 }
1507
1508 mMap.put(key, value);
1509 }
1510
1511 /**
1512 * Sets an integer parameter.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001513 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001514 * @param key the key name for the parameter
1515 * @param value the int value of the parameter
1516 */
1517 public void set(String key, int value) {
1518 mMap.put(key, Integer.toString(value));
1519 }
1520
1521 /**
1522 * Returns the value of a String parameter.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001523 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001524 * @param key the key name for the parameter
1525 * @return the String value of the parameter
1526 */
1527 public String get(String key) {
1528 return mMap.get(key);
1529 }
1530
1531 /**
1532 * Returns the value of an integer parameter.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001533 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001534 * @param key the key name for the parameter
1535 * @return the int value of the parameter
1536 */
1537 public int getInt(String key) {
1538 return Integer.parseInt(mMap.get(key));
1539 }
1540
1541 /**
1542 * Sets the dimensions for preview pictures.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001543 *
Wu-cheng Lic157e0c2010-10-07 18:36:07 +08001544 * The sides of width and height are based on camera orientation. That
1545 * is, the preview size is the size before it is rotated by display
1546 * orientation. So applications need to consider the display orientation
1547 * while setting preview size. For example, suppose the camera supports
1548 * both 480x320 and 320x480 preview sizes. The application wants a 3:2
1549 * preview ratio. If the display orientation is set to 0 or 180, preview
1550 * size should be set to 480x320. If the display orientation is set to
1551 * 90 or 270, preview size should be set to 320x480. The display
1552 * orientation should also be considered while setting picture size and
1553 * thumbnail size.
1554 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001555 * @param width the width of the pictures, in pixels
1556 * @param height the height of the pictures, in pixels
Wu-cheng Lic157e0c2010-10-07 18:36:07 +08001557 * @see #setDisplayOrientation(int)
1558 * @see #getCameraInfo(int, CameraInfo)
1559 * @see #setPictureSize(int, int)
1560 * @see #setJpegThumbnailSize(int, int)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001561 */
1562 public void setPreviewSize(int width, int height) {
1563 String v = Integer.toString(width) + "x" + Integer.toString(height);
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001564 set(KEY_PREVIEW_SIZE, v);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001565 }
1566
1567 /**
1568 * Returns the dimensions setting for preview pictures.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001569 *
James Dongdd0b16c2010-09-21 16:23:48 -07001570 * @return a Size object with the width and height setting
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001571 * for the preview picture
1572 */
1573 public Size getPreviewSize() {
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001574 String pair = get(KEY_PREVIEW_SIZE);
1575 return strToSize(pair);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001576 }
1577
1578 /**
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001579 * Gets the supported preview sizes.
1580 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08001581 * @return a list of Size object. This method will always return a list
Wu-cheng Li9c799382009-12-04 19:59:18 +08001582 * with at least one element.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001583 */
1584 public List<Size> getSupportedPreviewSizes() {
1585 String str = get(KEY_PREVIEW_SIZE + SUPPORTED_VALUES_SUFFIX);
1586 return splitSize(str);
1587 }
1588
1589 /**
James Dongdd0b16c2010-09-21 16:23:48 -07001590 * Gets the supported video frame sizes that can be used by
1591 * MediaRecorder.
1592 *
1593 * If the returned list is not null, the returned list will contain at
1594 * least one Size and one of the sizes in the returned list must be
1595 * passed to MediaRecorder.setVideoSize() for camcorder application if
1596 * camera is used as the video source. In this case, the size of the
1597 * preview can be different from the resolution of the recorded video
1598 * during video recording.
1599 *
1600 * @return a list of Size object if camera has separate preview and
1601 * video output; otherwise, null is returned.
1602 * @see #getPreferredPreviewSizeForVideo()
1603 */
1604 public List<Size> getSupportedVideoSizes() {
1605 String str = get(KEY_VIDEO_SIZE + SUPPORTED_VALUES_SUFFIX);
1606 return splitSize(str);
1607 }
1608
1609 /**
1610 * Returns the preferred or recommended preview size (width and height)
1611 * in pixels for video recording. Camcorder applications should
1612 * set the preview size to a value that is not larger than the
1613 * preferred preview size. In other words, the product of the width
1614 * and height of the preview size should not be larger than that of
1615 * the preferred preview size. In addition, we recommend to choose a
1616 * preview size that has the same aspect ratio as the resolution of
1617 * video to be recorded.
1618 *
1619 * @return the preferred preview size (width and height) in pixels for
1620 * video recording if getSupportedVideoSizes() does not return
1621 * null; otherwise, null is returned.
1622 * @see #getSupportedVideoSizes()
1623 */
1624 public Size getPreferredPreviewSizeForVideo() {
1625 String pair = get(KEY_PREFERRED_PREVIEW_SIZE_FOR_VIDEO);
1626 return strToSize(pair);
1627 }
1628
1629 /**
Wu-cheng Li4c4300c2010-01-23 15:45:39 +08001630 * Sets the dimensions for EXIF thumbnail in Jpeg picture. If
1631 * applications set both width and height to 0, EXIF will not contain
1632 * thumbnail.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001633 *
Wu-cheng Lic157e0c2010-10-07 18:36:07 +08001634 * Applications need to consider the display orientation. See {@link
1635 * #setPreviewSize(int,int)} for reference.
1636 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001637 * @param width the width of the thumbnail, in pixels
1638 * @param height the height of the thumbnail, in pixels
Wu-cheng Lic157e0c2010-10-07 18:36:07 +08001639 * @see #setPreviewSize(int,int)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001640 */
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001641 public void setJpegThumbnailSize(int width, int height) {
1642 set(KEY_JPEG_THUMBNAIL_WIDTH, width);
1643 set(KEY_JPEG_THUMBNAIL_HEIGHT, height);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001644 }
1645
1646 /**
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001647 * Returns the dimensions for EXIF thumbnail in Jpeg picture.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001648 *
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001649 * @return a Size object with the height and width setting for the EXIF
1650 * thumbnails
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001651 */
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001652 public Size getJpegThumbnailSize() {
1653 return new Size(getInt(KEY_JPEG_THUMBNAIL_WIDTH),
1654 getInt(KEY_JPEG_THUMBNAIL_HEIGHT));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001655 }
1656
1657 /**
Wu-cheng Li4c4300c2010-01-23 15:45:39 +08001658 * Gets the supported jpeg thumbnail sizes.
1659 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08001660 * @return a list of Size object. This method will always return a list
Wu-cheng Li4c4300c2010-01-23 15:45:39 +08001661 * with at least two elements. Size 0,0 (no thumbnail) is always
1662 * supported.
1663 */
1664 public List<Size> getSupportedJpegThumbnailSizes() {
1665 String str = get(KEY_JPEG_THUMBNAIL_SIZE + SUPPORTED_VALUES_SUFFIX);
1666 return splitSize(str);
1667 }
1668
1669 /**
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001670 * Sets the quality of the EXIF thumbnail in Jpeg picture.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001671 *
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001672 * @param quality the JPEG quality of the EXIF thumbnail. The range is 1
1673 * to 100, with 100 being the best.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001674 */
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001675 public void setJpegThumbnailQuality(int quality) {
1676 set(KEY_JPEG_THUMBNAIL_QUALITY, quality);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001677 }
1678
1679 /**
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001680 * Returns the quality setting for the EXIF thumbnail in Jpeg picture.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001681 *
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001682 * @return the JPEG quality setting of the EXIF thumbnail.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001683 */
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001684 public int getJpegThumbnailQuality() {
1685 return getInt(KEY_JPEG_THUMBNAIL_QUALITY);
1686 }
1687
1688 /**
1689 * Sets Jpeg quality of captured picture.
1690 *
1691 * @param quality the JPEG quality of captured picture. The range is 1
1692 * to 100, with 100 being the best.
1693 */
1694 public void setJpegQuality(int quality) {
1695 set(KEY_JPEG_QUALITY, quality);
1696 }
1697
1698 /**
1699 * Returns the quality setting for the JPEG picture.
1700 *
1701 * @return the JPEG picture quality setting.
1702 */
1703 public int getJpegQuality() {
1704 return getInt(KEY_JPEG_QUALITY);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001705 }
1706
1707 /**
Wu-cheng Lia18e9012010-02-10 13:05:29 +08001708 * Sets the rate at which preview frames are received. This is the
1709 * target frame rate. The actual frame rate depends on the driver.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001710 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001711 * @param fps the frame rate (frames per second)
Wu-cheng Li5f1e69c2010-08-18 11:39:12 -07001712 * @deprecated replaced by {@link #setPreviewFpsRange(int,int)}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001713 */
Wu-cheng Li5f1e69c2010-08-18 11:39:12 -07001714 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001715 public void setPreviewFrameRate(int fps) {
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001716 set(KEY_PREVIEW_FRAME_RATE, fps);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001717 }
1718
1719 /**
Wu-cheng Lia18e9012010-02-10 13:05:29 +08001720 * Returns the setting for the rate at which preview frames are
1721 * received. This is the target frame rate. The actual frame rate
1722 * depends on the driver.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001723 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001724 * @return the frame rate setting (frames per second)
Wu-cheng Li5f1e69c2010-08-18 11:39:12 -07001725 * @deprecated replaced by {@link #getPreviewFpsRange(int[])}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001726 */
Wu-cheng Li5f1e69c2010-08-18 11:39:12 -07001727 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001728 public int getPreviewFrameRate() {
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001729 return getInt(KEY_PREVIEW_FRAME_RATE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001730 }
1731
1732 /**
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001733 * Gets the supported preview frame rates.
1734 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08001735 * @return a list of supported preview frame rates. null if preview
1736 * frame rate setting is not supported.
Wu-cheng Li5f1e69c2010-08-18 11:39:12 -07001737 * @deprecated replaced by {@link #getSupportedPreviewFpsRange()}
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001738 */
Wu-cheng Li5f1e69c2010-08-18 11:39:12 -07001739 @Deprecated
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001740 public List<Integer> getSupportedPreviewFrameRates() {
1741 String str = get(KEY_PREVIEW_FRAME_RATE + SUPPORTED_VALUES_SUFFIX);
1742 return splitInt(str);
1743 }
1744
1745 /**
Wu-cheng Li454630f2010-08-11 16:48:05 -07001746 * Sets the maximum and maximum preview fps. This controls the rate of
Wu-cheng Li1620d112010-08-27 15:09:20 -07001747 * preview frames received in {@link PreviewCallback}. The minimum and
Wu-cheng Li454630f2010-08-11 16:48:05 -07001748 * maximum preview fps must be one of the elements from {@link
1749 * #getSupportedPreviewFpsRange}.
1750 *
1751 * @param min the minimum preview fps (scaled by 1000).
1752 * @param max the maximum preview fps (scaled by 1000).
1753 * @throws RuntimeException if fps range is invalid.
1754 * @see #setPreviewCallbackWithBuffer(Camera.PreviewCallback)
1755 * @see #getSupportedPreviewFpsRange()
Wu-cheng Li454630f2010-08-11 16:48:05 -07001756 */
1757 public void setPreviewFpsRange(int min, int max) {
1758 set(KEY_PREVIEW_FPS_RANGE, "" + min + "," + max);
1759 }
1760
1761 /**
1762 * Returns the current minimum and maximum preview fps. The values are
1763 * one of the elements returned by {@link #getSupportedPreviewFpsRange}.
1764 *
1765 * @return range the minimum and maximum preview fps (scaled by 1000).
1766 * @see #PREVIEW_FPS_MIN_INDEX
1767 * @see #PREVIEW_FPS_MAX_INDEX
1768 * @see #getSupportedPreviewFpsRange()
Wu-cheng Li454630f2010-08-11 16:48:05 -07001769 */
1770 public void getPreviewFpsRange(int[] range) {
1771 if (range == null || range.length != 2) {
1772 throw new IllegalArgumentException(
Wu-cheng Li5f1e69c2010-08-18 11:39:12 -07001773 "range must be an array with two elements.");
Wu-cheng Li454630f2010-08-11 16:48:05 -07001774 }
1775 splitInt(get(KEY_PREVIEW_FPS_RANGE), range);
1776 }
1777
1778 /**
1779 * Gets the supported preview fps (frame-per-second) ranges. Each range
1780 * contains a minimum fps and maximum fps. If minimum fps equals to
1781 * maximum fps, the camera outputs frames in fixed frame rate. If not,
1782 * the camera outputs frames in auto frame rate. The actual frame rate
1783 * fluctuates between the minimum and the maximum. The values are
1784 * multiplied by 1000 and represented in integers. For example, if frame
1785 * rate is 26.623 frames per second, the value is 26623.
1786 *
1787 * @return a list of supported preview fps ranges. This method returns a
1788 * list with at least one element. Every element is an int array
1789 * of two values - minimum fps and maximum fps. The list is
1790 * sorted from small to large (first by maximum fps and then
1791 * minimum fps).
1792 * @see #PREVIEW_FPS_MIN_INDEX
1793 * @see #PREVIEW_FPS_MAX_INDEX
Wu-cheng Li454630f2010-08-11 16:48:05 -07001794 */
1795 public List<int[]> getSupportedPreviewFpsRange() {
1796 String str = get(KEY_PREVIEW_FPS_RANGE + SUPPORTED_VALUES_SUFFIX);
1797 return splitRange(str);
1798 }
1799
1800 /**
Wu-cheng Li7478ea62009-09-16 18:52:55 +08001801 * Sets the image format for preview pictures.
Scott Mainda0a56d2009-09-10 18:08:37 -07001802 * <p>If this is never called, the default format will be
Mathias Agopiana696f5d2010-02-17 17:53:09 -08001803 * {@link android.graphics.ImageFormat#NV21}, which
Scott Maindf4578e2009-09-10 12:22:07 -07001804 * uses the NV21 encoding format.</p>
Wu-cheng Li7478ea62009-09-16 18:52:55 +08001805 *
Scott Maindf4578e2009-09-10 12:22:07 -07001806 * @param pixel_format the desired preview picture format, defined
Mathias Agopiana696f5d2010-02-17 17:53:09 -08001807 * by one of the {@link android.graphics.ImageFormat} constants.
1808 * (E.g., <var>ImageFormat.NV21</var> (default),
1809 * <var>ImageFormat.RGB_565</var>, or
1810 * <var>ImageFormat.JPEG</var>)
1811 * @see android.graphics.ImageFormat
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001812 */
1813 public void setPreviewFormat(int pixel_format) {
1814 String s = cameraFormatForPixelFormat(pixel_format);
1815 if (s == null) {
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001816 throw new IllegalArgumentException(
1817 "Invalid pixel_format=" + pixel_format);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001818 }
1819
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001820 set(KEY_PREVIEW_FORMAT, s);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001821 }
1822
1823 /**
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08001824 * Returns the image format for preview frames got from
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001825 * {@link PreviewCallback}.
Wu-cheng Li7478ea62009-09-16 18:52:55 +08001826 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08001827 * @return the preview format.
1828 * @see android.graphics.ImageFormat
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001829 */
1830 public int getPreviewFormat() {
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001831 return pixelFormatForCameraFormat(get(KEY_PREVIEW_FORMAT));
1832 }
1833
1834 /**
Wu-cheng Lif9293e72011-02-25 13:35:10 +08001835 * Gets the supported preview formats. {@link android.graphics.ImageFormat#NV21}
1836 * is always supported. {@link android.graphics.ImageFormat#YV12}
1837 * is always supported since API level 12.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001838 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08001839 * @return a list of supported preview formats. This method will always
1840 * return a list with at least one element.
1841 * @see android.graphics.ImageFormat
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001842 */
1843 public List<Integer> getSupportedPreviewFormats() {
1844 String str = get(KEY_PREVIEW_FORMAT + SUPPORTED_VALUES_SUFFIX);
Chih-Chung Changeb68c462009-09-18 18:37:44 +08001845 ArrayList<Integer> formats = new ArrayList<Integer>();
1846 for (String s : split(str)) {
1847 int f = pixelFormatForCameraFormat(s);
Mathias Agopiana696f5d2010-02-17 17:53:09 -08001848 if (f == ImageFormat.UNKNOWN) continue;
Chih-Chung Changeb68c462009-09-18 18:37:44 +08001849 formats.add(f);
1850 }
1851 return formats;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001852 }
1853
1854 /**
1855 * Sets the dimensions for pictures.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001856 *
Wu-cheng Lic157e0c2010-10-07 18:36:07 +08001857 * Applications need to consider the display orientation. See {@link
1858 * #setPreviewSize(int,int)} for reference.
1859 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001860 * @param width the width for pictures, in pixels
1861 * @param height the height for pictures, in pixels
Wu-cheng Lic157e0c2010-10-07 18:36:07 +08001862 * @see #setPreviewSize(int,int)
1863 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001864 */
1865 public void setPictureSize(int width, int height) {
1866 String v = Integer.toString(width) + "x" + Integer.toString(height);
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001867 set(KEY_PICTURE_SIZE, v);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001868 }
1869
1870 /**
1871 * Returns the dimension setting for pictures.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001872 *
1873 * @return a Size object with the height and width setting
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001874 * for pictures
1875 */
1876 public Size getPictureSize() {
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001877 String pair = get(KEY_PICTURE_SIZE);
1878 return strToSize(pair);
1879 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001880
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001881 /**
1882 * Gets the supported picture sizes.
1883 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08001884 * @return a list of supported picture sizes. This method will always
1885 * return a list with at least one element.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001886 */
1887 public List<Size> getSupportedPictureSizes() {
1888 String str = get(KEY_PICTURE_SIZE + SUPPORTED_VALUES_SUFFIX);
1889 return splitSize(str);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001890 }
1891
1892 /**
1893 * Sets the image format for pictures.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001894 *
1895 * @param pixel_format the desired picture format
Mathias Agopiana696f5d2010-02-17 17:53:09 -08001896 * (<var>ImageFormat.NV21</var>,
1897 * <var>ImageFormat.RGB_565</var>, or
1898 * <var>ImageFormat.JPEG</var>)
1899 * @see android.graphics.ImageFormat
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001900 */
1901 public void setPictureFormat(int pixel_format) {
1902 String s = cameraFormatForPixelFormat(pixel_format);
1903 if (s == null) {
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001904 throw new IllegalArgumentException(
1905 "Invalid pixel_format=" + pixel_format);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001906 }
1907
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001908 set(KEY_PICTURE_FORMAT, s);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001909 }
1910
1911 /**
1912 * Returns the image format for pictures.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001913 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08001914 * @return the picture format
1915 * @see android.graphics.ImageFormat
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001916 */
1917 public int getPictureFormat() {
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001918 return pixelFormatForCameraFormat(get(KEY_PICTURE_FORMAT));
1919 }
1920
1921 /**
1922 * Gets the supported picture formats.
1923 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08001924 * @return supported picture formats. This method will always return a
1925 * list with at least one element.
1926 * @see android.graphics.ImageFormat
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001927 */
1928 public List<Integer> getSupportedPictureFormats() {
Wu-cheng Li9c799382009-12-04 19:59:18 +08001929 String str = get(KEY_PICTURE_FORMAT + SUPPORTED_VALUES_SUFFIX);
1930 ArrayList<Integer> formats = new ArrayList<Integer>();
1931 for (String s : split(str)) {
1932 int f = pixelFormatForCameraFormat(s);
Mathias Agopiana696f5d2010-02-17 17:53:09 -08001933 if (f == ImageFormat.UNKNOWN) continue;
Wu-cheng Li9c799382009-12-04 19:59:18 +08001934 formats.add(f);
1935 }
1936 return formats;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001937 }
1938
1939 private String cameraFormatForPixelFormat(int pixel_format) {
1940 switch(pixel_format) {
Mathias Agopiana696f5d2010-02-17 17:53:09 -08001941 case ImageFormat.NV16: return PIXEL_FORMAT_YUV422SP;
1942 case ImageFormat.NV21: return PIXEL_FORMAT_YUV420SP;
1943 case ImageFormat.YUY2: return PIXEL_FORMAT_YUV422I;
Wu-cheng Li10a1b302011-02-22 15:49:25 +08001944 case ImageFormat.YV12: return PIXEL_FORMAT_YUV420P;
Mathias Agopiana696f5d2010-02-17 17:53:09 -08001945 case ImageFormat.RGB_565: return PIXEL_FORMAT_RGB565;
1946 case ImageFormat.JPEG: return PIXEL_FORMAT_JPEG;
1947 default: return null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001948 }
1949 }
1950
1951 private int pixelFormatForCameraFormat(String format) {
1952 if (format == null)
Mathias Agopiana696f5d2010-02-17 17:53:09 -08001953 return ImageFormat.UNKNOWN;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001954
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001955 if (format.equals(PIXEL_FORMAT_YUV422SP))
Mathias Agopiana696f5d2010-02-17 17:53:09 -08001956 return ImageFormat.NV16;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001957
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001958 if (format.equals(PIXEL_FORMAT_YUV420SP))
Mathias Agopiana696f5d2010-02-17 17:53:09 -08001959 return ImageFormat.NV21;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001960
Chih-Chung Changeb68c462009-09-18 18:37:44 +08001961 if (format.equals(PIXEL_FORMAT_YUV422I))
Mathias Agopiana696f5d2010-02-17 17:53:09 -08001962 return ImageFormat.YUY2;
Chih-Chung Changeb68c462009-09-18 18:37:44 +08001963
Wu-cheng Li10a1b302011-02-22 15:49:25 +08001964 if (format.equals(PIXEL_FORMAT_YUV420P))
1965 return ImageFormat.YV12;
1966
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001967 if (format.equals(PIXEL_FORMAT_RGB565))
Mathias Agopiana696f5d2010-02-17 17:53:09 -08001968 return ImageFormat.RGB_565;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001969
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001970 if (format.equals(PIXEL_FORMAT_JPEG))
Mathias Agopiana696f5d2010-02-17 17:53:09 -08001971 return ImageFormat.JPEG;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001972
Mathias Agopiana696f5d2010-02-17 17:53:09 -08001973 return ImageFormat.UNKNOWN;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001974 }
1975
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001976 /**
Wu-cheng Li2fb818c2010-09-13 20:02:01 -07001977 * Sets the rotation angle in degrees relative to the orientation of
1978 * the camera. This affects the pictures returned from JPEG {@link
1979 * PictureCallback}. The camera driver may set orientation in the
1980 * EXIF header without rotating the picture. Or the driver may rotate
1981 * the picture and the EXIF thumbnail. If the Jpeg picture is rotated,
1982 * the orientation in the EXIF header will be missing or 1 (row #0 is
1983 * top and column #0 is left side).
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001984 *
Brad Fitzpatrick69ea4e12011-01-05 11:13:40 -08001985 * <p>If applications want to rotate the picture to match the orientation
Wu-cheng Li2fe6fca2010-10-15 14:42:23 +08001986 * of what users see, apps should use {@link
Wu-cheng Li2fb818c2010-09-13 20:02:01 -07001987 * android.view.OrientationEventListener} and {@link CameraInfo}.
1988 * The value from OrientationEventListener is relative to the natural
Wu-cheng Li2fe6fca2010-10-15 14:42:23 +08001989 * orientation of the device. CameraInfo.orientation is the angle
Brad Fitzpatrick69ea4e12011-01-05 11:13:40 -08001990 * between camera orientation and natural device orientation. The sum
Wu-cheng Li2fe6fca2010-10-15 14:42:23 +08001991 * of the two is the rotation angle for back-facing camera. The
1992 * difference of the two is the rotation angle for front-facing camera.
1993 * Note that the JPEG pictures of front-facing cameras are not mirrored
1994 * as in preview display.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001995 *
Brad Fitzpatrick69ea4e12011-01-05 11:13:40 -08001996 * <p>For example, suppose the natural orientation of the device is
Wu-cheng Li2fb818c2010-09-13 20:02:01 -07001997 * portrait. The device is rotated 270 degrees clockwise, so the device
Wu-cheng Li2fe6fca2010-10-15 14:42:23 +08001998 * orientation is 270. Suppose a back-facing camera sensor is mounted in
1999 * landscape and the top side of the camera sensor is aligned with the
2000 * right edge of the display in natural orientation. So the camera
2001 * orientation is 90. The rotation should be set to 0 (270 + 90).
Wu-cheng Li2fb818c2010-09-13 20:02:01 -07002002 *
Brad Fitzpatrick69ea4e12011-01-05 11:13:40 -08002003 * <p>The reference code is as follows.
Wu-cheng Li2fb818c2010-09-13 20:02:01 -07002004 *
Brad Fitzpatrick69ea4e12011-01-05 11:13:40 -08002005 * <pre>
Wu-cheng Li2fb818c2010-09-13 20:02:01 -07002006 * public void public void onOrientationChanged(int orientation) {
2007 * if (orientation == ORIENTATION_UNKNOWN) return;
2008 * android.hardware.Camera.CameraInfo info =
2009 * new android.hardware.Camera.CameraInfo();
2010 * android.hardware.Camera.getCameraInfo(cameraId, info);
2011 * orientation = (orientation + 45) / 90 * 90;
Wu-cheng Li2fe6fca2010-10-15 14:42:23 +08002012 * int rotation = 0;
2013 * if (info.facing == CameraInfo.CAMERA_FACING_FRONT) {
2014 * rotation = (info.orientation - orientation + 360) % 360;
2015 * } else { // back-facing camera
2016 * rotation = (info.orientation + orientation) % 360;
2017 * }
2018 * mParameters.setRotation(rotation);
Wu-cheng Li2fb818c2010-09-13 20:02:01 -07002019 * }
Brad Fitzpatrick69ea4e12011-01-05 11:13:40 -08002020 * </pre>
Wu-cheng Li2fb818c2010-09-13 20:02:01 -07002021 *
2022 * @param rotation The rotation angle in degrees relative to the
2023 * orientation of the camera. Rotation can only be 0,
2024 * 90, 180 or 270.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002025 * @throws IllegalArgumentException if rotation value is invalid.
2026 * @see android.view.OrientationEventListener
Wu-cheng Li2fb818c2010-09-13 20:02:01 -07002027 * @see #getCameraInfo(int, CameraInfo)
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002028 */
2029 public void setRotation(int rotation) {
2030 if (rotation == 0 || rotation == 90 || rotation == 180
2031 || rotation == 270) {
2032 set(KEY_ROTATION, Integer.toString(rotation));
2033 } else {
2034 throw new IllegalArgumentException(
2035 "Invalid rotation=" + rotation);
2036 }
2037 }
2038
2039 /**
2040 * Sets GPS latitude coordinate. This will be stored in JPEG EXIF
2041 * header.
2042 *
2043 * @param latitude GPS latitude coordinate.
2044 */
2045 public void setGpsLatitude(double latitude) {
2046 set(KEY_GPS_LATITUDE, Double.toString(latitude));
2047 }
2048
2049 /**
2050 * Sets GPS longitude coordinate. This will be stored in JPEG EXIF
2051 * header.
2052 *
2053 * @param longitude GPS longitude coordinate.
2054 */
2055 public void setGpsLongitude(double longitude) {
2056 set(KEY_GPS_LONGITUDE, Double.toString(longitude));
2057 }
2058
2059 /**
2060 * Sets GPS altitude. This will be stored in JPEG EXIF header.
2061 *
2062 * @param altitude GPS altitude in meters.
2063 */
2064 public void setGpsAltitude(double altitude) {
2065 set(KEY_GPS_ALTITUDE, Double.toString(altitude));
2066 }
2067
2068 /**
2069 * Sets GPS timestamp. This will be stored in JPEG EXIF header.
2070 *
2071 * @param timestamp GPS timestamp (UTC in seconds since January 1,
2072 * 1970).
2073 */
2074 public void setGpsTimestamp(long timestamp) {
2075 set(KEY_GPS_TIMESTAMP, Long.toString(timestamp));
2076 }
2077
2078 /**
Ray Chene2083772010-03-10 15:02:49 -08002079 * Sets GPS processing method. It will store up to 32 characters
Ray Chen055c9862010-02-23 10:45:42 +08002080 * in JPEG EXIF header.
2081 *
2082 * @param processing_method The processing method to get this location.
2083 */
2084 public void setGpsProcessingMethod(String processing_method) {
2085 set(KEY_GPS_PROCESSING_METHOD, processing_method);
2086 }
2087
2088 /**
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002089 * Removes GPS latitude, longitude, altitude, and timestamp from the
2090 * parameters.
2091 */
2092 public void removeGpsData() {
2093 remove(KEY_GPS_LATITUDE);
2094 remove(KEY_GPS_LONGITUDE);
2095 remove(KEY_GPS_ALTITUDE);
2096 remove(KEY_GPS_TIMESTAMP);
Ray Chen055c9862010-02-23 10:45:42 +08002097 remove(KEY_GPS_PROCESSING_METHOD);
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002098 }
2099
2100 /**
2101 * Gets the current white balance setting.
2102 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08002103 * @return current white balance. null if white balance setting is not
2104 * supported.
2105 * @see #WHITE_BALANCE_AUTO
2106 * @see #WHITE_BALANCE_INCANDESCENT
2107 * @see #WHITE_BALANCE_FLUORESCENT
2108 * @see #WHITE_BALANCE_WARM_FLUORESCENT
2109 * @see #WHITE_BALANCE_DAYLIGHT
2110 * @see #WHITE_BALANCE_CLOUDY_DAYLIGHT
2111 * @see #WHITE_BALANCE_TWILIGHT
2112 * @see #WHITE_BALANCE_SHADE
2113 *
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002114 */
2115 public String getWhiteBalance() {
2116 return get(KEY_WHITE_BALANCE);
2117 }
2118
2119 /**
2120 * Sets the white balance.
2121 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08002122 * @param value new white balance.
2123 * @see #getWhiteBalance()
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002124 */
2125 public void setWhiteBalance(String value) {
2126 set(KEY_WHITE_BALANCE, value);
2127 }
2128
2129 /**
2130 * Gets the supported white balance.
2131 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08002132 * @return a list of supported white balance. null if white balance
2133 * setting is not supported.
2134 * @see #getWhiteBalance()
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002135 */
2136 public List<String> getSupportedWhiteBalance() {
2137 String str = get(KEY_WHITE_BALANCE + SUPPORTED_VALUES_SUFFIX);
2138 return split(str);
2139 }
2140
2141 /**
2142 * Gets the current color effect setting.
2143 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08002144 * @return current color effect. null if color effect
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002145 * setting is not supported.
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08002146 * @see #EFFECT_NONE
2147 * @see #EFFECT_MONO
2148 * @see #EFFECT_NEGATIVE
2149 * @see #EFFECT_SOLARIZE
2150 * @see #EFFECT_SEPIA
2151 * @see #EFFECT_POSTERIZE
2152 * @see #EFFECT_WHITEBOARD
2153 * @see #EFFECT_BLACKBOARD
2154 * @see #EFFECT_AQUA
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002155 */
2156 public String getColorEffect() {
2157 return get(KEY_EFFECT);
2158 }
2159
2160 /**
2161 * Sets the current color effect setting.
2162 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08002163 * @param value new color effect.
2164 * @see #getColorEffect()
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002165 */
2166 public void setColorEffect(String value) {
2167 set(KEY_EFFECT, value);
2168 }
2169
2170 /**
2171 * Gets the supported color effects.
2172 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08002173 * @return a list of supported color effects. null if color effect
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002174 * setting is not supported.
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08002175 * @see #getColorEffect()
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002176 */
2177 public List<String> getSupportedColorEffects() {
2178 String str = get(KEY_EFFECT + SUPPORTED_VALUES_SUFFIX);
2179 return split(str);
2180 }
2181
2182
2183 /**
2184 * Gets the current antibanding setting.
2185 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08002186 * @return current antibanding. null if antibanding setting is not
2187 * supported.
2188 * @see #ANTIBANDING_AUTO
2189 * @see #ANTIBANDING_50HZ
2190 * @see #ANTIBANDING_60HZ
2191 * @see #ANTIBANDING_OFF
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002192 */
2193 public String getAntibanding() {
2194 return get(KEY_ANTIBANDING);
2195 }
2196
2197 /**
2198 * Sets the antibanding.
2199 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08002200 * @param antibanding new antibanding value.
2201 * @see #getAntibanding()
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002202 */
2203 public void setAntibanding(String antibanding) {
2204 set(KEY_ANTIBANDING, antibanding);
2205 }
2206
2207 /**
2208 * Gets the supported antibanding values.
2209 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08002210 * @return a list of supported antibanding values. null if antibanding
2211 * setting is not supported.
2212 * @see #getAntibanding()
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002213 */
2214 public List<String> getSupportedAntibanding() {
2215 String str = get(KEY_ANTIBANDING + SUPPORTED_VALUES_SUFFIX);
2216 return split(str);
2217 }
2218
2219 /**
2220 * Gets the current scene mode setting.
2221 *
2222 * @return one of SCENE_MODE_XXX string constant. null if scene mode
2223 * setting is not supported.
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08002224 * @see #SCENE_MODE_AUTO
2225 * @see #SCENE_MODE_ACTION
2226 * @see #SCENE_MODE_PORTRAIT
2227 * @see #SCENE_MODE_LANDSCAPE
2228 * @see #SCENE_MODE_NIGHT
2229 * @see #SCENE_MODE_NIGHT_PORTRAIT
2230 * @see #SCENE_MODE_THEATRE
2231 * @see #SCENE_MODE_BEACH
2232 * @see #SCENE_MODE_SNOW
2233 * @see #SCENE_MODE_SUNSET
2234 * @see #SCENE_MODE_STEADYPHOTO
2235 * @see #SCENE_MODE_FIREWORKS
2236 * @see #SCENE_MODE_SPORTS
2237 * @see #SCENE_MODE_PARTY
2238 * @see #SCENE_MODE_CANDLELIGHT
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002239 */
2240 public String getSceneMode() {
2241 return get(KEY_SCENE_MODE);
2242 }
2243
2244 /**
Wu-cheng Lic58b4232010-03-29 17:21:28 +08002245 * Sets the scene mode. Changing scene mode may override other
2246 * parameters (such as flash mode, focus mode, white balance). For
2247 * example, suppose originally flash mode is on and supported flash
2248 * modes are on/off. In night scene mode, both flash mode and supported
2249 * flash mode may be changed to off. After setting scene mode,
Wu-cheng Li2988ab72009-09-30 17:08:19 -07002250 * applications should call getParameters to know if some parameters are
2251 * changed.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002252 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08002253 * @param value scene mode.
2254 * @see #getSceneMode()
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002255 */
2256 public void setSceneMode(String value) {
2257 set(KEY_SCENE_MODE, value);
2258 }
2259
2260 /**
2261 * Gets the supported scene modes.
2262 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08002263 * @return a list of supported scene modes. null if scene mode setting
2264 * is not supported.
2265 * @see #getSceneMode()
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002266 */
2267 public List<String> getSupportedSceneModes() {
2268 String str = get(KEY_SCENE_MODE + SUPPORTED_VALUES_SUFFIX);
2269 return split(str);
2270 }
2271
2272 /**
2273 * Gets the current flash mode setting.
2274 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08002275 * @return current flash mode. null if flash mode setting is not
2276 * supported.
2277 * @see #FLASH_MODE_OFF
2278 * @see #FLASH_MODE_AUTO
2279 * @see #FLASH_MODE_ON
2280 * @see #FLASH_MODE_RED_EYE
2281 * @see #FLASH_MODE_TORCH
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002282 */
2283 public String getFlashMode() {
2284 return get(KEY_FLASH_MODE);
2285 }
2286
2287 /**
2288 * Sets the flash mode.
2289 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08002290 * @param value flash mode.
2291 * @see #getFlashMode()
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002292 */
2293 public void setFlashMode(String value) {
2294 set(KEY_FLASH_MODE, value);
2295 }
2296
2297 /**
2298 * Gets the supported flash modes.
2299 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08002300 * @return a list of supported flash modes. null if flash mode setting
2301 * is not supported.
2302 * @see #getFlashMode()
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002303 */
2304 public List<String> getSupportedFlashModes() {
2305 String str = get(KEY_FLASH_MODE + SUPPORTED_VALUES_SUFFIX);
2306 return split(str);
2307 }
2308
Wu-cheng Li36322db2009-09-18 18:59:21 +08002309 /**
2310 * Gets the current focus mode setting.
2311 *
Wu-cheng Li699fe932010-08-05 11:50:25 -07002312 * @return current focus mode. This method will always return a non-null
2313 * value. Applications should call {@link
2314 * #autoFocus(AutoFocusCallback)} to start the focus if focus
2315 * mode is FOCUS_MODE_AUTO or FOCUS_MODE_MACRO.
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08002316 * @see #FOCUS_MODE_AUTO
2317 * @see #FOCUS_MODE_INFINITY
2318 * @see #FOCUS_MODE_MACRO
2319 * @see #FOCUS_MODE_FIXED
Wu-cheng Lif008f3e2010-08-17 13:44:35 -07002320 * @see #FOCUS_MODE_EDOF
Wu-cheng Lid45cb722010-09-20 16:15:32 -07002321 * @see #FOCUS_MODE_CONTINUOUS_VIDEO
Wu-cheng Li36322db2009-09-18 18:59:21 +08002322 */
2323 public String getFocusMode() {
2324 return get(KEY_FOCUS_MODE);
2325 }
2326
2327 /**
2328 * Sets the focus mode.
2329 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08002330 * @param value focus mode.
2331 * @see #getFocusMode()
Wu-cheng Li36322db2009-09-18 18:59:21 +08002332 */
2333 public void setFocusMode(String value) {
2334 set(KEY_FOCUS_MODE, value);
2335 }
2336
2337 /**
2338 * Gets the supported focus modes.
2339 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08002340 * @return a list of supported focus modes. This method will always
2341 * return a list with at least one element.
2342 * @see #getFocusMode()
Wu-cheng Li36322db2009-09-18 18:59:21 +08002343 */
2344 public List<String> getSupportedFocusModes() {
2345 String str = get(KEY_FOCUS_MODE + SUPPORTED_VALUES_SUFFIX);
2346 return split(str);
2347 }
2348
Wu-cheng Li36f68b82009-09-28 16:14:58 -07002349 /**
Wu-cheng Li6c8d2762010-01-27 22:55:14 +08002350 * Gets the focal length (in millimeter) of the camera.
2351 *
2352 * @return the focal length. This method will always return a valid
2353 * value.
2354 */
2355 public float getFocalLength() {
2356 return Float.parseFloat(get(KEY_FOCAL_LENGTH));
2357 }
2358
2359 /**
2360 * Gets the horizontal angle of view in degrees.
2361 *
2362 * @return horizontal angle of view. This method will always return a
2363 * valid value.
2364 */
2365 public float getHorizontalViewAngle() {
2366 return Float.parseFloat(get(KEY_HORIZONTAL_VIEW_ANGLE));
2367 }
2368
2369 /**
2370 * Gets the vertical angle of view in degrees.
2371 *
2372 * @return vertical angle of view. This method will always return a
2373 * valid value.
2374 */
2375 public float getVerticalViewAngle() {
2376 return Float.parseFloat(get(KEY_VERTICAL_VIEW_ANGLE));
2377 }
2378
2379 /**
Wu-cheng Li24b326a2010-02-20 17:47:04 +08002380 * Gets the current exposure compensation index.
Wu-cheng Liff723b62010-02-09 13:38:19 +08002381 *
Wu-cheng Li24b326a2010-02-20 17:47:04 +08002382 * @return current exposure compensation index. The range is {@link
2383 * #getMinExposureCompensation} to {@link
2384 * #getMaxExposureCompensation}. 0 means exposure is not
2385 * adjusted.
Wu-cheng Liff723b62010-02-09 13:38:19 +08002386 */
2387 public int getExposureCompensation() {
Wu-cheng Li24b326a2010-02-20 17:47:04 +08002388 return getInt(KEY_EXPOSURE_COMPENSATION, 0);
Wu-cheng Liff723b62010-02-09 13:38:19 +08002389 }
2390
2391 /**
Wu-cheng Li24b326a2010-02-20 17:47:04 +08002392 * Sets the exposure compensation index.
Wu-cheng Liff723b62010-02-09 13:38:19 +08002393 *
Wu-cheng Li0402e7d2010-02-26 15:04:55 +08002394 * @param value exposure compensation index. The valid value range is
2395 * from {@link #getMinExposureCompensation} (inclusive) to {@link
Wu-cheng Li24b326a2010-02-20 17:47:04 +08002396 * #getMaxExposureCompensation} (inclusive). 0 means exposure is
2397 * not adjusted. Application should call
2398 * getMinExposureCompensation and getMaxExposureCompensation to
2399 * know if exposure compensation is supported.
Wu-cheng Liff723b62010-02-09 13:38:19 +08002400 */
2401 public void setExposureCompensation(int value) {
2402 set(KEY_EXPOSURE_COMPENSATION, value);
2403 }
2404
2405 /**
Wu-cheng Li24b326a2010-02-20 17:47:04 +08002406 * Gets the maximum exposure compensation index.
Wu-cheng Liff723b62010-02-09 13:38:19 +08002407 *
Wu-cheng Li24b326a2010-02-20 17:47:04 +08002408 * @return maximum exposure compensation index (>=0). If both this
2409 * method and {@link #getMinExposureCompensation} return 0,
2410 * exposure compensation is not supported.
Wu-cheng Liff723b62010-02-09 13:38:19 +08002411 */
Wu-cheng Li24b326a2010-02-20 17:47:04 +08002412 public int getMaxExposureCompensation() {
2413 return getInt(KEY_MAX_EXPOSURE_COMPENSATION, 0);
2414 }
2415
2416 /**
2417 * Gets the minimum exposure compensation index.
2418 *
2419 * @return minimum exposure compensation index (<=0). If both this
2420 * method and {@link #getMaxExposureCompensation} return 0,
2421 * exposure compensation is not supported.
2422 */
2423 public int getMinExposureCompensation() {
2424 return getInt(KEY_MIN_EXPOSURE_COMPENSATION, 0);
2425 }
2426
2427 /**
2428 * Gets the exposure compensation step.
2429 *
2430 * @return exposure compensation step. Applications can get EV by
2431 * multiplying the exposure compensation index and step. Ex: if
2432 * exposure compensation index is -6 and step is 0.333333333, EV
2433 * is -2.
2434 */
2435 public float getExposureCompensationStep() {
2436 return getFloat(KEY_EXPOSURE_COMPENSATION_STEP, 0);
Wu-cheng Liff723b62010-02-09 13:38:19 +08002437 }
2438
2439 /**
Wu-cheng Li36f68b82009-09-28 16:14:58 -07002440 * Gets current zoom value. This also works when smooth zoom is in
Wu-cheng Li8cbb8f52010-02-28 23:19:55 -08002441 * progress. Applications should check {@link #isZoomSupported} before
2442 * using this method.
Wu-cheng Li36f68b82009-09-28 16:14:58 -07002443 *
2444 * @return the current zoom value. The range is 0 to {@link
Wu-cheng Li8cbb8f52010-02-28 23:19:55 -08002445 * #getMaxZoom}. 0 means the camera is not zoomed.
Wu-cheng Li36f68b82009-09-28 16:14:58 -07002446 */
2447 public int getZoom() {
Wu-cheng Li8cbb8f52010-02-28 23:19:55 -08002448 return getInt(KEY_ZOOM, 0);
Wu-cheng Li36f68b82009-09-28 16:14:58 -07002449 }
2450
2451 /**
Wu-cheng Li8cbb8f52010-02-28 23:19:55 -08002452 * Sets current zoom value. If the camera is zoomed (value > 0), the
2453 * actual picture size may be smaller than picture size setting.
2454 * Applications can check the actual picture size after picture is
2455 * returned from {@link PictureCallback}. The preview size remains the
2456 * same in zoom. Applications should check {@link #isZoomSupported}
2457 * before using this method.
Wu-cheng Li36f68b82009-09-28 16:14:58 -07002458 *
2459 * @param value zoom value. The valid range is 0 to {@link #getMaxZoom}.
Wu-cheng Li36f68b82009-09-28 16:14:58 -07002460 */
2461 public void setZoom(int value) {
Wu-cheng Li8cbb8f52010-02-28 23:19:55 -08002462 set(KEY_ZOOM, value);
Wu-cheng Li36f68b82009-09-28 16:14:58 -07002463 }
2464
2465 /**
2466 * Returns true if zoom is supported. Applications should call this
2467 * before using other zoom methods.
2468 *
2469 * @return true if zoom is supported.
Wu-cheng Li36f68b82009-09-28 16:14:58 -07002470 */
2471 public boolean isZoomSupported() {
Wu-cheng Li8cbb8f52010-02-28 23:19:55 -08002472 String str = get(KEY_ZOOM_SUPPORTED);
2473 return TRUE.equals(str);
Wu-cheng Li36f68b82009-09-28 16:14:58 -07002474 }
2475
2476 /**
2477 * Gets the maximum zoom value allowed for snapshot. This is the maximum
2478 * value that applications can set to {@link #setZoom(int)}.
Wu-cheng Li8cbb8f52010-02-28 23:19:55 -08002479 * Applications should call {@link #isZoomSupported} before using this
2480 * method. This value may change in different preview size. Applications
2481 * should call this again after setting preview size.
Wu-cheng Li36f68b82009-09-28 16:14:58 -07002482 *
2483 * @return the maximum zoom value supported by the camera.
Wu-cheng Li36f68b82009-09-28 16:14:58 -07002484 */
2485 public int getMaxZoom() {
Wu-cheng Li8cbb8f52010-02-28 23:19:55 -08002486 return getInt(KEY_MAX_ZOOM, 0);
Wu-cheng Li36f68b82009-09-28 16:14:58 -07002487 }
2488
2489 /**
Wu-cheng Li8cbb8f52010-02-28 23:19:55 -08002490 * Gets the zoom ratios of all zoom values. Applications should check
2491 * {@link #isZoomSupported} before using this method.
Wu-cheng Li36f68b82009-09-28 16:14:58 -07002492 *
Wu-cheng Li8cbb8f52010-02-28 23:19:55 -08002493 * @return the zoom ratios in 1/100 increments. Ex: a zoom of 3.2x is
2494 * returned as 320. The number of elements is {@link
2495 * #getMaxZoom} + 1. The list is sorted from small to large. The
2496 * first element is always 100. The last element is the zoom
2497 * ratio of the maximum zoom value.
Wu-cheng Li36f68b82009-09-28 16:14:58 -07002498 */
Wu-cheng Li8cbb8f52010-02-28 23:19:55 -08002499 public List<Integer> getZoomRatios() {
2500 return splitInt(get(KEY_ZOOM_RATIOS));
Wu-cheng Li36f68b82009-09-28 16:14:58 -07002501 }
2502
2503 /**
2504 * Returns true if smooth zoom is supported. Applications should call
2505 * this before using other smooth zoom methods.
2506 *
2507 * @return true if smooth zoom is supported.
Wu-cheng Li36f68b82009-09-28 16:14:58 -07002508 */
2509 public boolean isSmoothZoomSupported() {
Wu-cheng Li8cbb8f52010-02-28 23:19:55 -08002510 String str = get(KEY_SMOOTH_ZOOM_SUPPORTED);
2511 return TRUE.equals(str);
Wu-cheng Li36f68b82009-09-28 16:14:58 -07002512 }
2513
Wu-cheng Lie339c5e2010-05-13 19:31:02 +08002514 /**
2515 * Gets the distances from the camera to where an object appears to be
2516 * in focus. The object is sharpest at the optimal focus distance. The
2517 * depth of field is the far focus distance minus near focus distance.
2518 *
2519 * Focus distances may change after calling {@link
2520 * #autoFocus(AutoFocusCallback)}, {@link #cancelAutoFocus}, or {@link
2521 * #startPreview()}. Applications can call {@link #getParameters()}
2522 * and this method anytime to get the latest focus distances. If the
Wu-cheng Lid45cb722010-09-20 16:15:32 -07002523 * focus mode is FOCUS_MODE_CONTINUOUS_VIDEO, focus distances may change
2524 * from time to time.
Wu-cheng Li699fe932010-08-05 11:50:25 -07002525 *
2526 * This method is intended to estimate the distance between the camera
2527 * and the subject. After autofocus, the subject distance may be within
2528 * near and far focus distance. However, the precision depends on the
2529 * camera hardware, autofocus algorithm, the focus area, and the scene.
2530 * The error can be large and it should be only used as a reference.
Wu-cheng Lie339c5e2010-05-13 19:31:02 +08002531 *
Wu-cheng Li185cc452010-05-20 15:36:13 +08002532 * Far focus distance >= optimal focus distance >= near focus distance.
2533 * If the focus distance is infinity, the value will be
Wu-cheng Lie339c5e2010-05-13 19:31:02 +08002534 * Float.POSITIVE_INFINITY.
2535 *
2536 * @param output focus distances in meters. output must be a float
2537 * array with three elements. Near focus distance, optimal focus
2538 * distance, and far focus distance will be filled in the array.
Wu-cheng Li185cc452010-05-20 15:36:13 +08002539 * @see #FOCUS_DISTANCE_NEAR_INDEX
2540 * @see #FOCUS_DISTANCE_OPTIMAL_INDEX
2541 * @see #FOCUS_DISTANCE_FAR_INDEX
Wu-cheng Lie339c5e2010-05-13 19:31:02 +08002542 */
2543 public void getFocusDistances(float[] output) {
2544 if (output == null || output.length != 3) {
2545 throw new IllegalArgumentException(
2546 "output must be an float array with three elements.");
2547 }
Wu-cheng Li454630f2010-08-11 16:48:05 -07002548 splitFloat(get(KEY_FOCUS_DISTANCES), output);
Wu-cheng Lie339c5e2010-05-13 19:31:02 +08002549 }
2550
Wu-cheng Li30771b72011-04-02 06:19:46 +08002551 /**
2552 * Gets the maximum number of focus areas supported. This is the maximum
2553 * length of the list in {@link #setFocusArea(List<Area>)} and
2554 * {@link #getFocusArea()}.
2555 *
2556 * @return the maximum number of focus areas supported by the camera.
2557 * @see #getFocusAreas()
2558 * @hide
2559 */
2560 public int getMaxNumFocusAreas() {
2561 return getInt(KEY_MAX_NUM_FOCUS_AREAS, 0);
2562 }
2563
2564 /**
2565 * Gets the current focus areas.
2566 *
2567 * Before using this API or {@link #setFocusAreas(List<int>)}, apps
2568 * should call {@link #getMaxNumFocusArea()} to know the maximum number of
2569 * focus areas first. If the value is 0, focus area is not supported.
2570 *
2571 * Each focus area is a rectangle with specified weight. The direction
2572 * is relative to the sensor orientation, that is, what the sensor sees.
2573 * The direction is not affected by the rotation or mirroring of
2574 * {@link #setDisplayOrientation(int)}. Coordinates of the rectangle
2575 * range from -1000 to 1000. (-1000, -1000) is the upper left point.
2576 * (1000, 1000) is the lower right point. The length and width of focus
2577 * areas cannot be 0 or negative.
2578 *
2579 * The weight ranges from 1 to 1000. The sum of the weights of all focus
2580 * areas must be 1000. Focus areas can partially overlap and the driver
2581 * will add the weights in the overlap region. But apps should not set
2582 * two focus areas that have identical coordinates.
2583 *
2584 * A special case of all-zero single focus area means driver to decide
2585 * the focus area. For example, the driver may use more signals to
2586 * decide focus areas and change them dynamically. Apps can set all-zero
2587 * if they want the driver to decide focus areas.
2588 *
2589 * Focus areas are relative to the current field of view
2590 * ({@link #getZoom()}). No matter what the zoom level is, (-1000,-1000)
2591 * represents the top of the currently visible camera frame. The focus
2592 * area cannot be set to be outside the current field of view, even
2593 * when using zoom.
2594 *
2595 * Focus area only has effect if the current focus mode is
2596 * {@link #FOCUS_MODE_AUTO}, {@link #FOCUS_MODE_MACRO}, or
2597 * {@link #FOCUS_MODE_CONTINOUS_VIDEO}.
2598 *
2599 * @return a list of current focus areas
2600 * @hide
2601 */
2602 public List<Area> getFocusAreas() {
2603 return splitArea(KEY_FOCUS_AREAS);
2604 }
2605
2606 /**
2607 * Sets focus areas. See {@link #getFocusAreas()} for documentation.
2608 *
2609 * @param focusArea the focus areas
2610 * @see #getFocusAreas()
2611 * @hide
2612 */
2613 public void setFocusAreas(List<Area> focusArea) {
2614 StringBuilder buffer = new StringBuilder();
2615 for (int i = 0; i < focusArea.size(); i++) {
2616 Area area = focusArea.get(i);
2617 Rect rect = area.rect;
2618 buffer.append('(');
2619 buffer.append(rect.left);
2620 buffer.append(',');
2621 buffer.append(rect.top);
2622 buffer.append(',');
2623 buffer.append(rect.right);
2624 buffer.append(',');
2625 buffer.append(rect.bottom);
2626 buffer.append(',');
2627 buffer.append(area.weight);
2628 buffer.append(')');
2629 if (i != focusArea.size() - 1) buffer.append(',');
2630 }
2631 set(KEY_FOCUS_AREAS, buffer.toString());
2632 }
2633
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002634 // Splits a comma delimited string to an ArrayList of String.
2635 // Return null if the passing string is null or the size is 0.
2636 private ArrayList<String> split(String str) {
2637 if (str == null) return null;
2638
2639 // Use StringTokenizer because it is faster than split.
2640 StringTokenizer tokenizer = new StringTokenizer(str, ",");
2641 ArrayList<String> substrings = new ArrayList<String>();
2642 while (tokenizer.hasMoreElements()) {
2643 substrings.add(tokenizer.nextToken());
2644 }
2645 return substrings;
2646 }
2647
2648 // Splits a comma delimited string to an ArrayList of Integer.
2649 // Return null if the passing string is null or the size is 0.
2650 private ArrayList<Integer> splitInt(String str) {
2651 if (str == null) return null;
2652
2653 StringTokenizer tokenizer = new StringTokenizer(str, ",");
2654 ArrayList<Integer> substrings = new ArrayList<Integer>();
2655 while (tokenizer.hasMoreElements()) {
2656 String token = tokenizer.nextToken();
2657 substrings.add(Integer.parseInt(token));
2658 }
2659 if (substrings.size() == 0) return null;
2660 return substrings;
2661 }
2662
Wu-cheng Li454630f2010-08-11 16:48:05 -07002663 private void splitInt(String str, int[] output) {
2664 if (str == null) return;
Wu-cheng Lie339c5e2010-05-13 19:31:02 +08002665
2666 StringTokenizer tokenizer = new StringTokenizer(str, ",");
Wu-cheng Li454630f2010-08-11 16:48:05 -07002667 int index = 0;
Wu-cheng Lie339c5e2010-05-13 19:31:02 +08002668 while (tokenizer.hasMoreElements()) {
2669 String token = tokenizer.nextToken();
Wu-cheng Li454630f2010-08-11 16:48:05 -07002670 output[index++] = Integer.parseInt(token);
Wu-cheng Lie339c5e2010-05-13 19:31:02 +08002671 }
Wu-cheng Li454630f2010-08-11 16:48:05 -07002672 }
2673
2674 // Splits a comma delimited string to an ArrayList of Float.
2675 private void splitFloat(String str, float[] output) {
2676 if (str == null) return;
2677
2678 StringTokenizer tokenizer = new StringTokenizer(str, ",");
2679 int index = 0;
2680 while (tokenizer.hasMoreElements()) {
2681 String token = tokenizer.nextToken();
2682 output[index++] = Float.parseFloat(token);
2683 }
Wu-cheng Lie339c5e2010-05-13 19:31:02 +08002684 }
2685
Wu-cheng Li24b326a2010-02-20 17:47:04 +08002686 // Returns the value of a float parameter.
2687 private float getFloat(String key, float defaultValue) {
2688 try {
2689 return Float.parseFloat(mMap.get(key));
2690 } catch (NumberFormatException ex) {
2691 return defaultValue;
2692 }
2693 }
2694
2695 // Returns the value of a integer parameter.
2696 private int getInt(String key, int defaultValue) {
2697 try {
2698 return Integer.parseInt(mMap.get(key));
2699 } catch (NumberFormatException ex) {
2700 return defaultValue;
2701 }
2702 }
2703
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002704 // Splits a comma delimited string to an ArrayList of Size.
2705 // Return null if the passing string is null or the size is 0.
2706 private ArrayList<Size> splitSize(String str) {
2707 if (str == null) return null;
2708
2709 StringTokenizer tokenizer = new StringTokenizer(str, ",");
2710 ArrayList<Size> sizeList = new ArrayList<Size>();
2711 while (tokenizer.hasMoreElements()) {
2712 Size size = strToSize(tokenizer.nextToken());
2713 if (size != null) sizeList.add(size);
2714 }
2715 if (sizeList.size() == 0) return null;
2716 return sizeList;
2717 }
2718
2719 // Parses a string (ex: "480x320") to Size object.
2720 // Return null if the passing string is null.
2721 private Size strToSize(String str) {
2722 if (str == null) return null;
2723
2724 int pos = str.indexOf('x');
2725 if (pos != -1) {
2726 String width = str.substring(0, pos);
2727 String height = str.substring(pos + 1);
2728 return new Size(Integer.parseInt(width),
2729 Integer.parseInt(height));
2730 }
2731 Log.e(TAG, "Invalid size parameter string=" + str);
2732 return null;
2733 }
Wu-cheng Li454630f2010-08-11 16:48:05 -07002734
2735 // Splits a comma delimited string to an ArrayList of int array.
2736 // Example string: "(10000,26623),(10000,30000)". Return null if the
2737 // passing string is null or the size is 0.
2738 private ArrayList<int[]> splitRange(String str) {
2739 if (str == null || str.charAt(0) != '('
2740 || str.charAt(str.length() - 1) != ')') {
2741 Log.e(TAG, "Invalid range list string=" + str);
2742 return null;
2743 }
2744
2745 ArrayList<int[]> rangeList = new ArrayList<int[]>();
2746 int endIndex, fromIndex = 1;
2747 do {
2748 int[] range = new int[2];
2749 endIndex = str.indexOf("),(", fromIndex);
2750 if (endIndex == -1) endIndex = str.length() - 1;
2751 splitInt(str.substring(fromIndex, endIndex), range);
2752 rangeList.add(range);
2753 fromIndex = endIndex + 3;
2754 } while (endIndex != str.length() - 1);
2755
2756 if (rangeList.size() == 0) return null;
2757 return rangeList;
2758 }
Wu-cheng Li30771b72011-04-02 06:19:46 +08002759
2760 // Splits a comma delimited string to an ArrayList of Area objects.
2761 // Example string: "(-10,-10,0,0,300),(0,0,10,10,700)". Return null if
2762 // the passing string is null or the size is 0.
2763 private ArrayList<Area> splitArea(String str) {
2764 if (str == null || str.charAt(0) != '('
2765 || str.charAt(str.length() - 1) != ')') {
2766 Log.e(TAG, "Invalid area string=" + str);
2767 return null;
2768 }
2769
2770 ArrayList<Area> result = new ArrayList<Area>();
2771 int endIndex, fromIndex = 1;
2772 int[] array = new int[5];
2773 do {
2774 endIndex = str.indexOf("),(", fromIndex);
2775 if (endIndex == -1) endIndex = str.length() - 1;
2776 splitInt(str.substring(fromIndex, endIndex), array);
2777 Rect rect = new Rect(array[0], array[1], array[2], array[3]);
2778 result.add(new Area(rect, array[4]));
2779 fromIndex = endIndex + 3;
2780 } while (endIndex != str.length() - 1);
2781
2782 if (result.size() == 0) return null;
2783 return result;
2784 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002785 };
2786}