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