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 | /** |
| 35 | * The Camera class is used to connect/disconnect with the camera service, |
| 36 | * set capture settings, start/stop preview, snap a picture, and retrieve |
| 37 | * frames for encoding for video. |
| 38 | * <p>There is no default constructor for this class. Use {@link #open()} to |
| 39 | * get a Camera object.</p> |
Scott Main | df4578e | 2009-09-10 12:22:07 -0700 | [diff] [blame] | 40 | * |
Wu-cheng Li | 7478ea6 | 2009-09-16 18:52:55 +0800 | [diff] [blame] | 41 | * <p>In order to use the device camera, you must declare the |
| 42 | * {@link android.Manifest.permission#CAMERA} permission in your Android |
Scott Main | df4578e | 2009-09-10 12:22:07 -0700 | [diff] [blame] | 43 | * Manifest. Also be sure to include the |
| 44 | * <a href="{@docRoot}guide/topics/manifest/uses-feature-element.html"><uses-feature></a> |
Wu-cheng Li | 7478ea6 | 2009-09-16 18:52:55 +0800 | [diff] [blame] | 45 | * manifest element in order to declare camera features used by your application. |
| 46 | * For example, if you use the camera and auto-focus feature, your Manifest |
Scott Main | df4578e | 2009-09-10 12:22:07 -0700 | [diff] [blame] | 47 | * should include the following:</p> |
| 48 | * <pre> <uses-permission android:name="android.permission.CAMERA" /> |
| 49 | * <uses-feature android:name="android.hardware.camera" /> |
| 50 | * <uses-feature android:name="android.hardware.camera.autofocus" /></pre> |
| 51 | * |
| 52 | * <p class="caution"><strong>Caution:</strong> Different Android-powered devices |
| 53 | * may have different hardware specifications, such as megapixel ratings and |
| 54 | * 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] | 55 | * more devices, you should not make assumptions about the device camera |
Scott Main | df4578e | 2009-09-10 12:22:07 -0700 | [diff] [blame] | 56 | * specifications.</p> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 57 | */ |
| 58 | public class Camera { |
| 59 | private static final String TAG = "Camera"; |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 60 | |
Dave Sparks | c62f9bd | 2009-06-26 13:33:32 -0700 | [diff] [blame] | 61 | // These match the enums in frameworks/base/include/ui/Camera.h |
Benny Wong | da83f46 | 2009-08-12 12:01:27 -0500 | [diff] [blame] | 62 | private static final int CAMERA_MSG_ERROR = 0x001; |
| 63 | private static final int CAMERA_MSG_SHUTTER = 0x002; |
| 64 | private static final int CAMERA_MSG_FOCUS = 0x004; |
| 65 | private static final int CAMERA_MSG_ZOOM = 0x008; |
| 66 | private static final int CAMERA_MSG_PREVIEW_FRAME = 0x010; |
| 67 | private static final int CAMERA_MSG_VIDEO_FRAME = 0x020; |
| 68 | private static final int CAMERA_MSG_POSTVIEW_FRAME = 0x040; |
| 69 | private static final int CAMERA_MSG_RAW_IMAGE = 0x080; |
| 70 | private static final int CAMERA_MSG_COMPRESSED_IMAGE = 0x100; |
| 71 | private static final int CAMERA_MSG_ALL_MSGS = 0x1FF; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 72 | |
| 73 | private int mNativeContext; // accessed by native methods |
| 74 | private EventHandler mEventHandler; |
| 75 | private ShutterCallback mShutterCallback; |
| 76 | private PictureCallback mRawImageCallback; |
| 77 | private PictureCallback mJpegCallback; |
| 78 | private PreviewCallback mPreviewCallback; |
Dave Sparks | e8b26e1 | 2009-07-14 10:35:40 -0700 | [diff] [blame] | 79 | private PictureCallback mPostviewCallback; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 80 | private AutoFocusCallback mAutoFocusCallback; |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 81 | private OnZoomChangeListener mZoomListener; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 82 | private ErrorCallback mErrorCallback; |
| 83 | private boolean mOneShot; |
Andrew Harp | 94927df | 2009-10-20 01:47:05 -0400 | [diff] [blame] | 84 | private boolean mWithBuffer; |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 85 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 86 | /** |
Chih-Chung Chang | e25cc65 | 2010-05-06 16:36:58 +0800 | [diff] [blame] | 87 | * Returns the number of Cameras available. |
| 88 | * @hide |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 89 | */ |
Chih-Chung Chang | e25cc65 | 2010-05-06 16:36:58 +0800 | [diff] [blame] | 90 | public native static int getNumberOfCameras(); |
| 91 | |
| 92 | /** |
| 93 | * Returns a new Camera object. |
| 94 | * If {@link #getNumberOfCameras()} returns N, the valid is is 0 to N-1. |
| 95 | * The id 0 is the default camera. |
| 96 | * @hide |
| 97 | */ |
| 98 | public static Camera open(int cameraId) { |
| 99 | return new Camera(cameraId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 100 | } |
| 101 | |
Chih-Chung Chang | e25cc65 | 2010-05-06 16:36:58 +0800 | [diff] [blame] | 102 | /** |
| 103 | * Returns a new Camera object. This returns the default camera. |
| 104 | */ |
| 105 | public static Camera open() { |
| 106 | return new Camera(0); |
| 107 | } |
| 108 | |
| 109 | Camera(int cameraId) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 110 | mShutterCallback = null; |
| 111 | mRawImageCallback = null; |
| 112 | mJpegCallback = null; |
| 113 | mPreviewCallback = null; |
Dave Sparks | e8b26e1 | 2009-07-14 10:35:40 -0700 | [diff] [blame] | 114 | mPostviewCallback = null; |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 115 | mZoomListener = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 116 | |
| 117 | Looper looper; |
| 118 | if ((looper = Looper.myLooper()) != null) { |
| 119 | mEventHandler = new EventHandler(this, looper); |
| 120 | } else if ((looper = Looper.getMainLooper()) != null) { |
| 121 | mEventHandler = new EventHandler(this, looper); |
| 122 | } else { |
| 123 | mEventHandler = null; |
| 124 | } |
| 125 | |
Chih-Chung Chang | e25cc65 | 2010-05-06 16:36:58 +0800 | [diff] [blame] | 126 | native_setup(new WeakReference<Camera>(this), cameraId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 127 | } |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 128 | |
| 129 | protected void finalize() { |
| 130 | native_release(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 131 | } |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 132 | |
Chih-Chung Chang | e25cc65 | 2010-05-06 16:36:58 +0800 | [diff] [blame] | 133 | 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] | 134 | private native final void native_release(); |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 135 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 136 | |
| 137 | /** |
| 138 | * Disconnects and releases the Camera object resources. |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 139 | * <p>It is recommended that you call this as soon as you're done with the |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 140 | * Camera object.</p> |
| 141 | */ |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 142 | public final void release() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 143 | native_release(); |
| 144 | } |
| 145 | |
| 146 | /** |
| 147 | * Reconnect to the camera after passing it to MediaRecorder. To save |
| 148 | * setup/teardown time, a client of Camera can pass an initialized Camera |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 149 | * object to a MediaRecorder to use for video recording. Once the |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 150 | * MediaRecorder is done with the Camera, this method can be used to |
| 151 | * re-establish a connection with the camera hardware. NOTE: The Camera |
| 152 | * object must first be unlocked by the process that owns it before it |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 153 | * can be connected to another process. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 154 | * |
| 155 | * @throws IOException if the method fails. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 156 | */ |
| 157 | public native final void reconnect() throws IOException; |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 158 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 159 | /** |
| 160 | * Lock the camera to prevent other processes from accessing it. To save |
| 161 | * setup/teardown time, a client of Camera can pass an initialized Camera |
| 162 | * object to another process. This method is used to re-lock the Camera |
| 163 | * object prevent other processes from accessing it. By default, the |
| 164 | * Camera object is locked. Locking it again from the same process will |
| 165 | * have no effect. Attempting to lock it from another process if it has |
| 166 | * not been unlocked will fail. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 167 | * |
Wu-cheng Li | ffe1cf2 | 2009-09-10 16:49:17 +0800 | [diff] [blame] | 168 | * @throws RuntimeException if the method fails. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 169 | */ |
Wu-cheng Li | ffe1cf2 | 2009-09-10 16:49:17 +0800 | [diff] [blame] | 170 | public native final void lock(); |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 171 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 172 | /** |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 173 | * Unlock the camera to allow another process to access it. To save |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 174 | * setup/teardown time, a client of Camera can pass an initialized Camera |
| 175 | * object to another process. This method is used to unlock the Camera |
| 176 | * object before handing off the Camera object to the other process. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 177 | * |
Wu-cheng Li | ffe1cf2 | 2009-09-10 16:49:17 +0800 | [diff] [blame] | 178 | * @throws RuntimeException if the method fails. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 179 | */ |
Wu-cheng Li | ffe1cf2 | 2009-09-10 16:49:17 +0800 | [diff] [blame] | 180 | public native final void unlock(); |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 181 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 182 | /** |
| 183 | * Sets the SurfaceHolder to be used for a picture preview. If the surface |
| 184 | * changed since the last call, the screen will blank. Nothing happens |
| 185 | * if the same surface is re-set. |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 186 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 187 | * @param holder the SurfaceHolder upon which to place the picture preview |
| 188 | * @throws IOException if the method fails. |
| 189 | */ |
| 190 | public final void setPreviewDisplay(SurfaceHolder holder) throws IOException { |
Wu-cheng Li | b8a10fe | 2009-06-23 23:37:36 +0800 | [diff] [blame] | 191 | if (holder != null) { |
| 192 | setPreviewDisplay(holder.getSurface()); |
| 193 | } else { |
| 194 | setPreviewDisplay((Surface)null); |
| 195 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 196 | } |
| 197 | |
| 198 | private native final void setPreviewDisplay(Surface surface); |
| 199 | |
| 200 | /** |
| 201 | * Used to get a copy of each preview frame. |
| 202 | */ |
| 203 | public interface PreviewCallback |
| 204 | { |
| 205 | /** |
| 206 | * The callback that delivers the preview frames. |
| 207 | * |
Scott Main | df4578e | 2009-09-10 12:22:07 -0700 | [diff] [blame] | 208 | * @param data The contents of the preview frame in the format defined |
Mathias Agopian | a696f5d | 2010-02-17 17:53:09 -0800 | [diff] [blame] | 209 | * by {@link android.graphics.ImageFormat}, which can be queried |
Scott Main | df4578e | 2009-09-10 12:22:07 -0700 | [diff] [blame] | 210 | * with {@link android.hardware.Camera.Parameters#getPreviewFormat()}. |
Scott Main | da0a56d | 2009-09-10 18:08:37 -0700 | [diff] [blame] | 211 | * If {@link android.hardware.Camera.Parameters#setPreviewFormat(int)} |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 212 | * is never called, the default will be the YCbCr_420_SP |
| 213 | * (NV21) format. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 214 | * @param camera The Camera service object. |
| 215 | */ |
| 216 | void onPreviewFrame(byte[] data, Camera camera); |
| 217 | }; |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 218 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 219 | /** |
| 220 | * Start drawing preview frames to the surface. |
| 221 | */ |
| 222 | public native final void startPreview(); |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 223 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 224 | /** |
| 225 | * Stop drawing preview frames to the surface. |
| 226 | */ |
| 227 | public native final void stopPreview(); |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 228 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 229 | /** |
| 230 | * Return current preview state. |
| 231 | * |
| 232 | * FIXME: Unhide before release |
| 233 | * @hide |
| 234 | */ |
| 235 | public native final boolean previewEnabled(); |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 236 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 237 | /** |
| 238 | * Can be called at any time to instruct the camera to use a callback for |
| 239 | * each preview frame in addition to displaying it. |
| 240 | * |
| 241 | * @param cb A callback object that receives a copy of each preview frame. |
| 242 | * Pass null to stop receiving callbacks at any time. |
| 243 | */ |
| 244 | public final void setPreviewCallback(PreviewCallback cb) { |
| 245 | mPreviewCallback = cb; |
| 246 | mOneShot = false; |
Andrew Harp | 94927df | 2009-10-20 01:47:05 -0400 | [diff] [blame] | 247 | mWithBuffer = false; |
Dave Sparks | a6118c6 | 2009-10-13 02:28:54 -0700 | [diff] [blame] | 248 | // Always use one-shot mode. We fake camera preview mode by |
| 249 | // doing one-shot preview continuously. |
Andrew Harp | 94927df | 2009-10-20 01:47:05 -0400 | [diff] [blame] | 250 | setHasPreviewCallback(cb != null, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 251 | } |
| 252 | |
| 253 | /** |
| 254 | * Installs a callback to retrieve a single preview frame, after which the |
| 255 | * callback is cleared. |
| 256 | * |
| 257 | * @param cb A callback object that receives a copy of the preview frame. |
| 258 | */ |
| 259 | public final void setOneShotPreviewCallback(PreviewCallback cb) { |
Andrew Harp | 94927df | 2009-10-20 01:47:05 -0400 | [diff] [blame] | 260 | mPreviewCallback = cb; |
| 261 | mOneShot = true; |
| 262 | mWithBuffer = false; |
| 263 | setHasPreviewCallback(cb != null, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 264 | } |
| 265 | |
Andrew Harp | 94927df | 2009-10-20 01:47:05 -0400 | [diff] [blame] | 266 | private native final void setHasPreviewCallback(boolean installed, boolean manualBuffer); |
| 267 | |
| 268 | /** |
| 269 | * Installs a callback which will get called as long as there are buffers in the |
| 270 | * preview buffer queue, which minimizes dynamic allocation of preview buffers. |
| 271 | * |
| 272 | * Apps must call addCallbackBuffer to explicitly register the buffers to use, or no callbacks |
| 273 | * will be received. addCallbackBuffer may be safely called before or after |
| 274 | * a call to setPreviewCallbackWithBuffer with a non-null callback parameter. |
| 275 | * |
| 276 | * The buffer queue will be cleared upon any calls to setOneShotPreviewCallback, |
| 277 | * setPreviewCallback, or to this method with a null callback parameter. |
| 278 | * |
| 279 | * @param cb A callback object that receives a copy of the preview frame. A null value will clear the queue. |
Andrew Harp | 94927df | 2009-10-20 01:47:05 -0400 | [diff] [blame] | 280 | */ |
| 281 | public final void setPreviewCallbackWithBuffer(PreviewCallback cb) { |
| 282 | mPreviewCallback = cb; |
| 283 | mOneShot = false; |
| 284 | mWithBuffer = true; |
| 285 | setHasPreviewCallback(cb != null, true); |
| 286 | } |
| 287 | |
| 288 | /** |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 289 | * Adds a pre-allocated buffer to the preview callback buffer queue. |
| 290 | * Applications can add one or more buffers to the queue. When a preview |
| 291 | * frame arrives and there is still available buffer, buffer will be filled |
| 292 | * and it is removed from the queue. Then preview callback is invoked with |
| 293 | * the buffer. If a frame arrives and there is no buffer left, the frame is |
| 294 | * discarded. Applications should add the buffers back when they finish the |
| 295 | * processing. |
Wu-cheng Li | c10275a | 2010-03-09 13:49:21 -0800 | [diff] [blame] | 296 | * |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 297 | * The image format of the callback buffer can be read from {@link |
| 298 | * android.hardware.Camera.Parameters#getPreviewFormat()}. bitsPerPixel can |
| 299 | * be read from {@link android.graphics.ImageFormat#getBitsPerPixel(int)}. |
| 300 | * Preview width and height can be determined from getPreviewSize. |
Andrew Harp | 94927df | 2009-10-20 01:47:05 -0400 | [diff] [blame] | 301 | * |
| 302 | * Alternatively, a buffer from a previous callback may be passed in or used |
| 303 | * to determine the size of new preview frame buffers. |
| 304 | * |
| 305 | * @param callbackBuffer The buffer to register. Size should be width * height * bitsPerPixel / 8. |
Wu-cheng Li | 5b9bcda | 2010-03-07 14:59:28 -0800 | [diff] [blame] | 306 | * @see #setPreviewCallbackWithBuffer(PreviewCallback) |
Andrew Harp | 94927df | 2009-10-20 01:47:05 -0400 | [diff] [blame] | 307 | */ |
| 308 | public native final void addCallbackBuffer(byte[] callbackBuffer); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 309 | |
| 310 | private class EventHandler extends Handler |
| 311 | { |
| 312 | private Camera mCamera; |
| 313 | |
| 314 | public EventHandler(Camera c, Looper looper) { |
| 315 | super(looper); |
| 316 | mCamera = c; |
| 317 | } |
| 318 | |
| 319 | @Override |
| 320 | public void handleMessage(Message msg) { |
| 321 | switch(msg.what) { |
Dave Sparks | c62f9bd | 2009-06-26 13:33:32 -0700 | [diff] [blame] | 322 | case CAMERA_MSG_SHUTTER: |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 323 | if (mShutterCallback != null) { |
| 324 | mShutterCallback.onShutter(); |
| 325 | } |
| 326 | return; |
Dave Sparks | c62f9bd | 2009-06-26 13:33:32 -0700 | [diff] [blame] | 327 | |
| 328 | case CAMERA_MSG_RAW_IMAGE: |
Dave Sparks | e8b26e1 | 2009-07-14 10:35:40 -0700 | [diff] [blame] | 329 | if (mRawImageCallback != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 330 | mRawImageCallback.onPictureTaken((byte[])msg.obj, mCamera); |
Dave Sparks | e8b26e1 | 2009-07-14 10:35:40 -0700 | [diff] [blame] | 331 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 332 | return; |
| 333 | |
Dave Sparks | c62f9bd | 2009-06-26 13:33:32 -0700 | [diff] [blame] | 334 | case CAMERA_MSG_COMPRESSED_IMAGE: |
Dave Sparks | e8b26e1 | 2009-07-14 10:35:40 -0700 | [diff] [blame] | 335 | if (mJpegCallback != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 336 | mJpegCallback.onPictureTaken((byte[])msg.obj, mCamera); |
Dave Sparks | e8b26e1 | 2009-07-14 10:35:40 -0700 | [diff] [blame] | 337 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 338 | return; |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 339 | |
Dave Sparks | c62f9bd | 2009-06-26 13:33:32 -0700 | [diff] [blame] | 340 | case CAMERA_MSG_PREVIEW_FRAME: |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 341 | if (mPreviewCallback != null) { |
Dave Sparks | a6118c6 | 2009-10-13 02:28:54 -0700 | [diff] [blame] | 342 | PreviewCallback cb = mPreviewCallback; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 343 | if (mOneShot) { |
Dave Sparks | a6118c6 | 2009-10-13 02:28:54 -0700 | [diff] [blame] | 344 | // Clear the callback variable before the callback |
| 345 | // in case the app calls setPreviewCallback from |
| 346 | // the callback function |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 347 | mPreviewCallback = null; |
Andrew Harp | 94927df | 2009-10-20 01:47:05 -0400 | [diff] [blame] | 348 | } else if (!mWithBuffer) { |
Dave Sparks | a6118c6 | 2009-10-13 02:28:54 -0700 | [diff] [blame] | 349 | // We're faking the camera preview mode to prevent |
| 350 | // the app from being flooded with preview frames. |
| 351 | // Set to oneshot mode again. |
Andrew Harp | 94927df | 2009-10-20 01:47:05 -0400 | [diff] [blame] | 352 | setHasPreviewCallback(true, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 353 | } |
Dave Sparks | a6118c6 | 2009-10-13 02:28:54 -0700 | [diff] [blame] | 354 | cb.onPreviewFrame((byte[])msg.obj, mCamera); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 355 | } |
| 356 | return; |
| 357 | |
Dave Sparks | e8b26e1 | 2009-07-14 10:35:40 -0700 | [diff] [blame] | 358 | case CAMERA_MSG_POSTVIEW_FRAME: |
| 359 | if (mPostviewCallback != null) { |
| 360 | mPostviewCallback.onPictureTaken((byte[])msg.obj, mCamera); |
| 361 | } |
| 362 | return; |
| 363 | |
Dave Sparks | c62f9bd | 2009-06-26 13:33:32 -0700 | [diff] [blame] | 364 | case CAMERA_MSG_FOCUS: |
Dave Sparks | e8b26e1 | 2009-07-14 10:35:40 -0700 | [diff] [blame] | 365 | if (mAutoFocusCallback != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 366 | mAutoFocusCallback.onAutoFocus(msg.arg1 == 0 ? false : true, mCamera); |
Dave Sparks | e8b26e1 | 2009-07-14 10:35:40 -0700 | [diff] [blame] | 367 | } |
| 368 | return; |
| 369 | |
| 370 | case CAMERA_MSG_ZOOM: |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 371 | if (mZoomListener != null) { |
| 372 | mZoomListener.onZoomChange(msg.arg1, msg.arg2 != 0, mCamera); |
Dave Sparks | e8b26e1 | 2009-07-14 10:35:40 -0700 | [diff] [blame] | 373 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 374 | return; |
| 375 | |
Dave Sparks | c62f9bd | 2009-06-26 13:33:32 -0700 | [diff] [blame] | 376 | case CAMERA_MSG_ERROR : |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 377 | Log.e(TAG, "Error " + msg.arg1); |
Dave Sparks | e8b26e1 | 2009-07-14 10:35:40 -0700 | [diff] [blame] | 378 | if (mErrorCallback != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 379 | mErrorCallback.onError(msg.arg1, mCamera); |
Dave Sparks | e8b26e1 | 2009-07-14 10:35:40 -0700 | [diff] [blame] | 380 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 381 | return; |
| 382 | |
| 383 | default: |
| 384 | Log.e(TAG, "Unknown message type " + msg.what); |
| 385 | return; |
| 386 | } |
| 387 | } |
| 388 | } |
| 389 | |
| 390 | private static void postEventFromNative(Object camera_ref, |
| 391 | int what, int arg1, int arg2, Object obj) |
| 392 | { |
| 393 | Camera c = (Camera)((WeakReference)camera_ref).get(); |
| 394 | if (c == null) |
| 395 | return; |
| 396 | |
| 397 | if (c.mEventHandler != null) { |
| 398 | Message m = c.mEventHandler.obtainMessage(what, arg1, arg2, obj); |
| 399 | c.mEventHandler.sendMessage(m); |
| 400 | } |
| 401 | } |
| 402 | |
| 403 | /** |
| 404 | * Handles the callback for the camera auto focus. |
Wu-cheng Li | 7478ea6 | 2009-09-16 18:52:55 +0800 | [diff] [blame] | 405 | * <p>Devices that do not support auto-focus will receive a "fake" |
| 406 | * callback to this interface. If your application needs auto-focus and |
Scott Main | df4578e | 2009-09-10 12:22:07 -0700 | [diff] [blame] | 407 | * should not be installed on devices <em>without</em> auto-focus, you must |
| 408 | * declare that your app uses the |
Wu-cheng Li | 7478ea6 | 2009-09-16 18:52:55 +0800 | [diff] [blame] | 409 | * {@code android.hardware.camera.autofocus} feature, in the |
Scott Main | df4578e | 2009-09-10 12:22:07 -0700 | [diff] [blame] | 410 | * <a href="{@docRoot}guide/topics/manifest/uses-feature-element.html"><uses-feature></a> |
| 411 | * manifest element.</p> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 412 | */ |
| 413 | public interface AutoFocusCallback |
| 414 | { |
| 415 | /** |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 416 | * Callback for the camera auto focus. If the camera does not support |
| 417 | * auto-focus and autoFocus is called, onAutoFocus will be called |
| 418 | * immediately with success. |
| 419 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 420 | * @param success true if focus was successful, false if otherwise |
| 421 | * @param camera the Camera service object |
| 422 | */ |
| 423 | void onAutoFocus(boolean success, Camera camera); |
| 424 | }; |
| 425 | |
| 426 | /** |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 427 | * Starts auto-focus function and registers a callback function to run when |
Wu-cheng Li | 36322db | 2009-09-18 18:59:21 +0800 | [diff] [blame] | 428 | * camera is focused. Only valid after startPreview() has been called. |
| 429 | * Applications should call {@link |
| 430 | * android.hardware.Camera.Parameters#getFocusMode()} to determine if this |
| 431 | * method should be called. If the camera does not support auto-focus, it is |
| 432 | * a no-op and {@link AutoFocusCallback#onAutoFocus(boolean, Camera)} |
| 433 | * callback will be called immediately. |
Scott Main | da0a56d | 2009-09-10 18:08:37 -0700 | [diff] [blame] | 434 | * <p>If your application should not be installed |
Wu-cheng Li | 7478ea6 | 2009-09-16 18:52:55 +0800 | [diff] [blame] | 435 | * on devices without auto-focus, you must declare that your application |
| 436 | * uses auto-focus with the |
Scott Main | df4578e | 2009-09-10 12:22:07 -0700 | [diff] [blame] | 437 | * <a href="{@docRoot}guide/topics/manifest/uses-feature-element.html"><uses-feature></a> |
| 438 | * manifest element.</p> |
Wu-cheng Li | 068ef42 | 2009-09-27 13:19:36 -0700 | [diff] [blame] | 439 | * <p>If the current flash mode is not |
| 440 | * {@link android.hardware.Camera.Parameters#FLASH_MODE_OFF}, flash may be |
| 441 | * fired during auto-focus depending on the driver.<p> |
Wu-cheng Li | 7478ea6 | 2009-09-16 18:52:55 +0800 | [diff] [blame] | 442 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 443 | * @param cb the callback to run |
| 444 | */ |
| 445 | public final void autoFocus(AutoFocusCallback cb) |
| 446 | { |
| 447 | mAutoFocusCallback = cb; |
| 448 | native_autoFocus(); |
| 449 | } |
| 450 | private native final void native_autoFocus(); |
| 451 | |
| 452 | /** |
Chih-Chung Chang | 244f8c2 | 2009-09-15 14:51:56 +0800 | [diff] [blame] | 453 | * Cancels auto-focus function. If the auto-focus is still in progress, |
| 454 | * this function will cancel it. Whether the auto-focus is in progress |
| 455 | * or not, this function will return the focus position to the default. |
| 456 | * If the camera does not support auto-focus, this is a no-op. |
Chih-Chung Chang | 244f8c2 | 2009-09-15 14:51:56 +0800 | [diff] [blame] | 457 | */ |
| 458 | public final void cancelAutoFocus() |
| 459 | { |
| 460 | mAutoFocusCallback = null; |
| 461 | native_cancelAutoFocus(); |
| 462 | } |
| 463 | private native final void native_cancelAutoFocus(); |
| 464 | |
| 465 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 466 | * An interface which contains a callback for the shutter closing after taking a picture. |
| 467 | */ |
| 468 | public interface ShutterCallback |
| 469 | { |
| 470 | /** |
| 471 | * Can be used to play a shutter sound as soon as the image has been captured, but before |
| 472 | * the data is available. |
| 473 | */ |
| 474 | void onShutter(); |
| 475 | } |
| 476 | |
| 477 | /** |
| 478 | * Handles the callback for when a picture is taken. |
| 479 | */ |
| 480 | public interface PictureCallback { |
| 481 | /** |
| 482 | * Callback for when a picture is taken. |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 483 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 484 | * @param data a byte array of the picture data |
| 485 | * @param camera the Camera service object |
| 486 | */ |
| 487 | void onPictureTaken(byte[] data, Camera camera); |
| 488 | }; |
| 489 | |
| 490 | /** |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 491 | * Triggers an asynchronous image capture. The camera service will initiate |
| 492 | * a series of callbacks to the application as the image capture progresses. |
| 493 | * The shutter callback occurs after the image is captured. This can be used |
| 494 | * to trigger a sound to let the user know that image has been captured. The |
| 495 | * raw callback occurs when the raw image data is available (NOTE: the data |
| 496 | * may be null if the hardware does not have enough memory to make a copy). |
| 497 | * The jpeg callback occurs when the compressed image is available. If the |
| 498 | * application does not need a particular callback, a null can be passed |
| 499 | * instead of a callback method. |
| 500 | * |
Wu-cheng Li | 40057ce | 2009-12-02 18:57:29 +0800 | [diff] [blame] | 501 | * This method will stop the preview. Applications should not call {@link |
| 502 | * #stopPreview()} before this. After jpeg callback is received, |
| 503 | * applications can call {@link #startPreview()} to restart the preview. |
| 504 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 505 | * @param shutter callback after the image is captured, may be null |
| 506 | * @param raw callback with raw image data, may be null |
| 507 | * @param jpeg callback with jpeg image data, may be null |
| 508 | */ |
| 509 | public final void takePicture(ShutterCallback shutter, PictureCallback raw, |
| 510 | PictureCallback jpeg) { |
Dave Sparks | e8b26e1 | 2009-07-14 10:35:40 -0700 | [diff] [blame] | 511 | takePicture(shutter, raw, null, jpeg); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 512 | } |
| 513 | private native final void native_takePicture(); |
| 514 | |
Dave Sparks | e8b26e1 | 2009-07-14 10:35:40 -0700 | [diff] [blame] | 515 | /** |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 516 | * Triggers an asynchronous image capture. The camera service will initiate |
| 517 | * a series of callbacks to the application as the image capture progresses. |
| 518 | * The shutter callback occurs after the image is captured. This can be used |
| 519 | * to trigger a sound to let the user know that image has been captured. The |
| 520 | * raw callback occurs when the raw image data is available (NOTE: the data |
| 521 | * may be null if the hardware does not have enough memory to make a copy). |
| 522 | * The postview callback occurs when a scaled, fully processed postview |
| 523 | * image is available (NOTE: not all hardware supports this). The jpeg |
| 524 | * callback occurs when the compressed image is available. If the |
| 525 | * application does not need a particular callback, a null can be passed |
| 526 | * instead of a callback method. |
Dave Sparks | e8b26e1 | 2009-07-14 10:35:40 -0700 | [diff] [blame] | 527 | * |
Wu-cheng Li | 40057ce | 2009-12-02 18:57:29 +0800 | [diff] [blame] | 528 | * This method will stop the preview. Applications should not call {@link |
| 529 | * #stopPreview()} before this. After jpeg callback is received, |
| 530 | * applications can call {@link #startPreview()} to restart the preview. |
| 531 | * |
Dave Sparks | e8b26e1 | 2009-07-14 10:35:40 -0700 | [diff] [blame] | 532 | * @param shutter callback after the image is captured, may be null |
| 533 | * @param raw callback with raw image data, may be null |
| 534 | * @param postview callback with postview image data, may be null |
| 535 | * @param jpeg callback with jpeg image data, may be null |
| 536 | */ |
| 537 | public final void takePicture(ShutterCallback shutter, PictureCallback raw, |
| 538 | PictureCallback postview, PictureCallback jpeg) { |
| 539 | mShutterCallback = shutter; |
| 540 | mRawImageCallback = raw; |
| 541 | mPostviewCallback = postview; |
| 542 | mJpegCallback = jpeg; |
| 543 | native_takePicture(); |
| 544 | } |
| 545 | |
| 546 | /** |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 547 | * Zooms to the requested value smoothly. Driver will notify {@link |
| 548 | * OnZoomChangeListener} of the zoom value and whether zoom is stopped at |
| 549 | * the time. For example, suppose the current zoom is 0 and startSmoothZoom |
| 550 | * is called with value 3. Method onZoomChange will be called three times |
| 551 | * with zoom value 1, 2, and 3. The applications can call {@link |
| 552 | * #stopSmoothZoom} to stop the zoom earlier. The applications should not |
| 553 | * call startSmoothZoom again or change the zoom value before zoom stops. If |
| 554 | * the passing zoom value equals to the current zoom value, no zoom callback |
| 555 | * will be generated. This method is supported if {@link |
Wu-cheng Li | 0ca2519 | 2010-03-29 16:21:12 +0800 | [diff] [blame] | 556 | * android.hardware.Camera.Parameters#isSmoothZoomSupported} is true. |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 557 | * |
| 558 | * @param value zoom value. The valid range is 0 to {@link |
| 559 | * android.hardware.Camera.Parameters#getMaxZoom}. |
Wu-cheng Li | 0ca2519 | 2010-03-29 16:21:12 +0800 | [diff] [blame] | 560 | * @throws IllegalArgumentException if the zoom value is invalid. |
| 561 | * @throws RuntimeException if the method fails. |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 562 | */ |
| 563 | public native final void startSmoothZoom(int value); |
| 564 | |
| 565 | /** |
| 566 | * Stops the smooth zoom. The applications should wait for the {@link |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 567 | * OnZoomChangeListener} to know when the zoom is actually stopped. This |
| 568 | * method is supported if {@link |
Wu-cheng Li | 8cbb8f5 | 2010-02-28 23:19:55 -0800 | [diff] [blame] | 569 | * android.hardware.Camera.Parameters#isSmoothZoomSupported} is true. |
Wu-cheng Li | 0ca2519 | 2010-03-29 16:21:12 +0800 | [diff] [blame] | 570 | * |
| 571 | * @throws RuntimeException if the method fails. |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 572 | */ |
| 573 | public native final void stopSmoothZoom(); |
| 574 | |
| 575 | /** |
Chih-Chung Chang | d1d7706 | 2010-01-22 17:49:48 -0800 | [diff] [blame] | 576 | * Set the display orientation. This affects the preview frames and the |
| 577 | * picture displayed after snapshot. This method is useful for portrait |
| 578 | * mode applications. |
| 579 | * |
| 580 | * This does not affect the order of byte array passed in |
| 581 | * {@link PreviewCallback#onPreviewFrame}. This method is not allowed to |
| 582 | * be called during preview. |
| 583 | * |
| 584 | * @param degrees the angle that the picture will be rotated clockwise. |
Chih-Chung Chang | e7bd22a | 2010-01-27 10:24:42 -0800 | [diff] [blame] | 585 | * Valid values are 0, 90, 180, and 270. The starting |
| 586 | * position is 0 (landscape). |
Chih-Chung Chang | d1d7706 | 2010-01-22 17:49:48 -0800 | [diff] [blame] | 587 | */ |
| 588 | public native final void setDisplayOrientation(int degrees); |
| 589 | |
| 590 | /** |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 591 | * Interface for a callback to be invoked when zoom value changes. |
Dave Sparks | e8b26e1 | 2009-07-14 10:35:40 -0700 | [diff] [blame] | 592 | */ |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 593 | public interface OnZoomChangeListener |
Dave Sparks | e8b26e1 | 2009-07-14 10:35:40 -0700 | [diff] [blame] | 594 | { |
| 595 | /** |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 596 | * Called when the zoom value has changed. |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 597 | * |
| 598 | * @param zoomValue the current zoom value. In smooth zoom mode, camera |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 599 | * calls this for every new zoom value. |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 600 | * @param stopped whether smooth zoom is stopped. If the value is true, |
| 601 | * this is the last zoom update for the application. |
| 602 | * |
Dave Sparks | e8b26e1 | 2009-07-14 10:35:40 -0700 | [diff] [blame] | 603 | * @param camera the Camera service object |
Wu-cheng Li | 8cbb8f5 | 2010-02-28 23:19:55 -0800 | [diff] [blame] | 604 | * @see #startSmoothZoom(int) |
Dave Sparks | e8b26e1 | 2009-07-14 10:35:40 -0700 | [diff] [blame] | 605 | */ |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 606 | void onZoomChange(int zoomValue, boolean stopped, Camera camera); |
Dave Sparks | e8b26e1 | 2009-07-14 10:35:40 -0700 | [diff] [blame] | 607 | }; |
| 608 | |
| 609 | /** |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 610 | * 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] | 611 | * camera driver during smooth zoom. |
Wu-cheng Li | 8cbb8f5 | 2010-02-28 23:19:55 -0800 | [diff] [blame] | 612 | * |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 613 | * @param listener the listener to notify |
Wu-cheng Li | 8cbb8f5 | 2010-02-28 23:19:55 -0800 | [diff] [blame] | 614 | * @see #startSmoothZoom(int) |
Dave Sparks | e8b26e1 | 2009-07-14 10:35:40 -0700 | [diff] [blame] | 615 | */ |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 616 | public final void setZoomChangeListener(OnZoomChangeListener listener) |
Dave Sparks | e8b26e1 | 2009-07-14 10:35:40 -0700 | [diff] [blame] | 617 | { |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 618 | mZoomListener = listener; |
Dave Sparks | e8b26e1 | 2009-07-14 10:35:40 -0700 | [diff] [blame] | 619 | } |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 620 | |
James Dong | a1b653d | 2009-07-02 10:04:20 -0700 | [diff] [blame] | 621 | // These match the enum in include/ui/Camera.h |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 622 | /** Unspecified camerar error. @see #ErrorCallback */ |
| 623 | public static final int CAMERA_ERROR_UNKNOWN = 1; |
| 624 | /** Media server died. In this case, the application must release the |
| 625 | * Camera object and instantiate a new one. @see #ErrorCallback */ |
| 626 | public static final int CAMERA_ERROR_SERVER_DIED = 100; |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 627 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 628 | /** |
| 629 | * Handles the camera error callback. |
| 630 | */ |
| 631 | public interface ErrorCallback |
| 632 | { |
| 633 | /** |
| 634 | * Callback for camera errors. |
| 635 | * @param error error code: |
| 636 | * <ul> |
| 637 | * <li>{@link #CAMERA_ERROR_UNKNOWN} |
| 638 | * <li>{@link #CAMERA_ERROR_SERVER_DIED} |
| 639 | * </ul> |
| 640 | * @param camera the Camera service object |
| 641 | */ |
| 642 | void onError(int error, Camera camera); |
| 643 | }; |
| 644 | |
| 645 | /** |
| 646 | * Registers a callback to be invoked when an error occurs. |
| 647 | * @param cb the callback to run |
| 648 | */ |
| 649 | public final void setErrorCallback(ErrorCallback cb) |
| 650 | { |
| 651 | mErrorCallback = cb; |
| 652 | } |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 653 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 654 | private native final void native_setParameters(String params); |
| 655 | private native final String native_getParameters(); |
| 656 | |
| 657 | /** |
| 658 | * Sets the Parameters for pictures from this Camera service. |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 659 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 660 | * @param params the Parameters to use for this Camera service |
| 661 | */ |
| 662 | public void setParameters(Parameters params) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 663 | native_setParameters(params.flatten()); |
| 664 | } |
| 665 | |
| 666 | /** |
| 667 | * Returns the picture Parameters for this Camera service. |
| 668 | */ |
| 669 | public Parameters getParameters() { |
| 670 | Parameters p = new Parameters(); |
| 671 | String s = native_getParameters(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 672 | p.unflatten(s); |
| 673 | return p; |
| 674 | } |
| 675 | |
| 676 | /** |
| 677 | * Handles the picture size (dimensions). |
| 678 | */ |
| 679 | public class Size { |
| 680 | /** |
| 681 | * Sets the dimensions for pictures. |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 682 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 683 | * @param w the photo width (pixels) |
| 684 | * @param h the photo height (pixels) |
| 685 | */ |
| 686 | public Size(int w, int h) { |
| 687 | width = w; |
| 688 | height = h; |
| 689 | } |
Wu-cheng Li | 4c4300c | 2010-01-23 15:45:39 +0800 | [diff] [blame] | 690 | /** |
| 691 | * Compares {@code obj} to this size. |
| 692 | * |
| 693 | * @param obj the object to compare this size with. |
| 694 | * @return {@code true} if the width and height of {@code obj} is the |
| 695 | * same as those of this size. {@code false} otherwise. |
| 696 | */ |
| 697 | @Override |
| 698 | public boolean equals(Object obj) { |
| 699 | if (!(obj instanceof Size)) { |
| 700 | return false; |
| 701 | } |
| 702 | Size s = (Size) obj; |
| 703 | return width == s.width && height == s.height; |
| 704 | } |
| 705 | @Override |
| 706 | public int hashCode() { |
| 707 | return width * 32713 + height; |
| 708 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 709 | /** width of the picture */ |
| 710 | public int width; |
| 711 | /** height of the picture */ |
| 712 | public int height; |
| 713 | }; |
| 714 | |
| 715 | /** |
| 716 | * Handles the parameters for pictures created by a Camera service. |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 717 | * |
| 718 | * <p>To make camera parameters take effect, applications have to call |
| 719 | * Camera.setParameters. For example, after setWhiteBalance is called, white |
| 720 | * balance is not changed until Camera.setParameters() is called. |
| 721 | * |
| 722 | * <p>Different devices may have different camera capabilities, such as |
| 723 | * picture size or flash modes. The application should query the camera |
| 724 | * capabilities before setting parameters. For example, the application |
| 725 | * should call getSupportedColorEffects before calling setEffect. If the |
| 726 | * camera does not support color effects, getSupportedColorEffects will |
| 727 | * return null. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 728 | */ |
| 729 | public class Parameters { |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 730 | // Parameter keys to communicate with the camera driver. |
| 731 | private static final String KEY_PREVIEW_SIZE = "preview-size"; |
| 732 | private static final String KEY_PREVIEW_FORMAT = "preview-format"; |
| 733 | private static final String KEY_PREVIEW_FRAME_RATE = "preview-frame-rate"; |
| 734 | private static final String KEY_PICTURE_SIZE = "picture-size"; |
| 735 | private static final String KEY_PICTURE_FORMAT = "picture-format"; |
Wu-cheng Li | 4c4300c | 2010-01-23 15:45:39 +0800 | [diff] [blame] | 736 | private static final String KEY_JPEG_THUMBNAIL_SIZE = "jpeg-thumbnail-size"; |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 737 | private static final String KEY_JPEG_THUMBNAIL_WIDTH = "jpeg-thumbnail-width"; |
| 738 | private static final String KEY_JPEG_THUMBNAIL_HEIGHT = "jpeg-thumbnail-height"; |
| 739 | private static final String KEY_JPEG_THUMBNAIL_QUALITY = "jpeg-thumbnail-quality"; |
| 740 | private static final String KEY_JPEG_QUALITY = "jpeg-quality"; |
| 741 | private static final String KEY_ROTATION = "rotation"; |
| 742 | private static final String KEY_GPS_LATITUDE = "gps-latitude"; |
| 743 | private static final String KEY_GPS_LONGITUDE = "gps-longitude"; |
| 744 | private static final String KEY_GPS_ALTITUDE = "gps-altitude"; |
| 745 | private static final String KEY_GPS_TIMESTAMP = "gps-timestamp"; |
Ray Chen | 055c986 | 2010-02-23 10:45:42 +0800 | [diff] [blame] | 746 | private static final String KEY_GPS_PROCESSING_METHOD = "gps-processing-method"; |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 747 | private static final String KEY_WHITE_BALANCE = "whitebalance"; |
| 748 | private static final String KEY_EFFECT = "effect"; |
| 749 | private static final String KEY_ANTIBANDING = "antibanding"; |
| 750 | private static final String KEY_SCENE_MODE = "scene-mode"; |
| 751 | private static final String KEY_FLASH_MODE = "flash-mode"; |
Wu-cheng Li | 36322db | 2009-09-18 18:59:21 +0800 | [diff] [blame] | 752 | private static final String KEY_FOCUS_MODE = "focus-mode"; |
Wu-cheng Li | 6c8d276 | 2010-01-27 22:55:14 +0800 | [diff] [blame] | 753 | private static final String KEY_FOCAL_LENGTH = "focal-length"; |
| 754 | private static final String KEY_HORIZONTAL_VIEW_ANGLE = "horizontal-view-angle"; |
| 755 | private static final String KEY_VERTICAL_VIEW_ANGLE = "vertical-view-angle"; |
Wu-cheng Li | ff723b6 | 2010-02-09 13:38:19 +0800 | [diff] [blame] | 756 | private static final String KEY_EXPOSURE_COMPENSATION = "exposure-compensation"; |
Wu-cheng Li | 24b326a | 2010-02-20 17:47:04 +0800 | [diff] [blame] | 757 | private static final String KEY_MAX_EXPOSURE_COMPENSATION = "max-exposure-compensation"; |
| 758 | private static final String KEY_MIN_EXPOSURE_COMPENSATION = "min-exposure-compensation"; |
| 759 | private static final String KEY_EXPOSURE_COMPENSATION_STEP = "exposure-compensation-step"; |
Wu-cheng Li | 8cbb8f5 | 2010-02-28 23:19:55 -0800 | [diff] [blame] | 760 | private static final String KEY_ZOOM = "zoom"; |
| 761 | private static final String KEY_MAX_ZOOM = "max-zoom"; |
| 762 | private static final String KEY_ZOOM_RATIOS = "zoom-ratios"; |
| 763 | private static final String KEY_ZOOM_SUPPORTED = "zoom-supported"; |
| 764 | private static final String KEY_SMOOTH_ZOOM_SUPPORTED = "smooth-zoom-supported"; |
Wu-cheng Li | e339c5e | 2010-05-13 19:31:02 +0800 | [diff] [blame^] | 765 | private static final String KEY_FOCUS_DISTANCES = "focus-distances"; |
| 766 | |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 767 | // Parameter key suffix for supported values. |
| 768 | private static final String SUPPORTED_VALUES_SUFFIX = "-values"; |
| 769 | |
Wu-cheng Li | 8cbb8f5 | 2010-02-28 23:19:55 -0800 | [diff] [blame] | 770 | private static final String TRUE = "true"; |
| 771 | |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 772 | // Values for white balance settings. |
| 773 | public static final String WHITE_BALANCE_AUTO = "auto"; |
| 774 | public static final String WHITE_BALANCE_INCANDESCENT = "incandescent"; |
| 775 | public static final String WHITE_BALANCE_FLUORESCENT = "fluorescent"; |
| 776 | public static final String WHITE_BALANCE_WARM_FLUORESCENT = "warm-fluorescent"; |
| 777 | public static final String WHITE_BALANCE_DAYLIGHT = "daylight"; |
| 778 | public static final String WHITE_BALANCE_CLOUDY_DAYLIGHT = "cloudy-daylight"; |
| 779 | public static final String WHITE_BALANCE_TWILIGHT = "twilight"; |
| 780 | public static final String WHITE_BALANCE_SHADE = "shade"; |
| 781 | |
| 782 | // Values for color effect settings. |
| 783 | public static final String EFFECT_NONE = "none"; |
| 784 | public static final String EFFECT_MONO = "mono"; |
| 785 | public static final String EFFECT_NEGATIVE = "negative"; |
| 786 | public static final String EFFECT_SOLARIZE = "solarize"; |
| 787 | public static final String EFFECT_SEPIA = "sepia"; |
| 788 | public static final String EFFECT_POSTERIZE = "posterize"; |
| 789 | public static final String EFFECT_WHITEBOARD = "whiteboard"; |
| 790 | public static final String EFFECT_BLACKBOARD = "blackboard"; |
| 791 | public static final String EFFECT_AQUA = "aqua"; |
| 792 | |
| 793 | // Values for antibanding settings. |
| 794 | public static final String ANTIBANDING_AUTO = "auto"; |
| 795 | public static final String ANTIBANDING_50HZ = "50hz"; |
| 796 | public static final String ANTIBANDING_60HZ = "60hz"; |
| 797 | public static final String ANTIBANDING_OFF = "off"; |
| 798 | |
| 799 | // Values for flash mode settings. |
| 800 | /** |
| 801 | * Flash will not be fired. |
| 802 | */ |
| 803 | public static final String FLASH_MODE_OFF = "off"; |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 804 | |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 805 | /** |
Wu-cheng Li | 068ef42 | 2009-09-27 13:19:36 -0700 | [diff] [blame] | 806 | * Flash will be fired automatically when required. The flash may be fired |
| 807 | * during preview, auto-focus, or snapshot depending on the driver. |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 808 | */ |
| 809 | public static final String FLASH_MODE_AUTO = "auto"; |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 810 | |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 811 | /** |
Wu-cheng Li | 068ef42 | 2009-09-27 13:19:36 -0700 | [diff] [blame] | 812 | * Flash will always be fired during snapshot. The flash may also be |
| 813 | * fired during preview or auto-focus depending on the driver. |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 814 | */ |
| 815 | public static final String FLASH_MODE_ON = "on"; |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 816 | |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 817 | /** |
| 818 | * Flash will be fired in red-eye reduction mode. |
| 819 | */ |
| 820 | public static final String FLASH_MODE_RED_EYE = "red-eye"; |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 821 | |
Wu-cheng Li | 36322db | 2009-09-18 18:59:21 +0800 | [diff] [blame] | 822 | /** |
Wu-cheng Li | 068ef42 | 2009-09-27 13:19:36 -0700 | [diff] [blame] | 823 | * Constant emission of light during preview, auto-focus and snapshot. |
| 824 | * This can also be used for video recording. |
Wu-cheng Li | 36322db | 2009-09-18 18:59:21 +0800 | [diff] [blame] | 825 | */ |
Wu-cheng Li | 068ef42 | 2009-09-27 13:19:36 -0700 | [diff] [blame] | 826 | public static final String FLASH_MODE_TORCH = "torch"; |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 827 | |
| 828 | // Values for scene mode settings. |
| 829 | public static final String SCENE_MODE_AUTO = "auto"; |
| 830 | public static final String SCENE_MODE_ACTION = "action"; |
| 831 | public static final String SCENE_MODE_PORTRAIT = "portrait"; |
| 832 | public static final String SCENE_MODE_LANDSCAPE = "landscape"; |
| 833 | public static final String SCENE_MODE_NIGHT = "night"; |
| 834 | public static final String SCENE_MODE_NIGHT_PORTRAIT = "night-portrait"; |
| 835 | public static final String SCENE_MODE_THEATRE = "theatre"; |
| 836 | public static final String SCENE_MODE_BEACH = "beach"; |
| 837 | public static final String SCENE_MODE_SNOW = "snow"; |
| 838 | public static final String SCENE_MODE_SUNSET = "sunset"; |
| 839 | public static final String SCENE_MODE_STEADYPHOTO = "steadyphoto"; |
| 840 | public static final String SCENE_MODE_FIREWORKS = "fireworks"; |
| 841 | public static final String SCENE_MODE_SPORTS = "sports"; |
| 842 | public static final String SCENE_MODE_PARTY = "party"; |
| 843 | public static final String SCENE_MODE_CANDLELIGHT = "candlelight"; |
| 844 | |
Wu-cheng Li | c58b423 | 2010-03-29 17:21:28 +0800 | [diff] [blame] | 845 | /** |
| 846 | * Applications are looking for a barcode. Camera driver will be |
| 847 | * optimized for barcode reading. |
| 848 | */ |
| 849 | public static final String SCENE_MODE_BARCODE = "barcode"; |
| 850 | |
Wu-cheng Li | 36322db | 2009-09-18 18:59:21 +0800 | [diff] [blame] | 851 | // Values for focus mode settings. |
| 852 | /** |
| 853 | * Auto-focus mode. |
| 854 | */ |
| 855 | public static final String FOCUS_MODE_AUTO = "auto"; |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 856 | |
Wu-cheng Li | 36322db | 2009-09-18 18:59:21 +0800 | [diff] [blame] | 857 | /** |
| 858 | * Focus is set at infinity. Applications should not call |
| 859 | * {@link #autoFocus(AutoFocusCallback)} in this mode. |
| 860 | */ |
| 861 | public static final String FOCUS_MODE_INFINITY = "infinity"; |
| 862 | public static final String FOCUS_MODE_MACRO = "macro"; |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 863 | |
Wu-cheng Li | 36322db | 2009-09-18 18:59:21 +0800 | [diff] [blame] | 864 | /** |
| 865 | * Focus is fixed. The camera is always in this mode if the focus is not |
| 866 | * adjustable. If the camera has auto-focus, this mode can fix the |
| 867 | * focus, which is usually at hyperfocal distance. Applications should |
| 868 | * not call {@link #autoFocus(AutoFocusCallback)} in this mode. |
| 869 | */ |
| 870 | public static final String FOCUS_MODE_FIXED = "fixed"; |
| 871 | |
Wu-cheng Li | c58b423 | 2010-03-29 17:21:28 +0800 | [diff] [blame] | 872 | /** |
| 873 | * Extended depth of field (EDOF). Focusing is done digitally and |
| 874 | * continuously. Applications should not call {@link |
| 875 | * #autoFocus(AutoFocusCallback)} in this mode. |
| 876 | */ |
| 877 | public static final String FOCUS_MODE_EDOF = "edof"; |
| 878 | |
Wu-cheng Li | e339c5e | 2010-05-13 19:31:02 +0800 | [diff] [blame^] | 879 | // Indices for focus distance array. |
| 880 | /** |
| 881 | * The array index of near focus distance for use with |
| 882 | * {@link #getFocusDistances(float[])}. |
| 883 | */ |
| 884 | public static final int FOCUS_DISTANCE_NEAR_INDEX = 0; |
| 885 | |
| 886 | /** |
| 887 | * The array index of optimal focus distance for use with |
| 888 | * {@link #getFocusDistances(float[])}. |
| 889 | */ |
| 890 | public static final int FOCUS_DISTANCE_OPTIMAL_INDEX = 1; |
| 891 | |
| 892 | /** |
| 893 | * The array index of far focus distance for use with |
| 894 | * {@link #getFocusDistances(float[])}. |
| 895 | */ |
| 896 | public static final int FOCUS_DISTANCE_FAR_INDEX = 2; |
| 897 | |
Wu-cheng Li | ca09961 | 2010-05-06 16:47:30 +0800 | [diff] [blame] | 898 | /** |
| 899 | * Continuous focus mode. The camera continuously tries to focus. This |
| 900 | * is ideal for shooting video or shooting photo of moving object. |
| 901 | * Continuous focus starts when {@link #autoFocus(AutoFocusCallback)} is |
Wu-cheng Li | e339c5e | 2010-05-13 19:31:02 +0800 | [diff] [blame^] | 902 | * called. Continuous focus stops when {@link #cancelAutoFocus()} is |
Wu-cheng Li | ca09961 | 2010-05-06 16:47:30 +0800 | [diff] [blame] | 903 | * called. AutoFocusCallback will be only called once as soon as the |
| 904 | * picture is in focus. |
| 905 | */ |
| 906 | public static final String FOCUS_MODE_CONTINUOUS = "continuous"; |
| 907 | |
| 908 | |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 909 | // Formats for setPreviewFormat and setPictureFormat. |
| 910 | private static final String PIXEL_FORMAT_YUV422SP = "yuv422sp"; |
| 911 | private static final String PIXEL_FORMAT_YUV420SP = "yuv420sp"; |
Chih-Chung Chang | eb68c46 | 2009-09-18 18:37:44 +0800 | [diff] [blame] | 912 | private static final String PIXEL_FORMAT_YUV422I = "yuv422i-yuyv"; |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 913 | private static final String PIXEL_FORMAT_RGB565 = "rgb565"; |
| 914 | private static final String PIXEL_FORMAT_JPEG = "jpeg"; |
| 915 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 916 | private HashMap<String, String> mMap; |
| 917 | |
| 918 | private Parameters() { |
| 919 | mMap = new HashMap<String, String>(); |
| 920 | } |
| 921 | |
| 922 | /** |
| 923 | * Writes the current Parameters to the log. |
| 924 | * @hide |
| 925 | * @deprecated |
| 926 | */ |
| 927 | public void dump() { |
| 928 | Log.e(TAG, "dump: size=" + mMap.size()); |
| 929 | for (String k : mMap.keySet()) { |
| 930 | Log.e(TAG, "dump: " + k + "=" + mMap.get(k)); |
| 931 | } |
| 932 | } |
| 933 | |
| 934 | /** |
| 935 | * Creates a single string with all the parameters set in |
| 936 | * this Parameters object. |
| 937 | * <p>The {@link #unflatten(String)} method does the reverse.</p> |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 938 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 939 | * @return a String with all values from this Parameters object, in |
| 940 | * semi-colon delimited key-value pairs |
| 941 | */ |
| 942 | public String flatten() { |
| 943 | StringBuilder flattened = new StringBuilder(); |
| 944 | for (String k : mMap.keySet()) { |
| 945 | flattened.append(k); |
| 946 | flattened.append("="); |
| 947 | flattened.append(mMap.get(k)); |
| 948 | flattened.append(";"); |
| 949 | } |
| 950 | // chop off the extra semicolon at the end |
| 951 | flattened.deleteCharAt(flattened.length()-1); |
| 952 | return flattened.toString(); |
| 953 | } |
| 954 | |
| 955 | /** |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 956 | * 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] | 957 | * this Parameters object. |
| 958 | * <p>The {@link #flatten()} method does the reverse.</p> |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 959 | * |
| 960 | * @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] | 961 | * are semi-colon delimited |
| 962 | */ |
| 963 | public void unflatten(String flattened) { |
| 964 | mMap.clear(); |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 965 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 966 | StringTokenizer tokenizer = new StringTokenizer(flattened, ";"); |
| 967 | while (tokenizer.hasMoreElements()) { |
| 968 | String kv = tokenizer.nextToken(); |
| 969 | int pos = kv.indexOf('='); |
| 970 | if (pos == -1) { |
| 971 | continue; |
| 972 | } |
| 973 | String k = kv.substring(0, pos); |
| 974 | String v = kv.substring(pos + 1); |
| 975 | mMap.put(k, v); |
| 976 | } |
| 977 | } |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 978 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 979 | public void remove(String key) { |
| 980 | mMap.remove(key); |
| 981 | } |
| 982 | |
| 983 | /** |
| 984 | * Sets a String parameter. |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 985 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 986 | * @param key the key name for the parameter |
| 987 | * @param value the String value of the parameter |
| 988 | */ |
| 989 | public void set(String key, String value) { |
| 990 | if (key.indexOf('=') != -1 || key.indexOf(';') != -1) { |
| 991 | Log.e(TAG, "Key \"" + key + "\" contains invalid character (= or ;)"); |
| 992 | return; |
| 993 | } |
| 994 | if (value.indexOf('=') != -1 || value.indexOf(';') != -1) { |
| 995 | Log.e(TAG, "Value \"" + value + "\" contains invalid character (= or ;)"); |
| 996 | return; |
| 997 | } |
| 998 | |
| 999 | mMap.put(key, value); |
| 1000 | } |
| 1001 | |
| 1002 | /** |
| 1003 | * Sets an integer parameter. |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1004 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1005 | * @param key the key name for the parameter |
| 1006 | * @param value the int value of the parameter |
| 1007 | */ |
| 1008 | public void set(String key, int value) { |
| 1009 | mMap.put(key, Integer.toString(value)); |
| 1010 | } |
| 1011 | |
| 1012 | /** |
| 1013 | * Returns the value of a String parameter. |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1014 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1015 | * @param key the key name for the parameter |
| 1016 | * @return the String value of the parameter |
| 1017 | */ |
| 1018 | public String get(String key) { |
| 1019 | return mMap.get(key); |
| 1020 | } |
| 1021 | |
| 1022 | /** |
| 1023 | * Returns the value of an integer parameter. |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1024 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1025 | * @param key the key name for the parameter |
| 1026 | * @return the int value of the parameter |
| 1027 | */ |
| 1028 | public int getInt(String key) { |
| 1029 | return Integer.parseInt(mMap.get(key)); |
| 1030 | } |
| 1031 | |
| 1032 | /** |
| 1033 | * Sets the dimensions for preview pictures. |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1034 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1035 | * @param width the width of the pictures, in pixels |
| 1036 | * @param height the height of the pictures, in pixels |
| 1037 | */ |
| 1038 | public void setPreviewSize(int width, int height) { |
| 1039 | String v = Integer.toString(width) + "x" + Integer.toString(height); |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1040 | set(KEY_PREVIEW_SIZE, v); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1041 | } |
| 1042 | |
| 1043 | /** |
| 1044 | * Returns the dimensions setting for preview pictures. |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1045 | * |
| 1046 | * @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] | 1047 | * for the preview picture |
| 1048 | */ |
| 1049 | public Size getPreviewSize() { |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1050 | String pair = get(KEY_PREVIEW_SIZE); |
| 1051 | return strToSize(pair); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1052 | } |
| 1053 | |
| 1054 | /** |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1055 | * Gets the supported preview sizes. |
| 1056 | * |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 1057 | * @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] | 1058 | * with at least one element. |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1059 | */ |
| 1060 | public List<Size> getSupportedPreviewSizes() { |
| 1061 | String str = get(KEY_PREVIEW_SIZE + SUPPORTED_VALUES_SUFFIX); |
| 1062 | return splitSize(str); |
| 1063 | } |
| 1064 | |
| 1065 | /** |
Wu-cheng Li | 4c4300c | 2010-01-23 15:45:39 +0800 | [diff] [blame] | 1066 | * Sets the dimensions for EXIF thumbnail in Jpeg picture. If |
| 1067 | * applications set both width and height to 0, EXIF will not contain |
| 1068 | * thumbnail. |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1069 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1070 | * @param width the width of the thumbnail, in pixels |
| 1071 | * @param height the height of the thumbnail, in pixels |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1072 | */ |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1073 | public void setJpegThumbnailSize(int width, int height) { |
| 1074 | set(KEY_JPEG_THUMBNAIL_WIDTH, width); |
| 1075 | set(KEY_JPEG_THUMBNAIL_HEIGHT, height); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1076 | } |
| 1077 | |
| 1078 | /** |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1079 | * Returns the dimensions for EXIF thumbnail in Jpeg picture. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1080 | * |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1081 | * @return a Size object with the height and width setting for the EXIF |
| 1082 | * thumbnails |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1083 | */ |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1084 | public Size getJpegThumbnailSize() { |
| 1085 | return new Size(getInt(KEY_JPEG_THUMBNAIL_WIDTH), |
| 1086 | getInt(KEY_JPEG_THUMBNAIL_HEIGHT)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1087 | } |
| 1088 | |
| 1089 | /** |
Wu-cheng Li | 4c4300c | 2010-01-23 15:45:39 +0800 | [diff] [blame] | 1090 | * Gets the supported jpeg thumbnail sizes. |
| 1091 | * |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 1092 | * @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] | 1093 | * with at least two elements. Size 0,0 (no thumbnail) is always |
| 1094 | * supported. |
| 1095 | */ |
| 1096 | public List<Size> getSupportedJpegThumbnailSizes() { |
| 1097 | String str = get(KEY_JPEG_THUMBNAIL_SIZE + SUPPORTED_VALUES_SUFFIX); |
| 1098 | return splitSize(str); |
| 1099 | } |
| 1100 | |
| 1101 | /** |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1102 | * 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] | 1103 | * |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1104 | * @param quality the JPEG quality of the EXIF thumbnail. The range is 1 |
| 1105 | * to 100, with 100 being the best. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1106 | */ |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1107 | public void setJpegThumbnailQuality(int quality) { |
| 1108 | set(KEY_JPEG_THUMBNAIL_QUALITY, quality); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1109 | } |
| 1110 | |
| 1111 | /** |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1112 | * 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] | 1113 | * |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1114 | * @return the JPEG quality setting of the EXIF thumbnail. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1115 | */ |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1116 | public int getJpegThumbnailQuality() { |
| 1117 | return getInt(KEY_JPEG_THUMBNAIL_QUALITY); |
| 1118 | } |
| 1119 | |
| 1120 | /** |
| 1121 | * Sets Jpeg quality of captured picture. |
| 1122 | * |
| 1123 | * @param quality the JPEG quality of captured picture. The range is 1 |
| 1124 | * to 100, with 100 being the best. |
| 1125 | */ |
| 1126 | public void setJpegQuality(int quality) { |
| 1127 | set(KEY_JPEG_QUALITY, quality); |
| 1128 | } |
| 1129 | |
| 1130 | /** |
| 1131 | * Returns the quality setting for the JPEG picture. |
| 1132 | * |
| 1133 | * @return the JPEG picture quality setting. |
| 1134 | */ |
| 1135 | public int getJpegQuality() { |
| 1136 | return getInt(KEY_JPEG_QUALITY); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1137 | } |
| 1138 | |
| 1139 | /** |
Wu-cheng Li | a18e901 | 2010-02-10 13:05:29 +0800 | [diff] [blame] | 1140 | * Sets the rate at which preview frames are received. This is the |
| 1141 | * target frame rate. The actual frame rate depends on the driver. |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1142 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1143 | * @param fps the frame rate (frames per second) |
| 1144 | */ |
| 1145 | public void setPreviewFrameRate(int fps) { |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1146 | set(KEY_PREVIEW_FRAME_RATE, fps); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1147 | } |
| 1148 | |
| 1149 | /** |
Wu-cheng Li | a18e901 | 2010-02-10 13:05:29 +0800 | [diff] [blame] | 1150 | * Returns the setting for the rate at which preview frames are |
| 1151 | * received. This is the target frame rate. The actual frame rate |
| 1152 | * depends on the driver. |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1153 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1154 | * @return the frame rate setting (frames per second) |
| 1155 | */ |
| 1156 | public int getPreviewFrameRate() { |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1157 | return getInt(KEY_PREVIEW_FRAME_RATE); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1158 | } |
| 1159 | |
| 1160 | /** |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1161 | * Gets the supported preview frame rates. |
| 1162 | * |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 1163 | * @return a list of supported preview frame rates. null if preview |
| 1164 | * frame rate setting is not supported. |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1165 | */ |
| 1166 | public List<Integer> getSupportedPreviewFrameRates() { |
| 1167 | String str = get(KEY_PREVIEW_FRAME_RATE + SUPPORTED_VALUES_SUFFIX); |
| 1168 | return splitInt(str); |
| 1169 | } |
| 1170 | |
| 1171 | /** |
Wu-cheng Li | 7478ea6 | 2009-09-16 18:52:55 +0800 | [diff] [blame] | 1172 | * Sets the image format for preview pictures. |
Scott Main | da0a56d | 2009-09-10 18:08:37 -0700 | [diff] [blame] | 1173 | * <p>If this is never called, the default format will be |
Mathias Agopian | a696f5d | 2010-02-17 17:53:09 -0800 | [diff] [blame] | 1174 | * {@link android.graphics.ImageFormat#NV21}, which |
Scott Main | df4578e | 2009-09-10 12:22:07 -0700 | [diff] [blame] | 1175 | * uses the NV21 encoding format.</p> |
Wu-cheng Li | 7478ea6 | 2009-09-16 18:52:55 +0800 | [diff] [blame] | 1176 | * |
Scott Main | df4578e | 2009-09-10 12:22:07 -0700 | [diff] [blame] | 1177 | * @param pixel_format the desired preview picture format, defined |
Mathias Agopian | a696f5d | 2010-02-17 17:53:09 -0800 | [diff] [blame] | 1178 | * by one of the {@link android.graphics.ImageFormat} constants. |
| 1179 | * (E.g., <var>ImageFormat.NV21</var> (default), |
| 1180 | * <var>ImageFormat.RGB_565</var>, or |
| 1181 | * <var>ImageFormat.JPEG</var>) |
| 1182 | * @see android.graphics.ImageFormat |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1183 | */ |
| 1184 | public void setPreviewFormat(int pixel_format) { |
| 1185 | String s = cameraFormatForPixelFormat(pixel_format); |
| 1186 | if (s == null) { |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1187 | throw new IllegalArgumentException( |
| 1188 | "Invalid pixel_format=" + pixel_format); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1189 | } |
| 1190 | |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1191 | set(KEY_PREVIEW_FORMAT, s); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1192 | } |
| 1193 | |
| 1194 | /** |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 1195 | * Returns the image format for preview frames got from |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1196 | * {@link PreviewCallback}. |
Wu-cheng Li | 7478ea6 | 2009-09-16 18:52:55 +0800 | [diff] [blame] | 1197 | * |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 1198 | * @return the preview format. |
| 1199 | * @see android.graphics.ImageFormat |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1200 | */ |
| 1201 | public int getPreviewFormat() { |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1202 | return pixelFormatForCameraFormat(get(KEY_PREVIEW_FORMAT)); |
| 1203 | } |
| 1204 | |
| 1205 | /** |
| 1206 | * Gets the supported preview formats. |
| 1207 | * |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 1208 | * @return a list of supported preview formats. This method will always |
| 1209 | * return a list with at least one element. |
| 1210 | * @see android.graphics.ImageFormat |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1211 | */ |
| 1212 | public List<Integer> getSupportedPreviewFormats() { |
| 1213 | String str = get(KEY_PREVIEW_FORMAT + SUPPORTED_VALUES_SUFFIX); |
Chih-Chung Chang | eb68c46 | 2009-09-18 18:37:44 +0800 | [diff] [blame] | 1214 | ArrayList<Integer> formats = new ArrayList<Integer>(); |
| 1215 | for (String s : split(str)) { |
| 1216 | int f = pixelFormatForCameraFormat(s); |
Mathias Agopian | a696f5d | 2010-02-17 17:53:09 -0800 | [diff] [blame] | 1217 | if (f == ImageFormat.UNKNOWN) continue; |
Chih-Chung Chang | eb68c46 | 2009-09-18 18:37:44 +0800 | [diff] [blame] | 1218 | formats.add(f); |
| 1219 | } |
| 1220 | return formats; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1221 | } |
| 1222 | |
| 1223 | /** |
| 1224 | * Sets the dimensions for pictures. |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1225 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1226 | * @param width the width for pictures, in pixels |
| 1227 | * @param height the height for pictures, in pixels |
| 1228 | */ |
| 1229 | public void setPictureSize(int width, int height) { |
| 1230 | String v = Integer.toString(width) + "x" + Integer.toString(height); |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1231 | set(KEY_PICTURE_SIZE, v); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1232 | } |
| 1233 | |
| 1234 | /** |
| 1235 | * Returns the dimension setting for pictures. |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1236 | * |
| 1237 | * @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] | 1238 | * for pictures |
| 1239 | */ |
| 1240 | public Size getPictureSize() { |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1241 | String pair = get(KEY_PICTURE_SIZE); |
| 1242 | return strToSize(pair); |
| 1243 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1244 | |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1245 | /** |
| 1246 | * Gets the supported picture sizes. |
| 1247 | * |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 1248 | * @return a list of supported picture sizes. This method will always |
| 1249 | * return a list with at least one element. |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1250 | */ |
| 1251 | public List<Size> getSupportedPictureSizes() { |
| 1252 | String str = get(KEY_PICTURE_SIZE + SUPPORTED_VALUES_SUFFIX); |
| 1253 | return splitSize(str); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1254 | } |
| 1255 | |
| 1256 | /** |
| 1257 | * Sets the image format for pictures. |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1258 | * |
| 1259 | * @param pixel_format the desired picture format |
Mathias Agopian | a696f5d | 2010-02-17 17:53:09 -0800 | [diff] [blame] | 1260 | * (<var>ImageFormat.NV21</var>, |
| 1261 | * <var>ImageFormat.RGB_565</var>, or |
| 1262 | * <var>ImageFormat.JPEG</var>) |
| 1263 | * @see android.graphics.ImageFormat |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1264 | */ |
| 1265 | public void setPictureFormat(int pixel_format) { |
| 1266 | String s = cameraFormatForPixelFormat(pixel_format); |
| 1267 | if (s == null) { |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1268 | throw new IllegalArgumentException( |
| 1269 | "Invalid pixel_format=" + pixel_format); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1270 | } |
| 1271 | |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1272 | set(KEY_PICTURE_FORMAT, s); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1273 | } |
| 1274 | |
| 1275 | /** |
| 1276 | * Returns the image format for pictures. |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1277 | * |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 1278 | * @return the picture format |
| 1279 | * @see android.graphics.ImageFormat |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1280 | */ |
| 1281 | public int getPictureFormat() { |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1282 | return pixelFormatForCameraFormat(get(KEY_PICTURE_FORMAT)); |
| 1283 | } |
| 1284 | |
| 1285 | /** |
| 1286 | * Gets the supported picture formats. |
| 1287 | * |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 1288 | * @return supported picture formats. This method will always return a |
| 1289 | * list with at least one element. |
| 1290 | * @see android.graphics.ImageFormat |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1291 | */ |
| 1292 | public List<Integer> getSupportedPictureFormats() { |
Wu-cheng Li | 9c79938 | 2009-12-04 19:59:18 +0800 | [diff] [blame] | 1293 | String str = get(KEY_PICTURE_FORMAT + SUPPORTED_VALUES_SUFFIX); |
| 1294 | ArrayList<Integer> formats = new ArrayList<Integer>(); |
| 1295 | for (String s : split(str)) { |
| 1296 | int f = pixelFormatForCameraFormat(s); |
Mathias Agopian | a696f5d | 2010-02-17 17:53:09 -0800 | [diff] [blame] | 1297 | if (f == ImageFormat.UNKNOWN) continue; |
Wu-cheng Li | 9c79938 | 2009-12-04 19:59:18 +0800 | [diff] [blame] | 1298 | formats.add(f); |
| 1299 | } |
| 1300 | return formats; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1301 | } |
| 1302 | |
| 1303 | private String cameraFormatForPixelFormat(int pixel_format) { |
| 1304 | switch(pixel_format) { |
Mathias Agopian | a696f5d | 2010-02-17 17:53:09 -0800 | [diff] [blame] | 1305 | case ImageFormat.NV16: return PIXEL_FORMAT_YUV422SP; |
| 1306 | case ImageFormat.NV21: return PIXEL_FORMAT_YUV420SP; |
| 1307 | case ImageFormat.YUY2: return PIXEL_FORMAT_YUV422I; |
| 1308 | case ImageFormat.RGB_565: return PIXEL_FORMAT_RGB565; |
| 1309 | case ImageFormat.JPEG: return PIXEL_FORMAT_JPEG; |
| 1310 | default: return null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1311 | } |
| 1312 | } |
| 1313 | |
| 1314 | private int pixelFormatForCameraFormat(String format) { |
| 1315 | if (format == null) |
Mathias Agopian | a696f5d | 2010-02-17 17:53:09 -0800 | [diff] [blame] | 1316 | return ImageFormat.UNKNOWN; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1317 | |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1318 | if (format.equals(PIXEL_FORMAT_YUV422SP)) |
Mathias Agopian | a696f5d | 2010-02-17 17:53:09 -0800 | [diff] [blame] | 1319 | return ImageFormat.NV16; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1320 | |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1321 | if (format.equals(PIXEL_FORMAT_YUV420SP)) |
Mathias Agopian | a696f5d | 2010-02-17 17:53:09 -0800 | [diff] [blame] | 1322 | return ImageFormat.NV21; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1323 | |
Chih-Chung Chang | eb68c46 | 2009-09-18 18:37:44 +0800 | [diff] [blame] | 1324 | if (format.equals(PIXEL_FORMAT_YUV422I)) |
Mathias Agopian | a696f5d | 2010-02-17 17:53:09 -0800 | [diff] [blame] | 1325 | return ImageFormat.YUY2; |
Chih-Chung Chang | eb68c46 | 2009-09-18 18:37:44 +0800 | [diff] [blame] | 1326 | |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1327 | if (format.equals(PIXEL_FORMAT_RGB565)) |
Mathias Agopian | a696f5d | 2010-02-17 17:53:09 -0800 | [diff] [blame] | 1328 | return ImageFormat.RGB_565; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1329 | |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1330 | if (format.equals(PIXEL_FORMAT_JPEG)) |
Mathias Agopian | a696f5d | 2010-02-17 17:53:09 -0800 | [diff] [blame] | 1331 | return ImageFormat.JPEG; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1332 | |
Mathias Agopian | a696f5d | 2010-02-17 17:53:09 -0800 | [diff] [blame] | 1333 | return ImageFormat.UNKNOWN; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1334 | } |
| 1335 | |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1336 | /** |
Wu-cheng Li | e6bea60 | 2009-09-23 15:45:27 -0700 | [diff] [blame] | 1337 | * Sets the orientation of the device in degrees. For example, suppose |
| 1338 | * the natural position of the device is landscape. If the user takes a |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1339 | * picture in landscape mode in 2048x1536 resolution, the rotation |
| 1340 | * should be set to 0. If the user rotates the phone 90 degrees |
| 1341 | * clockwise, the rotation should be set to 90. Applications can use |
| 1342 | * {@link android.view.OrientationEventListener} to set this parameter. |
| 1343 | * |
Wu-cheng Li | e6bea60 | 2009-09-23 15:45:27 -0700 | [diff] [blame] | 1344 | * The camera driver may set orientation in the EXIF header without |
| 1345 | * rotating the picture. Or the driver may rotate the picture and |
| 1346 | * the EXIF thumbnail. If the Jpeg picture is rotated, the orientation |
| 1347 | * in the EXIF header will be missing or 1 (row #0 is top and column #0 |
| 1348 | * is left side). |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1349 | * |
| 1350 | * @param rotation The orientation of the device in degrees. Rotation |
| 1351 | * can only be 0, 90, 180 or 270. |
| 1352 | * @throws IllegalArgumentException if rotation value is invalid. |
| 1353 | * @see android.view.OrientationEventListener |
| 1354 | */ |
| 1355 | public void setRotation(int rotation) { |
| 1356 | if (rotation == 0 || rotation == 90 || rotation == 180 |
| 1357 | || rotation == 270) { |
| 1358 | set(KEY_ROTATION, Integer.toString(rotation)); |
| 1359 | } else { |
| 1360 | throw new IllegalArgumentException( |
| 1361 | "Invalid rotation=" + rotation); |
| 1362 | } |
| 1363 | } |
| 1364 | |
| 1365 | /** |
| 1366 | * Sets GPS latitude coordinate. This will be stored in JPEG EXIF |
| 1367 | * header. |
| 1368 | * |
| 1369 | * @param latitude GPS latitude coordinate. |
| 1370 | */ |
| 1371 | public void setGpsLatitude(double latitude) { |
| 1372 | set(KEY_GPS_LATITUDE, Double.toString(latitude)); |
| 1373 | } |
| 1374 | |
| 1375 | /** |
| 1376 | * Sets GPS longitude coordinate. This will be stored in JPEG EXIF |
| 1377 | * header. |
| 1378 | * |
| 1379 | * @param longitude GPS longitude coordinate. |
| 1380 | */ |
| 1381 | public void setGpsLongitude(double longitude) { |
| 1382 | set(KEY_GPS_LONGITUDE, Double.toString(longitude)); |
| 1383 | } |
| 1384 | |
| 1385 | /** |
| 1386 | * Sets GPS altitude. This will be stored in JPEG EXIF header. |
| 1387 | * |
| 1388 | * @param altitude GPS altitude in meters. |
| 1389 | */ |
| 1390 | public void setGpsAltitude(double altitude) { |
| 1391 | set(KEY_GPS_ALTITUDE, Double.toString(altitude)); |
| 1392 | } |
| 1393 | |
| 1394 | /** |
| 1395 | * Sets GPS timestamp. This will be stored in JPEG EXIF header. |
| 1396 | * |
| 1397 | * @param timestamp GPS timestamp (UTC in seconds since January 1, |
| 1398 | * 1970). |
| 1399 | */ |
| 1400 | public void setGpsTimestamp(long timestamp) { |
| 1401 | set(KEY_GPS_TIMESTAMP, Long.toString(timestamp)); |
| 1402 | } |
| 1403 | |
| 1404 | /** |
Ray Chen | e208377 | 2010-03-10 15:02:49 -0800 | [diff] [blame] | 1405 | * Sets GPS processing method. It will store up to 32 characters |
Ray Chen | 055c986 | 2010-02-23 10:45:42 +0800 | [diff] [blame] | 1406 | * in JPEG EXIF header. |
| 1407 | * |
| 1408 | * @param processing_method The processing method to get this location. |
| 1409 | */ |
| 1410 | public void setGpsProcessingMethod(String processing_method) { |
| 1411 | set(KEY_GPS_PROCESSING_METHOD, processing_method); |
| 1412 | } |
| 1413 | |
| 1414 | /** |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1415 | * Removes GPS latitude, longitude, altitude, and timestamp from the |
| 1416 | * parameters. |
| 1417 | */ |
| 1418 | public void removeGpsData() { |
| 1419 | remove(KEY_GPS_LATITUDE); |
| 1420 | remove(KEY_GPS_LONGITUDE); |
| 1421 | remove(KEY_GPS_ALTITUDE); |
| 1422 | remove(KEY_GPS_TIMESTAMP); |
Ray Chen | 055c986 | 2010-02-23 10:45:42 +0800 | [diff] [blame] | 1423 | remove(KEY_GPS_PROCESSING_METHOD); |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1424 | } |
| 1425 | |
| 1426 | /** |
| 1427 | * Gets the current white balance setting. |
| 1428 | * |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 1429 | * @return current white balance. null if white balance setting is not |
| 1430 | * supported. |
| 1431 | * @see #WHITE_BALANCE_AUTO |
| 1432 | * @see #WHITE_BALANCE_INCANDESCENT |
| 1433 | * @see #WHITE_BALANCE_FLUORESCENT |
| 1434 | * @see #WHITE_BALANCE_WARM_FLUORESCENT |
| 1435 | * @see #WHITE_BALANCE_DAYLIGHT |
| 1436 | * @see #WHITE_BALANCE_CLOUDY_DAYLIGHT |
| 1437 | * @see #WHITE_BALANCE_TWILIGHT |
| 1438 | * @see #WHITE_BALANCE_SHADE |
| 1439 | * |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1440 | */ |
| 1441 | public String getWhiteBalance() { |
| 1442 | return get(KEY_WHITE_BALANCE); |
| 1443 | } |
| 1444 | |
| 1445 | /** |
| 1446 | * Sets the white balance. |
| 1447 | * |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 1448 | * @param value new white balance. |
| 1449 | * @see #getWhiteBalance() |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1450 | */ |
| 1451 | public void setWhiteBalance(String value) { |
| 1452 | set(KEY_WHITE_BALANCE, value); |
| 1453 | } |
| 1454 | |
| 1455 | /** |
| 1456 | * Gets the supported white balance. |
| 1457 | * |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 1458 | * @return a list of supported white balance. null if white balance |
| 1459 | * setting is not supported. |
| 1460 | * @see #getWhiteBalance() |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1461 | */ |
| 1462 | public List<String> getSupportedWhiteBalance() { |
| 1463 | String str = get(KEY_WHITE_BALANCE + SUPPORTED_VALUES_SUFFIX); |
| 1464 | return split(str); |
| 1465 | } |
| 1466 | |
| 1467 | /** |
| 1468 | * Gets the current color effect setting. |
| 1469 | * |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 1470 | * @return current color effect. null if color effect |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1471 | * setting is not supported. |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 1472 | * @see #EFFECT_NONE |
| 1473 | * @see #EFFECT_MONO |
| 1474 | * @see #EFFECT_NEGATIVE |
| 1475 | * @see #EFFECT_SOLARIZE |
| 1476 | * @see #EFFECT_SEPIA |
| 1477 | * @see #EFFECT_POSTERIZE |
| 1478 | * @see #EFFECT_WHITEBOARD |
| 1479 | * @see #EFFECT_BLACKBOARD |
| 1480 | * @see #EFFECT_AQUA |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1481 | */ |
| 1482 | public String getColorEffect() { |
| 1483 | return get(KEY_EFFECT); |
| 1484 | } |
| 1485 | |
| 1486 | /** |
| 1487 | * Sets the current color effect setting. |
| 1488 | * |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 1489 | * @param value new color effect. |
| 1490 | * @see #getColorEffect() |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1491 | */ |
| 1492 | public void setColorEffect(String value) { |
| 1493 | set(KEY_EFFECT, value); |
| 1494 | } |
| 1495 | |
| 1496 | /** |
| 1497 | * Gets the supported color effects. |
| 1498 | * |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 1499 | * @return a list of supported color effects. null if color effect |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1500 | * setting is not supported. |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 1501 | * @see #getColorEffect() |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1502 | */ |
| 1503 | public List<String> getSupportedColorEffects() { |
| 1504 | String str = get(KEY_EFFECT + SUPPORTED_VALUES_SUFFIX); |
| 1505 | return split(str); |
| 1506 | } |
| 1507 | |
| 1508 | |
| 1509 | /** |
| 1510 | * Gets the current antibanding setting. |
| 1511 | * |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 1512 | * @return current antibanding. null if antibanding setting is not |
| 1513 | * supported. |
| 1514 | * @see #ANTIBANDING_AUTO |
| 1515 | * @see #ANTIBANDING_50HZ |
| 1516 | * @see #ANTIBANDING_60HZ |
| 1517 | * @see #ANTIBANDING_OFF |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1518 | */ |
| 1519 | public String getAntibanding() { |
| 1520 | return get(KEY_ANTIBANDING); |
| 1521 | } |
| 1522 | |
| 1523 | /** |
| 1524 | * Sets the antibanding. |
| 1525 | * |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 1526 | * @param antibanding new antibanding value. |
| 1527 | * @see #getAntibanding() |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1528 | */ |
| 1529 | public void setAntibanding(String antibanding) { |
| 1530 | set(KEY_ANTIBANDING, antibanding); |
| 1531 | } |
| 1532 | |
| 1533 | /** |
| 1534 | * Gets the supported antibanding values. |
| 1535 | * |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 1536 | * @return a list of supported antibanding values. null if antibanding |
| 1537 | * setting is not supported. |
| 1538 | * @see #getAntibanding() |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1539 | */ |
| 1540 | public List<String> getSupportedAntibanding() { |
| 1541 | String str = get(KEY_ANTIBANDING + SUPPORTED_VALUES_SUFFIX); |
| 1542 | return split(str); |
| 1543 | } |
| 1544 | |
| 1545 | /** |
| 1546 | * Gets the current scene mode setting. |
| 1547 | * |
| 1548 | * @return one of SCENE_MODE_XXX string constant. null if scene mode |
| 1549 | * setting is not supported. |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 1550 | * @see #SCENE_MODE_AUTO |
| 1551 | * @see #SCENE_MODE_ACTION |
| 1552 | * @see #SCENE_MODE_PORTRAIT |
| 1553 | * @see #SCENE_MODE_LANDSCAPE |
| 1554 | * @see #SCENE_MODE_NIGHT |
| 1555 | * @see #SCENE_MODE_NIGHT_PORTRAIT |
| 1556 | * @see #SCENE_MODE_THEATRE |
| 1557 | * @see #SCENE_MODE_BEACH |
| 1558 | * @see #SCENE_MODE_SNOW |
| 1559 | * @see #SCENE_MODE_SUNSET |
| 1560 | * @see #SCENE_MODE_STEADYPHOTO |
| 1561 | * @see #SCENE_MODE_FIREWORKS |
| 1562 | * @see #SCENE_MODE_SPORTS |
| 1563 | * @see #SCENE_MODE_PARTY |
| 1564 | * @see #SCENE_MODE_CANDLELIGHT |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1565 | */ |
| 1566 | public String getSceneMode() { |
| 1567 | return get(KEY_SCENE_MODE); |
| 1568 | } |
| 1569 | |
| 1570 | /** |
Wu-cheng Li | c58b423 | 2010-03-29 17:21:28 +0800 | [diff] [blame] | 1571 | * Sets the scene mode. Changing scene mode may override other |
| 1572 | * parameters (such as flash mode, focus mode, white balance). For |
| 1573 | * example, suppose originally flash mode is on and supported flash |
| 1574 | * modes are on/off. In night scene mode, both flash mode and supported |
| 1575 | * flash mode may be changed to off. After setting scene mode, |
Wu-cheng Li | 2988ab7 | 2009-09-30 17:08:19 -0700 | [diff] [blame] | 1576 | * applications should call getParameters to know if some parameters are |
| 1577 | * changed. |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1578 | * |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 1579 | * @param value scene mode. |
| 1580 | * @see #getSceneMode() |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1581 | */ |
| 1582 | public void setSceneMode(String value) { |
| 1583 | set(KEY_SCENE_MODE, value); |
| 1584 | } |
| 1585 | |
| 1586 | /** |
| 1587 | * Gets the supported scene modes. |
| 1588 | * |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 1589 | * @return a list of supported scene modes. null if scene mode setting |
| 1590 | * is not supported. |
| 1591 | * @see #getSceneMode() |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1592 | */ |
| 1593 | public List<String> getSupportedSceneModes() { |
| 1594 | String str = get(KEY_SCENE_MODE + SUPPORTED_VALUES_SUFFIX); |
| 1595 | return split(str); |
| 1596 | } |
| 1597 | |
| 1598 | /** |
| 1599 | * Gets the current flash mode setting. |
| 1600 | * |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 1601 | * @return current flash mode. null if flash mode setting is not |
| 1602 | * supported. |
| 1603 | * @see #FLASH_MODE_OFF |
| 1604 | * @see #FLASH_MODE_AUTO |
| 1605 | * @see #FLASH_MODE_ON |
| 1606 | * @see #FLASH_MODE_RED_EYE |
| 1607 | * @see #FLASH_MODE_TORCH |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1608 | */ |
| 1609 | public String getFlashMode() { |
| 1610 | return get(KEY_FLASH_MODE); |
| 1611 | } |
| 1612 | |
| 1613 | /** |
| 1614 | * Sets the flash mode. |
| 1615 | * |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 1616 | * @param value flash mode. |
| 1617 | * @see #getFlashMode() |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1618 | */ |
| 1619 | public void setFlashMode(String value) { |
| 1620 | set(KEY_FLASH_MODE, value); |
| 1621 | } |
| 1622 | |
| 1623 | /** |
| 1624 | * Gets the supported flash modes. |
| 1625 | * |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 1626 | * @return a list of supported flash modes. null if flash mode setting |
| 1627 | * is not supported. |
| 1628 | * @see #getFlashMode() |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1629 | */ |
| 1630 | public List<String> getSupportedFlashModes() { |
| 1631 | String str = get(KEY_FLASH_MODE + SUPPORTED_VALUES_SUFFIX); |
| 1632 | return split(str); |
| 1633 | } |
| 1634 | |
Wu-cheng Li | 36322db | 2009-09-18 18:59:21 +0800 | [diff] [blame] | 1635 | /** |
| 1636 | * Gets the current focus mode setting. |
| 1637 | * |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 1638 | * @return current focus mode. If the camera does not support |
| 1639 | * auto-focus, this should return {@link #FOCUS_MODE_FIXED}. If |
| 1640 | * the focus mode is not FOCUS_MODE_FIXED or {@link |
| 1641 | * #FOCUS_MODE_INFINITY}, applications should call {@link |
| 1642 | * #autoFocus(AutoFocusCallback)} to start the focus. |
| 1643 | * @see #FOCUS_MODE_AUTO |
| 1644 | * @see #FOCUS_MODE_INFINITY |
| 1645 | * @see #FOCUS_MODE_MACRO |
| 1646 | * @see #FOCUS_MODE_FIXED |
Wu-cheng Li | 36322db | 2009-09-18 18:59:21 +0800 | [diff] [blame] | 1647 | */ |
| 1648 | public String getFocusMode() { |
| 1649 | return get(KEY_FOCUS_MODE); |
| 1650 | } |
| 1651 | |
| 1652 | /** |
| 1653 | * Sets the focus mode. |
| 1654 | * |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 1655 | * @param value focus mode. |
| 1656 | * @see #getFocusMode() |
Wu-cheng Li | 36322db | 2009-09-18 18:59:21 +0800 | [diff] [blame] | 1657 | */ |
| 1658 | public void setFocusMode(String value) { |
| 1659 | set(KEY_FOCUS_MODE, value); |
| 1660 | } |
| 1661 | |
| 1662 | /** |
| 1663 | * Gets the supported focus modes. |
| 1664 | * |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 1665 | * @return a list of supported focus modes. This method will always |
| 1666 | * return a list with at least one element. |
| 1667 | * @see #getFocusMode() |
Wu-cheng Li | 36322db | 2009-09-18 18:59:21 +0800 | [diff] [blame] | 1668 | */ |
| 1669 | public List<String> getSupportedFocusModes() { |
| 1670 | String str = get(KEY_FOCUS_MODE + SUPPORTED_VALUES_SUFFIX); |
| 1671 | return split(str); |
| 1672 | } |
| 1673 | |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 1674 | /** |
Wu-cheng Li | 6c8d276 | 2010-01-27 22:55:14 +0800 | [diff] [blame] | 1675 | * Gets the focal length (in millimeter) of the camera. |
| 1676 | * |
| 1677 | * @return the focal length. This method will always return a valid |
| 1678 | * value. |
| 1679 | */ |
| 1680 | public float getFocalLength() { |
| 1681 | return Float.parseFloat(get(KEY_FOCAL_LENGTH)); |
| 1682 | } |
| 1683 | |
| 1684 | /** |
| 1685 | * Gets the horizontal angle of view in degrees. |
| 1686 | * |
| 1687 | * @return horizontal angle of view. This method will always return a |
| 1688 | * valid value. |
| 1689 | */ |
| 1690 | public float getHorizontalViewAngle() { |
| 1691 | return Float.parseFloat(get(KEY_HORIZONTAL_VIEW_ANGLE)); |
| 1692 | } |
| 1693 | |
| 1694 | /** |
| 1695 | * Gets the vertical angle of view in degrees. |
| 1696 | * |
| 1697 | * @return vertical angle of view. This method will always return a |
| 1698 | * valid value. |
| 1699 | */ |
| 1700 | public float getVerticalViewAngle() { |
| 1701 | return Float.parseFloat(get(KEY_VERTICAL_VIEW_ANGLE)); |
| 1702 | } |
| 1703 | |
| 1704 | /** |
Wu-cheng Li | 24b326a | 2010-02-20 17:47:04 +0800 | [diff] [blame] | 1705 | * Gets the current exposure compensation index. |
Wu-cheng Li | ff723b6 | 2010-02-09 13:38:19 +0800 | [diff] [blame] | 1706 | * |
Wu-cheng Li | 24b326a | 2010-02-20 17:47:04 +0800 | [diff] [blame] | 1707 | * @return current exposure compensation index. The range is {@link |
| 1708 | * #getMinExposureCompensation} to {@link |
| 1709 | * #getMaxExposureCompensation}. 0 means exposure is not |
| 1710 | * adjusted. |
Wu-cheng Li | ff723b6 | 2010-02-09 13:38:19 +0800 | [diff] [blame] | 1711 | */ |
| 1712 | public int getExposureCompensation() { |
Wu-cheng Li | 24b326a | 2010-02-20 17:47:04 +0800 | [diff] [blame] | 1713 | return getInt(KEY_EXPOSURE_COMPENSATION, 0); |
Wu-cheng Li | ff723b6 | 2010-02-09 13:38:19 +0800 | [diff] [blame] | 1714 | } |
| 1715 | |
| 1716 | /** |
Wu-cheng Li | 24b326a | 2010-02-20 17:47:04 +0800 | [diff] [blame] | 1717 | * Sets the exposure compensation index. |
Wu-cheng Li | ff723b6 | 2010-02-09 13:38:19 +0800 | [diff] [blame] | 1718 | * |
Wu-cheng Li | 0402e7d | 2010-02-26 15:04:55 +0800 | [diff] [blame] | 1719 | * @param value exposure compensation index. The valid value range is |
| 1720 | * from {@link #getMinExposureCompensation} (inclusive) to {@link |
Wu-cheng Li | 24b326a | 2010-02-20 17:47:04 +0800 | [diff] [blame] | 1721 | * #getMaxExposureCompensation} (inclusive). 0 means exposure is |
| 1722 | * not adjusted. Application should call |
| 1723 | * getMinExposureCompensation and getMaxExposureCompensation to |
| 1724 | * know if exposure compensation is supported. |
Wu-cheng Li | ff723b6 | 2010-02-09 13:38:19 +0800 | [diff] [blame] | 1725 | */ |
| 1726 | public void setExposureCompensation(int value) { |
| 1727 | set(KEY_EXPOSURE_COMPENSATION, value); |
| 1728 | } |
| 1729 | |
| 1730 | /** |
Wu-cheng Li | 24b326a | 2010-02-20 17:47:04 +0800 | [diff] [blame] | 1731 | * Gets the maximum exposure compensation index. |
Wu-cheng Li | ff723b6 | 2010-02-09 13:38:19 +0800 | [diff] [blame] | 1732 | * |
Wu-cheng Li | 24b326a | 2010-02-20 17:47:04 +0800 | [diff] [blame] | 1733 | * @return maximum exposure compensation index (>=0). If both this |
| 1734 | * method and {@link #getMinExposureCompensation} return 0, |
| 1735 | * exposure compensation is not supported. |
Wu-cheng Li | ff723b6 | 2010-02-09 13:38:19 +0800 | [diff] [blame] | 1736 | */ |
Wu-cheng Li | 24b326a | 2010-02-20 17:47:04 +0800 | [diff] [blame] | 1737 | public int getMaxExposureCompensation() { |
| 1738 | return getInt(KEY_MAX_EXPOSURE_COMPENSATION, 0); |
| 1739 | } |
| 1740 | |
| 1741 | /** |
| 1742 | * Gets the minimum exposure compensation index. |
| 1743 | * |
| 1744 | * @return minimum exposure compensation index (<=0). If both this |
| 1745 | * method and {@link #getMaxExposureCompensation} return 0, |
| 1746 | * exposure compensation is not supported. |
| 1747 | */ |
| 1748 | public int getMinExposureCompensation() { |
| 1749 | return getInt(KEY_MIN_EXPOSURE_COMPENSATION, 0); |
| 1750 | } |
| 1751 | |
| 1752 | /** |
| 1753 | * Gets the exposure compensation step. |
| 1754 | * |
| 1755 | * @return exposure compensation step. Applications can get EV by |
| 1756 | * multiplying the exposure compensation index and step. Ex: if |
| 1757 | * exposure compensation index is -6 and step is 0.333333333, EV |
| 1758 | * is -2. |
| 1759 | */ |
| 1760 | public float getExposureCompensationStep() { |
| 1761 | return getFloat(KEY_EXPOSURE_COMPENSATION_STEP, 0); |
Wu-cheng Li | ff723b6 | 2010-02-09 13:38:19 +0800 | [diff] [blame] | 1762 | } |
| 1763 | |
| 1764 | /** |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 1765 | * 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] | 1766 | * progress. Applications should check {@link #isZoomSupported} before |
| 1767 | * using this method. |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 1768 | * |
| 1769 | * @return the current zoom value. The range is 0 to {@link |
Wu-cheng Li | 8cbb8f5 | 2010-02-28 23:19:55 -0800 | [diff] [blame] | 1770 | * #getMaxZoom}. 0 means the camera is not zoomed. |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 1771 | */ |
| 1772 | public int getZoom() { |
Wu-cheng Li | 8cbb8f5 | 2010-02-28 23:19:55 -0800 | [diff] [blame] | 1773 | return getInt(KEY_ZOOM, 0); |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 1774 | } |
| 1775 | |
| 1776 | /** |
Wu-cheng Li | 8cbb8f5 | 2010-02-28 23:19:55 -0800 | [diff] [blame] | 1777 | * Sets current zoom value. If the camera is zoomed (value > 0), the |
| 1778 | * actual picture size may be smaller than picture size setting. |
| 1779 | * Applications can check the actual picture size after picture is |
| 1780 | * returned from {@link PictureCallback}. The preview size remains the |
| 1781 | * same in zoom. Applications should check {@link #isZoomSupported} |
| 1782 | * before using this method. |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 1783 | * |
| 1784 | * @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] | 1785 | */ |
| 1786 | public void setZoom(int value) { |
Wu-cheng Li | 8cbb8f5 | 2010-02-28 23:19:55 -0800 | [diff] [blame] | 1787 | set(KEY_ZOOM, value); |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 1788 | } |
| 1789 | |
| 1790 | /** |
| 1791 | * Returns true if zoom is supported. Applications should call this |
| 1792 | * before using other zoom methods. |
| 1793 | * |
| 1794 | * @return true if zoom is supported. |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 1795 | */ |
| 1796 | public boolean isZoomSupported() { |
Wu-cheng Li | 8cbb8f5 | 2010-02-28 23:19:55 -0800 | [diff] [blame] | 1797 | String str = get(KEY_ZOOM_SUPPORTED); |
| 1798 | return TRUE.equals(str); |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 1799 | } |
| 1800 | |
| 1801 | /** |
| 1802 | * Gets the maximum zoom value allowed for snapshot. This is the maximum |
| 1803 | * value that applications can set to {@link #setZoom(int)}. |
Wu-cheng Li | 8cbb8f5 | 2010-02-28 23:19:55 -0800 | [diff] [blame] | 1804 | * Applications should call {@link #isZoomSupported} before using this |
| 1805 | * method. This value may change in different preview size. Applications |
| 1806 | * should call this again after setting preview size. |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 1807 | * |
| 1808 | * @return the maximum zoom value supported by the camera. |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 1809 | */ |
| 1810 | public int getMaxZoom() { |
Wu-cheng Li | 8cbb8f5 | 2010-02-28 23:19:55 -0800 | [diff] [blame] | 1811 | return getInt(KEY_MAX_ZOOM, 0); |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 1812 | } |
| 1813 | |
| 1814 | /** |
Wu-cheng Li | 8cbb8f5 | 2010-02-28 23:19:55 -0800 | [diff] [blame] | 1815 | * Gets the zoom ratios of all zoom values. Applications should check |
| 1816 | * {@link #isZoomSupported} before using this method. |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 1817 | * |
Wu-cheng Li | 8cbb8f5 | 2010-02-28 23:19:55 -0800 | [diff] [blame] | 1818 | * @return the zoom ratios in 1/100 increments. Ex: a zoom of 3.2x is |
| 1819 | * returned as 320. The number of elements is {@link |
| 1820 | * #getMaxZoom} + 1. The list is sorted from small to large. The |
| 1821 | * first element is always 100. The last element is the zoom |
| 1822 | * ratio of the maximum zoom value. |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 1823 | */ |
Wu-cheng Li | 8cbb8f5 | 2010-02-28 23:19:55 -0800 | [diff] [blame] | 1824 | public List<Integer> getZoomRatios() { |
| 1825 | return splitInt(get(KEY_ZOOM_RATIOS)); |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 1826 | } |
| 1827 | |
| 1828 | /** |
| 1829 | * Returns true if smooth zoom is supported. Applications should call |
| 1830 | * this before using other smooth zoom methods. |
| 1831 | * |
| 1832 | * @return true if smooth zoom is supported. |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 1833 | */ |
| 1834 | public boolean isSmoothZoomSupported() { |
Wu-cheng Li | 8cbb8f5 | 2010-02-28 23:19:55 -0800 | [diff] [blame] | 1835 | String str = get(KEY_SMOOTH_ZOOM_SUPPORTED); |
| 1836 | return TRUE.equals(str); |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 1837 | } |
| 1838 | |
Wu-cheng Li | e339c5e | 2010-05-13 19:31:02 +0800 | [diff] [blame^] | 1839 | /** |
| 1840 | * Gets the distances from the camera to where an object appears to be |
| 1841 | * in focus. The object is sharpest at the optimal focus distance. The |
| 1842 | * depth of field is the far focus distance minus near focus distance. |
| 1843 | * |
| 1844 | * Focus distances may change after calling {@link |
| 1845 | * #autoFocus(AutoFocusCallback)}, {@link #cancelAutoFocus}, or {@link |
| 1846 | * #startPreview()}. Applications can call {@link #getParameters()} |
| 1847 | * and this method anytime to get the latest focus distances. If the |
| 1848 | * focus mode is FOCUS_MODE_EDOF, the values may be all 0, which means |
| 1849 | * focus distance is not applicable. If the focus mode is |
| 1850 | * FOCUS_MODE_CONTINUOUS and autofocus has started, focus distances may |
| 1851 | * change from time to time. |
| 1852 | * |
| 1853 | * Far focus distance > optimal focus distance > near focus distance. If |
| 1854 | * the far focus distance is infinity, the value will be |
| 1855 | * Float.POSITIVE_INFINITY. |
| 1856 | * |
| 1857 | * @param output focus distances in meters. output must be a float |
| 1858 | * array with three elements. Near focus distance, optimal focus |
| 1859 | * distance, and far focus distance will be filled in the array. |
| 1860 | * @see #NEAR_FOCUS_DISTANCE_INDEX |
| 1861 | * @see #OPTIMAL_FOCUS_DISTANCE_INDEX |
| 1862 | * @see #FAR_FOCUS_DISTANCE_INDEX |
| 1863 | */ |
| 1864 | public void getFocusDistances(float[] output) { |
| 1865 | if (output == null || output.length != 3) { |
| 1866 | throw new IllegalArgumentException( |
| 1867 | "output must be an float array with three elements."); |
| 1868 | } |
| 1869 | List<Float> distances = splitFloat(get(KEY_FOCUS_DISTANCES)); |
| 1870 | output[0] = distances.get(0); |
| 1871 | output[1] = distances.get(1); |
| 1872 | output[2] = distances.get(2); |
| 1873 | } |
| 1874 | |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1875 | // Splits a comma delimited string to an ArrayList of String. |
| 1876 | // Return null if the passing string is null or the size is 0. |
| 1877 | private ArrayList<String> split(String str) { |
| 1878 | if (str == null) return null; |
| 1879 | |
| 1880 | // Use StringTokenizer because it is faster than split. |
| 1881 | StringTokenizer tokenizer = new StringTokenizer(str, ","); |
| 1882 | ArrayList<String> substrings = new ArrayList<String>(); |
| 1883 | while (tokenizer.hasMoreElements()) { |
| 1884 | substrings.add(tokenizer.nextToken()); |
| 1885 | } |
| 1886 | return substrings; |
| 1887 | } |
| 1888 | |
| 1889 | // Splits a comma delimited string to an ArrayList of Integer. |
| 1890 | // Return null if the passing string is null or the size is 0. |
| 1891 | private ArrayList<Integer> splitInt(String str) { |
| 1892 | if (str == null) return null; |
| 1893 | |
| 1894 | StringTokenizer tokenizer = new StringTokenizer(str, ","); |
| 1895 | ArrayList<Integer> substrings = new ArrayList<Integer>(); |
| 1896 | while (tokenizer.hasMoreElements()) { |
| 1897 | String token = tokenizer.nextToken(); |
| 1898 | substrings.add(Integer.parseInt(token)); |
| 1899 | } |
| 1900 | if (substrings.size() == 0) return null; |
| 1901 | return substrings; |
| 1902 | } |
| 1903 | |
Wu-cheng Li | e339c5e | 2010-05-13 19:31:02 +0800 | [diff] [blame^] | 1904 | // Splits a comma delimited string to an ArrayList of Float. |
| 1905 | // Return null if the passing string is null or the size is 0. |
| 1906 | private ArrayList<Float> splitFloat(String str) { |
| 1907 | if (str == null) return null; |
| 1908 | |
| 1909 | StringTokenizer tokenizer = new StringTokenizer(str, ","); |
| 1910 | ArrayList<Float> substrings = new ArrayList<Float>(); |
| 1911 | while (tokenizer.hasMoreElements()) { |
| 1912 | String token = tokenizer.nextToken(); |
| 1913 | substrings.add(Float.parseFloat(token)); |
| 1914 | } |
| 1915 | if (substrings.size() == 0) return null; |
| 1916 | return substrings; |
| 1917 | } |
| 1918 | |
Wu-cheng Li | 24b326a | 2010-02-20 17:47:04 +0800 | [diff] [blame] | 1919 | // Returns the value of a float parameter. |
| 1920 | private float getFloat(String key, float defaultValue) { |
| 1921 | try { |
| 1922 | return Float.parseFloat(mMap.get(key)); |
| 1923 | } catch (NumberFormatException ex) { |
| 1924 | return defaultValue; |
| 1925 | } |
| 1926 | } |
| 1927 | |
| 1928 | // Returns the value of a integer parameter. |
| 1929 | private int getInt(String key, int defaultValue) { |
| 1930 | try { |
| 1931 | return Integer.parseInt(mMap.get(key)); |
| 1932 | } catch (NumberFormatException ex) { |
| 1933 | return defaultValue; |
| 1934 | } |
| 1935 | } |
| 1936 | |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1937 | // Splits a comma delimited string to an ArrayList of Size. |
| 1938 | // Return null if the passing string is null or the size is 0. |
| 1939 | private ArrayList<Size> splitSize(String str) { |
| 1940 | if (str == null) return null; |
| 1941 | |
| 1942 | StringTokenizer tokenizer = new StringTokenizer(str, ","); |
| 1943 | ArrayList<Size> sizeList = new ArrayList<Size>(); |
| 1944 | while (tokenizer.hasMoreElements()) { |
| 1945 | Size size = strToSize(tokenizer.nextToken()); |
| 1946 | if (size != null) sizeList.add(size); |
| 1947 | } |
| 1948 | if (sizeList.size() == 0) return null; |
| 1949 | return sizeList; |
| 1950 | } |
| 1951 | |
| 1952 | // Parses a string (ex: "480x320") to Size object. |
| 1953 | // Return null if the passing string is null. |
| 1954 | private Size strToSize(String str) { |
| 1955 | if (str == null) return null; |
| 1956 | |
| 1957 | int pos = str.indexOf('x'); |
| 1958 | if (pos != -1) { |
| 1959 | String width = str.substring(0, pos); |
| 1960 | String height = str.substring(pos + 1); |
| 1961 | return new Size(Integer.parseInt(width), |
| 1962 | Integer.parseInt(height)); |
| 1963 | } |
| 1964 | Log.e(TAG, "Invalid size parameter string=" + str); |
| 1965 | return null; |
| 1966 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1967 | }; |
| 1968 | } |