Camera.java revision b838d8d4a26c3cfea2e2a5ce831daebbb5653ae7
19066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project/*
29066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Copyright (C) 2008 The Android Open Source Project
39066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project *
49066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Licensed under the Apache License, Version 2.0 (the "License");
59066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * you may not use this file except in compliance with the License.
69066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * You may obtain a copy of the License at
79066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project *
89066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project *      http://www.apache.org/licenses/LICENSE-2.0
99066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project *
109066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Unless required by applicable law or agreed to in writing, software
119066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * distributed under the License is distributed on an "AS IS" BASIS,
129066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
139066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * See the License for the specific language governing permissions and
149066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * limitations under the License.
159066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */
169066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
179066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectpackage android.hardware;
189066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
1910e09c69d659bf54d6efbe1a3660add7f8a39d6eWu-cheng Liimport android.annotation.SdkConstant;
2010e09c69d659bf54d6efbe1a3660add7f8a39d6eWu-cheng Liimport android.annotation.SdkConstant.SdkConstantType;
21a696f5d667227365da732481770767dcb330dd23Mathias Agopianimport android.graphics.ImageFormat;
224c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Liimport android.graphics.Point;
2330771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Liimport android.graphics.Rect;
24fd6f39e147dc077139a41b9c2a4039fbaa20224eJamie Gennisimport android.graphics.SurfaceTexture;
25e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvalaimport android.media.AudioManager;
26e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvalaimport android.media.MediaPlayer;
279066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectimport android.os.Handler;
289066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectimport android.os.Looper;
299066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectimport android.os.Message;
30e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvalaimport android.os.SystemProperties;
31bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Liimport android.util.Log;
32bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Liimport android.view.Surface;
33bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Liimport android.view.SurfaceHolder;
34bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Li
35bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Liimport java.io.IOException;
36bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Liimport java.lang.ref.WeakReference;
37bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Liimport java.util.ArrayList;
38bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Liimport java.util.HashMap;
39bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Liimport java.util.List;
40bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Liimport java.util.StringTokenizer;
419066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
424c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li
439066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project/**
44bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * The Camera class is used to set image capture settings, start/stop preview,
45bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * snap pictures, and retrieve frames for encoding for video.  This class is a
46bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * client for the Camera service, which manages the actual camera hardware.
47df4578e8ab7008a7e528d5af2ae761b33cf2bdf4Scott Main *
48bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * <p>To access the device camera, you must declare the
497478ea6848c0059e65a4089b4ec2ff4158520870Wu-cheng Li * {@link android.Manifest.permission#CAMERA} permission in your Android
50df4578e8ab7008a7e528d5af2ae761b33cf2bdf4Scott Main * Manifest. Also be sure to include the
51df4578e8ab7008a7e528d5af2ae761b33cf2bdf4Scott Main * <a href="{@docRoot}guide/topics/manifest/uses-feature-element.html">&lt;uses-feature></a>
52bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * manifest element to declare camera features used by your application.
537478ea6848c0059e65a4089b4ec2ff4158520870Wu-cheng Li * For example, if you use the camera and auto-focus feature, your Manifest
54df4578e8ab7008a7e528d5af2ae761b33cf2bdf4Scott Main * should include the following:</p>
55df4578e8ab7008a7e528d5af2ae761b33cf2bdf4Scott Main * <pre> &lt;uses-permission android:name="android.permission.CAMERA" />
56df4578e8ab7008a7e528d5af2ae761b33cf2bdf4Scott Main * &lt;uses-feature android:name="android.hardware.camera" />
57df4578e8ab7008a7e528d5af2ae761b33cf2bdf4Scott Main * &lt;uses-feature android:name="android.hardware.camera.autofocus" /></pre>
58df4578e8ab7008a7e528d5af2ae761b33cf2bdf4Scott Main *
59bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * <p>To take pictures with this class, use the following steps:</p>
60bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor *
61bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * <ol>
62341ff13689dfe822b598e626272ac2e80041b482Dan Egnor * <li>Obtain an instance of Camera from {@link #open(int)}.
63bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor *
64bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * <li>Get existing (default) settings with {@link #getParameters()}.
65bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor *
66bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * <li>If necessary, modify the returned {@link Camera.Parameters} object and call
67bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * {@link #setParameters(Camera.Parameters)}.
68bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor *
69bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * <li>If desired, call {@link #setDisplayOrientation(int)}.
70bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor *
71bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * <li><b>Important</b>: Pass a fully initialized {@link SurfaceHolder} to
72bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * {@link #setPreviewDisplay(SurfaceHolder)}.  Without a surface, the camera
73bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * will be unable to start the preview.
74bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor *
75bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * <li><b>Important</b>: Call {@link #startPreview()} to start updating the
76bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * preview surface.  Preview must be started before you can take a picture.
77bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor *
78bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * <li>When you want, call {@link #takePicture(Camera.ShutterCallback,
79bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * Camera.PictureCallback, Camera.PictureCallback, Camera.PictureCallback)} to
80bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * capture a photo.  Wait for the callbacks to provide the actual image data.
81bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor *
82bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * <li>After taking a picture, preview display will have stopped.  To take more
83bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * photos, call {@link #startPreview()} again first.
84bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor *
85bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * <li>Call {@link #stopPreview()} to stop updating the preview surface.
86bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor *
87bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * <li><b>Important:</b> Call {@link #release()} to release the camera for
88bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * use by other applications.  Applications should release the camera
89bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * immediately in {@link android.app.Activity#onPause()} (and re-{@link #open()}
90bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * it in {@link android.app.Activity#onResume()}).
91bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * </ol>
92bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor *
93bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * <p>To quickly switch to video recording mode, use these steps:</p>
94bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor *
95bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * <ol>
96bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * <li>Obtain and initialize a Camera and start preview as described above.
97bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor *
98bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * <li>Call {@link #unlock()} to allow the media process to access the camera.
99bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor *
100bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * <li>Pass the camera to {@link android.media.MediaRecorder#setCamera(Camera)}.
101bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * See {@link android.media.MediaRecorder} information about video recording.
102bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor *
103bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * <li>When finished recording, call {@link #reconnect()} to re-acquire
104bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * and re-lock the camera.
105bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor *
106bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * <li>If desired, restart preview and take more photos or videos.
107bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor *
108bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * <li>Call {@link #stopPreview()} and {@link #release()} as described above.
109bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * </ol>
110bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor *
111bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * <p>This class is not thread-safe, and is meant for use from one event thread.
112bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * Most long-running operations (preview, focus, photo capture, etc) happen
113bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * asynchronously and invoke callbacks as necessary.  Callbacks will be invoked
114341ff13689dfe822b598e626272ac2e80041b482Dan Egnor * on the event thread {@link #open(int)} was called from.  This class's methods
115bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * must never be called from multiple threads at once.</p>
116bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor *
117df4578e8ab7008a7e528d5af2ae761b33cf2bdf4Scott Main * <p class="caution"><strong>Caution:</strong> Different Android-powered devices
118df4578e8ab7008a7e528d5af2ae761b33cf2bdf4Scott Main * may have different hardware specifications, such as megapixel ratings and
119df4578e8ab7008a7e528d5af2ae761b33cf2bdf4Scott Main * auto-focus capabilities. In order for your application to be compatible with
1207478ea6848c0059e65a4089b4ec2ff4158520870Wu-cheng Li * more devices, you should not make assumptions about the device camera
121df4578e8ab7008a7e528d5af2ae761b33cf2bdf4Scott Main * specifications.</p>
1226c5c3c392b8abce93fd2d366f12449c713ed0016Joe Fernandez *
1236c5c3c392b8abce93fd2d366f12449c713ed0016Joe Fernandez * <div class="special reference">
1246c5c3c392b8abce93fd2d366f12449c713ed0016Joe Fernandez * <h3>Developer Guides</h3>
1256c5c3c392b8abce93fd2d366f12449c713ed0016Joe Fernandez * <p>For more information about using cameras, read the
1266c5c3c392b8abce93fd2d366f12449c713ed0016Joe Fernandez * <a href="{@docRoot}guide/topics/media/camera.html">Camera</a> developer guide.</p>
1276c5c3c392b8abce93fd2d366f12449c713ed0016Joe Fernandez * </div>
1289066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */
1299066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectpublic class Camera {
1309066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    private static final String TAG = "Camera";
1319b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
132d2c2929c94bec68741b85f4174e11307fb65157fWu-cheng Li    // These match the enums in frameworks/base/include/camera/Camera.h
133da83f4674a564007baac03db062a289c8158d940Benny Wong    private static final int CAMERA_MSG_ERROR            = 0x001;
134da83f4674a564007baac03db062a289c8158d940Benny Wong    private static final int CAMERA_MSG_SHUTTER          = 0x002;
135da83f4674a564007baac03db062a289c8158d940Benny Wong    private static final int CAMERA_MSG_FOCUS            = 0x004;
136da83f4674a564007baac03db062a289c8158d940Benny Wong    private static final int CAMERA_MSG_ZOOM             = 0x008;
137da83f4674a564007baac03db062a289c8158d940Benny Wong    private static final int CAMERA_MSG_PREVIEW_FRAME    = 0x010;
138da83f4674a564007baac03db062a289c8158d940Benny Wong    private static final int CAMERA_MSG_VIDEO_FRAME      = 0x020;
139da83f4674a564007baac03db062a289c8158d940Benny Wong    private static final int CAMERA_MSG_POSTVIEW_FRAME   = 0x040;
140da83f4674a564007baac03db062a289c8158d940Benny Wong    private static final int CAMERA_MSG_RAW_IMAGE        = 0x080;
141da83f4674a564007baac03db062a289c8158d940Benny Wong    private static final int CAMERA_MSG_COMPRESSED_IMAGE = 0x100;
1424c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li    private static final int CAMERA_MSG_RAW_IMAGE_NOTIFY = 0x200;
143bb1e275c0e684dd213f124da77110cdd9d6f090cWu-cheng Li    private static final int CAMERA_MSG_PREVIEW_METADATA = 0x400;
1444c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li    private static final int CAMERA_MSG_ALL_MSGS         = 0x4FF;
1459066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
1469066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    private int mNativeContext; // accessed by native methods
1479066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    private EventHandler mEventHandler;
1489066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    private ShutterCallback mShutterCallback;
1499066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    private PictureCallback mRawImageCallback;
1509066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    private PictureCallback mJpegCallback;
1519066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    private PreviewCallback mPreviewCallback;
152e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks    private PictureCallback mPostviewCallback;
1539066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    private AutoFocusCallback mAutoFocusCallback;
1543f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li    private OnZoomChangeListener mZoomListener;
1554c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li    private FaceDetectionListener mFaceListener;
1569066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    private ErrorCallback mErrorCallback;
1579066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    private boolean mOneShot;
15894927dffce1626898b59579dfc5af53b5de8cef6Andrew Harp    private boolean mWithBuffer;
1594c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li    private boolean mFaceDetectionRunning = false;
160e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala    private boolean mReleased = false;
1619b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
1629066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
16310e09c69d659bf54d6efbe1a3660add7f8a39d6eWu-cheng Li     * Broadcast Action:  A new picture is taken by the camera, and the entry of
16410e09c69d659bf54d6efbe1a3660add7f8a39d6eWu-cheng Li     * the picture has been added to the media store.
16510e09c69d659bf54d6efbe1a3660add7f8a39d6eWu-cheng Li     * {@link android.content.Intent#getData} is URI of the picture.
16610e09c69d659bf54d6efbe1a3660add7f8a39d6eWu-cheng Li     */
16710e09c69d659bf54d6efbe1a3660add7f8a39d6eWu-cheng Li    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
16810e09c69d659bf54d6efbe1a3660add7f8a39d6eWu-cheng Li    public static final String ACTION_NEW_PICTURE = "android.hardware.action.NEW_PICTURE";
16910e09c69d659bf54d6efbe1a3660add7f8a39d6eWu-cheng Li
17010e09c69d659bf54d6efbe1a3660add7f8a39d6eWu-cheng Li    /**
17110e09c69d659bf54d6efbe1a3660add7f8a39d6eWu-cheng Li     * Broadcast Action:  A new video is recorded by the camera, and the entry
17210e09c69d659bf54d6efbe1a3660add7f8a39d6eWu-cheng Li     * of the video has been added to the media store.
17310e09c69d659bf54d6efbe1a3660add7f8a39d6eWu-cheng Li     * {@link android.content.Intent#getData} is URI of the video.
17410e09c69d659bf54d6efbe1a3660add7f8a39d6eWu-cheng Li     */
17510e09c69d659bf54d6efbe1a3660add7f8a39d6eWu-cheng Li    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
17610e09c69d659bf54d6efbe1a3660add7f8a39d6eWu-cheng Li    public static final String ACTION_NEW_VIDEO = "android.hardware.action.NEW_VIDEO";
17710e09c69d659bf54d6efbe1a3660add7f8a39d6eWu-cheng Li
17810e09c69d659bf54d6efbe1a3660add7f8a39d6eWu-cheng Li    /**
1794c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li     * Hardware face detection. It does not use much CPU.
1804c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li     */
181c0c683b3344c67700882f8059e7d18266366daa9Wu-cheng Li    private static final int CAMERA_FACE_DETECTION_HW = 0;
1824c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li
1834c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li    /**
184c0c683b3344c67700882f8059e7d18266366daa9Wu-cheng Li     * Software face detection. It uses some CPU.
1854c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li     */
186c0c683b3344c67700882f8059e7d18266366daa9Wu-cheng Li    private static final int CAMERA_FACE_DETECTION_SW = 1;
1874c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li
1884c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li    /**
189341ff13689dfe822b598e626272ac2e80041b482Dan Egnor     * Returns the number of physical cameras available on this device.
190e25cc656392d8866e163f78b60c7791455d0fb44Chih-Chung Chang     */
191e25cc656392d8866e163f78b60c7791455d0fb44Chih-Chung Chang    public native static int getNumberOfCameras();
192e25cc656392d8866e163f78b60c7791455d0fb44Chih-Chung Chang
193e25cc656392d8866e163f78b60c7791455d0fb44Chih-Chung Chang    /**
194341ff13689dfe822b598e626272ac2e80041b482Dan Egnor     * Returns the information about a particular camera.
195b8bb78f54b48868465a9d69d65fda08524ab5ae1Chih-Chung Chang     * If {@link #getNumberOfCameras()} returns N, the valid id is 0 to N-1.
196b8bb78f54b48868465a9d69d65fda08524ab5ae1Chih-Chung Chang     */
197b8bb78f54b48868465a9d69d65fda08524ab5ae1Chih-Chung Chang    public native static void getCameraInfo(int cameraId, CameraInfo cameraInfo);
198b8bb78f54b48868465a9d69d65fda08524ab5ae1Chih-Chung Chang
199b8bb78f54b48868465a9d69d65fda08524ab5ae1Chih-Chung Chang    /**
200b8bb78f54b48868465a9d69d65fda08524ab5ae1Chih-Chung Chang     * Information about a camera
201b8bb78f54b48868465a9d69d65fda08524ab5ae1Chih-Chung Chang     */
202b8bb78f54b48868465a9d69d65fda08524ab5ae1Chih-Chung Chang    public static class CameraInfo {
2037836660f5eb45b7b7e1f5119face65c80e2ade17Wu-cheng Li        /**
2047836660f5eb45b7b7e1f5119face65c80e2ade17Wu-cheng Li         * The facing of the camera is opposite to that of the screen.
2057836660f5eb45b7b7e1f5119face65c80e2ade17Wu-cheng Li         */
206b8bb78f54b48868465a9d69d65fda08524ab5ae1Chih-Chung Chang        public static final int CAMERA_FACING_BACK = 0;
2077836660f5eb45b7b7e1f5119face65c80e2ade17Wu-cheng Li
2087836660f5eb45b7b7e1f5119face65c80e2ade17Wu-cheng Li        /**
2097836660f5eb45b7b7e1f5119face65c80e2ade17Wu-cheng Li         * The facing of the camera is the same as that of the screen.
2107836660f5eb45b7b7e1f5119face65c80e2ade17Wu-cheng Li         */
211b8bb78f54b48868465a9d69d65fda08524ab5ae1Chih-Chung Chang        public static final int CAMERA_FACING_FRONT = 1;
212b8bb78f54b48868465a9d69d65fda08524ab5ae1Chih-Chung Chang
213b8bb78f54b48868465a9d69d65fda08524ab5ae1Chih-Chung Chang        /**
214464cb21e2aaa448072449b82156f18bd64c0e613Joe Fernandez         * The direction that the camera faces. It should be
215b8bb78f54b48868465a9d69d65fda08524ab5ae1Chih-Chung Chang         * CAMERA_FACING_BACK or CAMERA_FACING_FRONT.
216b8bb78f54b48868465a9d69d65fda08524ab5ae1Chih-Chung Chang         */
2177836660f5eb45b7b7e1f5119face65c80e2ade17Wu-cheng Li        public int facing;
218b8bb78f54b48868465a9d69d65fda08524ab5ae1Chih-Chung Chang
219b8bb78f54b48868465a9d69d65fda08524ab5ae1Chih-Chung Chang        /**
22032a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * <p>The orientation of the camera image. The value is the angle that the
221b8bb78f54b48868465a9d69d65fda08524ab5ae1Chih-Chung Chang         * camera image needs to be rotated clockwise so it shows correctly on
22232a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * the display in its natural orientation. It should be 0, 90, 180, or 270.</p>
223b8bb78f54b48868465a9d69d65fda08524ab5ae1Chih-Chung Chang         *
22432a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * <p>For example, suppose a device has a naturally tall screen. The
2252fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li         * back-facing camera sensor is mounted in landscape. You are looking at
2262fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li         * the screen. If the top side of the camera sensor is aligned with the
2272fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li         * right edge of the screen in natural orientation, the value should be
2282fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li         * 90. If the top side of a front-facing camera sensor is aligned with
22932a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * the right of the screen, the value should be 270.</p>
230b8bb78f54b48868465a9d69d65fda08524ab5ae1Chih-Chung Chang         *
231b8bb78f54b48868465a9d69d65fda08524ab5ae1Chih-Chung Chang         * @see #setDisplayOrientation(int)
23269ea4e15e52c456537575d21443ac1efdb03a902Brad Fitzpatrick         * @see Parameters#setRotation(int)
23369ea4e15e52c456537575d21443ac1efdb03a902Brad Fitzpatrick         * @see Parameters#setPreviewSize(int, int)
23469ea4e15e52c456537575d21443ac1efdb03a902Brad Fitzpatrick         * @see Parameters#setPictureSize(int, int)
23569ea4e15e52c456537575d21443ac1efdb03a902Brad Fitzpatrick         * @see Parameters#setJpegThumbnailSize(int, int)
236b8bb78f54b48868465a9d69d65fda08524ab5ae1Chih-Chung Chang         */
2377836660f5eb45b7b7e1f5119face65c80e2ade17Wu-cheng Li        public int orientation;
238b8bb78f54b48868465a9d69d65fda08524ab5ae1Chih-Chung Chang    };
239b8bb78f54b48868465a9d69d65fda08524ab5ae1Chih-Chung Chang
240b8bb78f54b48868465a9d69d65fda08524ab5ae1Chih-Chung Chang    /**
241341ff13689dfe822b598e626272ac2e80041b482Dan Egnor     * Creates a new Camera object to access a particular hardware camera.
242bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     *
243bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * <p>You must call {@link #release()} when you are done using the camera,
244bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * otherwise it will remain locked and be unavailable to other applications.
245bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     *
246341ff13689dfe822b598e626272ac2e80041b482Dan Egnor     * <p>Your application should only have one Camera object active at a time
247341ff13689dfe822b598e626272ac2e80041b482Dan Egnor     * for a particular hardware camera.
248bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     *
249bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * <p>Callbacks from other methods are delivered to the event loop of the
250bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * thread which called open().  If this thread has no event loop, then
251bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * callbacks are delivered to the main application event loop.  If there
252bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * is no main application event loop, callbacks are not delivered.
253bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     *
254bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * <p class="caution"><b>Caution:</b> On some devices, this method may
255bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * take a long time to complete.  It is best to call this method from a
256bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * worker thread (possibly using {@link android.os.AsyncTask}) to avoid
257bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * blocking the main application UI thread.
258bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     *
259341ff13689dfe822b598e626272ac2e80041b482Dan Egnor     * @param cameraId the hardware camera to access, between 0 and
260a48b70fa8ff6363d1e5282be70f6be12bc0688dcWu-cheng Li     *     {@link #getNumberOfCameras()}-1.
261bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * @return a new Camera object, connected, locked and ready for use.
262bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * @throws RuntimeException if connection to the camera service fails (for
263facc8ce116bd92f7ba7e8ecb76cbda3953260ef9Wu-cheng Li     *     example, if the camera is in use by another process or device policy
264facc8ce116bd92f7ba7e8ecb76cbda3953260ef9Wu-cheng Li     *     manager has disabled the camera).
265facc8ce116bd92f7ba7e8ecb76cbda3953260ef9Wu-cheng Li     * @see android.app.admin.DevicePolicyManager#getCameraDisabled(android.content.ComponentName)
266e25cc656392d8866e163f78b60c7791455d0fb44Chih-Chung Chang     */
267e25cc656392d8866e163f78b60c7791455d0fb44Chih-Chung Chang    public static Camera open(int cameraId) {
268e25cc656392d8866e163f78b60c7791455d0fb44Chih-Chung Chang        return new Camera(cameraId);
269e25cc656392d8866e163f78b60c7791455d0fb44Chih-Chung Chang    }
270e25cc656392d8866e163f78b60c7791455d0fb44Chih-Chung Chang
271e25cc656392d8866e163f78b60c7791455d0fb44Chih-Chung Chang    /**
272a48b70fa8ff6363d1e5282be70f6be12bc0688dcWu-cheng Li     * Creates a new Camera object to access the first back-facing camera on the
273a48b70fa8ff6363d1e5282be70f6be12bc0688dcWu-cheng Li     * device. If the device does not have a back-facing camera, this returns
274a48b70fa8ff6363d1e5282be70f6be12bc0688dcWu-cheng Li     * null.
2757836660f5eb45b7b7e1f5119face65c80e2ade17Wu-cheng Li     * @see #open(int)
2769066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
2779b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li    public static Camera open() {
278a48b70fa8ff6363d1e5282be70f6be12bc0688dcWu-cheng Li        int numberOfCameras = getNumberOfCameras();
279a48b70fa8ff6363d1e5282be70f6be12bc0688dcWu-cheng Li        CameraInfo cameraInfo = new CameraInfo();
280a48b70fa8ff6363d1e5282be70f6be12bc0688dcWu-cheng Li        for (int i = 0; i < numberOfCameras; i++) {
281a48b70fa8ff6363d1e5282be70f6be12bc0688dcWu-cheng Li            getCameraInfo(i, cameraInfo);
282a48b70fa8ff6363d1e5282be70f6be12bc0688dcWu-cheng Li            if (cameraInfo.facing == CameraInfo.CAMERA_FACING_BACK) {
283a48b70fa8ff6363d1e5282be70f6be12bc0688dcWu-cheng Li                return new Camera(i);
284a48b70fa8ff6363d1e5282be70f6be12bc0688dcWu-cheng Li            }
285a48b70fa8ff6363d1e5282be70f6be12bc0688dcWu-cheng Li        }
286a48b70fa8ff6363d1e5282be70f6be12bc0688dcWu-cheng Li        return null;
2879066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
2889066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
289e25cc656392d8866e163f78b60c7791455d0fb44Chih-Chung Chang    Camera(int cameraId) {
2909066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        mShutterCallback = null;
2919066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        mRawImageCallback = null;
2929066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        mJpegCallback = null;
2939066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        mPreviewCallback = null;
294e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks        mPostviewCallback = null;
2953f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li        mZoomListener = null;
2969066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
2979066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        Looper looper;
2989066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        if ((looper = Looper.myLooper()) != null) {
2999066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            mEventHandler = new EventHandler(this, looper);
3009066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        } else if ((looper = Looper.getMainLooper()) != null) {
3019066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            mEventHandler = new EventHandler(this, looper);
3029066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        } else {
3039066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            mEventHandler = null;
3049066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
3059066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
306e25cc656392d8866e163f78b60c7791455d0fb44Chih-Chung Chang        native_setup(new WeakReference<Camera>(this), cameraId);
3079066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
3089b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
3099b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li    protected void finalize() {
310e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala        release();
3119066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
3129b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
313e25cc656392d8866e163f78b60c7791455d0fb44Chih-Chung Chang    private native final void native_setup(Object camera_this, int cameraId);
3149066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    private native final void native_release();
3159b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
3169066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
3179066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
3189066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * Disconnects and releases the Camera object resources.
319bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     *
320bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * <p>You must call this as soon as you're done with the Camera object.</p>
3219066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
3229b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li    public final void release() {
3239066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        native_release();
3244c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li        mFaceDetectionRunning = false;
325e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala        if (mCameraSoundPlayers != null) {
326e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala            for (CameraSoundPlayer csp: mCameraSoundPlayers) {
327e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala                if (csp != null) {
328e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala                    csp.release();
329e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala                }
330e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala            }
331e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala            mCameraSoundPlayers = null;
332e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala        }
333e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala        mReleased = true;
3349066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
3359066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
3369066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
337bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * Unlocks the camera to allow another process to access it.
338bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * Normally, the camera is locked to the process with an active Camera
339bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * object until {@link #release()} is called.  To allow rapid handoff
340bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * between processes, you can call this method to release the camera
341bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * temporarily for another process to use; once the other process is done
342bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * you can call {@link #reconnect()} to reclaim the camera.
343bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     *
344bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * <p>This must be done before calling
34542419ce28a09eb63e29a8fef87e6f5534f41902fWu-cheng Li     * {@link android.media.MediaRecorder#setCamera(Camera)}. This cannot be
34642419ce28a09eb63e29a8fef87e6f5534f41902fWu-cheng Li     * called after recording starts.
3479066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     *
348bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * <p>If you are not recording video, you probably do not need this method.
3499066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     *
350bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * @throws RuntimeException if the camera cannot be unlocked.
3519066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
352bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor    public native final void unlock();
3539b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
3549066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
355bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * Re-locks the camera to prevent other processes from accessing it.
356bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * Camera objects are locked by default unless {@link #unlock()} is
357bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * called.  Normally {@link #reconnect()} is used instead.
3589066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     *
35953b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li     * <p>Since API level 14, camera is automatically locked for applications in
36042419ce28a09eb63e29a8fef87e6f5534f41902fWu-cheng Li     * {@link android.media.MediaRecorder#start()}. Applications can use the
36142419ce28a09eb63e29a8fef87e6f5534f41902fWu-cheng Li     * camera (ex: zoom) after recording starts. There is no need to call this
36242419ce28a09eb63e29a8fef87e6f5534f41902fWu-cheng Li     * after recording starts or stops.
36342419ce28a09eb63e29a8fef87e6f5534f41902fWu-cheng Li     *
364bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * <p>If you are not recording video, you probably do not need this method.
365bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     *
366bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * @throws RuntimeException if the camera cannot be re-locked (for
367bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     *     example, if the camera is still in use by another process).
3689066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
369ffe1cf251a4f8469695b8acfa37270684dc1b70cWu-cheng Li    public native final void lock();
3709b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
3719066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
372bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * Reconnects to the camera service after another process used it.
373bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * After {@link #unlock()} is called, another process may use the
374bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * camera; when the process is done, you must reconnect to the camera,
375bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * which will re-acquire the lock and allow you to continue using the
376bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * camera.
3779066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     *
37853b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li     * <p>Since API level 14, camera is automatically locked for applications in
37942419ce28a09eb63e29a8fef87e6f5534f41902fWu-cheng Li     * {@link android.media.MediaRecorder#start()}. Applications can use the
38042419ce28a09eb63e29a8fef87e6f5534f41902fWu-cheng Li     * camera (ex: zoom) after recording starts. There is no need to call this
38142419ce28a09eb63e29a8fef87e6f5534f41902fWu-cheng Li     * after recording starts or stops.
382bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     *
383bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * <p>If you are not recording video, you probably do not need this method.
384bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     *
385bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * @throws IOException if a connection cannot be re-established (for
386bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     *     example, if the camera is still in use by another process).
3879066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
388bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor    public native final void reconnect() throws IOException;
3899b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
3909066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
391bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * Sets the {@link Surface} to be used for live preview.
392fd6f39e147dc077139a41b9c2a4039fbaa20224eJamie Gennis     * Either a surface or surface texture is necessary for preview, and
393fd6f39e147dc077139a41b9c2a4039fbaa20224eJamie Gennis     * preview is necessary to take pictures.  The same surface can be re-set
394fd6f39e147dc077139a41b9c2a4039fbaa20224eJamie Gennis     * without harm.  Setting a preview surface will un-set any preview surface
395fd6f39e147dc077139a41b9c2a4039fbaa20224eJamie Gennis     * texture that was set via {@link #setPreviewTexture}.
3969b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li     *
397bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * <p>The {@link SurfaceHolder} must already contain a surface when this
398bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * method is called.  If you are using {@link android.view.SurfaceView},
399bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * you will need to register a {@link SurfaceHolder.Callback} with
400bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * {@link SurfaceHolder#addCallback(SurfaceHolder.Callback)} and wait for
401bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * {@link SurfaceHolder.Callback#surfaceCreated(SurfaceHolder)} before
402bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * calling setPreviewDisplay() or starting preview.
403bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     *
404bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * <p>This method must be called before {@link #startPreview()}.  The
405bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * one exception is that if the preview surface is not set (or set to null)
406bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * before startPreview() is called, then this method may be called once
407bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * with a non-null parameter to set the preview surface.  (This allows
408bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * camera setup and surface creation to happen in parallel, saving time.)
409bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * The preview surface may not otherwise change while preview is running.
4109b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li     *
411bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * @param holder containing the Surface on which to place the preview,
412bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     *     or null to remove the preview surface
413bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * @throws IOException if the method fails (for example, if the surface
414bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     *     is unavailable or unsuitable).
4159066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
4169066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public final void setPreviewDisplay(SurfaceHolder holder) throws IOException {
417b8a10fe45657f2dcc50cae8a06805f8438a6937eWu-cheng Li        if (holder != null) {
418b8a10fe45657f2dcc50cae8a06805f8438a6937eWu-cheng Li            setPreviewDisplay(holder.getSurface());
419b8a10fe45657f2dcc50cae8a06805f8438a6937eWu-cheng Li        } else {
420b8a10fe45657f2dcc50cae8a06805f8438a6937eWu-cheng Li            setPreviewDisplay((Surface)null);
421b8a10fe45657f2dcc50cae8a06805f8438a6937eWu-cheng Li        }
4229066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
4239066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
424dbc289d6c27968bd05cc547ca73579347c3adc99Glenn Kasten    private native final void setPreviewDisplay(Surface surface) throws IOException;
4259066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
4269066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
427fd6f39e147dc077139a41b9c2a4039fbaa20224eJamie Gennis     * Sets the {@link SurfaceTexture} to be used for live preview.
428fd6f39e147dc077139a41b9c2a4039fbaa20224eJamie Gennis     * Either a surface or surface texture is necessary for preview, and
429fd6f39e147dc077139a41b9c2a4039fbaa20224eJamie Gennis     * preview is necessary to take pictures.  The same surface texture can be
430fd6f39e147dc077139a41b9c2a4039fbaa20224eJamie Gennis     * re-set without harm.  Setting a preview surface texture will un-set any
431fd6f39e147dc077139a41b9c2a4039fbaa20224eJamie Gennis     * preview surface that was set via {@link #setPreviewDisplay}.
432fd6f39e147dc077139a41b9c2a4039fbaa20224eJamie Gennis     *
433fd6f39e147dc077139a41b9c2a4039fbaa20224eJamie Gennis     * <p>This method must be called before {@link #startPreview()}.  The
434fd6f39e147dc077139a41b9c2a4039fbaa20224eJamie Gennis     * one exception is that if the preview surface texture is not set (or set
435fd6f39e147dc077139a41b9c2a4039fbaa20224eJamie Gennis     * to null) before startPreview() is called, then this method may be called
436fd6f39e147dc077139a41b9c2a4039fbaa20224eJamie Gennis     * once with a non-null parameter to set the preview surface.  (This allows
437fd6f39e147dc077139a41b9c2a4039fbaa20224eJamie Gennis     * camera setup and surface creation to happen in parallel, saving time.)
438fd6f39e147dc077139a41b9c2a4039fbaa20224eJamie Gennis     * The preview surface texture may not otherwise change while preview is
439fd6f39e147dc077139a41b9c2a4039fbaa20224eJamie Gennis     * running.
440fd6f39e147dc077139a41b9c2a4039fbaa20224eJamie Gennis     *
44132a972c693400db50717435139fa292a63bc937aEino-Ville Talvala     * <p>The timestamps provided by {@link SurfaceTexture#getTimestamp()} for a
442e309a0fd2e528039b3c1f1372a9a7095bcd852ccEino-Ville Talvala     * SurfaceTexture set as the preview texture have an unspecified zero point,
443e309a0fd2e528039b3c1f1372a9a7095bcd852ccEino-Ville Talvala     * and cannot be directly compared between different cameras or different
444e309a0fd2e528039b3c1f1372a9a7095bcd852ccEino-Ville Talvala     * instances of the same camera, or across multiple runs of the same
445e309a0fd2e528039b3c1f1372a9a7095bcd852ccEino-Ville Talvala     * program.
446e309a0fd2e528039b3c1f1372a9a7095bcd852ccEino-Ville Talvala     *
447fd6f39e147dc077139a41b9c2a4039fbaa20224eJamie Gennis     * @param surfaceTexture the {@link SurfaceTexture} to which the preview
448fd6f39e147dc077139a41b9c2a4039fbaa20224eJamie Gennis     *     images are to be sent or null to remove the current preview surface
449fd6f39e147dc077139a41b9c2a4039fbaa20224eJamie Gennis     *     texture
450fd6f39e147dc077139a41b9c2a4039fbaa20224eJamie Gennis     * @throws IOException if the method fails (for example, if the surface
451fd6f39e147dc077139a41b9c2a4039fbaa20224eJamie Gennis     *     texture is unavailable or unsuitable).
452fd6f39e147dc077139a41b9c2a4039fbaa20224eJamie Gennis     */
453dbc289d6c27968bd05cc547ca73579347c3adc99Glenn Kasten    public native final void setPreviewTexture(SurfaceTexture surfaceTexture) throws IOException;
454fd6f39e147dc077139a41b9c2a4039fbaa20224eJamie Gennis
455fd6f39e147dc077139a41b9c2a4039fbaa20224eJamie Gennis    /**
456bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * Callback interface used to deliver copies of preview frames as
457bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * they are displayed.
458bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     *
459bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * @see #setPreviewCallback(Camera.PreviewCallback)
460bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * @see #setOneShotPreviewCallback(Camera.PreviewCallback)
461bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * @see #setPreviewCallbackWithBuffer(Camera.PreviewCallback)
462bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * @see #startPreview()
4639066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
4649066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public interface PreviewCallback
4659066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    {
4669066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        /**
467bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor         * Called as preview frames are displayed.  This callback is invoked
468341ff13689dfe822b598e626272ac2e80041b482Dan Egnor         * on the event thread {@link #open(int)} was called from.
4699066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         *
470bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor         * @param data the contents of the preview frame in the format defined
471a696f5d667227365da732481770767dcb330dd23Mathias Agopian         *  by {@link android.graphics.ImageFormat}, which can be queried
472df4578e8ab7008a7e528d5af2ae761b33cf2bdf4Scott Main         *  with {@link android.hardware.Camera.Parameters#getPreviewFormat()}.
473da0a56df963353a1f1bd1914fa31f870d982dd5aScott Main         *  If {@link android.hardware.Camera.Parameters#setPreviewFormat(int)}
4749b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *             is never called, the default will be the YCbCr_420_SP
4759b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *             (NV21) format.
476bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor         * @param camera the Camera service object.
4779066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         */
4789066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        void onPreviewFrame(byte[] data, Camera camera);
4799066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    };
4809b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
4819066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
482bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * Starts capturing and drawing preview frames to the screen.
483c5f94d8a4779050125145396ca83fbc862c7ed6bEino-Ville Talvala     * Preview will not actually start until a surface is supplied
484c5f94d8a4779050125145396ca83fbc862c7ed6bEino-Ville Talvala     * with {@link #setPreviewDisplay(SurfaceHolder)} or
485c5f94d8a4779050125145396ca83fbc862c7ed6bEino-Ville Talvala     * {@link #setPreviewTexture(SurfaceTexture)}.
486bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     *
487bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * <p>If {@link #setPreviewCallback(Camera.PreviewCallback)},
488bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * {@link #setOneShotPreviewCallback(Camera.PreviewCallback)}, or
489bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * {@link #setPreviewCallbackWithBuffer(Camera.PreviewCallback)} were
490bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * called, {@link Camera.PreviewCallback#onPreviewFrame(byte[], Camera)}
491bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * will be called when preview data becomes available.
4929066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
4939066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public native final void startPreview();
4949b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
4959066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
496bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * Stops capturing and drawing preview frames to the surface, and
497bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * resets the camera for a future call to {@link #startPreview()}.
4989066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
4994c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li    public final void stopPreview() {
5004c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li        _stopPreview();
5014c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li        mFaceDetectionRunning = false;
502664d72e6630522589cc013b25f5c9cdd5d949fa3Chih-yu Huang
503664d72e6630522589cc013b25f5c9cdd5d949fa3Chih-yu Huang        mShutterCallback = null;
504664d72e6630522589cc013b25f5c9cdd5d949fa3Chih-yu Huang        mRawImageCallback = null;
505664d72e6630522589cc013b25f5c9cdd5d949fa3Chih-yu Huang        mPostviewCallback = null;
506664d72e6630522589cc013b25f5c9cdd5d949fa3Chih-yu Huang        mJpegCallback = null;
507664d72e6630522589cc013b25f5c9cdd5d949fa3Chih-yu Huang        mAutoFocusCallback = null;
5084c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li    }
5094c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li
5104c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li    private native final void _stopPreview();
5119b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
5129066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
5139066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * Return current preview state.
5149066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     *
5159066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * FIXME: Unhide before release
5169066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @hide
5179066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
5189066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public native final boolean previewEnabled();
5199b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
5209066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
521bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * Installs a callback to be invoked for every preview frame in addition
522bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * to displaying them on the screen.  The callback will be repeatedly called
523bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * for as long as preview is active.  This method can be called at any time,
524bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * even while preview is live.  Any other preview callbacks are overridden.
5259066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     *
526bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * @param cb a callback object that receives a copy of each preview frame,
527bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     *     or null to stop receiving callbacks.
5289066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
5299066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public final void setPreviewCallback(PreviewCallback cb) {
5309066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        mPreviewCallback = cb;
5319066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        mOneShot = false;
53294927dffce1626898b59579dfc5af53b5de8cef6Andrew Harp        mWithBuffer = false;
533a6118c6383c6f5703a576d08586a340fd71d28a4Dave Sparks        // Always use one-shot mode. We fake camera preview mode by
534a6118c6383c6f5703a576d08586a340fd71d28a4Dave Sparks        // doing one-shot preview continuously.
53594927dffce1626898b59579dfc5af53b5de8cef6Andrew Harp        setHasPreviewCallback(cb != null, false);
5369066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
5379066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
5389066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
539bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * Installs a callback to be invoked for the next preview frame in addition
540bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * to displaying it on the screen.  After one invocation, the callback is
541bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * cleared. This method can be called any time, even when preview is live.
542bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * Any other preview callbacks are overridden.
5439066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     *
544bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * @param cb a callback object that receives a copy of the next preview frame,
545bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     *     or null to stop receiving callbacks.
5469066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
5479066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public final void setOneShotPreviewCallback(PreviewCallback cb) {
54894927dffce1626898b59579dfc5af53b5de8cef6Andrew Harp        mPreviewCallback = cb;
54994927dffce1626898b59579dfc5af53b5de8cef6Andrew Harp        mOneShot = true;
55094927dffce1626898b59579dfc5af53b5de8cef6Andrew Harp        mWithBuffer = false;
55194927dffce1626898b59579dfc5af53b5de8cef6Andrew Harp        setHasPreviewCallback(cb != null, false);
55294927dffce1626898b59579dfc5af53b5de8cef6Andrew Harp    }
55394927dffce1626898b59579dfc5af53b5de8cef6Andrew Harp
55494927dffce1626898b59579dfc5af53b5de8cef6Andrew Harp    private native final void setHasPreviewCallback(boolean installed, boolean manualBuffer);
55594927dffce1626898b59579dfc5af53b5de8cef6Andrew Harp
55694927dffce1626898b59579dfc5af53b5de8cef6Andrew Harp    /**
557bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * Installs a callback to be invoked for every preview frame, using buffers
558bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * supplied with {@link #addCallbackBuffer(byte[])}, in addition to
559bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * displaying them on the screen.  The callback will be repeatedly called
560bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * for as long as preview is active and buffers are available.
561bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * Any other preview callbacks are overridden.
56294927dffce1626898b59579dfc5af53b5de8cef6Andrew Harp     *
563bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * <p>The purpose of this method is to improve preview efficiency and frame
564bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * rate by allowing preview frame memory reuse.  You must call
565bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * {@link #addCallbackBuffer(byte[])} at some point -- before or after
566bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * calling this method -- or no callbacks will received.
56794927dffce1626898b59579dfc5af53b5de8cef6Andrew Harp     *
568bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * The buffer queue will be cleared if this method is called with a null
569bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * callback, {@link #setPreviewCallback(Camera.PreviewCallback)} is called,
570bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * or {@link #setOneShotPreviewCallback(Camera.PreviewCallback)} is called.
57194927dffce1626898b59579dfc5af53b5de8cef6Andrew Harp     *
572bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * @param cb a callback object that receives a copy of the preview frame,
573bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     *     or null to stop receiving callbacks and clear the buffer queue.
574bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * @see #addCallbackBuffer(byte[])
57594927dffce1626898b59579dfc5af53b5de8cef6Andrew Harp     */
57694927dffce1626898b59579dfc5af53b5de8cef6Andrew Harp    public final void setPreviewCallbackWithBuffer(PreviewCallback cb) {
57794927dffce1626898b59579dfc5af53b5de8cef6Andrew Harp        mPreviewCallback = cb;
57894927dffce1626898b59579dfc5af53b5de8cef6Andrew Harp        mOneShot = false;
57994927dffce1626898b59579dfc5af53b5de8cef6Andrew Harp        mWithBuffer = true;
58094927dffce1626898b59579dfc5af53b5de8cef6Andrew Harp        setHasPreviewCallback(cb != null, true);
5819066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
5829066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
58394927dffce1626898b59579dfc5af53b5de8cef6Andrew Harp    /**
5843f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li     * Adds a pre-allocated buffer to the preview callback buffer queue.
5853f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li     * Applications can add one or more buffers to the queue. When a preview
586bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * frame arrives and there is still at least one available buffer, the
587bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * buffer will be used and removed from the queue. Then preview callback is
588bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * invoked with the buffer. If a frame arrives and there is no buffer left,
589bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * the frame is discarded. Applications should add buffers back when they
590bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * finish processing the data in them.
591c10275abd6a494c93a025f683dde104a5d4f2793Wu-cheng Li     *
592bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * <p>The size of the buffer is determined by multiplying the preview
593e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     * image width, height, and bytes per pixel. The width and height can be
594e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     * read from {@link Camera.Parameters#getPreviewSize()}. Bytes per pixel
595bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * can be computed from
596bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * {@link android.graphics.ImageFormat#getBitsPerPixel(int)} / 8,
597bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * using the image format from {@link Camera.Parameters#getPreviewFormat()}.
59894927dffce1626898b59579dfc5af53b5de8cef6Andrew Harp     *
599bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * <p>This method is only necessary when
600e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     * {@link #setPreviewCallbackWithBuffer(PreviewCallback)} is used. When
601bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * {@link #setPreviewCallback(PreviewCallback)} or
602bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * {@link #setOneShotPreviewCallback(PreviewCallback)} are used, buffers
603e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     * are automatically allocated. When a supplied buffer is too small to
604e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     * hold the preview frame data, preview callback will return null and
605e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     * the buffer will be removed from the buffer queue.
60694927dffce1626898b59579dfc5af53b5de8cef6Andrew Harp     *
607bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * @param callbackBuffer the buffer to add to the queue.
608bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     *     The size should be width * height * bits_per_pixel / 8.
6095b9bcda3a26e9b1f9b1eff28a2be8853d69614f0Wu-cheng Li     * @see #setPreviewCallbackWithBuffer(PreviewCallback)
61094927dffce1626898b59579dfc5af53b5de8cef6Andrew Harp     */
611e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong    public final void addCallbackBuffer(byte[] callbackBuffer)
612e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong    {
613e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong        _addCallbackBuffer(callbackBuffer, CAMERA_MSG_PREVIEW_FRAME);
614e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong    }
615e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong
616e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong    /**
617e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     * Adds a pre-allocated buffer to the raw image callback buffer queue.
618e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     * Applications can add one or more buffers to the queue. When a raw image
619e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     * frame arrives and there is still at least one available buffer, the
620e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     * buffer will be used to hold the raw image data and removed from the
621e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     * queue. Then raw image callback is invoked with the buffer. If a raw
622e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     * image frame arrives but there is no buffer left, the frame is
623e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     * discarded. Applications should add buffers back when they finish
624e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     * processing the data in them by calling this method again in order
625e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     * to avoid running out of raw image callback buffers.
626e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     *
627e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     * <p>The size of the buffer is determined by multiplying the raw image
628e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     * width, height, and bytes per pixel. The width and height can be
629e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     * read from {@link Camera.Parameters#getPictureSize()}. Bytes per pixel
630e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     * can be computed from
631e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     * {@link android.graphics.ImageFormat#getBitsPerPixel(int)} / 8,
632e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     * using the image format from {@link Camera.Parameters#getPreviewFormat()}.
633e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     *
634e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     * <p>This method is only necessary when the PictureCallbck for raw image
635e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     * is used while calling {@link #takePicture(Camera.ShutterCallback,
636e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     * Camera.PictureCallback, Camera.PictureCallback, Camera.PictureCallback)}.
637e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     *
63832a972c693400db50717435139fa292a63bc937aEino-Ville Talvala     * <p>Please note that by calling this method, the mode for
63932a972c693400db50717435139fa292a63bc937aEino-Ville Talvala     * application-managed callback buffers is triggered. If this method has
64032a972c693400db50717435139fa292a63bc937aEino-Ville Talvala     * never been called, null will be returned by the raw image callback since
64132a972c693400db50717435139fa292a63bc937aEino-Ville Talvala     * there is no image callback buffer available. Furthermore, When a supplied
64232a972c693400db50717435139fa292a63bc937aEino-Ville Talvala     * buffer is too small to hold the raw image data, raw image callback will
64332a972c693400db50717435139fa292a63bc937aEino-Ville Talvala     * return null and the buffer will be removed from the buffer queue.
644e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     *
645e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     * @param callbackBuffer the buffer to add to the raw image callback buffer
646e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     *     queue. The size should be width * height * (bits per pixel) / 8. An
647e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     *     null callbackBuffer will be ignored and won't be added to the queue.
648e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     *
649e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     * @see #takePicture(Camera.ShutterCallback,
650e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     * Camera.PictureCallback, Camera.PictureCallback, Camera.PictureCallback)}.
651e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     *
652e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     * {@hide}
653e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     */
654e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong    public final void addRawImageCallbackBuffer(byte[] callbackBuffer)
655e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong    {
656e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong        addCallbackBuffer(callbackBuffer, CAMERA_MSG_RAW_IMAGE);
657e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong    }
658e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong
659e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong    private final void addCallbackBuffer(byte[] callbackBuffer, int msgType)
660e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong    {
661e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong        // CAMERA_MSG_VIDEO_FRAME may be allowed in the future.
662e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong        if (msgType != CAMERA_MSG_PREVIEW_FRAME &&
663e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong            msgType != CAMERA_MSG_RAW_IMAGE) {
664e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong            throw new IllegalArgumentException(
665e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong                            "Unsupported message type: " + msgType);
666e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong        }
667e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong
668e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong        _addCallbackBuffer(callbackBuffer, msgType);
669e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong    }
670e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong
671e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong    private native final void _addCallbackBuffer(
672e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong                                byte[] callbackBuffer, int msgType);
6739066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
6749066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    private class EventHandler extends Handler
6759066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    {
6769066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        private Camera mCamera;
6779066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
6789066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        public EventHandler(Camera c, Looper looper) {
6799066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            super(looper);
6809066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            mCamera = c;
6819066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
6829066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
6839066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        @Override
6849066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        public void handleMessage(Message msg) {
6859066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            switch(msg.what) {
686c62f9bd13327937aa2d2f20b44215397120634c1Dave Sparks            case CAMERA_MSG_SHUTTER:
6879066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                if (mShutterCallback != null) {
6889066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                    mShutterCallback.onShutter();
6899066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                }
6909066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                return;
691c62f9bd13327937aa2d2f20b44215397120634c1Dave Sparks
692c62f9bd13327937aa2d2f20b44215397120634c1Dave Sparks            case CAMERA_MSG_RAW_IMAGE:
693e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks                if (mRawImageCallback != null) {
6949066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                    mRawImageCallback.onPictureTaken((byte[])msg.obj, mCamera);
695e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks                }
6969066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                return;
6979066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
698c62f9bd13327937aa2d2f20b44215397120634c1Dave Sparks            case CAMERA_MSG_COMPRESSED_IMAGE:
699e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks                if (mJpegCallback != null) {
7009066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                    mJpegCallback.onPictureTaken((byte[])msg.obj, mCamera);
701e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks                }
7029066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                return;
7039b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
704c62f9bd13327937aa2d2f20b44215397120634c1Dave Sparks            case CAMERA_MSG_PREVIEW_FRAME:
7059066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                if (mPreviewCallback != null) {
706a6118c6383c6f5703a576d08586a340fd71d28a4Dave Sparks                    PreviewCallback cb = mPreviewCallback;
7079066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                    if (mOneShot) {
708a6118c6383c6f5703a576d08586a340fd71d28a4Dave Sparks                        // Clear the callback variable before the callback
709a6118c6383c6f5703a576d08586a340fd71d28a4Dave Sparks                        // in case the app calls setPreviewCallback from
710a6118c6383c6f5703a576d08586a340fd71d28a4Dave Sparks                        // the callback function
7119066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                        mPreviewCallback = null;
71294927dffce1626898b59579dfc5af53b5de8cef6Andrew Harp                    } else if (!mWithBuffer) {
713a6118c6383c6f5703a576d08586a340fd71d28a4Dave Sparks                        // We're faking the camera preview mode to prevent
714a6118c6383c6f5703a576d08586a340fd71d28a4Dave Sparks                        // the app from being flooded with preview frames.
715a6118c6383c6f5703a576d08586a340fd71d28a4Dave Sparks                        // Set to oneshot mode again.
71694927dffce1626898b59579dfc5af53b5de8cef6Andrew Harp                        setHasPreviewCallback(true, false);
7179066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                    }
718a6118c6383c6f5703a576d08586a340fd71d28a4Dave Sparks                    cb.onPreviewFrame((byte[])msg.obj, mCamera);
7199066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                }
7209066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                return;
7219066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
722e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks            case CAMERA_MSG_POSTVIEW_FRAME:
723e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks                if (mPostviewCallback != null) {
724e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks                    mPostviewCallback.onPictureTaken((byte[])msg.obj, mCamera);
725e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks                }
726e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks                return;
727e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks
728c62f9bd13327937aa2d2f20b44215397120634c1Dave Sparks            case CAMERA_MSG_FOCUS:
729e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks                if (mAutoFocusCallback != null) {
7309066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                    mAutoFocusCallback.onAutoFocus(msg.arg1 == 0 ? false : true, mCamera);
731e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks                }
732e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks                return;
733e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks
734e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks            case CAMERA_MSG_ZOOM:
7353f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li                if (mZoomListener != null) {
7363f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li                    mZoomListener.onZoomChange(msg.arg1, msg.arg2 != 0, mCamera);
737e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks                }
7389066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                return;
7399066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
740bb1e275c0e684dd213f124da77110cdd9d6f090cWu-cheng Li            case CAMERA_MSG_PREVIEW_METADATA:
7414c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li                if (mFaceListener != null) {
742f0d6a48c6ad852b84687127f14b1ffde02416dc4Wu-cheng Li                    mFaceListener.onFaceDetection((Face[])msg.obj, mCamera);
7434c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li                }
7444c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li                return;
7454c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li
746c62f9bd13327937aa2d2f20b44215397120634c1Dave Sparks            case CAMERA_MSG_ERROR :
7479066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                Log.e(TAG, "Error " + msg.arg1);
748e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks                if (mErrorCallback != null) {
7499066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                    mErrorCallback.onError(msg.arg1, mCamera);
750e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks                }
7519066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                return;
7529066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
7539066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            default:
7549066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                Log.e(TAG, "Unknown message type " + msg.what);
7559066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                return;
7569066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            }
7579066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
7589066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
7599066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
7609066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    private static void postEventFromNative(Object camera_ref,
7619066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                                            int what, int arg1, int arg2, Object obj)
7629066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    {
7639066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        Camera c = (Camera)((WeakReference)camera_ref).get();
7649066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        if (c == null)
7659066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            return;
7669066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
7679066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        if (c.mEventHandler != null) {
7689066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            Message m = c.mEventHandler.obtainMessage(what, arg1, arg2, obj);
7699066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            c.mEventHandler.sendMessage(m);
7709066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
7719066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
7729066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
7739066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
774bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * Callback interface used to notify on completion of camera auto focus.
775bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     *
7767478ea6848c0059e65a4089b4ec2ff4158520870Wu-cheng Li     * <p>Devices that do not support auto-focus will receive a "fake"
7777478ea6848c0059e65a4089b4ec2ff4158520870Wu-cheng Li     * callback to this interface. If your application needs auto-focus and
778df4578e8ab7008a7e528d5af2ae761b33cf2bdf4Scott Main     * should not be installed on devices <em>without</em> auto-focus, you must
779df4578e8ab7008a7e528d5af2ae761b33cf2bdf4Scott Main     * declare that your app uses the
7807478ea6848c0059e65a4089b4ec2ff4158520870Wu-cheng Li     * {@code android.hardware.camera.autofocus} feature, in the
781df4578e8ab7008a7e528d5af2ae761b33cf2bdf4Scott Main     * <a href="{@docRoot}guide/topics/manifest/uses-feature-element.html">&lt;uses-feature></a>
782df4578e8ab7008a7e528d5af2ae761b33cf2bdf4Scott Main     * manifest element.</p>
783bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     *
784bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * @see #autoFocus(AutoFocusCallback)
7859066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
7869066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public interface AutoFocusCallback
7879066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    {
7889066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        /**
78969ea4e15e52c456537575d21443ac1efdb03a902Brad Fitzpatrick         * Called when the camera auto focus completes.  If the camera
79069ea4e15e52c456537575d21443ac1efdb03a902Brad Fitzpatrick         * does not support auto-focus and autoFocus is called,
79169ea4e15e52c456537575d21443ac1efdb03a902Brad Fitzpatrick         * onAutoFocus will be called immediately with a fake value of
79269ea4e15e52c456537575d21443ac1efdb03a902Brad Fitzpatrick         * <code>success</code> set to <code>true</code>.
7939b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
794b4f95be03e018df825356fe2cd363797c66303f1Wu-cheng Li         * The auto-focus routine does not lock auto-exposure and auto-white
795b4f95be03e018df825356fe2cd363797c66303f1Wu-cheng Li         * balance after it completes.
79683d3352cf7a67efd60732c0d40e5928f642f6808Eino-Ville Talvala         *
7979066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * @param success true if focus was successful, false if otherwise
7989066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * @param camera  the Camera service object
79983d3352cf7a67efd60732c0d40e5928f642f6808Eino-Ville Talvala         * @see android.hardware.Camera.Parameters#setAutoExposureLock(boolean)
80083d3352cf7a67efd60732c0d40e5928f642f6808Eino-Ville Talvala         * @see android.hardware.Camera.Parameters#setAutoWhiteBalanceLock(boolean)
8019066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         */
8029066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        void onAutoFocus(boolean success, Camera camera);
80353b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li    }
8049066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
8059066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
806bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * Starts camera auto-focus and registers a callback function to run when
807bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * the camera is focused.  This method is only valid when preview is active
808bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * (between {@link #startPreview()} and before {@link #stopPreview()}).
809bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     *
810bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * <p>Callers should check
811bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * {@link android.hardware.Camera.Parameters#getFocusMode()} to determine if
812bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * this method should be called. If the camera does not support auto-focus,
813bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * it is a no-op and {@link AutoFocusCallback#onAutoFocus(boolean, Camera)}
81436322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li     * callback will be called immediately.
815bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     *
816da0a56df963353a1f1bd1914fa31f870d982dd5aScott Main     * <p>If your application should not be installed
8177478ea6848c0059e65a4089b4ec2ff4158520870Wu-cheng Li     * on devices without auto-focus, you must declare that your application
8187478ea6848c0059e65a4089b4ec2ff4158520870Wu-cheng Li     * uses auto-focus with the
819df4578e8ab7008a7e528d5af2ae761b33cf2bdf4Scott Main     * <a href="{@docRoot}guide/topics/manifest/uses-feature-element.html">&lt;uses-feature></a>
820df4578e8ab7008a7e528d5af2ae761b33cf2bdf4Scott Main     * manifest element.</p>
821bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     *
822068ef42c3ffe1eccec10f97f08541304f679fe67Wu-cheng Li     * <p>If the current flash mode is not
823068ef42c3ffe1eccec10f97f08541304f679fe67Wu-cheng Li     * {@link android.hardware.Camera.Parameters#FLASH_MODE_OFF}, flash may be
824bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * fired during auto-focus, depending on the driver and camera hardware.<p>
8257478ea6848c0059e65a4089b4ec2ff4158520870Wu-cheng Li     *
82653b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li     * <p>Auto-exposure lock {@link android.hardware.Camera.Parameters#getAutoExposureLock()}
827b4f95be03e018df825356fe2cd363797c66303f1Wu-cheng Li     * and auto-white balance locks {@link android.hardware.Camera.Parameters#getAutoWhiteBalanceLock()}
828b4f95be03e018df825356fe2cd363797c66303f1Wu-cheng Li     * do not change during and after autofocus. But auto-focus routine may stop
829b4f95be03e018df825356fe2cd363797c66303f1Wu-cheng Li     * auto-exposure and auto-white balance transiently during focusing.
83083d3352cf7a67efd60732c0d40e5928f642f6808Eino-Ville Talvala     *
83153b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li     * <p>Stopping preview with {@link #stopPreview()}, or triggering still
83253b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li     * image capture with {@link #takePicture(Camera.ShutterCallback,
83353b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li     * Camera.PictureCallback, Camera.PictureCallback)}, will not change the
83453b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li     * the focus position. Applications must call cancelAutoFocus to reset the
83553b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li     * focus.</p>
83653b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li     *
8379066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @param cb the callback to run
838bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * @see #cancelAutoFocus()
83983d3352cf7a67efd60732c0d40e5928f642f6808Eino-Ville Talvala     * @see android.hardware.Camera.Parameters#setAutoExposureLock(boolean)
84083d3352cf7a67efd60732c0d40e5928f642f6808Eino-Ville Talvala     * @see android.hardware.Camera.Parameters#setAutoWhiteBalanceLock(boolean)
8419066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
8429066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public final void autoFocus(AutoFocusCallback cb)
8439066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    {
8449066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        mAutoFocusCallback = cb;
8459066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        native_autoFocus();
8469066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
8479066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    private native final void native_autoFocus();
8489066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
8499066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
850bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * Cancels any auto-focus function in progress.
851bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * Whether or not auto-focus is currently in progress,
852bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * this function will return the focus position to the default.
853244f8c26365a303d9dd861bd48a29a4b48578da1Chih-Chung Chang     * If the camera does not support auto-focus, this is a no-op.
854bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     *
855bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * @see #autoFocus(Camera.AutoFocusCallback)
856244f8c26365a303d9dd861bd48a29a4b48578da1Chih-Chung Chang     */
857244f8c26365a303d9dd861bd48a29a4b48578da1Chih-Chung Chang    public final void cancelAutoFocus()
858244f8c26365a303d9dd861bd48a29a4b48578da1Chih-Chung Chang    {
859244f8c26365a303d9dd861bd48a29a4b48578da1Chih-Chung Chang        mAutoFocusCallback = null;
860244f8c26365a303d9dd861bd48a29a4b48578da1Chih-Chung Chang        native_cancelAutoFocus();
861244f8c26365a303d9dd861bd48a29a4b48578da1Chih-Chung Chang    }
862244f8c26365a303d9dd861bd48a29a4b48578da1Chih-Chung Chang    private native final void native_cancelAutoFocus();
863244f8c26365a303d9dd861bd48a29a4b48578da1Chih-Chung Chang
864244f8c26365a303d9dd861bd48a29a4b48578da1Chih-Chung Chang    /**
865bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * Callback interface used to signal the moment of actual image capture.
866bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     *
867bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * @see #takePicture(ShutterCallback, PictureCallback, PictureCallback, PictureCallback)
8689066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
8699066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public interface ShutterCallback
8709066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    {
8719066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        /**
872bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor         * Called as near as possible to the moment when a photo is captured
873bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor         * from the sensor.  This is a good opportunity to play a shutter sound
874bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor         * or give other feedback of camera operation.  This may be some time
875bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor         * after the photo was triggered, but some time before the actual data
876bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor         * is available.
8779066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         */
8789066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        void onShutter();
8799066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
8809066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
8819066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
882bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * Callback interface used to supply image data from a photo capture.
883bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     *
884bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * @see #takePicture(ShutterCallback, PictureCallback, PictureCallback, PictureCallback)
8859066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
8869066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public interface PictureCallback {
8879066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        /**
888bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor         * Called when image data is available after a picture is taken.
889bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor         * The format of the data depends on the context of the callback
890bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor         * and {@link Camera.Parameters} settings.
8919b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
8929066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * @param data   a byte array of the picture data
8939066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * @param camera the Camera service object
8949066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         */
8959066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        void onPictureTaken(byte[] data, Camera camera);
8969066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    };
8979066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
8989066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
899bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * Equivalent to takePicture(shutter, raw, null, jpeg).
9009b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li     *
901bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * @see #takePicture(ShutterCallback, PictureCallback, PictureCallback, PictureCallback)
9029066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
9039066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public final void takePicture(ShutterCallback shutter, PictureCallback raw,
9049066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            PictureCallback jpeg) {
905e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks        takePicture(shutter, raw, null, jpeg);
906e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks    }
907e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong    private native final void native_takePicture(int msgType);
908e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks
909e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks    /**
9109b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li     * Triggers an asynchronous image capture. The camera service will initiate
9119b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li     * a series of callbacks to the application as the image capture progresses.
9129b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li     * The shutter callback occurs after the image is captured. This can be used
9139b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li     * to trigger a sound to let the user know that image has been captured. The
9149b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li     * raw callback occurs when the raw image data is available (NOTE: the data
915e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     * will be null if there is no raw image callback buffer available or the
916e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     * raw image callback buffer is not large enough to hold the raw image).
9179b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li     * The postview callback occurs when a scaled, fully processed postview
9189b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li     * image is available (NOTE: not all hardware supports this). The jpeg
9199b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li     * callback occurs when the compressed image is available. If the
9209b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li     * application does not need a particular callback, a null can be passed
9219b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li     * instead of a callback method.
922e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks     *
923bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * <p>This method is only valid when preview is active (after
924bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * {@link #startPreview()}).  Preview will be stopped after the image is
925bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * taken; callers must call {@link #startPreview()} again if they want to
92642419ce28a09eb63e29a8fef87e6f5534f41902fWu-cheng Li     * re-start preview or take more pictures. This should not be called between
92742419ce28a09eb63e29a8fef87e6f5534f41902fWu-cheng Li     * {@link android.media.MediaRecorder#start()} and
92842419ce28a09eb63e29a8fef87e6f5534f41902fWu-cheng Li     * {@link android.media.MediaRecorder#stop()}.
92940057ce749c8c4d274db0352a2af4344bda92dbaWu-cheng Li     *
930bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * <p>After calling this method, you must not call {@link #startPreview()}
931bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * or take another picture until the JPEG callback has returned.
93240057ce749c8c4d274db0352a2af4344bda92dbaWu-cheng Li     *
933bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * @param shutter   the callback for image capture moment, or null
934bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * @param raw       the callback for raw (uncompressed) image data, or null
935e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks     * @param postview  callback with postview image data, may be null
936bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * @param jpeg      the callback for JPEG image data, or null
937e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks     */
938e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks    public final void takePicture(ShutterCallback shutter, PictureCallback raw,
939e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks            PictureCallback postview, PictureCallback jpeg) {
9409066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        mShutterCallback = shutter;
9419066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        mRawImageCallback = raw;
942e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks        mPostviewCallback = postview;
9439066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        mJpegCallback = jpeg;
944e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong
945e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong        // If callback is not set, do not send me callbacks.
946e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong        int msgType = 0;
947e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong        if (mShutterCallback != null) {
948e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong            msgType |= CAMERA_MSG_SHUTTER;
949e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong        }
950e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong        if (mRawImageCallback != null) {
951e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong            msgType |= CAMERA_MSG_RAW_IMAGE;
952e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong        }
953e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong        if (mPostviewCallback != null) {
954e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong            msgType |= CAMERA_MSG_POSTVIEW_FRAME;
955e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong        }
956e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong        if (mJpegCallback != null) {
957e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong            msgType |= CAMERA_MSG_COMPRESSED_IMAGE;
958e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong        }
959e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong
960e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong        native_takePicture(msgType);
9619066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
9629066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
963e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks    /**
964bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * Zooms to the requested value smoothly. The driver will notify {@link
9653f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li     * OnZoomChangeListener} of the zoom value and whether zoom is stopped at
9663f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li     * the time. For example, suppose the current zoom is 0 and startSmoothZoom
967bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * is called with value 3. The
968bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * {@link Camera.OnZoomChangeListener#onZoomChange(int, boolean, Camera)}
969bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * method will be called three times with zoom values 1, 2, and 3.
970bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * Applications can call {@link #stopSmoothZoom} to stop the zoom earlier.
971bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * Applications should not call startSmoothZoom again or change the zoom
972bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * value before zoom stops. If the supplied zoom value equals to the current
973bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * zoom value, no zoom callback will be generated. This method is supported
974bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * if {@link android.hardware.Camera.Parameters#isSmoothZoomSupported}
975bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * returns true.
97636f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li     *
97736f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li     * @param value zoom value. The valid range is 0 to {@link
97836f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li     *              android.hardware.Camera.Parameters#getMaxZoom}.
9790ca25191c663ef229f1f475b17899f2017ed6980Wu-cheng Li     * @throws IllegalArgumentException if the zoom value is invalid.
9800ca25191c663ef229f1f475b17899f2017ed6980Wu-cheng Li     * @throws RuntimeException if the method fails.
981bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * @see #setZoomChangeListener(OnZoomChangeListener)
98236f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li     */
98336f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li    public native final void startSmoothZoom(int value);
98436f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li
98536f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li    /**
986bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * Stops the smooth zoom. Applications should wait for the {@link
9873f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li     * OnZoomChangeListener} to know when the zoom is actually stopped. This
9883f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li     * method is supported if {@link
9898cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li     * android.hardware.Camera.Parameters#isSmoothZoomSupported} is true.
9900ca25191c663ef229f1f475b17899f2017ed6980Wu-cheng Li     *
9910ca25191c663ef229f1f475b17899f2017ed6980Wu-cheng Li     * @throws RuntimeException if the method fails.
99236f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li     */
99336f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li    public native final void stopSmoothZoom();
99436f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li
99536f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li    /**
9962fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li     * Set the clockwise rotation of preview display in degrees. This affects
9972fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li     * the preview frames and the picture displayed after snapshot. This method
9982fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li     * is useful for portrait mode applications. Note that preview display of
999b982fb4fd36a3cd24a0bb17c964139fe4c9cbb47Wu-cheng Li     * front-facing cameras is flipped horizontally before the rotation, that
1000b982fb4fd36a3cd24a0bb17c964139fe4c9cbb47Wu-cheng Li     * is, the image is reflected along the central vertical axis of the camera
1001b982fb4fd36a3cd24a0bb17c964139fe4c9cbb47Wu-cheng Li     * sensor. So the users can see themselves as looking into a mirror.
1002d1d7706fce19a9a0cf71ff9b65f3aba9b89eeb3bChih-Chung Chang     *
100369ea4e15e52c456537575d21443ac1efdb03a902Brad Fitzpatrick     * <p>This does not affect the order of byte array passed in {@link
10042fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li     * PreviewCallback#onPreviewFrame}, JPEG pictures, or recorded videos. This
10052fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li     * method is not allowed to be called during preview.
1006d1d7706fce19a9a0cf71ff9b65f3aba9b89eeb3bChih-Chung Chang     *
100769ea4e15e52c456537575d21443ac1efdb03a902Brad Fitzpatrick     * <p>If you want to make the camera image show in the same orientation as
100869ea4e15e52c456537575d21443ac1efdb03a902Brad Fitzpatrick     * the display, you can use the following code.
1009b8bb78f54b48868465a9d69d65fda08524ab5ae1Chih-Chung Chang     * <pre>
1010724c52244423feced2677fbd1f905e0b8b0639f2Chih-Chung Chang     * public static void setCameraDisplayOrientation(Activity activity,
1011724c52244423feced2677fbd1f905e0b8b0639f2Chih-Chung Chang     *         int cameraId, android.hardware.Camera camera) {
1012724c52244423feced2677fbd1f905e0b8b0639f2Chih-Chung Chang     *     android.hardware.Camera.CameraInfo info =
1013724c52244423feced2677fbd1f905e0b8b0639f2Chih-Chung Chang     *             new android.hardware.Camera.CameraInfo();
1014724c52244423feced2677fbd1f905e0b8b0639f2Chih-Chung Chang     *     android.hardware.Camera.getCameraInfo(cameraId, info);
1015724c52244423feced2677fbd1f905e0b8b0639f2Chih-Chung Chang     *     int rotation = activity.getWindowManager().getDefaultDisplay()
1016724c52244423feced2677fbd1f905e0b8b0639f2Chih-Chung Chang     *             .getRotation();
1017724c52244423feced2677fbd1f905e0b8b0639f2Chih-Chung Chang     *     int degrees = 0;
1018724c52244423feced2677fbd1f905e0b8b0639f2Chih-Chung Chang     *     switch (rotation) {
1019724c52244423feced2677fbd1f905e0b8b0639f2Chih-Chung Chang     *         case Surface.ROTATION_0: degrees = 0; break;
1020724c52244423feced2677fbd1f905e0b8b0639f2Chih-Chung Chang     *         case Surface.ROTATION_90: degrees = 90; break;
1021724c52244423feced2677fbd1f905e0b8b0639f2Chih-Chung Chang     *         case Surface.ROTATION_180: degrees = 180; break;
1022724c52244423feced2677fbd1f905e0b8b0639f2Chih-Chung Chang     *         case Surface.ROTATION_270: degrees = 270; break;
1023724c52244423feced2677fbd1f905e0b8b0639f2Chih-Chung Chang     *     }
1024b8bb78f54b48868465a9d69d65fda08524ab5ae1Chih-Chung Chang     *
10252fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li     *     int result;
10262fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li     *     if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
10272fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li     *         result = (info.orientation + degrees) % 360;
10282fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li     *         result = (360 - result) % 360;  // compensate the mirror
10292fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li     *     } else {  // back-facing
10302fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li     *         result = (info.orientation - degrees + 360) % 360;
10312fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li     *     }
1032724c52244423feced2677fbd1f905e0b8b0639f2Chih-Chung Chang     *     camera.setDisplayOrientation(result);
1033724c52244423feced2677fbd1f905e0b8b0639f2Chih-Chung Chang     * }
1034b8bb78f54b48868465a9d69d65fda08524ab5ae1Chih-Chung Chang     * </pre>
1035d303362ac21fb9de40f2f2366cbe7ecaa113dc12Wu-cheng Li     *
1036d303362ac21fb9de40f2f2366cbe7ecaa113dc12Wu-cheng Li     * <p>Starting from API level 14, this method can be called when preview is
1037d303362ac21fb9de40f2f2366cbe7ecaa113dc12Wu-cheng Li     * active.
1038d303362ac21fb9de40f2f2366cbe7ecaa113dc12Wu-cheng Li     *
1039d1d7706fce19a9a0cf71ff9b65f3aba9b89eeb3bChih-Chung Chang     * @param degrees the angle that the picture will be rotated clockwise.
1040e7bd22a9d9441916aa9c67d80ee9f02a2d3e10e5Chih-Chung Chang     *                Valid values are 0, 90, 180, and 270. The starting
1041e7bd22a9d9441916aa9c67d80ee9f02a2d3e10e5Chih-Chung Chang     *                position is 0 (landscape).
10422fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li     * @see #setPreviewDisplay(SurfaceHolder)
1043d1d7706fce19a9a0cf71ff9b65f3aba9b89eeb3bChih-Chung Chang     */
1044d1d7706fce19a9a0cf71ff9b65f3aba9b89eeb3bChih-Chung Chang    public native final void setDisplayOrientation(int degrees);
1045d1d7706fce19a9a0cf71ff9b65f3aba9b89eeb3bChih-Chung Chang
1046d1d7706fce19a9a0cf71ff9b65f3aba9b89eeb3bChih-Chung Chang    /**
1047bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * Callback interface for zoom changes during a smooth zoom operation.
1048bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     *
1049bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * @see #setZoomChangeListener(OnZoomChangeListener)
1050bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * @see #startSmoothZoom(int)
1051e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks     */
10523f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li    public interface OnZoomChangeListener
1053e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks    {
1054e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks        /**
1055bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor         * Called when the zoom value has changed during a smooth zoom.
105636f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li         *
105736f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li         * @param zoomValue the current zoom value. In smooth zoom mode, camera
10583f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         *                  calls this for every new zoom value.
105936f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li         * @param stopped whether smooth zoom is stopped. If the value is true,
106036f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li         *                this is the last zoom update for the application.
1061e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks         * @param camera  the Camera service object
1062e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks         */
10633f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li        void onZoomChange(int zoomValue, boolean stopped, Camera camera);
1064e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks    };
1065e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks
1066e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks    /**
10673f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li     * Registers a listener to be notified when the zoom value is updated by the
106836f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li     * camera driver during smooth zoom.
10698cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li     *
10703f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li     * @param listener the listener to notify
10718cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li     * @see #startSmoothZoom(int)
1072e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks     */
10733f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li    public final void setZoomChangeListener(OnZoomChangeListener listener)
1074e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks    {
10753f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li        mZoomListener = listener;
1076e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks    }
10779b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
10784c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li    /**
10794c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li     * Callback interface for face detected in the preview frame.
10804c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li     *
10814c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li     */
10824c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li    public interface FaceDetectionListener
10834c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li    {
10844c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li        /**
10854c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li         * Notify the listener of the detected faces in the preview frame.
10864c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li         *
108753b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li         * @param faces The detected faces in a list
1088464cb21e2aaa448072449b82156f18bd64c0e613Joe Fernandez         * @param camera  The {@link Camera} service object
10894c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li         */
1090f0d6a48c6ad852b84687127f14b1ffde02416dc4Wu-cheng Li        void onFaceDetection(Face[] faces, Camera camera);
10914c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li    }
10924c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li
10934c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li    /**
1094c0c683b3344c67700882f8059e7d18266366daa9Wu-cheng Li     * Registers a listener to be notified about the faces detected in the
10954c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li     * preview frame.
10964c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li     *
10974c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li     * @param listener the listener to notify
1098c0c683b3344c67700882f8059e7d18266366daa9Wu-cheng Li     * @see #startFaceDetection()
10994c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li     */
11004c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li    public final void setFaceDetectionListener(FaceDetectionListener listener)
11014c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li    {
11024c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li        mFaceListener = listener;
11034c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li    }
11044c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li
11054c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li    /**
1106c0c683b3344c67700882f8059e7d18266366daa9Wu-cheng Li     * Starts the face detection. This should be called after preview is started.
11074c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li     * The camera will notify {@link FaceDetectionListener} of the detected
11084c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li     * faces in the preview frame. The detected faces may be the same as the
11094c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li     * previous ones. Applications should call {@link #stopFaceDetection} to
11104c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li     * stop the face detection. This method is supported if {@link
1111c0c683b3344c67700882f8059e7d18266366daa9Wu-cheng Li     * Parameters#getMaxNumDetectedFaces()} returns a number larger than 0.
11124c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li     * If the face detection has started, apps should not call this again.
11134c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li     *
11148c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li     * <p>When the face detection is running, {@link Parameters#setWhiteBalance(String)},
11154c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li     * {@link Parameters#setFocusAreas(List)}, and {@link Parameters#setMeteringAreas(List)}
11168c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li     * have no effect. The camera uses the detected faces to do auto-white balance,
11178c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li     * auto exposure, and autofocus.
11188c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li     *
11198c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li     * <p>If the apps call {@link #autoFocus(AutoFocusCallback)}, the camera
11208c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li     * will stop sending face callbacks. The last face callback indicates the
11218c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li     * areas used to do autofocus. After focus completes, face detection will
11228c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li     * resume sending face callbacks. If the apps call {@link
11238c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li     * #cancelAutoFocus()}, the face callbacks will also resume.</p>
11248c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li     *
11258c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li     * <p>After calling {@link #takePicture(Camera.ShutterCallback, Camera.PictureCallback,
11268c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li     * Camera.PictureCallback)} or {@link #stopPreview()}, and then resuming
11278c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li     * preview with {@link #startPreview()}, the apps should call this method
11288c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li     * again to resume face detection.</p>
11294c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li     *
1130c0c683b3344c67700882f8059e7d18266366daa9Wu-cheng Li     * @throws IllegalArgumentException if the face detection is unsupported.
11314c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li     * @throws RuntimeException if the method fails or the face detection is
11324c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li     *         already running.
11334c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li     * @see FaceDetectionListener
11344c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li     * @see #stopFaceDetection()
1135c0c683b3344c67700882f8059e7d18266366daa9Wu-cheng Li     * @see Parameters#getMaxNumDetectedFaces()
11364c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li     */
1137c0c683b3344c67700882f8059e7d18266366daa9Wu-cheng Li    public final void startFaceDetection() {
11384c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li        if (mFaceDetectionRunning) {
11394c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li            throw new RuntimeException("Face detection is already running");
11404c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li        }
1141c0c683b3344c67700882f8059e7d18266366daa9Wu-cheng Li        _startFaceDetection(CAMERA_FACE_DETECTION_HW);
11424c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li        mFaceDetectionRunning = true;
11434c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li    }
11444c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li
11454c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li    /**
1146c0c683b3344c67700882f8059e7d18266366daa9Wu-cheng Li     * Stops the face detection.
11474c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li     *
1148464cb21e2aaa448072449b82156f18bd64c0e613Joe Fernandez     * @see #startFaceDetection()
11494c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li     */
11504c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li    public final void stopFaceDetection() {
11514c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li        _stopFaceDetection();
11524c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li        mFaceDetectionRunning = false;
11534c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li    }
11544c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li
11554c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li    private native final void _startFaceDetection(int type);
11564c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li    private native final void _stopFaceDetection();
11574c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li
11584c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li    /**
1159464cb21e2aaa448072449b82156f18bd64c0e613Joe Fernandez     * Information about a face identified through camera face detection.
116053b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li     *
1161464cb21e2aaa448072449b82156f18bd64c0e613Joe Fernandez     * <p>When face detection is used with a camera, the {@link FaceDetectionListener} returns a
1162464cb21e2aaa448072449b82156f18bd64c0e613Joe Fernandez     * list of face objects for use in focusing and metering.</p>
11634c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li     *
1164464cb21e2aaa448072449b82156f18bd64c0e613Joe Fernandez     * @see FaceDetectionListener
11654c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li     */
1166f0d6a48c6ad852b84687127f14b1ffde02416dc4Wu-cheng Li    public static class Face {
1167c0c683b3344c67700882f8059e7d18266366daa9Wu-cheng Li        /**
1168c0c683b3344c67700882f8059e7d18266366daa9Wu-cheng Li         * Create an empty face.
1169c0c683b3344c67700882f8059e7d18266366daa9Wu-cheng Li         */
1170bb1e275c0e684dd213f124da77110cdd9d6f090cWu-cheng Li        public Face() {
1171bb1e275c0e684dd213f124da77110cdd9d6f090cWu-cheng Li        }
1172bb1e275c0e684dd213f124da77110cdd9d6f090cWu-cheng Li
11734c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li        /**
11744c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li         * Bounds of the face. (-1000, -1000) represents the top-left of the
11754c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li         * camera field of view, and (1000, 1000) represents the bottom-right of
1176c0c683b3344c67700882f8059e7d18266366daa9Wu-cheng Li         * the field of view. For example, suppose the size of the viewfinder UI
1177c0c683b3344c67700882f8059e7d18266366daa9Wu-cheng Li         * is 800x480. The rect passed from the driver is (-1000, -1000, 0, 0).
11788c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li         * The corresponding viewfinder rect should be (0, 0, 400, 240). It is
11798c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li         * guaranteed left < right and top < bottom. The coordinates can be
11808c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li         * smaller than -1000 or bigger than 1000. But at least one vertex will
11818c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li         * be within (-1000, -1000) and (1000, 1000).
1182f0d6a48c6ad852b84687127f14b1ffde02416dc4Wu-cheng Li         *
1183f0d6a48c6ad852b84687127f14b1ffde02416dc4Wu-cheng Li         * <p>The direction is relative to the sensor orientation, that is, what
1184f0d6a48c6ad852b84687127f14b1ffde02416dc4Wu-cheng Li         * the sensor sees. The direction is not affected by the rotation or
11858c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li         * mirroring of {@link #setDisplayOrientation(int)}. The face bounding
11868c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li         * rectangle does not provide any information about face orientation.</p>
11878c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li         *
11888c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li         * <p>Here is the matrix to convert driver coordinates to View coordinates
11898c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li         * in pixels.</p>
11908c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li         * <pre>
11918c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li         * Matrix matrix = new Matrix();
11928c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li         * CameraInfo info = CameraHolder.instance().getCameraInfo()[cameraId];
11938c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li         * // Need mirror for front camera.
11948c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li         * boolean mirror = (info.facing == CameraInfo.CAMERA_FACING_FRONT);
11958c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li         * matrix.setScale(mirror ? -1 : 1, 1);
11968c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li         * // This is the value for android.hardware.Camera.setDisplayOrientation.
11978c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li         * matrix.postRotate(displayOrientation);
11988c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li         * // Camera driver coordinates range from (-1000, -1000) to (1000, 1000).
11998c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li         * // UI coordinates range from (0, 0) to (width, height).
12008c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li         * matrix.postScale(view.getWidth() / 2000f, view.getHeight() / 2000f);
12018c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li         * matrix.postTranslate(view.getWidth() / 2f, view.getHeight() / 2f);
12028c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li         * </pre>
12034c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li         *
1204464cb21e2aaa448072449b82156f18bd64c0e613Joe Fernandez         * @see #startFaceDetection()
12054c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li         */
1206bb1e275c0e684dd213f124da77110cdd9d6f090cWu-cheng Li        public Rect rect;
12074c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li
12084c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li        /**
1209464cb21e2aaa448072449b82156f18bd64c0e613Joe Fernandez         * The confidence level for the detection of the face. The range is 1 to 100. 100 is the
1210c0c683b3344c67700882f8059e7d18266366daa9Wu-cheng Li         * highest confidence.
12114c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li         *
1212464cb21e2aaa448072449b82156f18bd64c0e613Joe Fernandez         * @see #startFaceDetection()
12134c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li         */
1214bb1e275c0e684dd213f124da77110cdd9d6f090cWu-cheng Li        public int score;
1215d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua
1216d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua        /**
1217d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua         * An unique id per face while the face is visible to the tracker. If
1218d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua         * the face leaves the field-of-view and comes back, it will get a new
1219d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua         * id. This is an optional field, may not be supported on all devices.
1220d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua         * If not supported, id will always be set to -1. The optional fields
1221d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua         * are supported as a set. Either they are all valid, or none of them
1222d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua         * are.
1223d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua         */
1224d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua        public int id = -1;
1225d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua
1226d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua        /**
1227d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua         * The coordinates of the center of the left eye. The coordinates are in
1228d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua         * the same space as the ones for {@link #rect}. This is an optional
1229d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua         * field, may not be supported on all devices. If not supported, the
1230d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua         * value will always be set to null. The optional fields are supported
1231d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua         * as a set. Either they are all valid, or none of them are.
1232d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua         */
1233d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua        public Point leftEye = null;
1234d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua
1235d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua        /**
1236d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua         * The coordinates of the center of the right eye. The coordinates are
1237d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua         * in the same space as the ones for {@link #rect}.This is an optional
1238d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua         * field, may not be supported on all devices. If not supported, the
1239d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua         * value will always be set to null. The optional fields are supported
1240d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua         * as a set. Either they are all valid, or none of them are.
1241d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua         */
1242d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua        public Point rightEye = null;
1243d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua
1244d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua        /**
1245d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua         * The coordinates of the center of the mouth.  The coordinates are in
1246d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua         * the same space as the ones for {@link #rect}. This is an optional
1247d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua         * field, may not be supported on all devices. If not supported, the
1248d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua         * value will always be set to null. The optional fields are supported
1249d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua         * as a set. Either they are all valid, or none of them are.
1250d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua         */
1251d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua        public Point mouth = null;
12524c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li    }
12534c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li
1254bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor    // Error codes match the enum in include/ui/Camera.h
1255bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor
1256bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor    /**
1257bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * Unspecified camera error.
1258bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * @see Camera.ErrorCallback
1259bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     */
12609066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public static final int CAMERA_ERROR_UNKNOWN = 1;
1261bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor
1262bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor    /**
1263bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * Media server died. In this case, the application must release the
1264bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * Camera object and instantiate a new one.
1265bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * @see Camera.ErrorCallback
1266bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     */
12679066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public static final int CAMERA_ERROR_SERVER_DIED = 100;
12689b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
12699066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
1270bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * Callback interface for camera error notification.
1271bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     *
1272bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * @see #setErrorCallback(ErrorCallback)
12739066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
12749066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public interface ErrorCallback
12759066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    {
12769066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        /**
12779066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * Callback for camera errors.
12789066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * @param error   error code:
12799066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * <ul>
12809066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * <li>{@link #CAMERA_ERROR_UNKNOWN}
12819066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * <li>{@link #CAMERA_ERROR_SERVER_DIED}
12829066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * </ul>
12839066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * @param camera  the Camera service object
12849066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         */
12859066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        void onError(int error, Camera camera);
12869066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    };
12879066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
12889066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
12899066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * Registers a callback to be invoked when an error occurs.
1290bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * @param cb The callback to run
12919066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
12929066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public final void setErrorCallback(ErrorCallback cb)
12939066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    {
12949066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        mErrorCallback = cb;
12959066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
12969b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
12979066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    private native final void native_setParameters(String params);
12989066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    private native final String native_getParameters();
12999066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
13009066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
1301bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * Changes the settings for this Camera service.
13029b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li     *
13039066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @param params the Parameters to use for this Camera service
130499a3f3e4e06b4370101ca97cc11dbe81d772fefaWu-cheng Li     * @throws RuntimeException if any parameter is invalid or not supported.
1305bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * @see #getParameters()
13069066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
13079066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public void setParameters(Parameters params) {
13089066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        native_setParameters(params.flatten());
13099066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
13109066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
13119066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
1312bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * Returns the current settings for this Camera service.
1313bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * If modifications are made to the returned Parameters, they must be passed
1314bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * to {@link #setParameters(Camera.Parameters)} to take effect.
1315bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     *
1316bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * @see #setParameters(Camera.Parameters)
13179066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
13189066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public Parameters getParameters() {
13199066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        Parameters p = new Parameters();
13209066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        String s = native_getParameters();
13219066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        p.unflatten(s);
13229066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        return p;
13239066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
13249066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
13259066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
1326bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * Image size (width and height dimensions).
13279066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
13289066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public class Size {
13299066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        /**
13309066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * Sets the dimensions for pictures.
13319b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
13329066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * @param w the photo width (pixels)
13339066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * @param h the photo height (pixels)
13349066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         */
13359066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        public Size(int w, int h) {
13369066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            width = w;
13379066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            height = h;
13389066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
13394c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li        /**
13404c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li         * Compares {@code obj} to this size.
13414c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li         *
13424c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li         * @param obj the object to compare this size with.
13434c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li         * @return {@code true} if the width and height of {@code obj} is the
13444c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li         *         same as those of this size. {@code false} otherwise.
13454c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li         */
13464c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li        @Override
13474c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li        public boolean equals(Object obj) {
13484c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li            if (!(obj instanceof Size)) {
13494c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li                return false;
13504c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li            }
13514c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li            Size s = (Size) obj;
13524c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li            return width == s.width && height == s.height;
13534c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li        }
13544c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li        @Override
13554c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li        public int hashCode() {
13564c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li            return width * 32713 + height;
13574c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li        }
13589066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        /** width of the picture */
13599066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        public int width;
13609066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        /** height of the picture */
13619066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        public int height;
13629066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    };
13639066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
13649066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
136532a972c693400db50717435139fa292a63bc937aEino-Ville Talvala     * <p>The Area class is used for choosing specific metering and focus areas for
136632a972c693400db50717435139fa292a63bc937aEino-Ville Talvala     * the camera to use when calculating auto-exposure, auto-white balance, and
136732a972c693400db50717435139fa292a63bc937aEino-Ville Talvala     * auto-focus.</p>
136832a972c693400db50717435139fa292a63bc937aEino-Ville Talvala     *
136932a972c693400db50717435139fa292a63bc937aEino-Ville Talvala     * <p>To find out how many simultaneous areas a given camera supports, use
137032a972c693400db50717435139fa292a63bc937aEino-Ville Talvala     * {@link Parameters#getMaxNumMeteringAreas()} and
137132a972c693400db50717435139fa292a63bc937aEino-Ville Talvala     * {@link Parameters#getMaxNumFocusAreas()}. If metering or focusing area
137232a972c693400db50717435139fa292a63bc937aEino-Ville Talvala     * selection is unsupported, these methods will return 0.</p>
137332a972c693400db50717435139fa292a63bc937aEino-Ville Talvala     *
137432a972c693400db50717435139fa292a63bc937aEino-Ville Talvala     * <p>Each Area consists of a rectangle specifying its bounds, and a weight
137532a972c693400db50717435139fa292a63bc937aEino-Ville Talvala     * that determines its importance. The bounds are relative to the camera's
137632a972c693400db50717435139fa292a63bc937aEino-Ville Talvala     * current field of view. The coordinates are mapped so that (-1000, -1000)
137732a972c693400db50717435139fa292a63bc937aEino-Ville Talvala     * is always the top-left corner of the current field of view, and (1000,
137832a972c693400db50717435139fa292a63bc937aEino-Ville Talvala     * 1000) is always the bottom-right corner of the current field of
137932a972c693400db50717435139fa292a63bc937aEino-Ville Talvala     * view. Setting Areas with bounds outside that range is not allowed. Areas
138032a972c693400db50717435139fa292a63bc937aEino-Ville Talvala     * with zero or negative width or height are not allowed.</p>
138132a972c693400db50717435139fa292a63bc937aEino-Ville Talvala     *
138232a972c693400db50717435139fa292a63bc937aEino-Ville Talvala     * <p>The weight must range from 1 to 1000, and represents a weight for
138332a972c693400db50717435139fa292a63bc937aEino-Ville Talvala     * every pixel in the area. This means that a large metering area with
138432a972c693400db50717435139fa292a63bc937aEino-Ville Talvala     * the same weight as a smaller area will have more effect in the
138532a972c693400db50717435139fa292a63bc937aEino-Ville Talvala     * metering result.  Metering areas can overlap and the driver
138632a972c693400db50717435139fa292a63bc937aEino-Ville Talvala     * will add the weights in the overlap region.</p>
1387bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Li     *
1388bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Li     * @see Parameters#setFocusAreas(List)
1389bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Li     * @see Parameters#getFocusAreas()
1390bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Li     * @see Parameters#getMaxNumFocusAreas()
1391bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Li     * @see Parameters#setMeteringAreas(List)
1392bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Li     * @see Parameters#getMeteringAreas()
1393bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Li     * @see Parameters#getMaxNumMeteringAreas()
139430771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li     */
139530771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li    public static class Area {
139630771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li        /**
139730771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li         * Create an area with specified rectangle and weight.
139830771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li         *
139932a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * @param rect the bounds of the area.
140032a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * @param weight the weight of the area.
140130771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li         */
140230771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li        public Area(Rect rect, int weight) {
140330771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li            this.rect = rect;
140430771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li            this.weight = weight;
140530771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li        }
140630771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li        /**
140730771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li         * Compares {@code obj} to this area.
140830771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li         *
140930771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li         * @param obj the object to compare this area with.
141030771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li         * @return {@code true} if the rectangle and weight of {@code obj} is
141130771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li         *         the same as those of this area. {@code false} otherwise.
141230771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li         */
141330771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li        @Override
141430771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li        public boolean equals(Object obj) {
141530771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li            if (!(obj instanceof Area)) {
141630771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li                return false;
141730771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li            }
141830771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li            Area a = (Area) obj;
141930771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li            if (rect == null) {
142030771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li                if (a.rect != null) return false;
142130771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li            } else {
142230771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li                if (!rect.equals(a.rect)) return false;
142330771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li            }
142430771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li            return weight == a.weight;
142530771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li        }
142630771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li
1427bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Li        /**
142832a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * Bounds of the area. (-1000, -1000) represents the top-left of the
142932a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * camera field of view, and (1000, 1000) represents the bottom-right of
143032a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * the field of view. Setting bounds outside that range is not
143132a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * allowed. Bounds with zero or negative width or height are not
143232a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * allowed.
1433bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Li         *
1434bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Li         * @see Parameters#getFocusAreas()
1435bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Li         * @see Parameters#getMeteringAreas()
1436bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Li         */
143730771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li        public Rect rect;
143830771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li
1439bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Li        /**
144032a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * Weight of the area. The weight must range from 1 to 1000, and
144132a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * represents a weight for every pixel in the area. This means that a
144232a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * large metering area with the same weight as a smaller area will have
144332a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * more effect in the metering result.  Metering areas can overlap and
144432a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * the driver will add the weights in the overlap region.
1445bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Li         *
1446bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Li         * @see Parameters#getFocusAreas()
1447bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Li         * @see Parameters#getMeteringAreas()
1448bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Li         */
144930771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li        public int weight;
1450bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Li    }
145130771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li
145230771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li    /**
1453bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * Camera service settings.
14549b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li     *
14559b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li     * <p>To make camera parameters take effect, applications have to call
1456bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * {@link Camera#setParameters(Camera.Parameters)}. For example, after
1457bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * {@link Camera.Parameters#setWhiteBalance} is called, white balance is not
1458bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * actually changed until {@link Camera#setParameters(Camera.Parameters)}
1459bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * is called with the changed parameters object.
14609b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li     *
14619b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li     * <p>Different devices may have different camera capabilities, such as
14629b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li     * picture size or flash modes. The application should query the camera
14639b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li     * capabilities before setting parameters. For example, the application
1464bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * should call {@link Camera.Parameters#getSupportedColorEffects()} before
1465bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * calling {@link Camera.Parameters#setColorEffect(String)}. If the
1466bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * camera does not support color effects,
1467bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * {@link Camera.Parameters#getSupportedColorEffects()} will return null.
14689066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
14699066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public class Parameters {
14709b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        // Parameter keys to communicate with the camera driver.
14719b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        private static final String KEY_PREVIEW_SIZE = "preview-size";
14729b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        private static final String KEY_PREVIEW_FORMAT = "preview-format";
14739b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        private static final String KEY_PREVIEW_FRAME_RATE = "preview-frame-rate";
1474454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li        private static final String KEY_PREVIEW_FPS_RANGE = "preview-fps-range";
14759b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        private static final String KEY_PICTURE_SIZE = "picture-size";
14769b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        private static final String KEY_PICTURE_FORMAT = "picture-format";
14774c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li        private static final String KEY_JPEG_THUMBNAIL_SIZE = "jpeg-thumbnail-size";
14789b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        private static final String KEY_JPEG_THUMBNAIL_WIDTH = "jpeg-thumbnail-width";
14799b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        private static final String KEY_JPEG_THUMBNAIL_HEIGHT = "jpeg-thumbnail-height";
14809b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        private static final String KEY_JPEG_THUMBNAIL_QUALITY = "jpeg-thumbnail-quality";
14819b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        private static final String KEY_JPEG_QUALITY = "jpeg-quality";
14829b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        private static final String KEY_ROTATION = "rotation";
14839b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        private static final String KEY_GPS_LATITUDE = "gps-latitude";
14849b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        private static final String KEY_GPS_LONGITUDE = "gps-longitude";
14859b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        private static final String KEY_GPS_ALTITUDE = "gps-altitude";
14869b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        private static final String KEY_GPS_TIMESTAMP = "gps-timestamp";
1487055c986ab841f8f758398841730f1e90313b132aRay Chen        private static final String KEY_GPS_PROCESSING_METHOD = "gps-processing-method";
14889b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        private static final String KEY_WHITE_BALANCE = "whitebalance";
14899b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        private static final String KEY_EFFECT = "effect";
14909b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        private static final String KEY_ANTIBANDING = "antibanding";
14919b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        private static final String KEY_SCENE_MODE = "scene-mode";
14929b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        private static final String KEY_FLASH_MODE = "flash-mode";
149336322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li        private static final String KEY_FOCUS_MODE = "focus-mode";
149430771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li        private static final String KEY_FOCUS_AREAS = "focus-areas";
149530771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li        private static final String KEY_MAX_NUM_FOCUS_AREAS = "max-num-focus-areas";
14966c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li        private static final String KEY_FOCAL_LENGTH = "focal-length";
14976c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li        private static final String KEY_HORIZONTAL_VIEW_ANGLE = "horizontal-view-angle";
14986c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li        private static final String KEY_VERTICAL_VIEW_ANGLE = "vertical-view-angle";
1499ff723b6c43d5a8fd0ae0e0732f5d47012d74e01dWu-cheng Li        private static final String KEY_EXPOSURE_COMPENSATION = "exposure-compensation";
150024b326a8978bf78e3e560723dde221792784325bWu-cheng Li        private static final String KEY_MAX_EXPOSURE_COMPENSATION = "max-exposure-compensation";
150124b326a8978bf78e3e560723dde221792784325bWu-cheng Li        private static final String KEY_MIN_EXPOSURE_COMPENSATION = "min-exposure-compensation";
150224b326a8978bf78e3e560723dde221792784325bWu-cheng Li        private static final String KEY_EXPOSURE_COMPENSATION_STEP = "exposure-compensation-step";
15033773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala        private static final String KEY_AUTO_EXPOSURE_LOCK = "auto-exposure-lock";
15043773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala        private static final String KEY_AUTO_EXPOSURE_LOCK_SUPPORTED = "auto-exposure-lock-supported";
1505d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala        private static final String KEY_AUTO_WHITEBALANCE_LOCK = "auto-whitebalance-lock";
1506d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala        private static final String KEY_AUTO_WHITEBALANCE_LOCK_SUPPORTED = "auto-whitebalance-lock-supported";
1507e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li        private static final String KEY_METERING_AREAS = "metering-areas";
1508e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li        private static final String KEY_MAX_NUM_METERING_AREAS = "max-num-metering-areas";
15098cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li        private static final String KEY_ZOOM = "zoom";
15108cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li        private static final String KEY_MAX_ZOOM = "max-zoom";
15118cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li        private static final String KEY_ZOOM_RATIOS = "zoom-ratios";
15128cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li        private static final String KEY_ZOOM_SUPPORTED = "zoom-supported";
15138cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li        private static final String KEY_SMOOTH_ZOOM_SUPPORTED = "smooth-zoom-supported";
1514e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li        private static final String KEY_FOCUS_DISTANCES = "focus-distances";
1515dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong        private static final String KEY_VIDEO_SIZE = "video-size";
1516dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong        private static final String KEY_PREFERRED_PREVIEW_SIZE_FOR_VIDEO =
1517dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong                                            "preferred-preview-size-for-video";
15184c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li        private static final String KEY_MAX_NUM_DETECTED_FACES_HW = "max-num-detected-faces-hw";
15194c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li        private static final String KEY_MAX_NUM_DETECTED_FACES_SW = "max-num-detected-faces-sw";
152025d8fb51dae37f1becf4fb3d32e8600c418eb6e8Wu-cheng Li        private static final String KEY_RECORDING_HINT = "recording-hint";
152198bb251c8b527600e7a4cca6cc33499710bbfbf1Wu-cheng Li        private static final String KEY_VIDEO_SNAPSHOT_SUPPORTED = "video-snapshot-supported";
1522037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala        private static final String KEY_VIDEO_STABILIZATION = "video-stabilization";
1523037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala        private static final String KEY_VIDEO_STABILIZATION_SUPPORTED = "video-stabilization-supported";
1524e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li
15259b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        // Parameter key suffix for supported values.
15269b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        private static final String SUPPORTED_VALUES_SUFFIX = "-values";
15279b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
15288cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li        private static final String TRUE = "true";
15293773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala        private static final String FALSE = "false";
15308cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li
15319b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        // Values for white balance settings.
15329b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String WHITE_BALANCE_AUTO = "auto";
15339b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String WHITE_BALANCE_INCANDESCENT = "incandescent";
15349b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String WHITE_BALANCE_FLUORESCENT = "fluorescent";
15359b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String WHITE_BALANCE_WARM_FLUORESCENT = "warm-fluorescent";
15369b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String WHITE_BALANCE_DAYLIGHT = "daylight";
15379b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String WHITE_BALANCE_CLOUDY_DAYLIGHT = "cloudy-daylight";
15389b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String WHITE_BALANCE_TWILIGHT = "twilight";
15399b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String WHITE_BALANCE_SHADE = "shade";
15409b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
15419b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        // Values for color effect settings.
15429b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String EFFECT_NONE = "none";
15439b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String EFFECT_MONO = "mono";
15449b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String EFFECT_NEGATIVE = "negative";
15459b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String EFFECT_SOLARIZE = "solarize";
15469b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String EFFECT_SEPIA = "sepia";
15479b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String EFFECT_POSTERIZE = "posterize";
15489b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String EFFECT_WHITEBOARD = "whiteboard";
15499b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String EFFECT_BLACKBOARD = "blackboard";
15509b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String EFFECT_AQUA = "aqua";
15519b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
15529b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        // Values for antibanding settings.
15539b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String ANTIBANDING_AUTO = "auto";
15549b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String ANTIBANDING_50HZ = "50hz";
15559b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String ANTIBANDING_60HZ = "60hz";
15569b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String ANTIBANDING_OFF = "off";
15579b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
15589b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        // Values for flash mode settings.
15599b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        /**
15609b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * Flash will not be fired.
15619b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         */
15629b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String FLASH_MODE_OFF = "off";
156336f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li
15649b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        /**
1565068ef42c3ffe1eccec10f97f08541304f679fe67Wu-cheng Li         * Flash will be fired automatically when required. The flash may be fired
1566068ef42c3ffe1eccec10f97f08541304f679fe67Wu-cheng Li         * during preview, auto-focus, or snapshot depending on the driver.
15679b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         */
15689b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String FLASH_MODE_AUTO = "auto";
156936f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li
15709b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        /**
1571068ef42c3ffe1eccec10f97f08541304f679fe67Wu-cheng Li         * Flash will always be fired during snapshot. The flash may also be
1572068ef42c3ffe1eccec10f97f08541304f679fe67Wu-cheng Li         * fired during preview or auto-focus depending on the driver.
15739b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         */
15749b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String FLASH_MODE_ON = "on";
157536f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li
15769b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        /**
15779b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * Flash will be fired in red-eye reduction mode.
15789b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         */
15799b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String FLASH_MODE_RED_EYE = "red-eye";
158036f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li
158136322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li        /**
1582068ef42c3ffe1eccec10f97f08541304f679fe67Wu-cheng Li         * Constant emission of light during preview, auto-focus and snapshot.
1583068ef42c3ffe1eccec10f97f08541304f679fe67Wu-cheng Li         * This can also be used for video recording.
158436322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li         */
1585068ef42c3ffe1eccec10f97f08541304f679fe67Wu-cheng Li        public static final String FLASH_MODE_TORCH = "torch";
15869b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
158700e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li        /**
158800e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li         * Scene mode is off.
158900e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li         */
15909b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String SCENE_MODE_AUTO = "auto";
159100e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li
159200e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li        /**
159300e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li         * Take photos of fast moving objects. Same as {@link
159400e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li         * #SCENE_MODE_SPORTS}.
159500e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li         */
15969b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String SCENE_MODE_ACTION = "action";
159700e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li
159800e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li        /**
159900e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li         * Take people pictures.
160000e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li         */
16019b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String SCENE_MODE_PORTRAIT = "portrait";
160200e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li
160300e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li        /**
160400e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li         * Take pictures on distant objects.
160500e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li         */
16069b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String SCENE_MODE_LANDSCAPE = "landscape";
160700e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li
160800e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li        /**
160900e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li         * Take photos at night.
161000e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li         */
16119b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String SCENE_MODE_NIGHT = "night";
161200e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li
161300e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li        /**
161400e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li         * Take people pictures at night.
161500e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li         */
16169b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String SCENE_MODE_NIGHT_PORTRAIT = "night-portrait";
161700e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li
161800e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li        /**
161900e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li         * Take photos in a theater. Flash light is off.
162000e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li         */
16219b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String SCENE_MODE_THEATRE = "theatre";
162200e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li
162300e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li        /**
162400e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li         * Take pictures on the beach.
162500e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li         */
16269b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String SCENE_MODE_BEACH = "beach";
162700e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li
162800e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li        /**
162900e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li         * Take pictures on the snow.
163000e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li         */
16319b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String SCENE_MODE_SNOW = "snow";
163200e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li
163300e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li        /**
163400e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li         * Take sunset photos.
163500e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li         */
16369b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String SCENE_MODE_SUNSET = "sunset";
163700e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li
163800e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li        /**
163900e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li         * Avoid blurry pictures (for example, due to hand shake).
164000e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li         */
16419b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String SCENE_MODE_STEADYPHOTO = "steadyphoto";
164200e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li
164300e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li        /**
164400e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li         * For shooting firework displays.
164500e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li         */
16469b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String SCENE_MODE_FIREWORKS = "fireworks";
164700e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li
164800e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li        /**
164900e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li         * Take photos of fast moving objects. Same as {@link
165000e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li         * #SCENE_MODE_ACTION}.
165100e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li         */
16529b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String SCENE_MODE_SPORTS = "sports";
165300e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li
165400e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li        /**
165500e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li         * Take indoor low-light shot.
165600e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li         */
16579b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String SCENE_MODE_PARTY = "party";
165800e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li
165900e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li        /**
166000e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li         * Capture the naturally warm color of scenes lit by candles.
166100e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li         */
16629b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String SCENE_MODE_CANDLELIGHT = "candlelight";
16639b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
1664c58b42327df5fbc826e2fcc2674ab6db0edfcd92Wu-cheng Li        /**
1665c58b42327df5fbc826e2fcc2674ab6db0edfcd92Wu-cheng Li         * Applications are looking for a barcode. Camera driver will be
1666c58b42327df5fbc826e2fcc2674ab6db0edfcd92Wu-cheng Li         * optimized for barcode reading.
1667c58b42327df5fbc826e2fcc2674ab6db0edfcd92Wu-cheng Li         */
1668c58b42327df5fbc826e2fcc2674ab6db0edfcd92Wu-cheng Li        public static final String SCENE_MODE_BARCODE = "barcode";
1669c58b42327df5fbc826e2fcc2674ab6db0edfcd92Wu-cheng Li
167036322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li        /**
1671f008f3ea82a0518375ee4ea41b32451badffbd95Wu-cheng Li         * Auto-focus mode. Applications should call {@link
1672f008f3ea82a0518375ee4ea41b32451badffbd95Wu-cheng Li         * #autoFocus(AutoFocusCallback)} to start the focus in this mode.
167336322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li         */
167436322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li        public static final String FOCUS_MODE_AUTO = "auto";
167536f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li
167636322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li        /**
167736322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li         * Focus is set at infinity. Applications should not call
167836322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li         * {@link #autoFocus(AutoFocusCallback)} in this mode.
167936322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li         */
168036322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li        public static final String FOCUS_MODE_INFINITY = "infinity";
1681f008f3ea82a0518375ee4ea41b32451badffbd95Wu-cheng Li
1682f008f3ea82a0518375ee4ea41b32451badffbd95Wu-cheng Li        /**
1683f008f3ea82a0518375ee4ea41b32451badffbd95Wu-cheng Li         * Macro (close-up) focus mode. Applications should call
1684f008f3ea82a0518375ee4ea41b32451badffbd95Wu-cheng Li         * {@link #autoFocus(AutoFocusCallback)} to start the focus in this
1685f008f3ea82a0518375ee4ea41b32451badffbd95Wu-cheng Li         * mode.
1686f008f3ea82a0518375ee4ea41b32451badffbd95Wu-cheng Li         */
168736322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li        public static final String FOCUS_MODE_MACRO = "macro";
168836f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li
168936322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li        /**
169036322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li         * Focus is fixed. The camera is always in this mode if the focus is not
169136322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li         * adjustable. If the camera has auto-focus, this mode can fix the
169236322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li         * focus, which is usually at hyperfocal distance. Applications should
169336322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li         * not call {@link #autoFocus(AutoFocusCallback)} in this mode.
169436322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li         */
169536322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li        public static final String FOCUS_MODE_FIXED = "fixed";
169636322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li
1697c58b42327df5fbc826e2fcc2674ab6db0edfcd92Wu-cheng Li        /**
1698c58b42327df5fbc826e2fcc2674ab6db0edfcd92Wu-cheng Li         * Extended depth of field (EDOF). Focusing is done digitally and
1699c58b42327df5fbc826e2fcc2674ab6db0edfcd92Wu-cheng Li         * continuously. Applications should not call {@link
1700c58b42327df5fbc826e2fcc2674ab6db0edfcd92Wu-cheng Li         * #autoFocus(AutoFocusCallback)} in this mode.
1701c58b42327df5fbc826e2fcc2674ab6db0edfcd92Wu-cheng Li         */
1702c58b42327df5fbc826e2fcc2674ab6db0edfcd92Wu-cheng Li        public static final String FOCUS_MODE_EDOF = "edof";
1703c58b42327df5fbc826e2fcc2674ab6db0edfcd92Wu-cheng Li
1704699fe9397974685e6b2c73f9a3a0eb9e5a5a2ccfWu-cheng Li        /**
1705d45cb72ac0d7d57829ffc9223decb89a5fc42ce2Wu-cheng Li         * Continuous auto focus mode intended for video recording. The camera
1706b9ac75d3dfc53ab4a0a104da147f1dfd7bc8c12fWu-cheng Li         * continuously tries to focus. This is the best choice for video
1707b9ac75d3dfc53ab4a0a104da147f1dfd7bc8c12fWu-cheng Li         * recording because the focus changes smoothly . Applications still can
1708b9ac75d3dfc53ab4a0a104da147f1dfd7bc8c12fWu-cheng Li         * call {@link #takePicture(Camera.ShutterCallback,
1709b9ac75d3dfc53ab4a0a104da147f1dfd7bc8c12fWu-cheng Li         * Camera.PictureCallback, Camera.PictureCallback)} in this mode but the
1710b9ac75d3dfc53ab4a0a104da147f1dfd7bc8c12fWu-cheng Li         * subject may not be in focus. Auto focus starts when the parameter is
171153b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li         * set.
171253b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li         *
171353b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li         * <p>Since API level 14, applications can call {@link
171453b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li         * #autoFocus(AutoFocusCallback)} in this mode. The focus callback will
171553b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li         * immediately return with a boolean that indicates whether the focus is
171653b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li         * sharp or not. The focus position is locked after autoFocus call. If
171753b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li         * applications want to resume the continuous focus, cancelAutoFocus
171853b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li         * must be called. Restarting the preview will not resume the continuous
171953b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li         * autofocus. To stop continuous focus, applications should change the
172053b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li         * focus mode to other modes.
172153b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li         *
172253b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li         * @see #FOCUS_MODE_CONTINUOUS_PICTURE
1723d45cb72ac0d7d57829ffc9223decb89a5fc42ce2Wu-cheng Li         */
1724d45cb72ac0d7d57829ffc9223decb89a5fc42ce2Wu-cheng Li        public static final String FOCUS_MODE_CONTINUOUS_VIDEO = "continuous-video";
1725699fe9397974685e6b2c73f9a3a0eb9e5a5a2ccfWu-cheng Li
1726b9ac75d3dfc53ab4a0a104da147f1dfd7bc8c12fWu-cheng Li        /**
1727b9ac75d3dfc53ab4a0a104da147f1dfd7bc8c12fWu-cheng Li         * Continuous auto focus mode intended for taking pictures. The camera
1728b9ac75d3dfc53ab4a0a104da147f1dfd7bc8c12fWu-cheng Li         * continuously tries to focus. The speed of focus change is more
1729b9ac75d3dfc53ab4a0a104da147f1dfd7bc8c12fWu-cheng Li         * aggressive than {@link #FOCUS_MODE_CONTINUOUS_VIDEO}. Auto focus
173053b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li         * starts when the parameter is set.
173153b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li         *
17320f4f97b70f6ad59b32e78720ba7357733bdef3e9Wu-cheng Li         * <p>Applications can call {@link #autoFocus(AutoFocusCallback)} in
17330f4f97b70f6ad59b32e78720ba7357733bdef3e9Wu-cheng Li         * this mode. If the autofocus is in the middle of scanning, the focus
17340f4f97b70f6ad59b32e78720ba7357733bdef3e9Wu-cheng Li         * callback will return when it completes. If the autofocus is not
17350f4f97b70f6ad59b32e78720ba7357733bdef3e9Wu-cheng Li         * scanning, the focus callback will immediately return with a boolean
17360f4f97b70f6ad59b32e78720ba7357733bdef3e9Wu-cheng Li         * that indicates whether the focus is sharp or not. The apps can then
17370f4f97b70f6ad59b32e78720ba7357733bdef3e9Wu-cheng Li         * decide if they want to take a picture immediately or to change the
17380f4f97b70f6ad59b32e78720ba7357733bdef3e9Wu-cheng Li         * focus mode to auto, and run a full autofocus cycle. The focus
17390f4f97b70f6ad59b32e78720ba7357733bdef3e9Wu-cheng Li         * position is locked after autoFocus call. If applications want to
17400f4f97b70f6ad59b32e78720ba7357733bdef3e9Wu-cheng Li         * resume the continuous focus, cancelAutoFocus must be called.
17410f4f97b70f6ad59b32e78720ba7357733bdef3e9Wu-cheng Li         * Restarting the preview will not resume the continuous autofocus. To
17420f4f97b70f6ad59b32e78720ba7357733bdef3e9Wu-cheng Li         * stop continuous focus, applications should change the focus mode to
17430f4f97b70f6ad59b32e78720ba7357733bdef3e9Wu-cheng Li         * other modes.
1744b9ac75d3dfc53ab4a0a104da147f1dfd7bc8c12fWu-cheng Li         *
1745b9ac75d3dfc53ab4a0a104da147f1dfd7bc8c12fWu-cheng Li         * @see #FOCUS_MODE_CONTINUOUS_VIDEO
1746b9ac75d3dfc53ab4a0a104da147f1dfd7bc8c12fWu-cheng Li         */
1747b9ac75d3dfc53ab4a0a104da147f1dfd7bc8c12fWu-cheng Li        public static final String FOCUS_MODE_CONTINUOUS_PICTURE = "continuous-picture";
1748b9ac75d3dfc53ab4a0a104da147f1dfd7bc8c12fWu-cheng Li
1749e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li        // Indices for focus distance array.
1750e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li        /**
1751e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li         * The array index of near focus distance for use with
1752e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li         * {@link #getFocusDistances(float[])}.
1753e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li         */
1754e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li        public static final int FOCUS_DISTANCE_NEAR_INDEX = 0;
1755e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li
1756e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li        /**
1757e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li         * The array index of optimal focus distance for use with
1758e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li         * {@link #getFocusDistances(float[])}.
1759e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li         */
1760e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li        public static final int FOCUS_DISTANCE_OPTIMAL_INDEX = 1;
1761e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li
1762e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li        /**
1763e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li         * The array index of far focus distance for use with
1764e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li         * {@link #getFocusDistances(float[])}.
1765e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li         */
1766e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li        public static final int FOCUS_DISTANCE_FAR_INDEX = 2;
1767e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li
1768ca099614841bc619f217dfa088da630a7eb1ab65Wu-cheng Li        /**
1769454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         * The array index of minimum preview fps for use with {@link
1770454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         * #getPreviewFpsRange(int[])} or {@link
1771454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         * #getSupportedPreviewFpsRange()}.
1772454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         */
1773454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li        public static final int PREVIEW_FPS_MIN_INDEX = 0;
1774454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li
1775454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li        /**
1776454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         * The array index of maximum preview fps for use with {@link
1777454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         * #getPreviewFpsRange(int[])} or {@link
1778454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         * #getSupportedPreviewFpsRange()}.
1779454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         */
1780454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li        public static final int PREVIEW_FPS_MAX_INDEX = 1;
1781454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li
17829b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        // Formats for setPreviewFormat and setPictureFormat.
17839b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        private static final String PIXEL_FORMAT_YUV422SP = "yuv422sp";
17849b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        private static final String PIXEL_FORMAT_YUV420SP = "yuv420sp";
1785eb68c46a40c773eb56ef7bcf8e7ece5c6a5a8d23Chih-Chung Chang        private static final String PIXEL_FORMAT_YUV422I = "yuv422i-yuyv";
178610a1b30dfbd0bbeae6776e353600986647c6e0a8Wu-cheng Li        private static final String PIXEL_FORMAT_YUV420P = "yuv420p";
17879b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        private static final String PIXEL_FORMAT_RGB565 = "rgb565";
17889b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        private static final String PIXEL_FORMAT_JPEG = "jpeg";
178970fb9085044c5e6f52c33c970d238b764cf2373bWu-cheng Li        private static final String PIXEL_FORMAT_BAYER_RGGB = "bayer-rggb";
17909b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
17919066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        private HashMap<String, String> mMap;
17929066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
17939066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        private Parameters() {
17949066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            mMap = new HashMap<String, String>();
17959066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
17969066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
17979066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        /**
17989066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * Writes the current Parameters to the log.
17999066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * @hide
18009066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * @deprecated
18019066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         */
18029066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        public void dump() {
18039066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            Log.e(TAG, "dump: size=" + mMap.size());
18049066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            for (String k : mMap.keySet()) {
18059066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                Log.e(TAG, "dump: " + k + "=" + mMap.get(k));
18069066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            }
18079066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
18089066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
18099066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        /**
18109066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * Creates a single string with all the parameters set in
18119066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * this Parameters object.
18129066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * <p>The {@link #unflatten(String)} method does the reverse.</p>
18139b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
18149066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * @return a String with all values from this Parameters object, in
18159066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         *         semi-colon delimited key-value pairs
18169066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         */
18179066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        public String flatten() {
18189066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            StringBuilder flattened = new StringBuilder();
18199066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            for (String k : mMap.keySet()) {
18209066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                flattened.append(k);
18219066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                flattened.append("=");
18229066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                flattened.append(mMap.get(k));
18239066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                flattened.append(";");
18249066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            }
18259066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            // chop off the extra semicolon at the end
18269066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            flattened.deleteCharAt(flattened.length()-1);
18279066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            return flattened.toString();
18289066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
18299066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
18309066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        /**
18319b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * Takes a flattened string of parameters and adds each one to
18329066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * this Parameters object.
18339066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * <p>The {@link #flatten()} method does the reverse.</p>
18349b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
18359b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * @param flattened a String of parameters (key-value paired) that
18369066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         *                  are semi-colon delimited
18379066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         */
18389066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        public void unflatten(String flattened) {
18399066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            mMap.clear();
18409b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
18419066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            StringTokenizer tokenizer = new StringTokenizer(flattened, ";");
18429066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            while (tokenizer.hasMoreElements()) {
18439066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                String kv = tokenizer.nextToken();
18449066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                int pos = kv.indexOf('=');
18459066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                if (pos == -1) {
18469066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                    continue;
18479066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                }
18489066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                String k = kv.substring(0, pos);
18499066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                String v = kv.substring(pos + 1);
18509066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                mMap.put(k, v);
18519066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            }
18529066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
18539b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
18549066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        public void remove(String key) {
18559066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            mMap.remove(key);
18569066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
18579066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
18589066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        /**
18599066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * Sets a String parameter.
18609b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
18619066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * @param key   the key name for the parameter
18629066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * @param value the String value of the parameter
18639066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         */
18649066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        public void set(String key, String value) {
18659066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            if (key.indexOf('=') != -1 || key.indexOf(';') != -1) {
18669066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                Log.e(TAG, "Key \"" + key + "\" contains invalid character (= or ;)");
18679066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                return;
18689066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            }
18699066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            if (value.indexOf('=') != -1 || value.indexOf(';') != -1) {
18709066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                Log.e(TAG, "Value \"" + value + "\" contains invalid character (= or ;)");
18719066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                return;
18729066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            }
18739066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
18749066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            mMap.put(key, value);
18759066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
18769066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
18779066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        /**
18789066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * Sets an integer parameter.
18799b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
18809066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * @param key   the key name for the parameter
18819066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * @param value the int value of the parameter
18829066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         */
18839066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        public void set(String key, int value) {
18849066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            mMap.put(key, Integer.toString(value));
18859066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
18869066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
1887e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li        private void set(String key, List<Area> areas) {
1888f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li            if (areas == null) {
1889f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li                set(key, "(0,0,0,0,0)");
1890f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li            } else {
1891f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li                StringBuilder buffer = new StringBuilder();
1892f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li                for (int i = 0; i < areas.size(); i++) {
1893f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li                    Area area = areas.get(i);
1894f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li                    Rect rect = area.rect;
1895f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li                    buffer.append('(');
1896f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li                    buffer.append(rect.left);
1897f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li                    buffer.append(',');
1898f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li                    buffer.append(rect.top);
1899f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li                    buffer.append(',');
1900f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li                    buffer.append(rect.right);
1901f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li                    buffer.append(',');
1902f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li                    buffer.append(rect.bottom);
1903f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li                    buffer.append(',');
1904f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li                    buffer.append(area.weight);
1905f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li                    buffer.append(')');
1906f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li                    if (i != areas.size() - 1) buffer.append(',');
1907f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li                }
1908f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li                set(key, buffer.toString());
1909e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li            }
1910e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li        }
1911e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li
19129066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        /**
19139066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * Returns the value of a String parameter.
19149b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
19159066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * @param key the key name for the parameter
19169066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * @return the String value of the parameter
19179066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         */
19189066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        public String get(String key) {
19199066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            return mMap.get(key);
19209066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
19219066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
19229066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        /**
19239066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * Returns the value of an integer parameter.
19249b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
19259066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * @param key the key name for the parameter
19269066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * @return the int value of the parameter
19279066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         */
19289066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        public int getInt(String key) {
19299066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            return Integer.parseInt(mMap.get(key));
19309066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
19319066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
19329066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        /**
193326274fae33b7b056cf5fe9fd6e823cae9e4ddae2Wu-cheng Li         * Sets the dimensions for preview pictures. If the preview has already
193426274fae33b7b056cf5fe9fd6e823cae9e4ddae2Wu-cheng Li         * started, applications should stop the preview first before changing
193526274fae33b7b056cf5fe9fd6e823cae9e4ddae2Wu-cheng Li         * preview size.
19369b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
1937c157e0cd161e5b3b28b72bafebb3360ed856a608Wu-cheng Li         * The sides of width and height are based on camera orientation. That
1938c157e0cd161e5b3b28b72bafebb3360ed856a608Wu-cheng Li         * is, the preview size is the size before it is rotated by display
1939c157e0cd161e5b3b28b72bafebb3360ed856a608Wu-cheng Li         * orientation. So applications need to consider the display orientation
1940c157e0cd161e5b3b28b72bafebb3360ed856a608Wu-cheng Li         * while setting preview size. For example, suppose the camera supports
1941c157e0cd161e5b3b28b72bafebb3360ed856a608Wu-cheng Li         * both 480x320 and 320x480 preview sizes. The application wants a 3:2
1942c157e0cd161e5b3b28b72bafebb3360ed856a608Wu-cheng Li         * preview ratio. If the display orientation is set to 0 or 180, preview
1943c157e0cd161e5b3b28b72bafebb3360ed856a608Wu-cheng Li         * size should be set to 480x320. If the display orientation is set to
1944c157e0cd161e5b3b28b72bafebb3360ed856a608Wu-cheng Li         * 90 or 270, preview size should be set to 320x480. The display
1945c157e0cd161e5b3b28b72bafebb3360ed856a608Wu-cheng Li         * orientation should also be considered while setting picture size and
1946c157e0cd161e5b3b28b72bafebb3360ed856a608Wu-cheng Li         * thumbnail size.
1947c157e0cd161e5b3b28b72bafebb3360ed856a608Wu-cheng Li         *
19489066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * @param width  the width of the pictures, in pixels
19499066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * @param height the height of the pictures, in pixels
1950c157e0cd161e5b3b28b72bafebb3360ed856a608Wu-cheng Li         * @see #setDisplayOrientation(int)
1951c157e0cd161e5b3b28b72bafebb3360ed856a608Wu-cheng Li         * @see #getCameraInfo(int, CameraInfo)
1952c157e0cd161e5b3b28b72bafebb3360ed856a608Wu-cheng Li         * @see #setPictureSize(int, int)
1953c157e0cd161e5b3b28b72bafebb3360ed856a608Wu-cheng Li         * @see #setJpegThumbnailSize(int, int)
19549066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         */
19559066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        public void setPreviewSize(int width, int height) {
19569066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            String v = Integer.toString(width) + "x" + Integer.toString(height);
19579b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            set(KEY_PREVIEW_SIZE, v);
19589066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
19599066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
19609066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        /**
19619066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * Returns the dimensions setting for preview pictures.
19629b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
1963dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong         * @return a Size object with the width and height setting
19649066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         *          for the preview picture
19659066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         */
19669066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        public Size getPreviewSize() {
19679b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            String pair = get(KEY_PREVIEW_SIZE);
19689b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            return strToSize(pair);
19699b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        }
19709066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
19719b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        /**
19729b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * Gets the supported preview sizes.
19739b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
19743f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @return a list of Size object. This method will always return a list
19759c79938d47a3caa06e5fb956955374f30c55992bWu-cheng Li         *         with at least one element.
19769b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         */
19779b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public List<Size> getSupportedPreviewSizes() {
19789b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            String str = get(KEY_PREVIEW_SIZE + SUPPORTED_VALUES_SUFFIX);
19799b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            return splitSize(str);
19809066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
19819066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
19829066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        /**
198332a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * <p>Gets the supported video frame sizes that can be used by
198432a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * MediaRecorder.</p>
1985dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong         *
198632a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * <p>If the returned list is not null, the returned list will contain at
1987dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong         * least one Size and one of the sizes in the returned list must be
1988dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong         * passed to MediaRecorder.setVideoSize() for camcorder application if
1989dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong         * camera is used as the video source. In this case, the size of the
1990dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong         * preview can be different from the resolution of the recorded video
199132a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * during video recording.</p>
1992dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong         *
1993dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong         * @return a list of Size object if camera has separate preview and
1994dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong         *         video output; otherwise, null is returned.
1995dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong         * @see #getPreferredPreviewSizeForVideo()
1996dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong         */
1997dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong        public List<Size> getSupportedVideoSizes() {
1998dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong            String str = get(KEY_VIDEO_SIZE + SUPPORTED_VALUES_SUFFIX);
1999dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong            return splitSize(str);
2000dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong        }
2001dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong
2002dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong        /**
2003dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong         * Returns the preferred or recommended preview size (width and height)
2004dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong         * in pixels for video recording. Camcorder applications should
2005dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong         * set the preview size to a value that is not larger than the
2006dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong         * preferred preview size. In other words, the product of the width
2007dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong         * and height of the preview size should not be larger than that of
2008dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong         * the preferred preview size. In addition, we recommend to choose a
2009dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong         * preview size that has the same aspect ratio as the resolution of
2010dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong         * video to be recorded.
2011dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong         *
2012dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong         * @return the preferred preview size (width and height) in pixels for
2013dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong         *         video recording if getSupportedVideoSizes() does not return
2014dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong         *         null; otherwise, null is returned.
2015dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong         * @see #getSupportedVideoSizes()
2016dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong         */
2017dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong        public Size getPreferredPreviewSizeForVideo() {
2018dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong            String pair = get(KEY_PREFERRED_PREVIEW_SIZE_FOR_VIDEO);
2019dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong            return strToSize(pair);
2020dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong        }
2021dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong
2022dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong        /**
202332a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * <p>Sets the dimensions for EXIF thumbnail in Jpeg picture. If
20244c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li         * applications set both width and height to 0, EXIF will not contain
202532a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * thumbnail.</p>
20269b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
202732a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * <p>Applications need to consider the display orientation. See {@link
202832a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * #setPreviewSize(int,int)} for reference.</p>
2029c157e0cd161e5b3b28b72bafebb3360ed856a608Wu-cheng Li         *
20309066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * @param width  the width of the thumbnail, in pixels
20319066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * @param height the height of the thumbnail, in pixels
2032c157e0cd161e5b3b28b72bafebb3360ed856a608Wu-cheng Li         * @see #setPreviewSize(int,int)
20339b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         */
20349b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public void setJpegThumbnailSize(int width, int height) {
20359b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            set(KEY_JPEG_THUMBNAIL_WIDTH, width);
20369b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            set(KEY_JPEG_THUMBNAIL_HEIGHT, height);
20379b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        }
20389b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
20399b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        /**
20409b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * Returns the dimensions for EXIF thumbnail in Jpeg picture.
20419066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         *
20429b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * @return a Size object with the height and width setting for the EXIF
20439b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *         thumbnails
20449066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         */
20459b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public Size getJpegThumbnailSize() {
20469b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            return new Size(getInt(KEY_JPEG_THUMBNAIL_WIDTH),
20479b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li                            getInt(KEY_JPEG_THUMBNAIL_HEIGHT));
20489066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
20499066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
20509066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        /**
20514c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li         * Gets the supported jpeg thumbnail sizes.
20524c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li         *
20533f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @return a list of Size object. This method will always return a list
20544c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li         *         with at least two elements. Size 0,0 (no thumbnail) is always
20554c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li         *         supported.
20564c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li         */
20574c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li        public List<Size> getSupportedJpegThumbnailSizes() {
20584c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li            String str = get(KEY_JPEG_THUMBNAIL_SIZE + SUPPORTED_VALUES_SUFFIX);
20594c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li            return splitSize(str);
20604c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li        }
20614c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li
20624c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li        /**
20639b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * Sets the quality of the EXIF thumbnail in Jpeg picture.
20649066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         *
20659b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * @param quality the JPEG quality of the EXIF thumbnail. The range is 1
20669b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *                to 100, with 100 being the best.
20679066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         */
20689b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public void setJpegThumbnailQuality(int quality) {
20699b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            set(KEY_JPEG_THUMBNAIL_QUALITY, quality);
20709066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
20719066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
20729066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        /**
20739b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * Returns the quality setting for the EXIF thumbnail in Jpeg picture.
20749066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         *
20759b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * @return the JPEG quality setting of the EXIF thumbnail.
20769066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         */
20779b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public int getJpegThumbnailQuality() {
20789b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            return getInt(KEY_JPEG_THUMBNAIL_QUALITY);
20799066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
20809066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
20819066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        /**
20829b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * Sets Jpeg quality of captured picture.
20839066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         *
20849b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * @param quality the JPEG quality of captured picture. The range is 1
20859b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *                to 100, with 100 being the best.
20869b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         */
20879b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public void setJpegQuality(int quality) {
20889b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            set(KEY_JPEG_QUALITY, quality);
20899b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        }
20909b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
20919b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        /**
20929b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * Returns the quality setting for the JPEG picture.
20939b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
20949b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * @return the JPEG picture quality setting.
20959066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         */
20969b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public int getJpegQuality() {
20979b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            return getInt(KEY_JPEG_QUALITY);
20989066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
20999066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
21009066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        /**
2101a18e90176a8e2442837d0503fbfd4adb9df0818fWu-cheng Li         * Sets the rate at which preview frames are received. This is the
2102a18e90176a8e2442837d0503fbfd4adb9df0818fWu-cheng Li         * target frame rate. The actual frame rate depends on the driver.
21039b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
21049066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * @param fps the frame rate (frames per second)
21055f1e69c76ef5886ed65e303490c5f660da4756efWu-cheng Li         * @deprecated replaced by {@link #setPreviewFpsRange(int,int)}
21069066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         */
21075f1e69c76ef5886ed65e303490c5f660da4756efWu-cheng Li        @Deprecated
21089066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        public void setPreviewFrameRate(int fps) {
21099b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            set(KEY_PREVIEW_FRAME_RATE, fps);
21109066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
21119066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
21129066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        /**
2113a18e90176a8e2442837d0503fbfd4adb9df0818fWu-cheng Li         * Returns the setting for the rate at which preview frames are
2114a18e90176a8e2442837d0503fbfd4adb9df0818fWu-cheng Li         * received. This is the target frame rate. The actual frame rate
2115a18e90176a8e2442837d0503fbfd4adb9df0818fWu-cheng Li         * depends on the driver.
21169b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
21179066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * @return the frame rate setting (frames per second)
21185f1e69c76ef5886ed65e303490c5f660da4756efWu-cheng Li         * @deprecated replaced by {@link #getPreviewFpsRange(int[])}
21199066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         */
21205f1e69c76ef5886ed65e303490c5f660da4756efWu-cheng Li        @Deprecated
21219066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        public int getPreviewFrameRate() {
21229b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            return getInt(KEY_PREVIEW_FRAME_RATE);
21239b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        }
21249b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
21259b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        /**
21269b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * Gets the supported preview frame rates.
21279b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
21283f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @return a list of supported preview frame rates. null if preview
21293f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         *         frame rate setting is not supported.
21305f1e69c76ef5886ed65e303490c5f660da4756efWu-cheng Li         * @deprecated replaced by {@link #getSupportedPreviewFpsRange()}
21319b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         */
21325f1e69c76ef5886ed65e303490c5f660da4756efWu-cheng Li        @Deprecated
21339b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public List<Integer> getSupportedPreviewFrameRates() {
21349b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            String str = get(KEY_PREVIEW_FRAME_RATE + SUPPORTED_VALUES_SUFFIX);
21359b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            return splitInt(str);
21369066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
21379066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
21389066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        /**
2139454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         * Sets the maximum and maximum preview fps. This controls the rate of
21401620d118a49dc6df7b0e83d7343f8a8bb6e23b12Wu-cheng Li         * preview frames received in {@link PreviewCallback}. The minimum and
2141454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         * maximum preview fps must be one of the elements from {@link
2142454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         * #getSupportedPreviewFpsRange}.
2143454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         *
2144454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         * @param min the minimum preview fps (scaled by 1000).
2145454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         * @param max the maximum preview fps (scaled by 1000).
2146454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         * @throws RuntimeException if fps range is invalid.
2147454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         * @see #setPreviewCallbackWithBuffer(Camera.PreviewCallback)
2148454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         * @see #getSupportedPreviewFpsRange()
2149454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         */
2150454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li        public void setPreviewFpsRange(int min, int max) {
2151454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li            set(KEY_PREVIEW_FPS_RANGE, "" + min + "," + max);
2152454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li        }
2153454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li
2154454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li        /**
2155454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         * Returns the current minimum and maximum preview fps. The values are
2156454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         * one of the elements returned by {@link #getSupportedPreviewFpsRange}.
2157454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         *
2158454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         * @return range the minimum and maximum preview fps (scaled by 1000).
2159454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         * @see #PREVIEW_FPS_MIN_INDEX
2160454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         * @see #PREVIEW_FPS_MAX_INDEX
2161454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         * @see #getSupportedPreviewFpsRange()
2162454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         */
2163454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li        public void getPreviewFpsRange(int[] range) {
2164454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li            if (range == null || range.length != 2) {
2165454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li                throw new IllegalArgumentException(
21665f1e69c76ef5886ed65e303490c5f660da4756efWu-cheng Li                        "range must be an array with two elements.");
2167454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li            }
2168454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li            splitInt(get(KEY_PREVIEW_FPS_RANGE), range);
2169454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li        }
2170454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li
2171454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li        /**
2172454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         * Gets the supported preview fps (frame-per-second) ranges. Each range
2173454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         * contains a minimum fps and maximum fps. If minimum fps equals to
2174454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         * maximum fps, the camera outputs frames in fixed frame rate. If not,
2175454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         * the camera outputs frames in auto frame rate. The actual frame rate
2176454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         * fluctuates between the minimum and the maximum. The values are
2177454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         * multiplied by 1000 and represented in integers. For example, if frame
2178454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         * rate is 26.623 frames per second, the value is 26623.
2179454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         *
2180454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         * @return a list of supported preview fps ranges. This method returns a
2181454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         *         list with at least one element. Every element is an int array
2182454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         *         of two values - minimum fps and maximum fps. The list is
2183454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         *         sorted from small to large (first by maximum fps and then
2184454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         *         minimum fps).
2185454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         * @see #PREVIEW_FPS_MIN_INDEX
2186454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         * @see #PREVIEW_FPS_MAX_INDEX
2187454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         */
2188454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li        public List<int[]> getSupportedPreviewFpsRange() {
2189454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li            String str = get(KEY_PREVIEW_FPS_RANGE + SUPPORTED_VALUES_SUFFIX);
2190454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li            return splitRange(str);
2191454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li        }
2192454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li
2193454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li        /**
21947478ea6848c0059e65a4089b4ec2ff4158520870Wu-cheng Li         * Sets the image format for preview pictures.
2195da0a56df963353a1f1bd1914fa31f870d982dd5aScott Main         * <p>If this is never called, the default format will be
2196a696f5d667227365da732481770767dcb330dd23Mathias Agopian         * {@link android.graphics.ImageFormat#NV21}, which
2197df4578e8ab7008a7e528d5af2ae761b33cf2bdf4Scott Main         * uses the NV21 encoding format.</p>
21987478ea6848c0059e65a4089b4ec2ff4158520870Wu-cheng Li         *
2199df4578e8ab7008a7e528d5af2ae761b33cf2bdf4Scott Main         * @param pixel_format the desired preview picture format, defined
2200a696f5d667227365da732481770767dcb330dd23Mathias Agopian         *   by one of the {@link android.graphics.ImageFormat} constants.
2201a696f5d667227365da732481770767dcb330dd23Mathias Agopian         *   (E.g., <var>ImageFormat.NV21</var> (default),
2202a696f5d667227365da732481770767dcb330dd23Mathias Agopian         *                      <var>ImageFormat.RGB_565</var>, or
2203a696f5d667227365da732481770767dcb330dd23Mathias Agopian         *                      <var>ImageFormat.JPEG</var>)
2204a696f5d667227365da732481770767dcb330dd23Mathias Agopian         * @see android.graphics.ImageFormat
22059066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         */
22069066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        public void setPreviewFormat(int pixel_format) {
22079066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            String s = cameraFormatForPixelFormat(pixel_format);
22089066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            if (s == null) {
22099b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li                throw new IllegalArgumentException(
22109b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li                        "Invalid pixel_format=" + pixel_format);
22119066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            }
22129066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
22139b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            set(KEY_PREVIEW_FORMAT, s);
22149066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
22159066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
22169066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        /**
22173f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * Returns the image format for preview frames got from
22189b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * {@link PreviewCallback}.
22197478ea6848c0059e65a4089b4ec2ff4158520870Wu-cheng Li         *
22203f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @return the preview format.
22213f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see android.graphics.ImageFormat
22229066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         */
22239066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        public int getPreviewFormat() {
22249b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            return pixelFormatForCameraFormat(get(KEY_PREVIEW_FORMAT));
22259b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        }
22269b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
22279b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        /**
2228f9293e7d5057f54ec90423f55b78138d5729e30fWu-cheng Li         * Gets the supported preview formats. {@link android.graphics.ImageFormat#NV21}
2229f9293e7d5057f54ec90423f55b78138d5729e30fWu-cheng Li         * is always supported. {@link android.graphics.ImageFormat#YV12}
2230f9293e7d5057f54ec90423f55b78138d5729e30fWu-cheng Li         * is always supported since API level 12.
22319b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
22323f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @return a list of supported preview formats. This method will always
22333f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         *         return a list with at least one element.
22343f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see android.graphics.ImageFormat
22359b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         */
22369b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public List<Integer> getSupportedPreviewFormats() {
22379b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            String str = get(KEY_PREVIEW_FORMAT + SUPPORTED_VALUES_SUFFIX);
2238eb68c46a40c773eb56ef7bcf8e7ece5c6a5a8d23Chih-Chung Chang            ArrayList<Integer> formats = new ArrayList<Integer>();
2239eb68c46a40c773eb56ef7bcf8e7ece5c6a5a8d23Chih-Chung Chang            for (String s : split(str)) {
2240eb68c46a40c773eb56ef7bcf8e7ece5c6a5a8d23Chih-Chung Chang                int f = pixelFormatForCameraFormat(s);
2241a696f5d667227365da732481770767dcb330dd23Mathias Agopian                if (f == ImageFormat.UNKNOWN) continue;
2242eb68c46a40c773eb56ef7bcf8e7ece5c6a5a8d23Chih-Chung Chang                formats.add(f);
2243eb68c46a40c773eb56ef7bcf8e7ece5c6a5a8d23Chih-Chung Chang            }
2244eb68c46a40c773eb56ef7bcf8e7ece5c6a5a8d23Chih-Chung Chang            return formats;
22459066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
22469066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
22479066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        /**
224832a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * <p>Sets the dimensions for pictures.</p>
22499b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
225032a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * <p>Applications need to consider the display orientation. See {@link
225132a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * #setPreviewSize(int,int)} for reference.</p>
2252c157e0cd161e5b3b28b72bafebb3360ed856a608Wu-cheng Li         *
22539066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * @param width  the width for pictures, in pixels
22549066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * @param height the height for pictures, in pixels
2255c157e0cd161e5b3b28b72bafebb3360ed856a608Wu-cheng Li         * @see #setPreviewSize(int,int)
2256c157e0cd161e5b3b28b72bafebb3360ed856a608Wu-cheng Li         *
22579066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         */
22589066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        public void setPictureSize(int width, int height) {
22599066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            String v = Integer.toString(width) + "x" + Integer.toString(height);
22609b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            set(KEY_PICTURE_SIZE, v);
22619066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
22629066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
22639066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        /**
22649066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * Returns the dimension setting for pictures.
22659b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
22669b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * @return a Size object with the height and width setting
22679066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         *          for pictures
22689066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         */
22699066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        public Size getPictureSize() {
22709b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            String pair = get(KEY_PICTURE_SIZE);
22719b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            return strToSize(pair);
22729b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        }
22739066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
22749b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        /**
22759b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * Gets the supported picture sizes.
22769b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
22773f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @return a list of supported picture sizes. This method will always
22783f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         *         return a list with at least one element.
22799b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         */
22809b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public List<Size> getSupportedPictureSizes() {
22819b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            String str = get(KEY_PICTURE_SIZE + SUPPORTED_VALUES_SUFFIX);
22829b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            return splitSize(str);
22839066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
22849066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
22859066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        /**
22869066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * Sets the image format for pictures.
22879b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
22889b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * @param pixel_format the desired picture format
2289a696f5d667227365da732481770767dcb330dd23Mathias Agopian         *                     (<var>ImageFormat.NV21</var>,
2290a696f5d667227365da732481770767dcb330dd23Mathias Agopian         *                      <var>ImageFormat.RGB_565</var>, or
2291a696f5d667227365da732481770767dcb330dd23Mathias Agopian         *                      <var>ImageFormat.JPEG</var>)
2292a696f5d667227365da732481770767dcb330dd23Mathias Agopian         * @see android.graphics.ImageFormat
22939066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         */
22949066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        public void setPictureFormat(int pixel_format) {
22959066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            String s = cameraFormatForPixelFormat(pixel_format);
22969066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            if (s == null) {
22979b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li                throw new IllegalArgumentException(
22989b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li                        "Invalid pixel_format=" + pixel_format);
22999066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            }
23009066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
23019b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            set(KEY_PICTURE_FORMAT, s);
23029066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
23039066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
23049066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        /**
23059066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * Returns the image format for pictures.
23069b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
23073f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @return the picture format
23083f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see android.graphics.ImageFormat
23099066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         */
23109066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        public int getPictureFormat() {
23119b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            return pixelFormatForCameraFormat(get(KEY_PICTURE_FORMAT));
23129b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        }
23139b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
23149b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        /**
23159b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * Gets the supported picture formats.
23169b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
23173f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @return supported picture formats. This method will always return a
23183f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         *         list with at least one element.
23193f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see android.graphics.ImageFormat
23209b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         */
23219b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public List<Integer> getSupportedPictureFormats() {
23229c79938d47a3caa06e5fb956955374f30c55992bWu-cheng Li            String str = get(KEY_PICTURE_FORMAT + SUPPORTED_VALUES_SUFFIX);
23239c79938d47a3caa06e5fb956955374f30c55992bWu-cheng Li            ArrayList<Integer> formats = new ArrayList<Integer>();
23249c79938d47a3caa06e5fb956955374f30c55992bWu-cheng Li            for (String s : split(str)) {
23259c79938d47a3caa06e5fb956955374f30c55992bWu-cheng Li                int f = pixelFormatForCameraFormat(s);
2326a696f5d667227365da732481770767dcb330dd23Mathias Agopian                if (f == ImageFormat.UNKNOWN) continue;
23279c79938d47a3caa06e5fb956955374f30c55992bWu-cheng Li                formats.add(f);
23289c79938d47a3caa06e5fb956955374f30c55992bWu-cheng Li            }
23299c79938d47a3caa06e5fb956955374f30c55992bWu-cheng Li            return formats;
23309066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
23319066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
23329066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        private String cameraFormatForPixelFormat(int pixel_format) {
23339066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            switch(pixel_format) {
2334a696f5d667227365da732481770767dcb330dd23Mathias Agopian            case ImageFormat.NV16:      return PIXEL_FORMAT_YUV422SP;
2335a696f5d667227365da732481770767dcb330dd23Mathias Agopian            case ImageFormat.NV21:      return PIXEL_FORMAT_YUV420SP;
2336a696f5d667227365da732481770767dcb330dd23Mathias Agopian            case ImageFormat.YUY2:      return PIXEL_FORMAT_YUV422I;
233710a1b30dfbd0bbeae6776e353600986647c6e0a8Wu-cheng Li            case ImageFormat.YV12:      return PIXEL_FORMAT_YUV420P;
2338a696f5d667227365da732481770767dcb330dd23Mathias Agopian            case ImageFormat.RGB_565:   return PIXEL_FORMAT_RGB565;
2339a696f5d667227365da732481770767dcb330dd23Mathias Agopian            case ImageFormat.JPEG:      return PIXEL_FORMAT_JPEG;
234070fb9085044c5e6f52c33c970d238b764cf2373bWu-cheng Li            case ImageFormat.BAYER_RGGB: return PIXEL_FORMAT_BAYER_RGGB;
2341a696f5d667227365da732481770767dcb330dd23Mathias Agopian            default:                    return null;
23429066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            }
23439066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
23449066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
23459066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        private int pixelFormatForCameraFormat(String format) {
23469066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            if (format == null)
2347a696f5d667227365da732481770767dcb330dd23Mathias Agopian                return ImageFormat.UNKNOWN;
23489066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
23499b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            if (format.equals(PIXEL_FORMAT_YUV422SP))
2350a696f5d667227365da732481770767dcb330dd23Mathias Agopian                return ImageFormat.NV16;
23519066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
23529b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            if (format.equals(PIXEL_FORMAT_YUV420SP))
2353a696f5d667227365da732481770767dcb330dd23Mathias Agopian                return ImageFormat.NV21;
23549066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
2355eb68c46a40c773eb56ef7bcf8e7ece5c6a5a8d23Chih-Chung Chang            if (format.equals(PIXEL_FORMAT_YUV422I))
2356a696f5d667227365da732481770767dcb330dd23Mathias Agopian                return ImageFormat.YUY2;
2357eb68c46a40c773eb56ef7bcf8e7ece5c6a5a8d23Chih-Chung Chang
235810a1b30dfbd0bbeae6776e353600986647c6e0a8Wu-cheng Li            if (format.equals(PIXEL_FORMAT_YUV420P))
235910a1b30dfbd0bbeae6776e353600986647c6e0a8Wu-cheng Li                return ImageFormat.YV12;
236010a1b30dfbd0bbeae6776e353600986647c6e0a8Wu-cheng Li
23619b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            if (format.equals(PIXEL_FORMAT_RGB565))
2362a696f5d667227365da732481770767dcb330dd23Mathias Agopian                return ImageFormat.RGB_565;
23639066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
23649b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            if (format.equals(PIXEL_FORMAT_JPEG))
2365a696f5d667227365da732481770767dcb330dd23Mathias Agopian                return ImageFormat.JPEG;
23669066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
2367a696f5d667227365da732481770767dcb330dd23Mathias Agopian            return ImageFormat.UNKNOWN;
23689066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
23699066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
23709b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        /**
23712fb818ca7dd53d00646854a2473f1a69be43067cWu-cheng Li         * Sets the rotation angle in degrees relative to the orientation of
23722fb818ca7dd53d00646854a2473f1a69be43067cWu-cheng Li         * the camera. This affects the pictures returned from JPEG {@link
23732fb818ca7dd53d00646854a2473f1a69be43067cWu-cheng Li         * PictureCallback}. The camera driver may set orientation in the
23742fb818ca7dd53d00646854a2473f1a69be43067cWu-cheng Li         * EXIF header without rotating the picture. Or the driver may rotate
23752fb818ca7dd53d00646854a2473f1a69be43067cWu-cheng Li         * the picture and the EXIF thumbnail. If the Jpeg picture is rotated,
23762fb818ca7dd53d00646854a2473f1a69be43067cWu-cheng Li         * the orientation in the EXIF header will be missing or 1 (row #0 is
23772fb818ca7dd53d00646854a2473f1a69be43067cWu-cheng Li         * top and column #0 is left side).
23789b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
237969ea4e15e52c456537575d21443ac1efdb03a902Brad Fitzpatrick         * <p>If applications want to rotate the picture to match the orientation
23802fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li         * of what users see, apps should use {@link
23812fb818ca7dd53d00646854a2473f1a69be43067cWu-cheng Li         * android.view.OrientationEventListener} and {@link CameraInfo}.
23822fb818ca7dd53d00646854a2473f1a69be43067cWu-cheng Li         * The value from OrientationEventListener is relative to the natural
23832fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li         * orientation of the device. CameraInfo.orientation is the angle
238469ea4e15e52c456537575d21443ac1efdb03a902Brad Fitzpatrick         * between camera orientation and natural device orientation. The sum
23852fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li         * of the two is the rotation angle for back-facing camera. The
23862fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li         * difference of the two is the rotation angle for front-facing camera.
23872fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li         * Note that the JPEG pictures of front-facing cameras are not mirrored
23882fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li         * as in preview display.
23899b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
239069ea4e15e52c456537575d21443ac1efdb03a902Brad Fitzpatrick         * <p>For example, suppose the natural orientation of the device is
23912fb818ca7dd53d00646854a2473f1a69be43067cWu-cheng Li         * portrait. The device is rotated 270 degrees clockwise, so the device
23922fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li         * orientation is 270. Suppose a back-facing camera sensor is mounted in
23932fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li         * landscape and the top side of the camera sensor is aligned with the
23942fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li         * right edge of the display in natural orientation. So the camera
23952fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li         * orientation is 90. The rotation should be set to 0 (270 + 90).
23962fb818ca7dd53d00646854a2473f1a69be43067cWu-cheng Li         *
239769ea4e15e52c456537575d21443ac1efdb03a902Brad Fitzpatrick         * <p>The reference code is as follows.
23982fb818ca7dd53d00646854a2473f1a69be43067cWu-cheng Li         *
2399e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala         * <pre>
24009a10bf0386ac9822e33a15820d8cd1fd8bdb5572Scott Main         * public void onOrientationChanged(int orientation) {
24012fb818ca7dd53d00646854a2473f1a69be43067cWu-cheng Li         *     if (orientation == ORIENTATION_UNKNOWN) return;
24022fb818ca7dd53d00646854a2473f1a69be43067cWu-cheng Li         *     android.hardware.Camera.CameraInfo info =
24032fb818ca7dd53d00646854a2473f1a69be43067cWu-cheng Li         *            new android.hardware.Camera.CameraInfo();
24042fb818ca7dd53d00646854a2473f1a69be43067cWu-cheng Li         *     android.hardware.Camera.getCameraInfo(cameraId, info);
24052fb818ca7dd53d00646854a2473f1a69be43067cWu-cheng Li         *     orientation = (orientation + 45) / 90 * 90;
24062fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li         *     int rotation = 0;
24072fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li         *     if (info.facing == CameraInfo.CAMERA_FACING_FRONT) {
24082fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li         *         rotation = (info.orientation - orientation + 360) % 360;
24092fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li         *     } else {  // back-facing camera
24102fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li         *         rotation = (info.orientation + orientation) % 360;
24112fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li         *     }
24122fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li         *     mParameters.setRotation(rotation);
24132fb818ca7dd53d00646854a2473f1a69be43067cWu-cheng Li         * }
2414e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala         * </pre>
24152fb818ca7dd53d00646854a2473f1a69be43067cWu-cheng Li         *
24162fb818ca7dd53d00646854a2473f1a69be43067cWu-cheng Li         * @param rotation The rotation angle in degrees relative to the
24172fb818ca7dd53d00646854a2473f1a69be43067cWu-cheng Li         *                 orientation of the camera. Rotation can only be 0,
24182fb818ca7dd53d00646854a2473f1a69be43067cWu-cheng Li         *                 90, 180 or 270.
24199b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * @throws IllegalArgumentException if rotation value is invalid.
24209b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * @see android.view.OrientationEventListener
24212fb818ca7dd53d00646854a2473f1a69be43067cWu-cheng Li         * @see #getCameraInfo(int, CameraInfo)
24229b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         */
24239b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public void setRotation(int rotation) {
24249b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            if (rotation == 0 || rotation == 90 || rotation == 180
24259b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li                    || rotation == 270) {
24269b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li                set(KEY_ROTATION, Integer.toString(rotation));
24279b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            } else {
24289b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li                throw new IllegalArgumentException(
24299b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li                        "Invalid rotation=" + rotation);
24309b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            }
24319b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        }
24329b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
24339b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        /**
24349b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * Sets GPS latitude coordinate. This will be stored in JPEG EXIF
24359b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * header.
24369b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
24379b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * @param latitude GPS latitude coordinate.
24389b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         */
24399b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public void setGpsLatitude(double latitude) {
24409b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            set(KEY_GPS_LATITUDE, Double.toString(latitude));
24419b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        }
24429b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
24439b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        /**
24449b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * Sets GPS longitude coordinate. This will be stored in JPEG EXIF
24459b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * header.
24469b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
24479b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * @param longitude GPS longitude coordinate.
24489b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         */
24499b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public void setGpsLongitude(double longitude) {
24509b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            set(KEY_GPS_LONGITUDE, Double.toString(longitude));
24519b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        }
24529b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
24539b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        /**
24549b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * Sets GPS altitude. This will be stored in JPEG EXIF header.
24559b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
24569b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * @param altitude GPS altitude in meters.
24579b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         */
24589b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public void setGpsAltitude(double altitude) {
24599b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            set(KEY_GPS_ALTITUDE, Double.toString(altitude));
24609b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        }
24619b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
24629b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        /**
24639b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * Sets GPS timestamp. This will be stored in JPEG EXIF header.
24649b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
24659b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * @param timestamp GPS timestamp (UTC in seconds since January 1,
24669b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *                  1970).
24679b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         */
24689b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public void setGpsTimestamp(long timestamp) {
24699b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            set(KEY_GPS_TIMESTAMP, Long.toString(timestamp));
24709b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        }
24719b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
24729b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        /**
2473e208377fbab6b90f41e68699700942a81f4caaebRay Chen         * Sets GPS processing method. It will store up to 32 characters
2474055c986ab841f8f758398841730f1e90313b132aRay Chen         * in JPEG EXIF header.
2475055c986ab841f8f758398841730f1e90313b132aRay Chen         *
2476055c986ab841f8f758398841730f1e90313b132aRay Chen         * @param processing_method The processing method to get this location.
2477055c986ab841f8f758398841730f1e90313b132aRay Chen         */
2478055c986ab841f8f758398841730f1e90313b132aRay Chen        public void setGpsProcessingMethod(String processing_method) {
2479055c986ab841f8f758398841730f1e90313b132aRay Chen            set(KEY_GPS_PROCESSING_METHOD, processing_method);
2480055c986ab841f8f758398841730f1e90313b132aRay Chen        }
2481055c986ab841f8f758398841730f1e90313b132aRay Chen
2482055c986ab841f8f758398841730f1e90313b132aRay Chen        /**
24839b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * Removes GPS latitude, longitude, altitude, and timestamp from the
24849b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * parameters.
24859b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         */
24869b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public void removeGpsData() {
24879b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            remove(KEY_GPS_LATITUDE);
24889b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            remove(KEY_GPS_LONGITUDE);
24899b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            remove(KEY_GPS_ALTITUDE);
24909b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            remove(KEY_GPS_TIMESTAMP);
2491055c986ab841f8f758398841730f1e90313b132aRay Chen            remove(KEY_GPS_PROCESSING_METHOD);
24929b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        }
24939b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
24949b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        /**
24959b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * Gets the current white balance setting.
24969b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
24973f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @return current white balance. null if white balance setting is not
24983f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         *         supported.
24993f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #WHITE_BALANCE_AUTO
25003f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #WHITE_BALANCE_INCANDESCENT
25013f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #WHITE_BALANCE_FLUORESCENT
25023f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #WHITE_BALANCE_WARM_FLUORESCENT
25033f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #WHITE_BALANCE_DAYLIGHT
25043f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #WHITE_BALANCE_CLOUDY_DAYLIGHT
25053f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #WHITE_BALANCE_TWILIGHT
25063f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #WHITE_BALANCE_SHADE
25073f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         *
25089b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         */
25099b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public String getWhiteBalance() {
25109b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            return get(KEY_WHITE_BALANCE);
25119b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        }
25129b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
25139b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        /**
251416b67137b893f32491a38ab81d49368322e1ae92Eino-Ville Talvala         * Sets the white balance. Changing the setting will release the
2515b838d8d4a26c3cfea2e2a5ce831daebbb5653ae7Wu-cheng Li         * auto-white balance lock. It is recommended not to change white
2516b838d8d4a26c3cfea2e2a5ce831daebbb5653ae7Wu-cheng Li         * balance and AWB lock at the same time.
25179b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
25183f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @param value new white balance.
25193f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #getWhiteBalance()
2520037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala         * @see #setAutoWhiteBalanceLock(boolean)
25219b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         */
25229b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public void setWhiteBalance(String value) {
2523b838d8d4a26c3cfea2e2a5ce831daebbb5653ae7Wu-cheng Li            String oldValue = get(KEY_WHITE_BALANCE);
2524b838d8d4a26c3cfea2e2a5ce831daebbb5653ae7Wu-cheng Li            if (same(value, oldValue)) return;
25259b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            set(KEY_WHITE_BALANCE, value);
252616b67137b893f32491a38ab81d49368322e1ae92Eino-Ville Talvala            set(KEY_AUTO_WHITEBALANCE_LOCK, FALSE);
25279b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        }
25289b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
25299b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        /**
25309b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * Gets the supported white balance.
25319b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
25323f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @return a list of supported white balance. null if white balance
25333f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         *         setting is not supported.
25343f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #getWhiteBalance()
25359b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         */
25369b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public List<String> getSupportedWhiteBalance() {
25379b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            String str = get(KEY_WHITE_BALANCE + SUPPORTED_VALUES_SUFFIX);
25389b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            return split(str);
25399b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        }
25409b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
25419b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        /**
25429b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * Gets the current color effect setting.
25439b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
25443f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @return current color effect. null if color effect
25459b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *         setting is not supported.
25463f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #EFFECT_NONE
25473f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #EFFECT_MONO
25483f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #EFFECT_NEGATIVE
25493f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #EFFECT_SOLARIZE
25503f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #EFFECT_SEPIA
25513f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #EFFECT_POSTERIZE
25523f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #EFFECT_WHITEBOARD
25533f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #EFFECT_BLACKBOARD
25543f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #EFFECT_AQUA
25559b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         */
25569b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public String getColorEffect() {
25579b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            return get(KEY_EFFECT);
25589b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        }
25599b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
25609b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        /**
25619b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * Sets the current color effect setting.
25629b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
25633f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @param value new color effect.
25643f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #getColorEffect()
25659b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         */
25669b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public void setColorEffect(String value) {
25679b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            set(KEY_EFFECT, value);
25689b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        }
25699b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
25709b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        /**
25719b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * Gets the supported color effects.
25729b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
25733f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @return a list of supported color effects. null if color effect
25749b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *         setting is not supported.
25753f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #getColorEffect()
25769b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         */
25779b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public List<String> getSupportedColorEffects() {
25789b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            String str = get(KEY_EFFECT + SUPPORTED_VALUES_SUFFIX);
25799b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            return split(str);
25809b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        }
25819b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
25829b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
25839b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        /**
25849b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * Gets the current antibanding setting.
25859b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
25863f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @return current antibanding. null if antibanding setting is not
25873f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         *         supported.
25883f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #ANTIBANDING_AUTO
25893f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #ANTIBANDING_50HZ
25903f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #ANTIBANDING_60HZ
25913f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #ANTIBANDING_OFF
25929b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         */
25939b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public String getAntibanding() {
25949b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            return get(KEY_ANTIBANDING);
25959b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        }
25969b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
25979b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        /**
25989b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * Sets the antibanding.
25999b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
26003f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @param antibanding new antibanding value.
26013f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #getAntibanding()
26029b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         */
26039b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public void setAntibanding(String antibanding) {
26049b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            set(KEY_ANTIBANDING, antibanding);
26059b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        }
26069b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
26079b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        /**
26089b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * Gets the supported antibanding values.
26099b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
26103f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @return a list of supported antibanding values. null if antibanding
26113f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         *         setting is not supported.
26123f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #getAntibanding()
26139b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         */
26149b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public List<String> getSupportedAntibanding() {
26159b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            String str = get(KEY_ANTIBANDING + SUPPORTED_VALUES_SUFFIX);
26169b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            return split(str);
26179b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        }
26189b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
26199b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        /**
26209b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * Gets the current scene mode setting.
26219b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
26229b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * @return one of SCENE_MODE_XXX string constant. null if scene mode
26239b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *         setting is not supported.
26243f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #SCENE_MODE_AUTO
26253f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #SCENE_MODE_ACTION
26263f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #SCENE_MODE_PORTRAIT
26273f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #SCENE_MODE_LANDSCAPE
26283f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #SCENE_MODE_NIGHT
26293f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #SCENE_MODE_NIGHT_PORTRAIT
26303f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #SCENE_MODE_THEATRE
26313f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #SCENE_MODE_BEACH
26323f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #SCENE_MODE_SNOW
26333f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #SCENE_MODE_SUNSET
26343f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #SCENE_MODE_STEADYPHOTO
26353f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #SCENE_MODE_FIREWORKS
26363f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #SCENE_MODE_SPORTS
26373f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #SCENE_MODE_PARTY
26383f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #SCENE_MODE_CANDLELIGHT
26399b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         */
26409b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public String getSceneMode() {
26419b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            return get(KEY_SCENE_MODE);
26429b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        }
26439b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
26449b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        /**
2645c58b42327df5fbc826e2fcc2674ab6db0edfcd92Wu-cheng Li         * Sets the scene mode. Changing scene mode may override other
2646c58b42327df5fbc826e2fcc2674ab6db0edfcd92Wu-cheng Li         * parameters (such as flash mode, focus mode, white balance). For
2647c58b42327df5fbc826e2fcc2674ab6db0edfcd92Wu-cheng Li         * example, suppose originally flash mode is on and supported flash
2648c58b42327df5fbc826e2fcc2674ab6db0edfcd92Wu-cheng Li         * modes are on/off. In night scene mode, both flash mode and supported
2649c58b42327df5fbc826e2fcc2674ab6db0edfcd92Wu-cheng Li         * flash mode may be changed to off. After setting scene mode,
26502988ab7c322aad7508df930204886f334216b65cWu-cheng Li         * applications should call getParameters to know if some parameters are
26512988ab7c322aad7508df930204886f334216b65cWu-cheng Li         * changed.
26529b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
26533f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @param value scene mode.
26543f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #getSceneMode()
26559b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         */
26569b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public void setSceneMode(String value) {
26579b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            set(KEY_SCENE_MODE, value);
26589b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        }
26599b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
26609b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        /**
26619b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * Gets the supported scene modes.
26629b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
26633f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @return a list of supported scene modes. null if scene mode setting
26643f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         *         is not supported.
26653f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #getSceneMode()
26669b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         */
26679b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public List<String> getSupportedSceneModes() {
26689b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            String str = get(KEY_SCENE_MODE + SUPPORTED_VALUES_SUFFIX);
26699b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            return split(str);
26709b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        }
26719b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
26729b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        /**
26739b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * Gets the current flash mode setting.
26749b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
26753f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @return current flash mode. null if flash mode setting is not
26763f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         *         supported.
26773f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #FLASH_MODE_OFF
26783f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #FLASH_MODE_AUTO
26793f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #FLASH_MODE_ON
26803f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #FLASH_MODE_RED_EYE
26813f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #FLASH_MODE_TORCH
26829b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         */
26839b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public String getFlashMode() {
26849b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            return get(KEY_FLASH_MODE);
26859b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        }
26869b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
26879b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        /**
26889b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * Sets the flash mode.
26899b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
26903f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @param value flash mode.
26913f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #getFlashMode()
26929b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         */
26939b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public void setFlashMode(String value) {
26949b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            set(KEY_FLASH_MODE, value);
26959b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        }
26969b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
26979b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        /**
26989b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * Gets the supported flash modes.
26999b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
27003f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @return a list of supported flash modes. null if flash mode setting
27013f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         *         is not supported.
27023f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #getFlashMode()
27039b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         */
27049b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public List<String> getSupportedFlashModes() {
27059b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            String str = get(KEY_FLASH_MODE + SUPPORTED_VALUES_SUFFIX);
27069b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            return split(str);
27079b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        }
27089b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
270936322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li        /**
271036322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li         * Gets the current focus mode setting.
271136322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li         *
2712699fe9397974685e6b2c73f9a3a0eb9e5a5a2ccfWu-cheng Li         * @return current focus mode. This method will always return a non-null
2713699fe9397974685e6b2c73f9a3a0eb9e5a5a2ccfWu-cheng Li         *         value. Applications should call {@link
2714699fe9397974685e6b2c73f9a3a0eb9e5a5a2ccfWu-cheng Li         *         #autoFocus(AutoFocusCallback)} to start the focus if focus
2715699fe9397974685e6b2c73f9a3a0eb9e5a5a2ccfWu-cheng Li         *         mode is FOCUS_MODE_AUTO or FOCUS_MODE_MACRO.
27163f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #FOCUS_MODE_AUTO
27173f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #FOCUS_MODE_INFINITY
27183f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #FOCUS_MODE_MACRO
27193f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #FOCUS_MODE_FIXED
2720f008f3ea82a0518375ee4ea41b32451badffbd95Wu-cheng Li         * @see #FOCUS_MODE_EDOF
2721d45cb72ac0d7d57829ffc9223decb89a5fc42ce2Wu-cheng Li         * @see #FOCUS_MODE_CONTINUOUS_VIDEO
272236322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li         */
272336322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li        public String getFocusMode() {
272436322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li            return get(KEY_FOCUS_MODE);
272536322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li        }
272636322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li
272736322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li        /**
272836322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li         * Sets the focus mode.
272936322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li         *
27303f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @param value focus mode.
27313f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #getFocusMode()
273236322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li         */
273336322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li        public void setFocusMode(String value) {
273436322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li            set(KEY_FOCUS_MODE, value);
273536322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li        }
273636322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li
273736322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li        /**
273836322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li         * Gets the supported focus modes.
273936322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li         *
27403f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @return a list of supported focus modes. This method will always
27413f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         *         return a list with at least one element.
27423f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #getFocusMode()
274336322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li         */
274436322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li        public List<String> getSupportedFocusModes() {
274536322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li            String str = get(KEY_FOCUS_MODE + SUPPORTED_VALUES_SUFFIX);
274636322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li            return split(str);
274736322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li        }
274836322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li
274936f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li        /**
27506c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li         * Gets the focal length (in millimeter) of the camera.
27516c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li         *
27526c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li         * @return the focal length. This method will always return a valid
27536c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li         *         value.
27546c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li         */
27556c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li        public float getFocalLength() {
27566c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li            return Float.parseFloat(get(KEY_FOCAL_LENGTH));
27576c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li        }
27586c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li
27596c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li        /**
27606c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li         * Gets the horizontal angle of view in degrees.
27616c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li         *
27626c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li         * @return horizontal angle of view. This method will always return a
27636c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li         *         valid value.
27646c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li         */
27656c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li        public float getHorizontalViewAngle() {
27666c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li            return Float.parseFloat(get(KEY_HORIZONTAL_VIEW_ANGLE));
27676c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li        }
27686c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li
27696c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li        /**
27706c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li         * Gets the vertical angle of view in degrees.
27716c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li         *
27726c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li         * @return vertical angle of view. This method will always return a
27736c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li         *         valid value.
27746c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li         */
27756c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li        public float getVerticalViewAngle() {
27766c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li            return Float.parseFloat(get(KEY_VERTICAL_VIEW_ANGLE));
27776c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li        }
27786c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li
27796c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li        /**
278024b326a8978bf78e3e560723dde221792784325bWu-cheng Li         * Gets the current exposure compensation index.
2781ff723b6c43d5a8fd0ae0e0732f5d47012d74e01dWu-cheng Li         *
278224b326a8978bf78e3e560723dde221792784325bWu-cheng Li         * @return current exposure compensation index. The range is {@link
278324b326a8978bf78e3e560723dde221792784325bWu-cheng Li         *         #getMinExposureCompensation} to {@link
278424b326a8978bf78e3e560723dde221792784325bWu-cheng Li         *         #getMaxExposureCompensation}. 0 means exposure is not
278524b326a8978bf78e3e560723dde221792784325bWu-cheng Li         *         adjusted.
2786ff723b6c43d5a8fd0ae0e0732f5d47012d74e01dWu-cheng Li         */
2787ff723b6c43d5a8fd0ae0e0732f5d47012d74e01dWu-cheng Li        public int getExposureCompensation() {
278824b326a8978bf78e3e560723dde221792784325bWu-cheng Li            return getInt(KEY_EXPOSURE_COMPENSATION, 0);
2789ff723b6c43d5a8fd0ae0e0732f5d47012d74e01dWu-cheng Li        }
2790ff723b6c43d5a8fd0ae0e0732f5d47012d74e01dWu-cheng Li
2791ff723b6c43d5a8fd0ae0e0732f5d47012d74e01dWu-cheng Li        /**
279224b326a8978bf78e3e560723dde221792784325bWu-cheng Li         * Sets the exposure compensation index.
2793ff723b6c43d5a8fd0ae0e0732f5d47012d74e01dWu-cheng Li         *
27940402e7da70715c96af90aa95c16d1bedc5199645Wu-cheng Li         * @param value exposure compensation index. The valid value range is
27950402e7da70715c96af90aa95c16d1bedc5199645Wu-cheng Li         *        from {@link #getMinExposureCompensation} (inclusive) to {@link
279624b326a8978bf78e3e560723dde221792784325bWu-cheng Li         *        #getMaxExposureCompensation} (inclusive). 0 means exposure is
279724b326a8978bf78e3e560723dde221792784325bWu-cheng Li         *        not adjusted. Application should call
279824b326a8978bf78e3e560723dde221792784325bWu-cheng Li         *        getMinExposureCompensation and getMaxExposureCompensation to
279924b326a8978bf78e3e560723dde221792784325bWu-cheng Li         *        know if exposure compensation is supported.
2800ff723b6c43d5a8fd0ae0e0732f5d47012d74e01dWu-cheng Li         */
2801ff723b6c43d5a8fd0ae0e0732f5d47012d74e01dWu-cheng Li        public void setExposureCompensation(int value) {
2802ff723b6c43d5a8fd0ae0e0732f5d47012d74e01dWu-cheng Li            set(KEY_EXPOSURE_COMPENSATION, value);
2803ff723b6c43d5a8fd0ae0e0732f5d47012d74e01dWu-cheng Li        }
2804ff723b6c43d5a8fd0ae0e0732f5d47012d74e01dWu-cheng Li
2805ff723b6c43d5a8fd0ae0e0732f5d47012d74e01dWu-cheng Li        /**
280624b326a8978bf78e3e560723dde221792784325bWu-cheng Li         * Gets the maximum exposure compensation index.
2807ff723b6c43d5a8fd0ae0e0732f5d47012d74e01dWu-cheng Li         *
280824b326a8978bf78e3e560723dde221792784325bWu-cheng Li         * @return maximum exposure compensation index (>=0). If both this
280924b326a8978bf78e3e560723dde221792784325bWu-cheng Li         *         method and {@link #getMinExposureCompensation} return 0,
281024b326a8978bf78e3e560723dde221792784325bWu-cheng Li         *         exposure compensation is not supported.
281124b326a8978bf78e3e560723dde221792784325bWu-cheng Li         */
281224b326a8978bf78e3e560723dde221792784325bWu-cheng Li        public int getMaxExposureCompensation() {
281324b326a8978bf78e3e560723dde221792784325bWu-cheng Li            return getInt(KEY_MAX_EXPOSURE_COMPENSATION, 0);
281424b326a8978bf78e3e560723dde221792784325bWu-cheng Li        }
281524b326a8978bf78e3e560723dde221792784325bWu-cheng Li
281624b326a8978bf78e3e560723dde221792784325bWu-cheng Li        /**
281724b326a8978bf78e3e560723dde221792784325bWu-cheng Li         * Gets the minimum exposure compensation index.
281824b326a8978bf78e3e560723dde221792784325bWu-cheng Li         *
281924b326a8978bf78e3e560723dde221792784325bWu-cheng Li         * @return minimum exposure compensation index (<=0). If both this
282024b326a8978bf78e3e560723dde221792784325bWu-cheng Li         *         method and {@link #getMaxExposureCompensation} return 0,
282124b326a8978bf78e3e560723dde221792784325bWu-cheng Li         *         exposure compensation is not supported.
2822ff723b6c43d5a8fd0ae0e0732f5d47012d74e01dWu-cheng Li         */
282324b326a8978bf78e3e560723dde221792784325bWu-cheng Li        public int getMinExposureCompensation() {
282424b326a8978bf78e3e560723dde221792784325bWu-cheng Li            return getInt(KEY_MIN_EXPOSURE_COMPENSATION, 0);
282524b326a8978bf78e3e560723dde221792784325bWu-cheng Li        }
282624b326a8978bf78e3e560723dde221792784325bWu-cheng Li
282724b326a8978bf78e3e560723dde221792784325bWu-cheng Li        /**
282824b326a8978bf78e3e560723dde221792784325bWu-cheng Li         * Gets the exposure compensation step.
282924b326a8978bf78e3e560723dde221792784325bWu-cheng Li         *
283024b326a8978bf78e3e560723dde221792784325bWu-cheng Li         * @return exposure compensation step. Applications can get EV by
283124b326a8978bf78e3e560723dde221792784325bWu-cheng Li         *         multiplying the exposure compensation index and step. Ex: if
283224b326a8978bf78e3e560723dde221792784325bWu-cheng Li         *         exposure compensation index is -6 and step is 0.333333333, EV
283324b326a8978bf78e3e560723dde221792784325bWu-cheng Li         *         is -2.
283424b326a8978bf78e3e560723dde221792784325bWu-cheng Li         */
283524b326a8978bf78e3e560723dde221792784325bWu-cheng Li        public float getExposureCompensationStep() {
283624b326a8978bf78e3e560723dde221792784325bWu-cheng Li            return getFloat(KEY_EXPOSURE_COMPENSATION_STEP, 0);
2837ff723b6c43d5a8fd0ae0e0732f5d47012d74e01dWu-cheng Li        }
2838ff723b6c43d5a8fd0ae0e0732f5d47012d74e01dWu-cheng Li
2839ff723b6c43d5a8fd0ae0e0732f5d47012d74e01dWu-cheng Li        /**
2840d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * <p>Sets the auto-exposure lock state. Applications should check
2841d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * {@link #isAutoExposureLockSupported} before using this method.</p>
28423773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala         *
2843d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * <p>If set to true, the camera auto-exposure routine will immediately
2844d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * pause until the lock is set to false. Exposure compensation settings
2845d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * changes will still take effect while auto-exposure is locked.</p>
2846d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         *
2847d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * <p>If auto-exposure is already locked, setting this to true again has
2848d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * no effect (the driver will not recalculate exposure values).</p>
2849d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         *
2850d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * <p>Stopping preview with {@link #stopPreview()}, or triggering still
2851d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * image capture with {@link #takePicture(Camera.ShutterCallback,
2852b4f95be03e018df825356fe2cd363797c66303f1Wu-cheng Li         * Camera.PictureCallback, Camera.PictureCallback)}, will not change the
2853b4f95be03e018df825356fe2cd363797c66303f1Wu-cheng Li         * lock.</p>
2854d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         *
2855b4f95be03e018df825356fe2cd363797c66303f1Wu-cheng Li         * <p>Exposure compensation, auto-exposure lock, and auto-white balance
2856b4f95be03e018df825356fe2cd363797c66303f1Wu-cheng Li         * lock can be used to capture an exposure-bracketed burst of images,
2857b4f95be03e018df825356fe2cd363797c66303f1Wu-cheng Li         * for example.</p>
2858d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         *
2859d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * <p>Auto-exposure state, including the lock state, will not be
28603773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala         * maintained after camera {@link #release()} is called.  Locking
28613773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala         * auto-exposure after {@link #open()} but before the first call to
28623773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala         * {@link #startPreview()} will not allow the auto-exposure routine to
2863d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * run at all, and may result in severely over- or under-exposed
2864d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * images.</p>
28653773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala         *
28663773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala         * @param toggle new state of the auto-exposure lock. True means that
28673773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala         *        auto-exposure is locked, false means that the auto-exposure
28683773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala         *        routine is free to run normally.
28693773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala         *
2870d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * @see #getAutoExposureLock()
28713773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala         */
28723773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala        public void setAutoExposureLock(boolean toggle) {
28733773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala            set(KEY_AUTO_EXPOSURE_LOCK, toggle ? TRUE : FALSE);
28743773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala        }
28753773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala
28763773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala        /**
28773773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala         * Gets the state of the auto-exposure lock. Applications should check
28783773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala         * {@link #isAutoExposureLockSupported} before using this method. See
28793773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala         * {@link #setAutoExposureLock} for details about the lock.
28803773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala         *
28813773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala         * @return State of the auto-exposure lock. Returns true if
2882b4f95be03e018df825356fe2cd363797c66303f1Wu-cheng Li         *         auto-exposure is currently locked, and false otherwise.
28833773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala         *
28843773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala         * @see #setAutoExposureLock(boolean)
28853773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala         *
28863773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala         */
28873773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala        public boolean getAutoExposureLock() {
28883773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala            String str = get(KEY_AUTO_EXPOSURE_LOCK);
28893773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala            return TRUE.equals(str);
28903773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala        }
28913773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala
28923773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala        /**
28933773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala         * Returns true if auto-exposure locking is supported. Applications
28943773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala         * should call this before trying to lock auto-exposure. See
28953773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala         * {@link #setAutoExposureLock} for details about the lock.
28963773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala         *
28973773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala         * @return true if auto-exposure lock is supported.
28983773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala         * @see #setAutoExposureLock(boolean)
28993773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala         *
29003773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala         */
29013773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala        public boolean isAutoExposureLockSupported() {
29023773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala            String str = get(KEY_AUTO_EXPOSURE_LOCK_SUPPORTED);
29033773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala            return TRUE.equals(str);
29043773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala        }
29053773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala
29063773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala        /**
2907d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * <p>Sets the auto-white balance lock state. Applications should check
2908d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * {@link #isAutoWhiteBalanceLockSupported} before using this
2909d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * method.</p>
2910d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         *
2911d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * <p>If set to true, the camera auto-white balance routine will
2912d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * immediately pause until the lock is set to false.</p>
2913d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         *
2914d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * <p>If auto-white balance is already locked, setting this to true
2915d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * again has no effect (the driver will not recalculate white balance
2916d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * values).</p>
2917d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         *
2918d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * <p>Stopping preview with {@link #stopPreview()}, or triggering still
2919d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * image capture with {@link #takePicture(Camera.ShutterCallback,
2920b4f95be03e018df825356fe2cd363797c66303f1Wu-cheng Li         * Camera.PictureCallback, Camera.PictureCallback)}, will not change the
2921b4f95be03e018df825356fe2cd363797c66303f1Wu-cheng Li         * the lock.</p>
2922d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         *
292316b67137b893f32491a38ab81d49368322e1ae92Eino-Ville Talvala         * <p> Changing the white balance mode with {@link #setWhiteBalance}
292416b67137b893f32491a38ab81d49368322e1ae92Eino-Ville Talvala         * will release the auto-white balance lock if it is set.</p>
292516b67137b893f32491a38ab81d49368322e1ae92Eino-Ville Talvala         *
2926b4f95be03e018df825356fe2cd363797c66303f1Wu-cheng Li         * <p>Exposure compensation, AE lock, and AWB lock can be used to
2927b4f95be03e018df825356fe2cd363797c66303f1Wu-cheng Li         * capture an exposure-bracketed burst of images, for example.
2928b4f95be03e018df825356fe2cd363797c66303f1Wu-cheng Li         * Auto-white balance state, including the lock state, will not be
2929b4f95be03e018df825356fe2cd363797c66303f1Wu-cheng Li         * maintained after camera {@link #release()} is called.  Locking
2930b4f95be03e018df825356fe2cd363797c66303f1Wu-cheng Li         * auto-white balance after {@link #open()} but before the first call to
2931b4f95be03e018df825356fe2cd363797c66303f1Wu-cheng Li         * {@link #startPreview()} will not allow the auto-white balance routine
2932b4f95be03e018df825356fe2cd363797c66303f1Wu-cheng Li         * to run at all, and may result in severely incorrect color in captured
2933b4f95be03e018df825356fe2cd363797c66303f1Wu-cheng Li         * images.</p>
2934d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         *
2935d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * @param toggle new state of the auto-white balance lock. True means
2936d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         *        that auto-white balance is locked, false means that the
2937d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         *        auto-white balance routine is free to run normally.
2938d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         *
2939d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * @see #getAutoWhiteBalanceLock()
294016b67137b893f32491a38ab81d49368322e1ae92Eino-Ville Talvala         * @see #setWhiteBalance(String)
2941d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         */
2942d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala        public void setAutoWhiteBalanceLock(boolean toggle) {
2943d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala            set(KEY_AUTO_WHITEBALANCE_LOCK, toggle ? TRUE : FALSE);
2944d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala        }
2945d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala
2946d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala        /**
2947d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * Gets the state of the auto-white balance lock. Applications should
2948d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * check {@link #isAutoWhiteBalanceLockSupported} before using this
2949d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * method. See {@link #setAutoWhiteBalanceLock} for details about the
2950d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * lock.
2951d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         *
2952d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * @return State of the auto-white balance lock. Returns true if
2953d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         *         auto-white balance is currently locked, and false
2954b4f95be03e018df825356fe2cd363797c66303f1Wu-cheng Li         *         otherwise.
2955d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         *
2956d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * @see #setAutoWhiteBalanceLock(boolean)
2957d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         *
2958d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         */
2959d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala        public boolean getAutoWhiteBalanceLock() {
2960d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala            String str = get(KEY_AUTO_WHITEBALANCE_LOCK);
2961d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala            return TRUE.equals(str);
2962d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala        }
2963d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala
2964d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala        /**
2965d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * Returns true if auto-white balance locking is supported. Applications
2966d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * should call this before trying to lock auto-white balance. See
2967d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * {@link #setAutoWhiteBalanceLock} for details about the lock.
2968d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         *
2969d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * @return true if auto-white balance lock is supported.
2970d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * @see #setAutoWhiteBalanceLock(boolean)
2971d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         *
2972d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         */
2973d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala        public boolean isAutoWhiteBalanceLockSupported() {
2974d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala            String str = get(KEY_AUTO_WHITEBALANCE_LOCK_SUPPORTED);
2975d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala            return TRUE.equals(str);
2976d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala        }
2977d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala
2978d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala        /**
297936f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li         * Gets current zoom value. This also works when smooth zoom is in
29808cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li         * progress. Applications should check {@link #isZoomSupported} before
29818cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li         * using this method.
298236f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li         *
298336f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li         * @return the current zoom value. The range is 0 to {@link
29848cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li         *         #getMaxZoom}. 0 means the camera is not zoomed.
298536f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li         */
298636f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li        public int getZoom() {
29878cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li            return getInt(KEY_ZOOM, 0);
298836f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li        }
298936f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li
299036f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li        /**
29918cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li         * Sets current zoom value. If the camera is zoomed (value > 0), the
29928cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li         * actual picture size may be smaller than picture size setting.
29938cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li         * Applications can check the actual picture size after picture is
29948cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li         * returned from {@link PictureCallback}. The preview size remains the
29958cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li         * same in zoom. Applications should check {@link #isZoomSupported}
29968cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li         * before using this method.
299736f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li         *
299836f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li         * @param value zoom value. The valid range is 0 to {@link #getMaxZoom}.
299936f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li         */
300036f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li        public void setZoom(int value) {
30018cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li            set(KEY_ZOOM, value);
300236f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li        }
300336f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li
300436f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li        /**
300536f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li         * Returns true if zoom is supported. Applications should call this
300636f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li         * before using other zoom methods.
300736f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li         *
300836f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li         * @return true if zoom is supported.
300936f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li         */
301036f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li        public boolean isZoomSupported() {
30118cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li            String str = get(KEY_ZOOM_SUPPORTED);
30128cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li            return TRUE.equals(str);
301336f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li        }
301436f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li
301536f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li        /**
301636f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li         * Gets the maximum zoom value allowed for snapshot. This is the maximum
301736f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li         * value that applications can set to {@link #setZoom(int)}.
30188cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li         * Applications should call {@link #isZoomSupported} before using this
30198cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li         * method. This value may change in different preview size. Applications
30208cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li         * should call this again after setting preview size.
302136f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li         *
302236f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li         * @return the maximum zoom value supported by the camera.
302336f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li         */
302436f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li        public int getMaxZoom() {
30258cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li            return getInt(KEY_MAX_ZOOM, 0);
302636f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li        }
302736f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li
302836f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li        /**
30298cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li         * Gets the zoom ratios of all zoom values. Applications should check
30308cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li         * {@link #isZoomSupported} before using this method.
303136f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li         *
30328cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li         * @return the zoom ratios in 1/100 increments. Ex: a zoom of 3.2x is
30338cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li         *         returned as 320. The number of elements is {@link
30348cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li         *         #getMaxZoom} + 1. The list is sorted from small to large. The
30358cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li         *         first element is always 100. The last element is the zoom
30368cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li         *         ratio of the maximum zoom value.
303736f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li         */
30388cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li        public List<Integer> getZoomRatios() {
30398cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li            return splitInt(get(KEY_ZOOM_RATIOS));
304036f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li        }
304136f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li
304236f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li        /**
304336f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li         * Returns true if smooth zoom is supported. Applications should call
304436f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li         * this before using other smooth zoom methods.
304536f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li         *
304636f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li         * @return true if smooth zoom is supported.
304736f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li         */
304836f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li        public boolean isSmoothZoomSupported() {
30498cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li            String str = get(KEY_SMOOTH_ZOOM_SUPPORTED);
30508cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li            return TRUE.equals(str);
305136f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li        }
305236f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li
3053e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li        /**
305432a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * <p>Gets the distances from the camera to where an object appears to be
3055e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li         * in focus. The object is sharpest at the optimal focus distance. The
305632a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * depth of field is the far focus distance minus near focus distance.</p>
3057e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li         *
305832a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * <p>Focus distances may change after calling {@link
3059e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li         * #autoFocus(AutoFocusCallback)}, {@link #cancelAutoFocus}, or {@link
3060e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li         * #startPreview()}. Applications can call {@link #getParameters()}
3061e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li         * and this method anytime to get the latest focus distances. If the
3062d45cb72ac0d7d57829ffc9223decb89a5fc42ce2Wu-cheng Li         * focus mode is FOCUS_MODE_CONTINUOUS_VIDEO, focus distances may change
306332a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * from time to time.</p>
3064699fe9397974685e6b2c73f9a3a0eb9e5a5a2ccfWu-cheng Li         *
306532a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * <p>This method is intended to estimate the distance between the camera
3066699fe9397974685e6b2c73f9a3a0eb9e5a5a2ccfWu-cheng Li         * and the subject. After autofocus, the subject distance may be within
3067699fe9397974685e6b2c73f9a3a0eb9e5a5a2ccfWu-cheng Li         * near and far focus distance. However, the precision depends on the
3068699fe9397974685e6b2c73f9a3a0eb9e5a5a2ccfWu-cheng Li         * camera hardware, autofocus algorithm, the focus area, and the scene.
306932a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * The error can be large and it should be only used as a reference.</p>
3070e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li         *
307132a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * <p>Far focus distance >= optimal focus distance >= near focus distance.
3072185cc455a87c636d48ad9a16c13d2ebad7433735Wu-cheng Li         * If the focus distance is infinity, the value will be
307332a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * {@code Float.POSITIVE_INFINITY}.</p>
3074e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li         *
3075e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li         * @param output focus distances in meters. output must be a float
3076e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li         *        array with three elements. Near focus distance, optimal focus
3077e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li         *        distance, and far focus distance will be filled in the array.
3078185cc455a87c636d48ad9a16c13d2ebad7433735Wu-cheng Li         * @see #FOCUS_DISTANCE_NEAR_INDEX
3079185cc455a87c636d48ad9a16c13d2ebad7433735Wu-cheng Li         * @see #FOCUS_DISTANCE_OPTIMAL_INDEX
3080185cc455a87c636d48ad9a16c13d2ebad7433735Wu-cheng Li         * @see #FOCUS_DISTANCE_FAR_INDEX
3081e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li         */
3082e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li        public void getFocusDistances(float[] output) {
3083e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li            if (output == null || output.length != 3) {
3084e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li                throw new IllegalArgumentException(
3085e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li                        "output must be an float array with three elements.");
3086e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li            }
3087454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li            splitFloat(get(KEY_FOCUS_DISTANCES), output);
3088e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li        }
3089e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li
309030771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li        /**
309130771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li         * Gets the maximum number of focus areas supported. This is the maximum
30927b1c5c891a09e0e2a2de101fbf951cdc89e03957Wu-cheng Li         * length of the list in {@link #setFocusAreas(List)} and
30937b1c5c891a09e0e2a2de101fbf951cdc89e03957Wu-cheng Li         * {@link #getFocusAreas()}.
309430771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li         *
309530771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li         * @return the maximum number of focus areas supported by the camera.
309630771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li         * @see #getFocusAreas()
309730771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li         */
309830771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li        public int getMaxNumFocusAreas() {
309930771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li            return getInt(KEY_MAX_NUM_FOCUS_AREAS, 0);
310030771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li        }
310130771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li
310230771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li        /**
310332a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * <p>Gets the current focus areas. Camera driver uses the areas to decide
310432a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * focus.</p>
310530771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li         *
310632a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * <p>Before using this API or {@link #setFocusAreas(List)}, apps should
31077b1c5c891a09e0e2a2de101fbf951cdc89e03957Wu-cheng Li         * call {@link #getMaxNumFocusAreas()} to know the maximum number of
310832a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * focus areas first. If the value is 0, focus area is not supported.</p>
310930771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li         *
311032a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * <p>Each focus area is a rectangle with specified weight. The direction
311130771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li         * is relative to the sensor orientation, that is, what the sensor sees.
311230771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li         * The direction is not affected by the rotation or mirroring of
311330771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li         * {@link #setDisplayOrientation(int)}. Coordinates of the rectangle
311430771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li         * range from -1000 to 1000. (-1000, -1000) is the upper left point.
3115bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Li         * (1000, 1000) is the lower right point. The width and height of focus
311632a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * areas cannot be 0 or negative.</p>
311730771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li         *
311832a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * <p>The weight must range from 1 to 1000. The weight should be
31194e396e063c8b0fa6201b47166f547a98abfd6038Eino-Ville Talvala         * interpreted as a per-pixel weight - all pixels in the area have the
31204e396e063c8b0fa6201b47166f547a98abfd6038Eino-Ville Talvala         * specified weight. This means a small area with the same weight as a
31214e396e063c8b0fa6201b47166f547a98abfd6038Eino-Ville Talvala         * larger area will have less influence on the focusing than the larger
31224e396e063c8b0fa6201b47166f547a98abfd6038Eino-Ville Talvala         * area. Focus areas can partially overlap and the driver will add the
312332a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * weights in the overlap region.</p>
312430771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li         *
312532a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * <p>A special case of a {@code null} focus area list means the driver is
312632a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * free to select focus targets as it wants. For example, the driver may
312732a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * use more signals to select focus areas and change them
312832a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * dynamically. Apps can set the focus area list to {@code null} if they
312932a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * want the driver to completely control focusing.</p>
313030771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li         *
313132a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * <p>Focus areas are relative to the current field of view
313230771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li         * ({@link #getZoom()}). No matter what the zoom level is, (-1000,-1000)
313330771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li         * represents the top of the currently visible camera frame. The focus
313430771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li         * area cannot be set to be outside the current field of view, even
313532a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * when using zoom.</p>
313630771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li         *
313732a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * <p>Focus area only has effect if the current focus mode is
313853b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li         * {@link #FOCUS_MODE_AUTO}, {@link #FOCUS_MODE_MACRO},
313953b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li         * {@link #FOCUS_MODE_CONTINUOUS_VIDEO}, or
314053b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li         * {@link #FOCUS_MODE_CONTINUOUS_PICTURE}.</p>
314130771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li         *
314230771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li         * @return a list of current focus areas
314330771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li         */
314430771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li        public List<Area> getFocusAreas() {
3145f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li            return splitArea(get(KEY_FOCUS_AREAS));
314630771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li        }
314730771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li
314830771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li        /**
314930771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li         * Sets focus areas. See {@link #getFocusAreas()} for documentation.
315030771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li         *
31517b1c5c891a09e0e2a2de101fbf951cdc89e03957Wu-cheng Li         * @param focusAreas the focus areas
315230771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li         * @see #getFocusAreas()
315330771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li         */
3154e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li        public void setFocusAreas(List<Area> focusAreas) {
3155e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li            set(KEY_FOCUS_AREAS, focusAreas);
3156e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li        }
3157e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li
3158e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li        /**
3159e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li         * Gets the maximum number of metering areas supported. This is the
31607b1c5c891a09e0e2a2de101fbf951cdc89e03957Wu-cheng Li         * maximum length of the list in {@link #setMeteringAreas(List)} and
31617b1c5c891a09e0e2a2de101fbf951cdc89e03957Wu-cheng Li         * {@link #getMeteringAreas()}.
3162e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li         *
3163e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li         * @return the maximum number of metering areas supported by the camera.
3164e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li         * @see #getMeteringAreas()
3165e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li         */
3166e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li        public int getMaxNumMeteringAreas() {
3167e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li            return getInt(KEY_MAX_NUM_METERING_AREAS, 0);
3168e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li        }
3169e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li
3170e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li        /**
317132a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * <p>Gets the current metering areas. Camera driver uses these areas to
317232a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * decide exposure.</p>
3173e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li         *
317432a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * <p>Before using this API or {@link #setMeteringAreas(List)}, apps should
31757b1c5c891a09e0e2a2de101fbf951cdc89e03957Wu-cheng Li         * call {@link #getMaxNumMeteringAreas()} to know the maximum number of
31767b1c5c891a09e0e2a2de101fbf951cdc89e03957Wu-cheng Li         * metering areas first. If the value is 0, metering area is not
317732a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * supported.</p>
3178e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li         *
317932a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * <p>Each metering area is a rectangle with specified weight. The
3180e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li         * direction is relative to the sensor orientation, that is, what the
3181e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li         * sensor sees. The direction is not affected by the rotation or
3182e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li         * mirroring of {@link #setDisplayOrientation(int)}. Coordinates of the
3183e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li         * rectangle range from -1000 to 1000. (-1000, -1000) is the upper left
3184bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Li         * point. (1000, 1000) is the lower right point. The width and height of
318532a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * metering areas cannot be 0 or negative.</p>
3186e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li         *
318732a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * <p>The weight must range from 1 to 1000, and represents a weight for
31884e396e063c8b0fa6201b47166f547a98abfd6038Eino-Ville Talvala         * every pixel in the area. This means that a large metering area with
31894e396e063c8b0fa6201b47166f547a98abfd6038Eino-Ville Talvala         * the same weight as a smaller area will have more effect in the
31904e396e063c8b0fa6201b47166f547a98abfd6038Eino-Ville Talvala         * metering result.  Metering areas can partially overlap and the driver
319132a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * will add the weights in the overlap region.</p>
3192e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li         *
319332a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * <p>A special case of a {@code null} metering area list means the driver
319432a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * is free to meter as it chooses. For example, the driver may use more
319532a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * signals to select metering areas and change them dynamically. Apps
319632a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * can set the metering area list to {@code null} if they want the
319732a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * driver to completely control metering.</p>
3198e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li         *
319932a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * <p>Metering areas are relative to the current field of view
3200e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li         * ({@link #getZoom()}). No matter what the zoom level is, (-1000,-1000)
3201e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li         * represents the top of the currently visible camera frame. The
3202e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li         * metering area cannot be set to be outside the current field of view,
320332a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * even when using zoom.</p>
3204e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li         *
320532a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * <p>No matter what metering areas are, the final exposure are compensated
320632a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * by {@link #setExposureCompensation(int)}.</p>
3207e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li         *
3208e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li         * @return a list of current metering areas
3209e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li         */
3210e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li        public List<Area> getMeteringAreas() {
3211d8aab93f96a6357dedc791ccdea92412fb423d15Wu-cheng Li            return splitArea(get(KEY_METERING_AREAS));
3212e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li        }
3213e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li
3214e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li        /**
3215e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li         * Sets metering areas. See {@link #getMeteringAreas()} for
3216e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li         * documentation.
3217e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li         *
32187b1c5c891a09e0e2a2de101fbf951cdc89e03957Wu-cheng Li         * @param meteringAreas the metering areas
3219e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li         * @see #getMeteringAreas()
3220e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li         */
3221e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li        public void setMeteringAreas(List<Area> meteringAreas) {
3222e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li            set(KEY_METERING_AREAS, meteringAreas);
322330771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li        }
322430771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li
32254c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li        /**
32264c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li         * Gets the maximum number of detected faces supported. This is the
32274c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li         * maximum length of the list returned from {@link FaceDetectionListener}.
32284c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li         * If the return value is 0, face detection of the specified type is not
32294c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li         * supported.
32304c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li         *
32314c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li         * @return the maximum number of detected face supported by the camera.
3232464cb21e2aaa448072449b82156f18bd64c0e613Joe Fernandez         * @see #startFaceDetection()
32334c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li         */
3234c0c683b3344c67700882f8059e7d18266366daa9Wu-cheng Li        public int getMaxNumDetectedFaces() {
3235c0c683b3344c67700882f8059e7d18266366daa9Wu-cheng Li            return getInt(KEY_MAX_NUM_DETECTED_FACES_HW, 0);
32364c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li        }
32374c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li
323825d8fb51dae37f1becf4fb3d32e8600c418eb6e8Wu-cheng Li        /**
32399c53f1c33a433c1e9bd84a26d57e0e99f616fa24Wu-cheng Li         * Sets recording mode hint. This tells the camera that the intent of
32409c53f1c33a433c1e9bd84a26d57e0e99f616fa24Wu-cheng Li         * the application is to record videos {@link
32419c53f1c33a433c1e9bd84a26d57e0e99f616fa24Wu-cheng Li         * android.media.MediaRecorder#start()}, not to take still pictures
32429c53f1c33a433c1e9bd84a26d57e0e99f616fa24Wu-cheng Li         * {@link #takePicture(Camera.ShutterCallback, Camera.PictureCallback,
32439c53f1c33a433c1e9bd84a26d57e0e99f616fa24Wu-cheng Li         * Camera.PictureCallback, Camera.PictureCallback)}. Using this hint can
32449c53f1c33a433c1e9bd84a26d57e0e99f616fa24Wu-cheng Li         * allow MediaRecorder.start() to start faster or with fewer glitches on
32459c53f1c33a433c1e9bd84a26d57e0e99f616fa24Wu-cheng Li         * output. This should be called before starting preview for the best
32469c53f1c33a433c1e9bd84a26d57e0e99f616fa24Wu-cheng Li         * result, but can be changed while the preview is active. The default
32479c53f1c33a433c1e9bd84a26d57e0e99f616fa24Wu-cheng Li         * value is false.
32489c53f1c33a433c1e9bd84a26d57e0e99f616fa24Wu-cheng Li         *
32499c53f1c33a433c1e9bd84a26d57e0e99f616fa24Wu-cheng Li         * The app can still call takePicture() when the hint is true or call
32509c53f1c33a433c1e9bd84a26d57e0e99f616fa24Wu-cheng Li         * MediaRecorder.start() when the hint is false. But the performance may
32519c53f1c33a433c1e9bd84a26d57e0e99f616fa24Wu-cheng Li         * be worse.
32529c53f1c33a433c1e9bd84a26d57e0e99f616fa24Wu-cheng Li         *
32539c53f1c33a433c1e9bd84a26d57e0e99f616fa24Wu-cheng Li         * @param hint true if the apps intend to record videos using
325425d8fb51dae37f1becf4fb3d32e8600c418eb6e8Wu-cheng Li         *             {@link android.media.MediaRecorder}.
325525d8fb51dae37f1becf4fb3d32e8600c418eb6e8Wu-cheng Li         */
325625d8fb51dae37f1becf4fb3d32e8600c418eb6e8Wu-cheng Li        public void setRecordingHint(boolean hint) {
325725d8fb51dae37f1becf4fb3d32e8600c418eb6e8Wu-cheng Li            set(KEY_RECORDING_HINT, hint ? TRUE : FALSE);
325825d8fb51dae37f1becf4fb3d32e8600c418eb6e8Wu-cheng Li        }
325925d8fb51dae37f1becf4fb3d32e8600c418eb6e8Wu-cheng Li
326098bb251c8b527600e7a4cca6cc33499710bbfbf1Wu-cheng Li        /**
326198bb251c8b527600e7a4cca6cc33499710bbfbf1Wu-cheng Li         * Returns true if video snapshot is supported. That is, applications
326298bb251c8b527600e7a4cca6cc33499710bbfbf1Wu-cheng Li         * can call {@link #takePicture(Camera.ShutterCallback,
326398bb251c8b527600e7a4cca6cc33499710bbfbf1Wu-cheng Li         * Camera.PictureCallback, Camera.PictureCallback, Camera.PictureCallback)}
326498bb251c8b527600e7a4cca6cc33499710bbfbf1Wu-cheng Li         * during recording. Applications do not need to call {@link
326598bb251c8b527600e7a4cca6cc33499710bbfbf1Wu-cheng Li         * #startPreview()} after taking a picture. The preview will be still
326698bb251c8b527600e7a4cca6cc33499710bbfbf1Wu-cheng Li         * active. Other than that, taking a picture during recording is
326798bb251c8b527600e7a4cca6cc33499710bbfbf1Wu-cheng Li         * identical to taking a picture normally. All settings and methods
326898bb251c8b527600e7a4cca6cc33499710bbfbf1Wu-cheng Li         * related to takePicture work identically. Ex: {@link
326998bb251c8b527600e7a4cca6cc33499710bbfbf1Wu-cheng Li         * #getPictureSize()}, {@link #getSupportedPictureSizes()}, {@link
327098bb251c8b527600e7a4cca6cc33499710bbfbf1Wu-cheng Li         * #setJpegQuality(int)}, {@link #setRotation(int)}, and etc. The
327198bb251c8b527600e7a4cca6cc33499710bbfbf1Wu-cheng Li         * picture will have an EXIF header. {@link #FLASH_MODE_AUTO} and {@link
327298bb251c8b527600e7a4cca6cc33499710bbfbf1Wu-cheng Li         * #FLASH_MODE_ON} also still work, but the video will record the flash.
327398bb251c8b527600e7a4cca6cc33499710bbfbf1Wu-cheng Li         *
327498bb251c8b527600e7a4cca6cc33499710bbfbf1Wu-cheng Li         * Applications can set shutter callback as null to avoid the shutter
327598bb251c8b527600e7a4cca6cc33499710bbfbf1Wu-cheng Li         * sound. It is also recommended to set raw picture and post view
327698bb251c8b527600e7a4cca6cc33499710bbfbf1Wu-cheng Li         * callbacks to null to avoid the interrupt of preview display.
327798bb251c8b527600e7a4cca6cc33499710bbfbf1Wu-cheng Li         *
327898bb251c8b527600e7a4cca6cc33499710bbfbf1Wu-cheng Li         * Field-of-view of the recorded video may be different from that of the
327998bb251c8b527600e7a4cca6cc33499710bbfbf1Wu-cheng Li         * captured pictures.
328098bb251c8b527600e7a4cca6cc33499710bbfbf1Wu-cheng Li         *
328198bb251c8b527600e7a4cca6cc33499710bbfbf1Wu-cheng Li         * @return true if video snapshot is supported.
328298bb251c8b527600e7a4cca6cc33499710bbfbf1Wu-cheng Li         */
328398bb251c8b527600e7a4cca6cc33499710bbfbf1Wu-cheng Li        public boolean isVideoSnapshotSupported() {
328498bb251c8b527600e7a4cca6cc33499710bbfbf1Wu-cheng Li            String str = get(KEY_VIDEO_SNAPSHOT_SUPPORTED);
328598bb251c8b527600e7a4cca6cc33499710bbfbf1Wu-cheng Li            return TRUE.equals(str);
328698bb251c8b527600e7a4cca6cc33499710bbfbf1Wu-cheng Li        }
328798bb251c8b527600e7a4cca6cc33499710bbfbf1Wu-cheng Li
3288037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala        /**
3289037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala         * <p>Enables and disables video stabilization. Use
3290037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala         * {@link #isVideoStabilizationSupported} to determine if calling this
3291037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala         * method is valid.</p>
3292037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala         *
3293037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala         * <p>Video stabilization reduces the shaking due to the motion of the
3294037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala         * camera in both the preview stream and in recorded videos, including
3295037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala         * data received from the preview callback. It does not reduce motion
3296037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala         * blur in images captured with
3297037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala         * {@link Camera#takePicture takePicture}.</p>
3298037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala         *
3299037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala         * <p>Video stabilization can be enabled and disabled while preview or
3300037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala         * recording is active, but toggling it may cause a jump in the video
3301037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala         * stream that may be undesirable in a recorded video.</p>
3302037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala         *
3303037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala         * @param toggle Set to true to enable video stabilization, and false to
3304037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala         * disable video stabilization.
3305037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala         * @see #isVideoStabilizationSupported()
3306037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala         * @see #getVideoStabilization()
3307037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala         */
3308037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala        public void setVideoStabilization(boolean toggle) {
3309037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala            set(KEY_VIDEO_STABILIZATION, toggle ? TRUE : FALSE);
3310037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala        }
3311037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala
3312037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala        /**
3313037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala         * Get the current state of video stabilization. See
3314037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala         * {@link #setVideoStabilization} for details of video stabilization.
3315037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala         *
3316037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala         * @return true if video stabilization is enabled
3317037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala         * @see #isVideoStabilizationSupported()
3318037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala         * @see #setVideoStabilization(boolean)
3319037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala         */
3320037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala        public boolean getVideoStabilization() {
3321037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala            String str = get(KEY_VIDEO_STABILIZATION);
3322037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala            return TRUE.equals(str);
3323037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala        }
3324037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala
3325037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala        /**
3326037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala         * Returns true if video stabilization is supported. See
3327037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala         * {@link #setVideoStabilization} for details of video stabilization.
3328037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala         *
3329037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala         * @return true if video stabilization is supported
3330037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala         * @see #setVideoStabilization(boolean)
3331037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala         * @see #getVideoStabilization()
3332037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala         */
3333037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala        public boolean isVideoStabilizationSupported() {
3334037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala            String str = get(KEY_VIDEO_STABILIZATION_SUPPORTED);
3335037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala            return TRUE.equals(str);
3336037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala        }
3337037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala
33389b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        // Splits a comma delimited string to an ArrayList of String.
33399b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        // Return null if the passing string is null or the size is 0.
33409b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        private ArrayList<String> split(String str) {
33419b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            if (str == null) return null;
33429b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
33439b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            // Use StringTokenizer because it is faster than split.
33449b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            StringTokenizer tokenizer = new StringTokenizer(str, ",");
33459b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            ArrayList<String> substrings = new ArrayList<String>();
33469b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            while (tokenizer.hasMoreElements()) {
33479b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li                substrings.add(tokenizer.nextToken());
33489b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            }
33499b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            return substrings;
33509b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        }
33519b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
33529b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        // Splits a comma delimited string to an ArrayList of Integer.
33539b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        // Return null if the passing string is null or the size is 0.
33549b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        private ArrayList<Integer> splitInt(String str) {
33559b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            if (str == null) return null;
33569b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
33579b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            StringTokenizer tokenizer = new StringTokenizer(str, ",");
33589b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            ArrayList<Integer> substrings = new ArrayList<Integer>();
33599b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            while (tokenizer.hasMoreElements()) {
33609b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li                String token = tokenizer.nextToken();
33619b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li                substrings.add(Integer.parseInt(token));
33629b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            }
33639b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            if (substrings.size() == 0) return null;
33649b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            return substrings;
33659b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        }
33669b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
3367454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li        private void splitInt(String str, int[] output) {
3368454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li            if (str == null) return;
3369454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li
3370454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li            StringTokenizer tokenizer = new StringTokenizer(str, ",");
3371454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li            int index = 0;
3372454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li            while (tokenizer.hasMoreElements()) {
3373454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li                String token = tokenizer.nextToken();
3374454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li                output[index++] = Integer.parseInt(token);
3375454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li            }
3376454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li        }
3377454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li
3378e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li        // Splits a comma delimited string to an ArrayList of Float.
3379454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li        private void splitFloat(String str, float[] output) {
3380454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li            if (str == null) return;
3381e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li
3382e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li            StringTokenizer tokenizer = new StringTokenizer(str, ",");
3383454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li            int index = 0;
3384e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li            while (tokenizer.hasMoreElements()) {
3385e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li                String token = tokenizer.nextToken();
3386454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li                output[index++] = Float.parseFloat(token);
3387e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li            }
3388e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li        }
3389e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li
339024b326a8978bf78e3e560723dde221792784325bWu-cheng Li        // Returns the value of a float parameter.
339124b326a8978bf78e3e560723dde221792784325bWu-cheng Li        private float getFloat(String key, float defaultValue) {
339224b326a8978bf78e3e560723dde221792784325bWu-cheng Li            try {
339324b326a8978bf78e3e560723dde221792784325bWu-cheng Li                return Float.parseFloat(mMap.get(key));
339424b326a8978bf78e3e560723dde221792784325bWu-cheng Li            } catch (NumberFormatException ex) {
339524b326a8978bf78e3e560723dde221792784325bWu-cheng Li                return defaultValue;
339624b326a8978bf78e3e560723dde221792784325bWu-cheng Li            }
339724b326a8978bf78e3e560723dde221792784325bWu-cheng Li        }
339824b326a8978bf78e3e560723dde221792784325bWu-cheng Li
339924b326a8978bf78e3e560723dde221792784325bWu-cheng Li        // Returns the value of a integer parameter.
340024b326a8978bf78e3e560723dde221792784325bWu-cheng Li        private int getInt(String key, int defaultValue) {
340124b326a8978bf78e3e560723dde221792784325bWu-cheng Li            try {
340224b326a8978bf78e3e560723dde221792784325bWu-cheng Li                return Integer.parseInt(mMap.get(key));
340324b326a8978bf78e3e560723dde221792784325bWu-cheng Li            } catch (NumberFormatException ex) {
340424b326a8978bf78e3e560723dde221792784325bWu-cheng Li                return defaultValue;
340524b326a8978bf78e3e560723dde221792784325bWu-cheng Li            }
340624b326a8978bf78e3e560723dde221792784325bWu-cheng Li        }
340724b326a8978bf78e3e560723dde221792784325bWu-cheng Li
34089b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        // Splits a comma delimited string to an ArrayList of Size.
34099b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        // Return null if the passing string is null or the size is 0.
34109b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        private ArrayList<Size> splitSize(String str) {
34119b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            if (str == null) return null;
34129b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
34139b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            StringTokenizer tokenizer = new StringTokenizer(str, ",");
34149b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            ArrayList<Size> sizeList = new ArrayList<Size>();
34159b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            while (tokenizer.hasMoreElements()) {
34169b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li                Size size = strToSize(tokenizer.nextToken());
34179b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li                if (size != null) sizeList.add(size);
34189b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            }
34199b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            if (sizeList.size() == 0) return null;
34209b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            return sizeList;
34219b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        }
34229b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
34239b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        // Parses a string (ex: "480x320") to Size object.
34249b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        // Return null if the passing string is null.
34259b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        private Size strToSize(String str) {
34269b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            if (str == null) return null;
34279b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
34289b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            int pos = str.indexOf('x');
34299b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            if (pos != -1) {
34309b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li                String width = str.substring(0, pos);
34319b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li                String height = str.substring(pos + 1);
34329b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li                return new Size(Integer.parseInt(width),
34339b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li                                Integer.parseInt(height));
34349b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            }
34359b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            Log.e(TAG, "Invalid size parameter string=" + str);
34369b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            return null;
34379b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        }
3438454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li
3439454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li        // Splits a comma delimited string to an ArrayList of int array.
3440454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li        // Example string: "(10000,26623),(10000,30000)". Return null if the
3441454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li        // passing string is null or the size is 0.
3442454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li        private ArrayList<int[]> splitRange(String str) {
3443454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li            if (str == null || str.charAt(0) != '('
3444454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li                    || str.charAt(str.length() - 1) != ')') {
3445454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li                Log.e(TAG, "Invalid range list string=" + str);
3446454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li                return null;
3447454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li            }
3448454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li
3449454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li            ArrayList<int[]> rangeList = new ArrayList<int[]>();
3450454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li            int endIndex, fromIndex = 1;
3451454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li            do {
3452454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li                int[] range = new int[2];
3453454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li                endIndex = str.indexOf("),(", fromIndex);
3454454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li                if (endIndex == -1) endIndex = str.length() - 1;
3455454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li                splitInt(str.substring(fromIndex, endIndex), range);
3456454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li                rangeList.add(range);
3457454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li                fromIndex = endIndex + 3;
3458454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li            } while (endIndex != str.length() - 1);
3459454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li
3460454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li            if (rangeList.size() == 0) return null;
3461454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li            return rangeList;
3462454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li        }
346330771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li
346430771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li        // Splits a comma delimited string to an ArrayList of Area objects.
346530771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li        // Example string: "(-10,-10,0,0,300),(0,0,10,10,700)". Return null if
3466f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li        // the passing string is null or the size is 0 or (0,0,0,0,0).
346730771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li        private ArrayList<Area> splitArea(String str) {
346830771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li            if (str == null || str.charAt(0) != '('
346930771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li                    || str.charAt(str.length() - 1) != ')') {
347030771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li                Log.e(TAG, "Invalid area string=" + str);
347130771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li                return null;
347230771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li            }
347330771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li
347430771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li            ArrayList<Area> result = new ArrayList<Area>();
347530771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li            int endIndex, fromIndex = 1;
347630771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li            int[] array = new int[5];
347730771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li            do {
347830771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li                endIndex = str.indexOf("),(", fromIndex);
347930771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li                if (endIndex == -1) endIndex = str.length() - 1;
348030771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li                splitInt(str.substring(fromIndex, endIndex), array);
348130771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li                Rect rect = new Rect(array[0], array[1], array[2], array[3]);
348230771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li                result.add(new Area(rect, array[4]));
348330771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li                fromIndex = endIndex + 3;
348430771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li            } while (endIndex != str.length() - 1);
348530771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li
348630771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li            if (result.size() == 0) return null;
3487f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li
3488f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li            if (result.size() == 1) {
3489bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Li                Area area = result.get(0);
3490f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li                Rect rect = area.rect;
3491f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li                if (rect.left == 0 && rect.top == 0 && rect.right == 0
3492f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li                        && rect.bottom == 0 && area.weight == 0) {
3493f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li                    return null;
3494f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li                }
3495f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li            }
3496f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li
349730771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li            return result;
349830771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li        }
3499b838d8d4a26c3cfea2e2a5ce831daebbb5653ae7Wu-cheng Li
3500b838d8d4a26c3cfea2e2a5ce831daebbb5653ae7Wu-cheng Li        private boolean same(String s1, String s2) {
3501b838d8d4a26c3cfea2e2a5ce831daebbb5653ae7Wu-cheng Li            if (s1 == null && s2 == null) return true;
3502b838d8d4a26c3cfea2e2a5ce831daebbb5653ae7Wu-cheng Li            if (s1 != null && s1.equals(s2)) return true;
3503b838d8d4a26c3cfea2e2a5ce831daebbb5653ae7Wu-cheng Li            return false;
3504b838d8d4a26c3cfea2e2a5ce831daebbb5653ae7Wu-cheng Li        }
35059066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    };
3506e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala
3507e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala    /**
3508e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala     * <p>The set of default system sounds for camera actions. Use this with
3509e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala     * {@link #playSound} to play an appropriate sound when implementing a
3510e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala     * custom still or video recording mechanism through the preview
3511e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala     * callbacks.</p>
3512e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala     *
3513e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala     * <p>There is no need to play sounds when using {@link #takePicture} or
3514e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala     * {@link android.media.MediaRecorder} for still images or video,
3515e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala     * respectively, as these play their own sounds when needed.</p>
3516e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala     *
3517e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala     * @see #playSound
3518e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala     * @hide
3519e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala     */
3520e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala    public static class Sound {
3521e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala        /**
3522e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala         * The sound used by {@link android.hardware.Camera#takePicture} to
3523e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala         * indicate still image capture.
3524e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala         */
3525e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala        public static final int SHUTTER_CLICK         = 0;
3526e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala
3527e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala        /**
3528e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala         * A sound to indicate that focusing has completed. Because deciding
3529e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala         * when this occurs is application-dependent, this sound is not used by
3530e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala         * any methods in the Camera class.
3531e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala         */
3532e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala        public static final int FOCUS_COMPLETE        = 1;
3533e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala
3534e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala        /**
3535e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala         * The sound used by {@link android.media.MediaRecorder#start} to
3536e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala         * indicate the start of video recording.
3537e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala         */
3538e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala        public static final int START_VIDEO_RECORDING = 2;
3539e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala
3540e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala        /**
3541e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala         * The sound used by {@link android.media.MediaRecorder#stop} to
3542e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala         * indicate the end of video recording.
3543e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala         */
3544e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala        public static final int STOP_VIDEO_RECORDING  = 3;
3545e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala
3546e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala        private static final int NUM_SOUNDS           = 4;
3547e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala    };
3548e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala
3549e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala    /**
3550e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala     * <p>Play one of the predefined platform sounds for camera actions.</p>
3551e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala     *
3552e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala     * <p>Use this method to play a platform-specific sound for various camera
3553e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala     * actions. The sound playing is done asynchronously, with the same behavior
3554e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala     * and content as the sounds played by {@link #takePicture takePicture},
3555e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala     * {@link android.media.MediaRecorder#start MediaRecorder.start}, and
3556e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala     * {@link android.media.MediaRecorder#stop MediaRecorder.stop}.</p>
3557e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala     *
3558e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala     * <p>Using this method makes it easy to match the default device sounds
3559e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala     * when recording or capturing data through the preview callbacks
3560e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala     * ({@link #setPreviewCallback setPreviewCallback},
3561e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala     * {@link #setPreviewTexture setPreviewTexture}).</p>
3562e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala     *
3563e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala     * @param soundId The type of sound to play, selected from the options in
3564e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala     *   {@link android.hardware.Camera.Sound}
3565e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala     * @see android.hardware.Camera.Sound
3566e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala     * @see #takePicture
3567e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala     * @see android.media.MediaRecorder
3568e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala     * @hide
3569e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala     */
3570e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala    public void playSound(int soundId) {
3571e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala        if (mReleased) return;
3572e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala        if (mCameraSoundPlayers == null) {
3573e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala            mCameraSoundPlayers = new CameraSoundPlayer[Sound.NUM_SOUNDS];
3574e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala        }
3575e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala        if (mCameraSoundPlayers[soundId] == null) {
3576e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala            mCameraSoundPlayers[soundId] = new CameraSoundPlayer(soundId);
3577e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala        }
3578e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala        mCameraSoundPlayers[soundId].play();
3579e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala    }
3580e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala
3581e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala    private CameraSoundPlayer[] mCameraSoundPlayers;
3582e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala
3583e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala    private static class CameraSoundPlayer implements Runnable {
3584e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala        private int mSoundId;
3585e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala        private int mAudioStreamType;
3586e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala        private MediaPlayer mPlayer;
3587e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala        private Thread mThread;
3588e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala        private boolean mExit;
3589e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala        private int mPlayCount;
3590e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala
3591e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala        private static final String mShutterSound    =
3592e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala                "/system/media/audio/ui/camera_click.ogg";
3593e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala        private static final String mFocusSound      =
3594e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala                "/system/media/audio/ui/camera_focus.ogg";
3595e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala        private static final String mVideoStartSound =
3596e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala                "/system/media/audio/ui/VideoRecord.ogg";
3597e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala        private static final String mVideoStopSound  =
3598e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala                "/system/media/audio/ui/VideoRecord.ogg";
3599e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala
3600e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala        @Override
3601e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala        public void run() {
3602e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala            String soundFilePath;
3603e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala            switch (mSoundId) {
3604e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala                case Sound.SHUTTER_CLICK:
3605e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala                    soundFilePath = mShutterSound;
3606e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala                    break;
3607e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala                case Sound.FOCUS_COMPLETE:
3608e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala                    soundFilePath = mFocusSound;
3609e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala                    break;
3610e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala                case Sound.START_VIDEO_RECORDING:
3611e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala                    soundFilePath = mVideoStartSound;
3612e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala                    break;
3613e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala                case Sound.STOP_VIDEO_RECORDING:
3614e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala                    soundFilePath = mVideoStopSound;
3615e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala                    break;
3616e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala                default:
3617e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala                    Log.e(TAG, "Unknown sound " + mSoundId + " requested.");
3618e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala                    return;
3619e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala            }
3620e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala            mPlayer = new MediaPlayer();
3621e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala            try {
3622e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala                mPlayer.setAudioStreamType(mAudioStreamType);
3623e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala                mPlayer.setDataSource(soundFilePath);
3624e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala                mPlayer.setLooping(false);
3625e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala                mPlayer.prepare();
3626e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala            } catch(IOException e) {
3627e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala                Log.e(TAG, "Error setting up sound " + mSoundId, e);
3628e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala                return;
3629e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala            }
3630e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala
3631e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala            while(true) {
3632e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala                try {
3633e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala                    synchronized (this) {
3634e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala                        while(true) {
3635e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala                            if (mExit) {
3636e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala                                return;
3637e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala                            } else if (mPlayCount <= 0) {
3638e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala                                wait();
3639e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala                            } else {
3640e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala                                mPlayCount--;
3641e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala                                break;
3642e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala                            }
3643e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala                        }
3644e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala                    }
3645e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala                    mPlayer.start();
3646e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala                } catch (Exception e) {
3647e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala                    Log.e(TAG, "Error playing sound " + mSoundId, e);
3648e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala                }
3649e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala            }
3650e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala        }
3651e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala
3652e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala        public CameraSoundPlayer(int soundId) {
3653e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala            mSoundId = soundId;
3654e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala            if (SystemProperties.get("ro.camera.sound.forced", "0").equals("0")) {
3655e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala                mAudioStreamType = AudioManager.STREAM_MUSIC;
3656e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala            } else {
3657e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala                mAudioStreamType = AudioManager.STREAM_SYSTEM_ENFORCED;
3658e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala            }
3659e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala        }
3660e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala
3661e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala        public void play() {
3662e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala            if (mThread == null) {
3663e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala                mThread = new Thread(this);
3664e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala                mThread.start();
3665e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala            }
3666e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala            synchronized (this) {
3667e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala                mPlayCount++;
3668e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala                notifyAll();
3669e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala            }
3670e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala        }
3671e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala
3672e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala        public void release() {
3673e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala            if (mThread != null) {
3674e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala                synchronized (this) {
3675e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala                    mExit = true;
3676e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala                    notifyAll();
3677e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala                }
3678e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala                try {
3679e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala                    mThread.join();
3680e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala                } catch (InterruptedException e) {
3681e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala                }
3682e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala                mThread = null;
3683e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala            }
3684e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala            if (mPlayer != null) {
3685e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala                mPlayer.release();
3686e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala                mPlayer = null;
3687e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala            }
3688e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala        }
3689e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala
3690e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala        @Override
3691e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala        protected void finalize() {
3692e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala            release();
3693e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala        }
3694e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala    }
3695e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala
36969066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project}
3697