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