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