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