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