Camera.java revision 26274fae33b7b056cf5fe9fd6e823cae9e4ddae2
181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent/*
281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent * Copyright (C) 2008 The Android Open Source Project
381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent *
481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent * Licensed under the Apache License, Version 2.0 (the "License");
581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent * you may not use this file except in compliance with the License.
681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent * You may obtain a copy of the License at
781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent *
881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent *      http://www.apache.org/licenses/LICENSE-2.0
981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent *
1081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent * Unless required by applicable law or agreed to in writing, software
1181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent * distributed under the License is distributed on an "AS IS" BASIS,
1281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent * See the License for the specific language governing permissions and
1481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent * limitations under the License.
1581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent */
1681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent
1781784c37c61b09289654b979567a42bf73cd2b12Eric Laurentpackage android.hardware;
1881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent
1981784c37c61b09289654b979567a42bf73cd2b12Eric Laurentimport java.lang.ref.WeakReference;
2081784c37c61b09289654b979567a42bf73cd2b12Eric Laurentimport java.util.ArrayList;
2181784c37c61b09289654b979567a42bf73cd2b12Eric Laurentimport java.util.HashMap;
2281784c37c61b09289654b979567a42bf73cd2b12Eric Laurentimport java.util.List;
2381784c37c61b09289654b979567a42bf73cd2b12Eric Laurentimport java.util.StringTokenizer;
2481784c37c61b09289654b979567a42bf73cd2b12Eric Laurentimport java.io.IOException;
2581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent
2681784c37c61b09289654b979567a42bf73cd2b12Eric Laurentimport android.util.Log;
2781784c37c61b09289654b979567a42bf73cd2b12Eric Laurentimport android.view.Surface;
2881784c37c61b09289654b979567a42bf73cd2b12Eric Laurentimport android.view.SurfaceHolder;
2981784c37c61b09289654b979567a42bf73cd2b12Eric Laurentimport android.graphics.ImageFormat;
3081784c37c61b09289654b979567a42bf73cd2b12Eric Laurentimport android.graphics.Rect;
31bfb1b832079bbb9426f72f3863199a54aefd02daEric Laurentimport android.graphics.SurfaceTexture;
32bfb1b832079bbb9426f72f3863199a54aefd02daEric Laurentimport android.os.Handler;
3381784c37c61b09289654b979567a42bf73cd2b12Eric Laurentimport android.os.Looper;
3481784c37c61b09289654b979567a42bf73cd2b12Eric Laurentimport android.os.Message;
3597b7b75b6a31330e213bdb96ccc60916218ad903Glenn Kasten
3697b7b75b6a31330e213bdb96ccc60916218ad903Glenn Kasten/**
3781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent * The Camera class is used to set image capture settings, start/stop preview,
3872e3f39146fce4686bd96f11057c051bea376dfbEric Laurent * snap pictures, and retrieve frames for encoding for video.  This class is a
3972e3f39146fce4686bd96f11057c051bea376dfbEric Laurent * client for the Camera service, which manages the actual camera hardware.
4081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent *
4181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent * <p>To access the device camera, you must declare the
42cf04c2cb8e031acc03c1c91cb1ccab15098c89b6Glenn Kasten * {@link android.Manifest.permission#CAMERA} permission in your Android
43cf04c2cb8e031acc03c1c91cb1ccab15098c89b6Glenn Kasten * Manifest. Also be sure to include the
4481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent * <a href="{@docRoot}guide/topics/manifest/uses-feature-element.html">&lt;uses-feature></a>
4581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent * manifest element to declare camera features used by your application.
4681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent * For example, if you use the camera and auto-focus feature, your Manifest
4781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent * should include the following:</p>
4881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent * <pre> &lt;uses-permission android:name="android.permission.CAMERA" />
4981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent * &lt;uses-feature android:name="android.hardware.camera" />
5081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent * &lt;uses-feature android:name="android.hardware.camera.autofocus" /></pre>
5181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent *
521035194cee4fbd57e35ea15c56e66cd09b63d56eEric Laurent * <p>To take pictures with this class, use the following steps:</p>
531035194cee4fbd57e35ea15c56e66cd09b63d56eEric Laurent *
541c333e252cbca3337c1bedbc57a005f3b7d23fdbEric Laurent * <ol>
551c333e252cbca3337c1bedbc57a005f3b7d23fdbEric Laurent * <li>Obtain an instance of Camera from {@link #open(int)}.
5681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent *
5781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent * <li>Get existing (default) settings with {@link #getParameters()}.
581035194cee4fbd57e35ea15c56e66cd09b63d56eEric Laurent *
591035194cee4fbd57e35ea15c56e66cd09b63d56eEric Laurent * <li>If necessary, modify the returned {@link Camera.Parameters} object and call
601035194cee4fbd57e35ea15c56e66cd09b63d56eEric Laurent * {@link #setParameters(Camera.Parameters)}.
611035194cee4fbd57e35ea15c56e66cd09b63d56eEric Laurent *
621035194cee4fbd57e35ea15c56e66cd09b63d56eEric Laurent * <li>If desired, call {@link #setDisplayOrientation(int)}.
631035194cee4fbd57e35ea15c56e66cd09b63d56eEric Laurent *
641035194cee4fbd57e35ea15c56e66cd09b63d56eEric Laurent * <li><b>Important</b>: Pass a fully initialized {@link SurfaceHolder} to
651035194cee4fbd57e35ea15c56e66cd09b63d56eEric Laurent * {@link #setPreviewDisplay(SurfaceHolder)}.  Without a surface, the camera
661035194cee4fbd57e35ea15c56e66cd09b63d56eEric Laurent * will be unable to start the preview.
671035194cee4fbd57e35ea15c56e66cd09b63d56eEric Laurent *
681035194cee4fbd57e35ea15c56e66cd09b63d56eEric Laurent * <li><b>Important</b>: Call {@link #startPreview()} to start updating the
691035194cee4fbd57e35ea15c56e66cd09b63d56eEric Laurent * preview surface.  Preview must be started before you can take a picture.
701035194cee4fbd57e35ea15c56e66cd09b63d56eEric Laurent *
711035194cee4fbd57e35ea15c56e66cd09b63d56eEric Laurent * <li>When you want, call {@link #takePicture(Camera.ShutterCallback,
721035194cee4fbd57e35ea15c56e66cd09b63d56eEric Laurent * Camera.PictureCallback, Camera.PictureCallback, Camera.PictureCallback)} to
731035194cee4fbd57e35ea15c56e66cd09b63d56eEric Laurent * capture a photo.  Wait for the callbacks to provide the actual image data.
741035194cee4fbd57e35ea15c56e66cd09b63d56eEric Laurent *
751035194cee4fbd57e35ea15c56e66cd09b63d56eEric Laurent * <li>After taking a picture, preview display will have stopped.  To take more
761035194cee4fbd57e35ea15c56e66cd09b63d56eEric Laurent * photos, call {@link #startPreview()} again first.
771035194cee4fbd57e35ea15c56e66cd09b63d56eEric Laurent *
781035194cee4fbd57e35ea15c56e66cd09b63d56eEric Laurent * <li>Call {@link #stopPreview()} to stop updating the preview surface.
791035194cee4fbd57e35ea15c56e66cd09b63d56eEric Laurent *
801035194cee4fbd57e35ea15c56e66cd09b63d56eEric Laurent * <li><b>Important:</b> Call {@link #release()} to release the camera for
811035194cee4fbd57e35ea15c56e66cd09b63d56eEric Laurent * use by other applications.  Applications should release the camera
821035194cee4fbd57e35ea15c56e66cd09b63d56eEric Laurent * immediately in {@link android.app.Activity#onPause()} (and re-{@link #open()}
831035194cee4fbd57e35ea15c56e66cd09b63d56eEric Laurent * it in {@link android.app.Activity#onResume()}).
841035194cee4fbd57e35ea15c56e66cd09b63d56eEric Laurent * </ol>
851035194cee4fbd57e35ea15c56e66cd09b63d56eEric Laurent *
8681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent * <p>To quickly switch to video recording mode, use these steps:</p>
8781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent *
8881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent * <ol>
891035194cee4fbd57e35ea15c56e66cd09b63d56eEric Laurent * <li>Obtain and initialize a Camera and start preview as described above.
9081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent *
911035194cee4fbd57e35ea15c56e66cd09b63d56eEric Laurent * <li>Call {@link #unlock()} to allow the media process to access the camera.
921035194cee4fbd57e35ea15c56e66cd09b63d56eEric Laurent *
931035194cee4fbd57e35ea15c56e66cd09b63d56eEric Laurent * <li>Pass the camera to {@link android.media.MediaRecorder#setCamera(Camera)}.
941035194cee4fbd57e35ea15c56e66cd09b63d56eEric Laurent * See {@link android.media.MediaRecorder} information about video recording.
951035194cee4fbd57e35ea15c56e66cd09b63d56eEric Laurent *
9672e3f39146fce4686bd96f11057c051bea376dfbEric Laurent * <li>When finished recording, call {@link #reconnect()} to re-acquire
971035194cee4fbd57e35ea15c56e66cd09b63d56eEric Laurent * and re-lock the camera.
9881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent *
991035194cee4fbd57e35ea15c56e66cd09b63d56eEric Laurent * <li>If desired, restart preview and take more photos or videos.
100e964d4e421e2d1ca937227a580c0c837091a11e3Chih-Hung Hsieh *
10172e3f39146fce4686bd96f11057c051bea376dfbEric Laurent * <li>Call {@link #stopPreview()} and {@link #release()} as described above.
10272e3f39146fce4686bd96f11057c051bea376dfbEric Laurent * </ol>
10381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent *
10481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent * <p>This class is not thread-safe, and is meant for use from one event thread.
1051035194cee4fbd57e35ea15c56e66cd09b63d56eEric Laurent * Most long-running operations (preview, focus, photo capture, etc) happen
10681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent * asynchronously and invoke callbacks as necessary.  Callbacks will be invoked
1077c1ec5f038e63a5eb8b04434577c25bc23f5f410Eric Laurent * on the event thread {@link #open(int)} was called from.  This class's methods
1087c1ec5f038e63a5eb8b04434577c25bc23f5f410Eric Laurent * must never be called from multiple threads at once.</p>
10981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent *
11081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent * <p class="caution"><strong>Caution:</strong> Different Android-powered devices
11173e26b661af50be2c0a4ff6c9ac85f7347a8b235Eric Laurent * may have different hardware specifications, such as megapixel ratings and
11281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent * auto-focus capabilities. In order for your application to be compatible with
11381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent * more devices, you should not make assumptions about the device camera
11473e26b661af50be2c0a4ff6c9ac85f7347a8b235Eric Laurent * specifications.</p>
1157c1ec5f038e63a5eb8b04434577c25bc23f5f410Eric Laurent */
11681784c37c61b09289654b979567a42bf73cd2b12Eric Laurentpublic class Camera {
11781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent    private static final String TAG = "Camera";
1181035194cee4fbd57e35ea15c56e66cd09b63d56eEric Laurent
11981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent    // These match the enums in frameworks/base/include/camera/Camera.h
1207c1ec5f038e63a5eb8b04434577c25bc23f5f410Eric Laurent    private static final int CAMERA_MSG_ERROR            = 0x001;
1211035194cee4fbd57e35ea15c56e66cd09b63d56eEric Laurent    private static final int CAMERA_MSG_SHUTTER          = 0x002;
1227c1ec5f038e63a5eb8b04434577c25bc23f5f410Eric Laurent    private static final int CAMERA_MSG_FOCUS            = 0x004;
1231035194cee4fbd57e35ea15c56e66cd09b63d56eEric Laurent    private static final int CAMERA_MSG_ZOOM             = 0x008;
1241035194cee4fbd57e35ea15c56e66cd09b63d56eEric Laurent    private static final int CAMERA_MSG_PREVIEW_FRAME    = 0x010;
1251035194cee4fbd57e35ea15c56e66cd09b63d56eEric Laurent    private static final int CAMERA_MSG_VIDEO_FRAME      = 0x020;
12681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent    private static final int CAMERA_MSG_POSTVIEW_FRAME   = 0x040;
1271035194cee4fbd57e35ea15c56e66cd09b63d56eEric Laurent    private static final int CAMERA_MSG_RAW_IMAGE        = 0x080;
1281035194cee4fbd57e35ea15c56e66cd09b63d56eEric Laurent    private static final int CAMERA_MSG_COMPRESSED_IMAGE = 0x100;
12983f042776b131b149f803fff6ab184ae2c4d98cdMikhail Naganov    private static final int CAMERA_MSG_ALL_MSGS         = 0x1FF;
13083f042776b131b149f803fff6ab184ae2c4d98cdMikhail Naganov
13181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent    private int mNativeContext; // accessed by native methods
13281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent    private EventHandler mEventHandler;
13383f042776b131b149f803fff6ab184ae2c4d98cdMikhail Naganov    private ShutterCallback mShutterCallback;
13483f042776b131b149f803fff6ab184ae2c4d98cdMikhail Naganov    private PictureCallback mRawImageCallback;
13581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent    private PictureCallback mJpegCallback;
13681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent    private PreviewCallback mPreviewCallback;
13781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent    private PictureCallback mPostviewCallback;
13881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent    private AutoFocusCallback mAutoFocusCallback;
13981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent    private OnZoomChangeListener mZoomListener;
14083f042776b131b149f803fff6ab184ae2c4d98cdMikhail Naganov    private ErrorCallback mErrorCallback;
14181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent    private boolean mOneShot;
14281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent    private boolean mWithBuffer;
1431035194cee4fbd57e35ea15c56e66cd09b63d56eEric Laurent
1441035194cee4fbd57e35ea15c56e66cd09b63d56eEric Laurent    /**
14583f042776b131b149f803fff6ab184ae2c4d98cdMikhail Naganov     * Returns the number of physical cameras available on this device.
14672e3f39146fce4686bd96f11057c051bea376dfbEric Laurent     */
14783f042776b131b149f803fff6ab184ae2c4d98cdMikhail Naganov    public native static int getNumberOfCameras();
1481035194cee4fbd57e35ea15c56e66cd09b63d56eEric Laurent
1491035194cee4fbd57e35ea15c56e66cd09b63d56eEric Laurent    /**
1501035194cee4fbd57e35ea15c56e66cd09b63d56eEric Laurent     * Returns the information about a particular camera.
1511035194cee4fbd57e35ea15c56e66cd09b63d56eEric Laurent     * If {@link #getNumberOfCameras()} returns N, the valid id is 0 to N-1.
1521035194cee4fbd57e35ea15c56e66cd09b63d56eEric Laurent     */
1531035194cee4fbd57e35ea15c56e66cd09b63d56eEric Laurent    public native static void getCameraInfo(int cameraId, CameraInfo cameraInfo);
154e964d4e421e2d1ca937227a580c0c837091a11e3Chih-Hung Hsieh
1551035194cee4fbd57e35ea15c56e66cd09b63d56eEric Laurent    /**
1561035194cee4fbd57e35ea15c56e66cd09b63d56eEric Laurent     * Information about a camera
1571035194cee4fbd57e35ea15c56e66cd09b63d56eEric Laurent     */
1581035194cee4fbd57e35ea15c56e66cd09b63d56eEric Laurent    public static class CameraInfo {
1591035194cee4fbd57e35ea15c56e66cd09b63d56eEric Laurent        /**
1601035194cee4fbd57e35ea15c56e66cd09b63d56eEric Laurent         * The facing of the camera is opposite to that of the screen.
1611035194cee4fbd57e35ea15c56e66cd09b63d56eEric Laurent         */
1621035194cee4fbd57e35ea15c56e66cd09b63d56eEric Laurent        public static final int CAMERA_FACING_BACK = 0;
1631035194cee4fbd57e35ea15c56e66cd09b63d56eEric Laurent
1641035194cee4fbd57e35ea15c56e66cd09b63d56eEric Laurent        /**
1651035194cee4fbd57e35ea15c56e66cd09b63d56eEric Laurent         * The facing of the camera is the same as that of the screen.
166e964d4e421e2d1ca937227a580c0c837091a11e3Chih-Hung Hsieh         */
1671035194cee4fbd57e35ea15c56e66cd09b63d56eEric Laurent        public static final int CAMERA_FACING_FRONT = 1;
1681035194cee4fbd57e35ea15c56e66cd09b63d56eEric Laurent
1691035194cee4fbd57e35ea15c56e66cd09b63d56eEric Laurent        /**
1701035194cee4fbd57e35ea15c56e66cd09b63d56eEric Laurent         * The direction that the camera faces to. It should be
1711035194cee4fbd57e35ea15c56e66cd09b63d56eEric Laurent         * CAMERA_FACING_BACK or CAMERA_FACING_FRONT.
1721035194cee4fbd57e35ea15c56e66cd09b63d56eEric Laurent         */
1731035194cee4fbd57e35ea15c56e66cd09b63d56eEric Laurent        public int facing;
1741c333e252cbca3337c1bedbc57a005f3b7d23fdbEric Laurent
1751c333e252cbca3337c1bedbc57a005f3b7d23fdbEric Laurent        /**
1761c333e252cbca3337c1bedbc57a005f3b7d23fdbEric Laurent         * The orientation of the camera image. The value is the angle that the
1771c333e252cbca3337c1bedbc57a005f3b7d23fdbEric Laurent         * camera image needs to be rotated clockwise so it shows correctly on
1781c333e252cbca3337c1bedbc57a005f3b7d23fdbEric Laurent         * the display in its natural orientation. It should be 0, 90, 180, or 270.
1791c333e252cbca3337c1bedbc57a005f3b7d23fdbEric Laurent         *
1801c333e252cbca3337c1bedbc57a005f3b7d23fdbEric Laurent         * For example, suppose a device has a naturally tall screen. The
1811c333e252cbca3337c1bedbc57a005f3b7d23fdbEric Laurent         * back-facing camera sensor is mounted in landscape. You are looking at
1821c333e252cbca3337c1bedbc57a005f3b7d23fdbEric Laurent         * the screen. If the top side of the camera sensor is aligned with the
1831c333e252cbca3337c1bedbc57a005f3b7d23fdbEric Laurent         * right edge of the screen in natural orientation, the value should be
1841c333e252cbca3337c1bedbc57a005f3b7d23fdbEric Laurent         * 90. If the top side of a front-facing camera sensor is aligned with
1851c333e252cbca3337c1bedbc57a005f3b7d23fdbEric Laurent         * the right of the screen, the value should be 270.
1861c333e252cbca3337c1bedbc57a005f3b7d23fdbEric Laurent         *
1871c333e252cbca3337c1bedbc57a005f3b7d23fdbEric Laurent         * @see #setDisplayOrientation(int)
1881c333e252cbca3337c1bedbc57a005f3b7d23fdbEric Laurent         * @see Parameters#setRotation(int)
1891c333e252cbca3337c1bedbc57a005f3b7d23fdbEric Laurent         * @see Parameters#setPreviewSize(int, int)
1901c333e252cbca3337c1bedbc57a005f3b7d23fdbEric Laurent         * @see Parameters#setPictureSize(int, int)
1911c333e252cbca3337c1bedbc57a005f3b7d23fdbEric Laurent         * @see Parameters#setJpegThumbnailSize(int, int)
1921c333e252cbca3337c1bedbc57a005f3b7d23fdbEric Laurent         */
1931c333e252cbca3337c1bedbc57a005f3b7d23fdbEric Laurent        public int orientation;
1941c333e252cbca3337c1bedbc57a005f3b7d23fdbEric Laurent    };
1951c333e252cbca3337c1bedbc57a005f3b7d23fdbEric Laurent
1961c333e252cbca3337c1bedbc57a005f3b7d23fdbEric Laurent    /**
1971c333e252cbca3337c1bedbc57a005f3b7d23fdbEric Laurent     * Creates a new Camera object to access a particular hardware camera.
1981c333e252cbca3337c1bedbc57a005f3b7d23fdbEric Laurent     *
1991c333e252cbca3337c1bedbc57a005f3b7d23fdbEric Laurent     * <p>You must call {@link #release()} when you are done using the camera,
2001c333e252cbca3337c1bedbc57a005f3b7d23fdbEric Laurent     * otherwise it will remain locked and be unavailable to other applications.
201e964d4e421e2d1ca937227a580c0c837091a11e3Chih-Hung Hsieh     *
2021c333e252cbca3337c1bedbc57a005f3b7d23fdbEric Laurent     * <p>Your application should only have one Camera object active at a time
2031c333e252cbca3337c1bedbc57a005f3b7d23fdbEric Laurent     * for a particular hardware camera.
2041c333e252cbca3337c1bedbc57a005f3b7d23fdbEric Laurent     *
2051c333e252cbca3337c1bedbc57a005f3b7d23fdbEric Laurent     * <p>Callbacks from other methods are delivered to the event loop of the
2061c333e252cbca3337c1bedbc57a005f3b7d23fdbEric Laurent     * thread which called open().  If this thread has no event loop, then
2071c333e252cbca3337c1bedbc57a005f3b7d23fdbEric Laurent     * callbacks are delivered to the main application event loop.  If there
2081c333e252cbca3337c1bedbc57a005f3b7d23fdbEric Laurent     * is no main application event loop, callbacks are not delivered.
2091c333e252cbca3337c1bedbc57a005f3b7d23fdbEric Laurent     *
2101c333e252cbca3337c1bedbc57a005f3b7d23fdbEric Laurent     * <p class="caution"><b>Caution:</b> On some devices, this method may
2111c333e252cbca3337c1bedbc57a005f3b7d23fdbEric Laurent     * take a long time to complete.  It is best to call this method from a
2121c333e252cbca3337c1bedbc57a005f3b7d23fdbEric Laurent     * worker thread (possibly using {@link android.os.AsyncTask}) to avoid
213e964d4e421e2d1ca937227a580c0c837091a11e3Chih-Hung Hsieh     * blocking the main application UI thread.
2141c333e252cbca3337c1bedbc57a005f3b7d23fdbEric Laurent     *
2151c333e252cbca3337c1bedbc57a005f3b7d23fdbEric Laurent     * @param cameraId the hardware camera to access, between 0 and
2161c333e252cbca3337c1bedbc57a005f3b7d23fdbEric Laurent     *     {@link #getNumberOfCameras()}-1.
2171c333e252cbca3337c1bedbc57a005f3b7d23fdbEric Laurent     * @return a new Camera object, connected, locked and ready for use.
2181c333e252cbca3337c1bedbc57a005f3b7d23fdbEric Laurent     * @throws RuntimeException if connection to the camera service fails (for
2191c333e252cbca3337c1bedbc57a005f3b7d23fdbEric Laurent     *     example, if the camera is in use by another process).
22081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     */
22181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent    public static Camera open(int cameraId) {
22281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent        return new Camera(cameraId);
223e964d4e421e2d1ca937227a580c0c837091a11e3Chih-Hung Hsieh    }
22481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent
22581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent    /**
22681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     * Creates a new Camera object to access the first back-facing camera on the
22781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     * device. If the device does not have a back-facing camera, this returns
22881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     * null.
22981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     * @see #open(int)
23081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     */
23181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent    public static Camera open() {
23281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent        int numberOfCameras = getNumberOfCameras();
23381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent        CameraInfo cameraInfo = new CameraInfo();
23481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent        for (int i = 0; i < numberOfCameras; i++) {
23581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent            getCameraInfo(i, cameraInfo);
23681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent            if (cameraInfo.facing == CameraInfo.CAMERA_FACING_BACK) {
23781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent                return new Camera(i);
23881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent            }
23981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent        }
240f6870aefc5e31d4220f3778c4e79ff34a61f48adEric Laurent        return null;
241f6870aefc5e31d4220f3778c4e79ff34a61f48adEric Laurent    }
24281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent
24381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent    Camera(int cameraId) {
24481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent        mShutterCallback = null;
24581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent        mRawImageCallback = null;
24681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent        mJpegCallback = null;
247463be250de73907965faa6a216c00312bf81e049Andy Hung        mPreviewCallback = null;
24883b8808faad1e91690c64d7007348be8d9ebde73Eric Laurent        mPostviewCallback = null;
24981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent        mZoomListener = null;
2509b58f63e45ef2fdfb839b9b9bb3411d81eb96128Glenn Kasten
2519b58f63e45ef2fdfb839b9b9bb3411d81eb96128Glenn Kasten        Looper looper;
2524a8308b11b92e608cdaf29f73f7919e75706f9a2Glenn Kasten        if ((looper = Looper.myLooper()) != null) {
2534a8308b11b92e608cdaf29f73f7919e75706f9a2Glenn Kasten            mEventHandler = new EventHandler(this, looper);
2544a8308b11b92e608cdaf29f73f7919e75706f9a2Glenn Kasten        } else if ((looper = Looper.getMainLooper()) != null) {
2554a8308b11b92e608cdaf29f73f7919e75706f9a2Glenn Kasten            mEventHandler = new EventHandler(this, looper);
256bfb1b832079bbb9426f72f3863199a54aefd02daEric Laurent        } else {
25781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent            mEventHandler = null;
25881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent        }
25981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent
26081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent        native_setup(new WeakReference<Camera>(this), cameraId);
2611035194cee4fbd57e35ea15c56e66cd09b63d56eEric Laurent    }
2621035194cee4fbd57e35ea15c56e66cd09b63d56eEric Laurent
26381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent    protected void finalize() {
26481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent        native_release();
2657c1ec5f038e63a5eb8b04434577c25bc23f5f410Eric Laurent    }
2661035194cee4fbd57e35ea15c56e66cd09b63d56eEric Laurent
2671035194cee4fbd57e35ea15c56e66cd09b63d56eEric Laurent    private native final void native_setup(Object camera_this, int cameraId);
2681035194cee4fbd57e35ea15c56e66cd09b63d56eEric Laurent    private native final void native_release();
2691035194cee4fbd57e35ea15c56e66cd09b63d56eEric Laurent
2707c1ec5f038e63a5eb8b04434577c25bc23f5f410Eric Laurent
2717c1ec5f038e63a5eb8b04434577c25bc23f5f410Eric Laurent    /**
27283f042776b131b149f803fff6ab184ae2c4d98cdMikhail Naganov     * Disconnects and releases the Camera object resources.
27383f042776b131b149f803fff6ab184ae2c4d98cdMikhail Naganov     *
2741035194cee4fbd57e35ea15c56e66cd09b63d56eEric Laurent     * <p>You must call this as soon as you're done with the Camera object.</p>
2751c333e252cbca3337c1bedbc57a005f3b7d23fdbEric Laurent     */
2761c333e252cbca3337c1bedbc57a005f3b7d23fdbEric Laurent    public final void release() {
2771c333e252cbca3337c1bedbc57a005f3b7d23fdbEric Laurent        native_release();
278021cf9634ab09c0753a40b7c9ef4ba603be5c3daEric Laurent    }
2791035194cee4fbd57e35ea15c56e66cd09b63d56eEric Laurent
2801c333e252cbca3337c1bedbc57a005f3b7d23fdbEric Laurent    /**
2811c333e252cbca3337c1bedbc57a005f3b7d23fdbEric Laurent     * Unlocks the camera to allow another process to access it.
2821c333e252cbca3337c1bedbc57a005f3b7d23fdbEric Laurent     * Normally, the camera is locked to the process with an active Camera
28383b8808faad1e91690c64d7007348be8d9ebde73Eric Laurent     * object until {@link #release()} is called.  To allow rapid handoff
2841c333e252cbca3337c1bedbc57a005f3b7d23fdbEric Laurent     * between processes, you can call this method to release the camera
28581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     * temporarily for another process to use; once the other process is done
28681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     * you can call {@link #reconnect()} to reclaim the camera.
28781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     *
28881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     * <p>This must be done before calling
28981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     * {@link android.media.MediaRecorder#setCamera(Camera)}.
29081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     *
2911dc98674f701dada94143b4d31b7221c58346c6cMikhail Naganov     * <p>If you are not recording video, you probably do not need this method.
29281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     *
29381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     * @throws RuntimeException if the camera cannot be unlocked.
29481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     */
29581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent    public native final void unlock();
29681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent
297d848eb48c121c119e8ba7583efc75415fe102570Glenn Kasten    /**
29881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     * Re-locks the camera to prevent other processes from accessing it.
29981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     * Camera objects are locked by default unless {@link #unlock()} is
3000d5a2ed0a05a2bf337c68edb54f24c60e18032c1Eric Laurent     * called.  Normally {@link #reconnect()} is used instead.
3010d5a2ed0a05a2bf337c68edb54f24c60e18032c1Eric Laurent     *
30281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     * <p>If you are not recording video, you probably do not need this method.
30381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     *
30481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     * @throws RuntimeException if the camera cannot be re-locked (for
30581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     *     example, if the camera is still in use by another process).
30681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     */
3074c415062ad1bb53e9af8f644d8215837262b79bbEric Laurent    public native final void lock();
30881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent
3094c415062ad1bb53e9af8f644d8215837262b79bbEric Laurent    /**
3104c415062ad1bb53e9af8f644d8215837262b79bbEric Laurent     * Reconnects to the camera service after another process used it.
31181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     * After {@link #unlock()} is called, another process may use the
31281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     * camera; when the process is done, you must reconnect to the camera,
31381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     * which will re-acquire the lock and allow you to continue using the
314d848eb48c121c119e8ba7583efc75415fe102570Glenn Kasten     * camera.
31581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     *
316d848eb48c121c119e8ba7583efc75415fe102570Glenn Kasten     * <p>This must be done after {@link android.media.MediaRecorder} is
31781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     * done recording if {@link android.media.MediaRecorder#setCamera(Camera)}
31881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     * was used.
31981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     *
32081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     * <p>If you are not recording video, you probably do not need this method.
32181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     *
32281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     * @throws IOException if a connection cannot be re-established (for
32381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     *     example, if the camera is still in use by another process).
32481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     */
32581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent    public native final void reconnect() throws IOException;
32681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent
32781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent    /**
328bfb1b832079bbb9426f72f3863199a54aefd02daEric Laurent     * Sets the {@link Surface} to be used for live preview.
329bfb1b832079bbb9426f72f3863199a54aefd02daEric Laurent     * Either a surface or surface texture is necessary for preview, and
33081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     * preview is necessary to take pictures.  The same surface can be re-set
33181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     * without harm.  Setting a preview surface will un-set any preview surface
33281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     * texture that was set via {@link #setPreviewTexture}.
333d848eb48c121c119e8ba7583efc75415fe102570Glenn Kasten     *
334d848eb48c121c119e8ba7583efc75415fe102570Glenn Kasten     * <p>The {@link SurfaceHolder} must already contain a surface when this
33581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     * method is called.  If you are using {@link android.view.SurfaceView},
33681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     * you will need to register a {@link SurfaceHolder.Callback} with
33781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     * {@link SurfaceHolder#addCallback(SurfaceHolder.Callback)} and wait for
33881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     * {@link SurfaceHolder.Callback#surfaceCreated(SurfaceHolder)} before
33981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     * calling setPreviewDisplay() or starting preview.
3400d5a2ed0a05a2bf337c68edb54f24c60e18032c1Eric Laurent     *
3410d5a2ed0a05a2bf337c68edb54f24c60e18032c1Eric Laurent     * <p>This method must be called before {@link #startPreview()}.  The
3420d5a2ed0a05a2bf337c68edb54f24c60e18032c1Eric Laurent     * one exception is that if the preview surface is not set (or set to null)
34381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     * before startPreview() is called, then this method may be called once
3440f11b51a57bc9062c4fe8af73747319cedabc5d6Glenn Kasten     * with a non-null parameter to set the preview surface.  (This allows
3454c415062ad1bb53e9af8f644d8215837262b79bbEric Laurent     * camera setup and surface creation to happen in parallel, saving time.)
3464c415062ad1bb53e9af8f644d8215837262b79bbEric Laurent     * The preview surface may not otherwise change while preview is running.
3474c415062ad1bb53e9af8f644d8215837262b79bbEric Laurent     *
3484c415062ad1bb53e9af8f644d8215837262b79bbEric Laurent     * @param holder containing the Surface on which to place the preview,
3494c415062ad1bb53e9af8f644d8215837262b79bbEric Laurent     *     or null to remove the preview surface
3504c415062ad1bb53e9af8f644d8215837262b79bbEric Laurent     * @throws IOException if the method fails (for example, if the surface
3514c415062ad1bb53e9af8f644d8215837262b79bbEric Laurent     *     is unavailable or unsuitable).
3524c415062ad1bb53e9af8f644d8215837262b79bbEric Laurent     */
3534c415062ad1bb53e9af8f644d8215837262b79bbEric Laurent    public final void setPreviewDisplay(SurfaceHolder holder) throws IOException {
3544c415062ad1bb53e9af8f644d8215837262b79bbEric Laurent        if (holder != null) {
35581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent            setPreviewDisplay(holder.getSurface());
35681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent        } else {
357d848eb48c121c119e8ba7583efc75415fe102570Glenn Kasten            setPreviewDisplay((Surface)null);
358d848eb48c121c119e8ba7583efc75415fe102570Glenn Kasten        }
35981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent    }
36081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent
36181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent    private native final void setPreviewDisplay(Surface surface) throws IOException;
36281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent
36381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent    /**
364d848eb48c121c119e8ba7583efc75415fe102570Glenn Kasten     * Sets the {@link SurfaceTexture} to be used for live preview.
36581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     * Either a surface or surface texture is necessary for preview, and
36681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     * preview is necessary to take pictures.  The same surface texture can be
36781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     * re-set without harm.  Setting a preview surface texture will un-set any
36881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     * preview surface that was set via {@link #setPreviewDisplay}.
369d848eb48c121c119e8ba7583efc75415fe102570Glenn Kasten     *
370d848eb48c121c119e8ba7583efc75415fe102570Glenn Kasten     * <p>This method must be called before {@link #startPreview()}.  The
37181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     * one exception is that if the preview surface texture is not set (or set
37281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     * to null) before startPreview() is called, then this method may be called
373d848eb48c121c119e8ba7583efc75415fe102570Glenn Kasten     * once with a non-null parameter to set the preview surface.  (This allows
374d848eb48c121c119e8ba7583efc75415fe102570Glenn Kasten     * camera setup and surface creation to happen in parallel, saving time.)
37581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     * The preview surface texture may not otherwise change while preview is
37681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     * running.
37781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     *
37881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     * The timestamps provided by {@link SurfaceTexture#getTimestamp()} for a
379b880f5e5fc07397ddd09a94ba18bdf4fa62aae00Glenn Kasten     * SurfaceTexture set as the preview texture have an unspecified zero point,
380b880f5e5fc07397ddd09a94ba18bdf4fa62aae00Glenn Kasten     * and cannot be directly compared between different cameras or different
381b880f5e5fc07397ddd09a94ba18bdf4fa62aae00Glenn Kasten     * instances of the same camera, or across multiple runs of the same
382b880f5e5fc07397ddd09a94ba18bdf4fa62aae00Glenn Kasten     * program.
383b880f5e5fc07397ddd09a94ba18bdf4fa62aae00Glenn Kasten     *
384b880f5e5fc07397ddd09a94ba18bdf4fa62aae00Glenn Kasten     * @param surfaceTexture the {@link SurfaceTexture} to which the preview
385b880f5e5fc07397ddd09a94ba18bdf4fa62aae00Glenn Kasten     *     images are to be sent or null to remove the current preview surface
38681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     *     texture
3876181ffd90a436f333c43a7f812391eee2c35005aGlenn Kasten     * @throws IOException if the method fails (for example, if the surface
3886181ffd90a436f333c43a7f812391eee2c35005aGlenn Kasten     *     texture is unavailable or unsuitable).
38972e3f39146fce4686bd96f11057c051bea376dfbEric Laurent     */
39072e3f39146fce4686bd96f11057c051bea376dfbEric Laurent    public native final void setPreviewTexture(SurfaceTexture surfaceTexture) throws IOException;
3914c415062ad1bb53e9af8f644d8215837262b79bbEric Laurent
3924c415062ad1bb53e9af8f644d8215837262b79bbEric Laurent    /**
3934c415062ad1bb53e9af8f644d8215837262b79bbEric Laurent     * Callback interface used to deliver copies of preview frames as
3944c415062ad1bb53e9af8f644d8215837262b79bbEric Laurent     * they are displayed.
39581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     *
39681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     * @see #setPreviewCallback(Camera.PreviewCallback)
39781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     * @see #setOneShotPreviewCallback(Camera.PreviewCallback)
39881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     * @see #setPreviewCallbackWithBuffer(Camera.PreviewCallback)
39981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     * @see #startPreview()
40081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     */
40181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent    public interface PreviewCallback
40281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent    {
40381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent        /**
40481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent         * Called as preview frames are displayed.  This callback is invoked
40581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent         * on the event thread {@link #open(int)} was called from.
40681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent         *
40781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent         * @param data the contents of the preview frame in the format defined
408dae27707fc7d8370eb200d25d1a7c6dd7ad5e201Andy Hung         *  by {@link android.graphics.ImageFormat}, which can be queried
409dae27707fc7d8370eb200d25d1a7c6dd7ad5e201Andy Hung         *  with {@link android.hardware.Camera.Parameters#getPreviewFormat()}.
41081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent         *  If {@link android.hardware.Camera.Parameters#setPreviewFormat(int)}
41181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent         *             is never called, the default will be the YCbCr_420_SP
412d01b0f18491c355d808a57cb272404480e69618fAndy Hung         *             (NV21) format.
413462fd2fa9eef642b0574aa7409de0bde3fec8d43Marco Nelissen         * @param camera the Camera service object.
41481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent         */
41581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent        void onPreviewFrame(byte[] data, Camera camera);
416d848eb48c121c119e8ba7583efc75415fe102570Glenn Kasten    };
41781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent
41881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent    /**
41981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     * Starts capturing and drawing preview frames to the screen.
420d848eb48c121c119e8ba7583efc75415fe102570Glenn Kasten     * Preview will not actually start until a surface is supplied
42181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     * with {@link #setPreviewDisplay(SurfaceHolder)} or
42281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     * {@link #setPreviewTexture(SurfaceTexture)}.
42381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     *
424014e7fa2e90827d911c37bb0ce4d2e10e14d0bb3Narayan Kamath     * <p>If {@link #setPreviewCallback(Camera.PreviewCallback)},
425014e7fa2e90827d911c37bb0ce4d2e10e14d0bb3Narayan Kamath     * {@link #setOneShotPreviewCallback(Camera.PreviewCallback)}, or
42681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     * {@link #setPreviewCallbackWithBuffer(Camera.PreviewCallback)} were
4272ddee19245641e86bca436dda23a0f5089bf2ab5Andy Hung     * called, {@link Camera.PreviewCallback#onPreviewFrame(byte[], Camera)}
4282ddee19245641e86bca436dda23a0f5089bf2ab5Andy Hung     * will be called when preview data becomes available.
42981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     */
43081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent    public native final void startPreview();
43181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent
43281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent    /**
43381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     * Stops capturing and drawing preview frames to the surface, and
43481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     * resets the camera for a future call to {@link #startPreview()}.
43581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     */
43681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent    public native final void stopPreview();
43781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent
4389b58f63e45ef2fdfb839b9b9bb3411d81eb96128Glenn Kasten    /**
439deca2ae0a7cf8bc54ff3f30b7dc39bbc78b94c0dGlenn Kasten     * Return current preview state.
440deca2ae0a7cf8bc54ff3f30b7dc39bbc78b94c0dGlenn Kasten     *
44181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     * FIXME: Unhide before release
44281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     * @hide
44381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     */
444f6ed423af92a56ef54bba23eba883b1f21448b54Glenn Kasten    public native final boolean previewEnabled();
44581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent
44697b7b75b6a31330e213bdb96ccc60916218ad903Glenn Kasten    /**
447463be250de73907965faa6a216c00312bf81e049Andy Hung     * Installs a callback to be invoked for every preview frame in addition
448463be250de73907965faa6a216c00312bf81e049Andy Hung     * to displaying them on the screen.  The callback will be repeatedly called
449463be250de73907965faa6a216c00312bf81e049Andy Hung     * for as long as preview is active.  This method can be called at any time,
450463be250de73907965faa6a216c00312bf81e049Andy Hung     * even while preview is live.  Any other preview callbacks are overridden.
451463be250de73907965faa6a216c00312bf81e049Andy Hung     *
45270949c47fbae3f836d15f040551d7631be3ed7c2Glenn Kasten     * @param cb a callback object that receives a copy of each preview frame,
45381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     *     or null to stop receiving callbacks.
4541035194cee4fbd57e35ea15c56e66cd09b63d56eEric Laurent     */
45572e3f39146fce4686bd96f11057c051bea376dfbEric Laurent    public final void setPreviewCallback(PreviewCallback cb) {
45681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent        mPreviewCallback = cb;
45781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent        mOneShot = false;
4584944acb7355b3aa25748fd25945a363a69d65444Glenn Kasten        mWithBuffer = false;
45981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent        // Always use one-shot mode. We fake camera preview mode by
46081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent        // doing one-shot preview continuously.
46181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent        setHasPreviewCallback(cb != null, false);
46281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent    }
4634944acb7355b3aa25748fd25945a363a69d65444Glenn Kasten
46481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent    /**
46581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     * Installs a callback to be invoked for the next preview frame in addition
4667c1ec5f038e63a5eb8b04434577c25bc23f5f410Eric Laurent     * to displaying it on the screen.  After one invocation, the callback is
467e8726fea8a53bf3474aa3c6deaf2f6c1f565e694Eric Laurent     * cleared. This method can be called any time, even when preview is live.
468296fb13dd9b5e90d6a05cce897c3b1e7914a478aEric Laurent     * Any other preview callbacks are overridden.
469f59497bd3c190e087202043de5450ef06e92b27dGlenn Kasten     *
47081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     * @param cb a callback object that receives a copy of the next preview frame,
47181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     *     or null to stop receiving callbacks.
47281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     */
47381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent    public final void setOneShotPreviewCallback(PreviewCallback cb) {
474d7dca050c630bddbd73a6623271b34b4290460eeGlenn Kasten        mPreviewCallback = cb;
475d7dca050c630bddbd73a6623271b34b4290460eeGlenn Kasten        mOneShot = true;
47681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent        mWithBuffer = false;
47781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent        setHasPreviewCallback(cb != null, false);
47881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent    }
479d848eb48c121c119e8ba7583efc75415fe102570Glenn Kasten
480d848eb48c121c119e8ba7583efc75415fe102570Glenn Kasten    private native final void setHasPreviewCallback(boolean installed, boolean manualBuffer);
481d848eb48c121c119e8ba7583efc75415fe102570Glenn Kasten
48281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent    /**
483ab7d72f0804fbb7e91ad9d2a16f826d97e20e5d0Glenn Kasten     * Installs a callback to be invoked for every preview frame, using buffers
4849e58b552f51b00b3b674102876bd6c77ef3da806Glenn Kasten     * supplied with {@link #addCallbackBuffer(byte[])}, in addition to
48572e3f39146fce4686bd96f11057c051bea376dfbEric Laurent     * displaying them on the screen.  The callback will be repeatedly called
486818e7a32ce3633980138aff2c2bfcc5158b3cfccAndy Hung     * for as long as preview is active and buffers are available.
487dae27707fc7d8370eb200d25d1a7c6dd7ad5e201Andy Hung     * Any other preview callbacks are overridden.
488dae27707fc7d8370eb200d25d1a7c6dd7ad5e201Andy Hung     *
489dae27707fc7d8370eb200d25d1a7c6dd7ad5e201Andy Hung     * <p>The purpose of this method is to improve preview efficiency and frame
490dae27707fc7d8370eb200d25d1a7c6dd7ad5e201Andy Hung     * rate by allowing preview frame memory reuse.  You must call
491dae27707fc7d8370eb200d25d1a7c6dd7ad5e201Andy Hung     * {@link #addCallbackBuffer(byte[])} at some point -- before or after
492dae27707fc7d8370eb200d25d1a7c6dd7ad5e201Andy Hung     * calling this method -- or no callbacks will received.
493dae27707fc7d8370eb200d25d1a7c6dd7ad5e201Andy Hung     *
494dae27707fc7d8370eb200d25d1a7c6dd7ad5e201Andy Hung     * The buffer queue will be cleared if this method is called with a null
495dae27707fc7d8370eb200d25d1a7c6dd7ad5e201Andy Hung     * callback, {@link #setPreviewCallback(Camera.PreviewCallback)} is called,
496dae27707fc7d8370eb200d25d1a7c6dd7ad5e201Andy Hung     * or {@link #setOneShotPreviewCallback(Camera.PreviewCallback)} is called.
497dae27707fc7d8370eb200d25d1a7c6dd7ad5e201Andy Hung     *
498dae27707fc7d8370eb200d25d1a7c6dd7ad5e201Andy Hung     * @param cb a callback object that receives a copy of the preview frame,
499dae27707fc7d8370eb200d25d1a7c6dd7ad5e201Andy Hung     *     or null to stop receiving callbacks and clear the buffer queue.
500dae27707fc7d8370eb200d25d1a7c6dd7ad5e201Andy Hung     * @see #addCallbackBuffer(byte[])
501dae27707fc7d8370eb200d25d1a7c6dd7ad5e201Andy Hung     */
502dae27707fc7d8370eb200d25d1a7c6dd7ad5e201Andy Hung    public final void setPreviewCallbackWithBuffer(PreviewCallback cb) {
503dae27707fc7d8370eb200d25d1a7c6dd7ad5e201Andy Hung        mPreviewCallback = cb;
504dae27707fc7d8370eb200d25d1a7c6dd7ad5e201Andy Hung        mOneShot = false;
505dae27707fc7d8370eb200d25d1a7c6dd7ad5e201Andy Hung        mWithBuffer = true;
506dae27707fc7d8370eb200d25d1a7c6dd7ad5e201Andy Hung        setHasPreviewCallback(cb != null, true);
507dae27707fc7d8370eb200d25d1a7c6dd7ad5e201Andy Hung    }
508dae27707fc7d8370eb200d25d1a7c6dd7ad5e201Andy Hung
509dae27707fc7d8370eb200d25d1a7c6dd7ad5e201Andy Hung    /**
510dae27707fc7d8370eb200d25d1a7c6dd7ad5e201Andy Hung     * Adds a pre-allocated buffer to the preview callback buffer queue.
511dae27707fc7d8370eb200d25d1a7c6dd7ad5e201Andy Hung     * Applications can add one or more buffers to the queue. When a preview
512dae27707fc7d8370eb200d25d1a7c6dd7ad5e201Andy Hung     * frame arrives and there is still at least one available buffer, the
513dae27707fc7d8370eb200d25d1a7c6dd7ad5e201Andy Hung     * buffer will be used and removed from the queue. Then preview callback is
514dae27707fc7d8370eb200d25d1a7c6dd7ad5e201Andy Hung     * invoked with the buffer. If a frame arrives and there is no buffer left,
515dae27707fc7d8370eb200d25d1a7c6dd7ad5e201Andy Hung     * the frame is discarded. Applications should add buffers back when they
516dae27707fc7d8370eb200d25d1a7c6dd7ad5e201Andy Hung     * finish processing the data in them.
517dae27707fc7d8370eb200d25d1a7c6dd7ad5e201Andy Hung     *
518dae27707fc7d8370eb200d25d1a7c6dd7ad5e201Andy Hung     * <p>The size of the buffer is determined by multiplying the preview
519dae27707fc7d8370eb200d25d1a7c6dd7ad5e201Andy Hung     * image width, height, and bytes per pixel. The width and height can be
520dae27707fc7d8370eb200d25d1a7c6dd7ad5e201Andy Hung     * read from {@link Camera.Parameters#getPreviewSize()}. Bytes per pixel
521dae27707fc7d8370eb200d25d1a7c6dd7ad5e201Andy Hung     * can be computed from
522dae27707fc7d8370eb200d25d1a7c6dd7ad5e201Andy Hung     * {@link android.graphics.ImageFormat#getBitsPerPixel(int)} / 8,
523dae27707fc7d8370eb200d25d1a7c6dd7ad5e201Andy Hung     * using the image format from {@link Camera.Parameters#getPreviewFormat()}.
524dae27707fc7d8370eb200d25d1a7c6dd7ad5e201Andy Hung     *
525dae27707fc7d8370eb200d25d1a7c6dd7ad5e201Andy Hung     * <p>This method is only necessary when
526dae27707fc7d8370eb200d25d1a7c6dd7ad5e201Andy Hung     * {@link #setPreviewCallbackWithBuffer(PreviewCallback)} is used. When
527dae27707fc7d8370eb200d25d1a7c6dd7ad5e201Andy Hung     * {@link #setPreviewCallback(PreviewCallback)} or
528dae27707fc7d8370eb200d25d1a7c6dd7ad5e201Andy Hung     * {@link #setOneShotPreviewCallback(PreviewCallback)} are used, buffers
529dae27707fc7d8370eb200d25d1a7c6dd7ad5e201Andy Hung     * are automatically allocated. When a supplied buffer is too small to
530dae27707fc7d8370eb200d25d1a7c6dd7ad5e201Andy Hung     * hold the preview frame data, preview callback will return null and
531dae27707fc7d8370eb200d25d1a7c6dd7ad5e201Andy Hung     * the buffer will be removed from the buffer queue.
532dae27707fc7d8370eb200d25d1a7c6dd7ad5e201Andy Hung     *
533dae27707fc7d8370eb200d25d1a7c6dd7ad5e201Andy Hung     * @param callbackBuffer the buffer to add to the queue.
534dae27707fc7d8370eb200d25d1a7c6dd7ad5e201Andy Hung     *     The size should be width * height * bits_per_pixel / 8.
535dae27707fc7d8370eb200d25d1a7c6dd7ad5e201Andy Hung     * @see #setPreviewCallbackWithBuffer(PreviewCallback)
536dae27707fc7d8370eb200d25d1a7c6dd7ad5e201Andy Hung     */
537dae27707fc7d8370eb200d25d1a7c6dd7ad5e201Andy Hung    public final void addCallbackBuffer(byte[] callbackBuffer)
538dae27707fc7d8370eb200d25d1a7c6dd7ad5e201Andy Hung    {
539dae27707fc7d8370eb200d25d1a7c6dd7ad5e201Andy Hung        _addCallbackBuffer(callbackBuffer, CAMERA_MSG_PREVIEW_FRAME);
540dae27707fc7d8370eb200d25d1a7c6dd7ad5e201Andy Hung    }
541dae27707fc7d8370eb200d25d1a7c6dd7ad5e201Andy Hung
542dae27707fc7d8370eb200d25d1a7c6dd7ad5e201Andy Hung    /**
543dae27707fc7d8370eb200d25d1a7c6dd7ad5e201Andy Hung     * Adds a pre-allocated buffer to the raw image callback buffer queue.
544dae27707fc7d8370eb200d25d1a7c6dd7ad5e201Andy Hung     * Applications can add one or more buffers to the queue. When a raw image
545dae27707fc7d8370eb200d25d1a7c6dd7ad5e201Andy Hung     * frame arrives and there is still at least one available buffer, the
546dae27707fc7d8370eb200d25d1a7c6dd7ad5e201Andy Hung     * buffer will be used to hold the raw image data and removed from the
547dae27707fc7d8370eb200d25d1a7c6dd7ad5e201Andy Hung     * queue. Then raw image callback is invoked with the buffer. If a raw
548dae27707fc7d8370eb200d25d1a7c6dd7ad5e201Andy Hung     * image frame arrives but there is no buffer left, the frame is
549dae27707fc7d8370eb200d25d1a7c6dd7ad5e201Andy Hung     * discarded. Applications should add buffers back when they finish
550dae27707fc7d8370eb200d25d1a7c6dd7ad5e201Andy Hung     * processing the data in them by calling this method again in order
551dae27707fc7d8370eb200d25d1a7c6dd7ad5e201Andy Hung     * to avoid running out of raw image callback buffers.
552dae27707fc7d8370eb200d25d1a7c6dd7ad5e201Andy Hung     *
553dae27707fc7d8370eb200d25d1a7c6dd7ad5e201Andy Hung     * <p>The size of the buffer is determined by multiplying the raw image
554dae27707fc7d8370eb200d25d1a7c6dd7ad5e201Andy Hung     * width, height, and bytes per pixel. The width and height can be
555dae27707fc7d8370eb200d25d1a7c6dd7ad5e201Andy Hung     * read from {@link Camera.Parameters#getPictureSize()}. Bytes per pixel
556dae27707fc7d8370eb200d25d1a7c6dd7ad5e201Andy Hung     * can be computed from
557d01b0f18491c355d808a57cb272404480e69618fAndy Hung     * {@link android.graphics.ImageFormat#getBitsPerPixel(int)} / 8,
558d01b0f18491c355d808a57cb272404480e69618fAndy Hung     * using the image format from {@link Camera.Parameters#getPreviewFormat()}.
559dae27707fc7d8370eb200d25d1a7c6dd7ad5e201Andy Hung     *
560dae27707fc7d8370eb200d25d1a7c6dd7ad5e201Andy Hung     * <p>This method is only necessary when the PictureCallbck for raw image
561dae27707fc7d8370eb200d25d1a7c6dd7ad5e201Andy Hung     * is used while calling {@link #takePicture(Camera.ShutterCallback,
562dae27707fc7d8370eb200d25d1a7c6dd7ad5e201Andy Hung     * Camera.PictureCallback, Camera.PictureCallback, Camera.PictureCallback)}.
563dae27707fc7d8370eb200d25d1a7c6dd7ad5e201Andy Hung     *
564dae27707fc7d8370eb200d25d1a7c6dd7ad5e201Andy Hung     * Please note that by calling this method, the mode for application-managed
565dae27707fc7d8370eb200d25d1a7c6dd7ad5e201Andy Hung     * callback buffers is triggered. If this method has never been called,
566dae27707fc7d8370eb200d25d1a7c6dd7ad5e201Andy Hung     * null will be returned by the raw image callback since there is
567dae27707fc7d8370eb200d25d1a7c6dd7ad5e201Andy Hung     * no image callback buffer available. Furthermore, When a supplied buffer
568dae27707fc7d8370eb200d25d1a7c6dd7ad5e201Andy Hung     * is too small to hold the raw image data, raw image callback will return
569dae27707fc7d8370eb200d25d1a7c6dd7ad5e201Andy Hung     * null and the buffer will be removed from the buffer queue.
570dae27707fc7d8370eb200d25d1a7c6dd7ad5e201Andy Hung     *
571dae27707fc7d8370eb200d25d1a7c6dd7ad5e201Andy Hung     * @param callbackBuffer the buffer to add to the raw image callback buffer
57281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     *     queue. The size should be width * height * (bits per pixel) / 8. An
57381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     *     null callbackBuffer will be ignored and won't be added to the queue.
57481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     *
5751dc98674f701dada94143b4d31b7221c58346c6cMikhail Naganov     * @see #takePicture(Camera.ShutterCallback,
57681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     * Camera.PictureCallback, Camera.PictureCallback, Camera.PictureCallback)}.
57781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     *
57881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     * {@hide}
57981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     */
58081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent    public final void addRawImageCallbackBuffer(byte[] callbackBuffer)
58181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent    {
58281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent        addCallbackBuffer(callbackBuffer, CAMERA_MSG_RAW_IMAGE);
583bfb1b832079bbb9426f72f3863199a54aefd02daEric Laurent    }
584bfb1b832079bbb9426f72f3863199a54aefd02daEric Laurent
585bfb1b832079bbb9426f72f3863199a54aefd02daEric Laurent    private final void addCallbackBuffer(byte[] callbackBuffer, int msgType)
58681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent    {
58781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent        // CAMERA_MSG_VIDEO_FRAME may be allowed in the future.
58881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent        if (msgType != CAMERA_MSG_PREVIEW_FRAME &&
58981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent            msgType != CAMERA_MSG_RAW_IMAGE) {
590e93cc03da360a1a0d2ad937c745ce8c8e8be81c2Eric Laurent            throw new IllegalArgumentException(
591e93cc03da360a1a0d2ad937c745ce8c8e8be81c2Eric Laurent                            "Unsupported message type: " + msgType);
592e93cc03da360a1a0d2ad937c745ce8c8e8be81c2Eric Laurent        }
593e93cc03da360a1a0d2ad937c745ce8c8e8be81c2Eric Laurent
594e93cc03da360a1a0d2ad937c745ce8c8e8be81c2Eric Laurent        _addCallbackBuffer(callbackBuffer, msgType);
595e93cc03da360a1a0d2ad937c745ce8c8e8be81c2Eric Laurent    }
596e93cc03da360a1a0d2ad937c745ce8c8e8be81c2Eric Laurent
597ad7dd9610b6fafa81baf69607f4ac669da88182aEric Laurent    private native final void _addCallbackBuffer(
598ad7dd9610b6fafa81baf69607f4ac669da88182aEric Laurent                                byte[] callbackBuffer, int msgType);
599e93cc03da360a1a0d2ad937c745ce8c8e8be81c2Eric Laurent
60081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent    private class EventHandler extends Handler
601e93cc03da360a1a0d2ad937c745ce8c8e8be81c2Eric Laurent    {
60281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent        private Camera mCamera;
60381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent
60481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent        public EventHandler(Camera c, Looper looper) {
60581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent            super(looper);
60681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent            mCamera = c;
60781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent        }
60881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent
60981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent        @Override
61081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent        public void handleMessage(Message msg) {
61181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent            switch(msg.what) {
6124c415062ad1bb53e9af8f644d8215837262b79bbEric Laurent            case CAMERA_MSG_SHUTTER:
6134c415062ad1bb53e9af8f644d8215837262b79bbEric Laurent                if (mShutterCallback != null) {
6144c415062ad1bb53e9af8f644d8215837262b79bbEric Laurent                    mShutterCallback.onShutter();
61581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent                }
61681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent                return;
61781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent
61881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent            case CAMERA_MSG_RAW_IMAGE:
619bfb1b832079bbb9426f72f3863199a54aefd02daEric Laurent                if (mRawImageCallback != null) {
620bfb1b832079bbb9426f72f3863199a54aefd02daEric Laurent                    mRawImageCallback.onPictureTaken((byte[])msg.obj, mCamera);
62181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent                }
622bfb1b832079bbb9426f72f3863199a54aefd02daEric Laurent                return;
62381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent
62481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent            case CAMERA_MSG_COMPRESSED_IMAGE:
62581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent                if (mJpegCallback != null) {
62681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent                    mJpegCallback.onPictureTaken((byte[])msg.obj, mCamera);
62781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent                }
62881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent                return;
62981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent
630bfb1b832079bbb9426f72f3863199a54aefd02daEric Laurent            case CAMERA_MSG_PREVIEW_FRAME:
631bfb1b832079bbb9426f72f3863199a54aefd02daEric Laurent                if (mPreviewCallback != null) {
6321dc98674f701dada94143b4d31b7221c58346c6cMikhail Naganov                    PreviewCallback cb = mPreviewCallback;
6331dc98674f701dada94143b4d31b7221c58346c6cMikhail Naganov                    if (mOneShot) {
6341dc98674f701dada94143b4d31b7221c58346c6cMikhail Naganov                        // Clear the callback variable before the callback
6351dc98674f701dada94143b4d31b7221c58346c6cMikhail Naganov                        // in case the app calls setPreviewCallback from
6361dc98674f701dada94143b4d31b7221c58346c6cMikhail Naganov                        // the callback function
6373b4529e03c5fc7a44c22f9091ad15a269bfca3a8Eric Laurent                        mPreviewCallback = null;
6383b4529e03c5fc7a44c22f9091ad15a269bfca3a8Eric Laurent                    } else if (!mWithBuffer) {
639bfb1b832079bbb9426f72f3863199a54aefd02daEric Laurent                        // We're faking the camera preview mode to prevent
640bfb1b832079bbb9426f72f3863199a54aefd02daEric Laurent                        // the app from being flooded with preview frames.
641bfb1b832079bbb9426f72f3863199a54aefd02daEric Laurent                        // Set to oneshot mode again.
642bfb1b832079bbb9426f72f3863199a54aefd02daEric Laurent                        setHasPreviewCallback(true, false);
6434c6a433d74d5ae8b9bc0557207e3ced43bf34a25Haynes Mathew George                    }
6444527b9ebc6a37b861f5a3bba68bcc63dc8d69adaHaynes Mathew George                    cb.onPreviewFrame((byte[])msg.obj, mCamera);
64581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent                }
64681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent                return;
64781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent
64881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent            case CAMERA_MSG_POSTVIEW_FRAME:
649646679779a8f952980a5d4219ad9c6f93efc4b92Eric Laurent                if (mPostviewCallback != null) {
650dae27707fc7d8370eb200d25d1a7c6dd7ad5e201Andy Hung                    mPostviewCallback.onPictureTaken((byte[])msg.obj, mCamera);
651dae27707fc7d8370eb200d25d1a7c6dd7ad5e201Andy Hung                }
652dae27707fc7d8370eb200d25d1a7c6dd7ad5e201Andy Hung                return;
653dae27707fc7d8370eb200d25d1a7c6dd7ad5e201Andy Hung
654646679779a8f952980a5d4219ad9c6f93efc4b92Eric Laurent            case CAMERA_MSG_FOCUS:
65581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent                if (mAutoFocusCallback != null) {
65681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent                    mAutoFocusCallback.onAutoFocus(msg.arg1 == 0 ? false : true, mCamera);
65781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent                }
65881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent                return;
65981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent
66081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent            case CAMERA_MSG_ZOOM:
66181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent                if (mZoomListener != null) {
66281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent                    mZoomListener.onZoomChange(msg.arg1, msg.arg2 != 0, mCamera);
66381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent                }
66481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent                return;
66581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent
66681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent            case CAMERA_MSG_ERROR :
66781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent                Log.e(TAG, "Error " + msg.arg1);
66881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent                if (mErrorCallback != null) {
66981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent                    mErrorCallback.onError(msg.arg1, mCamera);
67081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent                }
67181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent                return;
67281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent
67381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent            default:
67481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent                Log.e(TAG, "Unknown message type " + msg.what);
67581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent                return;
67681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent            }
67781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent        }
67874935e44734c1ec235c2b6677db3e0dbefa5ddb8Glenn Kasten    }
67981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent
680d848eb48c121c119e8ba7583efc75415fe102570Glenn Kasten    private static void postEventFromNative(Object camera_ref,
681050677873c10d4da308ac222f8533c96cca3207eEric Laurent                                            int what, int arg1, int arg2, Object obj)
68281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent    {
6831f12a8ad958344c50733b948628ffa06db9c5bc6Andy Hung        Camera c = (Camera)((WeakReference)camera_ref).get();
68420b9ef0b55c9150ae11057ab997ae61be2d496efEric Laurent        if (c == null)
68520b9ef0b55c9150ae11057ab997ae61be2d496efEric Laurent            return;
68681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent
68781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent        if (c.mEventHandler != null) {
68881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent            Message m = c.mEventHandler.obtainMessage(what, arg1, arg2, obj);
6891dc98674f701dada94143b4d31b7221c58346c6cMikhail Naganov            c.mEventHandler.sendMessage(m);
69081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent        }
69181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent    }
69281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent
69381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent    /**
69481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     * Callback interface used to notify on completion of camera auto focus.
69581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     *
69681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     * <p>Devices that do not support auto-focus will receive a "fake"
69781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     * callback to this interface. If your application needs auto-focus and
69881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     * should not be installed on devices <em>without</em> auto-focus, you must
69981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     * declare that your app uses the
70081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     * {@code android.hardware.camera.autofocus} feature, in the
70181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     * <a href="{@docRoot}guide/topics/manifest/uses-feature-element.html">&lt;uses-feature></a>
70281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     * manifest element.</p>
70381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     *
70481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     * @see #autoFocus(AutoFocusCallback)
7057c1ec5f038e63a5eb8b04434577c25bc23f5f410Eric Laurent     */
706377b2ec9a2885f9b6405b07ba900a9e3f4349c38Kévin PETIT    public interface AutoFocusCallback
707010a1a1a552cdaad362cea8a0333b8906402dbcbAndy Hung    {
708010a1a1a552cdaad362cea8a0333b8906402dbcbAndy Hung        /**
709010a1a1a552cdaad362cea8a0333b8906402dbcbAndy Hung         * Called when the camera auto focus completes.  If the camera
710010a1a1a552cdaad362cea8a0333b8906402dbcbAndy Hung         * does not support auto-focus and autoFocus is called,
711010a1a1a552cdaad362cea8a0333b8906402dbcbAndy Hung         * onAutoFocus will be called immediately with a fake value of
71281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent         * <code>success</code> set to <code>true</code>.
71381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent         *
714e964d4e421e2d1ca937227a580c0c837091a11e3Chih-Hung Hsieh         * @param success true if focus was successful, false if otherwise
71581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent         * @param camera  the Camera service object
716e964d4e421e2d1ca937227a580c0c837091a11e3Chih-Hung Hsieh         */
71781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent        void onAutoFocus(boolean success, Camera camera);
71881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent    };
71981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent
72081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent    /**
7214c415062ad1bb53e9af8f644d8215837262b79bbEric Laurent     * Starts camera auto-focus and registers a callback function to run when
722d848eb48c121c119e8ba7583efc75415fe102570Glenn Kasten     * the camera is focused.  This method is only valid when preview is active
72381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     * (between {@link #startPreview()} and before {@link #stopPreview()}).
72481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     *
72581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     * <p>Callers should check
72681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     * {@link android.hardware.Camera.Parameters#getFocusMode()} to determine if
727fb1fdc9d6603aa228362e7349451f6455c9849c2Glenn Kasten     * this method should be called. If the camera does not support auto-focus,
728fb1fdc9d6603aa228362e7349451f6455c9849c2Glenn Kasten     * it is a no-op and {@link AutoFocusCallback#onAutoFocus(boolean, Camera)}
72913084621072ea2e4c34e2a9d79793c621d9bf005Eric Laurent     * callback will be called immediately.
73005317d29b27e5fda654bea21b80d4423a03f49b3Haynes Mathew George     *
73181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     * <p>If your application should not be installed
7329b58f63e45ef2fdfb839b9b9bb3411d81eb96128Glenn Kasten     * on devices without auto-focus, you must declare that your application
7339b58f63e45ef2fdfb839b9b9bb3411d81eb96128Glenn Kasten     * uses auto-focus with the
73483b8808faad1e91690c64d7007348be8d9ebde73Eric Laurent     * <a href="{@docRoot}guide/topics/manifest/uses-feature-element.html">&lt;uses-feature></a>
73583b8808faad1e91690c64d7007348be8d9ebde73Eric Laurent     * manifest element.</p>
73683b8808faad1e91690c64d7007348be8d9ebde73Eric Laurent     *
73783b8808faad1e91690c64d7007348be8d9ebde73Eric Laurent     * <p>If the current flash mode is not
73883b8808faad1e91690c64d7007348be8d9ebde73Eric Laurent     * {@link android.hardware.Camera.Parameters#FLASH_MODE_OFF}, flash may be
73983b8808faad1e91690c64d7007348be8d9ebde73Eric Laurent     * fired during auto-focus, depending on the driver and camera hardware.<p>
740accc147666bfd37fc8b4ef745f18a8c751555ec2Eric Laurent     *
74181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     * @param cb the callback to run
742deca2ae0a7cf8bc54ff3f30b7dc39bbc78b94c0dGlenn Kasten     * @see #cancelAutoFocus()
7439b58f63e45ef2fdfb839b9b9bb3411d81eb96128Glenn Kasten     */
7449b58f63e45ef2fdfb839b9b9bb3411d81eb96128Glenn Kasten    public final void autoFocus(AutoFocusCallback cb)
74508fb1743f80437c38b4094070d851ea7f6d485e5Andy Hung    {
74640eb1a1f8871909c272e72afaf7d5af84fea2412Andy Hung        mAutoFocusCallback = cb;
74740eb1a1f8871909c272e72afaf7d5af84fea2412Andy Hung        native_autoFocus();
74808fb1743f80437c38b4094070d851ea7f6d485e5Andy Hung    }
74908fb1743f80437c38b4094070d851ea7f6d485e5Andy Hung    private native final void native_autoFocus();
750010a1a1a552cdaad362cea8a0333b8906402dbcbAndy Hung
75181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent    /**
75298ef978df4e928f486d244c4d7f7ad9f13111e98Andy Hung     * Cancels any auto-focus function in progress.
75398ef978df4e928f486d244c4d7f7ad9f13111e98Andy Hung     * Whether or not auto-focus is currently in progress,
75498ef978df4e928f486d244c4d7f7ad9f13111e98Andy Hung     * this function will return the focus position to the default.
75598ef978df4e928f486d244c4d7f7ad9f13111e98Andy Hung     * If the camera does not support auto-focus, this is a no-op.
75698ef978df4e928f486d244c4d7f7ad9f13111e98Andy Hung     *
75798ef978df4e928f486d244c4d7f7ad9f13111e98Andy Hung     * @see #autoFocus(Camera.AutoFocusCallback)
75898ef978df4e928f486d244c4d7f7ad9f13111e98Andy Hung     */
75998ef978df4e928f486d244c4d7f7ad9f13111e98Andy Hung    public final void cancelAutoFocus()
76098ef978df4e928f486d244c4d7f7ad9f13111e98Andy Hung    {
76169aed5f0f4a3be3996d1e78a0473e1a72c1547daAndy Hung        mAutoFocusCallback = null;
76269aed5f0f4a3be3996d1e78a0473e1a72c1547daAndy Hung        native_cancelAutoFocus();
76369aed5f0f4a3be3996d1e78a0473e1a72c1547daAndy Hung    }
76469aed5f0f4a3be3996d1e78a0473e1a72c1547daAndy Hung    private native final void native_cancelAutoFocus();
76569aed5f0f4a3be3996d1e78a0473e1a72c1547daAndy Hung
76669aed5f0f4a3be3996d1e78a0473e1a72c1547daAndy Hung    /**
76769aed5f0f4a3be3996d1e78a0473e1a72c1547daAndy Hung     * Callback interface used to signal the moment of actual image capture.
76869aed5f0f4a3be3996d1e78a0473e1a72c1547daAndy Hung     *
76969aed5f0f4a3be3996d1e78a0473e1a72c1547daAndy Hung     * @see #takePicture(ShutterCallback, PictureCallback, PictureCallback, PictureCallback)
77069aed5f0f4a3be3996d1e78a0473e1a72c1547daAndy Hung     */
77169aed5f0f4a3be3996d1e78a0473e1a72c1547daAndy Hung    public interface ShutterCallback
77269aed5f0f4a3be3996d1e78a0473e1a72c1547daAndy Hung    {
77369aed5f0f4a3be3996d1e78a0473e1a72c1547daAndy Hung        /**
77469aed5f0f4a3be3996d1e78a0473e1a72c1547daAndy Hung         * Called as near as possible to the moment when a photo is captured
77569aed5f0f4a3be3996d1e78a0473e1a72c1547daAndy Hung         * from the sensor.  This is a good opportunity to play a shutter sound
77669aed5f0f4a3be3996d1e78a0473e1a72c1547daAndy Hung         * or give other feedback of camera operation.  This may be some time
77769aed5f0f4a3be3996d1e78a0473e1a72c1547daAndy Hung         * after the photo was triggered, but some time before the actual data
77869aed5f0f4a3be3996d1e78a0473e1a72c1547daAndy Hung         * is available.
77969aed5f0f4a3be3996d1e78a0473e1a72c1547daAndy Hung         */
78069aed5f0f4a3be3996d1e78a0473e1a72c1547daAndy Hung        void onShutter();
78169aed5f0f4a3be3996d1e78a0473e1a72c1547daAndy Hung    }
78269aed5f0f4a3be3996d1e78a0473e1a72c1547daAndy Hung
78369aed5f0f4a3be3996d1e78a0473e1a72c1547daAndy Hung    /**
78498ef978df4e928f486d244c4d7f7ad9f13111e98Andy Hung     * Callback interface used to supply image data from a photo capture.
78598ef978df4e928f486d244c4d7f7ad9f13111e98Andy Hung     *
78698ef978df4e928f486d244c4d7f7ad9f13111e98Andy Hung     * @see #takePicture(ShutterCallback, PictureCallback, PictureCallback, PictureCallback)
78798ef978df4e928f486d244c4d7f7ad9f13111e98Andy Hung     */
78898ef978df4e928f486d244c4d7f7ad9f13111e98Andy Hung    public interface PictureCallback {
78998ef978df4e928f486d244c4d7f7ad9f13111e98Andy Hung        /**
79098ef978df4e928f486d244c4d7f7ad9f13111e98Andy Hung         * Called when image data is available after a picture is taken.
79198ef978df4e928f486d244c4d7f7ad9f13111e98Andy Hung         * The format of the data depends on the context of the callback
79298ef978df4e928f486d244c4d7f7ad9f13111e98Andy Hung         * and {@link Camera.Parameters} settings.
79398ef978df4e928f486d244c4d7f7ad9f13111e98Andy Hung         *
79498ef978df4e928f486d244c4d7f7ad9f13111e98Andy Hung         * @param data   a byte array of the picture data
79598ef978df4e928f486d244c4d7f7ad9f13111e98Andy Hung         * @param camera the Camera service object
79698ef978df4e928f486d244c4d7f7ad9f13111e98Andy Hung         */
79798ef978df4e928f486d244c4d7f7ad9f13111e98Andy Hung        void onPictureTaken(byte[] data, Camera camera);
79898ef978df4e928f486d244c4d7f7ad9f13111e98Andy Hung    };
79998ef978df4e928f486d244c4d7f7ad9f13111e98Andy Hung
80098ef978df4e928f486d244c4d7f7ad9f13111e98Andy Hung    /**
80198ef978df4e928f486d244c4d7f7ad9f13111e98Andy Hung     * Equivalent to takePicture(shutter, raw, null, jpeg).
80298ef978df4e928f486d244c4d7f7ad9f13111e98Andy Hung     *
80398ef978df4e928f486d244c4d7f7ad9f13111e98Andy Hung     * @see #takePicture(ShutterCallback, PictureCallback, PictureCallback, PictureCallback)
80498ef978df4e928f486d244c4d7f7ad9f13111e98Andy Hung     */
80598ef978df4e928f486d244c4d7f7ad9f13111e98Andy Hung    public final void takePicture(ShutterCallback shutter, PictureCallback raw,
80698ef978df4e928f486d244c4d7f7ad9f13111e98Andy Hung            PictureCallback jpeg) {
80798ef978df4e928f486d244c4d7f7ad9f13111e98Andy Hung        takePicture(shutter, raw, null, jpeg);
80898ef978df4e928f486d244c4d7f7ad9f13111e98Andy Hung    }
80998ef978df4e928f486d244c4d7f7ad9f13111e98Andy Hung    private native final void native_takePicture(int msgType);
81081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent
81181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent    /**
81281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     * Triggers an asynchronous image capture. The camera service will initiate
81381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     * a series of callbacks to the application as the image capture progresses.
81481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     * The shutter callback occurs after the image is captured. This can be used
81581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     * to trigger a sound to let the user know that image has been captured. The
81681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     * raw callback occurs when the raw image data is available (NOTE: the data
817818e7a32ce3633980138aff2c2bfcc5158b3cfccAndy Hung     * will be null if there is no raw image callback buffer available or the
818c54b1ffc92b8ad27608a8af21033d7cab33cb3a0Andy Hung     * raw image callback buffer is not large enough to hold the raw image).
819238fa3deff26d7e4d9e81bd0a88c936f16226c4eAndy Hung     * The postview callback occurs when a scaled, fully processed postview
82081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     * image is available (NOTE: not all hardware supports this). The jpeg
82181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     * callback occurs when the compressed image is available. If the
82281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     * application does not need a particular callback, a null can be passed
82381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     * instead of a callback method.
82481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     *
82581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     * <p>This method is only valid when preview is active (after
82681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     * {@link #startPreview()}).  Preview will be stopped after the image is
827dae27707fc7d8370eb200d25d1a7c6dd7ad5e201Andy Hung     * taken; callers must call {@link #startPreview()} again if they want to
82881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     * re-start preview or take more pictures.
82981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     *
83081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     * <p>After calling this method, you must not call {@link #startPreview()}
831ad7dd9610b6fafa81baf69607f4ac669da88182aEric Laurent     * or take another picture until the JPEG callback has returned.
832ad7dd9610b6fafa81baf69607f4ac669da88182aEric Laurent     *
83381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     * @param shutter   the callback for image capture moment, or null
83481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     * @param raw       the callback for raw (uncompressed) image data, or null
83581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     * @param postview  callback with postview image data, may be null
83681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     * @param jpeg      the callback for JPEG image data, or null
83781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     *
83881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     * @see #addRawImageCallbackBuffer(byte[])
83981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     */
84081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent    public final void takePicture(ShutterCallback shutter, PictureCallback raw,
84181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent            PictureCallback postview, PictureCallback jpeg) {
84281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent        mShutterCallback = shutter;
84381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent        mRawImageCallback = raw;
84481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent        mPostviewCallback = postview;
84581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent        mJpegCallback = jpeg;
84681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent
84781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent        // If callback is not set, do not send me callbacks.
84881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent        int msgType = 0;
84981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent        if (mShutterCallback != null) {
85081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent            msgType |= CAMERA_MSG_SHUTTER;
85181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent        }
85281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent        if (mRawImageCallback != null) {
85381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent            msgType |= CAMERA_MSG_RAW_IMAGE;
8541c333e252cbca3337c1bedbc57a005f3b7d23fdbEric Laurent        }
8551c333e252cbca3337c1bedbc57a005f3b7d23fdbEric Laurent        if (mPostviewCallback != null) {
8561c333e252cbca3337c1bedbc57a005f3b7d23fdbEric Laurent            msgType |= CAMERA_MSG_POSTVIEW_FRAME;
8571c333e252cbca3337c1bedbc57a005f3b7d23fdbEric Laurent        }
8586fc2a7c81f62b1e21487ae37e11aae6241bc3eadPhil Burk        if (mJpegCallback != null) {
8596fc2a7c81f62b1e21487ae37e11aae6241bc3eadPhil Burk            msgType |= CAMERA_MSG_COMPRESSED_IMAGE;
8606fc2a7c81f62b1e21487ae37e11aae6241bc3eadPhil Burk        }
8610f7b5f2b231caf87da9b20b74d086e5a9d6f4a9dEric Laurent
862ad7dd9610b6fafa81baf69607f4ac669da88182aEric Laurent        native_takePicture(msgType);
863ad7dd9610b6fafa81baf69607f4ac669da88182aEric Laurent    }
86481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent
86581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent    /**
86681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     * Zooms to the requested value smoothly. The driver will notify {@link
86781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     * OnZoomChangeListener} of the zoom value and whether zoom is stopped at
86881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     * the time. For example, suppose the current zoom is 0 and startSmoothZoom
86981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     * is called with value 3. The
87081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     * {@link Camera.OnZoomChangeListener#onZoomChange(int, boolean, Camera)}
871bfb1b832079bbb9426f72f3863199a54aefd02daEric Laurent     * method will be called three times with zoom values 1, 2, and 3.
87281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     * Applications can call {@link #stopSmoothZoom} to stop the zoom earlier.
873ede6c3b8b1147bc425f7b923882f559a513fe23bEric Laurent     * Applications should not call startSmoothZoom again or change the zoom
87481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     * value before zoom stops. If the supplied zoom value equals to the current
875deca2ae0a7cf8bc54ff3f30b7dc39bbc78b94c0dGlenn Kasten     * zoom value, no zoom callback will be generated. This method is supported
87681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     * if {@link android.hardware.Camera.Parameters#isSmoothZoomSupported}
87781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     * returns true.
87881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     *
87981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     * @param value zoom value. The valid range is 0 to {@link
88081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     *              android.hardware.Camera.Parameters#getMaxZoom}.
881223fd5c9738e9665e495904d37d4632414b68c1eEric Laurent     * @throws IllegalArgumentException if the zoom value is invalid.
88281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     * @throws RuntimeException if the method fails.
88381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     * @see #setZoomChangeListener(OnZoomChangeListener)
88481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     */
88581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent    public native final void startSmoothZoom(int value);
88681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent
88781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent    /**
88881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     * Stops the smooth zoom. Applications should wait for the {@link
88981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     * OnZoomChangeListener} to know when the zoom is actually stopped. This
89081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     * method is supported if {@link
891ad9cb8b88e4f8face23f01d8dc89fa769dacb50fEric Laurent     * android.hardware.Camera.Parameters#isSmoothZoomSupported} is true.
89225c2dac12114699e90deb1c579cadebce7b91a97Andy Hung     *
89381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     * @throws RuntimeException if the method fails.
89481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     */
895ad9cb8b88e4f8face23f01d8dc89fa769dacb50fEric Laurent    public native final void stopSmoothZoom();
896ad9cb8b88e4f8face23f01d8dc89fa769dacb50fEric Laurent
89781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent    /**
898ad9cb8b88e4f8face23f01d8dc89fa769dacb50fEric Laurent     * Set the clockwise rotation of preview display in degrees. This affects
89981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     * the preview frames and the picture displayed after snapshot. This method
90081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     * is useful for portrait mode applications. Note that preview display of
90181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     * front-facing cameras is flipped horizontally before the rotation, that
90281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     * is, the image is reflected along the central vertical axis of the camera
90381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     * sensor. So the users can see themselves as looking into a mirror.
90481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     *
90581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     * <p>This does not affect the order of byte array passed in {@link
90681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     * PreviewCallback#onPreviewFrame}, JPEG pictures, or recorded videos. This
90781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     * method is not allowed to be called during preview.
90881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     *
90981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     * <p>If you want to make the camera image show in the same orientation as
91081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     * the display, you can use the following code.
911ad9cb8b88e4f8face23f01d8dc89fa769dacb50fEric Laurent     * <pre>
91281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     * public static void setCameraDisplayOrientation(Activity activity,
91381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     *         int cameraId, android.hardware.Camera camera) {
91481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     *     android.hardware.Camera.CameraInfo info =
91581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     *             new android.hardware.Camera.CameraInfo();
91681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     *     android.hardware.Camera.getCameraInfo(cameraId, info);
91781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     *     int rotation = activity.getWindowManager().getDefaultDisplay()
91881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     *             .getRotation();
919bfb1b832079bbb9426f72f3863199a54aefd02daEric Laurent     *     int degrees = 0;
920bfb1b832079bbb9426f72f3863199a54aefd02daEric Laurent     *     switch (rotation) {
921bfb1b832079bbb9426f72f3863199a54aefd02daEric Laurent     *         case Surface.ROTATION_0: degrees = 0; break;
9223b4529e03c5fc7a44c22f9091ad15a269bfca3a8Eric Laurent     *         case Surface.ROTATION_90: degrees = 90; break;
9233b4529e03c5fc7a44c22f9091ad15a269bfca3a8Eric Laurent     *         case Surface.ROTATION_180: degrees = 180; break;
9243b4529e03c5fc7a44c22f9091ad15a269bfca3a8Eric Laurent     *         case Surface.ROTATION_270: degrees = 270; break;
9253b4529e03c5fc7a44c22f9091ad15a269bfca3a8Eric Laurent     *     }
9263b4529e03c5fc7a44c22f9091ad15a269bfca3a8Eric Laurent     *
9273b4529e03c5fc7a44c22f9091ad15a269bfca3a8Eric Laurent     *     int result;
9283b4529e03c5fc7a44c22f9091ad15a269bfca3a8Eric Laurent     *     if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
9293b4529e03c5fc7a44c22f9091ad15a269bfca3a8Eric Laurent     *         result = (info.orientation + degrees) % 360;
9303b4529e03c5fc7a44c22f9091ad15a269bfca3a8Eric Laurent     *         result = (360 - result) % 360;  // compensate the mirror
9313b4529e03c5fc7a44c22f9091ad15a269bfca3a8Eric Laurent     *     } else {  // back-facing
9323b4529e03c5fc7a44c22f9091ad15a269bfca3a8Eric Laurent     *         result = (info.orientation - degrees + 360) % 360;
9333b4529e03c5fc7a44c22f9091ad15a269bfca3a8Eric Laurent     *     }
9343b4529e03c5fc7a44c22f9091ad15a269bfca3a8Eric Laurent     *     camera.setDisplayOrientation(result);
935ede6c3b8b1147bc425f7b923882f559a513fe23bEric Laurent     * }
936ede6c3b8b1147bc425f7b923882f559a513fe23bEric Laurent     * </pre>
937bfb1b832079bbb9426f72f3863199a54aefd02daEric Laurent     * @param degrees the angle that the picture will be rotated clockwise.
938bfb1b832079bbb9426f72f3863199a54aefd02daEric Laurent     *                Valid values are 0, 90, 180, and 270. The starting
939bfb1b832079bbb9426f72f3863199a54aefd02daEric Laurent     *                position is 0 (landscape).
94081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     * @see #setPreviewDisplay(SurfaceHolder)
94181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     */
94281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent    public native final void setDisplayOrientation(int degrees);
94381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent
94481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent    /**
94581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     * Callback interface for zoom changes during a smooth zoom operation.
94681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     *
94746909e7eb074ce1b95b8a411eb71154f53f84f77Glenn Kasten     * @see #setZoomChangeListener(OnZoomChangeListener)
94881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     * @see #startSmoothZoom(int)
94981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     */
95081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent    public interface OnZoomChangeListener
95146909e7eb074ce1b95b8a411eb71154f53f84f77Glenn Kasten    {
95281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent        /**
953ab7d72f0804fbb7e91ad9d2a16f826d97e20e5d0Glenn Kasten         * Called when the zoom value has changed during a smooth zoom.
9549e58b552f51b00b3b674102876bd6c77ef3da806Glenn Kasten         *
9552148bf0e79c436b8764b9edc4c8f2730cce98a32Andy Hung         * @param zoomValue the current zoom value. In smooth zoom mode, camera
9562148bf0e79c436b8764b9edc4c8f2730cce98a32Andy Hung         *                  calls this for every new zoom value.
9572148bf0e79c436b8764b9edc4c8f2730cce98a32Andy Hung         * @param stopped whether smooth zoom is stopped. If the value is true,
9582148bf0e79c436b8764b9edc4c8f2730cce98a32Andy Hung         *                this is the last zoom update for the application.
9592148bf0e79c436b8764b9edc4c8f2730cce98a32Andy Hung         * @param camera  the Camera service object
9602148bf0e79c436b8764b9edc4c8f2730cce98a32Andy Hung         */
9612148bf0e79c436b8764b9edc4c8f2730cce98a32Andy Hung        void onZoomChange(int zoomValue, boolean stopped, Camera camera);
9622148bf0e79c436b8764b9edc4c8f2730cce98a32Andy Hung    };
9632148bf0e79c436b8764b9edc4c8f2730cce98a32Andy Hung
9642148bf0e79c436b8764b9edc4c8f2730cce98a32Andy Hung    /**
9652148bf0e79c436b8764b9edc4c8f2730cce98a32Andy Hung     * Registers a listener to be notified when the zoom value is updated by the
9662148bf0e79c436b8764b9edc4c8f2730cce98a32Andy Hung     * camera driver during smooth zoom.
9672148bf0e79c436b8764b9edc4c8f2730cce98a32Andy Hung     *
9682148bf0e79c436b8764b9edc4c8f2730cce98a32Andy Hung     * @param listener the listener to notify
9692148bf0e79c436b8764b9edc4c8f2730cce98a32Andy Hung     * @see #startSmoothZoom(int)
9702148bf0e79c436b8764b9edc4c8f2730cce98a32Andy Hung     */
9712148bf0e79c436b8764b9edc4c8f2730cce98a32Andy Hung    public final void setZoomChangeListener(OnZoomChangeListener listener)
9722148bf0e79c436b8764b9edc4c8f2730cce98a32Andy Hung    {
9732148bf0e79c436b8764b9edc4c8f2730cce98a32Andy Hung        mZoomListener = listener;
9742148bf0e79c436b8764b9edc4c8f2730cce98a32Andy Hung    }
9752148bf0e79c436b8764b9edc4c8f2730cce98a32Andy Hung
9762148bf0e79c436b8764b9edc4c8f2730cce98a32Andy Hung    // Error codes match the enum in include/ui/Camera.h
9772148bf0e79c436b8764b9edc4c8f2730cce98a32Andy Hung
9782148bf0e79c436b8764b9edc4c8f2730cce98a32Andy Hung    /**
9792148bf0e79c436b8764b9edc4c8f2730cce98a32Andy Hung     * Unspecified camera error.
9802148bf0e79c436b8764b9edc4c8f2730cce98a32Andy Hung     * @see Camera.ErrorCallback
9812148bf0e79c436b8764b9edc4c8f2730cce98a32Andy Hung     */
9822148bf0e79c436b8764b9edc4c8f2730cce98a32Andy Hung    public static final int CAMERA_ERROR_UNKNOWN = 1;
9832148bf0e79c436b8764b9edc4c8f2730cce98a32Andy Hung
9842148bf0e79c436b8764b9edc4c8f2730cce98a32Andy Hung    /**
9852148bf0e79c436b8764b9edc4c8f2730cce98a32Andy Hung     * Media server died. In this case, the application must release the
9862148bf0e79c436b8764b9edc4c8f2730cce98a32Andy Hung     * Camera object and instantiate a new one.
9872148bf0e79c436b8764b9edc4c8f2730cce98a32Andy Hung     * @see Camera.ErrorCallback
9882148bf0e79c436b8764b9edc4c8f2730cce98a32Andy Hung     */
9892148bf0e79c436b8764b9edc4c8f2730cce98a32Andy Hung    public static final int CAMERA_ERROR_SERVER_DIED = 100;
9902148bf0e79c436b8764b9edc4c8f2730cce98a32Andy Hung
9912148bf0e79c436b8764b9edc4c8f2730cce98a32Andy Hung    /**
9922148bf0e79c436b8764b9edc4c8f2730cce98a32Andy Hung     * Callback interface for camera error notification.
9932148bf0e79c436b8764b9edc4c8f2730cce98a32Andy Hung     *
9942148bf0e79c436b8764b9edc4c8f2730cce98a32Andy Hung     * @see #setErrorCallback(ErrorCallback)
9952148bf0e79c436b8764b9edc4c8f2730cce98a32Andy Hung     */
9962148bf0e79c436b8764b9edc4c8f2730cce98a32Andy Hung    public interface ErrorCallback
9972148bf0e79c436b8764b9edc4c8f2730cce98a32Andy Hung    {
9982148bf0e79c436b8764b9edc4c8f2730cce98a32Andy Hung        /**
999f28bcf5c057dd9738a09f3cb367cf0b44087135dAndy Hung         * Callback for camera errors.
1000f28bcf5c057dd9738a09f3cb367cf0b44087135dAndy Hung         * @param error   error code:
1001f28bcf5c057dd9738a09f3cb367cf0b44087135dAndy Hung         * <ul>
1002f28bcf5c057dd9738a09f3cb367cf0b44087135dAndy Hung         * <li>{@link #CAMERA_ERROR_UNKNOWN}
1003f28bcf5c057dd9738a09f3cb367cf0b44087135dAndy Hung         * <li>{@link #CAMERA_ERROR_SERVER_DIED}
1004f28bcf5c057dd9738a09f3cb367cf0b44087135dAndy Hung         * </ul>
10052148bf0e79c436b8764b9edc4c8f2730cce98a32Andy Hung         * @param camera  the Camera service object
10062148bf0e79c436b8764b9edc4c8f2730cce98a32Andy Hung         */
10072148bf0e79c436b8764b9edc4c8f2730cce98a32Andy Hung        void onError(int error, Camera camera);
10082148bf0e79c436b8764b9edc4c8f2730cce98a32Andy Hung    };
10092148bf0e79c436b8764b9edc4c8f2730cce98a32Andy Hung
10102148bf0e79c436b8764b9edc4c8f2730cce98a32Andy Hung    /**
10112148bf0e79c436b8764b9edc4c8f2730cce98a32Andy Hung     * Registers a callback to be invoked when an error occurs.
10122148bf0e79c436b8764b9edc4c8f2730cce98a32Andy Hung     * @param cb The callback to run
10132148bf0e79c436b8764b9edc4c8f2730cce98a32Andy Hung     */
10142148bf0e79c436b8764b9edc4c8f2730cce98a32Andy Hung    public final void setErrorCallback(ErrorCallback cb)
10152148bf0e79c436b8764b9edc4c8f2730cce98a32Andy Hung    {
10162148bf0e79c436b8764b9edc4c8f2730cce98a32Andy Hung        mErrorCallback = cb;
10172148bf0e79c436b8764b9edc4c8f2730cce98a32Andy Hung    }
10182148bf0e79c436b8764b9edc4c8f2730cce98a32Andy Hung
10192148bf0e79c436b8764b9edc4c8f2730cce98a32Andy Hung    private native final void native_setParameters(String params);
10202148bf0e79c436b8764b9edc4c8f2730cce98a32Andy Hung    private native final String native_getParameters();
10212148bf0e79c436b8764b9edc4c8f2730cce98a32Andy Hung
10222148bf0e79c436b8764b9edc4c8f2730cce98a32Andy Hung    /**
10232148bf0e79c436b8764b9edc4c8f2730cce98a32Andy Hung     * Changes the settings for this Camera service.
10242148bf0e79c436b8764b9edc4c8f2730cce98a32Andy Hung     *
10252148bf0e79c436b8764b9edc4c8f2730cce98a32Andy Hung     * @param params the Parameters to use for this Camera service
10262148bf0e79c436b8764b9edc4c8f2730cce98a32Andy Hung     * @throws RuntimeException if any parameter is invalid or not supported.
10272148bf0e79c436b8764b9edc4c8f2730cce98a32Andy Hung     * @see #getParameters()
10282148bf0e79c436b8764b9edc4c8f2730cce98a32Andy Hung     */
10292148bf0e79c436b8764b9edc4c8f2730cce98a32Andy Hung    public void setParameters(Parameters params) {
10302148bf0e79c436b8764b9edc4c8f2730cce98a32Andy Hung        native_setParameters(params.flatten());
103181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent    }
103281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent
10330f11b51a57bc9062c4fe8af73747319cedabc5d6Glenn Kasten    /**
103481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     * Returns the current settings for this Camera service.
103581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     * If modifications are made to the returned Parameters, they must be passed
103681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     * to {@link #setParameters(Camera.Parameters)} to take effect.
103781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     *
103881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     * @see #setParameters(Camera.Parameters)
1039d1f69b0b17acbd96987ecb2f3378abd394d05903Eric Laurent     */
1040d1f69b0b17acbd96987ecb2f3378abd394d05903Eric Laurent    public Parameters getParameters() {
1041d1f69b0b17acbd96987ecb2f3378abd394d05903Eric Laurent        Parameters p = new Parameters();
104281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent        String s = native_getParameters();
104381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent        p.unflatten(s);
104481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent        return p;
104581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent    }
104681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent
104781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent    /**
104881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     * Image size (width and height dimensions).
104981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     */
105072e3f39146fce4686bd96f11057c051bea376dfbEric Laurent    public class Size {
105181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent        /**
105281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent         * Sets the dimensions for pictures.
105381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent         *
105481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent         * @param w the photo width (pixels)
105581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent         * @param h the photo height (pixels)
10561035194cee4fbd57e35ea15c56e66cd09b63d56eEric Laurent         */
10571035194cee4fbd57e35ea15c56e66cd09b63d56eEric Laurent        public Size(int w, int h) {
105881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent            width = w;
105981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent            height = h;
106081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent        }
106181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent        /**
1062ad7dd9610b6fafa81baf69607f4ac669da88182aEric Laurent         * Compares {@code obj} to this size.
1063ad7dd9610b6fafa81baf69607f4ac669da88182aEric Laurent         *
106481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent         * @param obj the object to compare this size with.
106581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent         * @return {@code true} if the width and height of {@code obj} is the
106681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent         *         same as those of this size. {@code false} otherwise.
106781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent         */
106881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent        @Override
1069dae27707fc7d8370eb200d25d1a7c6dd7ad5e201Andy Hung        public boolean equals(Object obj) {
1070dae27707fc7d8370eb200d25d1a7c6dd7ad5e201Andy Hung            if (!(obj instanceof Size)) {
1071818e7a32ce3633980138aff2c2bfcc5158b3cfccAndy Hung                return false;
1072818e7a32ce3633980138aff2c2bfcc5158b3cfccAndy Hung            }
1073818e7a32ce3633980138aff2c2bfcc5158b3cfccAndy Hung            Size s = (Size) obj;
1074818e7a32ce3633980138aff2c2bfcc5158b3cfccAndy Hung            return width == s.width && height == s.height;
1075818e7a32ce3633980138aff2c2bfcc5158b3cfccAndy Hung        }
1076818e7a32ce3633980138aff2c2bfcc5158b3cfccAndy Hung        @Override
107781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent        public int hashCode() {
1078bfb1b832079bbb9426f72f3863199a54aefd02daEric Laurent            return width * 32713 + height;
107981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent        }
108081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent        /** width of the picture */
108181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent        public int width;
108281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent        /** height of the picture */
108381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent        public int height;
108481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent    };
1085054d9d3dea1390294650ac704acb4aa0a0731217Eric Laurent
1086054d9d3dea1390294650ac704acb4aa0a0731217Eric Laurent    /**
1087054d9d3dea1390294650ac704acb4aa0a0731217Eric Laurent     * Area class for focus.
1088054d9d3dea1390294650ac704acb4aa0a0731217Eric Laurent     *
108981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     * @see #setFocusAreas(List)
109081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     * @see #getFocusAreas()
109181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     */
10924d23ca370dd0ce584f49a80ef9dfcdbb75ba2c8eGlenn Kasten    public static class Area {
109381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent        /**
109481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent         * Create an area with specified rectangle and weight.
109581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent         *
109681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent         * @param rect the rectangle of the area
109781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent         * @param weight the weight of the area
109881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent         */
109981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent        public Area(Rect rect, int weight) {
110081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent            this.rect = rect;
110181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent            this.weight = weight;
110281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent        }
110381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent        /**
110481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent         * Compares {@code obj} to this area.
110581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent         *
110681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent         * @param obj the object to compare this area with.
11072ddee19245641e86bca436dda23a0f5089bf2ab5Andy Hung         * @return {@code true} if the rectangle and weight of {@code obj} is
110881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent         *         the same as those of this area. {@code false} otherwise.
11094d23ca370dd0ce584f49a80ef9dfcdbb75ba2c8eGlenn Kasten         */
111081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent        @Override
1111dc2c50bad491d2c0c8a2efc0e24491076701c63cGlenn Kasten        public boolean equals(Object obj) {
111281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent            if (!(obj instanceof Area)) {
111381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent                return false;
111483b8808faad1e91690c64d7007348be8d9ebde73Eric Laurent            }
11152ddee19245641e86bca436dda23a0f5089bf2ab5Andy Hung            Area a = (Area) obj;
11162ddee19245641e86bca436dda23a0f5089bf2ab5Andy Hung            if (rect == null) {
11172ddee19245641e86bca436dda23a0f5089bf2ab5Andy Hung                if (a.rect != null) return false;
11182ddee19245641e86bca436dda23a0f5089bf2ab5Andy Hung            } else {
11192ddee19245641e86bca436dda23a0f5089bf2ab5Andy Hung                if (!rect.equals(a.rect)) return false;
11202ddee19245641e86bca436dda23a0f5089bf2ab5Andy Hung            }
11212ddee19245641e86bca436dda23a0f5089bf2ab5Andy Hung            return weight == a.weight;
11222ddee19245641e86bca436dda23a0f5089bf2ab5Andy Hung        }
112303c48d5afcb3dfc1e43df93e1f3b3b3e9292e148Glenn Kasten
112403c48d5afcb3dfc1e43df93e1f3b3b3e9292e148Glenn Kasten        /** rectangle of the area */
11252ddee19245641e86bca436dda23a0f5089bf2ab5Andy Hung        public Rect rect;
112681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent
112781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent        /** weight of the area */
112881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent        public int weight;
112981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent    };
113081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent
113181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent    /**
1132e93cc03da360a1a0d2ad937c745ce8c8e8be81c2Eric Laurent     * Camera service settings.
113381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     *
113481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     * <p>To make camera parameters take effect, applications have to call
113581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     * {@link Camera#setParameters(Camera.Parameters)}. For example, after
113681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     * {@link Camera.Parameters#setWhiteBalance} is called, white balance is not
11371035194cee4fbd57e35ea15c56e66cd09b63d56eEric Laurent     * actually changed until {@link Camera#setParameters(Camera.Parameters)}
11381035194cee4fbd57e35ea15c56e66cd09b63d56eEric Laurent     * is called with the changed parameters object.
1139e659ef420dae0caae84ab78f9df8952acb9ad3a0Eric Laurent     *
114081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     * <p>Different devices may have different camera capabilities, such as
114181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     * picture size or flash modes. The application should query the camera
1142ad7dd9610b6fafa81baf69607f4ac669da88182aEric Laurent     * capabilities before setting parameters. For example, the application
1143ad7dd9610b6fafa81baf69607f4ac669da88182aEric Laurent     * should call {@link Camera.Parameters#getSupportedColorEffects()} before
114481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     * calling {@link Camera.Parameters#setColorEffect(String)}. If the
114581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     * camera does not support color effects,
114681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     * {@link Camera.Parameters#getSupportedColorEffects()} will return null.
114781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent     */
114881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent    public class Parameters {
114981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent        // Parameter keys to communicate with the camera driver.
115081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent        private static final String KEY_PREVIEW_SIZE = "preview-size";
115181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent        private static final String KEY_PREVIEW_FORMAT = "preview-format";
115281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent        private static final String KEY_PREVIEW_FRAME_RATE = "preview-frame-rate";
115381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent        private static final String KEY_PREVIEW_FPS_RANGE = "preview-fps-range";
1154d1f69b0b17acbd96987ecb2f3378abd394d05903Eric Laurent        private static final String KEY_PICTURE_SIZE = "picture-size";
1155d1f69b0b17acbd96987ecb2f3378abd394d05903Eric Laurent        private static final String KEY_PICTURE_FORMAT = "picture-format";
115681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent        private static final String KEY_JPEG_THUMBNAIL_SIZE = "jpeg-thumbnail-size";
115743b4dcc660e6da96285e4672ae371070ab845401Phil Burk        private static final String KEY_JPEG_THUMBNAIL_WIDTH = "jpeg-thumbnail-width";
115843b4dcc660e6da96285e4672ae371070ab845401Phil Burk        private static final String KEY_JPEG_THUMBNAIL_HEIGHT = "jpeg-thumbnail-height";
115981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent        private static final String KEY_JPEG_THUMBNAIL_QUALITY = "jpeg-thumbnail-quality";
116081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent        private static final String KEY_JPEG_QUALITY = "jpeg-quality";
116181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent        private static final String KEY_ROTATION = "rotation";
116281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent        private static final String KEY_GPS_LATITUDE = "gps-latitude";
1163bfb1b832079bbb9426f72f3863199a54aefd02daEric Laurent        private static final String KEY_GPS_LONGITUDE = "gps-longitude";
116472e3f39146fce4686bd96f11057c051bea376dfbEric Laurent        private static final String KEY_GPS_ALTITUDE = "gps-altitude";
1165e93cc03da360a1a0d2ad937c745ce8c8e8be81c2Eric Laurent        private static final String KEY_GPS_TIMESTAMP = "gps-timestamp";
11665850c4c8eecbe0db3cee8511a4f82cb443e27d08Eric Laurent        private static final String KEY_GPS_PROCESSING_METHOD = "gps-processing-method";
1167bfb1b832079bbb9426f72f3863199a54aefd02daEric Laurent        private static final String KEY_WHITE_BALANCE = "whitebalance";
116881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent        private static final String KEY_EFFECT = "effect";
116981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent        private static final String KEY_ANTIBANDING = "antibanding";
117043b4dcc660e6da96285e4672ae371070ab845401Phil Burk        private static final String KEY_SCENE_MODE = "scene-mode";
117143b4dcc660e6da96285e4672ae371070ab845401Phil Burk        private static final String KEY_FLASH_MODE = "flash-mode";
117243b4dcc660e6da96285e4672ae371070ab845401Phil Burk        private static final String KEY_FOCUS_MODE = "focus-mode";
117381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent        private static final String KEY_FOCUS_AREAS = "focus-areas";
117481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent        private static final String KEY_MAX_NUM_FOCUS_AREAS = "max-num-focus-areas";
117581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent        private static final String KEY_FOCAL_LENGTH = "focal-length";
117681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent        private static final String KEY_HORIZONTAL_VIEW_ANGLE = "horizontal-view-angle";
1177bfb1b832079bbb9426f72f3863199a54aefd02daEric Laurent        private static final String KEY_VERTICAL_VIEW_ANGLE = "vertical-view-angle";
1178bfb1b832079bbb9426f72f3863199a54aefd02daEric Laurent        private static final String KEY_EXPOSURE_COMPENSATION = "exposure-compensation";
1179bfb1b832079bbb9426f72f3863199a54aefd02daEric Laurent        private static final String KEY_MAX_EXPOSURE_COMPENSATION = "max-exposure-compensation";
1180bfb1b832079bbb9426f72f3863199a54aefd02daEric Laurent        private static final String KEY_MIN_EXPOSURE_COMPENSATION = "min-exposure-compensation";
1181e93cc03da360a1a0d2ad937c745ce8c8e8be81c2Eric Laurent        private static final String KEY_EXPOSURE_COMPENSATION_STEP = "exposure-compensation-step";
11826a51d7ed7062536ccc892c8850a34ed55cbc8d5cEric Laurent        private static final String KEY_AUTO_EXPOSURE_LOCK = "auto-exposure-lock";
1183e659ef420dae0caae84ab78f9df8952acb9ad3a0Eric Laurent        private static final String KEY_AUTO_EXPOSURE_LOCK_SUPPORTED = "auto-exposure-lock-supported";
1184bfb1b832079bbb9426f72f3863199a54aefd02daEric Laurent        private static final String KEY_METERING_AREAS = "metering-areas";
1185bfb1b832079bbb9426f72f3863199a54aefd02daEric Laurent        private static final String KEY_MAX_NUM_METERING_AREAS = "max-num-metering-areas";
1186bfb1b832079bbb9426f72f3863199a54aefd02daEric Laurent        private static final String KEY_ZOOM = "zoom";
1187bfb1b832079bbb9426f72f3863199a54aefd02daEric Laurent        private static final String KEY_MAX_ZOOM = "max-zoom";
1188bfb1b832079bbb9426f72f3863199a54aefd02daEric Laurent        private static final String KEY_ZOOM_RATIOS = "zoom-ratios";
1189bfb1b832079bbb9426f72f3863199a54aefd02daEric Laurent        private static final String KEY_ZOOM_SUPPORTED = "zoom-supported";
1190bfb1b832079bbb9426f72f3863199a54aefd02daEric Laurent        private static final String KEY_SMOOTH_ZOOM_SUPPORTED = "smooth-zoom-supported";
1191bfb1b832079bbb9426f72f3863199a54aefd02daEric Laurent        private static final String KEY_FOCUS_DISTANCES = "focus-distances";
119205317d29b27e5fda654bea21b80d4423a03f49b3Haynes Mathew George        private static final String KEY_VIDEO_SIZE = "video-size";
1193bfb1b832079bbb9426f72f3863199a54aefd02daEric Laurent        private static final String KEY_PREFERRED_PREVIEW_SIZE_FOR_VIDEO =
1194de0613d0ad8b8fb9d19a27185ae4d307a5b7fb9dEric Laurent                                            "preferred-preview-size-for-video";
1195646679779a8f952980a5d4219ad9c6f93efc4b92Eric Laurent
1196bfb1b832079bbb9426f72f3863199a54aefd02daEric Laurent        // Parameter key suffix for supported values.
1197bfb1b832079bbb9426f72f3863199a54aefd02daEric Laurent        private static final String SUPPORTED_VALUES_SUFFIX = "-values";
1198bfb1b832079bbb9426f72f3863199a54aefd02daEric Laurent
1199646679779a8f952980a5d4219ad9c6f93efc4b92Eric Laurent        private static final String TRUE = "true";
1200f804475807407442d5596ab7378ed07d50664063Andy Hung        private static final String FALSE = "false";
1201f804475807407442d5596ab7378ed07d50664063Andy Hung
1202f804475807407442d5596ab7378ed07d50664063Andy Hung        // Values for white balance settings.
1203f804475807407442d5596ab7378ed07d50664063Andy Hung        public static final String WHITE_BALANCE_AUTO = "auto";
1204bfb1b832079bbb9426f72f3863199a54aefd02daEric Laurent        public static final String WHITE_BALANCE_INCANDESCENT = "incandescent";
1205bfb1b832079bbb9426f72f3863199a54aefd02daEric Laurent        public static final String WHITE_BALANCE_FLUORESCENT = "fluorescent";
1206bfb1b832079bbb9426f72f3863199a54aefd02daEric Laurent        public static final String WHITE_BALANCE_WARM_FLUORESCENT = "warm-fluorescent";
1207bfb1b832079bbb9426f72f3863199a54aefd02daEric Laurent        public static final String WHITE_BALANCE_DAYLIGHT = "daylight";
1208bfb1b832079bbb9426f72f3863199a54aefd02daEric Laurent        public static final String WHITE_BALANCE_CLOUDY_DAYLIGHT = "cloudy-daylight";
1209e964d4e421e2d1ca937227a580c0c837091a11e3Chih-Hung Hsieh        public static final String WHITE_BALANCE_TWILIGHT = "twilight";
1210bfb1b832079bbb9426f72f3863199a54aefd02daEric Laurent        public static final String WHITE_BALANCE_SHADE = "shade";
1211bfb1b832079bbb9426f72f3863199a54aefd02daEric Laurent
1212bfb1b832079bbb9426f72f3863199a54aefd02daEric Laurent        // Values for color effect settings.
1213bfb1b832079bbb9426f72f3863199a54aefd02daEric Laurent        public static final String EFFECT_NONE = "none";
1214bfb1b832079bbb9426f72f3863199a54aefd02daEric Laurent        public static final String EFFECT_MONO = "mono";
1215bfb1b832079bbb9426f72f3863199a54aefd02daEric Laurent        public static final String EFFECT_NEGATIVE = "negative";
1216bfb1b832079bbb9426f72f3863199a54aefd02daEric Laurent        public static final String EFFECT_SOLARIZE = "solarize";
1217bfb1b832079bbb9426f72f3863199a54aefd02daEric Laurent        public static final String EFFECT_SEPIA = "sepia";
1218bfb1b832079bbb9426f72f3863199a54aefd02daEric Laurent        public static final String EFFECT_POSTERIZE = "posterize";
1219bfb1b832079bbb9426f72f3863199a54aefd02daEric Laurent        public static final String EFFECT_WHITEBOARD = "whiteboard";
12203b4529e03c5fc7a44c22f9091ad15a269bfca3a8Eric Laurent        public static final String EFFECT_BLACKBOARD = "blackboard";
12213b4529e03c5fc7a44c22f9091ad15a269bfca3a8Eric Laurent        public static final String EFFECT_AQUA = "aqua";
12223b4529e03c5fc7a44c22f9091ad15a269bfca3a8Eric Laurent
12233b4529e03c5fc7a44c22f9091ad15a269bfca3a8Eric Laurent        // Values for antibanding settings.
12244527b9ebc6a37b861f5a3bba68bcc63dc8d69adaHaynes Mathew George        public static final String ANTIBANDING_AUTO = "auto";
1225bfb1b832079bbb9426f72f3863199a54aefd02daEric Laurent        public static final String ANTIBANDING_50HZ = "50hz";
1226bfb1b832079bbb9426f72f3863199a54aefd02daEric Laurent        public static final String ANTIBANDING_60HZ = "60hz";
12274de95592980dba88a35b3dc8f3fd045588387a4fEric Laurent        public static final String ANTIBANDING_OFF = "off";
12283b4529e03c5fc7a44c22f9091ad15a269bfca3a8Eric Laurent
12293b4529e03c5fc7a44c22f9091ad15a269bfca3a8Eric Laurent        // Values for flash mode settings.
12303b4529e03c5fc7a44c22f9091ad15a269bfca3a8Eric Laurent        /**
12314de95592980dba88a35b3dc8f3fd045588387a4fEric Laurent         * Flash will not be fired.
12323b4529e03c5fc7a44c22f9091ad15a269bfca3a8Eric Laurent         */
12333b4529e03c5fc7a44c22f9091ad15a269bfca3a8Eric Laurent        public static final String FLASH_MODE_OFF = "off";
12343b4529e03c5fc7a44c22f9091ad15a269bfca3a8Eric Laurent
12354de95592980dba88a35b3dc8f3fd045588387a4fEric Laurent        /**
12364de95592980dba88a35b3dc8f3fd045588387a4fEric Laurent         * Flash will be fired automatically when required. The flash may be fired
12374de95592980dba88a35b3dc8f3fd045588387a4fEric Laurent         * during preview, auto-focus, or snapshot depending on the driver.
12384527b9ebc6a37b861f5a3bba68bcc63dc8d69adaHaynes Mathew George         */
1239bfb1b832079bbb9426f72f3863199a54aefd02daEric Laurent        public static final String FLASH_MODE_AUTO = "auto";
1240bfb1b832079bbb9426f72f3863199a54aefd02daEric Laurent
124181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent        /**
124281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent         * Flash will always be fired during snapshot. The flash may also be
124381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent         * fired during preview or auto-focus depending on the driver.
124472e3f39146fce4686bd96f11057c051bea376dfbEric Laurent         */
124581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent        public static final String FLASH_MODE_ON = "on";
124681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent
124781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent        /**
124881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent         * Flash will be fired in red-eye reduction mode.
124981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent         */
125081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent        public static final String FLASH_MODE_RED_EYE = "red-eye";
125181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent
125281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent        /**
125381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent         * Constant emission of light during preview, auto-focus and snapshot.
125481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent         * This can also be used for video recording.
125581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent         */
125681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent        public static final String FLASH_MODE_TORCH = "torch";
125781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent
125881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent        /**
125981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent         * Scene mode is off.
1260bfb1b832079bbb9426f72f3863199a54aefd02daEric Laurent         */
126181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent        public static final String SCENE_MODE_AUTO = "auto";
126281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent
126381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent        /**
126481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent         * Take photos of fast moving objects. Same as {@link
126581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent         * #SCENE_MODE_SPORTS}.
126681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent         */
126781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent        public static final String SCENE_MODE_ACTION = "action";
126881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent
126981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent        /**
127081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent         * Take people pictures.
127181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent         */
127281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent        public static final String SCENE_MODE_PORTRAIT = "portrait";
127381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent
127481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent        /**
127581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent         * Take pictures on distant objects.
127681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent         */
127781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent        public static final String SCENE_MODE_LANDSCAPE = "landscape";
127881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent
127981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent        /**
128081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent         * Take photos at night.
12816dd62fb91d82dedcfa3ab38c02eb0940b4ba932aGlenn Kasten         */
128281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent        public static final String SCENE_MODE_NIGHT = "night";
128381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent
128481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent        /**
12856dd62fb91d82dedcfa3ab38c02eb0940b4ba932aGlenn Kasten         * Take people pictures at night.
128673c02e4277b399c2ec1555d32b6ad5df23bb83dcAndy Hung         */
128773c02e4277b399c2ec1555d32b6ad5df23bb83dcAndy Hung        public static final String SCENE_MODE_NIGHT_PORTRAIT = "night-portrait";
128873c02e4277b399c2ec1555d32b6ad5df23bb83dcAndy Hung
128973c02e4277b399c2ec1555d32b6ad5df23bb83dcAndy Hung        /**
129073c02e4277b399c2ec1555d32b6ad5df23bb83dcAndy Hung         * Take photos in a theater. Flash light is off.
12916dd62fb91d82dedcfa3ab38c02eb0940b4ba932aGlenn Kasten         */
12926dd62fb91d82dedcfa3ab38c02eb0940b4ba932aGlenn Kasten        public static final String SCENE_MODE_THEATRE = "theatre";
12936dd62fb91d82dedcfa3ab38c02eb0940b4ba932aGlenn Kasten
1294e964d4e421e2d1ca937227a580c0c837091a11e3Chih-Hung Hsieh        /**
129573c02e4277b399c2ec1555d32b6ad5df23bb83dcAndy Hung         * Take pictures on the beach.
129673c02e4277b399c2ec1555d32b6ad5df23bb83dcAndy Hung         */
12976dd62fb91d82dedcfa3ab38c02eb0940b4ba932aGlenn Kasten        public static final String SCENE_MODE_BEACH = "beach";
129873c02e4277b399c2ec1555d32b6ad5df23bb83dcAndy Hung
129973c02e4277b399c2ec1555d32b6ad5df23bb83dcAndy Hung        /**
130073c02e4277b399c2ec1555d32b6ad5df23bb83dcAndy Hung         * Take pictures on the snow.
130173c02e4277b399c2ec1555d32b6ad5df23bb83dcAndy Hung         */
130273c02e4277b399c2ec1555d32b6ad5df23bb83dcAndy Hung        public static final String SCENE_MODE_SNOW = "snow";
130373c02e4277b399c2ec1555d32b6ad5df23bb83dcAndy Hung
130473c02e4277b399c2ec1555d32b6ad5df23bb83dcAndy Hung        /**
130573c02e4277b399c2ec1555d32b6ad5df23bb83dcAndy Hung         * Take sunset photos.
130673c02e4277b399c2ec1555d32b6ad5df23bb83dcAndy Hung         */
130773c02e4277b399c2ec1555d32b6ad5df23bb83dcAndy Hung        public static final String SCENE_MODE_SUNSET = "sunset";
130873c02e4277b399c2ec1555d32b6ad5df23bb83dcAndy Hung
130973c02e4277b399c2ec1555d32b6ad5df23bb83dcAndy Hung        /**
131073c02e4277b399c2ec1555d32b6ad5df23bb83dcAndy Hung         * Avoid blurry pictures (for example, due to hand shake).
131173c02e4277b399c2ec1555d32b6ad5df23bb83dcAndy Hung         */
131273c02e4277b399c2ec1555d32b6ad5df23bb83dcAndy Hung        public static final String SCENE_MODE_STEADYPHOTO = "steadyphoto";
131373c02e4277b399c2ec1555d32b6ad5df23bb83dcAndy Hung
131473c02e4277b399c2ec1555d32b6ad5df23bb83dcAndy Hung        /**
131573c02e4277b399c2ec1555d32b6ad5df23bb83dcAndy Hung         * For shooting firework displays.
13166dd62fb91d82dedcfa3ab38c02eb0940b4ba932aGlenn Kasten         */
1317d79072e9dff59f767cce2cda1caab80ce5a0815bGlenn Kasten        public static final String SCENE_MODE_FIREWORKS = "fireworks";
13186dd62fb91d82dedcfa3ab38c02eb0940b4ba932aGlenn Kasten
13196dd62fb91d82dedcfa3ab38c02eb0940b4ba932aGlenn Kasten        /**
13206dd62fb91d82dedcfa3ab38c02eb0940b4ba932aGlenn Kasten         * Take photos of fast moving objects. Same as {@link
132173c02e4277b399c2ec1555d32b6ad5df23bb83dcAndy Hung         * #SCENE_MODE_ACTION}.
132273c02e4277b399c2ec1555d32b6ad5df23bb83dcAndy Hung         */
132373c02e4277b399c2ec1555d32b6ad5df23bb83dcAndy Hung        public static final String SCENE_MODE_SPORTS = "sports";
132473c02e4277b399c2ec1555d32b6ad5df23bb83dcAndy Hung
132573c02e4277b399c2ec1555d32b6ad5df23bb83dcAndy Hung        /**
13266dd62fb91d82dedcfa3ab38c02eb0940b4ba932aGlenn Kasten         * Take indoor low-light shot.
13276dd62fb91d82dedcfa3ab38c02eb0940b4ba932aGlenn Kasten         */
132881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent        public static final String SCENE_MODE_PARTY = "party";
132981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent
133081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent        /**
133181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent         * Capture the naturally warm color of scenes lit by candles.
133281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent         */
1333d3922f72601d82c6fc067a98916fda0bd1291c5fEric Laurent        public static final String SCENE_MODE_CANDLELIGHT = "candlelight";
133472e3f39146fce4686bd96f11057c051bea376dfbEric Laurent
133572e3f39146fce4686bd96f11057c051bea376dfbEric Laurent        /**
133646909e7eb074ce1b95b8a411eb71154f53f84f77Glenn Kasten         * Applications are looking for a barcode. Camera driver will be
133746909e7eb074ce1b95b8a411eb71154f53f84f77Glenn Kasten         * optimized for barcode reading.
133846909e7eb074ce1b95b8a411eb71154f53f84f77Glenn Kasten         */
133946909e7eb074ce1b95b8a411eb71154f53f84f77Glenn Kasten        public static final String SCENE_MODE_BARCODE = "barcode";
134081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent
134181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent        /**
134281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent         * Auto-focus mode. Applications should call {@link
134381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent         * #autoFocus(AutoFocusCallback)} to start the focus in this mode.
134481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent         */
134581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent        public static final String FOCUS_MODE_AUTO = "auto";
134681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent
134781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent        /**
134881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent         * Focus is set at infinity. Applications should not call
134981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent         * {@link #autoFocus(AutoFocusCallback)} in this mode.
135081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent         */
135181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent        public static final String FOCUS_MODE_INFINITY = "infinity";
135281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent
135381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent        /**
135481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent         * Macro (close-up) focus mode. Applications should call
135581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent         * {@link #autoFocus(AutoFocusCallback)} to start the focus in this
1356e198c360d5e75a9b2097844c495c10902e7e8500Glenn Kasten         * mode.
1357b880f5e5fc07397ddd09a94ba18bdf4fa62aae00Glenn Kasten         */
1358b880f5e5fc07397ddd09a94ba18bdf4fa62aae00Glenn Kasten        public static final String FOCUS_MODE_MACRO = "macro";
13596dbb5e3336cfff1ad51d429fcb847307c06efd61Glenn Kasten
13606dbb5e3336cfff1ad51d429fcb847307c06efd61Glenn Kasten        /**
136181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent         * Focus is fixed. The camera is always in this mode if the focus is not
136281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent         * adjustable. If the camera has auto-focus, this mode can fix the
136381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent         * focus, which is usually at hyperfocal distance. Applications should
136481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent         * not call {@link #autoFocus(AutoFocusCallback)} in this mode.
136581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent         */
136674935e44734c1ec235c2b6677db3e0dbefa5ddb8Glenn Kasten        public static final String FOCUS_MODE_FIXED = "fixed";
1367d848eb48c121c119e8ba7583efc75415fe102570Glenn Kasten
13687df8c0b799d8f52d6386e03313286dbd7d5cdc7cGlenn Kasten        /**
13691f12a8ad958344c50733b948628ffa06db9c5bc6Andy Hung         * Extended depth of field (EDOF). Focusing is done digitally and
1370050677873c10d4da308ac222f8533c96cca3207eEric Laurent         * continuously. Applications should not call {@link
137181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent         * #autoFocus(AutoFocusCallback)} in this mode.
137220b9ef0b55c9150ae11057ab997ae61be2d496efEric Laurent         */
137320b9ef0b55c9150ae11057ab997ae61be2d496efEric Laurent        public static final String FOCUS_MODE_EDOF = "edof";
137481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent
137581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent        /**
137681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent         * Continuous auto focus mode intended for video recording. The camera
1377d848eb48c121c119e8ba7583efc75415fe102570Glenn Kasten         * continuously tries to focus. This is ideal for shooting video.
137881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent         * Applications still can call {@link
137981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent         * #takePicture(Camera.ShutterCallback, Camera.PictureCallback,
138081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent         * Camera.PictureCallback)} in this mode but the subject may not be in
1381a8356f663014e7d4c27869629af83d8bb3441e19Glenn Kasten         * focus. Auto focus starts when the parameter is set. Applications
138281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent         * should not call {@link #autoFocus(AutoFocusCallback)} in this mode.
138381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent         * To stop continuous focus, applications should change the focus mode
138481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent         * to other modes.
13851dc98674f701dada94143b4d31b7221c58346c6cMikhail Naganov         */
138681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent        public static final String FOCUS_MODE_CONTINUOUS_VIDEO = "continuous-video";
138781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent
13881035194cee4fbd57e35ea15c56e66cd09b63d56eEric Laurent        // Indices for focus distance array.
13891035194cee4fbd57e35ea15c56e66cd09b63d56eEric Laurent        /**
13901035194cee4fbd57e35ea15c56e66cd09b63d56eEric Laurent         * The array index of near focus distance for use with
139181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent         * {@link #getFocusDistances(float[])}.
13927c1ec5f038e63a5eb8b04434577c25bc23f5f410Eric Laurent         */
13931c333e252cbca3337c1bedbc57a005f3b7d23fdbEric Laurent        public static final int FOCUS_DISTANCE_NEAR_INDEX = 0;
13941c333e252cbca3337c1bedbc57a005f3b7d23fdbEric Laurent
13951c333e252cbca3337c1bedbc57a005f3b7d23fdbEric Laurent        /**
139683b8808faad1e91690c64d7007348be8d9ebde73Eric Laurent         * The array index of optimal focus distance for use with
139783b8808faad1e91690c64d7007348be8d9ebde73Eric Laurent         * {@link #getFocusDistances(float[])}.
139883b8808faad1e91690c64d7007348be8d9ebde73Eric Laurent         */
139983b8808faad1e91690c64d7007348be8d9ebde73Eric Laurent        public static final int FOCUS_DISTANCE_OPTIMAL_INDEX = 1;
1400deca2ae0a7cf8bc54ff3f30b7dc39bbc78b94c0dGlenn Kasten
14015f972c031d4061f4f037c9fda1ea4bd9b6a756cdGlenn Kasten        /**
140281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent         * The array index of far focus distance for use with
140381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent         * {@link #getFocusDistances(float[])}.
140481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent         */
14054c415062ad1bb53e9af8f644d8215837262b79bbEric Laurent        public static final int FOCUS_DISTANCE_FAR_INDEX = 2;
140681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent
140781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent        /**
140881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent         * The array index of minimum preview fps for use with {@link
140981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent         * #getPreviewFpsRange(int[])} or {@link
1410d848eb48c121c119e8ba7583efc75415fe102570Glenn Kasten         * #getSupportedPreviewFpsRange()}.
141181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent         */
141281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent        public static final int PREVIEW_FPS_MIN_INDEX = 0;
141381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent
141481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent        /**
141581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent         * The array index of maximum preview fps for use with {@link
141681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent         * #getPreviewFpsRange(int[])} or {@link
14179b58f63e45ef2fdfb839b9b9bb3411d81eb96128Glenn Kasten         * #getSupportedPreviewFpsRange()}.
14186dbb5e3336cfff1ad51d429fcb847307c06efd61Glenn Kasten         */
141983b8808faad1e91690c64d7007348be8d9ebde73Eric Laurent        public static final int PREVIEW_FPS_MAX_INDEX = 1;
14209b58f63e45ef2fdfb839b9b9bb3411d81eb96128Glenn Kasten
14214c415062ad1bb53e9af8f644d8215837262b79bbEric Laurent        // Formats for setPreviewFormat and setPictureFormat.
14224c415062ad1bb53e9af8f644d8215837262b79bbEric Laurent        private static final String PIXEL_FORMAT_YUV422SP = "yuv422sp";
14234c415062ad1bb53e9af8f644d8215837262b79bbEric Laurent        private static final String PIXEL_FORMAT_YUV420SP = "yuv420sp";
1424dae27707fc7d8370eb200d25d1a7c6dd7ad5e201Andy Hung        private static final String PIXEL_FORMAT_YUV422I = "yuv422i-yuyv";
1425dae27707fc7d8370eb200d25d1a7c6dd7ad5e201Andy Hung        private static final String PIXEL_FORMAT_YUV420P = "yuv420p";
1426dae27707fc7d8370eb200d25d1a7c6dd7ad5e201Andy Hung        private static final String PIXEL_FORMAT_RGB565 = "rgb565";
1427dae27707fc7d8370eb200d25d1a7c6dd7ad5e201Andy Hung        private static final String PIXEL_FORMAT_JPEG = "jpeg";
1428dae27707fc7d8370eb200d25d1a7c6dd7ad5e201Andy Hung
142981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent        private HashMap<String, String> mMap;
143081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent
143193e471f620454f7de73d190521568b1e25879767Glenn Kasten        private Parameters() {
143281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent            mMap = new HashMap<String, String>();
143381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent        }
1434e198c360d5e75a9b2097844c495c10902e7e8500Glenn Kasten
143581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent        /**
143681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent         * Writes the current Parameters to the log.
143781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent         * @hide
14382b806406ac1ec680b6fe3aaa84c54bdc4e43ad8dGlenn Kasten         * @deprecated
143981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent         */
1440dae27707fc7d8370eb200d25d1a7c6dd7ad5e201Andy Hung        public void dump() {
1441dae27707fc7d8370eb200d25d1a7c6dd7ad5e201Andy Hung            Log.e(TAG, "dump: size=" + mMap.size());
144281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent            for (String k : mMap.keySet()) {
14439b58f63e45ef2fdfb839b9b9bb3411d81eb96128Glenn Kasten                Log.e(TAG, "dump: " + k + "=" + mMap.get(k));
14448594843c15b4722ced39436fe9e64f3e57e7ace4Glenn Kasten            }
14451b291841a58ce6b2b291232dfdd56134b2185c48Glenn Kasten        }
14468594843c15b4722ced39436fe9e64f3e57e7ace4Glenn Kasten
14478594843c15b4722ced39436fe9e64f3e57e7ace4Glenn Kasten        /**
14481b291841a58ce6b2b291232dfdd56134b2185c48Glenn Kasten         * Creates a single string with all the parameters set in
14496dd62fb91d82dedcfa3ab38c02eb0940b4ba932aGlenn Kasten         * this Parameters object.
14506dd62fb91d82dedcfa3ab38c02eb0940b4ba932aGlenn Kasten         * <p>The {@link #unflatten(String)} method does the reverse.</p>
14518594843c15b4722ced39436fe9e64f3e57e7ace4Glenn Kasten         *
14528594843c15b4722ced39436fe9e64f3e57e7ace4Glenn Kasten         * @return a String with all values from this Parameters object, in
145381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent         *         semi-colon delimited key-value pairs
145481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent         */
1455b880f5e5fc07397ddd09a94ba18bdf4fa62aae00Glenn Kasten        public String flatten() {
1456b880f5e5fc07397ddd09a94ba18bdf4fa62aae00Glenn Kasten            StringBuilder flattened = new StringBuilder();
14576dbb5e3336cfff1ad51d429fcb847307c06efd61Glenn Kasten            for (String k : mMap.keySet()) {
14586dbb5e3336cfff1ad51d429fcb847307c06efd61Glenn Kasten                flattened.append(k);
1459b187de1ada34a9023c05d020a4592686ba761278Glenn Kasten                flattened.append("=");
1460b187de1ada34a9023c05d020a4592686ba761278Glenn Kasten                flattened.append(mMap.get(k));
146172e3f39146fce4686bd96f11057c051bea376dfbEric Laurent                flattened.append(";");
14626dbb5e3336cfff1ad51d429fcb847307c06efd61Glenn Kasten            }
14636dbb5e3336cfff1ad51d429fcb847307c06efd61Glenn Kasten            // chop off the extra semicolon at the end
14646dbb5e3336cfff1ad51d429fcb847307c06efd61Glenn Kasten            flattened.deleteCharAt(flattened.length()-1);
14656dbb5e3336cfff1ad51d429fcb847307c06efd61Glenn Kasten            return flattened.toString();
14666dbb5e3336cfff1ad51d429fcb847307c06efd61Glenn Kasten        }
14676dbb5e3336cfff1ad51d429fcb847307c06efd61Glenn Kasten
14686dbb5e3336cfff1ad51d429fcb847307c06efd61Glenn Kasten        /**
14696dbb5e3336cfff1ad51d429fcb847307c06efd61Glenn Kasten         * Takes a flattened string of parameters and adds each one to
14706dbb5e3336cfff1ad51d429fcb847307c06efd61Glenn Kasten         * this Parameters object.
14716dbb5e3336cfff1ad51d429fcb847307c06efd61Glenn Kasten         * <p>The {@link #flatten()} method does the reverse.</p>
14726dbb5e3336cfff1ad51d429fcb847307c06efd61Glenn Kasten         *
14736dbb5e3336cfff1ad51d429fcb847307c06efd61Glenn Kasten         * @param flattened a String of parameters (key-value paired) that
14746dbb5e3336cfff1ad51d429fcb847307c06efd61Glenn Kasten         *                  are semi-colon delimited
14756dbb5e3336cfff1ad51d429fcb847307c06efd61Glenn Kasten         */
14766dbb5e3336cfff1ad51d429fcb847307c06efd61Glenn Kasten        public void unflatten(String flattened) {
14776dbb5e3336cfff1ad51d429fcb847307c06efd61Glenn Kasten            mMap.clear();
14786dbb5e3336cfff1ad51d429fcb847307c06efd61Glenn Kasten
14796dbb5e3336cfff1ad51d429fcb847307c06efd61Glenn Kasten            StringTokenizer tokenizer = new StringTokenizer(flattened, ";");
14806dbb5e3336cfff1ad51d429fcb847307c06efd61Glenn Kasten            while (tokenizer.hasMoreElements()) {
14816dbb5e3336cfff1ad51d429fcb847307c06efd61Glenn Kasten                String kv = tokenizer.nextToken();
14826dbb5e3336cfff1ad51d429fcb847307c06efd61Glenn Kasten                int pos = kv.indexOf('=');
14836dbb5e3336cfff1ad51d429fcb847307c06efd61Glenn Kasten                if (pos == -1) {
14846dbb5e3336cfff1ad51d429fcb847307c06efd61Glenn Kasten                    continue;
14856dbb5e3336cfff1ad51d429fcb847307c06efd61Glenn Kasten                }
14866dbb5e3336cfff1ad51d429fcb847307c06efd61Glenn Kasten                String k = kv.substring(0, pos);
14876dbb5e3336cfff1ad51d429fcb847307c06efd61Glenn Kasten                String v = kv.substring(pos + 1);
14886dbb5e3336cfff1ad51d429fcb847307c06efd61Glenn Kasten                mMap.put(k, v);
14896dbb5e3336cfff1ad51d429fcb847307c06efd61Glenn Kasten            }
14906dbb5e3336cfff1ad51d429fcb847307c06efd61Glenn Kasten        }
14916dbb5e3336cfff1ad51d429fcb847307c06efd61Glenn Kasten
14926dbb5e3336cfff1ad51d429fcb847307c06efd61Glenn Kasten        public void remove(String key) {
14936dbb5e3336cfff1ad51d429fcb847307c06efd61Glenn Kasten            mMap.remove(key);
14946dbb5e3336cfff1ad51d429fcb847307c06efd61Glenn Kasten        }
149581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent
1496        /**
1497         * Sets a String parameter.
1498         *
1499         * @param key   the key name for the parameter
1500         * @param value the String value of the parameter
1501         */
1502        public void set(String key, String value) {
1503            if (key.indexOf('=') != -1 || key.indexOf(';') != -1) {
1504                Log.e(TAG, "Key \"" + key + "\" contains invalid character (= or ;)");
1505                return;
1506            }
1507            if (value.indexOf('=') != -1 || value.indexOf(';') != -1) {
1508                Log.e(TAG, "Value \"" + value + "\" contains invalid character (= or ;)");
1509                return;
1510            }
1511
1512            mMap.put(key, value);
1513        }
1514
1515        /**
1516         * Sets an integer parameter.
1517         *
1518         * @param key   the key name for the parameter
1519         * @param value the int value of the parameter
1520         */
1521        public void set(String key, int value) {
1522            mMap.put(key, Integer.toString(value));
1523        }
1524
1525        private void set(String key, List<Area> areas) {
1526            if (areas == null) {
1527                set(key, "(0,0,0,0,0)");
1528            } else {
1529                StringBuilder buffer = new StringBuilder();
1530                for (int i = 0; i < areas.size(); i++) {
1531                    Area area = areas.get(i);
1532                    Rect rect = area.rect;
1533                    buffer.append('(');
1534                    buffer.append(rect.left);
1535                    buffer.append(',');
1536                    buffer.append(rect.top);
1537                    buffer.append(',');
1538                    buffer.append(rect.right);
1539                    buffer.append(',');
1540                    buffer.append(rect.bottom);
1541                    buffer.append(',');
1542                    buffer.append(area.weight);
1543                    buffer.append(')');
1544                    if (i != areas.size() - 1) buffer.append(',');
1545                }
1546                set(key, buffer.toString());
1547            }
1548        }
1549
1550        /**
1551         * Returns the value of a String parameter.
1552         *
1553         * @param key the key name for the parameter
1554         * @return the String value of the parameter
1555         */
1556        public String get(String key) {
1557            return mMap.get(key);
1558        }
1559
1560        /**
1561         * Returns the value of an integer parameter.
1562         *
1563         * @param key the key name for the parameter
1564         * @return the int value of the parameter
1565         */
1566        public int getInt(String key) {
1567            return Integer.parseInt(mMap.get(key));
1568        }
1569
1570        /**
1571         * Sets the dimensions for preview pictures. If the preview has already
1572         * started, applications should stop the preview first before changing
1573         * preview size.
1574         *
1575         * The sides of width and height are based on camera orientation. That
1576         * is, the preview size is the size before it is rotated by display
1577         * orientation. So applications need to consider the display orientation
1578         * while setting preview size. For example, suppose the camera supports
1579         * both 480x320 and 320x480 preview sizes. The application wants a 3:2
1580         * preview ratio. If the display orientation is set to 0 or 180, preview
1581         * size should be set to 480x320. If the display orientation is set to
1582         * 90 or 270, preview size should be set to 320x480. The display
1583         * orientation should also be considered while setting picture size and
1584         * thumbnail size.
1585         *
1586         * @param width  the width of the pictures, in pixels
1587         * @param height the height of the pictures, in pixels
1588         * @see #setDisplayOrientation(int)
1589         * @see #getCameraInfo(int, CameraInfo)
1590         * @see #setPictureSize(int, int)
1591         * @see #setJpegThumbnailSize(int, int)
1592         */
1593        public void setPreviewSize(int width, int height) {
1594            String v = Integer.toString(width) + "x" + Integer.toString(height);
1595            set(KEY_PREVIEW_SIZE, v);
1596        }
1597
1598        /**
1599         * Returns the dimensions setting for preview pictures.
1600         *
1601         * @return a Size object with the width and height setting
1602         *          for the preview picture
1603         */
1604        public Size getPreviewSize() {
1605            String pair = get(KEY_PREVIEW_SIZE);
1606            return strToSize(pair);
1607        }
1608
1609        /**
1610         * Gets the supported preview sizes.
1611         *
1612         * @return a list of Size object. This method will always return a list
1613         *         with at least one element.
1614         */
1615        public List<Size> getSupportedPreviewSizes() {
1616            String str = get(KEY_PREVIEW_SIZE + SUPPORTED_VALUES_SUFFIX);
1617            return splitSize(str);
1618        }
1619
1620        /**
1621         * Gets the supported video frame sizes that can be used by
1622         * MediaRecorder.
1623         *
1624         * If the returned list is not null, the returned list will contain at
1625         * least one Size and one of the sizes in the returned list must be
1626         * passed to MediaRecorder.setVideoSize() for camcorder application if
1627         * camera is used as the video source. In this case, the size of the
1628         * preview can be different from the resolution of the recorded video
1629         * during video recording.
1630         *
1631         * @return a list of Size object if camera has separate preview and
1632         *         video output; otherwise, null is returned.
1633         * @see #getPreferredPreviewSizeForVideo()
1634         */
1635        public List<Size> getSupportedVideoSizes() {
1636            String str = get(KEY_VIDEO_SIZE + SUPPORTED_VALUES_SUFFIX);
1637            return splitSize(str);
1638        }
1639
1640        /**
1641         * Returns the preferred or recommended preview size (width and height)
1642         * in pixels for video recording. Camcorder applications should
1643         * set the preview size to a value that is not larger than the
1644         * preferred preview size. In other words, the product of the width
1645         * and height of the preview size should not be larger than that of
1646         * the preferred preview size. In addition, we recommend to choose a
1647         * preview size that has the same aspect ratio as the resolution of
1648         * video to be recorded.
1649         *
1650         * @return the preferred preview size (width and height) in pixels for
1651         *         video recording if getSupportedVideoSizes() does not return
1652         *         null; otherwise, null is returned.
1653         * @see #getSupportedVideoSizes()
1654         */
1655        public Size getPreferredPreviewSizeForVideo() {
1656            String pair = get(KEY_PREFERRED_PREVIEW_SIZE_FOR_VIDEO);
1657            return strToSize(pair);
1658        }
1659
1660        /**
1661         * Sets the dimensions for EXIF thumbnail in Jpeg picture. If
1662         * applications set both width and height to 0, EXIF will not contain
1663         * thumbnail.
1664         *
1665         * Applications need to consider the display orientation. See {@link
1666         * #setPreviewSize(int,int)} for reference.
1667         *
1668         * @param width  the width of the thumbnail, in pixels
1669         * @param height the height of the thumbnail, in pixels
1670         * @see #setPreviewSize(int,int)
1671         */
1672        public void setJpegThumbnailSize(int width, int height) {
1673            set(KEY_JPEG_THUMBNAIL_WIDTH, width);
1674            set(KEY_JPEG_THUMBNAIL_HEIGHT, height);
1675        }
1676
1677        /**
1678         * Returns the dimensions for EXIF thumbnail in Jpeg picture.
1679         *
1680         * @return a Size object with the height and width setting for the EXIF
1681         *         thumbnails
1682         */
1683        public Size getJpegThumbnailSize() {
1684            return new Size(getInt(KEY_JPEG_THUMBNAIL_WIDTH),
1685                            getInt(KEY_JPEG_THUMBNAIL_HEIGHT));
1686        }
1687
1688        /**
1689         * Gets the supported jpeg thumbnail sizes.
1690         *
1691         * @return a list of Size object. This method will always return a list
1692         *         with at least two elements. Size 0,0 (no thumbnail) is always
1693         *         supported.
1694         */
1695        public List<Size> getSupportedJpegThumbnailSizes() {
1696            String str = get(KEY_JPEG_THUMBNAIL_SIZE + SUPPORTED_VALUES_SUFFIX);
1697            return splitSize(str);
1698        }
1699
1700        /**
1701         * Sets the quality of the EXIF thumbnail in Jpeg picture.
1702         *
1703         * @param quality the JPEG quality of the EXIF thumbnail. The range is 1
1704         *                to 100, with 100 being the best.
1705         */
1706        public void setJpegThumbnailQuality(int quality) {
1707            set(KEY_JPEG_THUMBNAIL_QUALITY, quality);
1708        }
1709
1710        /**
1711         * Returns the quality setting for the EXIF thumbnail in Jpeg picture.
1712         *
1713         * @return the JPEG quality setting of the EXIF thumbnail.
1714         */
1715        public int getJpegThumbnailQuality() {
1716            return getInt(KEY_JPEG_THUMBNAIL_QUALITY);
1717        }
1718
1719        /**
1720         * Sets Jpeg quality of captured picture.
1721         *
1722         * @param quality the JPEG quality of captured picture. The range is 1
1723         *                to 100, with 100 being the best.
1724         */
1725        public void setJpegQuality(int quality) {
1726            set(KEY_JPEG_QUALITY, quality);
1727        }
1728
1729        /**
1730         * Returns the quality setting for the JPEG picture.
1731         *
1732         * @return the JPEG picture quality setting.
1733         */
1734        public int getJpegQuality() {
1735            return getInt(KEY_JPEG_QUALITY);
1736        }
1737
1738        /**
1739         * Sets the rate at which preview frames are received. This is the
1740         * target frame rate. The actual frame rate depends on the driver.
1741         *
1742         * @param fps the frame rate (frames per second)
1743         * @deprecated replaced by {@link #setPreviewFpsRange(int,int)}
1744         */
1745        @Deprecated
1746        public void setPreviewFrameRate(int fps) {
1747            set(KEY_PREVIEW_FRAME_RATE, fps);
1748        }
1749
1750        /**
1751         * Returns the setting for the rate at which preview frames are
1752         * received. This is the target frame rate. The actual frame rate
1753         * depends on the driver.
1754         *
1755         * @return the frame rate setting (frames per second)
1756         * @deprecated replaced by {@link #getPreviewFpsRange(int[])}
1757         */
1758        @Deprecated
1759        public int getPreviewFrameRate() {
1760            return getInt(KEY_PREVIEW_FRAME_RATE);
1761        }
1762
1763        /**
1764         * Gets the supported preview frame rates.
1765         *
1766         * @return a list of supported preview frame rates. null if preview
1767         *         frame rate setting is not supported.
1768         * @deprecated replaced by {@link #getSupportedPreviewFpsRange()}
1769         */
1770        @Deprecated
1771        public List<Integer> getSupportedPreviewFrameRates() {
1772            String str = get(KEY_PREVIEW_FRAME_RATE + SUPPORTED_VALUES_SUFFIX);
1773            return splitInt(str);
1774        }
1775
1776        /**
1777         * Sets the maximum and maximum preview fps. This controls the rate of
1778         * preview frames received in {@link PreviewCallback}. The minimum and
1779         * maximum preview fps must be one of the elements from {@link
1780         * #getSupportedPreviewFpsRange}.
1781         *
1782         * @param min the minimum preview fps (scaled by 1000).
1783         * @param max the maximum preview fps (scaled by 1000).
1784         * @throws RuntimeException if fps range is invalid.
1785         * @see #setPreviewCallbackWithBuffer(Camera.PreviewCallback)
1786         * @see #getSupportedPreviewFpsRange()
1787         */
1788        public void setPreviewFpsRange(int min, int max) {
1789            set(KEY_PREVIEW_FPS_RANGE, "" + min + "," + max);
1790        }
1791
1792        /**
1793         * Returns the current minimum and maximum preview fps. The values are
1794         * one of the elements returned by {@link #getSupportedPreviewFpsRange}.
1795         *
1796         * @return range the minimum and maximum preview fps (scaled by 1000).
1797         * @see #PREVIEW_FPS_MIN_INDEX
1798         * @see #PREVIEW_FPS_MAX_INDEX
1799         * @see #getSupportedPreviewFpsRange()
1800         */
1801        public void getPreviewFpsRange(int[] range) {
1802            if (range == null || range.length != 2) {
1803                throw new IllegalArgumentException(
1804                        "range must be an array with two elements.");
1805            }
1806            splitInt(get(KEY_PREVIEW_FPS_RANGE), range);
1807        }
1808
1809        /**
1810         * Gets the supported preview fps (frame-per-second) ranges. Each range
1811         * contains a minimum fps and maximum fps. If minimum fps equals to
1812         * maximum fps, the camera outputs frames in fixed frame rate. If not,
1813         * the camera outputs frames in auto frame rate. The actual frame rate
1814         * fluctuates between the minimum and the maximum. The values are
1815         * multiplied by 1000 and represented in integers. For example, if frame
1816         * rate is 26.623 frames per second, the value is 26623.
1817         *
1818         * @return a list of supported preview fps ranges. This method returns a
1819         *         list with at least one element. Every element is an int array
1820         *         of two values - minimum fps and maximum fps. The list is
1821         *         sorted from small to large (first by maximum fps and then
1822         *         minimum fps).
1823         * @see #PREVIEW_FPS_MIN_INDEX
1824         * @see #PREVIEW_FPS_MAX_INDEX
1825         */
1826        public List<int[]> getSupportedPreviewFpsRange() {
1827            String str = get(KEY_PREVIEW_FPS_RANGE + SUPPORTED_VALUES_SUFFIX);
1828            return splitRange(str);
1829        }
1830
1831        /**
1832         * Sets the image format for preview pictures.
1833         * <p>If this is never called, the default format will be
1834         * {@link android.graphics.ImageFormat#NV21}, which
1835         * uses the NV21 encoding format.</p>
1836         *
1837         * @param pixel_format the desired preview picture format, defined
1838         *   by one of the {@link android.graphics.ImageFormat} constants.
1839         *   (E.g., <var>ImageFormat.NV21</var> (default),
1840         *                      <var>ImageFormat.RGB_565</var>, or
1841         *                      <var>ImageFormat.JPEG</var>)
1842         * @see android.graphics.ImageFormat
1843         */
1844        public void setPreviewFormat(int pixel_format) {
1845            String s = cameraFormatForPixelFormat(pixel_format);
1846            if (s == null) {
1847                throw new IllegalArgumentException(
1848                        "Invalid pixel_format=" + pixel_format);
1849            }
1850
1851            set(KEY_PREVIEW_FORMAT, s);
1852        }
1853
1854        /**
1855         * Returns the image format for preview frames got from
1856         * {@link PreviewCallback}.
1857         *
1858         * @return the preview format.
1859         * @see android.graphics.ImageFormat
1860         */
1861        public int getPreviewFormat() {
1862            return pixelFormatForCameraFormat(get(KEY_PREVIEW_FORMAT));
1863        }
1864
1865        /**
1866         * Gets the supported preview formats. {@link android.graphics.ImageFormat#NV21}
1867         * is always supported. {@link android.graphics.ImageFormat#YV12}
1868         * is always supported since API level 12.
1869         *
1870         * @return a list of supported preview formats. This method will always
1871         *         return a list with at least one element.
1872         * @see android.graphics.ImageFormat
1873         */
1874        public List<Integer> getSupportedPreviewFormats() {
1875            String str = get(KEY_PREVIEW_FORMAT + SUPPORTED_VALUES_SUFFIX);
1876            ArrayList<Integer> formats = new ArrayList<Integer>();
1877            for (String s : split(str)) {
1878                int f = pixelFormatForCameraFormat(s);
1879                if (f == ImageFormat.UNKNOWN) continue;
1880                formats.add(f);
1881            }
1882            return formats;
1883        }
1884
1885        /**
1886         * Sets the dimensions for pictures.
1887         *
1888         * Applications need to consider the display orientation. See {@link
1889         * #setPreviewSize(int,int)} for reference.
1890         *
1891         * @param width  the width for pictures, in pixels
1892         * @param height the height for pictures, in pixels
1893         * @see #setPreviewSize(int,int)
1894         *
1895         */
1896        public void setPictureSize(int width, int height) {
1897            String v = Integer.toString(width) + "x" + Integer.toString(height);
1898            set(KEY_PICTURE_SIZE, v);
1899        }
1900
1901        /**
1902         * Returns the dimension setting for pictures.
1903         *
1904         * @return a Size object with the height and width setting
1905         *          for pictures
1906         */
1907        public Size getPictureSize() {
1908            String pair = get(KEY_PICTURE_SIZE);
1909            return strToSize(pair);
1910        }
1911
1912        /**
1913         * Gets the supported picture sizes.
1914         *
1915         * @return a list of supported picture sizes. This method will always
1916         *         return a list with at least one element.
1917         */
1918        public List<Size> getSupportedPictureSizes() {
1919            String str = get(KEY_PICTURE_SIZE + SUPPORTED_VALUES_SUFFIX);
1920            return splitSize(str);
1921        }
1922
1923        /**
1924         * Sets the image format for pictures.
1925         *
1926         * @param pixel_format the desired picture format
1927         *                     (<var>ImageFormat.NV21</var>,
1928         *                      <var>ImageFormat.RGB_565</var>, or
1929         *                      <var>ImageFormat.JPEG</var>)
1930         * @see android.graphics.ImageFormat
1931         */
1932        public void setPictureFormat(int pixel_format) {
1933            String s = cameraFormatForPixelFormat(pixel_format);
1934            if (s == null) {
1935                throw new IllegalArgumentException(
1936                        "Invalid pixel_format=" + pixel_format);
1937            }
1938
1939            set(KEY_PICTURE_FORMAT, s);
1940        }
1941
1942        /**
1943         * Returns the image format for pictures.
1944         *
1945         * @return the picture format
1946         * @see android.graphics.ImageFormat
1947         */
1948        public int getPictureFormat() {
1949            return pixelFormatForCameraFormat(get(KEY_PICTURE_FORMAT));
1950        }
1951
1952        /**
1953         * Gets the supported picture formats.
1954         *
1955         * @return supported picture formats. This method will always return a
1956         *         list with at least one element.
1957         * @see android.graphics.ImageFormat
1958         */
1959        public List<Integer> getSupportedPictureFormats() {
1960            String str = get(KEY_PICTURE_FORMAT + SUPPORTED_VALUES_SUFFIX);
1961            ArrayList<Integer> formats = new ArrayList<Integer>();
1962            for (String s : split(str)) {
1963                int f = pixelFormatForCameraFormat(s);
1964                if (f == ImageFormat.UNKNOWN) continue;
1965                formats.add(f);
1966            }
1967            return formats;
1968        }
1969
1970        private String cameraFormatForPixelFormat(int pixel_format) {
1971            switch(pixel_format) {
1972            case ImageFormat.NV16:      return PIXEL_FORMAT_YUV422SP;
1973            case ImageFormat.NV21:      return PIXEL_FORMAT_YUV420SP;
1974            case ImageFormat.YUY2:      return PIXEL_FORMAT_YUV422I;
1975            case ImageFormat.YV12:      return PIXEL_FORMAT_YUV420P;
1976            case ImageFormat.RGB_565:   return PIXEL_FORMAT_RGB565;
1977            case ImageFormat.JPEG:      return PIXEL_FORMAT_JPEG;
1978            default:                    return null;
1979            }
1980        }
1981
1982        private int pixelFormatForCameraFormat(String format) {
1983            if (format == null)
1984                return ImageFormat.UNKNOWN;
1985
1986            if (format.equals(PIXEL_FORMAT_YUV422SP))
1987                return ImageFormat.NV16;
1988
1989            if (format.equals(PIXEL_FORMAT_YUV420SP))
1990                return ImageFormat.NV21;
1991
1992            if (format.equals(PIXEL_FORMAT_YUV422I))
1993                return ImageFormat.YUY2;
1994
1995            if (format.equals(PIXEL_FORMAT_YUV420P))
1996                return ImageFormat.YV12;
1997
1998            if (format.equals(PIXEL_FORMAT_RGB565))
1999                return ImageFormat.RGB_565;
2000
2001            if (format.equals(PIXEL_FORMAT_JPEG))
2002                return ImageFormat.JPEG;
2003
2004            return ImageFormat.UNKNOWN;
2005        }
2006
2007        /**
2008         * Sets the rotation angle in degrees relative to the orientation of
2009         * the camera. This affects the pictures returned from JPEG {@link
2010         * PictureCallback}. The camera driver may set orientation in the
2011         * EXIF header without rotating the picture. Or the driver may rotate
2012         * the picture and the EXIF thumbnail. If the Jpeg picture is rotated,
2013         * the orientation in the EXIF header will be missing or 1 (row #0 is
2014         * top and column #0 is left side).
2015         *
2016         * <p>If applications want to rotate the picture to match the orientation
2017         * of what users see, apps should use {@link
2018         * android.view.OrientationEventListener} and {@link CameraInfo}.
2019         * The value from OrientationEventListener is relative to the natural
2020         * orientation of the device. CameraInfo.orientation is the angle
2021         * between camera orientation and natural device orientation. The sum
2022         * of the two is the rotation angle for back-facing camera. The
2023         * difference of the two is the rotation angle for front-facing camera.
2024         * Note that the JPEG pictures of front-facing cameras are not mirrored
2025         * as in preview display.
2026         *
2027         * <p>For example, suppose the natural orientation of the device is
2028         * portrait. The device is rotated 270 degrees clockwise, so the device
2029         * orientation is 270. Suppose a back-facing camera sensor is mounted in
2030         * landscape and the top side of the camera sensor is aligned with the
2031         * right edge of the display in natural orientation. So the camera
2032         * orientation is 90. The rotation should be set to 0 (270 + 90).
2033         *
2034         * <p>The reference code is as follows.
2035         *
2036	 * <pre>
2037         * public void public void onOrientationChanged(int orientation) {
2038         *     if (orientation == ORIENTATION_UNKNOWN) return;
2039         *     android.hardware.Camera.CameraInfo info =
2040         *            new android.hardware.Camera.CameraInfo();
2041         *     android.hardware.Camera.getCameraInfo(cameraId, info);
2042         *     orientation = (orientation + 45) / 90 * 90;
2043         *     int rotation = 0;
2044         *     if (info.facing == CameraInfo.CAMERA_FACING_FRONT) {
2045         *         rotation = (info.orientation - orientation + 360) % 360;
2046         *     } else {  // back-facing camera
2047         *         rotation = (info.orientation + orientation) % 360;
2048         *     }
2049         *     mParameters.setRotation(rotation);
2050         * }
2051	 * </pre>
2052         *
2053         * @param rotation The rotation angle in degrees relative to the
2054         *                 orientation of the camera. Rotation can only be 0,
2055         *                 90, 180 or 270.
2056         * @throws IllegalArgumentException if rotation value is invalid.
2057         * @see android.view.OrientationEventListener
2058         * @see #getCameraInfo(int, CameraInfo)
2059         */
2060        public void setRotation(int rotation) {
2061            if (rotation == 0 || rotation == 90 || rotation == 180
2062                    || rotation == 270) {
2063                set(KEY_ROTATION, Integer.toString(rotation));
2064            } else {
2065                throw new IllegalArgumentException(
2066                        "Invalid rotation=" + rotation);
2067            }
2068        }
2069
2070        /**
2071         * Sets GPS latitude coordinate. This will be stored in JPEG EXIF
2072         * header.
2073         *
2074         * @param latitude GPS latitude coordinate.
2075         */
2076        public void setGpsLatitude(double latitude) {
2077            set(KEY_GPS_LATITUDE, Double.toString(latitude));
2078        }
2079
2080        /**
2081         * Sets GPS longitude coordinate. This will be stored in JPEG EXIF
2082         * header.
2083         *
2084         * @param longitude GPS longitude coordinate.
2085         */
2086        public void setGpsLongitude(double longitude) {
2087            set(KEY_GPS_LONGITUDE, Double.toString(longitude));
2088        }
2089
2090        /**
2091         * Sets GPS altitude. This will be stored in JPEG EXIF header.
2092         *
2093         * @param altitude GPS altitude in meters.
2094         */
2095        public void setGpsAltitude(double altitude) {
2096            set(KEY_GPS_ALTITUDE, Double.toString(altitude));
2097        }
2098
2099        /**
2100         * Sets GPS timestamp. This will be stored in JPEG EXIF header.
2101         *
2102         * @param timestamp GPS timestamp (UTC in seconds since January 1,
2103         *                  1970).
2104         */
2105        public void setGpsTimestamp(long timestamp) {
2106            set(KEY_GPS_TIMESTAMP, Long.toString(timestamp));
2107        }
2108
2109        /**
2110         * Sets GPS processing method. It will store up to 32 characters
2111         * in JPEG EXIF header.
2112         *
2113         * @param processing_method The processing method to get this location.
2114         */
2115        public void setGpsProcessingMethod(String processing_method) {
2116            set(KEY_GPS_PROCESSING_METHOD, processing_method);
2117        }
2118
2119        /**
2120         * Removes GPS latitude, longitude, altitude, and timestamp from the
2121         * parameters.
2122         */
2123        public void removeGpsData() {
2124            remove(KEY_GPS_LATITUDE);
2125            remove(KEY_GPS_LONGITUDE);
2126            remove(KEY_GPS_ALTITUDE);
2127            remove(KEY_GPS_TIMESTAMP);
2128            remove(KEY_GPS_PROCESSING_METHOD);
2129        }
2130
2131        /**
2132         * Gets the current white balance setting.
2133         *
2134         * @return current white balance. null if white balance setting is not
2135         *         supported.
2136         * @see #WHITE_BALANCE_AUTO
2137         * @see #WHITE_BALANCE_INCANDESCENT
2138         * @see #WHITE_BALANCE_FLUORESCENT
2139         * @see #WHITE_BALANCE_WARM_FLUORESCENT
2140         * @see #WHITE_BALANCE_DAYLIGHT
2141         * @see #WHITE_BALANCE_CLOUDY_DAYLIGHT
2142         * @see #WHITE_BALANCE_TWILIGHT
2143         * @see #WHITE_BALANCE_SHADE
2144         *
2145         */
2146        public String getWhiteBalance() {
2147            return get(KEY_WHITE_BALANCE);
2148        }
2149
2150        /**
2151         * Sets the white balance.
2152         *
2153         * @param value new white balance.
2154         * @see #getWhiteBalance()
2155         */
2156        public void setWhiteBalance(String value) {
2157            set(KEY_WHITE_BALANCE, value);
2158        }
2159
2160        /**
2161         * Gets the supported white balance.
2162         *
2163         * @return a list of supported white balance. null if white balance
2164         *         setting is not supported.
2165         * @see #getWhiteBalance()
2166         */
2167        public List<String> getSupportedWhiteBalance() {
2168            String str = get(KEY_WHITE_BALANCE + SUPPORTED_VALUES_SUFFIX);
2169            return split(str);
2170        }
2171
2172        /**
2173         * Gets the current color effect setting.
2174         *
2175         * @return current color effect. null if color effect
2176         *         setting is not supported.
2177         * @see #EFFECT_NONE
2178         * @see #EFFECT_MONO
2179         * @see #EFFECT_NEGATIVE
2180         * @see #EFFECT_SOLARIZE
2181         * @see #EFFECT_SEPIA
2182         * @see #EFFECT_POSTERIZE
2183         * @see #EFFECT_WHITEBOARD
2184         * @see #EFFECT_BLACKBOARD
2185         * @see #EFFECT_AQUA
2186         */
2187        public String getColorEffect() {
2188            return get(KEY_EFFECT);
2189        }
2190
2191        /**
2192         * Sets the current color effect setting.
2193         *
2194         * @param value new color effect.
2195         * @see #getColorEffect()
2196         */
2197        public void setColorEffect(String value) {
2198            set(KEY_EFFECT, value);
2199        }
2200
2201        /**
2202         * Gets the supported color effects.
2203         *
2204         * @return a list of supported color effects. null if color effect
2205         *         setting is not supported.
2206         * @see #getColorEffect()
2207         */
2208        public List<String> getSupportedColorEffects() {
2209            String str = get(KEY_EFFECT + SUPPORTED_VALUES_SUFFIX);
2210            return split(str);
2211        }
2212
2213
2214        /**
2215         * Gets the current antibanding setting.
2216         *
2217         * @return current antibanding. null if antibanding setting is not
2218         *         supported.
2219         * @see #ANTIBANDING_AUTO
2220         * @see #ANTIBANDING_50HZ
2221         * @see #ANTIBANDING_60HZ
2222         * @see #ANTIBANDING_OFF
2223         */
2224        public String getAntibanding() {
2225            return get(KEY_ANTIBANDING);
2226        }
2227
2228        /**
2229         * Sets the antibanding.
2230         *
2231         * @param antibanding new antibanding value.
2232         * @see #getAntibanding()
2233         */
2234        public void setAntibanding(String antibanding) {
2235            set(KEY_ANTIBANDING, antibanding);
2236        }
2237
2238        /**
2239         * Gets the supported antibanding values.
2240         *
2241         * @return a list of supported antibanding values. null if antibanding
2242         *         setting is not supported.
2243         * @see #getAntibanding()
2244         */
2245        public List<String> getSupportedAntibanding() {
2246            String str = get(KEY_ANTIBANDING + SUPPORTED_VALUES_SUFFIX);
2247            return split(str);
2248        }
2249
2250        /**
2251         * Gets the current scene mode setting.
2252         *
2253         * @return one of SCENE_MODE_XXX string constant. null if scene mode
2254         *         setting is not supported.
2255         * @see #SCENE_MODE_AUTO
2256         * @see #SCENE_MODE_ACTION
2257         * @see #SCENE_MODE_PORTRAIT
2258         * @see #SCENE_MODE_LANDSCAPE
2259         * @see #SCENE_MODE_NIGHT
2260         * @see #SCENE_MODE_NIGHT_PORTRAIT
2261         * @see #SCENE_MODE_THEATRE
2262         * @see #SCENE_MODE_BEACH
2263         * @see #SCENE_MODE_SNOW
2264         * @see #SCENE_MODE_SUNSET
2265         * @see #SCENE_MODE_STEADYPHOTO
2266         * @see #SCENE_MODE_FIREWORKS
2267         * @see #SCENE_MODE_SPORTS
2268         * @see #SCENE_MODE_PARTY
2269         * @see #SCENE_MODE_CANDLELIGHT
2270         */
2271        public String getSceneMode() {
2272            return get(KEY_SCENE_MODE);
2273        }
2274
2275        /**
2276         * Sets the scene mode. Changing scene mode may override other
2277         * parameters (such as flash mode, focus mode, white balance). For
2278         * example, suppose originally flash mode is on and supported flash
2279         * modes are on/off. In night scene mode, both flash mode and supported
2280         * flash mode may be changed to off. After setting scene mode,
2281         * applications should call getParameters to know if some parameters are
2282         * changed.
2283         *
2284         * @param value scene mode.
2285         * @see #getSceneMode()
2286         */
2287        public void setSceneMode(String value) {
2288            set(KEY_SCENE_MODE, value);
2289        }
2290
2291        /**
2292         * Gets the supported scene modes.
2293         *
2294         * @return a list of supported scene modes. null if scene mode setting
2295         *         is not supported.
2296         * @see #getSceneMode()
2297         */
2298        public List<String> getSupportedSceneModes() {
2299            String str = get(KEY_SCENE_MODE + SUPPORTED_VALUES_SUFFIX);
2300            return split(str);
2301        }
2302
2303        /**
2304         * Gets the current flash mode setting.
2305         *
2306         * @return current flash mode. null if flash mode setting is not
2307         *         supported.
2308         * @see #FLASH_MODE_OFF
2309         * @see #FLASH_MODE_AUTO
2310         * @see #FLASH_MODE_ON
2311         * @see #FLASH_MODE_RED_EYE
2312         * @see #FLASH_MODE_TORCH
2313         */
2314        public String getFlashMode() {
2315            return get(KEY_FLASH_MODE);
2316        }
2317
2318        /**
2319         * Sets the flash mode.
2320         *
2321         * @param value flash mode.
2322         * @see #getFlashMode()
2323         */
2324        public void setFlashMode(String value) {
2325            set(KEY_FLASH_MODE, value);
2326        }
2327
2328        /**
2329         * Gets the supported flash modes.
2330         *
2331         * @return a list of supported flash modes. null if flash mode setting
2332         *         is not supported.
2333         * @see #getFlashMode()
2334         */
2335        public List<String> getSupportedFlashModes() {
2336            String str = get(KEY_FLASH_MODE + SUPPORTED_VALUES_SUFFIX);
2337            return split(str);
2338        }
2339
2340        /**
2341         * Gets the current focus mode setting.
2342         *
2343         * @return current focus mode. This method will always return a non-null
2344         *         value. Applications should call {@link
2345         *         #autoFocus(AutoFocusCallback)} to start the focus if focus
2346         *         mode is FOCUS_MODE_AUTO or FOCUS_MODE_MACRO.
2347         * @see #FOCUS_MODE_AUTO
2348         * @see #FOCUS_MODE_INFINITY
2349         * @see #FOCUS_MODE_MACRO
2350         * @see #FOCUS_MODE_FIXED
2351         * @see #FOCUS_MODE_EDOF
2352         * @see #FOCUS_MODE_CONTINUOUS_VIDEO
2353         */
2354        public String getFocusMode() {
2355            return get(KEY_FOCUS_MODE);
2356        }
2357
2358        /**
2359         * Sets the focus mode.
2360         *
2361         * @param value focus mode.
2362         * @see #getFocusMode()
2363         */
2364        public void setFocusMode(String value) {
2365            set(KEY_FOCUS_MODE, value);
2366        }
2367
2368        /**
2369         * Gets the supported focus modes.
2370         *
2371         * @return a list of supported focus modes. This method will always
2372         *         return a list with at least one element.
2373         * @see #getFocusMode()
2374         */
2375        public List<String> getSupportedFocusModes() {
2376            String str = get(KEY_FOCUS_MODE + SUPPORTED_VALUES_SUFFIX);
2377            return split(str);
2378        }
2379
2380        /**
2381         * Gets the focal length (in millimeter) of the camera.
2382         *
2383         * @return the focal length. This method will always return a valid
2384         *         value.
2385         */
2386        public float getFocalLength() {
2387            return Float.parseFloat(get(KEY_FOCAL_LENGTH));
2388        }
2389
2390        /**
2391         * Gets the horizontal angle of view in degrees.
2392         *
2393         * @return horizontal angle of view. This method will always return a
2394         *         valid value.
2395         */
2396        public float getHorizontalViewAngle() {
2397            return Float.parseFloat(get(KEY_HORIZONTAL_VIEW_ANGLE));
2398        }
2399
2400        /**
2401         * Gets the vertical angle of view in degrees.
2402         *
2403         * @return vertical angle of view. This method will always return a
2404         *         valid value.
2405         */
2406        public float getVerticalViewAngle() {
2407            return Float.parseFloat(get(KEY_VERTICAL_VIEW_ANGLE));
2408        }
2409
2410        /**
2411         * Gets the current exposure compensation index.
2412         *
2413         * @return current exposure compensation index. The range is {@link
2414         *         #getMinExposureCompensation} to {@link
2415         *         #getMaxExposureCompensation}. 0 means exposure is not
2416         *         adjusted.
2417         */
2418        public int getExposureCompensation() {
2419            return getInt(KEY_EXPOSURE_COMPENSATION, 0);
2420        }
2421
2422        /**
2423         * Sets the exposure compensation index.
2424         *
2425         * @param value exposure compensation index. The valid value range is
2426         *        from {@link #getMinExposureCompensation} (inclusive) to {@link
2427         *        #getMaxExposureCompensation} (inclusive). 0 means exposure is
2428         *        not adjusted. Application should call
2429         *        getMinExposureCompensation and getMaxExposureCompensation to
2430         *        know if exposure compensation is supported.
2431         */
2432        public void setExposureCompensation(int value) {
2433            set(KEY_EXPOSURE_COMPENSATION, value);
2434        }
2435
2436        /**
2437         * Gets the maximum exposure compensation index.
2438         *
2439         * @return maximum exposure compensation index (>=0). If both this
2440         *         method and {@link #getMinExposureCompensation} return 0,
2441         *         exposure compensation is not supported.
2442         */
2443        public int getMaxExposureCompensation() {
2444            return getInt(KEY_MAX_EXPOSURE_COMPENSATION, 0);
2445        }
2446
2447        /**
2448         * Gets the minimum exposure compensation index.
2449         *
2450         * @return minimum exposure compensation index (<=0). If both this
2451         *         method and {@link #getMaxExposureCompensation} return 0,
2452         *         exposure compensation is not supported.
2453         */
2454        public int getMinExposureCompensation() {
2455            return getInt(KEY_MIN_EXPOSURE_COMPENSATION, 0);
2456        }
2457
2458        /**
2459         * Gets the exposure compensation step.
2460         *
2461         * @return exposure compensation step. Applications can get EV by
2462         *         multiplying the exposure compensation index and step. Ex: if
2463         *         exposure compensation index is -6 and step is 0.333333333, EV
2464         *         is -2.
2465         */
2466        public float getExposureCompensationStep() {
2467            return getFloat(KEY_EXPOSURE_COMPENSATION_STEP, 0);
2468        }
2469
2470        /**
2471         * Sets the auto-exposure lock state. Applications should check
2472         * {@link #isAutoExposureLockSupported} before using this method.
2473         *
2474         * If set to true, the camera auto-exposure routine will pause until the
2475         * lock is set to false. Exposure compensation settings changes will
2476         * still take effect while auto-exposure is locked. Stopping preview
2477         * with {@link #stopPreview()}, or triggering still image capture with
2478         * {@link #takePicture(Camera.ShutterCallback, Camera.PictureCallback,
2479         * Camera.PictureCallback)}, will automatically set the lock to
2480         * false. However, the lock can be re-enabled before preview is
2481         * re-started to keep the same AE parameters. Exposure compensation, in
2482         * conjunction with re-enabling the AE lock after each still capture,
2483         * can be used to capture an exposure-bracketed burst of images, for
2484         * example. Auto-exposure state, including the lock state, will not be
2485         * maintained after camera {@link #release()} is called.  Locking
2486         * auto-exposure after {@link #open()} but before the first call to
2487         * {@link #startPreview()} will not allow the auto-exposure routine to
2488         * run at all, and may result in severely over- or under-exposed images.
2489         *
2490         * The driver may also independently lock auto-exposure after auto-focus
2491         * completes. If this is undesirable, be sure to always set the
2492         * auto-exposure lock to false after the
2493         * {@link AutoFocusCallback#onAutoFocus(boolean, Camera)} callback is
2494         * received. The {@link #getAutoExposureLock()} method can be used after
2495         * the callback to determine if the camera has locked auto-exposure
2496         * independently.
2497         *
2498         * @param toggle new state of the auto-exposure lock. True means that
2499         *        auto-exposure is locked, false means that the auto-exposure
2500         *        routine is free to run normally.
2501         *
2502         * @hide
2503         */
2504        public void setAutoExposureLock(boolean toggle) {
2505            set(KEY_AUTO_EXPOSURE_LOCK, toggle ? TRUE : FALSE);
2506        }
2507
2508        /**
2509         * Gets the state of the auto-exposure lock. Applications should check
2510         * {@link #isAutoExposureLockSupported} before using this method. See
2511         * {@link #setAutoExposureLock} for details about the lock.
2512         *
2513         * @return State of the auto-exposure lock. Returns true if
2514         *         auto-exposure is currently locked, and false otherwise. The
2515         *         auto-exposure lock may be independently enabled by the camera
2516         *         subsystem when auto-focus has completed. This method can be
2517         *         used after the {@link AutoFocusCallback#onAutoFocus(boolean,
2518         *         Camera)} callback to determine if the camera has locked AE.
2519         *
2520         * @see #setAutoExposureLock(boolean)
2521         *
2522         * @hide
2523         */
2524        public boolean getAutoExposureLock() {
2525            String str = get(KEY_AUTO_EXPOSURE_LOCK);
2526            return TRUE.equals(str);
2527        }
2528
2529        /**
2530         * Returns true if auto-exposure locking is supported. Applications
2531         * should call this before trying to lock auto-exposure. See
2532         * {@link #setAutoExposureLock} for details about the lock.
2533         *
2534         * @return true if auto-exposure lock is supported.
2535         * @see #setAutoExposureLock(boolean)
2536         *
2537         * @hide
2538         */
2539        public boolean isAutoExposureLockSupported() {
2540            String str = get(KEY_AUTO_EXPOSURE_LOCK_SUPPORTED);
2541            return TRUE.equals(str);
2542        }
2543
2544        /**
2545         * Gets current zoom value. This also works when smooth zoom is in
2546         * progress. Applications should check {@link #isZoomSupported} before
2547         * using this method.
2548         *
2549         * @return the current zoom value. The range is 0 to {@link
2550         *         #getMaxZoom}. 0 means the camera is not zoomed.
2551         */
2552        public int getZoom() {
2553            return getInt(KEY_ZOOM, 0);
2554        }
2555
2556        /**
2557         * Sets current zoom value. If the camera is zoomed (value > 0), the
2558         * actual picture size may be smaller than picture size setting.
2559         * Applications can check the actual picture size after picture is
2560         * returned from {@link PictureCallback}. The preview size remains the
2561         * same in zoom. Applications should check {@link #isZoomSupported}
2562         * before using this method.
2563         *
2564         * @param value zoom value. The valid range is 0 to {@link #getMaxZoom}.
2565         */
2566        public void setZoom(int value) {
2567            set(KEY_ZOOM, value);
2568        }
2569
2570        /**
2571         * Returns true if zoom is supported. Applications should call this
2572         * before using other zoom methods.
2573         *
2574         * @return true if zoom is supported.
2575         */
2576        public boolean isZoomSupported() {
2577            String str = get(KEY_ZOOM_SUPPORTED);
2578            return TRUE.equals(str);
2579        }
2580
2581        /**
2582         * Gets the maximum zoom value allowed for snapshot. This is the maximum
2583         * value that applications can set to {@link #setZoom(int)}.
2584         * Applications should call {@link #isZoomSupported} before using this
2585         * method. This value may change in different preview size. Applications
2586         * should call this again after setting preview size.
2587         *
2588         * @return the maximum zoom value supported by the camera.
2589         */
2590        public int getMaxZoom() {
2591            return getInt(KEY_MAX_ZOOM, 0);
2592        }
2593
2594        /**
2595         * Gets the zoom ratios of all zoom values. Applications should check
2596         * {@link #isZoomSupported} before using this method.
2597         *
2598         * @return the zoom ratios in 1/100 increments. Ex: a zoom of 3.2x is
2599         *         returned as 320. The number of elements is {@link
2600         *         #getMaxZoom} + 1. The list is sorted from small to large. The
2601         *         first element is always 100. The last element is the zoom
2602         *         ratio of the maximum zoom value.
2603         */
2604        public List<Integer> getZoomRatios() {
2605            return splitInt(get(KEY_ZOOM_RATIOS));
2606        }
2607
2608        /**
2609         * Returns true if smooth zoom is supported. Applications should call
2610         * this before using other smooth zoom methods.
2611         *
2612         * @return true if smooth zoom is supported.
2613         */
2614        public boolean isSmoothZoomSupported() {
2615            String str = get(KEY_SMOOTH_ZOOM_SUPPORTED);
2616            return TRUE.equals(str);
2617        }
2618
2619        /**
2620         * Gets the distances from the camera to where an object appears to be
2621         * in focus. The object is sharpest at the optimal focus distance. The
2622         * depth of field is the far focus distance minus near focus distance.
2623         *
2624         * Focus distances may change after calling {@link
2625         * #autoFocus(AutoFocusCallback)}, {@link #cancelAutoFocus}, or {@link
2626         * #startPreview()}. Applications can call {@link #getParameters()}
2627         * and this method anytime to get the latest focus distances. If the
2628         * focus mode is FOCUS_MODE_CONTINUOUS_VIDEO, focus distances may change
2629         * from time to time.
2630         *
2631         * This method is intended to estimate the distance between the camera
2632         * and the subject. After autofocus, the subject distance may be within
2633         * near and far focus distance. However, the precision depends on the
2634         * camera hardware, autofocus algorithm, the focus area, and the scene.
2635         * The error can be large and it should be only used as a reference.
2636         *
2637         * Far focus distance >= optimal focus distance >= near focus distance.
2638         * If the focus distance is infinity, the value will be
2639         * Float.POSITIVE_INFINITY.
2640         *
2641         * @param output focus distances in meters. output must be a float
2642         *        array with three elements. Near focus distance, optimal focus
2643         *        distance, and far focus distance will be filled in the array.
2644         * @see #FOCUS_DISTANCE_NEAR_INDEX
2645         * @see #FOCUS_DISTANCE_OPTIMAL_INDEX
2646         * @see #FOCUS_DISTANCE_FAR_INDEX
2647         */
2648        public void getFocusDistances(float[] output) {
2649            if (output == null || output.length != 3) {
2650                throw new IllegalArgumentException(
2651                        "output must be an float array with three elements.");
2652            }
2653            splitFloat(get(KEY_FOCUS_DISTANCES), output);
2654        }
2655
2656        /**
2657         * Gets the maximum number of focus areas supported. This is the maximum
2658         * length of the list in {@link #setFocusAreas(List)} and
2659         * {@link #getFocusAreas()}.
2660         *
2661         * @return the maximum number of focus areas supported by the camera.
2662         * @see #getFocusAreas()
2663         */
2664        public int getMaxNumFocusAreas() {
2665            return getInt(KEY_MAX_NUM_FOCUS_AREAS, 0);
2666        }
2667
2668        /**
2669         * Gets the current focus areas. Camera driver uses the areas to decide
2670         * focus.
2671         *
2672         * Before using this API or {@link #setFocusAreas(List)}, apps should
2673         * call {@link #getMaxNumFocusAreas()} to know the maximum number of
2674         * focus areas first. If the value is 0, focus area is not supported.
2675         *
2676         * Each focus area is a rectangle with specified weight. The direction
2677         * is relative to the sensor orientation, that is, what the sensor sees.
2678         * The direction is not affected by the rotation or mirroring of
2679         * {@link #setDisplayOrientation(int)}. Coordinates of the rectangle
2680         * range from -1000 to 1000. (-1000, -1000) is the upper left point.
2681         * (1000, 1000) is the lower right point. The length and width of focus
2682         * areas cannot be 0 or negative.
2683         *
2684         * The weight must range from 1 to 1000. The weight should be
2685         * interpreted as a per-pixel weight - all pixels in the area have the
2686         * specified weight. This means a small area with the same weight as a
2687         * larger area will have less influence on the focusing than the larger
2688         * area. Focus areas can partially overlap and the driver will add the
2689         * weights in the overlap region.
2690         *
2691         * A special case of null focus area means driver to decide the focus
2692         * area. For example, the driver may use more signals to decide focus
2693         * areas and change them dynamically. Apps can set all-zero if they want
2694         * the driver to decide focus areas.
2695         *
2696         * Focus areas are relative to the current field of view
2697         * ({@link #getZoom()}). No matter what the zoom level is, (-1000,-1000)
2698         * represents the top of the currently visible camera frame. The focus
2699         * area cannot be set to be outside the current field of view, even
2700         * when using zoom.
2701         *
2702         * Focus area only has effect if the current focus mode is
2703         * {@link #FOCUS_MODE_AUTO}, {@link #FOCUS_MODE_MACRO}, or
2704         * {@link #FOCUS_MODE_CONTINUOUS_VIDEO}.
2705         *
2706         * @return a list of current focus areas
2707         */
2708        public List<Area> getFocusAreas() {
2709            return splitArea(get(KEY_FOCUS_AREAS));
2710        }
2711
2712        /**
2713         * Sets focus areas. See {@link #getFocusAreas()} for documentation.
2714         *
2715         * @param focusAreas the focus areas
2716         * @see #getFocusAreas()
2717         */
2718        public void setFocusAreas(List<Area> focusAreas) {
2719            set(KEY_FOCUS_AREAS, focusAreas);
2720        }
2721
2722        /**
2723         * Gets the maximum number of metering areas supported. This is the
2724         * maximum length of the list in {@link #setMeteringAreas(List)} and
2725         * {@link #getMeteringAreas()}.
2726         *
2727         * @return the maximum number of metering areas supported by the camera.
2728         * @see #getMeteringAreas()
2729         */
2730        public int getMaxNumMeteringAreas() {
2731            return getInt(KEY_MAX_NUM_METERING_AREAS, 0);
2732        }
2733
2734        /**
2735         * Gets the current metering areas. Camera driver uses these areas to
2736         * decide exposure.
2737         *
2738         * Before using this API or {@link #setMeteringAreas(List)}, apps should
2739         * call {@link #getMaxNumMeteringAreas()} to know the maximum number of
2740         * metering areas first. If the value is 0, metering area is not
2741         * supported.
2742         *
2743         * Each metering area is a rectangle with specified weight. The
2744         * direction is relative to the sensor orientation, that is, what the
2745         * sensor sees. The direction is not affected by the rotation or
2746         * mirroring of {@link #setDisplayOrientation(int)}. Coordinates of the
2747         * rectangle range from -1000 to 1000. (-1000, -1000) is the upper left
2748         * point. (1000, 1000) is the lower right point. The length and width of
2749         * metering areas cannot be 0 or negative.
2750         *
2751         * The weight must range from 1 to 1000, and represents a weight for
2752         * every pixel in the area. This means that a large metering area with
2753         * the same weight as a smaller area will have more effect in the
2754         * metering result.  Metering areas can partially overlap and the driver
2755         * will add the weights in the overlap region.
2756         *
2757         * A special case of null metering area means driver to decide the
2758         * metering area. For example, the driver may use more signals to decide
2759         * metering areas and change them dynamically. Apps can set all-zero if
2760         * they want the driver to decide metering areas.
2761         *
2762         * Metering areas are relative to the current field of view
2763         * ({@link #getZoom()}). No matter what the zoom level is, (-1000,-1000)
2764         * represents the top of the currently visible camera frame. The
2765         * metering area cannot be set to be outside the current field of view,
2766         * even when using zoom.
2767         *
2768         * No matter what metering areas are, the final exposure are compensated
2769         * by {@link #setExposureCompensation(int)}.
2770         *
2771         * @return a list of current metering areas
2772         */
2773        public List<Area> getMeteringAreas() {
2774            return splitArea(KEY_METERING_AREAS);
2775        }
2776
2777        /**
2778         * Sets metering areas. See {@link #getMeteringAreas()} for
2779         * documentation.
2780         *
2781         * @param meteringAreas the metering areas
2782         * @see #getMeteringAreas()
2783         */
2784        public void setMeteringAreas(List<Area> meteringAreas) {
2785            set(KEY_METERING_AREAS, meteringAreas);
2786        }
2787
2788        // Splits a comma delimited string to an ArrayList of String.
2789        // Return null if the passing string is null or the size is 0.
2790        private ArrayList<String> split(String str) {
2791            if (str == null) return null;
2792
2793            // Use StringTokenizer because it is faster than split.
2794            StringTokenizer tokenizer = new StringTokenizer(str, ",");
2795            ArrayList<String> substrings = new ArrayList<String>();
2796            while (tokenizer.hasMoreElements()) {
2797                substrings.add(tokenizer.nextToken());
2798            }
2799            return substrings;
2800        }
2801
2802        // Splits a comma delimited string to an ArrayList of Integer.
2803        // Return null if the passing string is null or the size is 0.
2804        private ArrayList<Integer> splitInt(String str) {
2805            if (str == null) return null;
2806
2807            StringTokenizer tokenizer = new StringTokenizer(str, ",");
2808            ArrayList<Integer> substrings = new ArrayList<Integer>();
2809            while (tokenizer.hasMoreElements()) {
2810                String token = tokenizer.nextToken();
2811                substrings.add(Integer.parseInt(token));
2812            }
2813            if (substrings.size() == 0) return null;
2814            return substrings;
2815        }
2816
2817        private void splitInt(String str, int[] output) {
2818            if (str == null) return;
2819
2820            StringTokenizer tokenizer = new StringTokenizer(str, ",");
2821            int index = 0;
2822            while (tokenizer.hasMoreElements()) {
2823                String token = tokenizer.nextToken();
2824                output[index++] = Integer.parseInt(token);
2825            }
2826        }
2827
2828        // Splits a comma delimited string to an ArrayList of Float.
2829        private void splitFloat(String str, float[] output) {
2830            if (str == null) return;
2831
2832            StringTokenizer tokenizer = new StringTokenizer(str, ",");
2833            int index = 0;
2834            while (tokenizer.hasMoreElements()) {
2835                String token = tokenizer.nextToken();
2836                output[index++] = Float.parseFloat(token);
2837            }
2838        }
2839
2840        // Returns the value of a float parameter.
2841        private float getFloat(String key, float defaultValue) {
2842            try {
2843                return Float.parseFloat(mMap.get(key));
2844            } catch (NumberFormatException ex) {
2845                return defaultValue;
2846            }
2847        }
2848
2849        // Returns the value of a integer parameter.
2850        private int getInt(String key, int defaultValue) {
2851            try {
2852                return Integer.parseInt(mMap.get(key));
2853            } catch (NumberFormatException ex) {
2854                return defaultValue;
2855            }
2856        }
2857
2858        // Splits a comma delimited string to an ArrayList of Size.
2859        // Return null if the passing string is null or the size is 0.
2860        private ArrayList<Size> splitSize(String str) {
2861            if (str == null) return null;
2862
2863            StringTokenizer tokenizer = new StringTokenizer(str, ",");
2864            ArrayList<Size> sizeList = new ArrayList<Size>();
2865            while (tokenizer.hasMoreElements()) {
2866                Size size = strToSize(tokenizer.nextToken());
2867                if (size != null) sizeList.add(size);
2868            }
2869            if (sizeList.size() == 0) return null;
2870            return sizeList;
2871        }
2872
2873        // Parses a string (ex: "480x320") to Size object.
2874        // Return null if the passing string is null.
2875        private Size strToSize(String str) {
2876            if (str == null) return null;
2877
2878            int pos = str.indexOf('x');
2879            if (pos != -1) {
2880                String width = str.substring(0, pos);
2881                String height = str.substring(pos + 1);
2882                return new Size(Integer.parseInt(width),
2883                                Integer.parseInt(height));
2884            }
2885            Log.e(TAG, "Invalid size parameter string=" + str);
2886            return null;
2887        }
2888
2889        // Splits a comma delimited string to an ArrayList of int array.
2890        // Example string: "(10000,26623),(10000,30000)". Return null if the
2891        // passing string is null or the size is 0.
2892        private ArrayList<int[]> splitRange(String str) {
2893            if (str == null || str.charAt(0) != '('
2894                    || str.charAt(str.length() - 1) != ')') {
2895                Log.e(TAG, "Invalid range list string=" + str);
2896                return null;
2897            }
2898
2899            ArrayList<int[]> rangeList = new ArrayList<int[]>();
2900            int endIndex, fromIndex = 1;
2901            do {
2902                int[] range = new int[2];
2903                endIndex = str.indexOf("),(", fromIndex);
2904                if (endIndex == -1) endIndex = str.length() - 1;
2905                splitInt(str.substring(fromIndex, endIndex), range);
2906                rangeList.add(range);
2907                fromIndex = endIndex + 3;
2908            } while (endIndex != str.length() - 1);
2909
2910            if (rangeList.size() == 0) return null;
2911            return rangeList;
2912        }
2913
2914        // Splits a comma delimited string to an ArrayList of Area objects.
2915        // Example string: "(-10,-10,0,0,300),(0,0,10,10,700)". Return null if
2916        // the passing string is null or the size is 0 or (0,0,0,0,0).
2917        private ArrayList<Area> splitArea(String str) {
2918            if (str == null || str.charAt(0) != '('
2919                    || str.charAt(str.length() - 1) != ')') {
2920                Log.e(TAG, "Invalid area string=" + str);
2921                return null;
2922            }
2923
2924            ArrayList<Area> result = new ArrayList<Area>();
2925            int endIndex, fromIndex = 1;
2926            int[] array = new int[5];
2927            do {
2928                endIndex = str.indexOf("),(", fromIndex);
2929                if (endIndex == -1) endIndex = str.length() - 1;
2930                splitInt(str.substring(fromIndex, endIndex), array);
2931                Rect rect = new Rect(array[0], array[1], array[2], array[3]);
2932                result.add(new Area(rect, array[4]));
2933                fromIndex = endIndex + 3;
2934            } while (endIndex != str.length() - 1);
2935
2936            if (result.size() == 0) return null;
2937
2938            if (result.size() == 1) {
2939                Area area = (Area) result.get(0);
2940                Rect rect = area.rect;
2941                if (rect.left == 0 && rect.top == 0 && rect.right == 0
2942                        && rect.bottom == 0 && area.weight == 0) {
2943                    return null;
2944                }
2945            }
2946
2947            return result;
2948        }
2949    };
2950}
2951