blob: 47c2cac2952becd0fb74f57a7e5157f6e200427f [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
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
17package android.hardware;
18
19import java.lang.ref.WeakReference;
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +080020import java.util.ArrayList;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080021import java.util.HashMap;
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +080022import java.util.List;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080023import java.util.StringTokenizer;
24import java.io.IOException;
25
26import android.util.Log;
27import android.view.Surface;
28import android.view.SurfaceHolder;
29import android.graphics.PixelFormat;
30import android.os.Handler;
31import android.os.Looper;
32import 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 Maindf4578e2009-09-10 12:22:07 -070040 *
Wu-cheng Li7478ea62009-09-16 18:52:55 +080041 * <p>In order to use the device camera, you must declare the
42 * {@link android.Manifest.permission#CAMERA} permission in your Android
Scott Maindf4578e2009-09-10 12:22:07 -070043 * Manifest. Also be sure to include the
44 * <a href="{@docRoot}guide/topics/manifest/uses-feature-element.html">&lt;uses-feature></a>
Wu-cheng Li7478ea62009-09-16 18:52:55 +080045 * 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 Maindf4578e2009-09-10 12:22:07 -070047 * should include the following:</p>
48 * <pre> &lt;uses-permission android:name="android.permission.CAMERA" />
49 * &lt;uses-feature android:name="android.hardware.camera" />
50 * &lt;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 Li7478ea62009-09-16 18:52:55 +080055 * more devices, you should not make assumptions about the device camera
Scott Maindf4578e2009-09-10 12:22:07 -070056 * specifications.</p>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080057 */
58public class Camera {
59 private static final String TAG = "Camera";
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +080060
Dave Sparksc62f9bd2009-06-26 13:33:32 -070061 // These match the enums in frameworks/base/include/ui/Camera.h
Benny Wongda83f462009-08-12 12:01:27 -050062 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 Project9066cfe2009-03-03 19:31:44 -080072
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 Sparkse8b26e12009-07-14 10:35:40 -070079 private PictureCallback mPostviewCallback;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080080 private AutoFocusCallback mAutoFocusCallback;
Dave Sparkse8b26e12009-07-14 10:35:40 -070081 private ZoomCallback mZoomCallback;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080082 private ErrorCallback mErrorCallback;
83 private boolean mOneShot;
Andrew Harp94927df2009-10-20 01:47:05 -040084 private boolean mWithBuffer;
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +080085
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080086 /**
87 * Returns a new Camera object.
88 */
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +080089 public static Camera open() {
90 return new Camera();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080091 }
92
93 Camera() {
94 mShutterCallback = null;
95 mRawImageCallback = null;
96 mJpegCallback = null;
97 mPreviewCallback = null;
Dave Sparkse8b26e12009-07-14 10:35:40 -070098 mPostviewCallback = null;
99 mZoomCallback = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800100
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 Li9b6a8ab2009-08-17 18:19:25 +0800112
113 protected void finalize() {
114 native_release();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800115 }
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800116
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800117 private native final void native_setup(Object camera_this);
118 private native final void native_release();
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800119
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800120
121 /**
122 * Disconnects and releases the Camera object resources.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800123 * <p>It is recommended that you call this as soon as you're done with the
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800124 * Camera object.</p>
125 */
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800126 public final void release() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800127 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 Li9b6a8ab2009-08-17 18:19:25 +0800133 * object to a MediaRecorder to use for video recording. Once the
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800134 * 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 Li9b6a8ab2009-08-17 18:19:25 +0800137 * can be connected to another process.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800138 *
139 * @throws IOException if the method fails.
140 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800141 * @hide
142 */
143 public native final void reconnect() throws IOException;
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800144
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800145 /**
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 Project9066cfe2009-03-03 19:31:44 -0800153 *
Wu-cheng Liffe1cf22009-09-10 16:49:17 +0800154 * @throws RuntimeException if the method fails.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800155 */
Wu-cheng Liffe1cf22009-09-10 16:49:17 +0800156 public native final void lock();
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800157
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800158 /**
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800159 * Unlock the camera to allow another process to access it. To save
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800160 * 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 Project9066cfe2009-03-03 19:31:44 -0800163 *
Wu-cheng Liffe1cf22009-09-10 16:49:17 +0800164 * @throws RuntimeException if the method fails.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800165 */
Wu-cheng Liffe1cf22009-09-10 16:49:17 +0800166 public native final void unlock();
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800167
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800168 /**
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 Li9b6a8ab2009-08-17 18:19:25 +0800172 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800173 * @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 Lib8a10fe2009-06-23 23:37:36 +0800177 if (holder != null) {
178 setPreviewDisplay(holder.getSurface());
179 } else {
180 setPreviewDisplay((Surface)null);
181 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800182 }
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 Maindf4578e2009-09-10 12:22:07 -0700194 * @param data The contents of the preview frame in the format defined
Wu-cheng Li7478ea62009-09-16 18:52:55 +0800195 * by {@link android.graphics.PixelFormat}, which can be queried
Scott Maindf4578e2009-09-10 12:22:07 -0700196 * with {@link android.hardware.Camera.Parameters#getPreviewFormat()}.
Scott Mainda0a56d2009-09-10 18:08:37 -0700197 * If {@link android.hardware.Camera.Parameters#setPreviewFormat(int)}
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800198 * is never called, the default will be the YCbCr_420_SP
199 * (NV21) format.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800200 * @param camera The Camera service object.
201 */
202 void onPreviewFrame(byte[] data, Camera camera);
203 };
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800204
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800205 /**
206 * Start drawing preview frames to the surface.
207 */
208 public native final void startPreview();
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800209
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800210 /**
211 * Stop drawing preview frames to the surface.
212 */
213 public native final void stopPreview();
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800214
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800215 /**
216 * Return current preview state.
217 *
218 * FIXME: Unhide before release
219 * @hide
220 */
221 public native final boolean previewEnabled();
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800222
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800223 /**
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 Harp94927df2009-10-20 01:47:05 -0400233 mWithBuffer = false;
Dave Sparksa6118c62009-10-13 02:28:54 -0700234 // Always use one-shot mode. We fake camera preview mode by
235 // doing one-shot preview continuously.
Andrew Harp94927df2009-10-20 01:47:05 -0400236 setHasPreviewCallback(cb != null, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800237 }
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 Harp94927df2009-10-20 01:47:05 -0400246 mPreviewCallback = cb;
247 mOneShot = true;
248 mWithBuffer = false;
249 setHasPreviewCallback(cb != null, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800250 }
251
Andrew Harp94927df2009-10-20 01:47:05 -0400252 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
279 * {@link android.graphics.PixelFormat#getPixelFormatInfo(int, PixelFormat)}
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 Project9066cfe2009-03-03 19:31:44 -0800288
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 Sparksc62f9bd2009-06-26 13:33:32 -0700301 case CAMERA_MSG_SHUTTER:
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800302 if (mShutterCallback != null) {
303 mShutterCallback.onShutter();
304 }
305 return;
Dave Sparksc62f9bd2009-06-26 13:33:32 -0700306
307 case CAMERA_MSG_RAW_IMAGE:
Dave Sparkse8b26e12009-07-14 10:35:40 -0700308 if (mRawImageCallback != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800309 mRawImageCallback.onPictureTaken((byte[])msg.obj, mCamera);
Dave Sparkse8b26e12009-07-14 10:35:40 -0700310 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800311 return;
312
Dave Sparksc62f9bd2009-06-26 13:33:32 -0700313 case CAMERA_MSG_COMPRESSED_IMAGE:
Dave Sparkse8b26e12009-07-14 10:35:40 -0700314 if (mJpegCallback != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800315 mJpegCallback.onPictureTaken((byte[])msg.obj, mCamera);
Dave Sparkse8b26e12009-07-14 10:35:40 -0700316 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800317 return;
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800318
Dave Sparksc62f9bd2009-06-26 13:33:32 -0700319 case CAMERA_MSG_PREVIEW_FRAME:
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800320 if (mPreviewCallback != null) {
Dave Sparksa6118c62009-10-13 02:28:54 -0700321 PreviewCallback cb = mPreviewCallback;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800322 if (mOneShot) {
Dave Sparksa6118c62009-10-13 02:28:54 -0700323 // Clear the callback variable before the callback
324 // in case the app calls setPreviewCallback from
325 // the callback function
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800326 mPreviewCallback = null;
Andrew Harp94927df2009-10-20 01:47:05 -0400327 } else if (!mWithBuffer) {
Dave Sparksa6118c62009-10-13 02:28:54 -0700328 // 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 Harp94927df2009-10-20 01:47:05 -0400331 setHasPreviewCallback(true, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800332 }
Dave Sparksa6118c62009-10-13 02:28:54 -0700333 cb.onPreviewFrame((byte[])msg.obj, mCamera);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800334 }
335 return;
336
Dave Sparkse8b26e12009-07-14 10:35:40 -0700337 case CAMERA_MSG_POSTVIEW_FRAME:
338 if (mPostviewCallback != null) {
339 mPostviewCallback.onPictureTaken((byte[])msg.obj, mCamera);
340 }
341 return;
342
Dave Sparksc62f9bd2009-06-26 13:33:32 -0700343 case CAMERA_MSG_FOCUS:
Dave Sparkse8b26e12009-07-14 10:35:40 -0700344 if (mAutoFocusCallback != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800345 mAutoFocusCallback.onAutoFocus(msg.arg1 == 0 ? false : true, mCamera);
Dave Sparkse8b26e12009-07-14 10:35:40 -0700346 }
347 return;
348
349 case CAMERA_MSG_ZOOM:
350 if (mZoomCallback != null) {
Wu-cheng Li36f68b82009-09-28 16:14:58 -0700351 mZoomCallback.onZoomUpdate(msg.arg1, msg.arg2 != 0, mCamera);
Dave Sparkse8b26e12009-07-14 10:35:40 -0700352 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800353 return;
354
Dave Sparksc62f9bd2009-06-26 13:33:32 -0700355 case CAMERA_MSG_ERROR :
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800356 Log.e(TAG, "Error " + msg.arg1);
Dave Sparkse8b26e12009-07-14 10:35:40 -0700357 if (mErrorCallback != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800358 mErrorCallback.onError(msg.arg1, mCamera);
Dave Sparkse8b26e12009-07-14 10:35:40 -0700359 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800360 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 Li7478ea62009-09-16 18:52:55 +0800384 * <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 Maindf4578e2009-09-10 12:22:07 -0700386 * should not be installed on devices <em>without</em> auto-focus, you must
387 * declare that your app uses the
Wu-cheng Li7478ea62009-09-16 18:52:55 +0800388 * {@code android.hardware.camera.autofocus} feature, in the
Scott Maindf4578e2009-09-10 12:22:07 -0700389 * <a href="{@docRoot}guide/topics/manifest/uses-feature-element.html">&lt;uses-feature></a>
390 * manifest element.</p>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800391 */
392 public interface AutoFocusCallback
393 {
394 /**
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800395 * 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 Project9066cfe2009-03-03 19:31:44 -0800399 * @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 Li9b6a8ab2009-08-17 18:19:25 +0800406 * Starts auto-focus function and registers a callback function to run when
Wu-cheng Li36322db2009-09-18 18:59:21 +0800407 * 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 Mainda0a56d2009-09-10 18:08:37 -0700413 * <p>If your application should not be installed
Wu-cheng Li7478ea62009-09-16 18:52:55 +0800414 * on devices without auto-focus, you must declare that your application
415 * uses auto-focus with the
Scott Maindf4578e2009-09-10 12:22:07 -0700416 * <a href="{@docRoot}guide/topics/manifest/uses-feature-element.html">&lt;uses-feature></a>
417 * manifest element.</p>
Wu-cheng Li068ef422009-09-27 13:19:36 -0700418 * <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 Li7478ea62009-09-16 18:52:55 +0800421 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800422 * @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 Chang244f8c22009-09-15 14:51:56 +0800432 * 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 Chang244f8c22009-09-15 14:51:56 +0800436 */
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 Project9066cfe2009-03-03 19:31:44 -0800445 * 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 Li9b6a8ab2009-08-17 18:19:25 +0800462 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800463 * @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 Li9b6a8ab2009-08-17 18:19:25 +0800470 * 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 Li40057ce2009-12-02 18:57:29 +0800480 * 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 Project9066cfe2009-03-03 19:31:44 -0800484 * @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 Sparkse8b26e12009-07-14 10:35:40 -0700490 takePicture(shutter, raw, null, jpeg);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800491 }
492 private native final void native_takePicture();
493
Dave Sparkse8b26e12009-07-14 10:35:40 -0700494 /**
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800495 * 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 Sparkse8b26e12009-07-14 10:35:40 -0700506 *
Wu-cheng Li40057ce2009-12-02 18:57:29 +0800507 * 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 Sparkse8b26e12009-07-14 10:35:40 -0700511 * @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 Li36f68b82009-09-28 16:14:58 -0700526 * Zooms to the requested value smoothly. Driver will generate {@link
527 * #ZoomCallback} for the current zoom value and whether zoom is stopped.
528 * The applications can call {@link #stopSmoothZoom} to stop the zoom
529 * earlier. The applications should not call startSmoothZoom again or {@link
530 * android.hardware.Camera.Parameters#setZoom(int)} before the zoom stops.
531 *
532 * @param value zoom value. The valid range is 0 to {@link
533 * android.hardware.Camera.Parameters#getMaxZoom}.
534 * @hide
535 */
536 public native final void startSmoothZoom(int value);
537
538 /**
539 * Stops the smooth zoom. The applications should wait for the {@link
540 * #ZoomCallback} to know when the zoom is actually stopped.
541 * @hide
542 */
543 public native final void stopSmoothZoom();
544
545 /**
Chih-Chung Changd1d77062010-01-22 17:49:48 -0800546 * Set the display orientation. This affects the preview frames and the
547 * picture displayed after snapshot. This method is useful for portrait
548 * mode applications.
549 *
550 * This does not affect the order of byte array passed in
551 * {@link PreviewCallback#onPreviewFrame}. This method is not allowed to
552 * be called during preview.
553 *
554 * @param degrees the angle that the picture will be rotated clockwise.
Chih-Chung Change7bd22a2010-01-27 10:24:42 -0800555 * Valid values are 0, 90, 180, and 270. The starting
556 * position is 0 (landscape).
Chih-Chung Changd1d77062010-01-22 17:49:48 -0800557 */
558 public native final void setDisplayOrientation(int degrees);
559
560 /**
Dave Sparkse8b26e12009-07-14 10:35:40 -0700561 * Handles the zoom callback.
Wu-cheng Li77153ee2009-09-29 16:04:21 -0700562 *
563 * @hide
Dave Sparkse8b26e12009-07-14 10:35:40 -0700564 */
565 public interface ZoomCallback
566 {
567 /**
568 * Callback for zoom updates
Wu-cheng Li36f68b82009-09-28 16:14:58 -0700569 *
570 * @param zoomValue the current zoom value. In smooth zoom mode, camera
571 * generates this callback for every new zoom value.
572 * @param stopped whether smooth zoom is stopped. If the value is true,
573 * this is the last zoom update for the application.
574 *
Dave Sparkse8b26e12009-07-14 10:35:40 -0700575 * @param camera the Camera service object
Wu-cheng Li36f68b82009-09-28 16:14:58 -0700576 * @see android.hardware.Camera.Parameters#startSmoothZoom
Dave Sparkse8b26e12009-07-14 10:35:40 -0700577 */
Wu-cheng Li36f68b82009-09-28 16:14:58 -0700578 void onZoomUpdate(int zoomValue, boolean stopped, Camera camera);
Dave Sparkse8b26e12009-07-14 10:35:40 -0700579 };
580
581 /**
Wu-cheng Li36f68b82009-09-28 16:14:58 -0700582 * Registers a callback to be invoked when the zoom value is updated by the
583 * camera driver during smooth zoom.
Dave Sparkse8b26e12009-07-14 10:35:40 -0700584 * @param cb the callback to run
Wu-cheng Li77153ee2009-09-29 16:04:21 -0700585 * @hide
Dave Sparkse8b26e12009-07-14 10:35:40 -0700586 */
587 public final void setZoomCallback(ZoomCallback cb)
588 {
589 mZoomCallback = cb;
590 }
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800591
James Donga1b653d2009-07-02 10:04:20 -0700592 // These match the enum in include/ui/Camera.h
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800593 /** Unspecified camerar error. @see #ErrorCallback */
594 public static final int CAMERA_ERROR_UNKNOWN = 1;
595 /** Media server died. In this case, the application must release the
596 * Camera object and instantiate a new one. @see #ErrorCallback */
597 public static final int CAMERA_ERROR_SERVER_DIED = 100;
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800598
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800599 /**
600 * Handles the camera error callback.
601 */
602 public interface ErrorCallback
603 {
604 /**
605 * Callback for camera errors.
606 * @param error error code:
607 * <ul>
608 * <li>{@link #CAMERA_ERROR_UNKNOWN}
609 * <li>{@link #CAMERA_ERROR_SERVER_DIED}
610 * </ul>
611 * @param camera the Camera service object
612 */
613 void onError(int error, Camera camera);
614 };
615
616 /**
617 * Registers a callback to be invoked when an error occurs.
618 * @param cb the callback to run
619 */
620 public final void setErrorCallback(ErrorCallback cb)
621 {
622 mErrorCallback = cb;
623 }
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800624
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800625 private native final void native_setParameters(String params);
626 private native final String native_getParameters();
627
628 /**
629 * Sets the Parameters for pictures from this Camera service.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800630 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800631 * @param params the Parameters to use for this Camera service
632 */
633 public void setParameters(Parameters params) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800634 native_setParameters(params.flatten());
635 }
636
637 /**
638 * Returns the picture Parameters for this Camera service.
639 */
640 public Parameters getParameters() {
641 Parameters p = new Parameters();
642 String s = native_getParameters();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800643 p.unflatten(s);
644 return p;
645 }
646
647 /**
648 * Handles the picture size (dimensions).
649 */
650 public class Size {
651 /**
652 * Sets the dimensions for pictures.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800653 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800654 * @param w the photo width (pixels)
655 * @param h the photo height (pixels)
656 */
657 public Size(int w, int h) {
658 width = w;
659 height = h;
660 }
Wu-cheng Li4c4300c2010-01-23 15:45:39 +0800661 /**
662 * Compares {@code obj} to this size.
663 *
664 * @param obj the object to compare this size with.
665 * @return {@code true} if the width and height of {@code obj} is the
666 * same as those of this size. {@code false} otherwise.
667 */
668 @Override
669 public boolean equals(Object obj) {
670 if (!(obj instanceof Size)) {
671 return false;
672 }
673 Size s = (Size) obj;
674 return width == s.width && height == s.height;
675 }
676 @Override
677 public int hashCode() {
678 return width * 32713 + height;
679 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800680 /** width of the picture */
681 public int width;
682 /** height of the picture */
683 public int height;
684 };
685
686 /**
687 * Handles the parameters for pictures created by a Camera service.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800688 *
689 * <p>To make camera parameters take effect, applications have to call
690 * Camera.setParameters. For example, after setWhiteBalance is called, white
691 * balance is not changed until Camera.setParameters() is called.
692 *
693 * <p>Different devices may have different camera capabilities, such as
694 * picture size or flash modes. The application should query the camera
695 * capabilities before setting parameters. For example, the application
696 * should call getSupportedColorEffects before calling setEffect. If the
697 * camera does not support color effects, getSupportedColorEffects will
698 * return null.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800699 */
700 public class Parameters {
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800701 // Parameter keys to communicate with the camera driver.
702 private static final String KEY_PREVIEW_SIZE = "preview-size";
703 private static final String KEY_PREVIEW_FORMAT = "preview-format";
704 private static final String KEY_PREVIEW_FRAME_RATE = "preview-frame-rate";
705 private static final String KEY_PICTURE_SIZE = "picture-size";
706 private static final String KEY_PICTURE_FORMAT = "picture-format";
Wu-cheng Li4c4300c2010-01-23 15:45:39 +0800707 private static final String KEY_JPEG_THUMBNAIL_SIZE = "jpeg-thumbnail-size";
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800708 private static final String KEY_JPEG_THUMBNAIL_WIDTH = "jpeg-thumbnail-width";
709 private static final String KEY_JPEG_THUMBNAIL_HEIGHT = "jpeg-thumbnail-height";
710 private static final String KEY_JPEG_THUMBNAIL_QUALITY = "jpeg-thumbnail-quality";
711 private static final String KEY_JPEG_QUALITY = "jpeg-quality";
712 private static final String KEY_ROTATION = "rotation";
713 private static final String KEY_GPS_LATITUDE = "gps-latitude";
714 private static final String KEY_GPS_LONGITUDE = "gps-longitude";
715 private static final String KEY_GPS_ALTITUDE = "gps-altitude";
716 private static final String KEY_GPS_TIMESTAMP = "gps-timestamp";
717 private static final String KEY_WHITE_BALANCE = "whitebalance";
718 private static final String KEY_EFFECT = "effect";
719 private static final String KEY_ANTIBANDING = "antibanding";
720 private static final String KEY_SCENE_MODE = "scene-mode";
721 private static final String KEY_FLASH_MODE = "flash-mode";
Wu-cheng Li36322db2009-09-18 18:59:21 +0800722 private static final String KEY_FOCUS_MODE = "focus-mode";
Wu-cheng Li6c8d2762010-01-27 22:55:14 +0800723 private static final String KEY_FOCAL_LENGTH = "focal-length";
724 private static final String KEY_HORIZONTAL_VIEW_ANGLE = "horizontal-view-angle";
725 private static final String KEY_VERTICAL_VIEW_ANGLE = "vertical-view-angle";
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800726 // Parameter key suffix for supported values.
727 private static final String SUPPORTED_VALUES_SUFFIX = "-values";
728
729 // Values for white balance settings.
730 public static final String WHITE_BALANCE_AUTO = "auto";
731 public static final String WHITE_BALANCE_INCANDESCENT = "incandescent";
732 public static final String WHITE_BALANCE_FLUORESCENT = "fluorescent";
733 public static final String WHITE_BALANCE_WARM_FLUORESCENT = "warm-fluorescent";
734 public static final String WHITE_BALANCE_DAYLIGHT = "daylight";
735 public static final String WHITE_BALANCE_CLOUDY_DAYLIGHT = "cloudy-daylight";
736 public static final String WHITE_BALANCE_TWILIGHT = "twilight";
737 public static final String WHITE_BALANCE_SHADE = "shade";
738
739 // Values for color effect settings.
740 public static final String EFFECT_NONE = "none";
741 public static final String EFFECT_MONO = "mono";
742 public static final String EFFECT_NEGATIVE = "negative";
743 public static final String EFFECT_SOLARIZE = "solarize";
744 public static final String EFFECT_SEPIA = "sepia";
745 public static final String EFFECT_POSTERIZE = "posterize";
746 public static final String EFFECT_WHITEBOARD = "whiteboard";
747 public static final String EFFECT_BLACKBOARD = "blackboard";
748 public static final String EFFECT_AQUA = "aqua";
749
750 // Values for antibanding settings.
751 public static final String ANTIBANDING_AUTO = "auto";
752 public static final String ANTIBANDING_50HZ = "50hz";
753 public static final String ANTIBANDING_60HZ = "60hz";
754 public static final String ANTIBANDING_OFF = "off";
755
756 // Values for flash mode settings.
757 /**
758 * Flash will not be fired.
759 */
760 public static final String FLASH_MODE_OFF = "off";
Wu-cheng Li36f68b82009-09-28 16:14:58 -0700761
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800762 /**
Wu-cheng Li068ef422009-09-27 13:19:36 -0700763 * Flash will be fired automatically when required. The flash may be fired
764 * during preview, auto-focus, or snapshot depending on the driver.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800765 */
766 public static final String FLASH_MODE_AUTO = "auto";
Wu-cheng Li36f68b82009-09-28 16:14:58 -0700767
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800768 /**
Wu-cheng Li068ef422009-09-27 13:19:36 -0700769 * Flash will always be fired during snapshot. The flash may also be
770 * fired during preview or auto-focus depending on the driver.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800771 */
772 public static final String FLASH_MODE_ON = "on";
Wu-cheng Li36f68b82009-09-28 16:14:58 -0700773
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800774 /**
775 * Flash will be fired in red-eye reduction mode.
776 */
777 public static final String FLASH_MODE_RED_EYE = "red-eye";
Wu-cheng Li36f68b82009-09-28 16:14:58 -0700778
Wu-cheng Li36322db2009-09-18 18:59:21 +0800779 /**
Wu-cheng Li068ef422009-09-27 13:19:36 -0700780 * Constant emission of light during preview, auto-focus and snapshot.
781 * This can also be used for video recording.
Wu-cheng Li36322db2009-09-18 18:59:21 +0800782 */
Wu-cheng Li068ef422009-09-27 13:19:36 -0700783 public static final String FLASH_MODE_TORCH = "torch";
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800784
785 // Values for scene mode settings.
786 public static final String SCENE_MODE_AUTO = "auto";
787 public static final String SCENE_MODE_ACTION = "action";
788 public static final String SCENE_MODE_PORTRAIT = "portrait";
789 public static final String SCENE_MODE_LANDSCAPE = "landscape";
790 public static final String SCENE_MODE_NIGHT = "night";
791 public static final String SCENE_MODE_NIGHT_PORTRAIT = "night-portrait";
792 public static final String SCENE_MODE_THEATRE = "theatre";
793 public static final String SCENE_MODE_BEACH = "beach";
794 public static final String SCENE_MODE_SNOW = "snow";
795 public static final String SCENE_MODE_SUNSET = "sunset";
796 public static final String SCENE_MODE_STEADYPHOTO = "steadyphoto";
797 public static final String SCENE_MODE_FIREWORKS = "fireworks";
798 public static final String SCENE_MODE_SPORTS = "sports";
799 public static final String SCENE_MODE_PARTY = "party";
800 public static final String SCENE_MODE_CANDLELIGHT = "candlelight";
801
Wu-cheng Li36322db2009-09-18 18:59:21 +0800802 // Values for focus mode settings.
803 /**
804 * Auto-focus mode.
805 */
806 public static final String FOCUS_MODE_AUTO = "auto";
Wu-cheng Li36f68b82009-09-28 16:14:58 -0700807
Wu-cheng Li36322db2009-09-18 18:59:21 +0800808 /**
809 * Focus is set at infinity. Applications should not call
810 * {@link #autoFocus(AutoFocusCallback)} in this mode.
811 */
812 public static final String FOCUS_MODE_INFINITY = "infinity";
813 public static final String FOCUS_MODE_MACRO = "macro";
Wu-cheng Li36f68b82009-09-28 16:14:58 -0700814
Wu-cheng Li36322db2009-09-18 18:59:21 +0800815 /**
816 * Focus is fixed. The camera is always in this mode if the focus is not
817 * adjustable. If the camera has auto-focus, this mode can fix the
818 * focus, which is usually at hyperfocal distance. Applications should
819 * not call {@link #autoFocus(AutoFocusCallback)} in this mode.
820 */
821 public static final String FOCUS_MODE_FIXED = "fixed";
822
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800823 // Formats for setPreviewFormat and setPictureFormat.
824 private static final String PIXEL_FORMAT_YUV422SP = "yuv422sp";
825 private static final String PIXEL_FORMAT_YUV420SP = "yuv420sp";
Chih-Chung Changeb68c462009-09-18 18:37:44 +0800826 private static final String PIXEL_FORMAT_YUV422I = "yuv422i-yuyv";
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800827 private static final String PIXEL_FORMAT_RGB565 = "rgb565";
828 private static final String PIXEL_FORMAT_JPEG = "jpeg";
829
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800830 private HashMap<String, String> mMap;
831
832 private Parameters() {
833 mMap = new HashMap<String, String>();
834 }
835
836 /**
837 * Writes the current Parameters to the log.
838 * @hide
839 * @deprecated
840 */
841 public void dump() {
842 Log.e(TAG, "dump: size=" + mMap.size());
843 for (String k : mMap.keySet()) {
844 Log.e(TAG, "dump: " + k + "=" + mMap.get(k));
845 }
846 }
847
848 /**
849 * Creates a single string with all the parameters set in
850 * this Parameters object.
851 * <p>The {@link #unflatten(String)} method does the reverse.</p>
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800852 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800853 * @return a String with all values from this Parameters object, in
854 * semi-colon delimited key-value pairs
855 */
856 public String flatten() {
857 StringBuilder flattened = new StringBuilder();
858 for (String k : mMap.keySet()) {
859 flattened.append(k);
860 flattened.append("=");
861 flattened.append(mMap.get(k));
862 flattened.append(";");
863 }
864 // chop off the extra semicolon at the end
865 flattened.deleteCharAt(flattened.length()-1);
866 return flattened.toString();
867 }
868
869 /**
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800870 * Takes a flattened string of parameters and adds each one to
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800871 * this Parameters object.
872 * <p>The {@link #flatten()} method does the reverse.</p>
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800873 *
874 * @param flattened a String of parameters (key-value paired) that
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800875 * are semi-colon delimited
876 */
877 public void unflatten(String flattened) {
878 mMap.clear();
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800879
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800880 StringTokenizer tokenizer = new StringTokenizer(flattened, ";");
881 while (tokenizer.hasMoreElements()) {
882 String kv = tokenizer.nextToken();
883 int pos = kv.indexOf('=');
884 if (pos == -1) {
885 continue;
886 }
887 String k = kv.substring(0, pos);
888 String v = kv.substring(pos + 1);
889 mMap.put(k, v);
890 }
891 }
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800892
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800893 public void remove(String key) {
894 mMap.remove(key);
895 }
896
897 /**
898 * Sets a String parameter.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800899 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800900 * @param key the key name for the parameter
901 * @param value the String value of the parameter
902 */
903 public void set(String key, String value) {
904 if (key.indexOf('=') != -1 || key.indexOf(';') != -1) {
905 Log.e(TAG, "Key \"" + key + "\" contains invalid character (= or ;)");
906 return;
907 }
908 if (value.indexOf('=') != -1 || value.indexOf(';') != -1) {
909 Log.e(TAG, "Value \"" + value + "\" contains invalid character (= or ;)");
910 return;
911 }
912
913 mMap.put(key, value);
914 }
915
916 /**
917 * Sets an integer parameter.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800918 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800919 * @param key the key name for the parameter
920 * @param value the int value of the parameter
921 */
922 public void set(String key, int value) {
923 mMap.put(key, Integer.toString(value));
924 }
925
926 /**
927 * Returns the value of a String parameter.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800928 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800929 * @param key the key name for the parameter
930 * @return the String value of the parameter
931 */
932 public String get(String key) {
933 return mMap.get(key);
934 }
935
936 /**
937 * Returns the value of an integer parameter.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800938 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800939 * @param key the key name for the parameter
940 * @return the int value of the parameter
941 */
942 public int getInt(String key) {
943 return Integer.parseInt(mMap.get(key));
944 }
945
946 /**
947 * Sets the dimensions for preview pictures.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800948 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800949 * @param width the width of the pictures, in pixels
950 * @param height the height of the pictures, in pixels
951 */
952 public void setPreviewSize(int width, int height) {
953 String v = Integer.toString(width) + "x" + Integer.toString(height);
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800954 set(KEY_PREVIEW_SIZE, v);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800955 }
956
957 /**
958 * Returns the dimensions setting for preview pictures.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800959 *
960 * @return a Size object with the height and width setting
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800961 * for the preview picture
962 */
963 public Size getPreviewSize() {
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800964 String pair = get(KEY_PREVIEW_SIZE);
965 return strToSize(pair);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800966 }
967
968 /**
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800969 * Gets the supported preview sizes.
970 *
Wu-cheng Li9c799382009-12-04 19:59:18 +0800971 * @return a List of Size object. This method will always return a list
972 * with at least one element.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800973 */
974 public List<Size> getSupportedPreviewSizes() {
975 String str = get(KEY_PREVIEW_SIZE + SUPPORTED_VALUES_SUFFIX);
976 return splitSize(str);
977 }
978
979 /**
Wu-cheng Li4c4300c2010-01-23 15:45:39 +0800980 * Sets the dimensions for EXIF thumbnail in Jpeg picture. If
981 * applications set both width and height to 0, EXIF will not contain
982 * thumbnail.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800983 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800984 * @param width the width of the thumbnail, in pixels
985 * @param height the height of the thumbnail, in pixels
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800986 */
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800987 public void setJpegThumbnailSize(int width, int height) {
988 set(KEY_JPEG_THUMBNAIL_WIDTH, width);
989 set(KEY_JPEG_THUMBNAIL_HEIGHT, height);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800990 }
991
992 /**
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800993 * Returns the dimensions for EXIF thumbnail in Jpeg picture.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800994 *
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800995 * @return a Size object with the height and width setting for the EXIF
996 * thumbnails
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800997 */
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800998 public Size getJpegThumbnailSize() {
999 return new Size(getInt(KEY_JPEG_THUMBNAIL_WIDTH),
1000 getInt(KEY_JPEG_THUMBNAIL_HEIGHT));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001001 }
1002
1003 /**
Wu-cheng Li4c4300c2010-01-23 15:45:39 +08001004 * Gets the supported jpeg thumbnail sizes.
1005 *
1006 * @return a List of Size object. This method will always return a list
1007 * with at least two elements. Size 0,0 (no thumbnail) is always
1008 * supported.
1009 */
1010 public List<Size> getSupportedJpegThumbnailSizes() {
1011 String str = get(KEY_JPEG_THUMBNAIL_SIZE + SUPPORTED_VALUES_SUFFIX);
1012 return splitSize(str);
1013 }
1014
1015 /**
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001016 * Sets the quality of the EXIF thumbnail in Jpeg picture.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001017 *
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001018 * @param quality the JPEG quality of the EXIF thumbnail. The range is 1
1019 * to 100, with 100 being the best.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001020 */
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001021 public void setJpegThumbnailQuality(int quality) {
1022 set(KEY_JPEG_THUMBNAIL_QUALITY, quality);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001023 }
1024
1025 /**
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001026 * Returns the quality setting for the EXIF thumbnail in Jpeg picture.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001027 *
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001028 * @return the JPEG quality setting of the EXIF thumbnail.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001029 */
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001030 public int getJpegThumbnailQuality() {
1031 return getInt(KEY_JPEG_THUMBNAIL_QUALITY);
1032 }
1033
1034 /**
1035 * Sets Jpeg quality of captured picture.
1036 *
1037 * @param quality the JPEG quality of captured picture. The range is 1
1038 * to 100, with 100 being the best.
1039 */
1040 public void setJpegQuality(int quality) {
1041 set(KEY_JPEG_QUALITY, quality);
1042 }
1043
1044 /**
1045 * Returns the quality setting for the JPEG picture.
1046 *
1047 * @return the JPEG picture quality setting.
1048 */
1049 public int getJpegQuality() {
1050 return getInt(KEY_JPEG_QUALITY);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001051 }
1052
1053 /**
1054 * Sets the rate at which preview frames are received.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001055 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001056 * @param fps the frame rate (frames per second)
1057 */
1058 public void setPreviewFrameRate(int fps) {
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001059 set(KEY_PREVIEW_FRAME_RATE, fps);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001060 }
1061
1062 /**
1063 * Returns the setting for the rate at which preview frames
1064 * are received.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001065 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001066 * @return the frame rate setting (frames per second)
1067 */
1068 public int getPreviewFrameRate() {
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001069 return getInt(KEY_PREVIEW_FRAME_RATE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001070 }
1071
1072 /**
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001073 * Gets the supported preview frame rates.
1074 *
1075 * @return a List of Integer objects (preview frame rates). null if
1076 * preview frame rate setting is not supported.
1077 */
1078 public List<Integer> getSupportedPreviewFrameRates() {
1079 String str = get(KEY_PREVIEW_FRAME_RATE + SUPPORTED_VALUES_SUFFIX);
1080 return splitInt(str);
1081 }
1082
1083 /**
Wu-cheng Li7478ea62009-09-16 18:52:55 +08001084 * Sets the image format for preview pictures.
Scott Mainda0a56d2009-09-10 18:08:37 -07001085 * <p>If this is never called, the default format will be
Scott Maindf4578e2009-09-10 12:22:07 -07001086 * {@link android.graphics.PixelFormat#YCbCr_420_SP}, which
1087 * uses the NV21 encoding format.</p>
Wu-cheng Li7478ea62009-09-16 18:52:55 +08001088 *
Scott Maindf4578e2009-09-10 12:22:07 -07001089 * @param pixel_format the desired preview picture format, defined
1090 * by one of the {@link android.graphics.PixelFormat} constants.
1091 * (E.g., <var>PixelFormat.YCbCr_420_SP</var> (default),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001092 * <var>PixelFormat.RGB_565</var>, or
1093 * <var>PixelFormat.JPEG</var>)
1094 * @see android.graphics.PixelFormat
1095 */
1096 public void setPreviewFormat(int pixel_format) {
1097 String s = cameraFormatForPixelFormat(pixel_format);
1098 if (s == null) {
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001099 throw new IllegalArgumentException(
1100 "Invalid pixel_format=" + pixel_format);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001101 }
1102
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001103 set(KEY_PREVIEW_FORMAT, s);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001104 }
1105
1106 /**
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001107 * Returns the image format for preview pictures got from
1108 * {@link PreviewCallback}.
Wu-cheng Li7478ea62009-09-16 18:52:55 +08001109 *
1110 * @return the {@link android.graphics.PixelFormat} int representing
Scott Maindf4578e2009-09-10 12:22:07 -07001111 * the preview picture format.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001112 */
1113 public int getPreviewFormat() {
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001114 return pixelFormatForCameraFormat(get(KEY_PREVIEW_FORMAT));
1115 }
1116
1117 /**
1118 * Gets the supported preview formats.
1119 *
Wu-cheng Li9c799382009-12-04 19:59:18 +08001120 * @return a List of Integer objects. This method will always return a
1121 * list with at least one element.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001122 */
1123 public List<Integer> getSupportedPreviewFormats() {
1124 String str = get(KEY_PREVIEW_FORMAT + SUPPORTED_VALUES_SUFFIX);
Chih-Chung Changeb68c462009-09-18 18:37:44 +08001125 ArrayList<Integer> formats = new ArrayList<Integer>();
1126 for (String s : split(str)) {
1127 int f = pixelFormatForCameraFormat(s);
1128 if (f == PixelFormat.UNKNOWN) continue;
1129 formats.add(f);
1130 }
1131 return formats;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001132 }
1133
1134 /**
1135 * Sets the dimensions for pictures.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001136 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001137 * @param width the width for pictures, in pixels
1138 * @param height the height for pictures, in pixels
1139 */
1140 public void setPictureSize(int width, int height) {
1141 String v = Integer.toString(width) + "x" + Integer.toString(height);
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001142 set(KEY_PICTURE_SIZE, v);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001143 }
1144
1145 /**
1146 * Returns the dimension setting for pictures.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001147 *
1148 * @return a Size object with the height and width setting
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001149 * for pictures
1150 */
1151 public Size getPictureSize() {
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001152 String pair = get(KEY_PICTURE_SIZE);
1153 return strToSize(pair);
1154 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001155
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001156 /**
1157 * Gets the supported picture sizes.
1158 *
Wu-cheng Li9c799382009-12-04 19:59:18 +08001159 * @return a List of Size objects. This method will always return a list
1160 * with at least one element.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001161 */
1162 public List<Size> getSupportedPictureSizes() {
1163 String str = get(KEY_PICTURE_SIZE + SUPPORTED_VALUES_SUFFIX);
1164 return splitSize(str);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001165 }
1166
1167 /**
1168 * Sets the image format for pictures.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001169 *
1170 * @param pixel_format the desired picture format
1171 * (<var>PixelFormat.YCbCr_420_SP (NV21)</var>,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001172 * <var>PixelFormat.RGB_565</var>, or
1173 * <var>PixelFormat.JPEG</var>)
1174 * @see android.graphics.PixelFormat
1175 */
1176 public void setPictureFormat(int pixel_format) {
1177 String s = cameraFormatForPixelFormat(pixel_format);
1178 if (s == null) {
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001179 throw new IllegalArgumentException(
1180 "Invalid pixel_format=" + pixel_format);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001181 }
1182
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001183 set(KEY_PICTURE_FORMAT, s);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001184 }
1185
1186 /**
1187 * Returns the image format for pictures.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001188 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001189 * @return the PixelFormat int representing the picture format
1190 */
1191 public int getPictureFormat() {
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001192 return pixelFormatForCameraFormat(get(KEY_PICTURE_FORMAT));
1193 }
1194
1195 /**
1196 * Gets the supported picture formats.
1197 *
Wu-cheng Li9c799382009-12-04 19:59:18 +08001198 * @return a List of Integer objects (values are PixelFormat.XXX). This
1199 * method will always return a list with at least one element.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001200 */
1201 public List<Integer> getSupportedPictureFormats() {
Wu-cheng Li9c799382009-12-04 19:59:18 +08001202 String str = get(KEY_PICTURE_FORMAT + SUPPORTED_VALUES_SUFFIX);
1203 ArrayList<Integer> formats = new ArrayList<Integer>();
1204 for (String s : split(str)) {
1205 int f = pixelFormatForCameraFormat(s);
1206 if (f == PixelFormat.UNKNOWN) continue;
1207 formats.add(f);
1208 }
1209 return formats;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001210 }
1211
1212 private String cameraFormatForPixelFormat(int pixel_format) {
1213 switch(pixel_format) {
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001214 case PixelFormat.YCbCr_422_SP: return PIXEL_FORMAT_YUV422SP;
1215 case PixelFormat.YCbCr_420_SP: return PIXEL_FORMAT_YUV420SP;
Chih-Chung Changeb68c462009-09-18 18:37:44 +08001216 case PixelFormat.YCbCr_422_I: return PIXEL_FORMAT_YUV422I;
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001217 case PixelFormat.RGB_565: return PIXEL_FORMAT_RGB565;
1218 case PixelFormat.JPEG: return PIXEL_FORMAT_JPEG;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001219 default: return null;
1220 }
1221 }
1222
1223 private int pixelFormatForCameraFormat(String format) {
1224 if (format == null)
1225 return PixelFormat.UNKNOWN;
1226
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001227 if (format.equals(PIXEL_FORMAT_YUV422SP))
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001228 return PixelFormat.YCbCr_422_SP;
1229
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001230 if (format.equals(PIXEL_FORMAT_YUV420SP))
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001231 return PixelFormat.YCbCr_420_SP;
1232
Chih-Chung Changeb68c462009-09-18 18:37:44 +08001233 if (format.equals(PIXEL_FORMAT_YUV422I))
1234 return PixelFormat.YCbCr_422_I;
1235
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001236 if (format.equals(PIXEL_FORMAT_RGB565))
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001237 return PixelFormat.RGB_565;
1238
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001239 if (format.equals(PIXEL_FORMAT_JPEG))
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001240 return PixelFormat.JPEG;
1241
1242 return PixelFormat.UNKNOWN;
1243 }
1244
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001245 /**
Wu-cheng Lie6bea602009-09-23 15:45:27 -07001246 * Sets the orientation of the device in degrees. For example, suppose
1247 * the natural position of the device is landscape. If the user takes a
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001248 * picture in landscape mode in 2048x1536 resolution, the rotation
1249 * should be set to 0. If the user rotates the phone 90 degrees
1250 * clockwise, the rotation should be set to 90. Applications can use
1251 * {@link android.view.OrientationEventListener} to set this parameter.
1252 *
Wu-cheng Lie6bea602009-09-23 15:45:27 -07001253 * The camera driver may set orientation in the EXIF header without
1254 * rotating the picture. Or the driver may rotate the picture and
1255 * the EXIF thumbnail. If the Jpeg picture is rotated, the orientation
1256 * in the EXIF header will be missing or 1 (row #0 is top and column #0
1257 * is left side).
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001258 *
1259 * @param rotation The orientation of the device in degrees. Rotation
1260 * can only be 0, 90, 180 or 270.
1261 * @throws IllegalArgumentException if rotation value is invalid.
1262 * @see android.view.OrientationEventListener
1263 */
1264 public void setRotation(int rotation) {
1265 if (rotation == 0 || rotation == 90 || rotation == 180
1266 || rotation == 270) {
1267 set(KEY_ROTATION, Integer.toString(rotation));
1268 } else {
1269 throw new IllegalArgumentException(
1270 "Invalid rotation=" + rotation);
1271 }
1272 }
1273
1274 /**
1275 * Sets GPS latitude coordinate. This will be stored in JPEG EXIF
1276 * header.
1277 *
1278 * @param latitude GPS latitude coordinate.
1279 */
1280 public void setGpsLatitude(double latitude) {
1281 set(KEY_GPS_LATITUDE, Double.toString(latitude));
1282 }
1283
1284 /**
1285 * Sets GPS longitude coordinate. This will be stored in JPEG EXIF
1286 * header.
1287 *
1288 * @param longitude GPS longitude coordinate.
1289 */
1290 public void setGpsLongitude(double longitude) {
1291 set(KEY_GPS_LONGITUDE, Double.toString(longitude));
1292 }
1293
1294 /**
1295 * Sets GPS altitude. This will be stored in JPEG EXIF header.
1296 *
1297 * @param altitude GPS altitude in meters.
1298 */
1299 public void setGpsAltitude(double altitude) {
1300 set(KEY_GPS_ALTITUDE, Double.toString(altitude));
1301 }
1302
1303 /**
1304 * Sets GPS timestamp. This will be stored in JPEG EXIF header.
1305 *
1306 * @param timestamp GPS timestamp (UTC in seconds since January 1,
1307 * 1970).
1308 */
1309 public void setGpsTimestamp(long timestamp) {
1310 set(KEY_GPS_TIMESTAMP, Long.toString(timestamp));
1311 }
1312
1313 /**
1314 * Removes GPS latitude, longitude, altitude, and timestamp from the
1315 * parameters.
1316 */
1317 public void removeGpsData() {
1318 remove(KEY_GPS_LATITUDE);
1319 remove(KEY_GPS_LONGITUDE);
1320 remove(KEY_GPS_ALTITUDE);
1321 remove(KEY_GPS_TIMESTAMP);
1322 }
1323
1324 /**
1325 * Gets the current white balance setting.
1326 *
1327 * @return one of WHITE_BALANCE_XXX string constant. null if white
1328 * balance setting is not supported.
1329 */
1330 public String getWhiteBalance() {
1331 return get(KEY_WHITE_BALANCE);
1332 }
1333
1334 /**
1335 * Sets the white balance.
1336 *
1337 * @param value WHITE_BALANCE_XXX string constant.
1338 */
1339 public void setWhiteBalance(String value) {
1340 set(KEY_WHITE_BALANCE, value);
1341 }
1342
1343 /**
1344 * Gets the supported white balance.
1345 *
1346 * @return a List of WHITE_BALANCE_XXX string constants. null if white
1347 * balance setting is not supported.
1348 */
1349 public List<String> getSupportedWhiteBalance() {
1350 String str = get(KEY_WHITE_BALANCE + SUPPORTED_VALUES_SUFFIX);
1351 return split(str);
1352 }
1353
1354 /**
1355 * Gets the current color effect setting.
1356 *
1357 * @return one of EFFECT_XXX string constant. null if color effect
1358 * setting is not supported.
1359 */
1360 public String getColorEffect() {
1361 return get(KEY_EFFECT);
1362 }
1363
1364 /**
1365 * Sets the current color effect setting.
1366 *
1367 * @param value EFFECT_XXX string constants.
1368 */
1369 public void setColorEffect(String value) {
1370 set(KEY_EFFECT, value);
1371 }
1372
1373 /**
1374 * Gets the supported color effects.
1375 *
1376 * @return a List of EFFECT_XXX string constants. null if color effect
1377 * setting is not supported.
1378 */
1379 public List<String> getSupportedColorEffects() {
1380 String str = get(KEY_EFFECT + SUPPORTED_VALUES_SUFFIX);
1381 return split(str);
1382 }
1383
1384
1385 /**
1386 * Gets the current antibanding setting.
1387 *
1388 * @return one of ANTIBANDING_XXX string constant. null if antibanding
1389 * setting is not supported.
1390 */
1391 public String getAntibanding() {
1392 return get(KEY_ANTIBANDING);
1393 }
1394
1395 /**
1396 * Sets the antibanding.
1397 *
1398 * @param antibanding ANTIBANDING_XXX string constant.
1399 */
1400 public void setAntibanding(String antibanding) {
1401 set(KEY_ANTIBANDING, antibanding);
1402 }
1403
1404 /**
1405 * Gets the supported antibanding values.
1406 *
1407 * @return a List of ANTIBANDING_XXX string constants. null if
1408 * antibanding setting is not supported.
1409 */
1410 public List<String> getSupportedAntibanding() {
1411 String str = get(KEY_ANTIBANDING + SUPPORTED_VALUES_SUFFIX);
1412 return split(str);
1413 }
1414
1415 /**
1416 * Gets the current scene mode setting.
1417 *
1418 * @return one of SCENE_MODE_XXX string constant. null if scene mode
1419 * setting is not supported.
1420 */
1421 public String getSceneMode() {
1422 return get(KEY_SCENE_MODE);
1423 }
1424
1425 /**
Wu-cheng Li2988ab72009-09-30 17:08:19 -07001426 * Sets the scene mode. Other parameters may be changed after changing
1427 * scene mode. For example, flash and supported flash mode may be
1428 * changed to "off" in night scene mode. After setting scene mode,
1429 * applications should call getParameters to know if some parameters are
1430 * changed.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001431 *
1432 * @param value SCENE_MODE_XXX string constants.
1433 */
1434 public void setSceneMode(String value) {
1435 set(KEY_SCENE_MODE, value);
1436 }
1437
1438 /**
1439 * Gets the supported scene modes.
1440 *
1441 * @return a List of SCENE_MODE_XXX string constant. null if scene mode
1442 * setting is not supported.
1443 */
1444 public List<String> getSupportedSceneModes() {
1445 String str = get(KEY_SCENE_MODE + SUPPORTED_VALUES_SUFFIX);
1446 return split(str);
1447 }
1448
1449 /**
1450 * Gets the current flash mode setting.
1451 *
1452 * @return one of FLASH_MODE_XXX string constant. null if flash mode
1453 * setting is not supported.
1454 */
1455 public String getFlashMode() {
1456 return get(KEY_FLASH_MODE);
1457 }
1458
1459 /**
1460 * Sets the flash mode.
1461 *
1462 * @param value FLASH_MODE_XXX string constants.
1463 */
1464 public void setFlashMode(String value) {
1465 set(KEY_FLASH_MODE, value);
1466 }
1467
1468 /**
1469 * Gets the supported flash modes.
1470 *
1471 * @return a List of FLASH_MODE_XXX string constants. null if flash mode
1472 * setting is not supported.
1473 */
1474 public List<String> getSupportedFlashModes() {
1475 String str = get(KEY_FLASH_MODE + SUPPORTED_VALUES_SUFFIX);
1476 return split(str);
1477 }
1478
Wu-cheng Li36322db2009-09-18 18:59:21 +08001479 /**
1480 * Gets the current focus mode setting.
1481 *
1482 * @return one of FOCUS_MODE_XXX string constant. If the camera does not
1483 * support auto-focus, this should return {@link
1484 * #FOCUS_MODE_FIXED}. If the focus mode is not FOCUS_MODE_FIXED
1485 * or {@link #FOCUS_MODE_INFINITY}, applications should call
1486 * {@link #autoFocus(AutoFocusCallback)} to start the focus.
1487 */
1488 public String getFocusMode() {
1489 return get(KEY_FOCUS_MODE);
1490 }
1491
1492 /**
1493 * Sets the focus mode.
1494 *
1495 * @param value FOCUS_MODE_XXX string constants.
1496 */
1497 public void setFocusMode(String value) {
1498 set(KEY_FOCUS_MODE, value);
1499 }
1500
1501 /**
1502 * Gets the supported focus modes.
1503 *
Wu-cheng Li9c799382009-12-04 19:59:18 +08001504 * @return a List of FOCUS_MODE_XXX string constants. This method will
1505 * always return a list with at least one element.
Wu-cheng Li36322db2009-09-18 18:59:21 +08001506 */
1507 public List<String> getSupportedFocusModes() {
1508 String str = get(KEY_FOCUS_MODE + SUPPORTED_VALUES_SUFFIX);
1509 return split(str);
1510 }
1511
Wu-cheng Li36f68b82009-09-28 16:14:58 -07001512 /**
Wu-cheng Li6c8d2762010-01-27 22:55:14 +08001513 * Gets the focal length (in millimeter) of the camera.
1514 *
1515 * @return the focal length. This method will always return a valid
1516 * value.
1517 */
1518 public float getFocalLength() {
1519 return Float.parseFloat(get(KEY_FOCAL_LENGTH));
1520 }
1521
1522 /**
1523 * Gets the horizontal angle of view in degrees.
1524 *
1525 * @return horizontal angle of view. This method will always return a
1526 * valid value.
1527 */
1528 public float getHorizontalViewAngle() {
1529 return Float.parseFloat(get(KEY_HORIZONTAL_VIEW_ANGLE));
1530 }
1531
1532 /**
1533 * Gets the vertical angle of view in degrees.
1534 *
1535 * @return vertical angle of view. This method will always return a
1536 * valid value.
1537 */
1538 public float getVerticalViewAngle() {
1539 return Float.parseFloat(get(KEY_VERTICAL_VIEW_ANGLE));
1540 }
1541
1542 /**
Wu-cheng Li36f68b82009-09-28 16:14:58 -07001543 * Gets current zoom value. This also works when smooth zoom is in
1544 * progress.
1545 *
1546 * @return the current zoom value. The range is 0 to {@link
1547 * #getMaxZoom}.
1548 * @hide
1549 */
1550 public int getZoom() {
1551 return getInt("zoom");
1552 }
1553
1554 /**
1555 * Sets current zoom value. If {@link #startSmoothZoom(int)} has been
1556 * called and zoom is not stopped yet, applications should not call this
1557 * method.
1558 *
1559 * @param value zoom value. The valid range is 0 to {@link #getMaxZoom}.
1560 * @hide
1561 */
1562 public void setZoom(int value) {
1563 set("zoom", value);
1564 }
1565
1566 /**
1567 * Returns true if zoom is supported. Applications should call this
1568 * before using other zoom methods.
1569 *
1570 * @return true if zoom is supported.
1571 * @hide
1572 */
1573 public boolean isZoomSupported() {
1574 String str = get("zoom-supported");
1575 return "true".equals(str);
1576 }
1577
1578 /**
1579 * Gets the maximum zoom value allowed for snapshot. This is the maximum
1580 * value that applications can set to {@link #setZoom(int)}.
1581 *
1582 * @return the maximum zoom value supported by the camera.
1583 * @hide
1584 */
1585 public int getMaxZoom() {
1586 return getInt("max-zoom");
1587 }
1588
1589 /**
1590 * Gets the zoom factors of all zoom values.
1591 *
1592 * @return the zoom factors in 1/100 increments. Ex: a zoom of 3.2x is
1593 * returned as 320. Accuracy of the value is dependent on the
1594 * hardware implementation. The first element of the list is the
1595 * zoom factor of first zoom value. If the first zoom value is
1596 * 0, the zoom factor should be 100. The last element is the
1597 * zoom factor of zoom value {@link #getMaxZoom}.
1598 * @hide
1599 */
1600 public List<Integer> getZoomFactors() {
1601 return splitInt(get("zoom-factors"));
1602 }
1603
1604 /**
1605 * Returns true if smooth zoom is supported. Applications should call
1606 * this before using other smooth zoom methods.
1607 *
1608 * @return true if smooth zoom is supported.
1609 * @hide
1610 */
1611 public boolean isSmoothZoomSupported() {
1612 String str = get("smooth-zoom-supported");
1613 return "true".equals(str);
1614 }
1615
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001616 // Splits a comma delimited string to an ArrayList of String.
1617 // Return null if the passing string is null or the size is 0.
1618 private ArrayList<String> split(String str) {
1619 if (str == null) return null;
1620
1621 // Use StringTokenizer because it is faster than split.
1622 StringTokenizer tokenizer = new StringTokenizer(str, ",");
1623 ArrayList<String> substrings = new ArrayList<String>();
1624 while (tokenizer.hasMoreElements()) {
1625 substrings.add(tokenizer.nextToken());
1626 }
1627 return substrings;
1628 }
1629
1630 // Splits a comma delimited string to an ArrayList of Integer.
1631 // Return null if the passing string is null or the size is 0.
1632 private ArrayList<Integer> splitInt(String str) {
1633 if (str == null) return null;
1634
1635 StringTokenizer tokenizer = new StringTokenizer(str, ",");
1636 ArrayList<Integer> substrings = new ArrayList<Integer>();
1637 while (tokenizer.hasMoreElements()) {
1638 String token = tokenizer.nextToken();
1639 substrings.add(Integer.parseInt(token));
1640 }
1641 if (substrings.size() == 0) return null;
1642 return substrings;
1643 }
1644
1645 // Splits a comma delimited string to an ArrayList of Size.
1646 // Return null if the passing string is null or the size is 0.
1647 private ArrayList<Size> splitSize(String str) {
1648 if (str == null) return null;
1649
1650 StringTokenizer tokenizer = new StringTokenizer(str, ",");
1651 ArrayList<Size> sizeList = new ArrayList<Size>();
1652 while (tokenizer.hasMoreElements()) {
1653 Size size = strToSize(tokenizer.nextToken());
1654 if (size != null) sizeList.add(size);
1655 }
1656 if (sizeList.size() == 0) return null;
1657 return sizeList;
1658 }
1659
1660 // Parses a string (ex: "480x320") to Size object.
1661 // Return null if the passing string is null.
1662 private Size strToSize(String str) {
1663 if (str == null) return null;
1664
1665 int pos = str.indexOf('x');
1666 if (pos != -1) {
1667 String width = str.substring(0, pos);
1668 String height = str.substring(pos + 1);
1669 return new Size(Integer.parseInt(width),
1670 Integer.parseInt(height));
1671 }
1672 Log.e(TAG, "Invalid size parameter string=" + str);
1673 return null;
1674 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001675 };
1676}