The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package android.hardware; |
| 18 | |
Wu-cheng Li | 10e09c6 | 2011-07-18 09:09:41 +0800 | [diff] [blame] | 19 | import android.annotation.SdkConstant; |
| 20 | import android.annotation.SdkConstant.SdkConstantType; |
Mathias Agopian | a696f5d | 2010-02-17 17:53:09 -0800 | [diff] [blame] | 21 | import android.graphics.ImageFormat; |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 22 | import android.graphics.Point; |
Wu-cheng Li | 30771b7 | 2011-04-02 06:19:46 +0800 | [diff] [blame] | 23 | import android.graphics.Rect; |
Jamie Gennis | fd6f39e | 2010-12-20 12:15:00 -0800 | [diff] [blame] | 24 | import android.graphics.SurfaceTexture; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 25 | import android.os.Handler; |
| 26 | import android.os.Looper; |
| 27 | import android.os.Message; |
Wu-cheng Li | bde61a5 | 2011-06-07 18:23:14 +0800 | [diff] [blame] | 28 | import android.util.Log; |
| 29 | import android.view.Surface; |
| 30 | import android.view.SurfaceHolder; |
| 31 | |
| 32 | import java.io.IOException; |
| 33 | import java.lang.ref.WeakReference; |
| 34 | import java.util.ArrayList; |
| 35 | import java.util.HashMap; |
| 36 | import java.util.List; |
| 37 | import java.util.StringTokenizer; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 38 | |
| 39 | /** |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 40 | * The Camera class is used to set image capture settings, start/stop preview, |
| 41 | * snap pictures, and retrieve frames for encoding for video. This class is a |
| 42 | * client for the Camera service, which manages the actual camera hardware. |
Scott Main | df4578e | 2009-09-10 12:22:07 -0700 | [diff] [blame] | 43 | * |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 44 | * <p>To access the device camera, you must declare the |
Wu-cheng Li | 7478ea6 | 2009-09-16 18:52:55 +0800 | [diff] [blame] | 45 | * {@link android.Manifest.permission#CAMERA} permission in your Android |
Scott Main | df4578e | 2009-09-10 12:22:07 -0700 | [diff] [blame] | 46 | * Manifest. Also be sure to include the |
| 47 | * <a href="{@docRoot}guide/topics/manifest/uses-feature-element.html"><uses-feature></a> |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 48 | * manifest element to declare camera features used by your application. |
Wu-cheng Li | 7478ea6 | 2009-09-16 18:52:55 +0800 | [diff] [blame] | 49 | * For example, if you use the camera and auto-focus feature, your Manifest |
Scott Main | df4578e | 2009-09-10 12:22:07 -0700 | [diff] [blame] | 50 | * should include the following:</p> |
| 51 | * <pre> <uses-permission android:name="android.permission.CAMERA" /> |
| 52 | * <uses-feature android:name="android.hardware.camera" /> |
| 53 | * <uses-feature android:name="android.hardware.camera.autofocus" /></pre> |
| 54 | * |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 55 | * <p>To take pictures with this class, use the following steps:</p> |
| 56 | * |
| 57 | * <ol> |
Dan Egnor | 341ff13 | 2010-07-20 11:30:17 -0700 | [diff] [blame] | 58 | * <li>Obtain an instance of Camera from {@link #open(int)}. |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 59 | * |
| 60 | * <li>Get existing (default) settings with {@link #getParameters()}. |
| 61 | * |
| 62 | * <li>If necessary, modify the returned {@link Camera.Parameters} object and call |
| 63 | * {@link #setParameters(Camera.Parameters)}. |
| 64 | * |
| 65 | * <li>If desired, call {@link #setDisplayOrientation(int)}. |
| 66 | * |
| 67 | * <li><b>Important</b>: Pass a fully initialized {@link SurfaceHolder} to |
| 68 | * {@link #setPreviewDisplay(SurfaceHolder)}. Without a surface, the camera |
| 69 | * will be unable to start the preview. |
| 70 | * |
| 71 | * <li><b>Important</b>: Call {@link #startPreview()} to start updating the |
| 72 | * preview surface. Preview must be started before you can take a picture. |
| 73 | * |
| 74 | * <li>When you want, call {@link #takePicture(Camera.ShutterCallback, |
| 75 | * Camera.PictureCallback, Camera.PictureCallback, Camera.PictureCallback)} to |
| 76 | * capture a photo. Wait for the callbacks to provide the actual image data. |
| 77 | * |
| 78 | * <li>After taking a picture, preview display will have stopped. To take more |
| 79 | * photos, call {@link #startPreview()} again first. |
| 80 | * |
| 81 | * <li>Call {@link #stopPreview()} to stop updating the preview surface. |
| 82 | * |
| 83 | * <li><b>Important:</b> Call {@link #release()} to release the camera for |
| 84 | * use by other applications. Applications should release the camera |
| 85 | * immediately in {@link android.app.Activity#onPause()} (and re-{@link #open()} |
| 86 | * it in {@link android.app.Activity#onResume()}). |
| 87 | * </ol> |
| 88 | * |
| 89 | * <p>To quickly switch to video recording mode, use these steps:</p> |
| 90 | * |
| 91 | * <ol> |
| 92 | * <li>Obtain and initialize a Camera and start preview as described above. |
| 93 | * |
| 94 | * <li>Call {@link #unlock()} to allow the media process to access the camera. |
| 95 | * |
| 96 | * <li>Pass the camera to {@link android.media.MediaRecorder#setCamera(Camera)}. |
| 97 | * See {@link android.media.MediaRecorder} information about video recording. |
| 98 | * |
| 99 | * <li>When finished recording, call {@link #reconnect()} to re-acquire |
| 100 | * and re-lock the camera. |
| 101 | * |
| 102 | * <li>If desired, restart preview and take more photos or videos. |
| 103 | * |
| 104 | * <li>Call {@link #stopPreview()} and {@link #release()} as described above. |
| 105 | * </ol> |
| 106 | * |
| 107 | * <p>This class is not thread-safe, and is meant for use from one event thread. |
| 108 | * Most long-running operations (preview, focus, photo capture, etc) happen |
| 109 | * asynchronously and invoke callbacks as necessary. Callbacks will be invoked |
Dan Egnor | 341ff13 | 2010-07-20 11:30:17 -0700 | [diff] [blame] | 110 | * on the event thread {@link #open(int)} was called from. This class's methods |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 111 | * must never be called from multiple threads at once.</p> |
| 112 | * |
Scott Main | df4578e | 2009-09-10 12:22:07 -0700 | [diff] [blame] | 113 | * <p class="caution"><strong>Caution:</strong> Different Android-powered devices |
| 114 | * may have different hardware specifications, such as megapixel ratings and |
| 115 | * auto-focus capabilities. In order for your application to be compatible with |
Wu-cheng Li | 7478ea6 | 2009-09-16 18:52:55 +0800 | [diff] [blame] | 116 | * more devices, you should not make assumptions about the device camera |
Scott Main | df4578e | 2009-09-10 12:22:07 -0700 | [diff] [blame] | 117 | * specifications.</p> |
Joe Fernandez | 6c5c3c3 | 2011-10-18 14:57:05 -0700 | [diff] [blame] | 118 | * |
| 119 | * <div class="special reference"> |
| 120 | * <h3>Developer Guides</h3> |
| 121 | * <p>For more information about using cameras, read the |
| 122 | * <a href="{@docRoot}guide/topics/media/camera.html">Camera</a> developer guide.</p> |
| 123 | * </div> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 124 | */ |
| 125 | public class Camera { |
| 126 | private static final String TAG = "Camera"; |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 127 | |
Wu-cheng Li | d2c2929 | 2010-05-28 17:32:41 +0800 | [diff] [blame] | 128 | // These match the enums in frameworks/base/include/camera/Camera.h |
Benny Wong | da83f46 | 2009-08-12 12:01:27 -0500 | [diff] [blame] | 129 | private static final int CAMERA_MSG_ERROR = 0x001; |
| 130 | private static final int CAMERA_MSG_SHUTTER = 0x002; |
| 131 | private static final int CAMERA_MSG_FOCUS = 0x004; |
| 132 | private static final int CAMERA_MSG_ZOOM = 0x008; |
| 133 | private static final int CAMERA_MSG_PREVIEW_FRAME = 0x010; |
| 134 | private static final int CAMERA_MSG_VIDEO_FRAME = 0x020; |
| 135 | private static final int CAMERA_MSG_POSTVIEW_FRAME = 0x040; |
| 136 | private static final int CAMERA_MSG_RAW_IMAGE = 0x080; |
| 137 | private static final int CAMERA_MSG_COMPRESSED_IMAGE = 0x100; |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 138 | private static final int CAMERA_MSG_RAW_IMAGE_NOTIFY = 0x200; |
Wu-cheng Li | bb1e275 | 2011-07-30 05:00:37 +0800 | [diff] [blame] | 139 | private static final int CAMERA_MSG_PREVIEW_METADATA = 0x400; |
Wu-cheng Li | 9d062cf | 2011-11-14 20:30:14 +0800 | [diff] [blame] | 140 | private static final int CAMERA_MSG_FOCUS_MOVE = 0x800; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 141 | |
| 142 | private int mNativeContext; // accessed by native methods |
| 143 | private EventHandler mEventHandler; |
| 144 | private ShutterCallback mShutterCallback; |
| 145 | private PictureCallback mRawImageCallback; |
| 146 | private PictureCallback mJpegCallback; |
| 147 | private PreviewCallback mPreviewCallback; |
Dave Sparks | e8b26e1 | 2009-07-14 10:35:40 -0700 | [diff] [blame] | 148 | private PictureCallback mPostviewCallback; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 149 | private AutoFocusCallback mAutoFocusCallback; |
Wu-cheng Li | 9d062cf | 2011-11-14 20:30:14 +0800 | [diff] [blame] | 150 | private AutoFocusMoveCallback mAutoFocusMoveCallback; |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 151 | private OnZoomChangeListener mZoomListener; |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 152 | private FaceDetectionListener mFaceListener; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 153 | private ErrorCallback mErrorCallback; |
| 154 | private boolean mOneShot; |
Andrew Harp | 94927df | 2009-10-20 01:47:05 -0400 | [diff] [blame] | 155 | private boolean mWithBuffer; |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 156 | private boolean mFaceDetectionRunning = false; |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 157 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 158 | /** |
Wu-cheng Li | 10e09c6 | 2011-07-18 09:09:41 +0800 | [diff] [blame] | 159 | * Broadcast Action: A new picture is taken by the camera, and the entry of |
| 160 | * the picture has been added to the media store. |
| 161 | * {@link android.content.Intent#getData} is URI of the picture. |
| 162 | */ |
| 163 | @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) |
| 164 | public static final String ACTION_NEW_PICTURE = "android.hardware.action.NEW_PICTURE"; |
| 165 | |
| 166 | /** |
| 167 | * Broadcast Action: A new video is recorded by the camera, and the entry |
| 168 | * of the video has been added to the media store. |
| 169 | * {@link android.content.Intent#getData} is URI of the video. |
| 170 | */ |
| 171 | @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) |
| 172 | public static final String ACTION_NEW_VIDEO = "android.hardware.action.NEW_VIDEO"; |
| 173 | |
| 174 | /** |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 175 | * Hardware face detection. It does not use much CPU. |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 176 | */ |
Wu-cheng Li | c0c683b | 2011-08-04 00:11:00 +0800 | [diff] [blame] | 177 | private static final int CAMERA_FACE_DETECTION_HW = 0; |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 178 | |
| 179 | /** |
Wu-cheng Li | c0c683b | 2011-08-04 00:11:00 +0800 | [diff] [blame] | 180 | * Software face detection. It uses some CPU. |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 181 | */ |
Wu-cheng Li | c0c683b | 2011-08-04 00:11:00 +0800 | [diff] [blame] | 182 | private static final int CAMERA_FACE_DETECTION_SW = 1; |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 183 | |
| 184 | /** |
Dan Egnor | 341ff13 | 2010-07-20 11:30:17 -0700 | [diff] [blame] | 185 | * Returns the number of physical cameras available on this device. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 186 | */ |
Chih-Chung Chang | e25cc65 | 2010-05-06 16:36:58 +0800 | [diff] [blame] | 187 | public native static int getNumberOfCameras(); |
| 188 | |
| 189 | /** |
Dan Egnor | 341ff13 | 2010-07-20 11:30:17 -0700 | [diff] [blame] | 190 | * Returns the information about a particular camera. |
Chih-Chung Chang | b8bb78f | 2010-06-10 13:32:16 +0800 | [diff] [blame] | 191 | * If {@link #getNumberOfCameras()} returns N, the valid id is 0 to N-1. |
Chih-Chung Chang | b8bb78f | 2010-06-10 13:32:16 +0800 | [diff] [blame] | 192 | */ |
| 193 | public native static void getCameraInfo(int cameraId, CameraInfo cameraInfo); |
| 194 | |
| 195 | /** |
| 196 | * Information about a camera |
Chih-Chung Chang | b8bb78f | 2010-06-10 13:32:16 +0800 | [diff] [blame] | 197 | */ |
| 198 | public static class CameraInfo { |
Wu-cheng Li | 7836660 | 2010-09-15 14:08:15 -0700 | [diff] [blame] | 199 | /** |
| 200 | * The facing of the camera is opposite to that of the screen. |
| 201 | */ |
Chih-Chung Chang | b8bb78f | 2010-06-10 13:32:16 +0800 | [diff] [blame] | 202 | public static final int CAMERA_FACING_BACK = 0; |
Wu-cheng Li | 7836660 | 2010-09-15 14:08:15 -0700 | [diff] [blame] | 203 | |
| 204 | /** |
| 205 | * The facing of the camera is the same as that of the screen. |
| 206 | */ |
Chih-Chung Chang | b8bb78f | 2010-06-10 13:32:16 +0800 | [diff] [blame] | 207 | public static final int CAMERA_FACING_FRONT = 1; |
| 208 | |
| 209 | /** |
Joe Fernandez | 464cb21 | 2011-10-04 16:56:47 -0700 | [diff] [blame] | 210 | * The direction that the camera faces. It should be |
Chih-Chung Chang | b8bb78f | 2010-06-10 13:32:16 +0800 | [diff] [blame] | 211 | * CAMERA_FACING_BACK or CAMERA_FACING_FRONT. |
| 212 | */ |
Wu-cheng Li | 7836660 | 2010-09-15 14:08:15 -0700 | [diff] [blame] | 213 | public int facing; |
Chih-Chung Chang | b8bb78f | 2010-06-10 13:32:16 +0800 | [diff] [blame] | 214 | |
| 215 | /** |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 216 | * <p>The orientation of the camera image. The value is the angle that the |
Chih-Chung Chang | b8bb78f | 2010-06-10 13:32:16 +0800 | [diff] [blame] | 217 | * camera image needs to be rotated clockwise so it shows correctly on |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 218 | * the display in its natural orientation. It should be 0, 90, 180, or 270.</p> |
Chih-Chung Chang | b8bb78f | 2010-06-10 13:32:16 +0800 | [diff] [blame] | 219 | * |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 220 | * <p>For example, suppose a device has a naturally tall screen. The |
Wu-cheng Li | 2fe6fca | 2010-10-15 14:42:23 +0800 | [diff] [blame] | 221 | * back-facing camera sensor is mounted in landscape. You are looking at |
| 222 | * the screen. If the top side of the camera sensor is aligned with the |
| 223 | * right edge of the screen in natural orientation, the value should be |
| 224 | * 90. If the top side of a front-facing camera sensor is aligned with |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 225 | * the right of the screen, the value should be 270.</p> |
Chih-Chung Chang | b8bb78f | 2010-06-10 13:32:16 +0800 | [diff] [blame] | 226 | * |
| 227 | * @see #setDisplayOrientation(int) |
Brad Fitzpatrick | 69ea4e1 | 2011-01-05 11:13:40 -0800 | [diff] [blame] | 228 | * @see Parameters#setRotation(int) |
| 229 | * @see Parameters#setPreviewSize(int, int) |
| 230 | * @see Parameters#setPictureSize(int, int) |
| 231 | * @see Parameters#setJpegThumbnailSize(int, int) |
Chih-Chung Chang | b8bb78f | 2010-06-10 13:32:16 +0800 | [diff] [blame] | 232 | */ |
Wu-cheng Li | 7836660 | 2010-09-15 14:08:15 -0700 | [diff] [blame] | 233 | public int orientation; |
Chih-Chung Chang | b8bb78f | 2010-06-10 13:32:16 +0800 | [diff] [blame] | 234 | }; |
| 235 | |
| 236 | /** |
Dan Egnor | 341ff13 | 2010-07-20 11:30:17 -0700 | [diff] [blame] | 237 | * Creates a new Camera object to access a particular hardware camera. |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 238 | * |
| 239 | * <p>You must call {@link #release()} when you are done using the camera, |
| 240 | * otherwise it will remain locked and be unavailable to other applications. |
| 241 | * |
Dan Egnor | 341ff13 | 2010-07-20 11:30:17 -0700 | [diff] [blame] | 242 | * <p>Your application should only have one Camera object active at a time |
| 243 | * for a particular hardware camera. |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 244 | * |
| 245 | * <p>Callbacks from other methods are delivered to the event loop of the |
| 246 | * thread which called open(). If this thread has no event loop, then |
| 247 | * callbacks are delivered to the main application event loop. If there |
| 248 | * is no main application event loop, callbacks are not delivered. |
| 249 | * |
| 250 | * <p class="caution"><b>Caution:</b> On some devices, this method may |
| 251 | * take a long time to complete. It is best to call this method from a |
| 252 | * worker thread (possibly using {@link android.os.AsyncTask}) to avoid |
| 253 | * blocking the main application UI thread. |
| 254 | * |
Dan Egnor | 341ff13 | 2010-07-20 11:30:17 -0700 | [diff] [blame] | 255 | * @param cameraId the hardware camera to access, between 0 and |
Wu-cheng Li | a48b70f | 2010-11-09 01:55:44 +0800 | [diff] [blame] | 256 | * {@link #getNumberOfCameras()}-1. |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 257 | * @return a new Camera object, connected, locked and ready for use. |
| 258 | * @throws RuntimeException if connection to the camera service fails (for |
Wu-cheng Li | facc8ce | 2011-06-17 13:09:40 +0800 | [diff] [blame] | 259 | * example, if the camera is in use by another process or device policy |
| 260 | * manager has disabled the camera). |
| 261 | * @see android.app.admin.DevicePolicyManager#getCameraDisabled(android.content.ComponentName) |
Chih-Chung Chang | e25cc65 | 2010-05-06 16:36:58 +0800 | [diff] [blame] | 262 | */ |
| 263 | public static Camera open(int cameraId) { |
| 264 | return new Camera(cameraId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 265 | } |
| 266 | |
Chih-Chung Chang | e25cc65 | 2010-05-06 16:36:58 +0800 | [diff] [blame] | 267 | /** |
Wu-cheng Li | a48b70f | 2010-11-09 01:55:44 +0800 | [diff] [blame] | 268 | * Creates a new Camera object to access the first back-facing camera on the |
| 269 | * device. If the device does not have a back-facing camera, this returns |
| 270 | * null. |
Wu-cheng Li | 7836660 | 2010-09-15 14:08:15 -0700 | [diff] [blame] | 271 | * @see #open(int) |
Chih-Chung Chang | e25cc65 | 2010-05-06 16:36:58 +0800 | [diff] [blame] | 272 | */ |
| 273 | public static Camera open() { |
Wu-cheng Li | a48b70f | 2010-11-09 01:55:44 +0800 | [diff] [blame] | 274 | int numberOfCameras = getNumberOfCameras(); |
| 275 | CameraInfo cameraInfo = new CameraInfo(); |
| 276 | for (int i = 0; i < numberOfCameras; i++) { |
| 277 | getCameraInfo(i, cameraInfo); |
| 278 | if (cameraInfo.facing == CameraInfo.CAMERA_FACING_BACK) { |
| 279 | return new Camera(i); |
| 280 | } |
| 281 | } |
| 282 | return null; |
Chih-Chung Chang | e25cc65 | 2010-05-06 16:36:58 +0800 | [diff] [blame] | 283 | } |
| 284 | |
| 285 | Camera(int cameraId) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 286 | mShutterCallback = null; |
| 287 | mRawImageCallback = null; |
| 288 | mJpegCallback = null; |
| 289 | mPreviewCallback = null; |
Dave Sparks | e8b26e1 | 2009-07-14 10:35:40 -0700 | [diff] [blame] | 290 | mPostviewCallback = null; |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 291 | mZoomListener = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 292 | |
| 293 | Looper looper; |
| 294 | if ((looper = Looper.myLooper()) != null) { |
| 295 | mEventHandler = new EventHandler(this, looper); |
| 296 | } else if ((looper = Looper.getMainLooper()) != null) { |
| 297 | mEventHandler = new EventHandler(this, looper); |
| 298 | } else { |
| 299 | mEventHandler = null; |
| 300 | } |
| 301 | |
Chih-Chung Chang | e25cc65 | 2010-05-06 16:36:58 +0800 | [diff] [blame] | 302 | native_setup(new WeakReference<Camera>(this), cameraId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 303 | } |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 304 | |
Wu-cheng Li | 1c04a33 | 2011-11-22 18:21:18 +0800 | [diff] [blame] | 305 | /** |
| 306 | * An empty Camera for testing purpose. |
| 307 | */ |
| 308 | Camera() { |
| 309 | } |
| 310 | |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 311 | protected void finalize() { |
Eino-Ville Talvala | e0cc55a | 2011-11-08 10:12:09 -0800 | [diff] [blame] | 312 | release(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 313 | } |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 314 | |
Chih-Chung Chang | e25cc65 | 2010-05-06 16:36:58 +0800 | [diff] [blame] | 315 | private native final void native_setup(Object camera_this, int cameraId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 316 | private native final void native_release(); |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 317 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 318 | |
| 319 | /** |
| 320 | * Disconnects and releases the Camera object resources. |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 321 | * |
| 322 | * <p>You must call this as soon as you're done with the Camera object.</p> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 323 | */ |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 324 | public final void release() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 325 | native_release(); |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 326 | mFaceDetectionRunning = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 327 | } |
| 328 | |
| 329 | /** |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 330 | * Unlocks the camera to allow another process to access it. |
| 331 | * Normally, the camera is locked to the process with an active Camera |
| 332 | * object until {@link #release()} is called. To allow rapid handoff |
| 333 | * between processes, you can call this method to release the camera |
| 334 | * temporarily for another process to use; once the other process is done |
| 335 | * you can call {@link #reconnect()} to reclaim the camera. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 336 | * |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 337 | * <p>This must be done before calling |
Wu-cheng Li | 42419ce | 2011-06-01 17:22:24 +0800 | [diff] [blame] | 338 | * {@link android.media.MediaRecorder#setCamera(Camera)}. This cannot be |
| 339 | * called after recording starts. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 340 | * |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 341 | * <p>If you are not recording video, you probably do not need this method. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 342 | * |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 343 | * @throws RuntimeException if the camera cannot be unlocked. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 344 | */ |
Wu-cheng Li | ffe1cf2 | 2009-09-10 16:49:17 +0800 | [diff] [blame] | 345 | public native final void unlock(); |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 346 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 347 | /** |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 348 | * Re-locks the camera to prevent other processes from accessing it. |
| 349 | * Camera objects are locked by default unless {@link #unlock()} is |
| 350 | * called. Normally {@link #reconnect()} is used instead. |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 351 | * |
Wu-cheng Li | 53b3091 | 2011-10-12 19:43:51 +0800 | [diff] [blame] | 352 | * <p>Since API level 14, camera is automatically locked for applications in |
Wu-cheng Li | 42419ce | 2011-06-01 17:22:24 +0800 | [diff] [blame] | 353 | * {@link android.media.MediaRecorder#start()}. Applications can use the |
| 354 | * camera (ex: zoom) after recording starts. There is no need to call this |
| 355 | * after recording starts or stops. |
| 356 | * |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 357 | * <p>If you are not recording video, you probably do not need this method. |
| 358 | * |
| 359 | * @throws RuntimeException if the camera cannot be re-locked (for |
| 360 | * example, if the camera is still in use by another process). |
| 361 | */ |
| 362 | public native final void lock(); |
| 363 | |
| 364 | /** |
| 365 | * Reconnects to the camera service after another process used it. |
| 366 | * After {@link #unlock()} is called, another process may use the |
| 367 | * camera; when the process is done, you must reconnect to the camera, |
| 368 | * which will re-acquire the lock and allow you to continue using the |
| 369 | * camera. |
| 370 | * |
Wu-cheng Li | 53b3091 | 2011-10-12 19:43:51 +0800 | [diff] [blame] | 371 | * <p>Since API level 14, camera is automatically locked for applications in |
Wu-cheng Li | 42419ce | 2011-06-01 17:22:24 +0800 | [diff] [blame] | 372 | * {@link android.media.MediaRecorder#start()}. Applications can use the |
| 373 | * camera (ex: zoom) after recording starts. There is no need to call this |
| 374 | * after recording starts or stops. |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 375 | * |
| 376 | * <p>If you are not recording video, you probably do not need this method. |
| 377 | * |
| 378 | * @throws IOException if a connection cannot be re-established (for |
| 379 | * example, if the camera is still in use by another process). |
| 380 | */ |
| 381 | public native final void reconnect() throws IOException; |
| 382 | |
| 383 | /** |
| 384 | * Sets the {@link Surface} to be used for live preview. |
Jamie Gennis | fd6f39e | 2010-12-20 12:15:00 -0800 | [diff] [blame] | 385 | * Either a surface or surface texture is necessary for preview, and |
| 386 | * preview is necessary to take pictures. The same surface can be re-set |
| 387 | * without harm. Setting a preview surface will un-set any preview surface |
| 388 | * texture that was set via {@link #setPreviewTexture}. |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 389 | * |
| 390 | * <p>The {@link SurfaceHolder} must already contain a surface when this |
| 391 | * method is called. If you are using {@link android.view.SurfaceView}, |
| 392 | * you will need to register a {@link SurfaceHolder.Callback} with |
| 393 | * {@link SurfaceHolder#addCallback(SurfaceHolder.Callback)} and wait for |
| 394 | * {@link SurfaceHolder.Callback#surfaceCreated(SurfaceHolder)} before |
| 395 | * calling setPreviewDisplay() or starting preview. |
| 396 | * |
| 397 | * <p>This method must be called before {@link #startPreview()}. The |
| 398 | * one exception is that if the preview surface is not set (or set to null) |
| 399 | * before startPreview() is called, then this method may be called once |
| 400 | * with a non-null parameter to set the preview surface. (This allows |
| 401 | * camera setup and surface creation to happen in parallel, saving time.) |
| 402 | * The preview surface may not otherwise change while preview is running. |
| 403 | * |
| 404 | * @param holder containing the Surface on which to place the preview, |
| 405 | * or null to remove the preview surface |
| 406 | * @throws IOException if the method fails (for example, if the surface |
| 407 | * is unavailable or unsuitable). |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 408 | */ |
| 409 | public final void setPreviewDisplay(SurfaceHolder holder) throws IOException { |
Wu-cheng Li | b8a10fe | 2009-06-23 23:37:36 +0800 | [diff] [blame] | 410 | if (holder != null) { |
| 411 | setPreviewDisplay(holder.getSurface()); |
| 412 | } else { |
| 413 | setPreviewDisplay((Surface)null); |
| 414 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 415 | } |
| 416 | |
Glenn Kasten | dbc289d | 2011-02-09 10:15:44 -0800 | [diff] [blame] | 417 | private native final void setPreviewDisplay(Surface surface) throws IOException; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 418 | |
| 419 | /** |
Jamie Gennis | fd6f39e | 2010-12-20 12:15:00 -0800 | [diff] [blame] | 420 | * Sets the {@link SurfaceTexture} to be used for live preview. |
| 421 | * Either a surface or surface texture is necessary for preview, and |
| 422 | * preview is necessary to take pictures. The same surface texture can be |
| 423 | * re-set without harm. Setting a preview surface texture will un-set any |
| 424 | * preview surface that was set via {@link #setPreviewDisplay}. |
| 425 | * |
| 426 | * <p>This method must be called before {@link #startPreview()}. The |
| 427 | * one exception is that if the preview surface texture is not set (or set |
| 428 | * to null) before startPreview() is called, then this method may be called |
| 429 | * once with a non-null parameter to set the preview surface. (This allows |
| 430 | * camera setup and surface creation to happen in parallel, saving time.) |
| 431 | * The preview surface texture may not otherwise change while preview is |
| 432 | * running. |
| 433 | * |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 434 | * <p>The timestamps provided by {@link SurfaceTexture#getTimestamp()} for a |
Eino-Ville Talvala | e309a0f | 2011-03-21 11:04:34 -0700 | [diff] [blame] | 435 | * SurfaceTexture set as the preview texture have an unspecified zero point, |
| 436 | * and cannot be directly compared between different cameras or different |
| 437 | * instances of the same camera, or across multiple runs of the same |
| 438 | * program. |
| 439 | * |
Jamie Gennis | fd6f39e | 2010-12-20 12:15:00 -0800 | [diff] [blame] | 440 | * @param surfaceTexture the {@link SurfaceTexture} to which the preview |
| 441 | * images are to be sent or null to remove the current preview surface |
| 442 | * texture |
| 443 | * @throws IOException if the method fails (for example, if the surface |
| 444 | * texture is unavailable or unsuitable). |
| 445 | */ |
Glenn Kasten | dbc289d | 2011-02-09 10:15:44 -0800 | [diff] [blame] | 446 | public native final void setPreviewTexture(SurfaceTexture surfaceTexture) throws IOException; |
Jamie Gennis | fd6f39e | 2010-12-20 12:15:00 -0800 | [diff] [blame] | 447 | |
| 448 | /** |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 449 | * Callback interface used to deliver copies of preview frames as |
| 450 | * they are displayed. |
| 451 | * |
| 452 | * @see #setPreviewCallback(Camera.PreviewCallback) |
| 453 | * @see #setOneShotPreviewCallback(Camera.PreviewCallback) |
| 454 | * @see #setPreviewCallbackWithBuffer(Camera.PreviewCallback) |
| 455 | * @see #startPreview() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 456 | */ |
| 457 | public interface PreviewCallback |
| 458 | { |
| 459 | /** |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 460 | * Called as preview frames are displayed. This callback is invoked |
Dan Egnor | 341ff13 | 2010-07-20 11:30:17 -0700 | [diff] [blame] | 461 | * on the event thread {@link #open(int)} was called from. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 462 | * |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 463 | * @param data the contents of the preview frame in the format defined |
Mathias Agopian | a696f5d | 2010-02-17 17:53:09 -0800 | [diff] [blame] | 464 | * by {@link android.graphics.ImageFormat}, which can be queried |
Scott Main | df4578e | 2009-09-10 12:22:07 -0700 | [diff] [blame] | 465 | * with {@link android.hardware.Camera.Parameters#getPreviewFormat()}. |
Scott Main | da0a56df | 2009-09-10 18:08:37 -0700 | [diff] [blame] | 466 | * If {@link android.hardware.Camera.Parameters#setPreviewFormat(int)} |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 467 | * is never called, the default will be the YCbCr_420_SP |
| 468 | * (NV21) format. |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 469 | * @param camera the Camera service object. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 470 | */ |
| 471 | void onPreviewFrame(byte[] data, Camera camera); |
| 472 | }; |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 473 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 474 | /** |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 475 | * Starts capturing and drawing preview frames to the screen. |
Eino-Ville Talvala | c5f94d8 | 2011-02-18 11:02:42 -0800 | [diff] [blame] | 476 | * Preview will not actually start until a surface is supplied |
| 477 | * with {@link #setPreviewDisplay(SurfaceHolder)} or |
| 478 | * {@link #setPreviewTexture(SurfaceTexture)}. |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 479 | * |
| 480 | * <p>If {@link #setPreviewCallback(Camera.PreviewCallback)}, |
| 481 | * {@link #setOneShotPreviewCallback(Camera.PreviewCallback)}, or |
| 482 | * {@link #setPreviewCallbackWithBuffer(Camera.PreviewCallback)} were |
| 483 | * called, {@link Camera.PreviewCallback#onPreviewFrame(byte[], Camera)} |
| 484 | * will be called when preview data becomes available. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 485 | */ |
| 486 | public native final void startPreview(); |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 487 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 488 | /** |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 489 | * Stops capturing and drawing preview frames to the surface, and |
| 490 | * resets the camera for a future call to {@link #startPreview()}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 491 | */ |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 492 | public final void stopPreview() { |
| 493 | _stopPreview(); |
| 494 | mFaceDetectionRunning = false; |
Chih-yu Huang | 664d72e | 2011-09-23 18:59:38 +0800 | [diff] [blame] | 495 | |
| 496 | mShutterCallback = null; |
| 497 | mRawImageCallback = null; |
| 498 | mPostviewCallback = null; |
| 499 | mJpegCallback = null; |
| 500 | mAutoFocusCallback = null; |
Wu-cheng Li | 9d062cf | 2011-11-14 20:30:14 +0800 | [diff] [blame] | 501 | mAutoFocusMoveCallback = null; |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 502 | } |
| 503 | |
| 504 | private native final void _stopPreview(); |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 505 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 506 | /** |
| 507 | * Return current preview state. |
| 508 | * |
| 509 | * FIXME: Unhide before release |
| 510 | * @hide |
| 511 | */ |
| 512 | public native final boolean previewEnabled(); |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 513 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 514 | /** |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 515 | * Installs a callback to be invoked for every preview frame in addition |
| 516 | * to displaying them on the screen. The callback will be repeatedly called |
| 517 | * for as long as preview is active. This method can be called at any time, |
| 518 | * even while preview is live. Any other preview callbacks are overridden. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 519 | * |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 520 | * @param cb a callback object that receives a copy of each preview frame, |
| 521 | * or null to stop receiving callbacks. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 522 | */ |
| 523 | public final void setPreviewCallback(PreviewCallback cb) { |
| 524 | mPreviewCallback = cb; |
| 525 | mOneShot = false; |
Andrew Harp | 94927df | 2009-10-20 01:47:05 -0400 | [diff] [blame] | 526 | mWithBuffer = false; |
Dave Sparks | a6118c6 | 2009-10-13 02:28:54 -0700 | [diff] [blame] | 527 | // Always use one-shot mode. We fake camera preview mode by |
| 528 | // doing one-shot preview continuously. |
Andrew Harp | 94927df | 2009-10-20 01:47:05 -0400 | [diff] [blame] | 529 | setHasPreviewCallback(cb != null, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 530 | } |
| 531 | |
| 532 | /** |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 533 | * Installs a callback to be invoked for the next preview frame in addition |
| 534 | * to displaying it on the screen. After one invocation, the callback is |
| 535 | * cleared. This method can be called any time, even when preview is live. |
| 536 | * Any other preview callbacks are overridden. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 537 | * |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 538 | * @param cb a callback object that receives a copy of the next preview frame, |
| 539 | * or null to stop receiving callbacks. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 540 | */ |
| 541 | public final void setOneShotPreviewCallback(PreviewCallback cb) { |
Andrew Harp | 94927df | 2009-10-20 01:47:05 -0400 | [diff] [blame] | 542 | mPreviewCallback = cb; |
| 543 | mOneShot = true; |
| 544 | mWithBuffer = false; |
| 545 | setHasPreviewCallback(cb != null, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 546 | } |
| 547 | |
Andrew Harp | 94927df | 2009-10-20 01:47:05 -0400 | [diff] [blame] | 548 | private native final void setHasPreviewCallback(boolean installed, boolean manualBuffer); |
| 549 | |
| 550 | /** |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 551 | * Installs a callback to be invoked for every preview frame, using buffers |
| 552 | * supplied with {@link #addCallbackBuffer(byte[])}, in addition to |
| 553 | * displaying them on the screen. The callback will be repeatedly called |
| 554 | * for as long as preview is active and buffers are available. |
| 555 | * Any other preview callbacks are overridden. |
Andrew Harp | 94927df | 2009-10-20 01:47:05 -0400 | [diff] [blame] | 556 | * |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 557 | * <p>The purpose of this method is to improve preview efficiency and frame |
| 558 | * rate by allowing preview frame memory reuse. You must call |
| 559 | * {@link #addCallbackBuffer(byte[])} at some point -- before or after |
| 560 | * calling this method -- or no callbacks will received. |
Andrew Harp | 94927df | 2009-10-20 01:47:05 -0400 | [diff] [blame] | 561 | * |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 562 | * The buffer queue will be cleared if this method is called with a null |
| 563 | * callback, {@link #setPreviewCallback(Camera.PreviewCallback)} is called, |
| 564 | * or {@link #setOneShotPreviewCallback(Camera.PreviewCallback)} is called. |
Andrew Harp | 94927df | 2009-10-20 01:47:05 -0400 | [diff] [blame] | 565 | * |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 566 | * @param cb a callback object that receives a copy of the preview frame, |
| 567 | * or null to stop receiving callbacks and clear the buffer queue. |
| 568 | * @see #addCallbackBuffer(byte[]) |
Andrew Harp | 94927df | 2009-10-20 01:47:05 -0400 | [diff] [blame] | 569 | */ |
| 570 | public final void setPreviewCallbackWithBuffer(PreviewCallback cb) { |
| 571 | mPreviewCallback = cb; |
| 572 | mOneShot = false; |
| 573 | mWithBuffer = true; |
| 574 | setHasPreviewCallback(cb != null, true); |
| 575 | } |
| 576 | |
| 577 | /** |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 578 | * Adds a pre-allocated buffer to the preview callback buffer queue. |
| 579 | * Applications can add one or more buffers to the queue. When a preview |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 580 | * frame arrives and there is still at least one available buffer, the |
| 581 | * buffer will be used and removed from the queue. Then preview callback is |
| 582 | * invoked with the buffer. If a frame arrives and there is no buffer left, |
| 583 | * the frame is discarded. Applications should add buffers back when they |
| 584 | * finish processing the data in them. |
Wu-cheng Li | c10275a | 2010-03-09 13:49:21 -0800 | [diff] [blame] | 585 | * |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 586 | * <p>The size of the buffer is determined by multiplying the preview |
James Dong | e00cab7 | 2011-02-17 16:38:06 -0800 | [diff] [blame] | 587 | * image width, height, and bytes per pixel. The width and height can be |
| 588 | * read from {@link Camera.Parameters#getPreviewSize()}. Bytes per pixel |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 589 | * can be computed from |
| 590 | * {@link android.graphics.ImageFormat#getBitsPerPixel(int)} / 8, |
| 591 | * using the image format from {@link Camera.Parameters#getPreviewFormat()}. |
Andrew Harp | 94927df | 2009-10-20 01:47:05 -0400 | [diff] [blame] | 592 | * |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 593 | * <p>This method is only necessary when |
James Dong | e00cab7 | 2011-02-17 16:38:06 -0800 | [diff] [blame] | 594 | * {@link #setPreviewCallbackWithBuffer(PreviewCallback)} is used. When |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 595 | * {@link #setPreviewCallback(PreviewCallback)} or |
| 596 | * {@link #setOneShotPreviewCallback(PreviewCallback)} are used, buffers |
James Dong | e00cab7 | 2011-02-17 16:38:06 -0800 | [diff] [blame] | 597 | * are automatically allocated. When a supplied buffer is too small to |
| 598 | * hold the preview frame data, preview callback will return null and |
| 599 | * the buffer will be removed from the buffer queue. |
Andrew Harp | 94927df | 2009-10-20 01:47:05 -0400 | [diff] [blame] | 600 | * |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 601 | * @param callbackBuffer the buffer to add to the queue. |
| 602 | * The size should be width * height * bits_per_pixel / 8. |
Wu-cheng Li | 5b9bcda | 2010-03-07 14:59:28 -0800 | [diff] [blame] | 603 | * @see #setPreviewCallbackWithBuffer(PreviewCallback) |
Andrew Harp | 94927df | 2009-10-20 01:47:05 -0400 | [diff] [blame] | 604 | */ |
James Dong | e00cab7 | 2011-02-17 16:38:06 -0800 | [diff] [blame] | 605 | public final void addCallbackBuffer(byte[] callbackBuffer) |
| 606 | { |
| 607 | _addCallbackBuffer(callbackBuffer, CAMERA_MSG_PREVIEW_FRAME); |
| 608 | } |
| 609 | |
| 610 | /** |
| 611 | * Adds a pre-allocated buffer to the raw image callback buffer queue. |
| 612 | * Applications can add one or more buffers to the queue. When a raw image |
| 613 | * frame arrives and there is still at least one available buffer, the |
| 614 | * buffer will be used to hold the raw image data and removed from the |
| 615 | * queue. Then raw image callback is invoked with the buffer. If a raw |
| 616 | * image frame arrives but there is no buffer left, the frame is |
| 617 | * discarded. Applications should add buffers back when they finish |
| 618 | * processing the data in them by calling this method again in order |
| 619 | * to avoid running out of raw image callback buffers. |
| 620 | * |
| 621 | * <p>The size of the buffer is determined by multiplying the raw image |
| 622 | * width, height, and bytes per pixel. The width and height can be |
| 623 | * read from {@link Camera.Parameters#getPictureSize()}. Bytes per pixel |
| 624 | * can be computed from |
| 625 | * {@link android.graphics.ImageFormat#getBitsPerPixel(int)} / 8, |
| 626 | * using the image format from {@link Camera.Parameters#getPreviewFormat()}. |
| 627 | * |
| 628 | * <p>This method is only necessary when the PictureCallbck for raw image |
| 629 | * is used while calling {@link #takePicture(Camera.ShutterCallback, |
| 630 | * Camera.PictureCallback, Camera.PictureCallback, Camera.PictureCallback)}. |
| 631 | * |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 632 | * <p>Please note that by calling this method, the mode for |
| 633 | * application-managed callback buffers is triggered. If this method has |
| 634 | * never been called, null will be returned by the raw image callback since |
| 635 | * there is no image callback buffer available. Furthermore, When a supplied |
| 636 | * buffer is too small to hold the raw image data, raw image callback will |
| 637 | * return null and the buffer will be removed from the buffer queue. |
James Dong | e00cab7 | 2011-02-17 16:38:06 -0800 | [diff] [blame] | 638 | * |
| 639 | * @param callbackBuffer the buffer to add to the raw image callback buffer |
| 640 | * queue. The size should be width * height * (bits per pixel) / 8. An |
| 641 | * null callbackBuffer will be ignored and won't be added to the queue. |
| 642 | * |
| 643 | * @see #takePicture(Camera.ShutterCallback, |
| 644 | * Camera.PictureCallback, Camera.PictureCallback, Camera.PictureCallback)}. |
| 645 | * |
| 646 | * {@hide} |
| 647 | */ |
| 648 | public final void addRawImageCallbackBuffer(byte[] callbackBuffer) |
| 649 | { |
| 650 | addCallbackBuffer(callbackBuffer, CAMERA_MSG_RAW_IMAGE); |
| 651 | } |
| 652 | |
| 653 | private final void addCallbackBuffer(byte[] callbackBuffer, int msgType) |
| 654 | { |
| 655 | // CAMERA_MSG_VIDEO_FRAME may be allowed in the future. |
| 656 | if (msgType != CAMERA_MSG_PREVIEW_FRAME && |
| 657 | msgType != CAMERA_MSG_RAW_IMAGE) { |
| 658 | throw new IllegalArgumentException( |
| 659 | "Unsupported message type: " + msgType); |
| 660 | } |
| 661 | |
| 662 | _addCallbackBuffer(callbackBuffer, msgType); |
| 663 | } |
| 664 | |
| 665 | private native final void _addCallbackBuffer( |
| 666 | byte[] callbackBuffer, int msgType); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 667 | |
| 668 | private class EventHandler extends Handler |
| 669 | { |
| 670 | private Camera mCamera; |
| 671 | |
| 672 | public EventHandler(Camera c, Looper looper) { |
| 673 | super(looper); |
| 674 | mCamera = c; |
| 675 | } |
| 676 | |
| 677 | @Override |
| 678 | public void handleMessage(Message msg) { |
| 679 | switch(msg.what) { |
Dave Sparks | c62f9bd | 2009-06-26 13:33:32 -0700 | [diff] [blame] | 680 | case CAMERA_MSG_SHUTTER: |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 681 | if (mShutterCallback != null) { |
| 682 | mShutterCallback.onShutter(); |
| 683 | } |
| 684 | return; |
Dave Sparks | c62f9bd | 2009-06-26 13:33:32 -0700 | [diff] [blame] | 685 | |
| 686 | case CAMERA_MSG_RAW_IMAGE: |
Dave Sparks | e8b26e1 | 2009-07-14 10:35:40 -0700 | [diff] [blame] | 687 | if (mRawImageCallback != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 688 | mRawImageCallback.onPictureTaken((byte[])msg.obj, mCamera); |
Dave Sparks | e8b26e1 | 2009-07-14 10:35:40 -0700 | [diff] [blame] | 689 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 690 | return; |
| 691 | |
Dave Sparks | c62f9bd | 2009-06-26 13:33:32 -0700 | [diff] [blame] | 692 | case CAMERA_MSG_COMPRESSED_IMAGE: |
Dave Sparks | e8b26e1 | 2009-07-14 10:35:40 -0700 | [diff] [blame] | 693 | if (mJpegCallback != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 694 | mJpegCallback.onPictureTaken((byte[])msg.obj, mCamera); |
Dave Sparks | e8b26e1 | 2009-07-14 10:35:40 -0700 | [diff] [blame] | 695 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 696 | return; |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 697 | |
Dave Sparks | c62f9bd | 2009-06-26 13:33:32 -0700 | [diff] [blame] | 698 | case CAMERA_MSG_PREVIEW_FRAME: |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 699 | if (mPreviewCallback != null) { |
Dave Sparks | a6118c6 | 2009-10-13 02:28:54 -0700 | [diff] [blame] | 700 | PreviewCallback cb = mPreviewCallback; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 701 | if (mOneShot) { |
Dave Sparks | a6118c6 | 2009-10-13 02:28:54 -0700 | [diff] [blame] | 702 | // Clear the callback variable before the callback |
| 703 | // in case the app calls setPreviewCallback from |
| 704 | // the callback function |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 705 | mPreviewCallback = null; |
Andrew Harp | 94927df | 2009-10-20 01:47:05 -0400 | [diff] [blame] | 706 | } else if (!mWithBuffer) { |
Dave Sparks | a6118c6 | 2009-10-13 02:28:54 -0700 | [diff] [blame] | 707 | // We're faking the camera preview mode to prevent |
| 708 | // the app from being flooded with preview frames. |
| 709 | // Set to oneshot mode again. |
Andrew Harp | 94927df | 2009-10-20 01:47:05 -0400 | [diff] [blame] | 710 | setHasPreviewCallback(true, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 711 | } |
Dave Sparks | a6118c6 | 2009-10-13 02:28:54 -0700 | [diff] [blame] | 712 | cb.onPreviewFrame((byte[])msg.obj, mCamera); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 713 | } |
| 714 | return; |
| 715 | |
Dave Sparks | e8b26e1 | 2009-07-14 10:35:40 -0700 | [diff] [blame] | 716 | case CAMERA_MSG_POSTVIEW_FRAME: |
| 717 | if (mPostviewCallback != null) { |
| 718 | mPostviewCallback.onPictureTaken((byte[])msg.obj, mCamera); |
| 719 | } |
| 720 | return; |
| 721 | |
Dave Sparks | c62f9bd | 2009-06-26 13:33:32 -0700 | [diff] [blame] | 722 | case CAMERA_MSG_FOCUS: |
Dave Sparks | e8b26e1 | 2009-07-14 10:35:40 -0700 | [diff] [blame] | 723 | if (mAutoFocusCallback != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 724 | mAutoFocusCallback.onAutoFocus(msg.arg1 == 0 ? false : true, mCamera); |
Dave Sparks | e8b26e1 | 2009-07-14 10:35:40 -0700 | [diff] [blame] | 725 | } |
| 726 | return; |
| 727 | |
| 728 | case CAMERA_MSG_ZOOM: |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 729 | if (mZoomListener != null) { |
| 730 | mZoomListener.onZoomChange(msg.arg1, msg.arg2 != 0, mCamera); |
Dave Sparks | e8b26e1 | 2009-07-14 10:35:40 -0700 | [diff] [blame] | 731 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 732 | return; |
| 733 | |
Wu-cheng Li | bb1e275 | 2011-07-30 05:00:37 +0800 | [diff] [blame] | 734 | case CAMERA_MSG_PREVIEW_METADATA: |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 735 | if (mFaceListener != null) { |
Wu-cheng Li | f0d6a48 | 2011-07-28 05:30:59 +0800 | [diff] [blame] | 736 | mFaceListener.onFaceDetection((Face[])msg.obj, mCamera); |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 737 | } |
| 738 | return; |
| 739 | |
Dave Sparks | c62f9bd | 2009-06-26 13:33:32 -0700 | [diff] [blame] | 740 | case CAMERA_MSG_ERROR : |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 741 | Log.e(TAG, "Error " + msg.arg1); |
Dave Sparks | e8b26e1 | 2009-07-14 10:35:40 -0700 | [diff] [blame] | 742 | if (mErrorCallback != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 743 | mErrorCallback.onError(msg.arg1, mCamera); |
Dave Sparks | e8b26e1 | 2009-07-14 10:35:40 -0700 | [diff] [blame] | 744 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 745 | return; |
| 746 | |
Wu-cheng Li | 9d062cf | 2011-11-14 20:30:14 +0800 | [diff] [blame] | 747 | case CAMERA_MSG_FOCUS_MOVE: |
| 748 | if (mAutoFocusMoveCallback != null) { |
| 749 | mAutoFocusMoveCallback.onAutoFocusMoving(msg.arg1 == 0 ? false : true, mCamera); |
| 750 | } |
| 751 | return; |
| 752 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 753 | default: |
| 754 | Log.e(TAG, "Unknown message type " + msg.what); |
| 755 | return; |
| 756 | } |
| 757 | } |
| 758 | } |
| 759 | |
| 760 | private static void postEventFromNative(Object camera_ref, |
| 761 | int what, int arg1, int arg2, Object obj) |
| 762 | { |
| 763 | Camera c = (Camera)((WeakReference)camera_ref).get(); |
| 764 | if (c == null) |
| 765 | return; |
| 766 | |
| 767 | if (c.mEventHandler != null) { |
| 768 | Message m = c.mEventHandler.obtainMessage(what, arg1, arg2, obj); |
| 769 | c.mEventHandler.sendMessage(m); |
| 770 | } |
| 771 | } |
| 772 | |
| 773 | /** |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 774 | * Callback interface used to notify on completion of camera auto focus. |
| 775 | * |
Wu-cheng Li | 7478ea6 | 2009-09-16 18:52:55 +0800 | [diff] [blame] | 776 | * <p>Devices that do not support auto-focus will receive a "fake" |
| 777 | * callback to this interface. If your application needs auto-focus and |
Scott Main | df4578e | 2009-09-10 12:22:07 -0700 | [diff] [blame] | 778 | * should not be installed on devices <em>without</em> auto-focus, you must |
| 779 | * declare that your app uses the |
Wu-cheng Li | 7478ea6 | 2009-09-16 18:52:55 +0800 | [diff] [blame] | 780 | * {@code android.hardware.camera.autofocus} feature, in the |
Scott Main | df4578e | 2009-09-10 12:22:07 -0700 | [diff] [blame] | 781 | * <a href="{@docRoot}guide/topics/manifest/uses-feature-element.html"><uses-feature></a> |
| 782 | * manifest element.</p> |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 783 | * |
| 784 | * @see #autoFocus(AutoFocusCallback) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 785 | */ |
| 786 | public interface AutoFocusCallback |
| 787 | { |
| 788 | /** |
Brad Fitzpatrick | 69ea4e1 | 2011-01-05 11:13:40 -0800 | [diff] [blame] | 789 | * Called when the camera auto focus completes. If the camera |
| 790 | * does not support auto-focus and autoFocus is called, |
| 791 | * onAutoFocus will be called immediately with a fake value of |
| 792 | * <code>success</code> set to <code>true</code>. |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 793 | * |
Wu-cheng Li | b4f95be | 2011-09-22 11:43:28 +0800 | [diff] [blame] | 794 | * The auto-focus routine does not lock auto-exposure and auto-white |
| 795 | * balance after it completes. |
Eino-Ville Talvala | 83d3352 | 2011-05-13 10:25:00 -0700 | [diff] [blame] | 796 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 797 | * @param success true if focus was successful, false if otherwise |
| 798 | * @param camera the Camera service object |
Eino-Ville Talvala | 83d3352 | 2011-05-13 10:25:00 -0700 | [diff] [blame] | 799 | * @see android.hardware.Camera.Parameters#setAutoExposureLock(boolean) |
| 800 | * @see android.hardware.Camera.Parameters#setAutoWhiteBalanceLock(boolean) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 801 | */ |
| 802 | void onAutoFocus(boolean success, Camera camera); |
Wu-cheng Li | 53b3091 | 2011-10-12 19:43:51 +0800 | [diff] [blame] | 803 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 804 | |
| 805 | /** |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 806 | * Starts camera auto-focus and registers a callback function to run when |
| 807 | * the camera is focused. This method is only valid when preview is active |
| 808 | * (between {@link #startPreview()} and before {@link #stopPreview()}). |
| 809 | * |
| 810 | * <p>Callers should check |
| 811 | * {@link android.hardware.Camera.Parameters#getFocusMode()} to determine if |
| 812 | * this method should be called. If the camera does not support auto-focus, |
| 813 | * it is a no-op and {@link AutoFocusCallback#onAutoFocus(boolean, Camera)} |
Wu-cheng Li | 36322db | 2009-09-18 18:59:21 +0800 | [diff] [blame] | 814 | * callback will be called immediately. |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 815 | * |
Scott Main | da0a56df | 2009-09-10 18:08:37 -0700 | [diff] [blame] | 816 | * <p>If your application should not be installed |
Wu-cheng Li | 7478ea6 | 2009-09-16 18:52:55 +0800 | [diff] [blame] | 817 | * on devices without auto-focus, you must declare that your application |
| 818 | * uses auto-focus with the |
Scott Main | df4578e | 2009-09-10 12:22:07 -0700 | [diff] [blame] | 819 | * <a href="{@docRoot}guide/topics/manifest/uses-feature-element.html"><uses-feature></a> |
| 820 | * manifest element.</p> |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 821 | * |
Wu-cheng Li | 068ef42 | 2009-09-27 13:19:36 -0700 | [diff] [blame] | 822 | * <p>If the current flash mode is not |
| 823 | * {@link android.hardware.Camera.Parameters#FLASH_MODE_OFF}, flash may be |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 824 | * fired during auto-focus, depending on the driver and camera hardware.<p> |
Wu-cheng Li | 7478ea6 | 2009-09-16 18:52:55 +0800 | [diff] [blame] | 825 | * |
Wu-cheng Li | 53b3091 | 2011-10-12 19:43:51 +0800 | [diff] [blame] | 826 | * <p>Auto-exposure lock {@link android.hardware.Camera.Parameters#getAutoExposureLock()} |
Wu-cheng Li | b4f95be | 2011-09-22 11:43:28 +0800 | [diff] [blame] | 827 | * and auto-white balance locks {@link android.hardware.Camera.Parameters#getAutoWhiteBalanceLock()} |
| 828 | * do not change during and after autofocus. But auto-focus routine may stop |
| 829 | * auto-exposure and auto-white balance transiently during focusing. |
Eino-Ville Talvala | 83d3352 | 2011-05-13 10:25:00 -0700 | [diff] [blame] | 830 | * |
Wu-cheng Li | 53b3091 | 2011-10-12 19:43:51 +0800 | [diff] [blame] | 831 | * <p>Stopping preview with {@link #stopPreview()}, or triggering still |
| 832 | * image capture with {@link #takePicture(Camera.ShutterCallback, |
| 833 | * Camera.PictureCallback, Camera.PictureCallback)}, will not change the |
| 834 | * the focus position. Applications must call cancelAutoFocus to reset the |
| 835 | * focus.</p> |
| 836 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 837 | * @param cb the callback to run |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 838 | * @see #cancelAutoFocus() |
Eino-Ville Talvala | 83d3352 | 2011-05-13 10:25:00 -0700 | [diff] [blame] | 839 | * @see android.hardware.Camera.Parameters#setAutoExposureLock(boolean) |
| 840 | * @see android.hardware.Camera.Parameters#setAutoWhiteBalanceLock(boolean) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 841 | */ |
| 842 | public final void autoFocus(AutoFocusCallback cb) |
| 843 | { |
| 844 | mAutoFocusCallback = cb; |
| 845 | native_autoFocus(); |
| 846 | } |
| 847 | private native final void native_autoFocus(); |
| 848 | |
| 849 | /** |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 850 | * Cancels any auto-focus function in progress. |
| 851 | * Whether or not auto-focus is currently in progress, |
| 852 | * this function will return the focus position to the default. |
Chih-Chung Chang | 244f8c2 | 2009-09-15 14:51:56 +0800 | [diff] [blame] | 853 | * If the camera does not support auto-focus, this is a no-op. |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 854 | * |
| 855 | * @see #autoFocus(Camera.AutoFocusCallback) |
Chih-Chung Chang | 244f8c2 | 2009-09-15 14:51:56 +0800 | [diff] [blame] | 856 | */ |
| 857 | public final void cancelAutoFocus() |
| 858 | { |
| 859 | mAutoFocusCallback = null; |
| 860 | native_cancelAutoFocus(); |
| 861 | } |
| 862 | private native final void native_cancelAutoFocus(); |
| 863 | |
| 864 | /** |
Wu-cheng Li | 9d062cf | 2011-11-14 20:30:14 +0800 | [diff] [blame] | 865 | * Callback interface used to notify on auto focus start and stop. |
| 866 | * |
| 867 | * <p>This is useful for continuous autofocus -- {@link Parameters#FOCUS_MODE_CONTINUOUS_VIDEO} |
| 868 | * and {@link Parameters#FOCUS_MODE_CONTINUOUS_PICTURE}. Applications can |
| 869 | * show autofocus animation.</p> |
| 870 | * |
| 871 | * @hide |
| 872 | */ |
| 873 | public interface AutoFocusMoveCallback |
| 874 | { |
| 875 | /** |
| 876 | * Called when the camera auto focus starts or stops. |
| 877 | * |
| 878 | * @param start true if focus starts to move, false if focus stops to move |
| 879 | * @param camera the Camera service object |
| 880 | */ |
| 881 | void onAutoFocusMoving(boolean start, Camera camera); |
| 882 | } |
| 883 | |
| 884 | /** |
| 885 | * Sets camera auto-focus move callback. |
| 886 | * |
| 887 | * @param cb the callback to run |
| 888 | * @hide |
| 889 | */ |
| 890 | public void setAutoFocusMoveCallback(AutoFocusMoveCallback cb) { |
| 891 | mAutoFocusMoveCallback = cb; |
| 892 | enableFocusMoveCallback((mAutoFocusMoveCallback != null) ? 1 : 0); |
| 893 | } |
| 894 | |
| 895 | private native void enableFocusMoveCallback(int enable); |
| 896 | |
| 897 | /** |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 898 | * Callback interface used to signal the moment of actual image capture. |
| 899 | * |
| 900 | * @see #takePicture(ShutterCallback, PictureCallback, PictureCallback, PictureCallback) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 901 | */ |
| 902 | public interface ShutterCallback |
| 903 | { |
| 904 | /** |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 905 | * Called as near as possible to the moment when a photo is captured |
| 906 | * from the sensor. This is a good opportunity to play a shutter sound |
| 907 | * or give other feedback of camera operation. This may be some time |
| 908 | * after the photo was triggered, but some time before the actual data |
| 909 | * is available. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 910 | */ |
| 911 | void onShutter(); |
| 912 | } |
| 913 | |
| 914 | /** |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 915 | * Callback interface used to supply image data from a photo capture. |
| 916 | * |
| 917 | * @see #takePicture(ShutterCallback, PictureCallback, PictureCallback, PictureCallback) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 918 | */ |
| 919 | public interface PictureCallback { |
| 920 | /** |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 921 | * Called when image data is available after a picture is taken. |
| 922 | * The format of the data depends on the context of the callback |
| 923 | * and {@link Camera.Parameters} settings. |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 924 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 925 | * @param data a byte array of the picture data |
| 926 | * @param camera the Camera service object |
| 927 | */ |
| 928 | void onPictureTaken(byte[] data, Camera camera); |
| 929 | }; |
| 930 | |
| 931 | /** |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 932 | * Equivalent to takePicture(shutter, raw, null, jpeg). |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 933 | * |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 934 | * @see #takePicture(ShutterCallback, PictureCallback, PictureCallback, PictureCallback) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 935 | */ |
| 936 | public final void takePicture(ShutterCallback shutter, PictureCallback raw, |
| 937 | PictureCallback jpeg) { |
Dave Sparks | e8b26e1 | 2009-07-14 10:35:40 -0700 | [diff] [blame] | 938 | takePicture(shutter, raw, null, jpeg); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 939 | } |
James Dong | e00cab7 | 2011-02-17 16:38:06 -0800 | [diff] [blame] | 940 | private native final void native_takePicture(int msgType); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 941 | |
Dave Sparks | e8b26e1 | 2009-07-14 10:35:40 -0700 | [diff] [blame] | 942 | /** |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 943 | * Triggers an asynchronous image capture. The camera service will initiate |
| 944 | * a series of callbacks to the application as the image capture progresses. |
| 945 | * The shutter callback occurs after the image is captured. This can be used |
| 946 | * to trigger a sound to let the user know that image has been captured. The |
| 947 | * raw callback occurs when the raw image data is available (NOTE: the data |
James Dong | e00cab7 | 2011-02-17 16:38:06 -0800 | [diff] [blame] | 948 | * will be null if there is no raw image callback buffer available or the |
| 949 | * raw image callback buffer is not large enough to hold the raw image). |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 950 | * The postview callback occurs when a scaled, fully processed postview |
| 951 | * image is available (NOTE: not all hardware supports this). The jpeg |
| 952 | * callback occurs when the compressed image is available. If the |
| 953 | * application does not need a particular callback, a null can be passed |
| 954 | * instead of a callback method. |
Dave Sparks | e8b26e1 | 2009-07-14 10:35:40 -0700 | [diff] [blame] | 955 | * |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 956 | * <p>This method is only valid when preview is active (after |
| 957 | * {@link #startPreview()}). Preview will be stopped after the image is |
| 958 | * taken; callers must call {@link #startPreview()} again if they want to |
Wu-cheng Li | 42419ce | 2011-06-01 17:22:24 +0800 | [diff] [blame] | 959 | * re-start preview or take more pictures. This should not be called between |
| 960 | * {@link android.media.MediaRecorder#start()} and |
| 961 | * {@link android.media.MediaRecorder#stop()}. |
Wu-cheng Li | 40057ce | 2009-12-02 18:57:29 +0800 | [diff] [blame] | 962 | * |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 963 | * <p>After calling this method, you must not call {@link #startPreview()} |
| 964 | * or take another picture until the JPEG callback has returned. |
| 965 | * |
| 966 | * @param shutter the callback for image capture moment, or null |
| 967 | * @param raw the callback for raw (uncompressed) image data, or null |
Dave Sparks | e8b26e1 | 2009-07-14 10:35:40 -0700 | [diff] [blame] | 968 | * @param postview callback with postview image data, may be null |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 969 | * @param jpeg the callback for JPEG image data, or null |
Dave Sparks | e8b26e1 | 2009-07-14 10:35:40 -0700 | [diff] [blame] | 970 | */ |
| 971 | public final void takePicture(ShutterCallback shutter, PictureCallback raw, |
| 972 | PictureCallback postview, PictureCallback jpeg) { |
| 973 | mShutterCallback = shutter; |
| 974 | mRawImageCallback = raw; |
| 975 | mPostviewCallback = postview; |
| 976 | mJpegCallback = jpeg; |
James Dong | e00cab7 | 2011-02-17 16:38:06 -0800 | [diff] [blame] | 977 | |
| 978 | // If callback is not set, do not send me callbacks. |
| 979 | int msgType = 0; |
| 980 | if (mShutterCallback != null) { |
| 981 | msgType |= CAMERA_MSG_SHUTTER; |
| 982 | } |
| 983 | if (mRawImageCallback != null) { |
| 984 | msgType |= CAMERA_MSG_RAW_IMAGE; |
| 985 | } |
| 986 | if (mPostviewCallback != null) { |
| 987 | msgType |= CAMERA_MSG_POSTVIEW_FRAME; |
| 988 | } |
| 989 | if (mJpegCallback != null) { |
| 990 | msgType |= CAMERA_MSG_COMPRESSED_IMAGE; |
| 991 | } |
| 992 | |
| 993 | native_takePicture(msgType); |
Dave Sparks | e8b26e1 | 2009-07-14 10:35:40 -0700 | [diff] [blame] | 994 | } |
| 995 | |
| 996 | /** |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 997 | * Zooms to the requested value smoothly. The driver will notify {@link |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 998 | * OnZoomChangeListener} of the zoom value and whether zoom is stopped at |
| 999 | * the time. For example, suppose the current zoom is 0 and startSmoothZoom |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 1000 | * is called with value 3. The |
| 1001 | * {@link Camera.OnZoomChangeListener#onZoomChange(int, boolean, Camera)} |
| 1002 | * method will be called three times with zoom values 1, 2, and 3. |
| 1003 | * Applications can call {@link #stopSmoothZoom} to stop the zoom earlier. |
| 1004 | * Applications should not call startSmoothZoom again or change the zoom |
| 1005 | * value before zoom stops. If the supplied zoom value equals to the current |
| 1006 | * zoom value, no zoom callback will be generated. This method is supported |
| 1007 | * if {@link android.hardware.Camera.Parameters#isSmoothZoomSupported} |
| 1008 | * returns true. |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 1009 | * |
| 1010 | * @param value zoom value. The valid range is 0 to {@link |
| 1011 | * android.hardware.Camera.Parameters#getMaxZoom}. |
Wu-cheng Li | 0ca2519 | 2010-03-29 16:21:12 +0800 | [diff] [blame] | 1012 | * @throws IllegalArgumentException if the zoom value is invalid. |
| 1013 | * @throws RuntimeException if the method fails. |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 1014 | * @see #setZoomChangeListener(OnZoomChangeListener) |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 1015 | */ |
| 1016 | public native final void startSmoothZoom(int value); |
| 1017 | |
| 1018 | /** |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 1019 | * Stops the smooth zoom. Applications should wait for the {@link |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 1020 | * OnZoomChangeListener} to know when the zoom is actually stopped. This |
| 1021 | * method is supported if {@link |
Wu-cheng Li | 8cbb8f5 | 2010-02-28 23:19:55 -0800 | [diff] [blame] | 1022 | * android.hardware.Camera.Parameters#isSmoothZoomSupported} is true. |
Wu-cheng Li | 0ca2519 | 2010-03-29 16:21:12 +0800 | [diff] [blame] | 1023 | * |
| 1024 | * @throws RuntimeException if the method fails. |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 1025 | */ |
| 1026 | public native final void stopSmoothZoom(); |
| 1027 | |
| 1028 | /** |
Wu-cheng Li | 2fe6fca | 2010-10-15 14:42:23 +0800 | [diff] [blame] | 1029 | * Set the clockwise rotation of preview display in degrees. This affects |
| 1030 | * the preview frames and the picture displayed after snapshot. This method |
| 1031 | * is useful for portrait mode applications. Note that preview display of |
Wu-cheng Li | b982fb4 | 2010-10-19 17:19:09 +0800 | [diff] [blame] | 1032 | * front-facing cameras is flipped horizontally before the rotation, that |
| 1033 | * is, the image is reflected along the central vertical axis of the camera |
| 1034 | * sensor. So the users can see themselves as looking into a mirror. |
Chih-Chung Chang | d1d7706 | 2010-01-22 17:49:48 -0800 | [diff] [blame] | 1035 | * |
Brad Fitzpatrick | 69ea4e1 | 2011-01-05 11:13:40 -0800 | [diff] [blame] | 1036 | * <p>This does not affect the order of byte array passed in {@link |
Wu-cheng Li | 2fe6fca | 2010-10-15 14:42:23 +0800 | [diff] [blame] | 1037 | * PreviewCallback#onPreviewFrame}, JPEG pictures, or recorded videos. This |
| 1038 | * method is not allowed to be called during preview. |
Chih-Chung Chang | d1d7706 | 2010-01-22 17:49:48 -0800 | [diff] [blame] | 1039 | * |
Brad Fitzpatrick | 69ea4e1 | 2011-01-05 11:13:40 -0800 | [diff] [blame] | 1040 | * <p>If you want to make the camera image show in the same orientation as |
| 1041 | * the display, you can use the following code. |
Chih-Chung Chang | b8bb78f | 2010-06-10 13:32:16 +0800 | [diff] [blame] | 1042 | * <pre> |
Chih-Chung Chang | 724c522 | 2010-06-14 18:57:15 +0800 | [diff] [blame] | 1043 | * public static void setCameraDisplayOrientation(Activity activity, |
| 1044 | * int cameraId, android.hardware.Camera camera) { |
| 1045 | * android.hardware.Camera.CameraInfo info = |
| 1046 | * new android.hardware.Camera.CameraInfo(); |
| 1047 | * android.hardware.Camera.getCameraInfo(cameraId, info); |
| 1048 | * int rotation = activity.getWindowManager().getDefaultDisplay() |
| 1049 | * .getRotation(); |
| 1050 | * int degrees = 0; |
| 1051 | * switch (rotation) { |
| 1052 | * case Surface.ROTATION_0: degrees = 0; break; |
| 1053 | * case Surface.ROTATION_90: degrees = 90; break; |
| 1054 | * case Surface.ROTATION_180: degrees = 180; break; |
| 1055 | * case Surface.ROTATION_270: degrees = 270; break; |
| 1056 | * } |
Chih-Chung Chang | b8bb78f | 2010-06-10 13:32:16 +0800 | [diff] [blame] | 1057 | * |
Wu-cheng Li | 2fe6fca | 2010-10-15 14:42:23 +0800 | [diff] [blame] | 1058 | * int result; |
| 1059 | * if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) { |
| 1060 | * result = (info.orientation + degrees) % 360; |
| 1061 | * result = (360 - result) % 360; // compensate the mirror |
| 1062 | * } else { // back-facing |
| 1063 | * result = (info.orientation - degrees + 360) % 360; |
| 1064 | * } |
Chih-Chung Chang | 724c522 | 2010-06-14 18:57:15 +0800 | [diff] [blame] | 1065 | * camera.setDisplayOrientation(result); |
| 1066 | * } |
Chih-Chung Chang | b8bb78f | 2010-06-10 13:32:16 +0800 | [diff] [blame] | 1067 | * </pre> |
Wu-cheng Li | d303362 | 2011-10-07 13:13:54 +0800 | [diff] [blame] | 1068 | * |
| 1069 | * <p>Starting from API level 14, this method can be called when preview is |
| 1070 | * active. |
| 1071 | * |
Chih-Chung Chang | d1d7706 | 2010-01-22 17:49:48 -0800 | [diff] [blame] | 1072 | * @param degrees the angle that the picture will be rotated clockwise. |
Chih-Chung Chang | e7bd22a | 2010-01-27 10:24:42 -0800 | [diff] [blame] | 1073 | * Valid values are 0, 90, 180, and 270. The starting |
| 1074 | * position is 0 (landscape). |
Wu-cheng Li | 2fe6fca | 2010-10-15 14:42:23 +0800 | [diff] [blame] | 1075 | * @see #setPreviewDisplay(SurfaceHolder) |
Chih-Chung Chang | d1d7706 | 2010-01-22 17:49:48 -0800 | [diff] [blame] | 1076 | */ |
| 1077 | public native final void setDisplayOrientation(int degrees); |
| 1078 | |
| 1079 | /** |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 1080 | * Callback interface for zoom changes during a smooth zoom operation. |
| 1081 | * |
| 1082 | * @see #setZoomChangeListener(OnZoomChangeListener) |
| 1083 | * @see #startSmoothZoom(int) |
Dave Sparks | e8b26e1 | 2009-07-14 10:35:40 -0700 | [diff] [blame] | 1084 | */ |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 1085 | public interface OnZoomChangeListener |
Dave Sparks | e8b26e1 | 2009-07-14 10:35:40 -0700 | [diff] [blame] | 1086 | { |
| 1087 | /** |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 1088 | * Called when the zoom value has changed during a smooth zoom. |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 1089 | * |
| 1090 | * @param zoomValue the current zoom value. In smooth zoom mode, camera |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 1091 | * calls this for every new zoom value. |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 1092 | * @param stopped whether smooth zoom is stopped. If the value is true, |
| 1093 | * this is the last zoom update for the application. |
Dave Sparks | e8b26e1 | 2009-07-14 10:35:40 -0700 | [diff] [blame] | 1094 | * @param camera the Camera service object |
| 1095 | */ |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 1096 | void onZoomChange(int zoomValue, boolean stopped, Camera camera); |
Dave Sparks | e8b26e1 | 2009-07-14 10:35:40 -0700 | [diff] [blame] | 1097 | }; |
| 1098 | |
| 1099 | /** |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 1100 | * Registers a listener to be notified when the zoom value is updated by the |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 1101 | * camera driver during smooth zoom. |
Wu-cheng Li | 8cbb8f5 | 2010-02-28 23:19:55 -0800 | [diff] [blame] | 1102 | * |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 1103 | * @param listener the listener to notify |
Wu-cheng Li | 8cbb8f5 | 2010-02-28 23:19:55 -0800 | [diff] [blame] | 1104 | * @see #startSmoothZoom(int) |
Dave Sparks | e8b26e1 | 2009-07-14 10:35:40 -0700 | [diff] [blame] | 1105 | */ |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 1106 | public final void setZoomChangeListener(OnZoomChangeListener listener) |
Dave Sparks | e8b26e1 | 2009-07-14 10:35:40 -0700 | [diff] [blame] | 1107 | { |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 1108 | mZoomListener = listener; |
Dave Sparks | e8b26e1 | 2009-07-14 10:35:40 -0700 | [diff] [blame] | 1109 | } |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1110 | |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 1111 | /** |
| 1112 | * Callback interface for face detected in the preview frame. |
| 1113 | * |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 1114 | */ |
| 1115 | public interface FaceDetectionListener |
| 1116 | { |
| 1117 | /** |
| 1118 | * Notify the listener of the detected faces in the preview frame. |
| 1119 | * |
Wu-cheng Li | 53b3091 | 2011-10-12 19:43:51 +0800 | [diff] [blame] | 1120 | * @param faces The detected faces in a list |
Joe Fernandez | 464cb21 | 2011-10-04 16:56:47 -0700 | [diff] [blame] | 1121 | * @param camera The {@link Camera} service object |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 1122 | */ |
Wu-cheng Li | f0d6a48 | 2011-07-28 05:30:59 +0800 | [diff] [blame] | 1123 | void onFaceDetection(Face[] faces, Camera camera); |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 1124 | } |
| 1125 | |
| 1126 | /** |
Wu-cheng Li | c0c683b | 2011-08-04 00:11:00 +0800 | [diff] [blame] | 1127 | * Registers a listener to be notified about the faces detected in the |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 1128 | * preview frame. |
| 1129 | * |
| 1130 | * @param listener the listener to notify |
Wu-cheng Li | c0c683b | 2011-08-04 00:11:00 +0800 | [diff] [blame] | 1131 | * @see #startFaceDetection() |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 1132 | */ |
| 1133 | public final void setFaceDetectionListener(FaceDetectionListener listener) |
| 1134 | { |
| 1135 | mFaceListener = listener; |
| 1136 | } |
| 1137 | |
| 1138 | /** |
Wu-cheng Li | c0c683b | 2011-08-04 00:11:00 +0800 | [diff] [blame] | 1139 | * Starts the face detection. This should be called after preview is started. |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 1140 | * The camera will notify {@link FaceDetectionListener} of the detected |
| 1141 | * faces in the preview frame. The detected faces may be the same as the |
| 1142 | * previous ones. Applications should call {@link #stopFaceDetection} to |
| 1143 | * stop the face detection. This method is supported if {@link |
Wu-cheng Li | c0c683b | 2011-08-04 00:11:00 +0800 | [diff] [blame] | 1144 | * Parameters#getMaxNumDetectedFaces()} returns a number larger than 0. |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 1145 | * If the face detection has started, apps should not call this again. |
| 1146 | * |
Wu-cheng Li | 8c13670 | 2011-08-12 20:25:00 +0800 | [diff] [blame] | 1147 | * <p>When the face detection is running, {@link Parameters#setWhiteBalance(String)}, |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 1148 | * {@link Parameters#setFocusAreas(List)}, and {@link Parameters#setMeteringAreas(List)} |
Wu-cheng Li | 8c13670 | 2011-08-12 20:25:00 +0800 | [diff] [blame] | 1149 | * have no effect. The camera uses the detected faces to do auto-white balance, |
| 1150 | * auto exposure, and autofocus. |
| 1151 | * |
| 1152 | * <p>If the apps call {@link #autoFocus(AutoFocusCallback)}, the camera |
| 1153 | * will stop sending face callbacks. The last face callback indicates the |
| 1154 | * areas used to do autofocus. After focus completes, face detection will |
| 1155 | * resume sending face callbacks. If the apps call {@link |
| 1156 | * #cancelAutoFocus()}, the face callbacks will also resume.</p> |
| 1157 | * |
| 1158 | * <p>After calling {@link #takePicture(Camera.ShutterCallback, Camera.PictureCallback, |
| 1159 | * Camera.PictureCallback)} or {@link #stopPreview()}, and then resuming |
| 1160 | * preview with {@link #startPreview()}, the apps should call this method |
| 1161 | * again to resume face detection.</p> |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 1162 | * |
Wu-cheng Li | c0c683b | 2011-08-04 00:11:00 +0800 | [diff] [blame] | 1163 | * @throws IllegalArgumentException if the face detection is unsupported. |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 1164 | * @throws RuntimeException if the method fails or the face detection is |
| 1165 | * already running. |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 1166 | * @see FaceDetectionListener |
| 1167 | * @see #stopFaceDetection() |
Wu-cheng Li | c0c683b | 2011-08-04 00:11:00 +0800 | [diff] [blame] | 1168 | * @see Parameters#getMaxNumDetectedFaces() |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 1169 | */ |
Wu-cheng Li | c0c683b | 2011-08-04 00:11:00 +0800 | [diff] [blame] | 1170 | public final void startFaceDetection() { |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 1171 | if (mFaceDetectionRunning) { |
| 1172 | throw new RuntimeException("Face detection is already running"); |
| 1173 | } |
Wu-cheng Li | c0c683b | 2011-08-04 00:11:00 +0800 | [diff] [blame] | 1174 | _startFaceDetection(CAMERA_FACE_DETECTION_HW); |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 1175 | mFaceDetectionRunning = true; |
| 1176 | } |
| 1177 | |
| 1178 | /** |
Wu-cheng Li | c0c683b | 2011-08-04 00:11:00 +0800 | [diff] [blame] | 1179 | * Stops the face detection. |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 1180 | * |
Joe Fernandez | 464cb21 | 2011-10-04 16:56:47 -0700 | [diff] [blame] | 1181 | * @see #startFaceDetection() |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 1182 | */ |
| 1183 | public final void stopFaceDetection() { |
| 1184 | _stopFaceDetection(); |
| 1185 | mFaceDetectionRunning = false; |
| 1186 | } |
| 1187 | |
| 1188 | private native final void _startFaceDetection(int type); |
| 1189 | private native final void _stopFaceDetection(); |
| 1190 | |
| 1191 | /** |
Joe Fernandez | 464cb21 | 2011-10-04 16:56:47 -0700 | [diff] [blame] | 1192 | * Information about a face identified through camera face detection. |
Wu-cheng Li | 53b3091 | 2011-10-12 19:43:51 +0800 | [diff] [blame] | 1193 | * |
Joe Fernandez | 464cb21 | 2011-10-04 16:56:47 -0700 | [diff] [blame] | 1194 | * <p>When face detection is used with a camera, the {@link FaceDetectionListener} returns a |
| 1195 | * list of face objects for use in focusing and metering.</p> |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 1196 | * |
Joe Fernandez | 464cb21 | 2011-10-04 16:56:47 -0700 | [diff] [blame] | 1197 | * @see FaceDetectionListener |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 1198 | */ |
Wu-cheng Li | f0d6a48 | 2011-07-28 05:30:59 +0800 | [diff] [blame] | 1199 | public static class Face { |
Wu-cheng Li | c0c683b | 2011-08-04 00:11:00 +0800 | [diff] [blame] | 1200 | /** |
| 1201 | * Create an empty face. |
| 1202 | */ |
Wu-cheng Li | bb1e275 | 2011-07-30 05:00:37 +0800 | [diff] [blame] | 1203 | public Face() { |
| 1204 | } |
| 1205 | |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 1206 | /** |
| 1207 | * Bounds of the face. (-1000, -1000) represents the top-left of the |
| 1208 | * camera field of view, and (1000, 1000) represents the bottom-right of |
Wu-cheng Li | c0c683b | 2011-08-04 00:11:00 +0800 | [diff] [blame] | 1209 | * the field of view. For example, suppose the size of the viewfinder UI |
| 1210 | * is 800x480. The rect passed from the driver is (-1000, -1000, 0, 0). |
Wu-cheng Li | 8c13670 | 2011-08-12 20:25:00 +0800 | [diff] [blame] | 1211 | * The corresponding viewfinder rect should be (0, 0, 400, 240). It is |
| 1212 | * guaranteed left < right and top < bottom. The coordinates can be |
| 1213 | * smaller than -1000 or bigger than 1000. But at least one vertex will |
| 1214 | * be within (-1000, -1000) and (1000, 1000). |
Wu-cheng Li | f0d6a48 | 2011-07-28 05:30:59 +0800 | [diff] [blame] | 1215 | * |
| 1216 | * <p>The direction is relative to the sensor orientation, that is, what |
| 1217 | * the sensor sees. The direction is not affected by the rotation or |
Wu-cheng Li | 8c13670 | 2011-08-12 20:25:00 +0800 | [diff] [blame] | 1218 | * mirroring of {@link #setDisplayOrientation(int)}. The face bounding |
| 1219 | * rectangle does not provide any information about face orientation.</p> |
| 1220 | * |
| 1221 | * <p>Here is the matrix to convert driver coordinates to View coordinates |
| 1222 | * in pixels.</p> |
| 1223 | * <pre> |
| 1224 | * Matrix matrix = new Matrix(); |
| 1225 | * CameraInfo info = CameraHolder.instance().getCameraInfo()[cameraId]; |
| 1226 | * // Need mirror for front camera. |
| 1227 | * boolean mirror = (info.facing == CameraInfo.CAMERA_FACING_FRONT); |
| 1228 | * matrix.setScale(mirror ? -1 : 1, 1); |
| 1229 | * // This is the value for android.hardware.Camera.setDisplayOrientation. |
| 1230 | * matrix.postRotate(displayOrientation); |
| 1231 | * // Camera driver coordinates range from (-1000, -1000) to (1000, 1000). |
| 1232 | * // UI coordinates range from (0, 0) to (width, height). |
| 1233 | * matrix.postScale(view.getWidth() / 2000f, view.getHeight() / 2000f); |
| 1234 | * matrix.postTranslate(view.getWidth() / 2f, view.getHeight() / 2f); |
| 1235 | * </pre> |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 1236 | * |
Joe Fernandez | 464cb21 | 2011-10-04 16:56:47 -0700 | [diff] [blame] | 1237 | * @see #startFaceDetection() |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 1238 | */ |
Wu-cheng Li | bb1e275 | 2011-07-30 05:00:37 +0800 | [diff] [blame] | 1239 | public Rect rect; |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 1240 | |
| 1241 | /** |
Joe Fernandez | 464cb21 | 2011-10-04 16:56:47 -0700 | [diff] [blame] | 1242 | * The confidence level for the detection of the face. The range is 1 to 100. 100 is the |
Wu-cheng Li | c0c683b | 2011-08-04 00:11:00 +0800 | [diff] [blame] | 1243 | * highest confidence. |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 1244 | * |
Joe Fernandez | 464cb21 | 2011-10-04 16:56:47 -0700 | [diff] [blame] | 1245 | * @see #startFaceDetection() |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 1246 | */ |
Wu-cheng Li | bb1e275 | 2011-07-30 05:00:37 +0800 | [diff] [blame] | 1247 | public int score; |
Wei Hua | d52b308 | 2011-08-19 13:01:51 -0700 | [diff] [blame] | 1248 | |
| 1249 | /** |
| 1250 | * An unique id per face while the face is visible to the tracker. If |
| 1251 | * the face leaves the field-of-view and comes back, it will get a new |
| 1252 | * id. This is an optional field, may not be supported on all devices. |
| 1253 | * If not supported, id will always be set to -1. The optional fields |
| 1254 | * are supported as a set. Either they are all valid, or none of them |
| 1255 | * are. |
| 1256 | */ |
| 1257 | public int id = -1; |
| 1258 | |
| 1259 | /** |
| 1260 | * The coordinates of the center of the left eye. The coordinates are in |
| 1261 | * the same space as the ones for {@link #rect}. This is an optional |
| 1262 | * field, may not be supported on all devices. If not supported, the |
| 1263 | * value will always be set to null. The optional fields are supported |
| 1264 | * as a set. Either they are all valid, or none of them are. |
| 1265 | */ |
| 1266 | public Point leftEye = null; |
| 1267 | |
| 1268 | /** |
| 1269 | * The coordinates of the center of the right eye. The coordinates are |
| 1270 | * in the same space as the ones for {@link #rect}.This is an optional |
| 1271 | * field, may not be supported on all devices. If not supported, the |
| 1272 | * value will always be set to null. The optional fields are supported |
| 1273 | * as a set. Either they are all valid, or none of them are. |
| 1274 | */ |
| 1275 | public Point rightEye = null; |
| 1276 | |
| 1277 | /** |
| 1278 | * The coordinates of the center of the mouth. The coordinates are in |
| 1279 | * the same space as the ones for {@link #rect}. This is an optional |
| 1280 | * field, may not be supported on all devices. If not supported, the |
| 1281 | * value will always be set to null. The optional fields are supported |
| 1282 | * as a set. Either they are all valid, or none of them are. |
| 1283 | */ |
| 1284 | public Point mouth = null; |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 1285 | } |
| 1286 | |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 1287 | // Error codes match the enum in include/ui/Camera.h |
| 1288 | |
| 1289 | /** |
| 1290 | * Unspecified camera error. |
| 1291 | * @see Camera.ErrorCallback |
| 1292 | */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1293 | public static final int CAMERA_ERROR_UNKNOWN = 1; |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 1294 | |
| 1295 | /** |
| 1296 | * Media server died. In this case, the application must release the |
| 1297 | * Camera object and instantiate a new one. |
| 1298 | * @see Camera.ErrorCallback |
| 1299 | */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1300 | public static final int CAMERA_ERROR_SERVER_DIED = 100; |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1301 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1302 | /** |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 1303 | * Callback interface for camera error notification. |
| 1304 | * |
| 1305 | * @see #setErrorCallback(ErrorCallback) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1306 | */ |
| 1307 | public interface ErrorCallback |
| 1308 | { |
| 1309 | /** |
| 1310 | * Callback for camera errors. |
| 1311 | * @param error error code: |
| 1312 | * <ul> |
| 1313 | * <li>{@link #CAMERA_ERROR_UNKNOWN} |
| 1314 | * <li>{@link #CAMERA_ERROR_SERVER_DIED} |
| 1315 | * </ul> |
| 1316 | * @param camera the Camera service object |
| 1317 | */ |
| 1318 | void onError(int error, Camera camera); |
| 1319 | }; |
| 1320 | |
| 1321 | /** |
| 1322 | * Registers a callback to be invoked when an error occurs. |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 1323 | * @param cb The callback to run |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1324 | */ |
| 1325 | public final void setErrorCallback(ErrorCallback cb) |
| 1326 | { |
| 1327 | mErrorCallback = cb; |
| 1328 | } |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1329 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1330 | private native final void native_setParameters(String params); |
| 1331 | private native final String native_getParameters(); |
| 1332 | |
| 1333 | /** |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 1334 | * Changes the settings for this Camera service. |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1335 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1336 | * @param params the Parameters to use for this Camera service |
Wu-cheng Li | 99a3f3e | 2010-11-19 15:56:16 +0800 | [diff] [blame] | 1337 | * @throws RuntimeException if any parameter is invalid or not supported. |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 1338 | * @see #getParameters() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1339 | */ |
| 1340 | public void setParameters(Parameters params) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1341 | native_setParameters(params.flatten()); |
| 1342 | } |
| 1343 | |
| 1344 | /** |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 1345 | * Returns the current settings for this Camera service. |
| 1346 | * If modifications are made to the returned Parameters, they must be passed |
| 1347 | * to {@link #setParameters(Camera.Parameters)} to take effect. |
| 1348 | * |
| 1349 | * @see #setParameters(Camera.Parameters) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1350 | */ |
| 1351 | public Parameters getParameters() { |
| 1352 | Parameters p = new Parameters(); |
| 1353 | String s = native_getParameters(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1354 | p.unflatten(s); |
| 1355 | return p; |
| 1356 | } |
| 1357 | |
| 1358 | /** |
Wu-cheng Li | 1c04a33 | 2011-11-22 18:21:18 +0800 | [diff] [blame] | 1359 | * Returns an empty {@link Parameters} for testing purpose. |
| 1360 | * |
Ken Wakasa | f76a50c | 2012-03-09 19:56:35 +0900 | [diff] [blame] | 1361 | * @return a Parameter object. |
Wu-cheng Li | 1c04a33 | 2011-11-22 18:21:18 +0800 | [diff] [blame] | 1362 | * |
| 1363 | * @hide |
| 1364 | */ |
| 1365 | public static Parameters getEmptyParameters() { |
| 1366 | Camera camera = new Camera(); |
| 1367 | return camera.new Parameters(); |
| 1368 | } |
| 1369 | |
| 1370 | /** |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 1371 | * Image size (width and height dimensions). |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1372 | */ |
| 1373 | public class Size { |
| 1374 | /** |
| 1375 | * Sets the dimensions for pictures. |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1376 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1377 | * @param w the photo width (pixels) |
| 1378 | * @param h the photo height (pixels) |
| 1379 | */ |
| 1380 | public Size(int w, int h) { |
| 1381 | width = w; |
| 1382 | height = h; |
| 1383 | } |
Wu-cheng Li | 4c4300c | 2010-01-23 15:45:39 +0800 | [diff] [blame] | 1384 | /** |
| 1385 | * Compares {@code obj} to this size. |
| 1386 | * |
| 1387 | * @param obj the object to compare this size with. |
| 1388 | * @return {@code true} if the width and height of {@code obj} is the |
| 1389 | * same as those of this size. {@code false} otherwise. |
| 1390 | */ |
| 1391 | @Override |
| 1392 | public boolean equals(Object obj) { |
| 1393 | if (!(obj instanceof Size)) { |
| 1394 | return false; |
| 1395 | } |
| 1396 | Size s = (Size) obj; |
| 1397 | return width == s.width && height == s.height; |
| 1398 | } |
| 1399 | @Override |
| 1400 | public int hashCode() { |
| 1401 | return width * 32713 + height; |
| 1402 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1403 | /** width of the picture */ |
| 1404 | public int width; |
| 1405 | /** height of the picture */ |
| 1406 | public int height; |
| 1407 | }; |
| 1408 | |
| 1409 | /** |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 1410 | * <p>The Area class is used for choosing specific metering and focus areas for |
| 1411 | * the camera to use when calculating auto-exposure, auto-white balance, and |
| 1412 | * auto-focus.</p> |
| 1413 | * |
| 1414 | * <p>To find out how many simultaneous areas a given camera supports, use |
| 1415 | * {@link Parameters#getMaxNumMeteringAreas()} and |
| 1416 | * {@link Parameters#getMaxNumFocusAreas()}. If metering or focusing area |
| 1417 | * selection is unsupported, these methods will return 0.</p> |
| 1418 | * |
| 1419 | * <p>Each Area consists of a rectangle specifying its bounds, and a weight |
| 1420 | * that determines its importance. The bounds are relative to the camera's |
| 1421 | * current field of view. The coordinates are mapped so that (-1000, -1000) |
| 1422 | * is always the top-left corner of the current field of view, and (1000, |
| 1423 | * 1000) is always the bottom-right corner of the current field of |
| 1424 | * view. Setting Areas with bounds outside that range is not allowed. Areas |
| 1425 | * with zero or negative width or height are not allowed.</p> |
| 1426 | * |
| 1427 | * <p>The weight must range from 1 to 1000, and represents a weight for |
| 1428 | * every pixel in the area. This means that a large metering area with |
| 1429 | * the same weight as a smaller area will have more effect in the |
| 1430 | * metering result. Metering areas can overlap and the driver |
| 1431 | * will add the weights in the overlap region.</p> |
Wu-cheng Li | 30771b7 | 2011-04-02 06:19:46 +0800 | [diff] [blame] | 1432 | * |
Wu-cheng Li | bde61a5 | 2011-06-07 18:23:14 +0800 | [diff] [blame] | 1433 | * @see Parameters#setFocusAreas(List) |
| 1434 | * @see Parameters#getFocusAreas() |
| 1435 | * @see Parameters#getMaxNumFocusAreas() |
| 1436 | * @see Parameters#setMeteringAreas(List) |
| 1437 | * @see Parameters#getMeteringAreas() |
| 1438 | * @see Parameters#getMaxNumMeteringAreas() |
Wu-cheng Li | 30771b7 | 2011-04-02 06:19:46 +0800 | [diff] [blame] | 1439 | */ |
| 1440 | public static class Area { |
| 1441 | /** |
| 1442 | * Create an area with specified rectangle and weight. |
| 1443 | * |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 1444 | * @param rect the bounds of the area. |
| 1445 | * @param weight the weight of the area. |
Wu-cheng Li | 30771b7 | 2011-04-02 06:19:46 +0800 | [diff] [blame] | 1446 | */ |
| 1447 | public Area(Rect rect, int weight) { |
| 1448 | this.rect = rect; |
| 1449 | this.weight = weight; |
| 1450 | } |
| 1451 | /** |
| 1452 | * Compares {@code obj} to this area. |
| 1453 | * |
| 1454 | * @param obj the object to compare this area with. |
| 1455 | * @return {@code true} if the rectangle and weight of {@code obj} is |
| 1456 | * the same as those of this area. {@code false} otherwise. |
| 1457 | */ |
| 1458 | @Override |
| 1459 | public boolean equals(Object obj) { |
| 1460 | if (!(obj instanceof Area)) { |
| 1461 | return false; |
| 1462 | } |
| 1463 | Area a = (Area) obj; |
| 1464 | if (rect == null) { |
| 1465 | if (a.rect != null) return false; |
| 1466 | } else { |
| 1467 | if (!rect.equals(a.rect)) return false; |
| 1468 | } |
| 1469 | return weight == a.weight; |
| 1470 | } |
| 1471 | |
Wu-cheng Li | bde61a5 | 2011-06-07 18:23:14 +0800 | [diff] [blame] | 1472 | /** |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 1473 | * Bounds of the area. (-1000, -1000) represents the top-left of the |
| 1474 | * camera field of view, and (1000, 1000) represents the bottom-right of |
| 1475 | * the field of view. Setting bounds outside that range is not |
| 1476 | * allowed. Bounds with zero or negative width or height are not |
| 1477 | * allowed. |
Wu-cheng Li | bde61a5 | 2011-06-07 18:23:14 +0800 | [diff] [blame] | 1478 | * |
| 1479 | * @see Parameters#getFocusAreas() |
| 1480 | * @see Parameters#getMeteringAreas() |
| 1481 | */ |
Wu-cheng Li | 30771b7 | 2011-04-02 06:19:46 +0800 | [diff] [blame] | 1482 | public Rect rect; |
| 1483 | |
Wu-cheng Li | bde61a5 | 2011-06-07 18:23:14 +0800 | [diff] [blame] | 1484 | /** |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 1485 | * Weight of the area. The weight must range from 1 to 1000, and |
| 1486 | * represents a weight for every pixel in the area. This means that a |
| 1487 | * large metering area with the same weight as a smaller area will have |
| 1488 | * more effect in the metering result. Metering areas can overlap and |
| 1489 | * the driver will add the weights in the overlap region. |
Wu-cheng Li | bde61a5 | 2011-06-07 18:23:14 +0800 | [diff] [blame] | 1490 | * |
| 1491 | * @see Parameters#getFocusAreas() |
| 1492 | * @see Parameters#getMeteringAreas() |
| 1493 | */ |
Wu-cheng Li | 30771b7 | 2011-04-02 06:19:46 +0800 | [diff] [blame] | 1494 | public int weight; |
Wu-cheng Li | bde61a5 | 2011-06-07 18:23:14 +0800 | [diff] [blame] | 1495 | } |
Wu-cheng Li | 30771b7 | 2011-04-02 06:19:46 +0800 | [diff] [blame] | 1496 | |
| 1497 | /** |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 1498 | * Camera service settings. |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1499 | * |
| 1500 | * <p>To make camera parameters take effect, applications have to call |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 1501 | * {@link Camera#setParameters(Camera.Parameters)}. For example, after |
| 1502 | * {@link Camera.Parameters#setWhiteBalance} is called, white balance is not |
| 1503 | * actually changed until {@link Camera#setParameters(Camera.Parameters)} |
| 1504 | * is called with the changed parameters object. |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1505 | * |
| 1506 | * <p>Different devices may have different camera capabilities, such as |
| 1507 | * picture size or flash modes. The application should query the camera |
| 1508 | * capabilities before setting parameters. For example, the application |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 1509 | * should call {@link Camera.Parameters#getSupportedColorEffects()} before |
| 1510 | * calling {@link Camera.Parameters#setColorEffect(String)}. If the |
| 1511 | * camera does not support color effects, |
| 1512 | * {@link Camera.Parameters#getSupportedColorEffects()} will return null. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1513 | */ |
| 1514 | public class Parameters { |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1515 | // Parameter keys to communicate with the camera driver. |
| 1516 | private static final String KEY_PREVIEW_SIZE = "preview-size"; |
| 1517 | private static final String KEY_PREVIEW_FORMAT = "preview-format"; |
| 1518 | private static final String KEY_PREVIEW_FRAME_RATE = "preview-frame-rate"; |
Wu-cheng Li | 454630f | 2010-08-11 16:48:05 -0700 | [diff] [blame] | 1519 | private static final String KEY_PREVIEW_FPS_RANGE = "preview-fps-range"; |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1520 | private static final String KEY_PICTURE_SIZE = "picture-size"; |
| 1521 | private static final String KEY_PICTURE_FORMAT = "picture-format"; |
Wu-cheng Li | 4c4300c | 2010-01-23 15:45:39 +0800 | [diff] [blame] | 1522 | private static final String KEY_JPEG_THUMBNAIL_SIZE = "jpeg-thumbnail-size"; |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1523 | private static final String KEY_JPEG_THUMBNAIL_WIDTH = "jpeg-thumbnail-width"; |
| 1524 | private static final String KEY_JPEG_THUMBNAIL_HEIGHT = "jpeg-thumbnail-height"; |
| 1525 | private static final String KEY_JPEG_THUMBNAIL_QUALITY = "jpeg-thumbnail-quality"; |
| 1526 | private static final String KEY_JPEG_QUALITY = "jpeg-quality"; |
| 1527 | private static final String KEY_ROTATION = "rotation"; |
| 1528 | private static final String KEY_GPS_LATITUDE = "gps-latitude"; |
| 1529 | private static final String KEY_GPS_LONGITUDE = "gps-longitude"; |
| 1530 | private static final String KEY_GPS_ALTITUDE = "gps-altitude"; |
| 1531 | private static final String KEY_GPS_TIMESTAMP = "gps-timestamp"; |
Ray Chen | 055c986 | 2010-02-23 10:45:42 +0800 | [diff] [blame] | 1532 | private static final String KEY_GPS_PROCESSING_METHOD = "gps-processing-method"; |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1533 | private static final String KEY_WHITE_BALANCE = "whitebalance"; |
| 1534 | private static final String KEY_EFFECT = "effect"; |
| 1535 | private static final String KEY_ANTIBANDING = "antibanding"; |
| 1536 | private static final String KEY_SCENE_MODE = "scene-mode"; |
| 1537 | private static final String KEY_FLASH_MODE = "flash-mode"; |
Wu-cheng Li | 36322db | 2009-09-18 18:59:21 +0800 | [diff] [blame] | 1538 | private static final String KEY_FOCUS_MODE = "focus-mode"; |
Wu-cheng Li | 30771b7 | 2011-04-02 06:19:46 +0800 | [diff] [blame] | 1539 | private static final String KEY_FOCUS_AREAS = "focus-areas"; |
| 1540 | private static final String KEY_MAX_NUM_FOCUS_AREAS = "max-num-focus-areas"; |
Wu-cheng Li | 6c8d276 | 2010-01-27 22:55:14 +0800 | [diff] [blame] | 1541 | private static final String KEY_FOCAL_LENGTH = "focal-length"; |
| 1542 | private static final String KEY_HORIZONTAL_VIEW_ANGLE = "horizontal-view-angle"; |
| 1543 | private static final String KEY_VERTICAL_VIEW_ANGLE = "vertical-view-angle"; |
Wu-cheng Li | ff723b6c | 2010-02-09 13:38:19 +0800 | [diff] [blame] | 1544 | private static final String KEY_EXPOSURE_COMPENSATION = "exposure-compensation"; |
Wu-cheng Li | 24b326a | 2010-02-20 17:47:04 +0800 | [diff] [blame] | 1545 | private static final String KEY_MAX_EXPOSURE_COMPENSATION = "max-exposure-compensation"; |
| 1546 | private static final String KEY_MIN_EXPOSURE_COMPENSATION = "min-exposure-compensation"; |
| 1547 | private static final String KEY_EXPOSURE_COMPENSATION_STEP = "exposure-compensation-step"; |
Eino-Ville Talvala | 3773eef | 2011-04-15 13:51:42 -0700 | [diff] [blame] | 1548 | private static final String KEY_AUTO_EXPOSURE_LOCK = "auto-exposure-lock"; |
| 1549 | private static final String KEY_AUTO_EXPOSURE_LOCK_SUPPORTED = "auto-exposure-lock-supported"; |
Eino-Ville Talvala | d9c2601a | 2011-05-13 10:19:59 -0700 | [diff] [blame] | 1550 | private static final String KEY_AUTO_WHITEBALANCE_LOCK = "auto-whitebalance-lock"; |
| 1551 | private static final String KEY_AUTO_WHITEBALANCE_LOCK_SUPPORTED = "auto-whitebalance-lock-supported"; |
Wu-cheng Li | e98e4c8 | 2011-04-12 19:34:29 +0800 | [diff] [blame] | 1552 | private static final String KEY_METERING_AREAS = "metering-areas"; |
| 1553 | private static final String KEY_MAX_NUM_METERING_AREAS = "max-num-metering-areas"; |
Wu-cheng Li | 8cbb8f5 | 2010-02-28 23:19:55 -0800 | [diff] [blame] | 1554 | private static final String KEY_ZOOM = "zoom"; |
| 1555 | private static final String KEY_MAX_ZOOM = "max-zoom"; |
| 1556 | private static final String KEY_ZOOM_RATIOS = "zoom-ratios"; |
| 1557 | private static final String KEY_ZOOM_SUPPORTED = "zoom-supported"; |
| 1558 | private static final String KEY_SMOOTH_ZOOM_SUPPORTED = "smooth-zoom-supported"; |
Wu-cheng Li | e339c5e | 2010-05-13 19:31:02 +0800 | [diff] [blame] | 1559 | private static final String KEY_FOCUS_DISTANCES = "focus-distances"; |
James Dong | dd0b16c | 2010-09-21 16:23:48 -0700 | [diff] [blame] | 1560 | private static final String KEY_VIDEO_SIZE = "video-size"; |
| 1561 | private static final String KEY_PREFERRED_PREVIEW_SIZE_FOR_VIDEO = |
| 1562 | "preferred-preview-size-for-video"; |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 1563 | private static final String KEY_MAX_NUM_DETECTED_FACES_HW = "max-num-detected-faces-hw"; |
| 1564 | private static final String KEY_MAX_NUM_DETECTED_FACES_SW = "max-num-detected-faces-sw"; |
Wu-cheng Li | 25d8fb5 | 2011-08-02 13:20:36 +0800 | [diff] [blame] | 1565 | private static final String KEY_RECORDING_HINT = "recording-hint"; |
Wu-cheng Li | 98bb251 | 2011-08-30 21:33:10 +0800 | [diff] [blame] | 1566 | private static final String KEY_VIDEO_SNAPSHOT_SUPPORTED = "video-snapshot-supported"; |
Eino-Ville Talvala | 037abb8 | 2011-10-11 12:41:58 -0700 | [diff] [blame] | 1567 | private static final String KEY_VIDEO_STABILIZATION = "video-stabilization"; |
| 1568 | private static final String KEY_VIDEO_STABILIZATION_SUPPORTED = "video-stabilization-supported"; |
Wu-cheng Li | e339c5e | 2010-05-13 19:31:02 +0800 | [diff] [blame] | 1569 | |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1570 | // Parameter key suffix for supported values. |
| 1571 | private static final String SUPPORTED_VALUES_SUFFIX = "-values"; |
| 1572 | |
Wu-cheng Li | 8cbb8f5 | 2010-02-28 23:19:55 -0800 | [diff] [blame] | 1573 | private static final String TRUE = "true"; |
Eino-Ville Talvala | 3773eef | 2011-04-15 13:51:42 -0700 | [diff] [blame] | 1574 | private static final String FALSE = "false"; |
Wu-cheng Li | 8cbb8f5 | 2010-02-28 23:19:55 -0800 | [diff] [blame] | 1575 | |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1576 | // Values for white balance settings. |
| 1577 | public static final String WHITE_BALANCE_AUTO = "auto"; |
| 1578 | public static final String WHITE_BALANCE_INCANDESCENT = "incandescent"; |
| 1579 | public static final String WHITE_BALANCE_FLUORESCENT = "fluorescent"; |
| 1580 | public static final String WHITE_BALANCE_WARM_FLUORESCENT = "warm-fluorescent"; |
| 1581 | public static final String WHITE_BALANCE_DAYLIGHT = "daylight"; |
| 1582 | public static final String WHITE_BALANCE_CLOUDY_DAYLIGHT = "cloudy-daylight"; |
| 1583 | public static final String WHITE_BALANCE_TWILIGHT = "twilight"; |
| 1584 | public static final String WHITE_BALANCE_SHADE = "shade"; |
| 1585 | |
| 1586 | // Values for color effect settings. |
| 1587 | public static final String EFFECT_NONE = "none"; |
| 1588 | public static final String EFFECT_MONO = "mono"; |
| 1589 | public static final String EFFECT_NEGATIVE = "negative"; |
| 1590 | public static final String EFFECT_SOLARIZE = "solarize"; |
| 1591 | public static final String EFFECT_SEPIA = "sepia"; |
| 1592 | public static final String EFFECT_POSTERIZE = "posterize"; |
| 1593 | public static final String EFFECT_WHITEBOARD = "whiteboard"; |
| 1594 | public static final String EFFECT_BLACKBOARD = "blackboard"; |
| 1595 | public static final String EFFECT_AQUA = "aqua"; |
| 1596 | |
| 1597 | // Values for antibanding settings. |
| 1598 | public static final String ANTIBANDING_AUTO = "auto"; |
| 1599 | public static final String ANTIBANDING_50HZ = "50hz"; |
| 1600 | public static final String ANTIBANDING_60HZ = "60hz"; |
| 1601 | public static final String ANTIBANDING_OFF = "off"; |
| 1602 | |
| 1603 | // Values for flash mode settings. |
| 1604 | /** |
| 1605 | * Flash will not be fired. |
| 1606 | */ |
| 1607 | public static final String FLASH_MODE_OFF = "off"; |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 1608 | |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1609 | /** |
Wu-cheng Li | 068ef42 | 2009-09-27 13:19:36 -0700 | [diff] [blame] | 1610 | * Flash will be fired automatically when required. The flash may be fired |
| 1611 | * during preview, auto-focus, or snapshot depending on the driver. |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1612 | */ |
| 1613 | public static final String FLASH_MODE_AUTO = "auto"; |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 1614 | |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1615 | /** |
Wu-cheng Li | 068ef42 | 2009-09-27 13:19:36 -0700 | [diff] [blame] | 1616 | * Flash will always be fired during snapshot. The flash may also be |
| 1617 | * fired during preview or auto-focus depending on the driver. |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1618 | */ |
| 1619 | public static final String FLASH_MODE_ON = "on"; |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 1620 | |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1621 | /** |
| 1622 | * Flash will be fired in red-eye reduction mode. |
| 1623 | */ |
| 1624 | public static final String FLASH_MODE_RED_EYE = "red-eye"; |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 1625 | |
Wu-cheng Li | 36322db | 2009-09-18 18:59:21 +0800 | [diff] [blame] | 1626 | /** |
Wu-cheng Li | 068ef42 | 2009-09-27 13:19:36 -0700 | [diff] [blame] | 1627 | * Constant emission of light during preview, auto-focus and snapshot. |
| 1628 | * This can also be used for video recording. |
Wu-cheng Li | 36322db | 2009-09-18 18:59:21 +0800 | [diff] [blame] | 1629 | */ |
Wu-cheng Li | 068ef42 | 2009-09-27 13:19:36 -0700 | [diff] [blame] | 1630 | public static final String FLASH_MODE_TORCH = "torch"; |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1631 | |
Wu-cheng Li | 00e21f8 | 2010-05-28 16:43:38 +0800 | [diff] [blame] | 1632 | /** |
| 1633 | * Scene mode is off. |
| 1634 | */ |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1635 | public static final String SCENE_MODE_AUTO = "auto"; |
Wu-cheng Li | 00e21f8 | 2010-05-28 16:43:38 +0800 | [diff] [blame] | 1636 | |
| 1637 | /** |
| 1638 | * Take photos of fast moving objects. Same as {@link |
| 1639 | * #SCENE_MODE_SPORTS}. |
| 1640 | */ |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1641 | public static final String SCENE_MODE_ACTION = "action"; |
Wu-cheng Li | 00e21f8 | 2010-05-28 16:43:38 +0800 | [diff] [blame] | 1642 | |
| 1643 | /** |
| 1644 | * Take people pictures. |
| 1645 | */ |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1646 | public static final String SCENE_MODE_PORTRAIT = "portrait"; |
Wu-cheng Li | 00e21f8 | 2010-05-28 16:43:38 +0800 | [diff] [blame] | 1647 | |
| 1648 | /** |
| 1649 | * Take pictures on distant objects. |
| 1650 | */ |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1651 | public static final String SCENE_MODE_LANDSCAPE = "landscape"; |
Wu-cheng Li | 00e21f8 | 2010-05-28 16:43:38 +0800 | [diff] [blame] | 1652 | |
| 1653 | /** |
| 1654 | * Take photos at night. |
| 1655 | */ |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1656 | public static final String SCENE_MODE_NIGHT = "night"; |
Wu-cheng Li | 00e21f8 | 2010-05-28 16:43:38 +0800 | [diff] [blame] | 1657 | |
| 1658 | /** |
| 1659 | * Take people pictures at night. |
| 1660 | */ |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1661 | public static final String SCENE_MODE_NIGHT_PORTRAIT = "night-portrait"; |
Wu-cheng Li | 00e21f8 | 2010-05-28 16:43:38 +0800 | [diff] [blame] | 1662 | |
| 1663 | /** |
| 1664 | * Take photos in a theater. Flash light is off. |
| 1665 | */ |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1666 | public static final String SCENE_MODE_THEATRE = "theatre"; |
Wu-cheng Li | 00e21f8 | 2010-05-28 16:43:38 +0800 | [diff] [blame] | 1667 | |
| 1668 | /** |
| 1669 | * Take pictures on the beach. |
| 1670 | */ |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1671 | public static final String SCENE_MODE_BEACH = "beach"; |
Wu-cheng Li | 00e21f8 | 2010-05-28 16:43:38 +0800 | [diff] [blame] | 1672 | |
| 1673 | /** |
| 1674 | * Take pictures on the snow. |
| 1675 | */ |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1676 | public static final String SCENE_MODE_SNOW = "snow"; |
Wu-cheng Li | 00e21f8 | 2010-05-28 16:43:38 +0800 | [diff] [blame] | 1677 | |
| 1678 | /** |
| 1679 | * Take sunset photos. |
| 1680 | */ |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1681 | public static final String SCENE_MODE_SUNSET = "sunset"; |
Wu-cheng Li | 00e21f8 | 2010-05-28 16:43:38 +0800 | [diff] [blame] | 1682 | |
| 1683 | /** |
| 1684 | * Avoid blurry pictures (for example, due to hand shake). |
| 1685 | */ |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1686 | public static final String SCENE_MODE_STEADYPHOTO = "steadyphoto"; |
Wu-cheng Li | 00e21f8 | 2010-05-28 16:43:38 +0800 | [diff] [blame] | 1687 | |
| 1688 | /** |
| 1689 | * For shooting firework displays. |
| 1690 | */ |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1691 | public static final String SCENE_MODE_FIREWORKS = "fireworks"; |
Wu-cheng Li | 00e21f8 | 2010-05-28 16:43:38 +0800 | [diff] [blame] | 1692 | |
| 1693 | /** |
| 1694 | * Take photos of fast moving objects. Same as {@link |
| 1695 | * #SCENE_MODE_ACTION}. |
| 1696 | */ |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1697 | public static final String SCENE_MODE_SPORTS = "sports"; |
Wu-cheng Li | 00e21f8 | 2010-05-28 16:43:38 +0800 | [diff] [blame] | 1698 | |
| 1699 | /** |
| 1700 | * Take indoor low-light shot. |
| 1701 | */ |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1702 | public static final String SCENE_MODE_PARTY = "party"; |
Wu-cheng Li | 00e21f8 | 2010-05-28 16:43:38 +0800 | [diff] [blame] | 1703 | |
| 1704 | /** |
| 1705 | * Capture the naturally warm color of scenes lit by candles. |
| 1706 | */ |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1707 | public static final String SCENE_MODE_CANDLELIGHT = "candlelight"; |
| 1708 | |
Wu-cheng Li | c58b423 | 2010-03-29 17:21:28 +0800 | [diff] [blame] | 1709 | /** |
| 1710 | * Applications are looking for a barcode. Camera driver will be |
| 1711 | * optimized for barcode reading. |
| 1712 | */ |
| 1713 | public static final String SCENE_MODE_BARCODE = "barcode"; |
| 1714 | |
Wu-cheng Li | 36322db | 2009-09-18 18:59:21 +0800 | [diff] [blame] | 1715 | /** |
Wu-cheng Li | f008f3e | 2010-08-17 13:44:35 -0700 | [diff] [blame] | 1716 | * Auto-focus mode. Applications should call {@link |
| 1717 | * #autoFocus(AutoFocusCallback)} to start the focus in this mode. |
Wu-cheng Li | 36322db | 2009-09-18 18:59:21 +0800 | [diff] [blame] | 1718 | */ |
| 1719 | public static final String FOCUS_MODE_AUTO = "auto"; |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 1720 | |
Wu-cheng Li | 36322db | 2009-09-18 18:59:21 +0800 | [diff] [blame] | 1721 | /** |
| 1722 | * Focus is set at infinity. Applications should not call |
| 1723 | * {@link #autoFocus(AutoFocusCallback)} in this mode. |
| 1724 | */ |
| 1725 | public static final String FOCUS_MODE_INFINITY = "infinity"; |
Wu-cheng Li | f008f3e | 2010-08-17 13:44:35 -0700 | [diff] [blame] | 1726 | |
| 1727 | /** |
| 1728 | * Macro (close-up) focus mode. Applications should call |
| 1729 | * {@link #autoFocus(AutoFocusCallback)} to start the focus in this |
| 1730 | * mode. |
| 1731 | */ |
Wu-cheng Li | 36322db | 2009-09-18 18:59:21 +0800 | [diff] [blame] | 1732 | public static final String FOCUS_MODE_MACRO = "macro"; |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 1733 | |
Wu-cheng Li | 36322db | 2009-09-18 18:59:21 +0800 | [diff] [blame] | 1734 | /** |
| 1735 | * Focus is fixed. The camera is always in this mode if the focus is not |
| 1736 | * adjustable. If the camera has auto-focus, this mode can fix the |
| 1737 | * focus, which is usually at hyperfocal distance. Applications should |
| 1738 | * not call {@link #autoFocus(AutoFocusCallback)} in this mode. |
| 1739 | */ |
| 1740 | public static final String FOCUS_MODE_FIXED = "fixed"; |
| 1741 | |
Wu-cheng Li | c58b423 | 2010-03-29 17:21:28 +0800 | [diff] [blame] | 1742 | /** |
| 1743 | * Extended depth of field (EDOF). Focusing is done digitally and |
| 1744 | * continuously. Applications should not call {@link |
| 1745 | * #autoFocus(AutoFocusCallback)} in this mode. |
| 1746 | */ |
| 1747 | public static final String FOCUS_MODE_EDOF = "edof"; |
| 1748 | |
Wu-cheng Li | 699fe93 | 2010-08-05 11:50:25 -0700 | [diff] [blame] | 1749 | /** |
Wu-cheng Li | d45cb72 | 2010-09-20 16:15:32 -0700 | [diff] [blame] | 1750 | * Continuous auto focus mode intended for video recording. The camera |
Wu-cheng Li | b9ac75d | 2011-08-16 21:14:16 +0800 | [diff] [blame] | 1751 | * continuously tries to focus. This is the best choice for video |
| 1752 | * recording because the focus changes smoothly . Applications still can |
| 1753 | * call {@link #takePicture(Camera.ShutterCallback, |
| 1754 | * Camera.PictureCallback, Camera.PictureCallback)} in this mode but the |
| 1755 | * subject may not be in focus. Auto focus starts when the parameter is |
Wu-cheng Li | 53b3091 | 2011-10-12 19:43:51 +0800 | [diff] [blame] | 1756 | * set. |
| 1757 | * |
| 1758 | * <p>Since API level 14, applications can call {@link |
| 1759 | * #autoFocus(AutoFocusCallback)} in this mode. The focus callback will |
| 1760 | * immediately return with a boolean that indicates whether the focus is |
| 1761 | * sharp or not. The focus position is locked after autoFocus call. If |
| 1762 | * applications want to resume the continuous focus, cancelAutoFocus |
| 1763 | * must be called. Restarting the preview will not resume the continuous |
| 1764 | * autofocus. To stop continuous focus, applications should change the |
| 1765 | * focus mode to other modes. |
| 1766 | * |
| 1767 | * @see #FOCUS_MODE_CONTINUOUS_PICTURE |
Wu-cheng Li | 699fe93 | 2010-08-05 11:50:25 -0700 | [diff] [blame] | 1768 | */ |
Wu-cheng Li | d45cb72 | 2010-09-20 16:15:32 -0700 | [diff] [blame] | 1769 | public static final String FOCUS_MODE_CONTINUOUS_VIDEO = "continuous-video"; |
Wu-cheng Li | 699fe93 | 2010-08-05 11:50:25 -0700 | [diff] [blame] | 1770 | |
Wu-cheng Li | b9ac75d | 2011-08-16 21:14:16 +0800 | [diff] [blame] | 1771 | /** |
| 1772 | * Continuous auto focus mode intended for taking pictures. The camera |
| 1773 | * continuously tries to focus. The speed of focus change is more |
| 1774 | * aggressive than {@link #FOCUS_MODE_CONTINUOUS_VIDEO}. Auto focus |
Wu-cheng Li | 53b3091 | 2011-10-12 19:43:51 +0800 | [diff] [blame] | 1775 | * starts when the parameter is set. |
| 1776 | * |
Wu-cheng Li | 0f4f97b | 2011-10-27 18:07:01 +0800 | [diff] [blame] | 1777 | * <p>Applications can call {@link #autoFocus(AutoFocusCallback)} in |
| 1778 | * this mode. If the autofocus is in the middle of scanning, the focus |
| 1779 | * callback will return when it completes. If the autofocus is not |
| 1780 | * scanning, the focus callback will immediately return with a boolean |
| 1781 | * that indicates whether the focus is sharp or not. The apps can then |
| 1782 | * decide if they want to take a picture immediately or to change the |
| 1783 | * focus mode to auto, and run a full autofocus cycle. The focus |
| 1784 | * position is locked after autoFocus call. If applications want to |
| 1785 | * resume the continuous focus, cancelAutoFocus must be called. |
| 1786 | * Restarting the preview will not resume the continuous autofocus. To |
| 1787 | * stop continuous focus, applications should change the focus mode to |
| 1788 | * other modes. |
Wu-cheng Li | b9ac75d | 2011-08-16 21:14:16 +0800 | [diff] [blame] | 1789 | * |
| 1790 | * @see #FOCUS_MODE_CONTINUOUS_VIDEO |
Wu-cheng Li | b9ac75d | 2011-08-16 21:14:16 +0800 | [diff] [blame] | 1791 | */ |
| 1792 | public static final String FOCUS_MODE_CONTINUOUS_PICTURE = "continuous-picture"; |
| 1793 | |
Wu-cheng Li | e339c5e | 2010-05-13 19:31:02 +0800 | [diff] [blame] | 1794 | // Indices for focus distance array. |
| 1795 | /** |
| 1796 | * The array index of near focus distance for use with |
| 1797 | * {@link #getFocusDistances(float[])}. |
| 1798 | */ |
| 1799 | public static final int FOCUS_DISTANCE_NEAR_INDEX = 0; |
| 1800 | |
| 1801 | /** |
| 1802 | * The array index of optimal focus distance for use with |
| 1803 | * {@link #getFocusDistances(float[])}. |
| 1804 | */ |
| 1805 | public static final int FOCUS_DISTANCE_OPTIMAL_INDEX = 1; |
| 1806 | |
| 1807 | /** |
| 1808 | * The array index of far focus distance for use with |
| 1809 | * {@link #getFocusDistances(float[])}. |
| 1810 | */ |
| 1811 | public static final int FOCUS_DISTANCE_FAR_INDEX = 2; |
| 1812 | |
Wu-cheng Li | ca09961 | 2010-05-06 16:47:30 +0800 | [diff] [blame] | 1813 | /** |
Wu-cheng Li | 454630f | 2010-08-11 16:48:05 -0700 | [diff] [blame] | 1814 | * The array index of minimum preview fps for use with {@link |
| 1815 | * #getPreviewFpsRange(int[])} or {@link |
| 1816 | * #getSupportedPreviewFpsRange()}. |
Wu-cheng Li | 454630f | 2010-08-11 16:48:05 -0700 | [diff] [blame] | 1817 | */ |
| 1818 | public static final int PREVIEW_FPS_MIN_INDEX = 0; |
| 1819 | |
| 1820 | /** |
| 1821 | * The array index of maximum preview fps for use with {@link |
| 1822 | * #getPreviewFpsRange(int[])} or {@link |
| 1823 | * #getSupportedPreviewFpsRange()}. |
Wu-cheng Li | 454630f | 2010-08-11 16:48:05 -0700 | [diff] [blame] | 1824 | */ |
| 1825 | public static final int PREVIEW_FPS_MAX_INDEX = 1; |
| 1826 | |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1827 | // Formats for setPreviewFormat and setPictureFormat. |
| 1828 | private static final String PIXEL_FORMAT_YUV422SP = "yuv422sp"; |
| 1829 | private static final String PIXEL_FORMAT_YUV420SP = "yuv420sp"; |
Chih-Chung Chang | eb68c46 | 2009-09-18 18:37:44 +0800 | [diff] [blame] | 1830 | private static final String PIXEL_FORMAT_YUV422I = "yuv422i-yuyv"; |
Wu-cheng Li | 10a1b30 | 2011-02-22 15:49:25 +0800 | [diff] [blame] | 1831 | private static final String PIXEL_FORMAT_YUV420P = "yuv420p"; |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1832 | private static final String PIXEL_FORMAT_RGB565 = "rgb565"; |
| 1833 | private static final String PIXEL_FORMAT_JPEG = "jpeg"; |
Wu-cheng Li | 70fb908 | 2011-08-02 17:49:50 +0800 | [diff] [blame] | 1834 | private static final String PIXEL_FORMAT_BAYER_RGGB = "bayer-rggb"; |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1835 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1836 | private HashMap<String, String> mMap; |
| 1837 | |
| 1838 | private Parameters() { |
| 1839 | mMap = new HashMap<String, String>(); |
| 1840 | } |
| 1841 | |
| 1842 | /** |
| 1843 | * Writes the current Parameters to the log. |
| 1844 | * @hide |
| 1845 | * @deprecated |
| 1846 | */ |
| 1847 | public void dump() { |
| 1848 | Log.e(TAG, "dump: size=" + mMap.size()); |
| 1849 | for (String k : mMap.keySet()) { |
| 1850 | Log.e(TAG, "dump: " + k + "=" + mMap.get(k)); |
| 1851 | } |
| 1852 | } |
| 1853 | |
| 1854 | /** |
| 1855 | * Creates a single string with all the parameters set in |
| 1856 | * this Parameters object. |
| 1857 | * <p>The {@link #unflatten(String)} method does the reverse.</p> |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1858 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1859 | * @return a String with all values from this Parameters object, in |
| 1860 | * semi-colon delimited key-value pairs |
| 1861 | */ |
| 1862 | public String flatten() { |
| 1863 | StringBuilder flattened = new StringBuilder(); |
| 1864 | for (String k : mMap.keySet()) { |
| 1865 | flattened.append(k); |
| 1866 | flattened.append("="); |
| 1867 | flattened.append(mMap.get(k)); |
| 1868 | flattened.append(";"); |
| 1869 | } |
| 1870 | // chop off the extra semicolon at the end |
| 1871 | flattened.deleteCharAt(flattened.length()-1); |
| 1872 | return flattened.toString(); |
| 1873 | } |
| 1874 | |
| 1875 | /** |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1876 | * Takes a flattened string of parameters and adds each one to |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1877 | * this Parameters object. |
| 1878 | * <p>The {@link #flatten()} method does the reverse.</p> |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1879 | * |
| 1880 | * @param flattened a String of parameters (key-value paired) that |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1881 | * are semi-colon delimited |
| 1882 | */ |
| 1883 | public void unflatten(String flattened) { |
| 1884 | mMap.clear(); |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1885 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1886 | StringTokenizer tokenizer = new StringTokenizer(flattened, ";"); |
| 1887 | while (tokenizer.hasMoreElements()) { |
| 1888 | String kv = tokenizer.nextToken(); |
| 1889 | int pos = kv.indexOf('='); |
| 1890 | if (pos == -1) { |
| 1891 | continue; |
| 1892 | } |
| 1893 | String k = kv.substring(0, pos); |
| 1894 | String v = kv.substring(pos + 1); |
| 1895 | mMap.put(k, v); |
| 1896 | } |
| 1897 | } |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1898 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1899 | public void remove(String key) { |
| 1900 | mMap.remove(key); |
| 1901 | } |
| 1902 | |
| 1903 | /** |
| 1904 | * Sets a String parameter. |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1905 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1906 | * @param key the key name for the parameter |
| 1907 | * @param value the String value of the parameter |
| 1908 | */ |
| 1909 | public void set(String key, String value) { |
| 1910 | if (key.indexOf('=') != -1 || key.indexOf(';') != -1) { |
| 1911 | Log.e(TAG, "Key \"" + key + "\" contains invalid character (= or ;)"); |
| 1912 | return; |
| 1913 | } |
| 1914 | if (value.indexOf('=') != -1 || value.indexOf(';') != -1) { |
| 1915 | Log.e(TAG, "Value \"" + value + "\" contains invalid character (= or ;)"); |
| 1916 | return; |
| 1917 | } |
| 1918 | |
| 1919 | mMap.put(key, value); |
| 1920 | } |
| 1921 | |
| 1922 | /** |
| 1923 | * Sets an integer parameter. |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1924 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1925 | * @param key the key name for the parameter |
| 1926 | * @param value the int value of the parameter |
| 1927 | */ |
| 1928 | public void set(String key, int value) { |
| 1929 | mMap.put(key, Integer.toString(value)); |
| 1930 | } |
| 1931 | |
Wu-cheng Li | e98e4c8 | 2011-04-12 19:34:29 +0800 | [diff] [blame] | 1932 | private void set(String key, List<Area> areas) { |
Wu-cheng Li | f715bf9 | 2011-04-14 14:04:18 +0800 | [diff] [blame] | 1933 | if (areas == null) { |
| 1934 | set(key, "(0,0,0,0,0)"); |
| 1935 | } else { |
| 1936 | StringBuilder buffer = new StringBuilder(); |
| 1937 | for (int i = 0; i < areas.size(); i++) { |
| 1938 | Area area = areas.get(i); |
| 1939 | Rect rect = area.rect; |
| 1940 | buffer.append('('); |
| 1941 | buffer.append(rect.left); |
| 1942 | buffer.append(','); |
| 1943 | buffer.append(rect.top); |
| 1944 | buffer.append(','); |
| 1945 | buffer.append(rect.right); |
| 1946 | buffer.append(','); |
| 1947 | buffer.append(rect.bottom); |
| 1948 | buffer.append(','); |
| 1949 | buffer.append(area.weight); |
| 1950 | buffer.append(')'); |
| 1951 | if (i != areas.size() - 1) buffer.append(','); |
| 1952 | } |
| 1953 | set(key, buffer.toString()); |
Wu-cheng Li | e98e4c8 | 2011-04-12 19:34:29 +0800 | [diff] [blame] | 1954 | } |
Wu-cheng Li | e98e4c8 | 2011-04-12 19:34:29 +0800 | [diff] [blame] | 1955 | } |
| 1956 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1957 | /** |
| 1958 | * Returns the value of a String parameter. |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1959 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1960 | * @param key the key name for the parameter |
| 1961 | * @return the String value of the parameter |
| 1962 | */ |
| 1963 | public String get(String key) { |
| 1964 | return mMap.get(key); |
| 1965 | } |
| 1966 | |
| 1967 | /** |
| 1968 | * Returns the value of an integer parameter. |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1969 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1970 | * @param key the key name for the parameter |
| 1971 | * @return the int value of the parameter |
| 1972 | */ |
| 1973 | public int getInt(String key) { |
| 1974 | return Integer.parseInt(mMap.get(key)); |
| 1975 | } |
| 1976 | |
| 1977 | /** |
Wu-cheng Li | 26274fa | 2011-05-05 14:36:28 +0800 | [diff] [blame] | 1978 | * Sets the dimensions for preview pictures. If the preview has already |
| 1979 | * started, applications should stop the preview first before changing |
| 1980 | * preview size. |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1981 | * |
Wu-cheng Li | c157e0c | 2010-10-07 18:36:07 +0800 | [diff] [blame] | 1982 | * The sides of width and height are based on camera orientation. That |
| 1983 | * is, the preview size is the size before it is rotated by display |
| 1984 | * orientation. So applications need to consider the display orientation |
| 1985 | * while setting preview size. For example, suppose the camera supports |
| 1986 | * both 480x320 and 320x480 preview sizes. The application wants a 3:2 |
| 1987 | * preview ratio. If the display orientation is set to 0 or 180, preview |
| 1988 | * size should be set to 480x320. If the display orientation is set to |
| 1989 | * 90 or 270, preview size should be set to 320x480. The display |
| 1990 | * orientation should also be considered while setting picture size and |
| 1991 | * thumbnail size. |
| 1992 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1993 | * @param width the width of the pictures, in pixels |
| 1994 | * @param height the height of the pictures, in pixels |
Wu-cheng Li | c157e0c | 2010-10-07 18:36:07 +0800 | [diff] [blame] | 1995 | * @see #setDisplayOrientation(int) |
| 1996 | * @see #getCameraInfo(int, CameraInfo) |
| 1997 | * @see #setPictureSize(int, int) |
| 1998 | * @see #setJpegThumbnailSize(int, int) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1999 | */ |
| 2000 | public void setPreviewSize(int width, int height) { |
| 2001 | String v = Integer.toString(width) + "x" + Integer.toString(height); |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2002 | set(KEY_PREVIEW_SIZE, v); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2003 | } |
| 2004 | |
| 2005 | /** |
| 2006 | * Returns the dimensions setting for preview pictures. |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2007 | * |
James Dong | dd0b16c | 2010-09-21 16:23:48 -0700 | [diff] [blame] | 2008 | * @return a Size object with the width and height setting |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2009 | * for the preview picture |
| 2010 | */ |
| 2011 | public Size getPreviewSize() { |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2012 | String pair = get(KEY_PREVIEW_SIZE); |
| 2013 | return strToSize(pair); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2014 | } |
| 2015 | |
| 2016 | /** |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2017 | * Gets the supported preview sizes. |
| 2018 | * |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 2019 | * @return a list of Size object. This method will always return a list |
Wu-cheng Li | 9c79938 | 2009-12-04 19:59:18 +0800 | [diff] [blame] | 2020 | * with at least one element. |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2021 | */ |
| 2022 | public List<Size> getSupportedPreviewSizes() { |
| 2023 | String str = get(KEY_PREVIEW_SIZE + SUPPORTED_VALUES_SUFFIX); |
| 2024 | return splitSize(str); |
| 2025 | } |
| 2026 | |
| 2027 | /** |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 2028 | * <p>Gets the supported video frame sizes that can be used by |
| 2029 | * MediaRecorder.</p> |
James Dong | dd0b16c | 2010-09-21 16:23:48 -0700 | [diff] [blame] | 2030 | * |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 2031 | * <p>If the returned list is not null, the returned list will contain at |
James Dong | dd0b16c | 2010-09-21 16:23:48 -0700 | [diff] [blame] | 2032 | * least one Size and one of the sizes in the returned list must be |
| 2033 | * passed to MediaRecorder.setVideoSize() for camcorder application if |
| 2034 | * camera is used as the video source. In this case, the size of the |
| 2035 | * preview can be different from the resolution of the recorded video |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 2036 | * during video recording.</p> |
James Dong | dd0b16c | 2010-09-21 16:23:48 -0700 | [diff] [blame] | 2037 | * |
| 2038 | * @return a list of Size object if camera has separate preview and |
| 2039 | * video output; otherwise, null is returned. |
| 2040 | * @see #getPreferredPreviewSizeForVideo() |
| 2041 | */ |
| 2042 | public List<Size> getSupportedVideoSizes() { |
| 2043 | String str = get(KEY_VIDEO_SIZE + SUPPORTED_VALUES_SUFFIX); |
| 2044 | return splitSize(str); |
| 2045 | } |
| 2046 | |
| 2047 | /** |
| 2048 | * Returns the preferred or recommended preview size (width and height) |
| 2049 | * in pixels for video recording. Camcorder applications should |
| 2050 | * set the preview size to a value that is not larger than the |
| 2051 | * preferred preview size. In other words, the product of the width |
| 2052 | * and height of the preview size should not be larger than that of |
| 2053 | * the preferred preview size. In addition, we recommend to choose a |
| 2054 | * preview size that has the same aspect ratio as the resolution of |
| 2055 | * video to be recorded. |
| 2056 | * |
| 2057 | * @return the preferred preview size (width and height) in pixels for |
| 2058 | * video recording if getSupportedVideoSizes() does not return |
| 2059 | * null; otherwise, null is returned. |
| 2060 | * @see #getSupportedVideoSizes() |
| 2061 | */ |
| 2062 | public Size getPreferredPreviewSizeForVideo() { |
| 2063 | String pair = get(KEY_PREFERRED_PREVIEW_SIZE_FOR_VIDEO); |
| 2064 | return strToSize(pair); |
| 2065 | } |
| 2066 | |
| 2067 | /** |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 2068 | * <p>Sets the dimensions for EXIF thumbnail in Jpeg picture. If |
Wu-cheng Li | 4c4300c | 2010-01-23 15:45:39 +0800 | [diff] [blame] | 2069 | * applications set both width and height to 0, EXIF will not contain |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 2070 | * thumbnail.</p> |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2071 | * |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 2072 | * <p>Applications need to consider the display orientation. See {@link |
| 2073 | * #setPreviewSize(int,int)} for reference.</p> |
Wu-cheng Li | c157e0c | 2010-10-07 18:36:07 +0800 | [diff] [blame] | 2074 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2075 | * @param width the width of the thumbnail, in pixels |
| 2076 | * @param height the height of the thumbnail, in pixels |
Wu-cheng Li | c157e0c | 2010-10-07 18:36:07 +0800 | [diff] [blame] | 2077 | * @see #setPreviewSize(int,int) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2078 | */ |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2079 | public void setJpegThumbnailSize(int width, int height) { |
| 2080 | set(KEY_JPEG_THUMBNAIL_WIDTH, width); |
| 2081 | set(KEY_JPEG_THUMBNAIL_HEIGHT, height); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2082 | } |
| 2083 | |
| 2084 | /** |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2085 | * Returns the dimensions for EXIF thumbnail in Jpeg picture. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2086 | * |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2087 | * @return a Size object with the height and width setting for the EXIF |
| 2088 | * thumbnails |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2089 | */ |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2090 | public Size getJpegThumbnailSize() { |
| 2091 | return new Size(getInt(KEY_JPEG_THUMBNAIL_WIDTH), |
| 2092 | getInt(KEY_JPEG_THUMBNAIL_HEIGHT)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2093 | } |
| 2094 | |
| 2095 | /** |
Wu-cheng Li | 4c4300c | 2010-01-23 15:45:39 +0800 | [diff] [blame] | 2096 | * Gets the supported jpeg thumbnail sizes. |
| 2097 | * |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 2098 | * @return a list of Size object. This method will always return a list |
Wu-cheng Li | 4c4300c | 2010-01-23 15:45:39 +0800 | [diff] [blame] | 2099 | * with at least two elements. Size 0,0 (no thumbnail) is always |
| 2100 | * supported. |
| 2101 | */ |
| 2102 | public List<Size> getSupportedJpegThumbnailSizes() { |
| 2103 | String str = get(KEY_JPEG_THUMBNAIL_SIZE + SUPPORTED_VALUES_SUFFIX); |
| 2104 | return splitSize(str); |
| 2105 | } |
| 2106 | |
| 2107 | /** |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2108 | * Sets the quality of the EXIF thumbnail in Jpeg picture. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2109 | * |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2110 | * @param quality the JPEG quality of the EXIF thumbnail. The range is 1 |
| 2111 | * to 100, with 100 being the best. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2112 | */ |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2113 | public void setJpegThumbnailQuality(int quality) { |
| 2114 | set(KEY_JPEG_THUMBNAIL_QUALITY, quality); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2115 | } |
| 2116 | |
| 2117 | /** |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2118 | * Returns the quality setting for the EXIF thumbnail in Jpeg picture. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2119 | * |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2120 | * @return the JPEG quality setting of the EXIF thumbnail. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2121 | */ |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2122 | public int getJpegThumbnailQuality() { |
| 2123 | return getInt(KEY_JPEG_THUMBNAIL_QUALITY); |
| 2124 | } |
| 2125 | |
| 2126 | /** |
| 2127 | * Sets Jpeg quality of captured picture. |
| 2128 | * |
| 2129 | * @param quality the JPEG quality of captured picture. The range is 1 |
| 2130 | * to 100, with 100 being the best. |
| 2131 | */ |
| 2132 | public void setJpegQuality(int quality) { |
| 2133 | set(KEY_JPEG_QUALITY, quality); |
| 2134 | } |
| 2135 | |
| 2136 | /** |
| 2137 | * Returns the quality setting for the JPEG picture. |
| 2138 | * |
| 2139 | * @return the JPEG picture quality setting. |
| 2140 | */ |
| 2141 | public int getJpegQuality() { |
| 2142 | return getInt(KEY_JPEG_QUALITY); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2143 | } |
| 2144 | |
| 2145 | /** |
Wu-cheng Li | a18e901 | 2010-02-10 13:05:29 +0800 | [diff] [blame] | 2146 | * Sets the rate at which preview frames are received. This is the |
| 2147 | * target frame rate. The actual frame rate depends on the driver. |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2148 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2149 | * @param fps the frame rate (frames per second) |
Wu-cheng Li | 5f1e69c | 2010-08-18 11:39:12 -0700 | [diff] [blame] | 2150 | * @deprecated replaced by {@link #setPreviewFpsRange(int,int)} |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2151 | */ |
Wu-cheng Li | 5f1e69c | 2010-08-18 11:39:12 -0700 | [diff] [blame] | 2152 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2153 | public void setPreviewFrameRate(int fps) { |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2154 | set(KEY_PREVIEW_FRAME_RATE, fps); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2155 | } |
| 2156 | |
| 2157 | /** |
Wu-cheng Li | a18e901 | 2010-02-10 13:05:29 +0800 | [diff] [blame] | 2158 | * Returns the setting for the rate at which preview frames are |
| 2159 | * received. This is the target frame rate. The actual frame rate |
| 2160 | * depends on the driver. |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2161 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2162 | * @return the frame rate setting (frames per second) |
Wu-cheng Li | 5f1e69c | 2010-08-18 11:39:12 -0700 | [diff] [blame] | 2163 | * @deprecated replaced by {@link #getPreviewFpsRange(int[])} |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2164 | */ |
Wu-cheng Li | 5f1e69c | 2010-08-18 11:39:12 -0700 | [diff] [blame] | 2165 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2166 | public int getPreviewFrameRate() { |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2167 | return getInt(KEY_PREVIEW_FRAME_RATE); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2168 | } |
| 2169 | |
| 2170 | /** |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2171 | * Gets the supported preview frame rates. |
| 2172 | * |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 2173 | * @return a list of supported preview frame rates. null if preview |
| 2174 | * frame rate setting is not supported. |
Wu-cheng Li | 5f1e69c | 2010-08-18 11:39:12 -0700 | [diff] [blame] | 2175 | * @deprecated replaced by {@link #getSupportedPreviewFpsRange()} |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2176 | */ |
Wu-cheng Li | 5f1e69c | 2010-08-18 11:39:12 -0700 | [diff] [blame] | 2177 | @Deprecated |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2178 | public List<Integer> getSupportedPreviewFrameRates() { |
| 2179 | String str = get(KEY_PREVIEW_FRAME_RATE + SUPPORTED_VALUES_SUFFIX); |
| 2180 | return splitInt(str); |
| 2181 | } |
| 2182 | |
| 2183 | /** |
Wu-cheng Li | 454630f | 2010-08-11 16:48:05 -0700 | [diff] [blame] | 2184 | * Sets the maximum and maximum preview fps. This controls the rate of |
Wu-cheng Li | 1620d11 | 2010-08-27 15:09:20 -0700 | [diff] [blame] | 2185 | * preview frames received in {@link PreviewCallback}. The minimum and |
Wu-cheng Li | 454630f | 2010-08-11 16:48:05 -0700 | [diff] [blame] | 2186 | * maximum preview fps must be one of the elements from {@link |
| 2187 | * #getSupportedPreviewFpsRange}. |
| 2188 | * |
| 2189 | * @param min the minimum preview fps (scaled by 1000). |
| 2190 | * @param max the maximum preview fps (scaled by 1000). |
| 2191 | * @throws RuntimeException if fps range is invalid. |
| 2192 | * @see #setPreviewCallbackWithBuffer(Camera.PreviewCallback) |
| 2193 | * @see #getSupportedPreviewFpsRange() |
Wu-cheng Li | 454630f | 2010-08-11 16:48:05 -0700 | [diff] [blame] | 2194 | */ |
| 2195 | public void setPreviewFpsRange(int min, int max) { |
| 2196 | set(KEY_PREVIEW_FPS_RANGE, "" + min + "," + max); |
| 2197 | } |
| 2198 | |
| 2199 | /** |
| 2200 | * Returns the current minimum and maximum preview fps. The values are |
| 2201 | * one of the elements returned by {@link #getSupportedPreviewFpsRange}. |
| 2202 | * |
| 2203 | * @return range the minimum and maximum preview fps (scaled by 1000). |
| 2204 | * @see #PREVIEW_FPS_MIN_INDEX |
| 2205 | * @see #PREVIEW_FPS_MAX_INDEX |
| 2206 | * @see #getSupportedPreviewFpsRange() |
Wu-cheng Li | 454630f | 2010-08-11 16:48:05 -0700 | [diff] [blame] | 2207 | */ |
| 2208 | public void getPreviewFpsRange(int[] range) { |
| 2209 | if (range == null || range.length != 2) { |
| 2210 | throw new IllegalArgumentException( |
Wu-cheng Li | 5f1e69c | 2010-08-18 11:39:12 -0700 | [diff] [blame] | 2211 | "range must be an array with two elements."); |
Wu-cheng Li | 454630f | 2010-08-11 16:48:05 -0700 | [diff] [blame] | 2212 | } |
| 2213 | splitInt(get(KEY_PREVIEW_FPS_RANGE), range); |
| 2214 | } |
| 2215 | |
| 2216 | /** |
| 2217 | * Gets the supported preview fps (frame-per-second) ranges. Each range |
| 2218 | * contains a minimum fps and maximum fps. If minimum fps equals to |
| 2219 | * maximum fps, the camera outputs frames in fixed frame rate. If not, |
| 2220 | * the camera outputs frames in auto frame rate. The actual frame rate |
| 2221 | * fluctuates between the minimum and the maximum. The values are |
| 2222 | * multiplied by 1000 and represented in integers. For example, if frame |
| 2223 | * rate is 26.623 frames per second, the value is 26623. |
| 2224 | * |
| 2225 | * @return a list of supported preview fps ranges. This method returns a |
| 2226 | * list with at least one element. Every element is an int array |
| 2227 | * of two values - minimum fps and maximum fps. The list is |
| 2228 | * sorted from small to large (first by maximum fps and then |
| 2229 | * minimum fps). |
| 2230 | * @see #PREVIEW_FPS_MIN_INDEX |
| 2231 | * @see #PREVIEW_FPS_MAX_INDEX |
Wu-cheng Li | 454630f | 2010-08-11 16:48:05 -0700 | [diff] [blame] | 2232 | */ |
| 2233 | public List<int[]> getSupportedPreviewFpsRange() { |
| 2234 | String str = get(KEY_PREVIEW_FPS_RANGE + SUPPORTED_VALUES_SUFFIX); |
| 2235 | return splitRange(str); |
| 2236 | } |
| 2237 | |
| 2238 | /** |
Wu-cheng Li | 7478ea6 | 2009-09-16 18:52:55 +0800 | [diff] [blame] | 2239 | * Sets the image format for preview pictures. |
Scott Main | da0a56df | 2009-09-10 18:08:37 -0700 | [diff] [blame] | 2240 | * <p>If this is never called, the default format will be |
Mathias Agopian | a696f5d | 2010-02-17 17:53:09 -0800 | [diff] [blame] | 2241 | * {@link android.graphics.ImageFormat#NV21}, which |
Scott Main | df4578e | 2009-09-10 12:22:07 -0700 | [diff] [blame] | 2242 | * uses the NV21 encoding format.</p> |
Wu-cheng Li | 7478ea6 | 2009-09-16 18:52:55 +0800 | [diff] [blame] | 2243 | * |
Scott Main | df4578e | 2009-09-10 12:22:07 -0700 | [diff] [blame] | 2244 | * @param pixel_format the desired preview picture format, defined |
Mathias Agopian | a696f5d | 2010-02-17 17:53:09 -0800 | [diff] [blame] | 2245 | * by one of the {@link android.graphics.ImageFormat} constants. |
| 2246 | * (E.g., <var>ImageFormat.NV21</var> (default), |
| 2247 | * <var>ImageFormat.RGB_565</var>, or |
| 2248 | * <var>ImageFormat.JPEG</var>) |
| 2249 | * @see android.graphics.ImageFormat |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2250 | */ |
| 2251 | public void setPreviewFormat(int pixel_format) { |
| 2252 | String s = cameraFormatForPixelFormat(pixel_format); |
| 2253 | if (s == null) { |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2254 | throw new IllegalArgumentException( |
| 2255 | "Invalid pixel_format=" + pixel_format); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2256 | } |
| 2257 | |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2258 | set(KEY_PREVIEW_FORMAT, s); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2259 | } |
| 2260 | |
| 2261 | /** |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 2262 | * Returns the image format for preview frames got from |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2263 | * {@link PreviewCallback}. |
Wu-cheng Li | 7478ea6 | 2009-09-16 18:52:55 +0800 | [diff] [blame] | 2264 | * |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 2265 | * @return the preview format. |
| 2266 | * @see android.graphics.ImageFormat |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2267 | */ |
| 2268 | public int getPreviewFormat() { |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2269 | return pixelFormatForCameraFormat(get(KEY_PREVIEW_FORMAT)); |
| 2270 | } |
| 2271 | |
| 2272 | /** |
Wu-cheng Li | f9293e7 | 2011-02-25 13:35:10 +0800 | [diff] [blame] | 2273 | * Gets the supported preview formats. {@link android.graphics.ImageFormat#NV21} |
| 2274 | * is always supported. {@link android.graphics.ImageFormat#YV12} |
| 2275 | * is always supported since API level 12. |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2276 | * |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 2277 | * @return a list of supported preview formats. This method will always |
| 2278 | * return a list with at least one element. |
| 2279 | * @see android.graphics.ImageFormat |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2280 | */ |
| 2281 | public List<Integer> getSupportedPreviewFormats() { |
| 2282 | String str = get(KEY_PREVIEW_FORMAT + SUPPORTED_VALUES_SUFFIX); |
Chih-Chung Chang | eb68c46 | 2009-09-18 18:37:44 +0800 | [diff] [blame] | 2283 | ArrayList<Integer> formats = new ArrayList<Integer>(); |
| 2284 | for (String s : split(str)) { |
| 2285 | int f = pixelFormatForCameraFormat(s); |
Mathias Agopian | a696f5d | 2010-02-17 17:53:09 -0800 | [diff] [blame] | 2286 | if (f == ImageFormat.UNKNOWN) continue; |
Chih-Chung Chang | eb68c46 | 2009-09-18 18:37:44 +0800 | [diff] [blame] | 2287 | formats.add(f); |
| 2288 | } |
| 2289 | return formats; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2290 | } |
| 2291 | |
| 2292 | /** |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 2293 | * <p>Sets the dimensions for pictures.</p> |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2294 | * |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 2295 | * <p>Applications need to consider the display orientation. See {@link |
| 2296 | * #setPreviewSize(int,int)} for reference.</p> |
Wu-cheng Li | c157e0c | 2010-10-07 18:36:07 +0800 | [diff] [blame] | 2297 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2298 | * @param width the width for pictures, in pixels |
| 2299 | * @param height the height for pictures, in pixels |
Wu-cheng Li | c157e0c | 2010-10-07 18:36:07 +0800 | [diff] [blame] | 2300 | * @see #setPreviewSize(int,int) |
| 2301 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2302 | */ |
| 2303 | public void setPictureSize(int width, int height) { |
| 2304 | String v = Integer.toString(width) + "x" + Integer.toString(height); |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2305 | set(KEY_PICTURE_SIZE, v); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2306 | } |
| 2307 | |
| 2308 | /** |
| 2309 | * Returns the dimension setting for pictures. |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2310 | * |
| 2311 | * @return a Size object with the height and width setting |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2312 | * for pictures |
| 2313 | */ |
| 2314 | public Size getPictureSize() { |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2315 | String pair = get(KEY_PICTURE_SIZE); |
| 2316 | return strToSize(pair); |
| 2317 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2318 | |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2319 | /** |
| 2320 | * Gets the supported picture sizes. |
| 2321 | * |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 2322 | * @return a list of supported picture sizes. This method will always |
| 2323 | * return a list with at least one element. |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2324 | */ |
| 2325 | public List<Size> getSupportedPictureSizes() { |
| 2326 | String str = get(KEY_PICTURE_SIZE + SUPPORTED_VALUES_SUFFIX); |
| 2327 | return splitSize(str); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2328 | } |
| 2329 | |
| 2330 | /** |
| 2331 | * Sets the image format for pictures. |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2332 | * |
| 2333 | * @param pixel_format the desired picture format |
Mathias Agopian | a696f5d | 2010-02-17 17:53:09 -0800 | [diff] [blame] | 2334 | * (<var>ImageFormat.NV21</var>, |
| 2335 | * <var>ImageFormat.RGB_565</var>, or |
| 2336 | * <var>ImageFormat.JPEG</var>) |
| 2337 | * @see android.graphics.ImageFormat |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2338 | */ |
| 2339 | public void setPictureFormat(int pixel_format) { |
| 2340 | String s = cameraFormatForPixelFormat(pixel_format); |
| 2341 | if (s == null) { |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2342 | throw new IllegalArgumentException( |
| 2343 | "Invalid pixel_format=" + pixel_format); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2344 | } |
| 2345 | |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2346 | set(KEY_PICTURE_FORMAT, s); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2347 | } |
| 2348 | |
| 2349 | /** |
| 2350 | * Returns the image format for pictures. |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2351 | * |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 2352 | * @return the picture format |
| 2353 | * @see android.graphics.ImageFormat |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2354 | */ |
| 2355 | public int getPictureFormat() { |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2356 | return pixelFormatForCameraFormat(get(KEY_PICTURE_FORMAT)); |
| 2357 | } |
| 2358 | |
| 2359 | /** |
| 2360 | * Gets the supported picture formats. |
| 2361 | * |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 2362 | * @return supported picture formats. This method will always return a |
| 2363 | * list with at least one element. |
| 2364 | * @see android.graphics.ImageFormat |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2365 | */ |
| 2366 | public List<Integer> getSupportedPictureFormats() { |
Wu-cheng Li | 9c79938 | 2009-12-04 19:59:18 +0800 | [diff] [blame] | 2367 | String str = get(KEY_PICTURE_FORMAT + SUPPORTED_VALUES_SUFFIX); |
| 2368 | ArrayList<Integer> formats = new ArrayList<Integer>(); |
| 2369 | for (String s : split(str)) { |
| 2370 | int f = pixelFormatForCameraFormat(s); |
Mathias Agopian | a696f5d | 2010-02-17 17:53:09 -0800 | [diff] [blame] | 2371 | if (f == ImageFormat.UNKNOWN) continue; |
Wu-cheng Li | 9c79938 | 2009-12-04 19:59:18 +0800 | [diff] [blame] | 2372 | formats.add(f); |
| 2373 | } |
| 2374 | return formats; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2375 | } |
| 2376 | |
| 2377 | private String cameraFormatForPixelFormat(int pixel_format) { |
| 2378 | switch(pixel_format) { |
Mathias Agopian | a696f5d | 2010-02-17 17:53:09 -0800 | [diff] [blame] | 2379 | case ImageFormat.NV16: return PIXEL_FORMAT_YUV422SP; |
| 2380 | case ImageFormat.NV21: return PIXEL_FORMAT_YUV420SP; |
| 2381 | case ImageFormat.YUY2: return PIXEL_FORMAT_YUV422I; |
Wu-cheng Li | 10a1b30 | 2011-02-22 15:49:25 +0800 | [diff] [blame] | 2382 | case ImageFormat.YV12: return PIXEL_FORMAT_YUV420P; |
Mathias Agopian | a696f5d | 2010-02-17 17:53:09 -0800 | [diff] [blame] | 2383 | case ImageFormat.RGB_565: return PIXEL_FORMAT_RGB565; |
| 2384 | case ImageFormat.JPEG: return PIXEL_FORMAT_JPEG; |
Wu-cheng Li | 70fb908 | 2011-08-02 17:49:50 +0800 | [diff] [blame] | 2385 | case ImageFormat.BAYER_RGGB: return PIXEL_FORMAT_BAYER_RGGB; |
Mathias Agopian | a696f5d | 2010-02-17 17:53:09 -0800 | [diff] [blame] | 2386 | default: return null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2387 | } |
| 2388 | } |
| 2389 | |
| 2390 | private int pixelFormatForCameraFormat(String format) { |
| 2391 | if (format == null) |
Mathias Agopian | a696f5d | 2010-02-17 17:53:09 -0800 | [diff] [blame] | 2392 | return ImageFormat.UNKNOWN; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2393 | |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2394 | if (format.equals(PIXEL_FORMAT_YUV422SP)) |
Mathias Agopian | a696f5d | 2010-02-17 17:53:09 -0800 | [diff] [blame] | 2395 | return ImageFormat.NV16; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2396 | |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2397 | if (format.equals(PIXEL_FORMAT_YUV420SP)) |
Mathias Agopian | a696f5d | 2010-02-17 17:53:09 -0800 | [diff] [blame] | 2398 | return ImageFormat.NV21; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2399 | |
Chih-Chung Chang | eb68c46 | 2009-09-18 18:37:44 +0800 | [diff] [blame] | 2400 | if (format.equals(PIXEL_FORMAT_YUV422I)) |
Mathias Agopian | a696f5d | 2010-02-17 17:53:09 -0800 | [diff] [blame] | 2401 | return ImageFormat.YUY2; |
Chih-Chung Chang | eb68c46 | 2009-09-18 18:37:44 +0800 | [diff] [blame] | 2402 | |
Wu-cheng Li | 10a1b30 | 2011-02-22 15:49:25 +0800 | [diff] [blame] | 2403 | if (format.equals(PIXEL_FORMAT_YUV420P)) |
| 2404 | return ImageFormat.YV12; |
| 2405 | |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2406 | if (format.equals(PIXEL_FORMAT_RGB565)) |
Mathias Agopian | a696f5d | 2010-02-17 17:53:09 -0800 | [diff] [blame] | 2407 | return ImageFormat.RGB_565; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2408 | |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2409 | if (format.equals(PIXEL_FORMAT_JPEG)) |
Mathias Agopian | a696f5d | 2010-02-17 17:53:09 -0800 | [diff] [blame] | 2410 | return ImageFormat.JPEG; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2411 | |
Mathias Agopian | a696f5d | 2010-02-17 17:53:09 -0800 | [diff] [blame] | 2412 | return ImageFormat.UNKNOWN; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2413 | } |
| 2414 | |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2415 | /** |
Wu-cheng Li | 2fb818c | 2010-09-13 20:02:01 -0700 | [diff] [blame] | 2416 | * Sets the rotation angle in degrees relative to the orientation of |
| 2417 | * the camera. This affects the pictures returned from JPEG {@link |
| 2418 | * PictureCallback}. The camera driver may set orientation in the |
| 2419 | * EXIF header without rotating the picture. Or the driver may rotate |
| 2420 | * the picture and the EXIF thumbnail. If the Jpeg picture is rotated, |
| 2421 | * the orientation in the EXIF header will be missing or 1 (row #0 is |
| 2422 | * top and column #0 is left side). |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2423 | * |
Brad Fitzpatrick | 69ea4e1 | 2011-01-05 11:13:40 -0800 | [diff] [blame] | 2424 | * <p>If applications want to rotate the picture to match the orientation |
Wu-cheng Li | 2fe6fca | 2010-10-15 14:42:23 +0800 | [diff] [blame] | 2425 | * of what users see, apps should use {@link |
Wu-cheng Li | 2fb818c | 2010-09-13 20:02:01 -0700 | [diff] [blame] | 2426 | * android.view.OrientationEventListener} and {@link CameraInfo}. |
| 2427 | * The value from OrientationEventListener is relative to the natural |
Wu-cheng Li | 2fe6fca | 2010-10-15 14:42:23 +0800 | [diff] [blame] | 2428 | * orientation of the device. CameraInfo.orientation is the angle |
Brad Fitzpatrick | 69ea4e1 | 2011-01-05 11:13:40 -0800 | [diff] [blame] | 2429 | * between camera orientation and natural device orientation. The sum |
Wu-cheng Li | 2fe6fca | 2010-10-15 14:42:23 +0800 | [diff] [blame] | 2430 | * of the two is the rotation angle for back-facing camera. The |
| 2431 | * difference of the two is the rotation angle for front-facing camera. |
| 2432 | * Note that the JPEG pictures of front-facing cameras are not mirrored |
| 2433 | * as in preview display. |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2434 | * |
Brad Fitzpatrick | 69ea4e1 | 2011-01-05 11:13:40 -0800 | [diff] [blame] | 2435 | * <p>For example, suppose the natural orientation of the device is |
Wu-cheng Li | 2fb818c | 2010-09-13 20:02:01 -0700 | [diff] [blame] | 2436 | * portrait. The device is rotated 270 degrees clockwise, so the device |
Wu-cheng Li | 2fe6fca | 2010-10-15 14:42:23 +0800 | [diff] [blame] | 2437 | * orientation is 270. Suppose a back-facing camera sensor is mounted in |
| 2438 | * landscape and the top side of the camera sensor is aligned with the |
| 2439 | * right edge of the display in natural orientation. So the camera |
| 2440 | * orientation is 90. The rotation should be set to 0 (270 + 90). |
Wu-cheng Li | 2fb818c | 2010-09-13 20:02:01 -0700 | [diff] [blame] | 2441 | * |
Brad Fitzpatrick | 69ea4e1 | 2011-01-05 11:13:40 -0800 | [diff] [blame] | 2442 | * <p>The reference code is as follows. |
Wu-cheng Li | 2fb818c | 2010-09-13 20:02:01 -0700 | [diff] [blame] | 2443 | * |
Eino-Ville Talvala | e0cc55a | 2011-11-08 10:12:09 -0800 | [diff] [blame] | 2444 | * <pre> |
Scott Main | 9a10bf0 | 2011-08-24 19:09:48 -0700 | [diff] [blame] | 2445 | * public void onOrientationChanged(int orientation) { |
Wu-cheng Li | 2fb818c | 2010-09-13 20:02:01 -0700 | [diff] [blame] | 2446 | * if (orientation == ORIENTATION_UNKNOWN) return; |
| 2447 | * android.hardware.Camera.CameraInfo info = |
| 2448 | * new android.hardware.Camera.CameraInfo(); |
| 2449 | * android.hardware.Camera.getCameraInfo(cameraId, info); |
| 2450 | * orientation = (orientation + 45) / 90 * 90; |
Wu-cheng Li | 2fe6fca | 2010-10-15 14:42:23 +0800 | [diff] [blame] | 2451 | * int rotation = 0; |
| 2452 | * if (info.facing == CameraInfo.CAMERA_FACING_FRONT) { |
| 2453 | * rotation = (info.orientation - orientation + 360) % 360; |
| 2454 | * } else { // back-facing camera |
| 2455 | * rotation = (info.orientation + orientation) % 360; |
| 2456 | * } |
| 2457 | * mParameters.setRotation(rotation); |
Wu-cheng Li | 2fb818c | 2010-09-13 20:02:01 -0700 | [diff] [blame] | 2458 | * } |
Eino-Ville Talvala | e0cc55a | 2011-11-08 10:12:09 -0800 | [diff] [blame] | 2459 | * </pre> |
Wu-cheng Li | 2fb818c | 2010-09-13 20:02:01 -0700 | [diff] [blame] | 2460 | * |
| 2461 | * @param rotation The rotation angle in degrees relative to the |
| 2462 | * orientation of the camera. Rotation can only be 0, |
| 2463 | * 90, 180 or 270. |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2464 | * @throws IllegalArgumentException if rotation value is invalid. |
| 2465 | * @see android.view.OrientationEventListener |
Wu-cheng Li | 2fb818c | 2010-09-13 20:02:01 -0700 | [diff] [blame] | 2466 | * @see #getCameraInfo(int, CameraInfo) |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2467 | */ |
| 2468 | public void setRotation(int rotation) { |
| 2469 | if (rotation == 0 || rotation == 90 || rotation == 180 |
| 2470 | || rotation == 270) { |
| 2471 | set(KEY_ROTATION, Integer.toString(rotation)); |
| 2472 | } else { |
| 2473 | throw new IllegalArgumentException( |
| 2474 | "Invalid rotation=" + rotation); |
| 2475 | } |
| 2476 | } |
| 2477 | |
| 2478 | /** |
| 2479 | * Sets GPS latitude coordinate. This will be stored in JPEG EXIF |
| 2480 | * header. |
| 2481 | * |
| 2482 | * @param latitude GPS latitude coordinate. |
| 2483 | */ |
| 2484 | public void setGpsLatitude(double latitude) { |
| 2485 | set(KEY_GPS_LATITUDE, Double.toString(latitude)); |
| 2486 | } |
| 2487 | |
| 2488 | /** |
| 2489 | * Sets GPS longitude coordinate. This will be stored in JPEG EXIF |
| 2490 | * header. |
| 2491 | * |
| 2492 | * @param longitude GPS longitude coordinate. |
| 2493 | */ |
| 2494 | public void setGpsLongitude(double longitude) { |
| 2495 | set(KEY_GPS_LONGITUDE, Double.toString(longitude)); |
| 2496 | } |
| 2497 | |
| 2498 | /** |
| 2499 | * Sets GPS altitude. This will be stored in JPEG EXIF header. |
| 2500 | * |
| 2501 | * @param altitude GPS altitude in meters. |
| 2502 | */ |
| 2503 | public void setGpsAltitude(double altitude) { |
| 2504 | set(KEY_GPS_ALTITUDE, Double.toString(altitude)); |
| 2505 | } |
| 2506 | |
| 2507 | /** |
| 2508 | * Sets GPS timestamp. This will be stored in JPEG EXIF header. |
| 2509 | * |
| 2510 | * @param timestamp GPS timestamp (UTC in seconds since January 1, |
| 2511 | * 1970). |
| 2512 | */ |
| 2513 | public void setGpsTimestamp(long timestamp) { |
| 2514 | set(KEY_GPS_TIMESTAMP, Long.toString(timestamp)); |
| 2515 | } |
| 2516 | |
| 2517 | /** |
Ray Chen | e208377 | 2010-03-10 15:02:49 -0800 | [diff] [blame] | 2518 | * Sets GPS processing method. It will store up to 32 characters |
Ray Chen | 055c986 | 2010-02-23 10:45:42 +0800 | [diff] [blame] | 2519 | * in JPEG EXIF header. |
| 2520 | * |
| 2521 | * @param processing_method The processing method to get this location. |
| 2522 | */ |
| 2523 | public void setGpsProcessingMethod(String processing_method) { |
| 2524 | set(KEY_GPS_PROCESSING_METHOD, processing_method); |
| 2525 | } |
| 2526 | |
| 2527 | /** |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2528 | * Removes GPS latitude, longitude, altitude, and timestamp from the |
| 2529 | * parameters. |
| 2530 | */ |
| 2531 | public void removeGpsData() { |
| 2532 | remove(KEY_GPS_LATITUDE); |
| 2533 | remove(KEY_GPS_LONGITUDE); |
| 2534 | remove(KEY_GPS_ALTITUDE); |
| 2535 | remove(KEY_GPS_TIMESTAMP); |
Ray Chen | 055c986 | 2010-02-23 10:45:42 +0800 | [diff] [blame] | 2536 | remove(KEY_GPS_PROCESSING_METHOD); |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2537 | } |
| 2538 | |
| 2539 | /** |
| 2540 | * Gets the current white balance setting. |
| 2541 | * |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 2542 | * @return current white balance. null if white balance setting is not |
| 2543 | * supported. |
| 2544 | * @see #WHITE_BALANCE_AUTO |
| 2545 | * @see #WHITE_BALANCE_INCANDESCENT |
| 2546 | * @see #WHITE_BALANCE_FLUORESCENT |
| 2547 | * @see #WHITE_BALANCE_WARM_FLUORESCENT |
| 2548 | * @see #WHITE_BALANCE_DAYLIGHT |
| 2549 | * @see #WHITE_BALANCE_CLOUDY_DAYLIGHT |
| 2550 | * @see #WHITE_BALANCE_TWILIGHT |
| 2551 | * @see #WHITE_BALANCE_SHADE |
| 2552 | * |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2553 | */ |
| 2554 | public String getWhiteBalance() { |
| 2555 | return get(KEY_WHITE_BALANCE); |
| 2556 | } |
| 2557 | |
| 2558 | /** |
Eino-Ville Talvala | 16b6713 | 2011-08-18 13:57:49 -0700 | [diff] [blame] | 2559 | * Sets the white balance. Changing the setting will release the |
Wu-cheng Li | b838d8d | 2011-11-17 20:12:23 +0800 | [diff] [blame] | 2560 | * auto-white balance lock. It is recommended not to change white |
| 2561 | * balance and AWB lock at the same time. |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2562 | * |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 2563 | * @param value new white balance. |
| 2564 | * @see #getWhiteBalance() |
Eino-Ville Talvala | 037abb8 | 2011-10-11 12:41:58 -0700 | [diff] [blame] | 2565 | * @see #setAutoWhiteBalanceLock(boolean) |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2566 | */ |
| 2567 | public void setWhiteBalance(String value) { |
Wu-cheng Li | b838d8d | 2011-11-17 20:12:23 +0800 | [diff] [blame] | 2568 | String oldValue = get(KEY_WHITE_BALANCE); |
| 2569 | if (same(value, oldValue)) return; |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2570 | set(KEY_WHITE_BALANCE, value); |
Eino-Ville Talvala | 16b6713 | 2011-08-18 13:57:49 -0700 | [diff] [blame] | 2571 | set(KEY_AUTO_WHITEBALANCE_LOCK, FALSE); |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2572 | } |
| 2573 | |
| 2574 | /** |
| 2575 | * Gets the supported white balance. |
| 2576 | * |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 2577 | * @return a list of supported white balance. null if white balance |
| 2578 | * setting is not supported. |
| 2579 | * @see #getWhiteBalance() |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2580 | */ |
| 2581 | public List<String> getSupportedWhiteBalance() { |
| 2582 | String str = get(KEY_WHITE_BALANCE + SUPPORTED_VALUES_SUFFIX); |
| 2583 | return split(str); |
| 2584 | } |
| 2585 | |
| 2586 | /** |
| 2587 | * Gets the current color effect setting. |
| 2588 | * |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 2589 | * @return current color effect. null if color effect |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2590 | * setting is not supported. |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 2591 | * @see #EFFECT_NONE |
| 2592 | * @see #EFFECT_MONO |
| 2593 | * @see #EFFECT_NEGATIVE |
| 2594 | * @see #EFFECT_SOLARIZE |
| 2595 | * @see #EFFECT_SEPIA |
| 2596 | * @see #EFFECT_POSTERIZE |
| 2597 | * @see #EFFECT_WHITEBOARD |
| 2598 | * @see #EFFECT_BLACKBOARD |
| 2599 | * @see #EFFECT_AQUA |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2600 | */ |
| 2601 | public String getColorEffect() { |
| 2602 | return get(KEY_EFFECT); |
| 2603 | } |
| 2604 | |
| 2605 | /** |
| 2606 | * Sets the current color effect setting. |
| 2607 | * |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 2608 | * @param value new color effect. |
| 2609 | * @see #getColorEffect() |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2610 | */ |
| 2611 | public void setColorEffect(String value) { |
| 2612 | set(KEY_EFFECT, value); |
| 2613 | } |
| 2614 | |
| 2615 | /** |
| 2616 | * Gets the supported color effects. |
| 2617 | * |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 2618 | * @return a list of supported color effects. null if color effect |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2619 | * setting is not supported. |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 2620 | * @see #getColorEffect() |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2621 | */ |
| 2622 | public List<String> getSupportedColorEffects() { |
| 2623 | String str = get(KEY_EFFECT + SUPPORTED_VALUES_SUFFIX); |
| 2624 | return split(str); |
| 2625 | } |
| 2626 | |
| 2627 | |
| 2628 | /** |
| 2629 | * Gets the current antibanding setting. |
| 2630 | * |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 2631 | * @return current antibanding. null if antibanding setting is not |
| 2632 | * supported. |
| 2633 | * @see #ANTIBANDING_AUTO |
| 2634 | * @see #ANTIBANDING_50HZ |
| 2635 | * @see #ANTIBANDING_60HZ |
| 2636 | * @see #ANTIBANDING_OFF |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2637 | */ |
| 2638 | public String getAntibanding() { |
| 2639 | return get(KEY_ANTIBANDING); |
| 2640 | } |
| 2641 | |
| 2642 | /** |
| 2643 | * Sets the antibanding. |
| 2644 | * |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 2645 | * @param antibanding new antibanding value. |
| 2646 | * @see #getAntibanding() |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2647 | */ |
| 2648 | public void setAntibanding(String antibanding) { |
| 2649 | set(KEY_ANTIBANDING, antibanding); |
| 2650 | } |
| 2651 | |
| 2652 | /** |
| 2653 | * Gets the supported antibanding values. |
| 2654 | * |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 2655 | * @return a list of supported antibanding values. null if antibanding |
| 2656 | * setting is not supported. |
| 2657 | * @see #getAntibanding() |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2658 | */ |
| 2659 | public List<String> getSupportedAntibanding() { |
| 2660 | String str = get(KEY_ANTIBANDING + SUPPORTED_VALUES_SUFFIX); |
| 2661 | return split(str); |
| 2662 | } |
| 2663 | |
| 2664 | /** |
| 2665 | * Gets the current scene mode setting. |
| 2666 | * |
| 2667 | * @return one of SCENE_MODE_XXX string constant. null if scene mode |
| 2668 | * setting is not supported. |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 2669 | * @see #SCENE_MODE_AUTO |
| 2670 | * @see #SCENE_MODE_ACTION |
| 2671 | * @see #SCENE_MODE_PORTRAIT |
| 2672 | * @see #SCENE_MODE_LANDSCAPE |
| 2673 | * @see #SCENE_MODE_NIGHT |
| 2674 | * @see #SCENE_MODE_NIGHT_PORTRAIT |
| 2675 | * @see #SCENE_MODE_THEATRE |
| 2676 | * @see #SCENE_MODE_BEACH |
| 2677 | * @see #SCENE_MODE_SNOW |
| 2678 | * @see #SCENE_MODE_SUNSET |
| 2679 | * @see #SCENE_MODE_STEADYPHOTO |
| 2680 | * @see #SCENE_MODE_FIREWORKS |
| 2681 | * @see #SCENE_MODE_SPORTS |
| 2682 | * @see #SCENE_MODE_PARTY |
| 2683 | * @see #SCENE_MODE_CANDLELIGHT |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2684 | */ |
| 2685 | public String getSceneMode() { |
| 2686 | return get(KEY_SCENE_MODE); |
| 2687 | } |
| 2688 | |
| 2689 | /** |
Wu-cheng Li | c58b423 | 2010-03-29 17:21:28 +0800 | [diff] [blame] | 2690 | * Sets the scene mode. Changing scene mode may override other |
| 2691 | * parameters (such as flash mode, focus mode, white balance). For |
| 2692 | * example, suppose originally flash mode is on and supported flash |
| 2693 | * modes are on/off. In night scene mode, both flash mode and supported |
| 2694 | * flash mode may be changed to off. After setting scene mode, |
Wu-cheng Li | 2988ab7 | 2009-09-30 17:08:19 -0700 | [diff] [blame] | 2695 | * applications should call getParameters to know if some parameters are |
| 2696 | * changed. |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2697 | * |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 2698 | * @param value scene mode. |
| 2699 | * @see #getSceneMode() |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2700 | */ |
| 2701 | public void setSceneMode(String value) { |
| 2702 | set(KEY_SCENE_MODE, value); |
| 2703 | } |
| 2704 | |
| 2705 | /** |
| 2706 | * Gets the supported scene modes. |
| 2707 | * |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 2708 | * @return a list of supported scene modes. null if scene mode setting |
| 2709 | * is not supported. |
| 2710 | * @see #getSceneMode() |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2711 | */ |
| 2712 | public List<String> getSupportedSceneModes() { |
| 2713 | String str = get(KEY_SCENE_MODE + SUPPORTED_VALUES_SUFFIX); |
| 2714 | return split(str); |
| 2715 | } |
| 2716 | |
| 2717 | /** |
| 2718 | * Gets the current flash mode setting. |
| 2719 | * |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 2720 | * @return current flash mode. null if flash mode setting is not |
| 2721 | * supported. |
| 2722 | * @see #FLASH_MODE_OFF |
| 2723 | * @see #FLASH_MODE_AUTO |
| 2724 | * @see #FLASH_MODE_ON |
| 2725 | * @see #FLASH_MODE_RED_EYE |
| 2726 | * @see #FLASH_MODE_TORCH |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2727 | */ |
| 2728 | public String getFlashMode() { |
| 2729 | return get(KEY_FLASH_MODE); |
| 2730 | } |
| 2731 | |
| 2732 | /** |
| 2733 | * Sets the flash mode. |
| 2734 | * |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 2735 | * @param value flash mode. |
| 2736 | * @see #getFlashMode() |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2737 | */ |
| 2738 | public void setFlashMode(String value) { |
| 2739 | set(KEY_FLASH_MODE, value); |
| 2740 | } |
| 2741 | |
| 2742 | /** |
| 2743 | * Gets the supported flash modes. |
| 2744 | * |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 2745 | * @return a list of supported flash modes. null if flash mode setting |
| 2746 | * is not supported. |
| 2747 | * @see #getFlashMode() |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2748 | */ |
| 2749 | public List<String> getSupportedFlashModes() { |
| 2750 | String str = get(KEY_FLASH_MODE + SUPPORTED_VALUES_SUFFIX); |
| 2751 | return split(str); |
| 2752 | } |
| 2753 | |
Wu-cheng Li | 36322db | 2009-09-18 18:59:21 +0800 | [diff] [blame] | 2754 | /** |
| 2755 | * Gets the current focus mode setting. |
| 2756 | * |
Wu-cheng Li | 699fe93 | 2010-08-05 11:50:25 -0700 | [diff] [blame] | 2757 | * @return current focus mode. This method will always return a non-null |
| 2758 | * value. Applications should call {@link |
| 2759 | * #autoFocus(AutoFocusCallback)} to start the focus if focus |
| 2760 | * mode is FOCUS_MODE_AUTO or FOCUS_MODE_MACRO. |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 2761 | * @see #FOCUS_MODE_AUTO |
| 2762 | * @see #FOCUS_MODE_INFINITY |
| 2763 | * @see #FOCUS_MODE_MACRO |
| 2764 | * @see #FOCUS_MODE_FIXED |
Wu-cheng Li | f008f3e | 2010-08-17 13:44:35 -0700 | [diff] [blame] | 2765 | * @see #FOCUS_MODE_EDOF |
Wu-cheng Li | d45cb72 | 2010-09-20 16:15:32 -0700 | [diff] [blame] | 2766 | * @see #FOCUS_MODE_CONTINUOUS_VIDEO |
Wu-cheng Li | 36322db | 2009-09-18 18:59:21 +0800 | [diff] [blame] | 2767 | */ |
| 2768 | public String getFocusMode() { |
| 2769 | return get(KEY_FOCUS_MODE); |
| 2770 | } |
| 2771 | |
| 2772 | /** |
| 2773 | * Sets the focus mode. |
| 2774 | * |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 2775 | * @param value focus mode. |
| 2776 | * @see #getFocusMode() |
Wu-cheng Li | 36322db | 2009-09-18 18:59:21 +0800 | [diff] [blame] | 2777 | */ |
| 2778 | public void setFocusMode(String value) { |
| 2779 | set(KEY_FOCUS_MODE, value); |
| 2780 | } |
| 2781 | |
| 2782 | /** |
| 2783 | * Gets the supported focus modes. |
| 2784 | * |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 2785 | * @return a list of supported focus modes. This method will always |
| 2786 | * return a list with at least one element. |
| 2787 | * @see #getFocusMode() |
Wu-cheng Li | 36322db | 2009-09-18 18:59:21 +0800 | [diff] [blame] | 2788 | */ |
| 2789 | public List<String> getSupportedFocusModes() { |
| 2790 | String str = get(KEY_FOCUS_MODE + SUPPORTED_VALUES_SUFFIX); |
| 2791 | return split(str); |
| 2792 | } |
| 2793 | |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 2794 | /** |
Wu-cheng Li | 6c8d276 | 2010-01-27 22:55:14 +0800 | [diff] [blame] | 2795 | * Gets the focal length (in millimeter) of the camera. |
| 2796 | * |
| 2797 | * @return the focal length. This method will always return a valid |
| 2798 | * value. |
| 2799 | */ |
| 2800 | public float getFocalLength() { |
| 2801 | return Float.parseFloat(get(KEY_FOCAL_LENGTH)); |
| 2802 | } |
| 2803 | |
| 2804 | /** |
| 2805 | * Gets the horizontal angle of view in degrees. |
| 2806 | * |
| 2807 | * @return horizontal angle of view. This method will always return a |
| 2808 | * valid value. |
| 2809 | */ |
| 2810 | public float getHorizontalViewAngle() { |
| 2811 | return Float.parseFloat(get(KEY_HORIZONTAL_VIEW_ANGLE)); |
| 2812 | } |
| 2813 | |
| 2814 | /** |
| 2815 | * Gets the vertical angle of view in degrees. |
| 2816 | * |
| 2817 | * @return vertical angle of view. This method will always return a |
| 2818 | * valid value. |
| 2819 | */ |
| 2820 | public float getVerticalViewAngle() { |
| 2821 | return Float.parseFloat(get(KEY_VERTICAL_VIEW_ANGLE)); |
| 2822 | } |
| 2823 | |
| 2824 | /** |
Wu-cheng Li | 24b326a | 2010-02-20 17:47:04 +0800 | [diff] [blame] | 2825 | * Gets the current exposure compensation index. |
Wu-cheng Li | ff723b6c | 2010-02-09 13:38:19 +0800 | [diff] [blame] | 2826 | * |
Wu-cheng Li | 24b326a | 2010-02-20 17:47:04 +0800 | [diff] [blame] | 2827 | * @return current exposure compensation index. The range is {@link |
| 2828 | * #getMinExposureCompensation} to {@link |
| 2829 | * #getMaxExposureCompensation}. 0 means exposure is not |
| 2830 | * adjusted. |
Wu-cheng Li | ff723b6c | 2010-02-09 13:38:19 +0800 | [diff] [blame] | 2831 | */ |
| 2832 | public int getExposureCompensation() { |
Wu-cheng Li | 24b326a | 2010-02-20 17:47:04 +0800 | [diff] [blame] | 2833 | return getInt(KEY_EXPOSURE_COMPENSATION, 0); |
Wu-cheng Li | ff723b6c | 2010-02-09 13:38:19 +0800 | [diff] [blame] | 2834 | } |
| 2835 | |
| 2836 | /** |
Wu-cheng Li | 24b326a | 2010-02-20 17:47:04 +0800 | [diff] [blame] | 2837 | * Sets the exposure compensation index. |
Wu-cheng Li | ff723b6c | 2010-02-09 13:38:19 +0800 | [diff] [blame] | 2838 | * |
Wu-cheng Li | 0402e7d | 2010-02-26 15:04:55 +0800 | [diff] [blame] | 2839 | * @param value exposure compensation index. The valid value range is |
| 2840 | * from {@link #getMinExposureCompensation} (inclusive) to {@link |
Wu-cheng Li | 24b326a | 2010-02-20 17:47:04 +0800 | [diff] [blame] | 2841 | * #getMaxExposureCompensation} (inclusive). 0 means exposure is |
| 2842 | * not adjusted. Application should call |
| 2843 | * getMinExposureCompensation and getMaxExposureCompensation to |
| 2844 | * know if exposure compensation is supported. |
Wu-cheng Li | ff723b6c | 2010-02-09 13:38:19 +0800 | [diff] [blame] | 2845 | */ |
| 2846 | public void setExposureCompensation(int value) { |
| 2847 | set(KEY_EXPOSURE_COMPENSATION, value); |
| 2848 | } |
| 2849 | |
| 2850 | /** |
Wu-cheng Li | 24b326a | 2010-02-20 17:47:04 +0800 | [diff] [blame] | 2851 | * Gets the maximum exposure compensation index. |
Wu-cheng Li | ff723b6c | 2010-02-09 13:38:19 +0800 | [diff] [blame] | 2852 | * |
Wu-cheng Li | 24b326a | 2010-02-20 17:47:04 +0800 | [diff] [blame] | 2853 | * @return maximum exposure compensation index (>=0). If both this |
| 2854 | * method and {@link #getMinExposureCompensation} return 0, |
| 2855 | * exposure compensation is not supported. |
Wu-cheng Li | ff723b6c | 2010-02-09 13:38:19 +0800 | [diff] [blame] | 2856 | */ |
Wu-cheng Li | 24b326a | 2010-02-20 17:47:04 +0800 | [diff] [blame] | 2857 | public int getMaxExposureCompensation() { |
| 2858 | return getInt(KEY_MAX_EXPOSURE_COMPENSATION, 0); |
| 2859 | } |
| 2860 | |
| 2861 | /** |
| 2862 | * Gets the minimum exposure compensation index. |
| 2863 | * |
| 2864 | * @return minimum exposure compensation index (<=0). If both this |
| 2865 | * method and {@link #getMaxExposureCompensation} return 0, |
| 2866 | * exposure compensation is not supported. |
| 2867 | */ |
| 2868 | public int getMinExposureCompensation() { |
| 2869 | return getInt(KEY_MIN_EXPOSURE_COMPENSATION, 0); |
| 2870 | } |
| 2871 | |
| 2872 | /** |
| 2873 | * Gets the exposure compensation step. |
| 2874 | * |
| 2875 | * @return exposure compensation step. Applications can get EV by |
| 2876 | * multiplying the exposure compensation index and step. Ex: if |
| 2877 | * exposure compensation index is -6 and step is 0.333333333, EV |
| 2878 | * is -2. |
| 2879 | */ |
| 2880 | public float getExposureCompensationStep() { |
| 2881 | return getFloat(KEY_EXPOSURE_COMPENSATION_STEP, 0); |
Wu-cheng Li | ff723b6c | 2010-02-09 13:38:19 +0800 | [diff] [blame] | 2882 | } |
| 2883 | |
| 2884 | /** |
Eino-Ville Talvala | d9c2601a | 2011-05-13 10:19:59 -0700 | [diff] [blame] | 2885 | * <p>Sets the auto-exposure lock state. Applications should check |
| 2886 | * {@link #isAutoExposureLockSupported} before using this method.</p> |
Eino-Ville Talvala | 3773eef | 2011-04-15 13:51:42 -0700 | [diff] [blame] | 2887 | * |
Eino-Ville Talvala | d9c2601a | 2011-05-13 10:19:59 -0700 | [diff] [blame] | 2888 | * <p>If set to true, the camera auto-exposure routine will immediately |
| 2889 | * pause until the lock is set to false. Exposure compensation settings |
| 2890 | * changes will still take effect while auto-exposure is locked.</p> |
| 2891 | * |
| 2892 | * <p>If auto-exposure is already locked, setting this to true again has |
| 2893 | * no effect (the driver will not recalculate exposure values).</p> |
| 2894 | * |
| 2895 | * <p>Stopping preview with {@link #stopPreview()}, or triggering still |
| 2896 | * image capture with {@link #takePicture(Camera.ShutterCallback, |
Wu-cheng Li | b4f95be | 2011-09-22 11:43:28 +0800 | [diff] [blame] | 2897 | * Camera.PictureCallback, Camera.PictureCallback)}, will not change the |
| 2898 | * lock.</p> |
Eino-Ville Talvala | d9c2601a | 2011-05-13 10:19:59 -0700 | [diff] [blame] | 2899 | * |
Wu-cheng Li | b4f95be | 2011-09-22 11:43:28 +0800 | [diff] [blame] | 2900 | * <p>Exposure compensation, auto-exposure lock, and auto-white balance |
| 2901 | * lock can be used to capture an exposure-bracketed burst of images, |
| 2902 | * for example.</p> |
Eino-Ville Talvala | d9c2601a | 2011-05-13 10:19:59 -0700 | [diff] [blame] | 2903 | * |
| 2904 | * <p>Auto-exposure state, including the lock state, will not be |
Eino-Ville Talvala | 3773eef | 2011-04-15 13:51:42 -0700 | [diff] [blame] | 2905 | * maintained after camera {@link #release()} is called. Locking |
| 2906 | * auto-exposure after {@link #open()} but before the first call to |
| 2907 | * {@link #startPreview()} will not allow the auto-exposure routine to |
Eino-Ville Talvala | d9c2601a | 2011-05-13 10:19:59 -0700 | [diff] [blame] | 2908 | * run at all, and may result in severely over- or under-exposed |
| 2909 | * images.</p> |
Eino-Ville Talvala | 3773eef | 2011-04-15 13:51:42 -0700 | [diff] [blame] | 2910 | * |
Eino-Ville Talvala | 3773eef | 2011-04-15 13:51:42 -0700 | [diff] [blame] | 2911 | * @param toggle new state of the auto-exposure lock. True means that |
| 2912 | * auto-exposure is locked, false means that the auto-exposure |
| 2913 | * routine is free to run normally. |
| 2914 | * |
Eino-Ville Talvala | d9c2601a | 2011-05-13 10:19:59 -0700 | [diff] [blame] | 2915 | * @see #getAutoExposureLock() |
Eino-Ville Talvala | 3773eef | 2011-04-15 13:51:42 -0700 | [diff] [blame] | 2916 | */ |
| 2917 | public void setAutoExposureLock(boolean toggle) { |
| 2918 | set(KEY_AUTO_EXPOSURE_LOCK, toggle ? TRUE : FALSE); |
| 2919 | } |
| 2920 | |
| 2921 | /** |
| 2922 | * Gets the state of the auto-exposure lock. Applications should check |
| 2923 | * {@link #isAutoExposureLockSupported} before using this method. See |
| 2924 | * {@link #setAutoExposureLock} for details about the lock. |
| 2925 | * |
| 2926 | * @return State of the auto-exposure lock. Returns true if |
Wu-cheng Li | b4f95be | 2011-09-22 11:43:28 +0800 | [diff] [blame] | 2927 | * auto-exposure is currently locked, and false otherwise. |
Eino-Ville Talvala | 3773eef | 2011-04-15 13:51:42 -0700 | [diff] [blame] | 2928 | * |
| 2929 | * @see #setAutoExposureLock(boolean) |
| 2930 | * |
Eino-Ville Talvala | 3773eef | 2011-04-15 13:51:42 -0700 | [diff] [blame] | 2931 | */ |
| 2932 | public boolean getAutoExposureLock() { |
| 2933 | String str = get(KEY_AUTO_EXPOSURE_LOCK); |
| 2934 | return TRUE.equals(str); |
| 2935 | } |
| 2936 | |
| 2937 | /** |
| 2938 | * Returns true if auto-exposure locking is supported. Applications |
| 2939 | * should call this before trying to lock auto-exposure. See |
| 2940 | * {@link #setAutoExposureLock} for details about the lock. |
| 2941 | * |
| 2942 | * @return true if auto-exposure lock is supported. |
| 2943 | * @see #setAutoExposureLock(boolean) |
| 2944 | * |
Eino-Ville Talvala | 3773eef | 2011-04-15 13:51:42 -0700 | [diff] [blame] | 2945 | */ |
| 2946 | public boolean isAutoExposureLockSupported() { |
| 2947 | String str = get(KEY_AUTO_EXPOSURE_LOCK_SUPPORTED); |
| 2948 | return TRUE.equals(str); |
| 2949 | } |
| 2950 | |
| 2951 | /** |
Eino-Ville Talvala | d9c2601a | 2011-05-13 10:19:59 -0700 | [diff] [blame] | 2952 | * <p>Sets the auto-white balance lock state. Applications should check |
| 2953 | * {@link #isAutoWhiteBalanceLockSupported} before using this |
| 2954 | * method.</p> |
| 2955 | * |
| 2956 | * <p>If set to true, the camera auto-white balance routine will |
| 2957 | * immediately pause until the lock is set to false.</p> |
| 2958 | * |
| 2959 | * <p>If auto-white balance is already locked, setting this to true |
| 2960 | * again has no effect (the driver will not recalculate white balance |
| 2961 | * values).</p> |
| 2962 | * |
| 2963 | * <p>Stopping preview with {@link #stopPreview()}, or triggering still |
| 2964 | * image capture with {@link #takePicture(Camera.ShutterCallback, |
Wu-cheng Li | b4f95be | 2011-09-22 11:43:28 +0800 | [diff] [blame] | 2965 | * Camera.PictureCallback, Camera.PictureCallback)}, will not change the |
| 2966 | * the lock.</p> |
Eino-Ville Talvala | d9c2601a | 2011-05-13 10:19:59 -0700 | [diff] [blame] | 2967 | * |
Eino-Ville Talvala | 16b6713 | 2011-08-18 13:57:49 -0700 | [diff] [blame] | 2968 | * <p> Changing the white balance mode with {@link #setWhiteBalance} |
| 2969 | * will release the auto-white balance lock if it is set.</p> |
| 2970 | * |
Wu-cheng Li | b4f95be | 2011-09-22 11:43:28 +0800 | [diff] [blame] | 2971 | * <p>Exposure compensation, AE lock, and AWB lock can be used to |
| 2972 | * capture an exposure-bracketed burst of images, for example. |
| 2973 | * Auto-white balance state, including the lock state, will not be |
| 2974 | * maintained after camera {@link #release()} is called. Locking |
| 2975 | * auto-white balance after {@link #open()} but before the first call to |
| 2976 | * {@link #startPreview()} will not allow the auto-white balance routine |
| 2977 | * to run at all, and may result in severely incorrect color in captured |
| 2978 | * images.</p> |
Eino-Ville Talvala | d9c2601a | 2011-05-13 10:19:59 -0700 | [diff] [blame] | 2979 | * |
| 2980 | * @param toggle new state of the auto-white balance lock. True means |
| 2981 | * that auto-white balance is locked, false means that the |
| 2982 | * auto-white balance routine is free to run normally. |
| 2983 | * |
| 2984 | * @see #getAutoWhiteBalanceLock() |
Eino-Ville Talvala | 16b6713 | 2011-08-18 13:57:49 -0700 | [diff] [blame] | 2985 | * @see #setWhiteBalance(String) |
Eino-Ville Talvala | d9c2601a | 2011-05-13 10:19:59 -0700 | [diff] [blame] | 2986 | */ |
| 2987 | public void setAutoWhiteBalanceLock(boolean toggle) { |
| 2988 | set(KEY_AUTO_WHITEBALANCE_LOCK, toggle ? TRUE : FALSE); |
| 2989 | } |
| 2990 | |
| 2991 | /** |
| 2992 | * Gets the state of the auto-white balance lock. Applications should |
| 2993 | * check {@link #isAutoWhiteBalanceLockSupported} before using this |
| 2994 | * method. See {@link #setAutoWhiteBalanceLock} for details about the |
| 2995 | * lock. |
| 2996 | * |
| 2997 | * @return State of the auto-white balance lock. Returns true if |
| 2998 | * auto-white balance is currently locked, and false |
Wu-cheng Li | b4f95be | 2011-09-22 11:43:28 +0800 | [diff] [blame] | 2999 | * otherwise. |
Eino-Ville Talvala | d9c2601a | 2011-05-13 10:19:59 -0700 | [diff] [blame] | 3000 | * |
| 3001 | * @see #setAutoWhiteBalanceLock(boolean) |
| 3002 | * |
Eino-Ville Talvala | d9c2601a | 2011-05-13 10:19:59 -0700 | [diff] [blame] | 3003 | */ |
| 3004 | public boolean getAutoWhiteBalanceLock() { |
| 3005 | String str = get(KEY_AUTO_WHITEBALANCE_LOCK); |
| 3006 | return TRUE.equals(str); |
| 3007 | } |
| 3008 | |
| 3009 | /** |
| 3010 | * Returns true if auto-white balance locking is supported. Applications |
| 3011 | * should call this before trying to lock auto-white balance. See |
| 3012 | * {@link #setAutoWhiteBalanceLock} for details about the lock. |
| 3013 | * |
| 3014 | * @return true if auto-white balance lock is supported. |
| 3015 | * @see #setAutoWhiteBalanceLock(boolean) |
| 3016 | * |
Eino-Ville Talvala | d9c2601a | 2011-05-13 10:19:59 -0700 | [diff] [blame] | 3017 | */ |
| 3018 | public boolean isAutoWhiteBalanceLockSupported() { |
| 3019 | String str = get(KEY_AUTO_WHITEBALANCE_LOCK_SUPPORTED); |
| 3020 | return TRUE.equals(str); |
| 3021 | } |
| 3022 | |
| 3023 | /** |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 3024 | * Gets current zoom value. This also works when smooth zoom is in |
Wu-cheng Li | 8cbb8f5 | 2010-02-28 23:19:55 -0800 | [diff] [blame] | 3025 | * progress. Applications should check {@link #isZoomSupported} before |
| 3026 | * using this method. |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 3027 | * |
| 3028 | * @return the current zoom value. The range is 0 to {@link |
Wu-cheng Li | 8cbb8f5 | 2010-02-28 23:19:55 -0800 | [diff] [blame] | 3029 | * #getMaxZoom}. 0 means the camera is not zoomed. |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 3030 | */ |
| 3031 | public int getZoom() { |
Wu-cheng Li | 8cbb8f5 | 2010-02-28 23:19:55 -0800 | [diff] [blame] | 3032 | return getInt(KEY_ZOOM, 0); |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 3033 | } |
| 3034 | |
| 3035 | /** |
Wu-cheng Li | 8cbb8f5 | 2010-02-28 23:19:55 -0800 | [diff] [blame] | 3036 | * Sets current zoom value. If the camera is zoomed (value > 0), the |
| 3037 | * actual picture size may be smaller than picture size setting. |
| 3038 | * Applications can check the actual picture size after picture is |
| 3039 | * returned from {@link PictureCallback}. The preview size remains the |
| 3040 | * same in zoom. Applications should check {@link #isZoomSupported} |
| 3041 | * before using this method. |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 3042 | * |
| 3043 | * @param value zoom value. The valid range is 0 to {@link #getMaxZoom}. |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 3044 | */ |
| 3045 | public void setZoom(int value) { |
Wu-cheng Li | 8cbb8f5 | 2010-02-28 23:19:55 -0800 | [diff] [blame] | 3046 | set(KEY_ZOOM, value); |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 3047 | } |
| 3048 | |
| 3049 | /** |
| 3050 | * Returns true if zoom is supported. Applications should call this |
| 3051 | * before using other zoom methods. |
| 3052 | * |
| 3053 | * @return true if zoom is supported. |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 3054 | */ |
| 3055 | public boolean isZoomSupported() { |
Wu-cheng Li | 8cbb8f5 | 2010-02-28 23:19:55 -0800 | [diff] [blame] | 3056 | String str = get(KEY_ZOOM_SUPPORTED); |
| 3057 | return TRUE.equals(str); |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 3058 | } |
| 3059 | |
| 3060 | /** |
| 3061 | * Gets the maximum zoom value allowed for snapshot. This is the maximum |
| 3062 | * value that applications can set to {@link #setZoom(int)}. |
Wu-cheng Li | 8cbb8f5 | 2010-02-28 23:19:55 -0800 | [diff] [blame] | 3063 | * Applications should call {@link #isZoomSupported} before using this |
| 3064 | * method. This value may change in different preview size. Applications |
| 3065 | * should call this again after setting preview size. |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 3066 | * |
| 3067 | * @return the maximum zoom value supported by the camera. |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 3068 | */ |
| 3069 | public int getMaxZoom() { |
Wu-cheng Li | 8cbb8f5 | 2010-02-28 23:19:55 -0800 | [diff] [blame] | 3070 | return getInt(KEY_MAX_ZOOM, 0); |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 3071 | } |
| 3072 | |
| 3073 | /** |
Wu-cheng Li | 8cbb8f5 | 2010-02-28 23:19:55 -0800 | [diff] [blame] | 3074 | * Gets the zoom ratios of all zoom values. Applications should check |
| 3075 | * {@link #isZoomSupported} before using this method. |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 3076 | * |
Wu-cheng Li | 8cbb8f5 | 2010-02-28 23:19:55 -0800 | [diff] [blame] | 3077 | * @return the zoom ratios in 1/100 increments. Ex: a zoom of 3.2x is |
| 3078 | * returned as 320. The number of elements is {@link |
| 3079 | * #getMaxZoom} + 1. The list is sorted from small to large. The |
| 3080 | * first element is always 100. The last element is the zoom |
| 3081 | * ratio of the maximum zoom value. |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 3082 | */ |
Wu-cheng Li | 8cbb8f5 | 2010-02-28 23:19:55 -0800 | [diff] [blame] | 3083 | public List<Integer> getZoomRatios() { |
| 3084 | return splitInt(get(KEY_ZOOM_RATIOS)); |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 3085 | } |
| 3086 | |
| 3087 | /** |
| 3088 | * Returns true if smooth zoom is supported. Applications should call |
| 3089 | * this before using other smooth zoom methods. |
| 3090 | * |
| 3091 | * @return true if smooth zoom is supported. |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 3092 | */ |
| 3093 | public boolean isSmoothZoomSupported() { |
Wu-cheng Li | 8cbb8f5 | 2010-02-28 23:19:55 -0800 | [diff] [blame] | 3094 | String str = get(KEY_SMOOTH_ZOOM_SUPPORTED); |
| 3095 | return TRUE.equals(str); |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 3096 | } |
| 3097 | |
Wu-cheng Li | e339c5e | 2010-05-13 19:31:02 +0800 | [diff] [blame] | 3098 | /** |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 3099 | * <p>Gets the distances from the camera to where an object appears to be |
Wu-cheng Li | e339c5e | 2010-05-13 19:31:02 +0800 | [diff] [blame] | 3100 | * in focus. The object is sharpest at the optimal focus distance. The |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 3101 | * depth of field is the far focus distance minus near focus distance.</p> |
Wu-cheng Li | e339c5e | 2010-05-13 19:31:02 +0800 | [diff] [blame] | 3102 | * |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 3103 | * <p>Focus distances may change after calling {@link |
Wu-cheng Li | e339c5e | 2010-05-13 19:31:02 +0800 | [diff] [blame] | 3104 | * #autoFocus(AutoFocusCallback)}, {@link #cancelAutoFocus}, or {@link |
| 3105 | * #startPreview()}. Applications can call {@link #getParameters()} |
| 3106 | * and this method anytime to get the latest focus distances. If the |
Wu-cheng Li | d45cb72 | 2010-09-20 16:15:32 -0700 | [diff] [blame] | 3107 | * focus mode is FOCUS_MODE_CONTINUOUS_VIDEO, focus distances may change |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 3108 | * from time to time.</p> |
Wu-cheng Li | 699fe93 | 2010-08-05 11:50:25 -0700 | [diff] [blame] | 3109 | * |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 3110 | * <p>This method is intended to estimate the distance between the camera |
Wu-cheng Li | 699fe93 | 2010-08-05 11:50:25 -0700 | [diff] [blame] | 3111 | * and the subject. After autofocus, the subject distance may be within |
| 3112 | * near and far focus distance. However, the precision depends on the |
| 3113 | * camera hardware, autofocus algorithm, the focus area, and the scene. |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 3114 | * The error can be large and it should be only used as a reference.</p> |
Wu-cheng Li | e339c5e | 2010-05-13 19:31:02 +0800 | [diff] [blame] | 3115 | * |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 3116 | * <p>Far focus distance >= optimal focus distance >= near focus distance. |
Wu-cheng Li | 185cc45 | 2010-05-20 15:36:13 +0800 | [diff] [blame] | 3117 | * If the focus distance is infinity, the value will be |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 3118 | * {@code Float.POSITIVE_INFINITY}.</p> |
Wu-cheng Li | e339c5e | 2010-05-13 19:31:02 +0800 | [diff] [blame] | 3119 | * |
| 3120 | * @param output focus distances in meters. output must be a float |
| 3121 | * array with three elements. Near focus distance, optimal focus |
| 3122 | * distance, and far focus distance will be filled in the array. |
Wu-cheng Li | 185cc45 | 2010-05-20 15:36:13 +0800 | [diff] [blame] | 3123 | * @see #FOCUS_DISTANCE_NEAR_INDEX |
| 3124 | * @see #FOCUS_DISTANCE_OPTIMAL_INDEX |
| 3125 | * @see #FOCUS_DISTANCE_FAR_INDEX |
Wu-cheng Li | e339c5e | 2010-05-13 19:31:02 +0800 | [diff] [blame] | 3126 | */ |
| 3127 | public void getFocusDistances(float[] output) { |
| 3128 | if (output == null || output.length != 3) { |
| 3129 | throw new IllegalArgumentException( |
Ken Wakasa | f76a50c | 2012-03-09 19:56:35 +0900 | [diff] [blame] | 3130 | "output must be a float array with three elements."); |
Wu-cheng Li | e339c5e | 2010-05-13 19:31:02 +0800 | [diff] [blame] | 3131 | } |
Wu-cheng Li | 454630f | 2010-08-11 16:48:05 -0700 | [diff] [blame] | 3132 | splitFloat(get(KEY_FOCUS_DISTANCES), output); |
Wu-cheng Li | e339c5e | 2010-05-13 19:31:02 +0800 | [diff] [blame] | 3133 | } |
| 3134 | |
Wu-cheng Li | 30771b7 | 2011-04-02 06:19:46 +0800 | [diff] [blame] | 3135 | /** |
| 3136 | * Gets the maximum number of focus areas supported. This is the maximum |
Wu-cheng Li | 7b1c5c8 | 2011-04-15 19:16:52 +0800 | [diff] [blame] | 3137 | * length of the list in {@link #setFocusAreas(List)} and |
| 3138 | * {@link #getFocusAreas()}. |
Wu-cheng Li | 30771b7 | 2011-04-02 06:19:46 +0800 | [diff] [blame] | 3139 | * |
| 3140 | * @return the maximum number of focus areas supported by the camera. |
| 3141 | * @see #getFocusAreas() |
Wu-cheng Li | 30771b7 | 2011-04-02 06:19:46 +0800 | [diff] [blame] | 3142 | */ |
| 3143 | public int getMaxNumFocusAreas() { |
| 3144 | return getInt(KEY_MAX_NUM_FOCUS_AREAS, 0); |
| 3145 | } |
| 3146 | |
| 3147 | /** |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 3148 | * <p>Gets the current focus areas. Camera driver uses the areas to decide |
| 3149 | * focus.</p> |
Wu-cheng Li | 30771b7 | 2011-04-02 06:19:46 +0800 | [diff] [blame] | 3150 | * |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 3151 | * <p>Before using this API or {@link #setFocusAreas(List)}, apps should |
Wu-cheng Li | 7b1c5c8 | 2011-04-15 19:16:52 +0800 | [diff] [blame] | 3152 | * call {@link #getMaxNumFocusAreas()} to know the maximum number of |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 3153 | * focus areas first. If the value is 0, focus area is not supported.</p> |
Wu-cheng Li | 30771b7 | 2011-04-02 06:19:46 +0800 | [diff] [blame] | 3154 | * |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 3155 | * <p>Each focus area is a rectangle with specified weight. The direction |
Wu-cheng Li | 30771b7 | 2011-04-02 06:19:46 +0800 | [diff] [blame] | 3156 | * is relative to the sensor orientation, that is, what the sensor sees. |
| 3157 | * The direction is not affected by the rotation or mirroring of |
| 3158 | * {@link #setDisplayOrientation(int)}. Coordinates of the rectangle |
| 3159 | * range from -1000 to 1000. (-1000, -1000) is the upper left point. |
Wu-cheng Li | bde61a5 | 2011-06-07 18:23:14 +0800 | [diff] [blame] | 3160 | * (1000, 1000) is the lower right point. The width and height of focus |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 3161 | * areas cannot be 0 or negative.</p> |
Wu-cheng Li | 30771b7 | 2011-04-02 06:19:46 +0800 | [diff] [blame] | 3162 | * |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 3163 | * <p>The weight must range from 1 to 1000. The weight should be |
Eino-Ville Talvala | 4e396e0 | 2011-04-21 09:23:15 -0700 | [diff] [blame] | 3164 | * interpreted as a per-pixel weight - all pixels in the area have the |
| 3165 | * specified weight. This means a small area with the same weight as a |
| 3166 | * larger area will have less influence on the focusing than the larger |
| 3167 | * area. Focus areas can partially overlap and the driver will add the |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 3168 | * weights in the overlap region.</p> |
Wu-cheng Li | 30771b7 | 2011-04-02 06:19:46 +0800 | [diff] [blame] | 3169 | * |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 3170 | * <p>A special case of a {@code null} focus area list means the driver is |
| 3171 | * free to select focus targets as it wants. For example, the driver may |
| 3172 | * use more signals to select focus areas and change them |
| 3173 | * dynamically. Apps can set the focus area list to {@code null} if they |
| 3174 | * want the driver to completely control focusing.</p> |
Wu-cheng Li | 30771b7 | 2011-04-02 06:19:46 +0800 | [diff] [blame] | 3175 | * |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 3176 | * <p>Focus areas are relative to the current field of view |
Wu-cheng Li | 30771b7 | 2011-04-02 06:19:46 +0800 | [diff] [blame] | 3177 | * ({@link #getZoom()}). No matter what the zoom level is, (-1000,-1000) |
| 3178 | * represents the top of the currently visible camera frame. The focus |
| 3179 | * area cannot be set to be outside the current field of view, even |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 3180 | * when using zoom.</p> |
Wu-cheng Li | 30771b7 | 2011-04-02 06:19:46 +0800 | [diff] [blame] | 3181 | * |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 3182 | * <p>Focus area only has effect if the current focus mode is |
Wu-cheng Li | 53b3091 | 2011-10-12 19:43:51 +0800 | [diff] [blame] | 3183 | * {@link #FOCUS_MODE_AUTO}, {@link #FOCUS_MODE_MACRO}, |
| 3184 | * {@link #FOCUS_MODE_CONTINUOUS_VIDEO}, or |
| 3185 | * {@link #FOCUS_MODE_CONTINUOUS_PICTURE}.</p> |
Wu-cheng Li | 30771b7 | 2011-04-02 06:19:46 +0800 | [diff] [blame] | 3186 | * |
| 3187 | * @return a list of current focus areas |
Wu-cheng Li | 30771b7 | 2011-04-02 06:19:46 +0800 | [diff] [blame] | 3188 | */ |
| 3189 | public List<Area> getFocusAreas() { |
Wu-cheng Li | f715bf9 | 2011-04-14 14:04:18 +0800 | [diff] [blame] | 3190 | return splitArea(get(KEY_FOCUS_AREAS)); |
Wu-cheng Li | 30771b7 | 2011-04-02 06:19:46 +0800 | [diff] [blame] | 3191 | } |
| 3192 | |
| 3193 | /** |
| 3194 | * Sets focus areas. See {@link #getFocusAreas()} for documentation. |
| 3195 | * |
Wu-cheng Li | 7b1c5c8 | 2011-04-15 19:16:52 +0800 | [diff] [blame] | 3196 | * @param focusAreas the focus areas |
Wu-cheng Li | 30771b7 | 2011-04-02 06:19:46 +0800 | [diff] [blame] | 3197 | * @see #getFocusAreas() |
Wu-cheng Li | 30771b7 | 2011-04-02 06:19:46 +0800 | [diff] [blame] | 3198 | */ |
Wu-cheng Li | e98e4c8 | 2011-04-12 19:34:29 +0800 | [diff] [blame] | 3199 | public void setFocusAreas(List<Area> focusAreas) { |
| 3200 | set(KEY_FOCUS_AREAS, focusAreas); |
| 3201 | } |
| 3202 | |
| 3203 | /** |
| 3204 | * Gets the maximum number of metering areas supported. This is the |
Wu-cheng Li | 7b1c5c8 | 2011-04-15 19:16:52 +0800 | [diff] [blame] | 3205 | * maximum length of the list in {@link #setMeteringAreas(List)} and |
| 3206 | * {@link #getMeteringAreas()}. |
Wu-cheng Li | e98e4c8 | 2011-04-12 19:34:29 +0800 | [diff] [blame] | 3207 | * |
| 3208 | * @return the maximum number of metering areas supported by the camera. |
| 3209 | * @see #getMeteringAreas() |
Wu-cheng Li | e98e4c8 | 2011-04-12 19:34:29 +0800 | [diff] [blame] | 3210 | */ |
| 3211 | public int getMaxNumMeteringAreas() { |
| 3212 | return getInt(KEY_MAX_NUM_METERING_AREAS, 0); |
| 3213 | } |
| 3214 | |
| 3215 | /** |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 3216 | * <p>Gets the current metering areas. Camera driver uses these areas to |
| 3217 | * decide exposure.</p> |
Wu-cheng Li | e98e4c8 | 2011-04-12 19:34:29 +0800 | [diff] [blame] | 3218 | * |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 3219 | * <p>Before using this API or {@link #setMeteringAreas(List)}, apps should |
Wu-cheng Li | 7b1c5c8 | 2011-04-15 19:16:52 +0800 | [diff] [blame] | 3220 | * call {@link #getMaxNumMeteringAreas()} to know the maximum number of |
| 3221 | * metering areas first. If the value is 0, metering area is not |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 3222 | * supported.</p> |
Wu-cheng Li | e98e4c8 | 2011-04-12 19:34:29 +0800 | [diff] [blame] | 3223 | * |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 3224 | * <p>Each metering area is a rectangle with specified weight. The |
Wu-cheng Li | e98e4c8 | 2011-04-12 19:34:29 +0800 | [diff] [blame] | 3225 | * direction is relative to the sensor orientation, that is, what the |
| 3226 | * sensor sees. The direction is not affected by the rotation or |
| 3227 | * mirroring of {@link #setDisplayOrientation(int)}. Coordinates of the |
| 3228 | * rectangle range from -1000 to 1000. (-1000, -1000) is the upper left |
Wu-cheng Li | bde61a5 | 2011-06-07 18:23:14 +0800 | [diff] [blame] | 3229 | * point. (1000, 1000) is the lower right point. The width and height of |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 3230 | * metering areas cannot be 0 or negative.</p> |
Wu-cheng Li | e98e4c8 | 2011-04-12 19:34:29 +0800 | [diff] [blame] | 3231 | * |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 3232 | * <p>The weight must range from 1 to 1000, and represents a weight for |
Eino-Ville Talvala | 4e396e0 | 2011-04-21 09:23:15 -0700 | [diff] [blame] | 3233 | * every pixel in the area. This means that a large metering area with |
| 3234 | * the same weight as a smaller area will have more effect in the |
| 3235 | * metering result. Metering areas can partially overlap and the driver |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 3236 | * will add the weights in the overlap region.</p> |
Wu-cheng Li | e98e4c8 | 2011-04-12 19:34:29 +0800 | [diff] [blame] | 3237 | * |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 3238 | * <p>A special case of a {@code null} metering area list means the driver |
| 3239 | * is free to meter as it chooses. For example, the driver may use more |
| 3240 | * signals to select metering areas and change them dynamically. Apps |
| 3241 | * can set the metering area list to {@code null} if they want the |
| 3242 | * driver to completely control metering.</p> |
Wu-cheng Li | e98e4c8 | 2011-04-12 19:34:29 +0800 | [diff] [blame] | 3243 | * |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 3244 | * <p>Metering areas are relative to the current field of view |
Wu-cheng Li | e98e4c8 | 2011-04-12 19:34:29 +0800 | [diff] [blame] | 3245 | * ({@link #getZoom()}). No matter what the zoom level is, (-1000,-1000) |
| 3246 | * represents the top of the currently visible camera frame. The |
| 3247 | * metering area cannot be set to be outside the current field of view, |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 3248 | * even when using zoom.</p> |
Wu-cheng Li | e98e4c8 | 2011-04-12 19:34:29 +0800 | [diff] [blame] | 3249 | * |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 3250 | * <p>No matter what metering areas are, the final exposure are compensated |
| 3251 | * by {@link #setExposureCompensation(int)}.</p> |
Wu-cheng Li | e98e4c8 | 2011-04-12 19:34:29 +0800 | [diff] [blame] | 3252 | * |
| 3253 | * @return a list of current metering areas |
Wu-cheng Li | e98e4c8 | 2011-04-12 19:34:29 +0800 | [diff] [blame] | 3254 | */ |
| 3255 | public List<Area> getMeteringAreas() { |
Wu-cheng Li | d8aab93 | 2011-06-21 11:50:43 +0800 | [diff] [blame] | 3256 | return splitArea(get(KEY_METERING_AREAS)); |
Wu-cheng Li | e98e4c8 | 2011-04-12 19:34:29 +0800 | [diff] [blame] | 3257 | } |
| 3258 | |
| 3259 | /** |
| 3260 | * Sets metering areas. See {@link #getMeteringAreas()} for |
| 3261 | * documentation. |
| 3262 | * |
Wu-cheng Li | 7b1c5c8 | 2011-04-15 19:16:52 +0800 | [diff] [blame] | 3263 | * @param meteringAreas the metering areas |
Wu-cheng Li | e98e4c8 | 2011-04-12 19:34:29 +0800 | [diff] [blame] | 3264 | * @see #getMeteringAreas() |
Wu-cheng Li | e98e4c8 | 2011-04-12 19:34:29 +0800 | [diff] [blame] | 3265 | */ |
| 3266 | public void setMeteringAreas(List<Area> meteringAreas) { |
| 3267 | set(KEY_METERING_AREAS, meteringAreas); |
Wu-cheng Li | 30771b7 | 2011-04-02 06:19:46 +0800 | [diff] [blame] | 3268 | } |
| 3269 | |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 3270 | /** |
| 3271 | * Gets the maximum number of detected faces supported. This is the |
| 3272 | * maximum length of the list returned from {@link FaceDetectionListener}. |
| 3273 | * If the return value is 0, face detection of the specified type is not |
| 3274 | * supported. |
| 3275 | * |
| 3276 | * @return the maximum number of detected face supported by the camera. |
Joe Fernandez | 464cb21 | 2011-10-04 16:56:47 -0700 | [diff] [blame] | 3277 | * @see #startFaceDetection() |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 3278 | */ |
Wu-cheng Li | c0c683b | 2011-08-04 00:11:00 +0800 | [diff] [blame] | 3279 | public int getMaxNumDetectedFaces() { |
| 3280 | return getInt(KEY_MAX_NUM_DETECTED_FACES_HW, 0); |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 3281 | } |
| 3282 | |
Wu-cheng Li | 25d8fb5 | 2011-08-02 13:20:36 +0800 | [diff] [blame] | 3283 | /** |
Wu-cheng Li | 9c53f1c | 2011-08-02 17:26:58 +0800 | [diff] [blame] | 3284 | * Sets recording mode hint. This tells the camera that the intent of |
| 3285 | * the application is to record videos {@link |
| 3286 | * android.media.MediaRecorder#start()}, not to take still pictures |
| 3287 | * {@link #takePicture(Camera.ShutterCallback, Camera.PictureCallback, |
| 3288 | * Camera.PictureCallback, Camera.PictureCallback)}. Using this hint can |
| 3289 | * allow MediaRecorder.start() to start faster or with fewer glitches on |
| 3290 | * output. This should be called before starting preview for the best |
| 3291 | * result, but can be changed while the preview is active. The default |
| 3292 | * value is false. |
Wu-cheng Li | 25d8fb5 | 2011-08-02 13:20:36 +0800 | [diff] [blame] | 3293 | * |
Wu-cheng Li | 9c53f1c | 2011-08-02 17:26:58 +0800 | [diff] [blame] | 3294 | * The app can still call takePicture() when the hint is true or call |
| 3295 | * MediaRecorder.start() when the hint is false. But the performance may |
| 3296 | * be worse. |
Wu-cheng Li | 25d8fb5 | 2011-08-02 13:20:36 +0800 | [diff] [blame] | 3297 | * |
Wu-cheng Li | 9c53f1c | 2011-08-02 17:26:58 +0800 | [diff] [blame] | 3298 | * @param hint true if the apps intend to record videos using |
Wu-cheng Li | 25d8fb5 | 2011-08-02 13:20:36 +0800 | [diff] [blame] | 3299 | * {@link android.media.MediaRecorder}. |
Wu-cheng Li | 25d8fb5 | 2011-08-02 13:20:36 +0800 | [diff] [blame] | 3300 | */ |
| 3301 | public void setRecordingHint(boolean hint) { |
| 3302 | set(KEY_RECORDING_HINT, hint ? TRUE : FALSE); |
| 3303 | } |
| 3304 | |
Wu-cheng Li | 98bb251 | 2011-08-30 21:33:10 +0800 | [diff] [blame] | 3305 | /** |
| 3306 | * Returns true if video snapshot is supported. That is, applications |
| 3307 | * can call {@link #takePicture(Camera.ShutterCallback, |
| 3308 | * Camera.PictureCallback, Camera.PictureCallback, Camera.PictureCallback)} |
| 3309 | * during recording. Applications do not need to call {@link |
| 3310 | * #startPreview()} after taking a picture. The preview will be still |
| 3311 | * active. Other than that, taking a picture during recording is |
| 3312 | * identical to taking a picture normally. All settings and methods |
| 3313 | * related to takePicture work identically. Ex: {@link |
| 3314 | * #getPictureSize()}, {@link #getSupportedPictureSizes()}, {@link |
| 3315 | * #setJpegQuality(int)}, {@link #setRotation(int)}, and etc. The |
| 3316 | * picture will have an EXIF header. {@link #FLASH_MODE_AUTO} and {@link |
| 3317 | * #FLASH_MODE_ON} also still work, but the video will record the flash. |
| 3318 | * |
| 3319 | * Applications can set shutter callback as null to avoid the shutter |
| 3320 | * sound. It is also recommended to set raw picture and post view |
| 3321 | * callbacks to null to avoid the interrupt of preview display. |
| 3322 | * |
| 3323 | * Field-of-view of the recorded video may be different from that of the |
| 3324 | * captured pictures. |
| 3325 | * |
| 3326 | * @return true if video snapshot is supported. |
Wu-cheng Li | 98bb251 | 2011-08-30 21:33:10 +0800 | [diff] [blame] | 3327 | */ |
| 3328 | public boolean isVideoSnapshotSupported() { |
| 3329 | String str = get(KEY_VIDEO_SNAPSHOT_SUPPORTED); |
| 3330 | return TRUE.equals(str); |
| 3331 | } |
| 3332 | |
Eino-Ville Talvala | 037abb8 | 2011-10-11 12:41:58 -0700 | [diff] [blame] | 3333 | /** |
| 3334 | * <p>Enables and disables video stabilization. Use |
| 3335 | * {@link #isVideoStabilizationSupported} to determine if calling this |
| 3336 | * method is valid.</p> |
| 3337 | * |
| 3338 | * <p>Video stabilization reduces the shaking due to the motion of the |
| 3339 | * camera in both the preview stream and in recorded videos, including |
| 3340 | * data received from the preview callback. It does not reduce motion |
| 3341 | * blur in images captured with |
| 3342 | * {@link Camera#takePicture takePicture}.</p> |
| 3343 | * |
| 3344 | * <p>Video stabilization can be enabled and disabled while preview or |
| 3345 | * recording is active, but toggling it may cause a jump in the video |
| 3346 | * stream that may be undesirable in a recorded video.</p> |
| 3347 | * |
| 3348 | * @param toggle Set to true to enable video stabilization, and false to |
| 3349 | * disable video stabilization. |
| 3350 | * @see #isVideoStabilizationSupported() |
| 3351 | * @see #getVideoStabilization() |
Eino-Ville Talvala | 037abb8 | 2011-10-11 12:41:58 -0700 | [diff] [blame] | 3352 | */ |
| 3353 | public void setVideoStabilization(boolean toggle) { |
| 3354 | set(KEY_VIDEO_STABILIZATION, toggle ? TRUE : FALSE); |
| 3355 | } |
| 3356 | |
| 3357 | /** |
| 3358 | * Get the current state of video stabilization. See |
| 3359 | * {@link #setVideoStabilization} for details of video stabilization. |
| 3360 | * |
| 3361 | * @return true if video stabilization is enabled |
| 3362 | * @see #isVideoStabilizationSupported() |
| 3363 | * @see #setVideoStabilization(boolean) |
Eino-Ville Talvala | 037abb8 | 2011-10-11 12:41:58 -0700 | [diff] [blame] | 3364 | */ |
| 3365 | public boolean getVideoStabilization() { |
| 3366 | String str = get(KEY_VIDEO_STABILIZATION); |
| 3367 | return TRUE.equals(str); |
| 3368 | } |
| 3369 | |
| 3370 | /** |
| 3371 | * Returns true if video stabilization is supported. See |
| 3372 | * {@link #setVideoStabilization} for details of video stabilization. |
| 3373 | * |
| 3374 | * @return true if video stabilization is supported |
| 3375 | * @see #setVideoStabilization(boolean) |
| 3376 | * @see #getVideoStabilization() |
Eino-Ville Talvala | 037abb8 | 2011-10-11 12:41:58 -0700 | [diff] [blame] | 3377 | */ |
| 3378 | public boolean isVideoStabilizationSupported() { |
| 3379 | String str = get(KEY_VIDEO_STABILIZATION_SUPPORTED); |
| 3380 | return TRUE.equals(str); |
| 3381 | } |
| 3382 | |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3383 | // Splits a comma delimited string to an ArrayList of String. |
| 3384 | // Return null if the passing string is null or the size is 0. |
| 3385 | private ArrayList<String> split(String str) { |
| 3386 | if (str == null) return null; |
| 3387 | |
| 3388 | // Use StringTokenizer because it is faster than split. |
| 3389 | StringTokenizer tokenizer = new StringTokenizer(str, ","); |
| 3390 | ArrayList<String> substrings = new ArrayList<String>(); |
| 3391 | while (tokenizer.hasMoreElements()) { |
| 3392 | substrings.add(tokenizer.nextToken()); |
| 3393 | } |
| 3394 | return substrings; |
| 3395 | } |
| 3396 | |
| 3397 | // Splits a comma delimited string to an ArrayList of Integer. |
| 3398 | // Return null if the passing string is null or the size is 0. |
| 3399 | private ArrayList<Integer> splitInt(String str) { |
| 3400 | if (str == null) return null; |
| 3401 | |
| 3402 | StringTokenizer tokenizer = new StringTokenizer(str, ","); |
| 3403 | ArrayList<Integer> substrings = new ArrayList<Integer>(); |
| 3404 | while (tokenizer.hasMoreElements()) { |
| 3405 | String token = tokenizer.nextToken(); |
| 3406 | substrings.add(Integer.parseInt(token)); |
| 3407 | } |
| 3408 | if (substrings.size() == 0) return null; |
| 3409 | return substrings; |
| 3410 | } |
| 3411 | |
Wu-cheng Li | 454630f | 2010-08-11 16:48:05 -0700 | [diff] [blame] | 3412 | private void splitInt(String str, int[] output) { |
| 3413 | if (str == null) return; |
Wu-cheng Li | e339c5e | 2010-05-13 19:31:02 +0800 | [diff] [blame] | 3414 | |
| 3415 | StringTokenizer tokenizer = new StringTokenizer(str, ","); |
Wu-cheng Li | 454630f | 2010-08-11 16:48:05 -0700 | [diff] [blame] | 3416 | int index = 0; |
Wu-cheng Li | e339c5e | 2010-05-13 19:31:02 +0800 | [diff] [blame] | 3417 | while (tokenizer.hasMoreElements()) { |
| 3418 | String token = tokenizer.nextToken(); |
Wu-cheng Li | 454630f | 2010-08-11 16:48:05 -0700 | [diff] [blame] | 3419 | output[index++] = Integer.parseInt(token); |
Wu-cheng Li | e339c5e | 2010-05-13 19:31:02 +0800 | [diff] [blame] | 3420 | } |
Wu-cheng Li | 454630f | 2010-08-11 16:48:05 -0700 | [diff] [blame] | 3421 | } |
| 3422 | |
| 3423 | // Splits a comma delimited string to an ArrayList of Float. |
| 3424 | private void splitFloat(String str, float[] output) { |
| 3425 | if (str == null) return; |
| 3426 | |
| 3427 | StringTokenizer tokenizer = new StringTokenizer(str, ","); |
| 3428 | int index = 0; |
| 3429 | while (tokenizer.hasMoreElements()) { |
| 3430 | String token = tokenizer.nextToken(); |
| 3431 | output[index++] = Float.parseFloat(token); |
| 3432 | } |
Wu-cheng Li | e339c5e | 2010-05-13 19:31:02 +0800 | [diff] [blame] | 3433 | } |
| 3434 | |
Wu-cheng Li | 24b326a | 2010-02-20 17:47:04 +0800 | [diff] [blame] | 3435 | // Returns the value of a float parameter. |
| 3436 | private float getFloat(String key, float defaultValue) { |
| 3437 | try { |
| 3438 | return Float.parseFloat(mMap.get(key)); |
| 3439 | } catch (NumberFormatException ex) { |
| 3440 | return defaultValue; |
| 3441 | } |
| 3442 | } |
| 3443 | |
| 3444 | // Returns the value of a integer parameter. |
| 3445 | private int getInt(String key, int defaultValue) { |
| 3446 | try { |
| 3447 | return Integer.parseInt(mMap.get(key)); |
| 3448 | } catch (NumberFormatException ex) { |
| 3449 | return defaultValue; |
| 3450 | } |
| 3451 | } |
| 3452 | |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3453 | // Splits a comma delimited string to an ArrayList of Size. |
| 3454 | // Return null if the passing string is null or the size is 0. |
| 3455 | private ArrayList<Size> splitSize(String str) { |
| 3456 | if (str == null) return null; |
| 3457 | |
| 3458 | StringTokenizer tokenizer = new StringTokenizer(str, ","); |
| 3459 | ArrayList<Size> sizeList = new ArrayList<Size>(); |
| 3460 | while (tokenizer.hasMoreElements()) { |
| 3461 | Size size = strToSize(tokenizer.nextToken()); |
| 3462 | if (size != null) sizeList.add(size); |
| 3463 | } |
| 3464 | if (sizeList.size() == 0) return null; |
| 3465 | return sizeList; |
| 3466 | } |
| 3467 | |
| 3468 | // Parses a string (ex: "480x320") to Size object. |
| 3469 | // Return null if the passing string is null. |
| 3470 | private Size strToSize(String str) { |
| 3471 | if (str == null) return null; |
| 3472 | |
| 3473 | int pos = str.indexOf('x'); |
| 3474 | if (pos != -1) { |
| 3475 | String width = str.substring(0, pos); |
| 3476 | String height = str.substring(pos + 1); |
| 3477 | return new Size(Integer.parseInt(width), |
| 3478 | Integer.parseInt(height)); |
| 3479 | } |
| 3480 | Log.e(TAG, "Invalid size parameter string=" + str); |
| 3481 | return null; |
| 3482 | } |
Wu-cheng Li | 454630f | 2010-08-11 16:48:05 -0700 | [diff] [blame] | 3483 | |
| 3484 | // Splits a comma delimited string to an ArrayList of int array. |
| 3485 | // Example string: "(10000,26623),(10000,30000)". Return null if the |
| 3486 | // passing string is null or the size is 0. |
| 3487 | private ArrayList<int[]> splitRange(String str) { |
| 3488 | if (str == null || str.charAt(0) != '(' |
| 3489 | || str.charAt(str.length() - 1) != ')') { |
| 3490 | Log.e(TAG, "Invalid range list string=" + str); |
| 3491 | return null; |
| 3492 | } |
| 3493 | |
| 3494 | ArrayList<int[]> rangeList = new ArrayList<int[]>(); |
| 3495 | int endIndex, fromIndex = 1; |
| 3496 | do { |
| 3497 | int[] range = new int[2]; |
| 3498 | endIndex = str.indexOf("),(", fromIndex); |
| 3499 | if (endIndex == -1) endIndex = str.length() - 1; |
| 3500 | splitInt(str.substring(fromIndex, endIndex), range); |
| 3501 | rangeList.add(range); |
| 3502 | fromIndex = endIndex + 3; |
| 3503 | } while (endIndex != str.length() - 1); |
| 3504 | |
| 3505 | if (rangeList.size() == 0) return null; |
| 3506 | return rangeList; |
| 3507 | } |
Wu-cheng Li | 30771b7 | 2011-04-02 06:19:46 +0800 | [diff] [blame] | 3508 | |
| 3509 | // Splits a comma delimited string to an ArrayList of Area objects. |
| 3510 | // Example string: "(-10,-10,0,0,300),(0,0,10,10,700)". Return null if |
Wu-cheng Li | f715bf9 | 2011-04-14 14:04:18 +0800 | [diff] [blame] | 3511 | // the passing string is null or the size is 0 or (0,0,0,0,0). |
Wu-cheng Li | 30771b7 | 2011-04-02 06:19:46 +0800 | [diff] [blame] | 3512 | private ArrayList<Area> splitArea(String str) { |
| 3513 | if (str == null || str.charAt(0) != '(' |
| 3514 | || str.charAt(str.length() - 1) != ')') { |
| 3515 | Log.e(TAG, "Invalid area string=" + str); |
| 3516 | return null; |
| 3517 | } |
| 3518 | |
| 3519 | ArrayList<Area> result = new ArrayList<Area>(); |
| 3520 | int endIndex, fromIndex = 1; |
| 3521 | int[] array = new int[5]; |
| 3522 | do { |
| 3523 | endIndex = str.indexOf("),(", fromIndex); |
| 3524 | if (endIndex == -1) endIndex = str.length() - 1; |
| 3525 | splitInt(str.substring(fromIndex, endIndex), array); |
| 3526 | Rect rect = new Rect(array[0], array[1], array[2], array[3]); |
| 3527 | result.add(new Area(rect, array[4])); |
| 3528 | fromIndex = endIndex + 3; |
| 3529 | } while (endIndex != str.length() - 1); |
| 3530 | |
| 3531 | if (result.size() == 0) return null; |
Wu-cheng Li | f715bf9 | 2011-04-14 14:04:18 +0800 | [diff] [blame] | 3532 | |
| 3533 | if (result.size() == 1) { |
Wu-cheng Li | bde61a5 | 2011-06-07 18:23:14 +0800 | [diff] [blame] | 3534 | Area area = result.get(0); |
Wu-cheng Li | f715bf9 | 2011-04-14 14:04:18 +0800 | [diff] [blame] | 3535 | Rect rect = area.rect; |
| 3536 | if (rect.left == 0 && rect.top == 0 && rect.right == 0 |
| 3537 | && rect.bottom == 0 && area.weight == 0) { |
| 3538 | return null; |
| 3539 | } |
| 3540 | } |
| 3541 | |
Wu-cheng Li | 30771b7 | 2011-04-02 06:19:46 +0800 | [diff] [blame] | 3542 | return result; |
| 3543 | } |
Wu-cheng Li | b838d8d | 2011-11-17 20:12:23 +0800 | [diff] [blame] | 3544 | |
| 3545 | private boolean same(String s1, String s2) { |
| 3546 | if (s1 == null && s2 == null) return true; |
| 3547 | if (s1 != null && s1.equals(s2)) return true; |
| 3548 | return false; |
| 3549 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3550 | }; |
| 3551 | } |